| 77 | | if( is_privileged_importer( $user ) || isSuperUser( $user )) |
|---|
| 78 | | return "you cannot snuff a superuser."; |
|---|
| 79 | | |
|---|
| 80 | | # disable their login |
|---|
| 81 | | disable_user( $user ); |
|---|
| 82 | | |
|---|
| 83 | | # reset their password to garbage |
|---|
| 84 | | $snuff_pass = get_validation_code( $user . "-SNUFFED" ); |
|---|
| 85 | | $q = run_query( getQuery( "snuff_pass", $user, $snuff_pass )); |
|---|
| 86 | | |
|---|
| 87 | | # mark all their tags private |
|---|
| 88 | | $q = run_query( getQuery( "privatize_tags", $user )); |
|---|
| 89 | | |
|---|
| 90 | | # mark all their links private |
|---|
| 91 | | $q = run_query( getQuery( "privatize_links", $user )); |
|---|
| 92 | | |
|---|
| 93 | | # make their user directory un-readable |
|---|
| 94 | | $f = get_user_folder( $user ); |
|---|
| 95 | | if( is_dir( $f )) { |
|---|
| 96 | | shell_exec( "cp " . get_webserver_root() . "/admin/.htaccess $f/" ); |
|---|
| 97 | | } |
|---|
| 98 | | |
|---|
| 99 | | # mark them as snuffed |
|---|
| 100 | | $q = run_query( getQuery( "snuff_user", $user )); |
|---|
| 101 | | |
|---|
| 102 | | log_mesg_to( "snuffed out user $user", "global" ); |
|---|
| 103 | | echo get_snuffed_mesg(); |
|---|
| 104 | | %> |
|---|
| 105 | | |
|---|
| 106 | | <a href="/u/<%= $user %>">Done. Check your work</a>. |
|---|
| 107 | | |
|---|
| 108 | | <% |
|---|
| 109 | | return "success."; |
|---|
| | 77 | if( is_privileged_importer( $user ) || isSuperUser( $user )) |
|---|
| | 78 | return "you cannot snuff a superuser."; |
|---|
| | 79 | |
|---|
| | 80 | # disable their login |
|---|
| | 81 | disable_user( $user ); |
|---|
| | 82 | |
|---|
| | 83 | # reset their password to garbage |
|---|
| | 84 | $snuff_pass = get_validation_code( $user . "-SNUFFED" ); |
|---|
| | 85 | $q = run_query( getQuery( "snuff_pass", $user, $snuff_pass )); |
|---|
| | 86 | |
|---|
| | 87 | # mark all their tags private |
|---|
| | 88 | $q = run_query( getQuery( "privatize_tags", $user )); |
|---|
| | 89 | |
|---|
| | 90 | # mark all their links private |
|---|
| | 91 | $q = run_query( getQuery( "privatize_links", $user )); |
|---|
| | 92 | |
|---|
| | 93 | # make their user directory un-readable |
|---|
| | 94 | $f = get_user_folder( $user ); |
|---|
| | 95 | if( is_dir( $f )) { |
|---|
| | 96 | shell_exec( "cp " . get_webserver_root() . "/admin/.htaccess $f/" ); |
|---|
| | 97 | } |
|---|
| | 98 | |
|---|
| | 99 | # mark them as snuffed |
|---|
| | 100 | $q = run_query( getQuery( "snuff_user", $user )); |
|---|
| | 101 | |
|---|
| | 102 | log_mesg_to( "snuffed out user $user", "global" ); |
|---|
| | 103 | echo get_snuffed_mesg(); |
|---|
| | 104 | %> |
|---|
| | 105 | |
|---|
| | 106 | <a href="/u/<%= $user %>">Done. Check your work</a>. |
|---|
| | 107 | |
|---|
| | 108 | <% |
|---|
| | 109 | return "success."; |
|---|
| 190 | | $goal = 64; |
|---|
| 191 | | list($width, $height, $type, $attr) = getimagesize( $i ); |
|---|
| 192 | | |
|---|
| 193 | | #calculate which is the shorter side, re-map that to $goal, and calculate the new length of the longer side |
|---|
| 194 | | $tall = ( $width < $height ) ? true : false; |
|---|
| 195 | | $new_height = $new_width = $goal; |
|---|
| 196 | | if( $tall ) { |
|---|
| 197 | | $frac = $goal / $width; |
|---|
| 198 | | $new_height = $height * $frac; |
|---|
| 199 | | } else { |
|---|
| 200 | | $frac = $goal / $height; |
|---|
| 201 | | $new_width = $width * $frac; |
|---|
| 202 | | } |
|---|
| 203 | | |
|---|
| 204 | | switch( $type ){ |
|---|
| 205 | | case 1 : $orig = imagecreatefromgif($i); break; |
|---|
| 206 | | case 2 : $orig = imagecreatefromjpeg($i); break; |
|---|
| 207 | | case 3 : $orig = imagecreatefrompng($i); break; |
|---|
| 208 | | default: break; |
|---|
| 209 | | } |
|---|
| 210 | | |
|---|
| 211 | | # resize it: |
|---|
| 212 | | $small = imagecreatetruecolor( $new_width, $new_height ); |
|---|
| 213 | | imagecopyresampled( $small, $orig, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|---|
| 214 | | imagepng( $small, "icons/small.png" ); |
|---|
| 215 | | |
|---|
| 216 | | # new black-bordered palette to copy onto: |
|---|
| 217 | | $cropped = imagecreatetruecolor( $goal + 2, $goal + 2 ); |
|---|
| 218 | | imagefill( $cropped, 0, 0, imagecolorallocate( $cropped, 0, 0, 0 )); |
|---|
| 219 | | |
|---|
| 220 | | # crop image onto black |
|---|
| 221 | | imagecopy($cropped, $small, 1, 1, ceil( ($new_width - $goal) / 2), ceil( ($new_height - $goal) / 2), $goal, $goal); |
|---|
| 222 | | |
|---|
| 223 | | imagedestroy($small); |
|---|
| 224 | | imagedestroy($orig); |
|---|
| 225 | | return $cropped; |
|---|
| | 190 | $goal = 64; |
|---|
| | 191 | list($width, $height, $type, $attr) = getimagesize( $i ); |
|---|
| | 192 | |
|---|
| | 193 | #calculate which is the shorter side, re-map that to $goal, and calculate the new length of the longer side |
|---|
| | 194 | $tall = ( $width < $height ) ? true : false; |
|---|
| | 195 | $new_height = $new_width = $goal; |
|---|
| | 196 | if( $tall ) { |
|---|
| | 197 | $frac = $goal / $width; |
|---|
| | 198 | $new_height = $height * $frac; |
|---|
| | 199 | } else { |
|---|
| | 200 | $frac = $goal / $height; |
|---|
| | 201 | $new_width = $width * $frac; |
|---|
| | 202 | } |
|---|
| | 203 | |
|---|
| | 204 | switch( $type ){ |
|---|
| | 205 | case 1 : $orig = imagecreatefromgif($i); break; |
|---|
| | 206 | case 2 : $orig = imagecreatefromjpeg($i); break; |
|---|
| | 207 | case 3 : $orig = imagecreatefrompng($i); break; |
|---|
| | 208 | default: break; |
|---|
| | 209 | } |
|---|
| | 210 | |
|---|
| | 211 | # resize it: |
|---|
| | 212 | $small = imagecreatetruecolor( $new_width, $new_height ); |
|---|
| | 213 | imagecopyresampled( $small, $orig, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|---|
| | 214 | imagepng( $small, "icons/small.png" ); |
|---|
| | 215 | |
|---|
| | 216 | # new black-bordered palette to copy onto: |
|---|
| | 217 | $cropped = imagecreatetruecolor( $goal + 2, $goal + 2 ); |
|---|
| | 218 | imagefill( $cropped, 0, 0, imagecolorallocate( $cropped, 0, 0, 0 )); |
|---|
| | 219 | |
|---|
| | 220 | # crop image onto black |
|---|
| | 221 | imagecopy($cropped, $small, 1, 1, ceil( ($new_width - $goal) / 2), ceil( ($new_height - $goal) / 2), $goal, $goal); |
|---|
| | 222 | |
|---|
| | 223 | imagedestroy($small); |
|---|
| | 224 | imagedestroy($orig); |
|---|
| | 225 | return $cropped; |
|---|
| 363 | | if( ! auth( $u, $tok ) ) |
|---|
| 364 | | return; |
|---|
| 365 | | $con = mysql_connect(); |
|---|
| 366 | | mysql_selectdb( getDBName() ); |
|---|
| 367 | | |
|---|
| 368 | | $new_value = o( $new_value ); |
|---|
| 369 | | if( $type == "checkbox" ) |
|---|
| 370 | | $new_value = ($new_value == 'false') ? "NULL" : 1; |
|---|
| 371 | | |
|---|
| 372 | | $qs = getQuery( "edit_$subtype", "$new_value", $l, $u ); |
|---|
| 373 | | |
|---|
| 374 | | if( $debug ) echo "DEBUG: $qs<br>"; |
|---|
| 375 | | $arg = "$u, $tok, $type, $subtype, $l, $new_value, $use_xajax"; |
|---|
| 376 | | |
|---|
| 377 | | $q = mysql_query( $qs ); |
|---|
| 378 | | $num_rows = mysql_affected_rows($con); |
|---|
| 379 | | $e = mysql_error($con); |
|---|
| 380 | | |
|---|
| 381 | | if( $debug ) echo "\$q: $q<br>"; |
|---|
| 382 | | if( $debug ) echo "\$num_rows: $num_rows<br>"; |
|---|
| 383 | | |
|---|
| 384 | | if( $num_rows > 0 || ! $e ) |
|---|
| 385 | | $success = "success"; |
|---|
| 386 | | |
|---|
| 387 | | $safe_value = preg_replace( "/'/", "\'", $new_value ); |
|---|
| 388 | | |
|---|
| 389 | | conClose( $con ); |
|---|
| 390 | | if( $use_xajax ) { |
|---|
| 391 | | $objResponse = new xajaxResponse(); |
|---|
| 392 | | if( $success ) |
|---|
| 393 | | $objResponse->addScript( "update_" . $type . "_after_save( '$safe_value' );" ); |
|---|
| 394 | | else |
|---|
| 395 | | $objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>$qs / $arg)</b>!!!" ); |
|---|
| 396 | | #$objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>Database $e (edit_$subtype / $qs / $arg)</b>!!!" ); |
|---|
| 397 | | // FIXME: in the above else case, also unroll the edit also so the user can try again |
|---|
| 398 | | return $objResponse->getXML(); |
|---|
| 399 | | } else |
|---|
| 400 | | return $success ? true : ""; |
|---|
| | 363 | if( ! auth( $u, $tok ) ) |
|---|
| | 364 | return; |
|---|
| | 365 | $con = mysql_connect(); |
|---|
| | 366 | mysql_selectdb( getDBName() ); |
|---|
| | 367 | |
|---|
| | 368 | $new_value = o( $new_value ); |
|---|
| | 369 | if( $type == "checkbox" ) |
|---|
| | 370 | $new_value = ($new_value == 'false') ? "NULL" : 1; |
|---|
| | 371 | |
|---|
| | 372 | $qs = getQuery( "edit_$subtype", "$new_value", $l, $u ); |
|---|
| | 373 | |
|---|
| | 374 | if( $debug ) echo "DEBUG: $qs<br>"; |
|---|
| | 375 | $arg = "$u, $tok, $type, $subtype, $l, $new_value, $use_xajax"; |
|---|
| | 376 | |
|---|
| | 377 | $q = mysql_query( $qs ); |
|---|
| | 378 | $num_rows = mysql_affected_rows($con); |
|---|
| | 379 | $e = mysql_error($con); |
|---|
| | 380 | |
|---|
| | 381 | if( $debug ) echo "\$q: $q<br>"; |
|---|
| | 382 | if( $debug ) echo "\$num_rows: $num_rows<br>"; |
|---|
| | 383 | |
|---|
| | 384 | if( $num_rows > 0 || ! $e ) |
|---|
| | 385 | $success = "success"; |
|---|
| | 386 | |
|---|
| | 387 | $safe_value = preg_replace( "/'/", "\'", $new_value ); |
|---|
| | 388 | |
|---|
| | 389 | conClose( $con ); |
|---|
| | 390 | if( $use_xajax ) { |
|---|
| | 391 | $objResponse = new xajaxResponse(); |
|---|
| | 392 | if( $success ) |
|---|
| | 393 | $objResponse->addScript( "update_" . $type . "_after_save( '$safe_value' );" ); |
|---|
| | 394 | else |
|---|
| | 395 | $objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>$qs / $arg)</b>!!!" ); |
|---|
| | 396 | #$objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>Database $e (edit_$subtype / $qs / $arg)</b>!!!" ); |
|---|
| | 397 | // FIXME: in the above else case, also unroll the edit also so the user can try again |
|---|
| | 398 | return $objResponse->getXML(); |
|---|
| | 399 | } else |
|---|
| | 400 | return $success ? true : ""; |
|---|
| 404 | | if( $debug ) echo "<hr>"; |
|---|
| 405 | | |
|---|
| 406 | | $newCatNames = Array(); |
|---|
| 407 | | |
|---|
| 408 | | foreach( $_POST as $paramName => $newCatName ) { |
|---|
| 409 | | if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { |
|---|
| 410 | | array_push( $newCatNames, $newCatName ); |
|---|
| 411 | | } |
|---|
| 412 | | } |
|---|
| 413 | | |
|---|
| 414 | | foreach( $_GET as $paramName => $newCatName ) { |
|---|
| 415 | | if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { |
|---|
| 416 | | array_push( $newCatNames, $newCatName ); |
|---|
| 417 | | } |
|---|
| 418 | | } |
|---|
| 419 | | |
|---|
| 420 | | if( $debug ) { |
|---|
| 421 | | echo "User entered " . count( $newCatNames ) . " 'new' tags: "; |
|---|
| 422 | | print_r( $newCatNames ); |
|---|
| 423 | | echo "<br>And " . count( $catNums ) . " existing tags: "; |
|---|
| 424 | | print_r( $catNums ); |
|---|
| 425 | | echo "<br>"; |
|---|
| 426 | | } |
|---|
| 427 | | |
|---|
| 428 | | if( count( $newCatNames )) { |
|---|
| 429 | | foreach( $newCatNames as $newCategoryName ) { |
|---|
| 430 | | if( $debug ) |
|---|
| 431 | | echo "First we add any tags that are actually new, then we tag the link w/all the remaining existing tags:<br />"; |
|---|
| 432 | | $categoryAlreadyExists = getIdForFolder( $newCategoryName, $u ); |
|---|
| 433 | | if( ! $categoryAlreadyExists ) { |
|---|
| 434 | | if( $debug ) |
|---|
| 435 | | echo "User $u correctly claims s/he has no " . getCatName() . " called '$newCategoryName' yet...<br />"; |
|---|
| 436 | | $newCatNum = addFolder( $newCategoryName, $u ); |
|---|
| 437 | | if( $debug ) |
|---|
| 438 | | echo "added $newCategoryName successfully as: \$newCatNum: $newCatNum<br />"; |
|---|
| 439 | | if( $newCatNum ) |
|---|
| 440 | | array_push( $catNums, $newCatNum ); |
|---|
| 441 | | } else |
|---|
| 442 | | # user actually already had this tag, so just push it onto the rest of the existing tags to tag this link with |
|---|
| 443 | | array_push( $catNums, $categoryAlreadyExists ); |
|---|
| 444 | | } |
|---|
| 445 | | } else { |
|---|
| 446 | | if( $debug ) |
|---|
| 447 | | echo "no new " . getCatsName() . " to be added, adding to existing " . getCatsName() . "...<br />"; |
|---|
| 448 | | } |
|---|
| 449 | | |
|---|
| 450 | | #starting sentinal value: |
|---|
| 451 | | $q = "bogus query"; |
|---|
| 452 | | |
|---|
| 453 | | if( $debug ) |
|---|
| 454 | | echo "<br />DEBUG: looping over " . (count($catNums)) . " tags"; |
|---|
| 455 | | foreach( $catNums as $catNum ) { |
|---|
| 456 | | if( ! $q || ! $catNum ) |
|---|
| 457 | | return; |
|---|
| 458 | | if( $debug ) echo "<br />"; |
|---|
| 459 | | |
|---|
| 460 | | $qs = getQuery( "add_new_category_xref", $newLinkID, $catNum ); |
|---|
| 461 | | if( $debug ) |
|---|
| 462 | | echo "DEBUG: $qs"; |
|---|
| 463 | | $q = mysql_query( $qs ); |
|---|
| 464 | | if( ! $q ) { |
|---|
| 465 | | $e = mysql_error($con); |
|---|
| 466 | | $tok = get_mysql_dupe_error(); |
|---|
| 467 | | if( ! strstr( $e, $tok)) { |
|---|
| | 404 | if( $debug ) echo "<hr>"; |
|---|
| | 405 | |
|---|
| | 406 | $newCatNames = Array(); |
|---|
| | 407 | |
|---|
| | 408 | foreach( $_POST as $paramName => $newCatName ) { |
|---|
| | 409 | if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { |
|---|
| | 410 | array_push( $newCatNames, $newCatName ); |
|---|
| | 411 | } |
|---|
| | 412 | } |
|---|
| | 413 | |
|---|
| | 414 | foreach( $_GET as $paramName => $newCatName ) { |
|---|
| | 415 | if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { |
|---|
| | 416 | array_push( $newCatNames, $newCatName ); |
|---|
| | 417 | } |
|---|
| | 418 | } |
|---|
| | 419 | |
|---|
| | 420 | if( $debug ) { |
|---|
| | 421 | echo "User entered " . count( $newCatNames ) . " 'new' tags: "; |
|---|
| | 422 | print_r( $newCatNames ); |
|---|
| | 423 | echo "<br>And " . count( $catNums ) . " existing tags: "; |
|---|
| | 424 | print_r( $catNums ); |
|---|
| | 425 | echo "<br>"; |
|---|
| | 426 | } |
|---|
| | 427 | |
|---|
| | 428 | if( count( $newCatNames )) { |
|---|
| | 429 | foreach( $newCatNames as $newCategoryName ) { |
|---|
| | 430 | if( $debug ) |
|---|
| | 431 | echo "First we add any tags that are actually new, then we tag the link w/all the remaining existing tags:<br />"; |
|---|
| | 432 | $categoryAlreadyExists = getIdForFolder( $newCategoryName, $u ); |
|---|
| | 433 | if( ! $categoryAlreadyExists ) { |
|---|
| | 434 | if( $debug ) |
|---|
| | 435 | echo "User $u correctly claims s/he has no " . getCatName() . " called '$newCategoryName' yet...<br />"; |
|---|
| | 436 | $newCatNum = addFolder( $newCategoryName, $u ); |
|---|
| | 437 | if( $debug ) |
|---|
| | 438 | echo "added $newCategoryName successfully as: \$newCatNum: $newCatNum<br />"; |
|---|
| | 439 | if( $newCatNum ) |
|---|
| | 440 | array_push( $catNums, $newCatNum ); |
|---|
| | 441 | } else |
|---|
| | 442 | # user actually already had this tag, so just push it onto the rest of the existing tags to tag this link with |
|---|
| | 443 | array_push( $catNums, $categoryAlreadyExists ); |
|---|
| | 444 | } |
|---|
| | 445 | } else { |
|---|
| | 446 | if( $debug ) |
|---|
| | 447 | echo "no new " . getCatsName() . " to be added, adding to existing " . getCatsName() . "...<br />"; |
|---|
| | 448 | } |
|---|
| | 449 | |
|---|
| | 450 | #starting sentinal value: |
|---|
| | 451 | $q = "bogus query"; |
|---|
| | 452 | |
|---|
| | 453 | if( $debug ) |
|---|
| | 454 | echo "<br />DEBUG: looping over " . (count($catNums)) . " tags"; |
|---|
| | 455 | foreach( $catNums as $catNum ) { |
|---|
| | 456 | if( ! $q || ! $catNum ) |
|---|
| | 457 | return; |
|---|
| | 458 | if( $debug ) echo "<br />"; |
|---|
| | 459 | |
|---|
| | 460 | $qs = getQuery( "add_new_category_xref", $newLinkID, $catNum ); |
|---|
| | 461 | if( $debug ) |
|---|
| | 462 | echo "DEBUG: $qs"; |
|---|
| | 463 | $q = mysql_query( $qs ); |
|---|
| | 464 | if( ! $q ) { |
|---|
| | 465 | $e = mysql_error($con); |
|---|
| | 466 | $tok = get_mysql_dupe_error(); |
|---|
| | 467 | if( ! strstr( $e, $tok)) { |
|---|
| 487 | | return "Duplicate entry"; |
|---|
| 488 | | } |
|---|
| 489 | | |
|---|
| 490 | | function dumpParams() { |
|---|
| 491 | | %> |
|---|
| 492 | | <% |
|---|
| 493 | | foreach( $_GET as $pname => $pval ) { e( $pname . " = " . $pval ); } |
|---|
| 494 | | e( "" ); |
|---|
| 495 | | foreach( $_POST as $pname => $pval ) { e( $pname . " = " . $pval ); } |
|---|
| 496 | | %> |
|---|
| 497 | | <% |
|---|
| 498 | | } |
|---|
| 499 | | |
|---|
| 500 | | # search to see if the URL exists anywhere public |
|---|
| 501 | | function link_exists( $url ) { |
|---|
| 502 | | $qs = getQuery( "get_id_for_existing_link", $url ); |
|---|
| 503 | | $q = mysql_query( $qs ); |
|---|
| 504 | | if( $q && mysql_num_rows($q) ) |
|---|
| 505 | | return mysql_result( $q, 0, "id" ); |
|---|
| 506 | | } |
|---|
| 507 | | |
|---|
| 508 | | function users_link_exists( $u, $url ) { |
|---|
| 509 | | $url = urlencode( $url ); |
|---|
| 510 | | $con_users_link_exists = mysql_connect(); |
|---|
| 511 | | mysql_selectdb( getDBName() ); |
|---|
| 512 | | $qs = "SELECT COUNT(id) as count FROM links WHERE url = '$url' AND submitter = '$u';"; |
|---|
| 513 | | $q = mysql_query( $qs ); |
|---|
| 514 | | if( $q ) |
|---|
| 515 | | $count = mysql_result($q, 0, "count" ); |
|---|
| 516 | | conClose( $con_users_link_exists ); |
|---|
| 517 | | return $count; |
|---|
| 518 | | } |
|---|
| 519 | | |
|---|
| 520 | | function users_tag_exists( $u, $tag ) { |
|---|
| 521 | | $tag = urlencode( $tag ); |
|---|
| 522 | | $con_users_tag_exists = mysql_connect(); |
|---|
| 523 | | mysql_selectdb( getDBName() ); |
|---|
| 524 | | $qs = "SELECT COUNT(id) as count FROM linksgroups WHERE name = '$tag' AND userid = '$u';"; |
|---|
| 525 | | $q = mysql_query( $qs ); |
|---|
| 526 | | if( $q ) |
|---|
| 527 | | $count = mysql_result($q, 0, "count" ); |
|---|
| 528 | | conClose( $con_users_tag_exists ); |
|---|
| 529 | | return $count; |
|---|
| 530 | | } |
|---|
| 531 | | |
|---|
| 532 | | # can this user import more than max_links? |
|---|
| 533 | | function is_privileged_importer( $userId ) { |
|---|
| 534 | | $pi = Array(); |
|---|
| 535 | | |
|---|
| 536 | | $pi["jm3"] = true; |
|---|
| 537 | | $pi["pheezy"] = true; |
|---|
| 538 | | $pi["gus"] = true; |
|---|
| 539 | | $pi["dcnstctr"] = true; |
|---|
| 540 | | $pi["formalplay"] = true; |
|---|
| 541 | | $pi["testuser"] = true; |
|---|
| 542 | | $pi["samanthers"] = true; |
|---|
| 543 | | |
|---|
| 544 | | #$pi["rrhobbs"] = true; |
|---|
| 545 | | #$pi["Madrisa"] = true; |
|---|
| 546 | | #$pi["stutes"] = true; |
|---|
| 547 | | #$pi["gagliaudo"] = true; |
|---|
| 548 | | #$pi["auslander"] = true; |
|---|
| 549 | | |
|---|
| 550 | | return $pi[ $userId ]; |
|---|
| 551 | | } |
|---|
| 552 | | |
|---|
| 553 | | class Config { |
|---|
| 554 | | function get_import_links_cache_file_name() { return "LINKS.RAW"; } |
|---|
| 555 | | function get_deduped_links_cache_file_name() { return "LINKS.READY"; } |
|---|
| 556 | | function get_import_tags_cache_file_name() { return "TAGS.RAW"; } |
|---|
| 557 | | function get_deduped_tags_cache_file_name() { return "TAGS.READY"; } |
|---|
| 558 | | function get_delimeter() { return "___DELIMETER___"; } |
|---|
| 559 | | function get_import_tag_name() { return "imported links"; } |
|---|
| 560 | | } |
|---|
| 561 | | $config = new Config; |
|---|
| 562 | | |
|---|
| 563 | | function make_user_dir( $u ) { |
|---|
| 564 | | chdir( get_root() ); |
|---|
| 565 | | $u_dir = get_user_folder( $u ? $u : get_user() ); |
|---|
| 566 | | if( ! is_dir( $u_dir )) { |
|---|
| 567 | | $old_umask = umask(0); |
|---|
| 568 | | mkdir( $u_dir ); |
|---|
| 569 | | umask($old_umask); |
|---|
| 570 | | } |
|---|
| 571 | | if( !is_dir( $u_dir )) |
|---|
| 572 | | fatal( "Your user folder could not be created." ); |
|---|
| 573 | | else if( ! is_writable( $u_dir )) |
|---|
| 574 | | fatal( "Your folder was not writable." ); |
|---|
| 575 | | else |
|---|
| 576 | | return $u_dir; |
|---|
| 577 | | } |
|---|
| 578 | | |
|---|
| 579 | | function open_user_file_for_write( $f, $u ) { |
|---|
| 580 | | $u_dir = make_user_dir( $u ); |
|---|
| 581 | | if( ! is_writable( $u_dir )) |
|---|
| 582 | | fatal( "Your folder was not writable." ); |
|---|
| 583 | | else { |
|---|
| 584 | | $f = $u_dir . "/" . escapeshellcmd( $f ); |
|---|
| 585 | | if( is_file( $f )) |
|---|
| 586 | | l( "warning: opening existing user $u's file $f for write and erasing it" ); |
|---|
| 587 | | return fopen( $f, "w" ); |
|---|
| 588 | | } |
|---|
| 589 | | } |
|---|
| 590 | | |
|---|
| 591 | | # NOTE THAT THE RETURN SEMANTICS OF _for_read ARE VERY DIFFERENT THAN _for_write; WE RETURN AN ARRAY, NOT A FILE_POINTER!! |
|---|
| 592 | | function open_user_file_for_read( $f ) { |
|---|
| 593 | | chdir( get_root() ); |
|---|
| 594 | | $u_dir = get_user_folder( get_user() ); |
|---|
| 595 | | $f = $u_dir . "/" . escapeshellcmd( $f ); |
|---|
| 596 | | if( ! is_dir( $u_dir )) |
|---|
| 597 | | fatal( "Your user folder could not be found." ); |
|---|
| 598 | | else if( !is_file( $f )) |
|---|
| 599 | | l( "the file $f could not be found." ); |
|---|
| 600 | | else |
|---|
| 601 | | return file( $f ); |
|---|
| 602 | | } |
|---|
| 603 | | |
|---|
| 604 | | function get_bookmarks_info( $u ) { |
|---|
| 605 | | $b = Array(); |
|---|
| 606 | | $b["file_name"] = "/imported-favorites.html"; |
|---|
| 607 | | $b["field_name"] = "bookmarks_file"; |
|---|
| 608 | | $b["dir"] = get_root() . "/" . get_user_folder( $u ); |
|---|
| 609 | | $b["path"] = $b["dir"] . $b["file_name"]; |
|---|
| 610 | | |
|---|
| 611 | | return $b; |
|---|
| 612 | | } |
|---|
| 613 | | |
|---|
| 614 | | function e( $m ) { |
|---|
| 615 | | echo "$m<br>\n"; |
|---|
| 616 | | } |
|---|
| 617 | | |
|---|
| 618 | | function croak( $m ) { |
|---|
| 619 | | ob_clean(); |
|---|
| 620 | | exit( $m ); |
|---|
| 621 | | } |
|---|
| 622 | | |
|---|
| 623 | | function l( $m ) { |
|---|
| 624 | | trigger_error( $m ); |
|---|
| 625 | | } |
|---|
| 626 | | |
|---|
| 627 | | function comment( $m ) { |
|---|
| 628 | | echo "\n<!-- $m -->\n"; |
|---|
| 629 | | } |
|---|
| 630 | | |
|---|
| 631 | | function fatal( $m ) { |
|---|
| 632 | | l( "FATAL ERROR.", $m ); |
|---|
| 633 | | return tell( "Darn! ", $m ); |
|---|
| 634 | | } |
|---|
| 635 | | |
|---|
| 636 | | function warn( $m ) { |
|---|
| 637 | | return tell( "Warning.", $m ); |
|---|
| 638 | | } |
|---|
| 639 | | |
|---|
| 640 | | function shout( $t, $m ) { |
|---|
| 641 | | tell( $t, $m, $wide = true ); |
|---|
| 642 | | } |
|---|
| 643 | | |
|---|
| 644 | | |
|---|
| 645 | | function startTell( $t = "", $wide = false ) { |
|---|
| | 487 | return "Duplicate entry"; |
|---|
| | 488 | } |
|---|
| | 489 | |
|---|
| | 490 | function dumpParams() { |
|---|
| | 491 | %> |
|---|
| | 492 | <% |
|---|
| | 493 | foreach( $_GET as $pname => $pval ) { e( $pname . " = " . $pval ); } |
|---|
| | 494 | e( "" ); |
|---|
| | 495 | foreach( $_POST as $pname => $pval ) { e( $pname . " = " . $pval ); } |
|---|
| | 496 | %> |
|---|
| | 497 | <% |
|---|
| | 498 | } |
|---|
| | 499 | |
|---|
| | 500 | # search to see if the URL exists anywhere public |
|---|
| | 501 | function link_exists( $url ) { |
|---|
| | 502 | $qs = getQuery( "get_id_for_existing_link", $url ); |
|---|
| | 503 | $q = mysql_query( $qs ); |
|---|
| | 504 | if( $q && mysql_num_rows($q) ) |
|---|
| | 505 | return mysql_result( $q, 0, "id" ); |
|---|
| | 506 | } |
|---|
| | 507 | |
|---|
| | 508 | function users_link_exists( $u, $url ) { |
|---|
| | 509 | $url = urlencode( $url ); |
|---|
| | 510 | $con_users_link_exists = mysql_connect(); |
|---|
| | 511 | mysql_selectdb( getDBName() ); |
|---|
| | 512 | $qs = "SELECT COUNT(id) as count FROM links WHERE url = '$url' AND submitter = '$u';"; |
|---|
| | 513 | $q = mysql_query( $qs ); |
|---|
| | 514 | if( $q ) |
|---|
| | 515 | $count = mysql_result($q, 0, "count" ); |
|---|
| | 516 | conClose( $con_users_link_exists ); |
|---|
| | 517 | return $count; |
|---|
| | 518 | } |
|---|
| | 519 | |
|---|
| | 520 | function users_tag_exists( $u, $tag ) { |
|---|
| | 521 | $tag = urlencode( $tag ); |
|---|
| | 522 | $con_users_tag_exists = mysql_connect(); |
|---|
| | 523 | mysql_selectdb( getDBName() ); |
|---|
| | 524 | $qs = "SELECT COUNT(id) as count FROM linksgroups WHERE name = '$tag' AND userid = '$u';"; |
|---|
| | 525 | $q = mysql_query( $qs ); |
|---|
| | 526 | if( $q ) |
|---|
| | 527 | $count = mysql_result($q, 0, "count" ); |
|---|
| | 528 | conClose( $con_users_tag_exists ); |
|---|
| | 529 | return $count; |
|---|
| | 530 | } |
|---|
| | 531 | |
|---|
| | 532 | # can this user import more than max_links? |
|---|
| | 533 | function is_privileged_importer( $userId ) { |
|---|
| | 534 | $pi = Array(); |
|---|
| | 535 | |
|---|
| | 536 | $pi["jm3"] = true; |
|---|
| | 537 | $pi["pheezy"] = true; |
|---|
| | 538 | $pi["gus"] = true; |
|---|
| | 539 | $pi["dcnstctr"] = true; |
|---|
| | 540 | $pi["formalplay"] = true; |
|---|
| | 541 | $pi["testuser"] = true; |
|---|
| | 542 | $pi["samanthers"] = true; |
|---|
| | 543 | |
|---|
| | 544 | #$pi["rrhobbs"] = true; |
|---|
| | 545 | #$pi["Madrisa"] = true; |
|---|
| | 546 | #$pi["stutes"] = true; |
|---|
| | 547 | #$pi["gagliaudo"] = true; |
|---|
| | 548 | #$pi["auslander"] = true; |
|---|
| | 549 | |
|---|
| | 550 | return $pi[ $userId ]; |
|---|
| | 551 | } |
|---|
| | 552 | |
|---|
| | 553 | class Config { |
|---|
| | 554 | function get_import_links_cache_file_name() { return "LINKS.RAW"; } |
|---|
| | 555 | function get_deduped_links_cache_file_name() { return "LINKS.READY"; } |
|---|
| | 556 | function get_import_tags_cache_file_name() { return "TAGS.RAW"; } |
|---|
| | 557 | function get_deduped_tags_cache_file_name() { return "TAGS.READY"; } |
|---|
| | 558 | function get_delimeter() { return "___DELIMETER___"; } |
|---|
| | 559 | function get_import_tag_name() { return "imported links"; } |
|---|
| | 560 | } |
|---|
| | 561 | $config = new Config; |
|---|
| | 562 | |
|---|
| | 563 | function make_user_dir( $u ) { |
|---|
| | 564 | chdir( get_root() ); |
|---|
| | 565 | $u_dir = get_user_folder( $u ? $u : get_user() ); |
|---|
| | 566 | if( ! is_dir( $u_dir )) { |
|---|
| | 567 | $old_umask = umask(0); |
|---|
| | 568 | mkdir( $u_dir ); |
|---|
| | 569 | umask($old_umask); |
|---|
| | 570 | } |
|---|
| | 571 | if( !is_dir( $u_dir )) |
|---|
| | 572 | fatal( "Your user folder could not be created." ); |
|---|
| | 573 | else if( ! is_writable( $u_dir )) |
|---|
| | 574 | fatal( "Your folder was not writable." ); |
|---|
| | 575 | else |
|---|
| | 576 | return $u_dir; |
|---|
| | 577 | } |
|---|
| | 578 | |
|---|