| 2 | | if( ! $cached_page_include ) |
|---|
| 3 | | session_register("cache"); |
|---|
| 4 | | include_once( "env.inc.php" ); |
|---|
| 5 | | include( get_root() . "/modules/prep-cache.inc.php" ); |
|---|
| 6 | | |
|---|
| 7 | | function get_id_for_existing_link( $url, $u ) { |
|---|
| 8 | | $q = run_query( getQuery( "get_id_for_existing_link", $url, $u )); |
|---|
| 9 | | return mysql_result($q, 0, "id" ); |
|---|
| 10 | | } |
|---|
| 11 | | |
|---|
| 12 | | function diff_in_secs( $db_date_0, $db_date_1 ) { |
|---|
| 13 | | $dt0 = strtotime( $db_date_0 ); |
|---|
| 14 | | $dt1 = strtotime( $db_date_1 ); |
|---|
| 15 | | return( $dt0 - $dt1 ); |
|---|
| 16 | | } |
|---|
| 17 | | |
|---|
| 18 | | function get_db_date_diff_in_days( $qs ) { |
|---|
| 19 | | $con_fuq_slot = mysql_connect(); |
|---|
| 20 | | mysql_selectdb( getDBName() ); |
|---|
| 21 | | $q = mysql_query( $qs ); |
|---|
| 22 | | if( ! $q ) |
|---|
| 23 | | return undefined; |
|---|
| 24 | | |
|---|
| 25 | | $d0 = mysql_result($q,0); |
|---|
| 26 | | $d1 = mysql_result($q,1); |
|---|
| 27 | | $diff = round( diff_in_secs( $d0, $d1 ) / 60 / 60 / 24, 4); |
|---|
| 28 | | return $diff > 0 ? $diff : 0; |
|---|
| 29 | | } |
|---|
| 30 | | |
|---|
| 31 | | function get_simple_rs( $qs ) { |
|---|
| 32 | | $con = mysql_connect(); |
|---|
| 33 | | mysql_selectdb( getDBName() ); |
|---|
| 34 | | $q = mysql_query( $qs ); |
|---|
| 35 | | if( ! $q ) |
|---|
| 36 | | return undefined; |
|---|
| 37 | | |
|---|
| 38 | | return mysql_result($q,0); |
|---|
| 39 | | } |
|---|
| 40 | | |
|---|
| 41 | | function get_fuq_threshold() { return 2; } |
|---|
| 42 | | |
|---|
| 43 | | function get_fuq( $u ) { |
|---|
| 44 | | $con = mysql_connect(); |
|---|
| 45 | | mysql_selectdb( getDBName() ); |
|---|
| 46 | | $qs = getQuery( "get_fuq", $u ); |
|---|
| | 2 | if( ! $cached_page_include ) |
|---|
| | 3 | session_register("cache"); |
|---|
| | 4 | include_once( "env.inc.php" ); |
|---|
| | 5 | include( get_root() . "/modules/prep-cache.inc.php" ); |
|---|
| | 6 | |
|---|
| | 7 | # returns the PATH to the newly created thumbnail |
|---|
| | 8 | function make_thumbnail_for_user( $u ) { |
|---|
| | 9 | $i = get_profile_image( $u ); |
|---|
| | 10 | $out = "/" . get_user_folder( $u ) . "/thumb.png"; |
|---|
| | 11 | imagepng( get_png_thumbnail_from_image( $i ), get_root() . $out ); |
|---|
| | 12 | return $out; |
|---|
| | 13 | } |
|---|
| | 14 | |
|---|
| | 15 | # returns an image OBJECT of the newly created thumbnail |
|---|
| | 16 | function get_png_thumbnail_from_image( $i ) { |
|---|
| | 17 | $goal = 64; |
|---|
| | 18 | list($width, $height, $type, $attr) = getimagesize( $i ); |
|---|
| | 19 | |
|---|
| | 20 | #calculate which is the shorter side, re-map that to $goal, and calculate the new length of the longer side |
|---|
| | 21 | $tall = ( $width < $height ) ? true : false; |
|---|
| | 22 | $new_height = $new_width = $goal; |
|---|
| | 23 | if( $tall ) { |
|---|
| | 24 | $frac = $goal / $width; |
|---|
| | 25 | $new_height = $height * $frac; |
|---|
| | 26 | } else { |
|---|
| | 27 | $frac = $goal / $height; |
|---|
| | 28 | $new_width = $width * $frac; |
|---|
| | 29 | } |
|---|
| | 30 | |
|---|
| | 31 | switch( $type ){ |
|---|
| | 32 | case 1 : $orig = imagecreatefromgif($i); break; |
|---|
| | 33 | case 2 : $orig = imagecreatefromjpeg($i); break; |
|---|
| | 34 | case 3 : $orig = imagecreatefrompng($i); break; |
|---|
| | 35 | default: break; |
|---|
| | 36 | } |
|---|
| | 37 | |
|---|
| | 38 | # resize it: |
|---|
| | 39 | $small = imagecreatetruecolor( $new_width, $new_height ); |
|---|
| | 40 | imagecopyresampled( $small, $orig, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|---|
| | 41 | imagepng( $small, "icons/small.png" ); |
|---|
| | 42 | |
|---|
| | 43 | # new black-bordered palette to copy onto: |
|---|
| | 44 | $cropped = imagecreatetruecolor( $goal + 2, $goal + 2 ); |
|---|
| | 45 | imagefill( $cropped, 0, 0, imagecolorallocate( $cropped, 0, 0, 0 )); |
|---|
| | 46 | |
|---|
| | 47 | # crop image onto black |
|---|
| | 48 | imagecopy($cropped, $small, 1, 1, ceil( ($new_width - $goal) / 2), ceil( ($new_height - $goal) / 2), $goal, $goal); |
|---|
| | 49 | |
|---|
| | 50 | imagedestroy($small); |
|---|
| | 51 | imagedestroy($orig); |
|---|
| | 52 | return $cropped; |
|---|
| | 53 | } |
|---|
| | 54 | |
|---|
| | 55 | function get_id_for_existing_link( $url, $u ) { |
|---|
| | 56 | $q = run_query( getQuery( "get_id_for_existing_link", $url, $u )); |
|---|
| | 57 | return mysql_result($q, 0, "id" ); |
|---|
| | 58 | } |
|---|
| | 59 | |
|---|
| | 60 | function diff_in_secs( $db_date_0, $db_date_1 ) { |
|---|
| | 61 | $dt0 = strtotime( $db_date_0 ); |
|---|
| | 62 | $dt1 = strtotime( $db_date_1 ); |
|---|
| | 63 | return( $dt0 - $dt1 ); |
|---|
| | 64 | } |
|---|
| | 65 | |
|---|
| | 66 | function get_db_date_diff_in_days( $qs ) { |
|---|
| | 67 | $con_fuq_slot = mysql_connect(); |
|---|
| | 68 | mysql_selectdb( getDBName() ); |
|---|
| | 69 | $q = mysql_query( $qs ); |
|---|
| | 70 | if( ! $q ) |
|---|
| | 71 | return undefined; |
|---|
| 51 | | if( $num_rows == 1 ) |
|---|
| 52 | | return mysql_result($q, 0, "FUQ" ); |
|---|
| 53 | | else |
|---|
| 54 | | return 2; |
|---|
| 55 | | } |
|---|
| 56 | | |
|---|
| 57 | | function delta_time_between_links( $u, $raw = false ) { |
|---|
| 58 | | $value = get_db_date_diff_in_days( getQuery( "get_fuq_slot_delta_time_between_links", $u )) * 60; |
|---|
| 59 | | if( $raw ) |
|---|
| 60 | | return $value; |
|---|
| 61 | | else |
|---|
| 62 | | if( $value < 0.5 ) |
|---|
| 63 | | return -1; |
|---|
| 64 | | else if( $value > 10 ) |
|---|
| 65 | | return 1; |
|---|
| 66 | | else |
|---|
| 67 | | return 0; |
|---|
| 68 | | } |
|---|
| 69 | | |
|---|
| 70 | | function recency( $u, $raw = false ) { |
|---|
| 71 | | $d0 = get_simple_rs( getQuery( "get_fuq_slot_recency", $u )); |
|---|
| 72 | | |
|---|
| 73 | | $now = getdate(); |
|---|
| 74 | | $d1 = $now['year'] ."-". ($now['mon'] < 10 ? "0" : "" ) . $now['mon'] ."-". ($now['mday'] < 10 ? "0" : "" ) . $now['mday'] ." ". $now['hours'] .":". $now['minutes'] .":". $now['seconds']; |
|---|
| 75 | | $value = round( diff_in_secs( $d1, $d0 ) / 60 / 60 / 24, 3 ); |
|---|
| | 86 | return mysql_result($q,0); |
|---|
| | 87 | } |
|---|
| | 88 | |
|---|
| | 89 | function get_fuq_threshold() { return 2; } |
|---|
| | 90 | |
|---|
| | 91 | function get_fuq( $u ) { |
|---|
| | 92 | $con = mysql_connect(); |
|---|
| | 93 | mysql_selectdb( getDBName() ); |
|---|
| | 94 | $qs = getQuery( "get_fuq", $u ); |
|---|
| | 95 | |
|---|
| | 96 | $q = mysql_query( $qs ); |
|---|
| | 97 | $num_rows = mysql_affected_rows($con); |
|---|
| | 98 | |
|---|
| | 99 | if( $num_rows == 1 ) |
|---|
| | 100 | return mysql_result($q, 0, "FUQ" ); |
|---|
| | 101 | else |
|---|
| | 102 | return 2; |
|---|
| | 103 | } |
|---|
| | 104 | |
|---|
| | 105 | function delta_time_between_links( $u, $raw = false ) { |
|---|
| | 106 | $value = get_db_date_diff_in_days( getQuery( "get_fuq_slot_delta_time_between_links", $u )) * 60; |
|---|
| | 107 | if( $raw ) |
|---|
| 77 | | } |
|---|
| 78 | | |
|---|
| 79 | | function length_of_usage( $u, $raw = false ) { |
|---|
| 80 | | $r0 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id DESC LIMIT 1;" ); |
|---|
| 81 | | $r1 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id ASC LIMIT 1;" ); |
|---|
| 82 | | $value = round( diff_in_secs( $r0, $r1 ) / 60 / 60 / 24, 1 ); |
|---|
| 83 | | return $value; |
|---|
| 84 | | } |
|---|
| 85 | | |
|---|
| 86 | | #loops through the fuq metrics, calculating each of them, and mashes them together to re-calculate a users FUQ |
|---|
| 87 | | function recalculate_fuq( $u ) { |
|---|
| 88 | | |
|---|
| 89 | | # calculate new fuq: |
|---|
| 90 | | $new_fuq = get_fuq( $u ); |
|---|
| 91 | | |
|---|
| 92 | | $slots = array( |
|---|
| 93 | | "delta_time_between_links" => 0, |
|---|
| 94 | | "length_of_usage" => 0 |
|---|
| 95 | | ); |
|---|
| 96 | | |
|---|
| 97 | | foreach( $slots as $key => $value ) { $slots[$key] = call_user_func( $key, $u ); } |
|---|
| 98 | | |
|---|
| 99 | | # mash together slot values here: |
|---|
| 100 | | # TBD |
|---|
| 101 | | |
|---|
| 102 | | #foreach( $slots as $slot ) { echo "\$slot = $slot<br>"; } |
|---|
| 103 | | |
|---|
| 104 | | return; |
|---|
| 105 | | |
|---|
| 106 | | # this method sig changed: run_query( getQuery( "update_fuq", $u, $new_fuq )); # and then set it |
|---|
| 107 | | # this will break now: return $new_fuq; |
|---|
| 108 | | } |
|---|
| 109 | | |
|---|
| 110 | | function run_query( $qs ) { |
|---|
| 111 | | $con = mysql_connect(); |
|---|
| 112 | | mysql_selectdb( getDBName() ); |
|---|
| 113 | | $q = mysql_query( $qs ); |
|---|
| 114 | | return $q; |
|---|
| 115 | | } |
|---|
| 116 | | |
|---|
| 117 | | function run_count( $qs ) { |
|---|
| 118 | | $con = mysql_connect(); |
|---|
| 119 | | mysql_selectdb( getDBName() ); |
|---|
| 120 | | $q = mysql_query( $qs ); |
|---|
| 121 | | |
|---|
| 122 | | if( $q ) |
|---|
| 123 | | return mysql_result($q,0); |
|---|
| | 109 | else |
|---|
| | 110 | if( $value < 0.5 ) |
|---|
| | 111 | return -1; |
|---|
| | 112 | else if( $value > 10 ) |
|---|
| | 113 | return 1; |
|---|
| 126 | | } |
|---|
| 127 | | |
|---|
| 128 | | # usr dirs are of the path /usr/u/username |
|---|
| 129 | | function get_user_folder( $u ) { |
|---|
| 130 | | if( !$u ) |
|---|
| 131 | | return "usr/NO_PROFILE/"; |
|---|
| | 116 | } |
|---|
| | 117 | |
|---|
| | 118 | function recency( $u, $raw = false ) { |
|---|
| | 119 | $d0 = get_simple_rs( getQuery( "get_fuq_slot_recency", $u )); |
|---|
| | 120 | |
|---|
| | 121 | $now = getdate(); |
|---|
| | 122 | $d1 = $now['year'] ."-". ($now['mon'] < 10 ? "0" : "" ) . $now['mon'] ."-". ($now['mday'] < 10 ? "0" : "" ) . $now['mday'] ." ". $now['hours'] .":". $now['minutes'] .":". $now['seconds']; |
|---|
| | 123 | $value = round( diff_in_secs( $d1, $d0 ) / 60 / 60 / 24, 3 ); |
|---|
| | 124 | return $value; |
|---|
| | 125 | } |
|---|
| | 126 | |
|---|
| | 127 | function length_of_usage( $u, $raw = false ) { |
|---|
| | 128 | $r0 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id DESC LIMIT 1;" ); |
|---|
| | 129 | $r1 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id ASC LIMIT 1;" ); |
|---|
| | 130 | $value = round( diff_in_secs( $r0, $r1 ) / 60 / 60 / 24, 1 ); |
|---|
| | 131 | return $value; |
|---|
| | 132 | } |
|---|
| | 133 | |
|---|
| | 134 | #loops through the fuq metrics, calculating each of them, and mashes them together to re-calculate a users FUQ |
|---|
| | 135 | function recalculate_fuq( $u ) { |
|---|
| | 136 | |
|---|
| | 137 | # calculate new fuq: |
|---|
| | 138 | $new_fuq = get_fuq( $u ); |
|---|
| | 139 | |
|---|
| | 140 | $slots = array( |
|---|
| | 141 | "delta_time_between_links" => 0, |
|---|
| | 142 | "length_of_usage" => 0 |
|---|
| | 143 | ); |
|---|
| | 144 | |
|---|
| | 145 | foreach( $slots as $key => $value ) { $slots[$key] = call_user_func( $key, $u ); } |
|---|
| | 146 | |
|---|
| | 147 | # mash together slot values here: |
|---|
| | 148 | # TBD |
|---|
| | 149 | |
|---|
| | 150 | #foreach( $slots as $slot ) { echo "\$slot = $slot<br>"; } |
|---|
| | 151 | |
|---|
| | 152 | return; |
|---|
| | 153 | |
|---|
| | 154 | # this method sig changed: run_query( getQuery( "update_fuq", $u, $new_fuq )); # and then set it |
|---|
| | 155 | # this will break now: return $new_fuq; |
|---|
| | 156 | } |
|---|
| | 157 | |
|---|
| | 158 | function run_query( $qs ) { |
|---|
| | 159 | $con = mysql_connect(); |
|---|
| | 160 | mysql_selectdb( getDBName() ); |
|---|
| | 161 | $q = mysql_query( $qs ); |
|---|
| | 162 | return $q; |
|---|
| | 163 | } |
|---|
| | 164 | |
|---|
| | 165 | function run_count( $qs ) { |
|---|
| | 166 | $con = mysql_connect(); |
|---|
| | 167 | mysql_selectdb( getDBName() ); |
|---|
| | 168 | $q = mysql_query( $qs ); |
|---|
| | 169 | |
|---|
| | 170 | if( $q ) |
|---|
| | 171 | return mysql_result($q,0); |
|---|
| | 172 | else |
|---|
| | 173 | return 0; |
|---|
| | 174 | } |
|---|
| | 175 | |
|---|
| | 176 | # usr dirs are of the path /usr/u/username |
|---|
| | 177 | function get_user_folder( $u ) { |
|---|
| | 178 | if( !$u ) |
|---|
| | 179 | return "usr/NO_PROFILE/"; |
|---|
| | 180 | else |
|---|
| | 181 | return "usr/" . substr( $u, 0, 1 ) . "/" . $u; |
|---|
| | 182 | } |
|---|
| | 183 | |
|---|
| | 184 | function ajax_edit( $u, $tok, $type, $subtype, $l, $new_value, $use_xajax = false ) { |
|---|
| | 185 | if( ! auth( $u, $tok ) ) |
|---|
| | 186 | return; |
|---|
| | 187 | $con = mysql_connect(); |
|---|
| | 188 | mysql_selectdb( getDBName() ); |
|---|
| | 189 | |
|---|
| | 190 | $new_value = o( $new_value ); |
|---|
| | 191 | if( $type == "checkbox" ) |
|---|
| | 192 | $new_value = ($new_value == 'false') ? "NULL" : 1; |
|---|
| | 193 | |
|---|
| | 194 | $qs = getQuery( "edit_$subtype", "$new_value", $l, $u ); |
|---|
| | 195 | |
|---|
| | 196 | if( $debug ) echo "DEBUG: $qs<br>"; |
|---|
| | 197 | $arg = "$u, $tok, $type, $subtype, $l, $new_value, $use_xajax"; |
|---|
| | 198 | |
|---|
| | 199 | $q = mysql_query( $qs ); |
|---|
| | 200 | $num_rows = mysql_affected_rows($con); |
|---|
| | 201 | $e = mysql_error($con); |
|---|
| | 202 | |
|---|
| | 203 | if( $debug ) echo "\$q: $q<br>"; |
|---|
| | 204 | if( $debug ) echo "\$num_rows: $num_rows<br>"; |
|---|
| | 205 | |
|---|
| | 206 | if( $num_rows > 0 || ! $e ) |
|---|
| | 207 | $success = "success"; |
|---|
| | 208 | |
|---|
| | 209 | $safe_value = preg_replace( "/'/", "\'", $new_value ); |
|---|
| | 210 | |
|---|
| | 211 | conClose( $con ); |
|---|
| | 212 | if( $use_xajax ) { |
|---|
| | 213 | $objResponse = new xajaxResponse(); |
|---|
| | 214 | if( $success ) |
|---|
| | 215 | $objResponse->addScript( "update_" . $type . "_after_save( '$safe_value' );" ); |
|---|
| 133 | | return "usr/" . substr( $u, 0, 1 ) . "/" . $u; |
|---|
| 134 | | } |
|---|
| 135 | | |
|---|
| 136 | | function ajax_edit( $u, $tok, $type, $subtype, $l, $new_value, $use_xajax = false ) { |
|---|
| 137 | | if( ! auth( $u, $tok ) ) |
|---|
| | 217 | $objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>$qs / $arg)</b>!!!" ); |
|---|
| | 218 | #$objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>Database $e (edit_$subtype / $qs / $arg)</b>!!!" ); |
|---|
| | 219 | // FIXME: in the above else case, also unroll the edit also so the user can try again |
|---|
| | 220 | return $objResponse->getXML(); |
|---|
| | 221 | } else |
|---|
| | 222 | return $success ? true : ""; |
|---|
| | 223 | } |
|---|
| | 224 | |
|---|
| | 225 | function add_tags_from_request( $u, $newLinkID, $catNums, $con ) { |
|---|
| | 226 | if( $debug ) echo "<hr>"; |
|---|
| | 227 | |
|---|
| | 228 | $newCatNames = Array(); |
|---|
| | 229 | |
|---|
| | 230 | foreach( $_POST as $paramName => $newCatName ) { |
|---|
| | 231 | if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { |
|---|
| | 232 | array_push( $newCatNames, $newCatName ); |
|---|
| | 233 | } |
|---|
| | 234 | } |
|---|
| | 235 | |
|---|
| | 236 | foreach( $_GET as $paramName => $newCatName ) { |
|---|
| | 237 | if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { |
|---|
| | 238 | array_push( $newCatNames, $newCatName ); |
|---|
| | 239 | } |
|---|
| | 240 | } |
|---|
| | 241 | |
|---|
| | 242 | if( $debug ) { |
|---|
| | 243 | echo "User entered " . count( $newCatNames ) . " 'new' tags: "; |
|---|
| | 244 | print_r( $newCatNames ); |
|---|
| | 245 | echo "<br>And " . count( $catNums ) . " existing tags: "; |
|---|
| | 246 | print_r( $catNums ); |
|---|
| | 247 | echo "<br>"; |
|---|
| | 248 | } |
|---|
| | 249 | |
|---|
| | 250 | if( count( $newCatNames )) { |
|---|
| | 251 | foreach( $newCatNames as $newCategoryName ) { |
|---|
| | 252 | if( $debug ) |
|---|
| | 253 | echo "First we add any tags that are actually new, then we tag the link w/all the remaining existing tags:<br />"; |
|---|
| | 254 | $categoryAlreadyExists = getIdForFolder( $newCategoryName, $u ); |
|---|
| | 255 | if( ! $categoryAlreadyExists ) { |
|---|
| | 256 | if( $debug ) |
|---|
| | 257 | echo "User $u correctly claims s/he has no " . getCatName() . " called '$newCategoryName' yet...<br />"; |
|---|
| | 258 | $newCatNum = addFolder( $newCategoryName, $u ); |
|---|
| | 259 | if( $debug ) |
|---|
| | 260 | echo "added $newCategoryName successfully as: \$newCatNum: $newCatNum<br />"; |
|---|
| | 261 | if( $newCatNum ) |
|---|
| | 262 | array_push( $catNums, $newCatNum ); |
|---|
| | 263 | } else |
|---|
| | 264 | # user actually already had this tag, so just push it onto the rest of the existing tags to tag this link with |
|---|
| | 265 | array_push( $catNums, $categoryAlreadyExists ); |
|---|
| | 266 | } |
|---|
| | 267 | } else { |
|---|
| | 268 | if( $debug ) |
|---|
| | 269 | echo "no new " . getCatsName() . " to be added, adding to existing " . getCatsName() . "...<br />"; |
|---|
| | 270 | } |
|---|
| | 271 | |
|---|
| | 272 | #starting sentinal value: |
|---|
| | 273 | $q = "bogus query"; |
|---|
| | 274 | |
|---|
| | 275 | if( $debug ) |
|---|
| | 276 | echo "<br />DEBUG: looping over " . (count($catNums)) . " tags"; |
|---|
| | 277 | foreach( $catNums as $catNum ) { |
|---|
| | 278 | if( ! $q || ! $catNum ) |
|---|
| 152 | | $num_rows = mysql_affected_rows($con); |
|---|
| 153 | | $e = mysql_error($con); |
|---|
| 154 | | |
|---|
| 155 | | if( $debug ) echo "\$q: $q<br>"; |
|---|
| 156 | | if( $debug ) echo "\$num_rows: $num_rows<br>"; |
|---|
| 157 | | |
|---|
| 158 | | if( $num_rows > 0 || ! $e ) |
|---|
| 159 | | $success = "success"; |
|---|
| 160 | | |
|---|
| 161 | | $safe_value = preg_replace( "/'/", "\'", $new_value ); |
|---|
| 162 | | |
|---|
| 163 | | conClose( $con ); |
|---|
| 164 | | if( $use_xajax ) { |
|---|
| 165 | | $objResponse = new xajaxResponse(); |
|---|
| 166 | | if( $success ) |
|---|
| 167 | | $objResponse->addScript( "update_" . $type . "_after_save( '$safe_value' );" ); |
|---|
| 168 | | else |
|---|
| 169 | | $objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>$qs / $arg)</b>!!!" ); |
|---|
| 170 | | #$objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>Database $e (edit_$subtype / $qs / $arg)</b>!!!" ); |
|---|
| 171 | | // FIXME: in the above else case, also unroll the edit also so the user can try again |
|---|
| 172 | | return $objResponse->getXML(); |
|---|
| 173 | | } else |
|---|
| 174 | | return $success ? true : ""; |
|---|
| 175 | | } |
|---|
| 176 | | |
|---|
| 177 | | function add_tags_from_request( $u, $newLinkID, $catNums, $con ) { |
|---|
| 178 | | if( $debug ) echo "<hr>"; |
|---|
| 179 | | |
|---|
| 180 | | $newCatNames = Array(); |
|---|
| 181 | | |
|---|
| 182 | | foreach( $_POST as $paramName => $newCatName ) { |
|---|
| 183 | | if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { |
|---|
| 184 | | array_push( $newCatNames, $newCatName ); |
|---|
| 185 | | } |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | foreach( $_GET as $paramName => $newCatName ) { |
|---|
| 189 | | if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { |
|---|
| 190 | | array_push( $newCatNames, $newCatName ); |
|---|
| 191 | | } |
|---|
| 192 | | } |
|---|
| 193 | | |
|---|
| 194 | | if( $debug ) { |
|---|
| 195 | | echo "User entered " . count( $newCatNames ) . " 'new' tags: "; |
|---|
| 196 | | print_r( $newCatNames ); |
|---|
| 197 | | echo "<br>And " . count( $catNums ) . " existing tags: "; |
|---|
| 198 | | print_r( $catNums ); |
|---|
| 199 | | echo "<br>"; |
|---|
| 200 | | } |
|---|
| 201 | | |
|---|
| 202 | | if( count( $newCatNames )) { |
|---|
| 203 | | foreach( $newCatNames as $newCategoryName ) { |
|---|
| 204 | | if( $debug ) |
|---|
| 205 | | echo "First we add any tags that are actually new, then we tag the link w/all the remaining existing tags:<br />"; |
|---|
| 206 | | $categoryAlreadyExists = getIdForFolder( $newCategoryName, $u ); |
|---|
| 207 | | if( ! $categoryAlreadyExists ) { |
|---|
| 208 | | if( $debug ) |
|---|
| 209 | | echo "User $u correctly claims s/he has no " . getCatName() . " called '$newCategoryName' yet...<br />"; |
|---|
| 210 | | $newCatNum = addFolder( $newCategoryName, $u ); |
|---|
| 211 | | if( $debug ) |
|---|
| 212 | | echo "added $newCategoryName successfully as: \$newCatNum: $newCatNum<br />"; |
|---|
| 213 | | if( $newCatNum ) |
|---|
| 214 | | array_push( $catNums, $newCatNum ); |
|---|
| 215 | | } else |
|---|
| 216 | | # user actually already had this tag, so just push it onto the rest of the existing tags to tag this link with |
|---|
| 217 | | array_push( $catNums, $categoryAlreadyExists ); |
|---|
| 218 | | } |
|---|
| 219 | | } else { |
|---|
| 220 | | if( $debug ) |
|---|
| 221 | | echo "no new " . getCatsName() . " to be added, adding to existing " . getCatsName() . "...<br />"; |
|---|
| 222 | | } |
|---|
| 223 | | |
|---|
| 224 | | #starting sentinal value: |
|---|
| 225 | | $q = "bogus query"; |
|---|
| 226 | | |
|---|
| 227 | | if( $debug ) |
|---|
| 228 | | echo "<br />DEBUG: looping over " . (count($catNums)) . " tags"; |
|---|
| 229 | | foreach( $catNums as $catNum ) { |
|---|
| 230 | | if( ! $q || ! $catNum ) |
|---|
| 231 | | return; |
|---|
| 232 | | if( $debug ) echo "<br />"; |
|---|
| 233 | | |
|---|
| 234 | | $qs = getQuery( "add_new_category_xref", $newLinkID, $catNum ); |
|---|
| 235 | | if( $debug ) |
|---|
| 236 | | echo "DEBUG: $qs"; |
|---|
| 237 | | $q = mysql_query( $qs ); |
|---|
| 238 | | if( ! $q ) { |
|---|
| 239 | | $e = mysql_error($con); |
|---|
| 240 | | $tok = get_mysql_dupe_error(); |
|---|
| 241 | | if( ! strstr( $e, $tok)) { |
|---|
| | 286 | if( ! $q ) { |
|---|
| | 287 | $e = mysql_error($con); |
|---|
| | 288 | $tok = get_mysql_dupe_error(); |
|---|
| | 289 | if( ! strstr( $e, $tok)) { |
|---|
| | 1875 | function get_user_image( $u, $thingy ) { |
|---|
| | 1876 | $exts = array( "gif", "jpg", "jpeg", "png" ); |
|---|
| | 1877 | foreach ($exts as $ext) { |
|---|
| | 1878 | $f = get_user_folder( $u ) . "/$thingy.$ext"; |
|---|
| | 1879 | if( is_file( get_root() . "/" . $f )) { |
|---|
| | 1880 | return $f; |
|---|
| | 1881 | } |
|---|
| | 1882 | } |
|---|
| | 1883 | } |
|---|
| | 1884 | |
|---|
| | 1885 | function get_thumbnail_image( $u ) { |
|---|
| | 1886 | if( ! is_file( get_user_image( $u, "thumb" )) && is_file( get_profile_image( $u ))) |
|---|
| | 1887 | make_thumbnail_for_user( $u ); |
|---|
| | 1888 | if( ! is_file( get_user_image( $u, "thumb" ))) |
|---|
| | 1889 | return "/usr/NO_PROFILE/thumb.png"; |
|---|
| | 1890 | else |
|---|
| | 1891 | return get_user_image( $u, "thumb" ); |
|---|
| | 1892 | } |
|---|
| | 1893 | |
|---|
| | 1894 | function get_profile_image( $u ) { |
|---|
| | 1895 | return get_user_image( $u, "profile" ); |
|---|
| | 1896 | } |
|---|
| | 1897 | |
|---|