Changeset 1375
- Timestamp:
- 03/04/07 02:59:37 (1 year ago)
- Files:
-
- feedmelinks/.htaccess-global (modified) (1 diff)
- feedmelinks/404.php (modified) (2 diffs)
- feedmelinks/FAQ/index.php (modified) (3 diffs)
- feedmelinks/bin/hybrid-to-xml.pl (modified) (1 diff)
- feedmelinks/bin/import-bookmarks.pl (modified) (4 diffs)
- feedmelinks/import/complete.php (modified) (2 diffs)
- feedmelinks/import/present-clean-pre-flight-input.inc.php (modified) (4 diffs)
- feedmelinks/import/processing.php (modified) (5 diffs)
- feedmelinks/import/ready-to-import.php (modified) (2 diffs)
- feedmelinks/modules/utils.inc.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
feedmelinks/.htaccess-global
r1360 r1375 53 53 RewriteRule ^xml/peeps$ /peeps-as-xml [L] 54 54 RewriteRule ^api/backroom/(.*)$ /api/restricted/secure-call.php?call=$1 [L] 55 56 RewriteRule ^api/rename/(.*)$ /api/core/index.php?op=rename&user=$1 [L] 57 RewriteRule ^api/add_tags/(.*)$ /api/core/index.php?op=add_tags&user=$1 [L] 55 58 56 59 # JSON API feedmelinks/404.php
r770 r1375 4 4 5 5 include( "$modules/header.insecure.inc.php" ); 6 log_mesg_to( "[missing page] $page", "global" ); 7 6 8 %> 7 9 … … 11 13 </h1> 12 14 --> 15 <!-- <img src="/img/tiny-heaton-404.gif"/> --> 13 16 14 17 <center> 15 <img src="/img/tiny-heaton-404.gif"/> 18 <h1> 19 Whoops - we screwed up! 20 </h1> 21 <h2> 22 <u><code><?= $page ?></code></u> was not found. 23 </h2> 24 <h2> 25 <a href="/">Click to go back to the homepage</a> 26 </h2> 27 28 <p/> 29 30 <small>(The admins have been notified of this error)</small> 16 31 </center> 17 32 18 19 20 <%= bounceWithDelay( $site, 4 ) %> 33 <%= #bounceWithDelay( $site, 4 ) %> feedmelinks/FAQ/index.php
r1369 r1375 406 406 (pass <code>user</code> and <code>password</code>) 407 407 <br /> 408 <br /> 408 409 409 410 # <b>get all your links as XML</b>:<br /> … … 413 414 # <b>get all your tags as XML</b>:<br /> 414 415 <span class="subtle">http://feedmelinks.com</span>/xml/tags<br /> 416 <br /> 417 418 # <b>rename a link</b>:<br /> 419 <span class="subtle">http://feedmelinks.com</span>/api/rename/USERNAME&id=LINK_ID&name=NAME<br /> 420 <br /> 421 422 # <b>add tags to a link</b>:<br /> 423 <span class="subtle">http://feedmelinks.com</span>/api/add_tags/USERNAME&id=LINK_ID&tags=COMMA,SEPARATED,TAGS<br /> 415 424 <br /> 416 425 … … 431 440 --> 432 441 433 # <b> how to get a list ofyour peeps as XML</b>:<br />442 # <b>get your peeps as XML</b>:<br /> 434 443 <span class="subtle">http://feedmelinks.com</span>/xml/peeps<br /> 435 444 </code> feedmelinks/bin/hybrid-to-xml.pl
r1371 r1375 7 7 "; 8 8 9 #format is DT link info, then DD link comment 10 11 12 $comment_delim = "__FML_COMMENT__"; 13 9 14 $header = 1; 15 16 $last_link = ""; 10 17 while( <> ) { 11 18 if( $header ) { next unless ( /<DL>/ ); } 19 $line = $_; 12 20 $header = 0; 13 next unless ( /<DT>/ ); 14 chomp(); 15 s/^<DT>//; 16 s/ LAST_VISIT="\d+" //; 17 s/ADD_DATE="\d+"//; 18 s/<A/ <post/; 19 s/A>/post>/; 20 s/HREF="/href="/; 21 s/TAGS="/tag="/; 22 $name = m/>([^<]+)</; 23 $name = $1; 24 $clean_modulo_tags = $_; 25 $clean_modulo_tags =~ s/tag="[^"]+"/tag=""/; 26 $tags = $_; 27 $tags =~ s/tag="([^"]+)"/$1/; 28 $tags = $1; 29 $tags =~ s/,/ /g; 30 $clean_modulo_tags =~ s/tag=""/tag="$tags"/; 31 $clean_modulo_tags =~ s/" /" description="$name" /; 32 print "$clean_modulo_tags\n"; 21 next unless ( $line =~ /<(DT|DD)>/ ); 22 chomp( $line ); 23 24 # link info comes first... 25 if( $line =~ /<DT>/ ) { 26 $line =~ s/^<DT>//; 27 $line =~ s/ LAST_VISIT="\d+" //; 28 $line =~ s/ADD_DATE="\d+"//; 29 $line =~ s/<A/ <post/; 30 $line =~ s/A>/post>/; 31 $line =~ s/HREF="/href="/; 32 $line =~ s/TAGS="/tag="/; 33 $line =~ s/>([^<]+)<.*$/\/>/; 34 35 $name = $1; 36 $name = escape_string( $name ); 37 38 # PLACEHOLDER TO REPLACE WITH REAL COMMENT IN NEXT BLOCK 39 $name .= $comment_delim; 40 41 $clean_modulo_tags = $line; 42 $clean_modulo_tags =~ s/tag="[^"]+"/tag=""/; 43 $tags = $line; 44 $tags =~ s/tag="([^"]+)"/$1/; 45 $tags = $1; 46 $tags =~ s/,/ /g; 47 $clean_modulo_tags =~ s/tag=""/tag="$tags"/; 48 $clean_modulo_tags =~ s/" /" description="$name" /; 49 50 $href = $clean_modulo_tags; 51 $clean_modulo_tags =~ s/href="([^"]+)"//; #delete the old href="..." 52 $href = make_safe_url( $1 ); # clean it 53 $clean_modulo_tags =~ s/description="/href="$href" description="/; #stuff it back in 54 $last_link = $clean_modulo_tags; 55 56 # link COMMENTS come next: 57 } else { 58 $comment = $line; 59 $comment =~ s/^<DD>//; 60 $comment = escape_string( $comment ); 61 $last_link =~ s/$comment_delim/$comment_delim$comment/; 62 print "$last_link\n"; 63 } 33 64 } 34 65 35 66 print "\n</posts>\n"; 67 68 # for name and comments -- NOT url encoding 69 sub escape_string { 70 my $s = $_[0]; 71 #print "name is now $s\n"; 72 $s =~ s/&([^a][^m][^p][^;])/&$1/g; 73 $s =~ s/&([^a])/&$1/g; 74 $s =~ s/"/"/g; 75 76 # escape all but these chars: 77 $s =~ s/([^,\]\[\)\(%A-Za-z! \/\\|0-9'&;:._\?=-])/sprintf("%%%02X", ord($1))/seg; 78 79 $s =~ s/%C2%AB/»/g; 80 return $s; 81 } 82 83 sub make_safe_url { 84 my $url = $_[0]; 85 my @bits = split /\?/, $url; 86 if( scalar( @bits ) == 2 ) { 87 $bits[1] =~ s/([^A-Za-z0-9\?=])/sprintf("%%%02X", ord($1))/seg; 88 return $bits[0] . $bits[1]; 89 } else { 90 return $url; 91 } 92 } feedmelinks/bin/import-bookmarks.pl
r1373 r1375 1 #!/usr/bin/perl 1 #!/usr/local/bin/perl 2 use lib "/home/fml/public_html/lib"; 2 3 use FeedMeLinks::Environment; 3 4 use File::Temp qw/ :mktemp /; 4 5 5 6 6 $glc = 0; … … 23 23 $tag_xslt = $ARGV[3]; 24 24 $path =~ s:\/([^/]+)$::; #strip filename 25 $bin = FeedMeLinks::Environment::get_webserver_root() . "/bin"; 26 27 ($fh, $converted) = mkstemp( "bookmark_conversion_XXXX" ); 25 $bin ="/home/fml/public_html/bin"; 26 27 $success_code = ""; 28 29 $converted = "/tmp/import-" . int(rand(1000)); 28 30 # one of: delicious-hybrid, netscape, delicious-API 29 31 $format = detect_bookmarks_format( $bin, $filename ); 30 32 if( $format == "delicious-hybrid" ) { 33 print "converting from hybrid format:\n"; 31 34 $cmd = "$bin/hybrid-to-xml.pl $filename > $converted"; 32 #print "cmd: $cmd\n"; 33 $out =`$cmd`; 34 #print "converted is $converted\n out is : $out\n"; 35 print "cmd: $cmd\n"; 36 `$cmd`; 35 37 $filename = $converted; 38 #print "new converted xml output is in $filename\n"; 39 $out = `cat $filename`; 40 print "$filename contains: \n$out\n\n"; 41 $success_code = "converted from hybrid to stock xml"; 36 42 } 37 43 … … 39 45 $line = $_; 40 46 41 if( $line =~ m/^<\?xml version='1.0'/ ) { 47 # EITHER THE FUCKING PERL REGEX SYNTAX CHANGED OR RP HAS A BROKEN PERL 48 if( $line =~ m/xml version/ ) { 49 #<?xml version='1.0' standalone='yes'?> 42 50 43 51 $cmd = "xsltproc $link_xslt $filename > $path/LINKS.RAW\n"; 44 #print "$cmd\n";52 print "$cmd\n"; 45 53 $out = `$cmd`; 46 #print "cmd output was: $out\n";54 print "cmd output was: $out\n"; 47 55 48 56 $cmd = "xsltproc $tag_xslt $filename | sort | uniq | grep -v '^\$' > $path/TAGS.RAW\n"; 49 #print "$cmd\n";57 print "cmd: $cmd\n"; 50 58 $out = `$cmd`; 51 #print "cmd output was: $out\n"; 52 53 print qq(<result delimeter="$dd">SUCCESS</result>\n); 59 print "cmd output: $out\n"; 60 61 # FIXME: 62 print "leaving the xml loop thing\n"; 63 print qq(<result delimeter="$dd" note="$success_code">SUCCESS</result>\n); 54 64 exit 0; 55 65 … … 145 155 foreach( @tags ) { print TAGS "$_\n"; } 146 156 close( TAGS ); 147 print qq(<result delimeter="$dd" >SUCCESS</result>\n);157 print qq(<result delimeter="$dd" note="$success_code">SUCCESS</result>\n); 148 158 } 149 159 feedmelinks/import/complete.php
r1168 r1375 37 37 shout( "Importing Complete!", 38 38 "Your links were quite tasty! We imported your links and created tags from each of your folders." 39 . ($num_issues ? " There were $num_issues issues)." : "")39 . ($num_issues ? "<small>(There were $num_issues issues).</small>" : "") 40 40 ); 41 41 %> … … 45 45 <h1> 46 46 Now either:<br /> 47 <a href='/ f/<%= $imported_folder_ID %>'>Explore your new links</a>,47 <a href='/'>Explore your new links</a>, 48 48 </h1> 49 49 or feedmelinks/import/present-clean-pre-flight-input.inc.php
r1336 r1375 15 15 16 16 %> 17 <div id="newLinks" class="box">17 <div> 18 18 <div class="subhead"> 19 19 new tags to be created: 20 20 </div> 21 <div >22 < %21 <div style="border: 1px solid #cdcdcd; padding: 2.0em; margin: 0.2em; font-size: 16px;"> 22 <?php 23 23 for( $i = 0; $i < $ts; $i++ ) { 24 24 $line = rtrim( $tags[$i] ); … … 27 27 if( substr( $line, 0, 2 ) == "X " ) { 28 28 $tag = preg_replace( "/^X /", "", $line ); 29 echo row_wrap( " <span class='subtle'>Ignoring duplicate tag $tag</span>", ($i % 2 == 0) ? 1 : 0 ) . "\n";29 echo "<span class='subtle'>Ignoring duplicate tag $tag</span>" . ",\n"; 30 30 } else { 31 31 ++$num_tags; 32 echo row_wrap( " <span class='hot'>Create tag: $line</span>", ($i % 2 == 0) ? 1 : 0 ) . "\n";32 echo "<span class='hot'>$line</span>, \n"; 33 33 } 34 echo "</div>\n";35 34 } 36 %>35 ?> 37 36 </div> 38 37 </div> … … 40 39 <div id="newLinks" class="box"> 41 40 <div class="subhead"> 42 new favorites to be imported:41 new links to be imported: 43 42 </div> 44 < %43 <?php 45 44 for( $i = 0; $i < $ls; $i++ ) { 46 45 $line = rtrim( $links[$i] ); 47 46 $l = preg_split( "/$delimeter/", $line ); 47 $delimeter = "___DELIMETER___"; # FIXME: this is supposed to be pased in as one ofthe args in the XML but its not 48 48 $url = $l[0]; 49 49 $name = $l[1]; 50 50 $max_length = 65; 51 if( $debug ) 52 print_r ( $l ); 51 53 if( ! $line ) 52 54 continue; … … 57 59 ++$num_links; 58 60 $url = getCompactString( $url, $max_length ); 59 echo row_wrap( " <span class='hot'><a target='external' href='$url'>$url</a></span>", ($i % 2 == 0) ? 1 : 0 ); 61 $pieces = get_imported_link_and_comment( $name ); 62 $name = $pieces[0]; 63 $comment = $pieces[1]; 64 echo row_wrap( " <span class='hot'><a target='external' href='$url'>$name</a></span><br>$comment", ($i % 2 == 0) ? 1 : 0 ); 60 65 } 61 66 echo "</div>\n"; 62 67 } 63 %>68 ?> 64 69 </div> 65 70 </div> feedmelinks/import/processing.php
r1336 r1375 35 35 # A. the links 36 36 ############################################## 37 38 37 for( $i = 0; $i < sizeof( $links ); $i++ ) { 39 38 $line = rtrim( $links[$i] ); 40 39 if( substr( $line, 0, 2 ) != "X " ) { # skip dupes 41 40 42 #e( "$i ::" );43 41 $l = preg_split( "/$delimeter/", $line ); 44 42 $taglist = array_slice( $l, 2, sizeof( $l )); 45 $inserted_id = addLinkSimple( $l[0], $l[1], $user, 1 ); 46 if( !$inserted_id ) 47 ++$db_errors; 43 if( $l[0] && $l[1] ) { 44 45 $url = $l[0]; 46 $name = $l[1]; 47 48 $x = get_imported_link_and_comment( $name ); 49 $name = $x[0]; 50 $comment = $x[1]; 51 52 $inserted_id = addLinkSimple( $url, $name, $user, 1 ); 53 54 if( !$inserted_id ) { 55 ++$db_errors; 56 } else { 57 if ( $comment ) { 58 addCommentToLink( $inserted_id, $comment, $user ); 59 } 60 } 48 61 49 62 # B. the tag / link associations 50 63 ############################################## 51 $current_link_ID = mysql_insert_id();64 $current_link_ID = $inserted_id; 52 65 for( $j = 0; $j < sizeof( $taglist ); $j++ ) { 53 $tag = urlencode( rtrim( $taglist[$j] ) ); 54 # e( "ON tag $tag" ); 66 $tag = rtrim( $taglist[$j] ); 55 67 56 68 # C. the tags … … 75 87 76 88 # Finally, with no recourse left to us, we insert the new tag in the db 89 if( $debug ) 90 echo "attempting to add tag '$tag'<br>"; 77 91 if( $run_query ) { 78 92 $qs = getQuery( "add_tag", $user, $tag ); 79 93 $q = mysql_query( $qs ); 94 if( $debug ) 95 echo "$qs<br>"; 80 96 if( !$q ) { 81 97 ++$db_errors; 98 if( $debug ) 99 echo "Inserting tag $tag into DB for $u failed: $qs<br>"; 82 100 log_mesg_to( "Inserting tag $tag for $u failed: $qs", "global" ); 83 101 } else { … … 85 103 # first, we save the new tag id for inserting in the xref table 86 104 $current_tag_ID = mysql_insert_id(); 105 if( $debug ) 106 echo "query ran and gave us new tag ID $current_tag_ID <br>"; 87 107 88 108 # THEN, WE CACHE IT IN CASE WE SEE THIS TAG AGAIN: … … 108 128 } else { 109 129 ++$db_errors; 130 if( $debug ) 131 echo "current_link_ID ($current_link_ID) and/or current_tag_ID($current_tag_ID) were 0, meaning a database Insert failed on import<br>"; 110 132 l( "current_link_ID and/or current_tag_ID were 0, meaning a database Insert failed on import" ); 111 133 } … … 113 135 } 114 136 } 137 } 115 138 116 139 conClose( $con_bulk_import ); feedmelinks/import/ready-to-import.php
r1374 r1375 7 7 if( $tok && $tok == md5( getPasswdForUser( $u ))) { 8 8 include_once( "$modules/header.inc.php" ); 9 10 9 ?> 11 10 <br /> 12 11 <?php 12 13 $debug = 0; 13 14 14 15 $b = get_bookmarks_info( $u ); … … 26 27 $tag_xslt = get_root() . "/import/import-delicious-tags.xsl"; 27 28 $cmd = "$bin/import-bookmarks.pl $dir$file_name $parser $link_xslt $tag_xslt"; 29 if( $debug ) 30 echo "<big><code>\$cmd: $cmd</code></big><p/>"; 28 31 29 $result = exec( $cmd ); 30 echo "<br>cmd: <br>$cmd<br>"; 31 echo "<br>result: <br>$result<br>"; 32 if( preg_match( "/SUCCESS/", $result )) { 32 $last_line = exec( $cmd, $out ); 33 if( $debug ) { 34 echo "<big><pre>\$out:"; 35 print_r( $out ); 36 echo "</pre></big><p/>"; 37 echo "<big><code>\$last_line: $last_line</code></big><p/>"; 38 } 39 40 if( preg_match( "/SUCCESS/", $last_line )) { 33 41 # extract whatever delimeter the perl used from the result XML: 34 42 $delimeter = preg_replace( '/^[^"]+"([^"]+).*/', "\${1}", $result ); feedmelinks/modules/utils.inc.php
r1372 r1375 11 11 define( "IDLENESS", 1 ); 12 12 define( "SPAMMING", 2 ); 13 14 function get_imported_link_and_comment( $raw_name ) { 15 $comment = ""; 16 $comment_pieces = preg_split( "/__FML_COMMENT__/", $raw_name ); 17 $name = $comment_pieces[0]; 18 if( sizeof( $comment_pieces ) > 1 ) 19 $comment = $comment_pieces[1]; 20 $name = preg_replace( "/__FML_COMMENT__.*/", "", $name ); 21 return array($name, $comment ); 22 } 23 24 function rename_link( $u, $id, $name ) { 25 if( !( $u && $id && $name )) 26 return; 27 return run_query( getQuery( "edit_name", $name, $id, $u )); 28 } 13 29 14 30 function get_mime_type( $format ) { … … 601 617 $name = make_safe_for_email( get_link_name( $orig_link_ID )); 602 618 $body = <<<END 603 604 619 Hey $grabbee. 605 620 … … 971 986 972 987 function add_tags_from_request( $u, $newLinkID, $known_tag_IDs, $con, $possibly_new_tag_names ) { 988 if( $u != getOwnerForLink( $newLinkID )) { 989 log_mesg_to( "[failed tag hijacking attempt] $u, $newLinkID", "security" ); 990 return "FAILED"; 991 } 973 992 # if we were called with a big list of possible tags, use that, 974 993 # otherwise, slurp them out of the request (_GET + _POST arrays) … … 1042 1061 break; 1043 1062 } else { 1044 e( "already tagged w/that tag -- no worries!" );1045 1063 # fake a real result set so our caller thinks we succeeded, since we did 1046 1064 $q = 1; … … 1112 1130 $pi["webgirl"] = true; 1113 1131 $pi["marker_pen"] = true; 1132 $pi["briancors"] = true; 1114 1133 1115 1134 #$pi["khemraj"] = true; … … 1204 1223 1205 1224 function l( $m ) { 1225 log_mesg_to( $m, "global" ); 1206 1226 trigger_error( $m ); 1207 1227 } … … 2474 2494 2475 2495 } else if( $argWhichQuery == "add_tag" ) { 2476 $isPrivate = ( $args[3] == "NULL" || !$args[3] ) ? 1 : 0; 2477 run_heuristics( $argWhichQuery, $args[1], array( "tag" => $args[2])); 2496 2497 # preserve colons, ugh 2498 $tag = $args[2]; 2499 $tag = preg_replace( "/:/", "_FML_COLON_", $tag ); 2500 $tag = urlencode( $tag ); 2501 $tag = preg_replace( "/_FML_COLON_/", ":",$tag ); 2502 2503 $isPrivate = ( $args[3] == "NULL" || !$tag ) ? 1 : 0; 2504 run_heuristics( $argWhichQuery, $args[1], array( "tag" => $tag)); 2478 2505 return " 2479 INSERT INTO tags VALUES(NULL,'" . urlencode( $args[1] ) . "','" . urlencode( $args[2] ). "','', $isPrivate);";2506 INSERT INTO tags VALUES(NULL,'" . urlencode( $args[1] ) . "','" . $tag . "','', $isPrivate);"; 2480 2507 2481 2508 } else if( $argWhichQuery == "tag_by_name" ) { … … 3451 3478 } 3452 3479 3480 # convert any Cf. footnotes 3481 function linkReplace_cb( $matches ) { 3482 ob_start(); 3483 makeUserLink( getOwnerForLink( $matches[1] )); 3484 echo "'s "; 3485 makeLinkOut( $matches[1] ); 3486 echo " "; 3487 makePermaLink( $matches[1] ); 3488 $linkOutHTML = ob_get_clean(); 3489 return $linkOutHTML; 3490 } 3491 3453 3492 function addCommentToLink( $argId, $argComment, $commenter, $debug ) { 3454 3493 if( snuffed( $commenter )) { … … 3505 3544 $comment = preg_replace( "/user\( *([^\)]+) *\)/", "<a href=\"/u/\\1\">\\1</a>", $comment ); 3506 3545 3507 # convert any Cf. footnotes3508 function linkReplace_cb( $matches ) {3509 ob_start();3510 makeUserLink( getOwnerForLink( $matches[1] ));3511 echo "'s ";3512 makeLinkOut( $matches[1] );3513 echo " ";3514 makePermaLink( $matches[1] );3515 $linkOutHTML = ob_get_clean();3516 return $linkOutHTML;3517 }3518 3546 3519 3547 $comment =