Changeset 1375

Show
Ignore:
Timestamp:
03/04/07 02:59:37 (1 year ago)
Author:
jm3
Message:

Finished support for not-so-nice delicious hybrid bookmark format (it looks like traditional netscape, but with an added tags attribute and comments).
Whatevs, we rock, add it to the list of things we support, it works, you're sexy, your links will all import, comments intact. Hi.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedmelinks/.htaccess-global

    r1360 r1375  
    5353RewriteRule    ^xml/peeps$ /peeps-as-xml [L] 
    5454RewriteRule    ^api/backroom/(.*)$ /api/restricted/secure-call.php?call=$1 [L] 
     55 
     56RewriteRule    ^api/rename/(.*)$ /api/core/index.php?op=rename&user=$1 [L] 
     57RewriteRule    ^api/add_tags/(.*)$ /api/core/index.php?op=add_tags&user=$1 [L] 
    5558 
    5659# JSON API 
  • feedmelinks/404.php

    r770 r1375  
    44 
    55        include( "$modules/header.insecure.inc.php" );  
     6         log_mesg_to( "[missing page] $page", "global" ); 
     7 
    68%> 
    79 
     
    1113</h1> 
    1214--> 
     15<!-- <img src="/img/tiny-heaton-404.gif"/> --> 
    1316 
    1417<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> 
    1631</center> 
    1732 
    18  
    19  
    20 <%= bounceWithDelay( $site, 4 ) %> 
     33<%= #bounceWithDelay( $site, 4 ) %> 
  • feedmelinks/FAQ/index.php

    r1369 r1375  
    406406                        (pass <code>user</code> and <code>password</code>) 
    407407                        <br /> 
     408                        <br /> 
    408409 
    409410                        # <b>get all your links as XML</b>:<br /> 
     
    413414                        # <b>get all your tags as XML</b>:<br /> 
    414415                        <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 /> 
    415424                        <br /> 
    416425 
     
    431440--> 
    432441 
    433                         # <b>how to get a list of your peeps as XML</b>:<br /> 
     442                        # <b>get your peeps as XML</b>:<br /> 
    434443                        <span class="subtle">http://feedmelinks.com</span>/xml/peeps<br /> 
    435444                        </code> 
  • feedmelinks/bin/hybrid-to-xml.pl

    r1371 r1375  
    77"; 
    88 
     9#format is DT link info, then DD link comment 
     10 
     11 
     12$comment_delim = "__FML_COMMENT__"; 
     13 
    914$header = 1; 
     15 
     16$last_link = ""; 
    1017while( <> ) { 
    1118  if( $header ) { next unless ( /<DL>/ ); } 
     19        $line = $_; 
    1220  $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        } 
    3364} 
    3465 
    3566print "\n</posts>\n"; 
     67 
     68# for name and comments -- NOT url encoding 
     69sub escape_string { 
     70        my $s = $_[0]; 
     71        #print "name is now $s\n"; 
     72        $s =~ s/&([^a][^m][^p][^;])/&amp;$1/g; 
     73        $s =~ s/&([^a])/&amp;$1/g; 
     74        $s =~ s/"/&quot;/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/&#187;/g; 
     80        return $s; 
     81} 
     82 
     83sub 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 
     2use lib "/home/fml/public_html/lib"; 
    23use FeedMeLinks::Environment; 
    34use File::Temp qw/ :mktemp  /; 
    4  
    55 
    66$glc = 0; 
     
    2323$tag_xslt   = $ARGV[3]; 
    2424$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)); 
    2830# one of: delicious-hybrid, netscape, delicious-API 
    2931$format = detect_bookmarks_format( $bin, $filename ); 
    3032if( $format == "delicious-hybrid" ) { 
     33        print "converting from hybrid format:\n"; 
    3134        $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`; 
    3537        $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"; 
    3642} 
    3743 
     
    3945        $line = $_; 
    4046 
    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'?> 
    4250                 
    4351                $cmd = "xsltproc $link_xslt $filename > $path/LINKS.RAW\n"; 
    44                 #print "$cmd\n"; 
     52                print "$cmd\n"; 
    4553                $out = `$cmd`; 
    46                 #print "cmd output was: $out\n"; 
     54                print "cmd output was: $out\n"; 
    4755                 
    4856                $cmd = "xsltproc $tag_xslt $filename | sort | uniq | grep -v '^\$' > $path/TAGS.RAW\n"; 
    49                 #print "$cmd\n"; 
     57                print "cmd: $cmd\n"; 
    5058                $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); 
    5464                exit 0; 
    5565 
     
    145155        foreach( @tags ) { print TAGS "$_\n"; } 
    146156        close( TAGS ); 
    147         print qq(<result delimeter="$dd">SUCCESS</result>\n); 
     157        print qq(<result delimeter="$dd" note="$success_code">SUCCESS</result>\n); 
    148158} 
    149159 
  • feedmelinks/import/complete.php

    r1168 r1375  
    3737                shout( "Importing Complete!",  
    3838                "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>" : "")  
    4040                ); 
    4141%> 
     
    4545<h1> 
    4646Now either:<br /> 
    47 <a href='/f/<%= $imported_folder_ID %>'>Explore your new links</a>,  
     47<a href='/'>Explore your new links</a>,  
    4848</h1> 
    4949or  
  • feedmelinks/import/present-clean-pre-flight-input.inc.php

    r1336 r1375  
    1515 
    1616%> 
    17 <div id="newLinks" class="box"
     17<div
    1818        <div class="subhead"> 
    1919                new tags to be created: 
    2020        </div> 
    21         <div
    22 <% 
     21        <div style="border: 1px solid #cdcdcd; padding: 2.0em; margin: 0.2em; font-size: 16px;"
     22<?php 
    2323        for( $i = 0; $i < $ts; $i++ ) { 
    2424                $line = rtrim( $tags[$i] ); 
     
    2727                if( substr( $line, 0, 2 ) == "X " ) { 
    2828                        $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"; 
    3030                } else { 
    3131                        ++$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"; 
    3333                } 
    34                 echo "</div>\n"; 
    3534        } 
    36 %
     35?
    3736        </div> 
    3837</div> 
     
    4039<div id="newLinks" class="box"> 
    4140        <div class="subhead"> 
    42                 new favorites to be imported: 
     41                new links to be imported: 
    4342        </div> 
    44 <% 
     43<?php 
    4544        for( $i = 0; $i < $ls; $i++ ) { 
    4645                $line = rtrim( $links[$i] ); 
    4746                $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 
    4848                $url = $l[0]; 
    4949                $name = $l[1]; 
    5050                $max_length = 65; 
     51                if( $debug ) 
     52                        print_r ( $l ); 
    5153                if( ! $line )  
    5254                        continue; 
     
    5759                        ++$num_links; 
    5860                        $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 ); 
    6065                } 
    6166                echo "</div>\n"; 
    6267        } 
    63 %
     68?
    6469        </div> 
    6570</div> 
  • feedmelinks/import/processing.php

    r1336 r1375  
    3535                # A. the links 
    3636                ############################################## 
    37  
    3837                for( $i = 0; $i < sizeof( $links ); $i++ ) { 
    3938                        $line = rtrim( $links[$i] ); 
    4039                        if( substr( $line, 0, 2 ) != "X " ) { # skip dupes 
    4140 
    42                                 #e( "$i ::" ); 
    4341                                $l = preg_split( "/$delimeter/", $line ); 
    4442                                $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                                        } 
    4861 
    4962                                # B. the tag / link associations 
    5063                                ############################################## 
    51                                 $current_link_ID = mysql_insert_id()
     64                                $current_link_ID = $inserted_id
    5265                                for( $j = 0; $j < sizeof( $taglist ); $j++ ) { 
    53                                         $tag = urlencode( rtrim( $taglist[$j] ) ); 
    54                                         #       e( "ON tag $tag" ); 
     66                                        $tag = rtrim( $taglist[$j] ); 
    5567 
    5668                                        # C. the tags 
     
    7587 
    7688                                                # 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>"; 
    7791                                                if( $run_query ) { 
    7892                                                        $qs = getQuery( "add_tag", $user, $tag ); 
    7993                                                        $q = mysql_query( $qs ); 
     94                                                        if( $debug ) 
     95                                                                echo "$qs<br>"; 
    8096                                                        if( !$q ) { 
    8197                                                                ++$db_errors; 
     98                                                                if( $debug ) 
     99                                                                        echo "Inserting tag $tag into DB for $u failed: $qs<br>"; 
    82100                                                                log_mesg_to( "Inserting tag $tag for $u failed: $qs", "global" ); 
    83101                                                        } else { 
     
    85103                                                                # first, we save the new tag id for inserting in the xref table 
    86104                                                                $current_tag_ID = mysql_insert_id(); 
     105                                                                if( $debug ) 
     106                                                                        echo "query ran and gave us new tag ID $current_tag_ID <br>"; 
    87107 
    88108                                                                # THEN, WE CACHE IT IN CASE WE SEE THIS TAG AGAIN: 
     
    108128                                        } else { 
    109129                                                ++$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>"; 
    110132                                                l( "current_link_ID and/or current_tag_ID were 0, meaning a database Insert failed on import" ); 
    111133                                        } 
     
    113135                        } 
    114136                } 
     137        } 
    115138 
    116139                conClose( $con_bulk_import ); 
  • feedmelinks/import/ready-to-import.php

    r1374 r1375  
    77        if( $tok && $tok == md5( getPasswdForUser( $u ))) { 
    88                include_once( "$modules/header.inc.php" ); 
    9  
    109?> 
    1110<br /> 
    1211<?php 
     12 
     13        $debug = 0; 
    1314 
    1415                $b =  get_bookmarks_info( $u ); 
     
    2627                $tag_xslt = get_root() . "/import/import-delicious-tags.xsl"; 
    2728                $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/>"; 
    2831 
    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 )) { 
    3341                        # extract whatever delimeter the perl used from the result XML: 
    3442                        $delimeter = preg_replace( '/^[^"]+"([^"]+).*/', "\${1}", $result ); 
  • feedmelinks/modules/utils.inc.php

    r1372 r1375  
    1111define( "IDLENESS", 1 ); 
    1212define( "SPAMMING", 2 ); 
     13 
     14function 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 
     24function rename_link( $u, $id, $name ) { 
     25        if( !( $u && $id && $name )) 
     26                return; 
     27        return run_query( getQuery( "edit_name", $name, $id, $u ));  
     28} 
    1329 
    1430function get_mime_type( $format ) { 
     
    601617        $name = make_safe_for_email( get_link_name( $orig_link_ID )); 
    602618        $body = <<<END 
    603  
    604619Hey $grabbee. 
    605620 
     
    971986 
    972987function 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        } 
    973992  # if we were called with a big list of possible tags, use that,  
    974993        # otherwise, slurp them out of the request (_GET + _POST arrays) 
     
    10421061        break; 
    10431062      } else { 
    1044         e( "already tagged w/that tag -- no worries!" ); 
    10451063        # fake a real result set so our caller thinks we succeeded, since we did 
    10461064        $q = 1; 
     
    11121130    $pi["webgirl"] = true; 
    11131131    $pi["marker_pen"] = true; 
     1132    $pi["briancors"] = true; 
    11141133 
    11151134    #$pi["khemraj"] = true; 
     
    12041223 
    12051224  function l( $m ) { 
     1225                log_mesg_to( $m, "global" ); 
    12061226    trigger_error( $m ); 
    12071227  } 
     
    24742494 
    24752495  } 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)); 
    24782505                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);";  
    24802507   
    24812508  } else if( $argWhichQuery  == "tag_by_name" ) { 
     
    34513478} 
    34523479 
     3480# convert any Cf. footnotes 
     3481function 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 
    34533492function addCommentToLink( $argId, $argComment, $commenter, $debug ) { 
    34543493        if( snuffed( $commenter )) { 
     
    35053544                                $comment = preg_replace( "/user\( *([^\)]+) *\)/", "<a href=\"/u/\\1\">\\1</a>", $comment ); 
    35063545 
    3507                                 # convert any Cf. footnotes 
    3508                                 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                                 } 
    35183546 
    35193547                                $comment =