sitebar2scuttle.php
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sitebar2scuttle.php [2006/11/08 02:16] – old revision restored 84.142.251.254 | sitebar2scuttle.php [2006/11/13 13:50] (current) – old revision restored andi | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== scuttle2sitebar bookmark import ====== | ||
| + | This is a simple script that will import bookmarks from a [[http:// | ||
| + | |||
| + | Features: | ||
| + | |||
| + | * Honours private bookmarks | ||
| + | * Uses folder names as tags | ||
| + | |||
| + | Current Limitations: | ||
| + | |||
| + | * missing error handling - it's just a quick hack | ||
| + | * compatibility with new database structure is an even bigger hack by someone clueless... | ||
| + | * Only one user is converted at a time, identified by his email address | ||
| + | * The user must exist in both databases and have the same email address | ||
| + | * Scuttle doesn' | ||
| + | * maybe others | ||
| + | |||
| + | <code php> | ||
| + | <? | ||
| + | // sitebar | ||
| + | $sb_name=' | ||
| + | $sb_host=' | ||
| + | $sb_user=' | ||
| + | $sb_pass=' | ||
| + | $sb_pre=' | ||
| + | |||
| + | // scuttle | ||
| + | $sc_name=' | ||
| + | $sc_host=' | ||
| + | $sc_user=' | ||
| + | $sc_pass=' | ||
| + | |||
| + | // email of user to convert | ||
| + | $email = ' | ||
| + | |||
| + | /* -------- no editing below needed -------------------------------------- */ | ||
| + | |||
| + | if (!extension_loaded(' | ||
| + | dl(' | ||
| + | } | ||
| + | |||
| + | $sb = mysql_connect($sb_host, | ||
| + | mysql_select_db($sb_name, | ||
| + | |||
| + | $sc = mysql_connect($sc_host, | ||
| + | mysql_select_db($sc_name, | ||
| + | |||
| + | $sql = " | ||
| + | FROM ${sb_pre}root A, ${sb_pre}user B | ||
| + | WHERE A.uid = B.uid | ||
| + | AND B.email = '" | ||
| + | $res = mysql_query($sql, | ||
| + | $row = mysql_fetch_array($res, | ||
| + | $nid = $row[' | ||
| + | |||
| + | $sql = " | ||
| + | WHERE email = '" | ||
| + | $res = mysql_query($sql, | ||
| + | $row = mysql_fetch_array($res, | ||
| + | $SC_UID = $row[' | ||
| + | |||
| + | print "NID: $nid -> UID: $SC_UID\n"; | ||
| + | |||
| + | list_links($nid,'', | ||
| + | |||
| + | function check_privacy($nid, | ||
| + | global $sb; | ||
| + | global $sb_pre; | ||
| + | global $sc_pre; | ||
| + | $sql = " | ||
| + | FROM ${sb_pre}acl A, ${sb_pre}group B | ||
| + | WHERE B.name=' | ||
| + | AND A.nid = $nid"; | ||
| + | |||
| + | $res = mysql_query($sql, | ||
| + | if(mysql_affected_rows($sb)){ | ||
| + | $line = mysql_fetch_array($res, | ||
| + | if($line[' | ||
| + | $private=0; | ||
| + | }else{ | ||
| + | $private=1; | ||
| + | } | ||
| + | } | ||
| + | mysql_free_result($res); | ||
| + | return $private; | ||
| + | } | ||
| + | |||
| + | function list_links($nid, | ||
| + | global $sb; | ||
| + | global $sc; | ||
| + | global $sb_pre; | ||
| + | global $sc_pre; | ||
| + | global $SC_UID; | ||
| + | |||
| + | // update privacy | ||
| + | $private = check_privacy($nid, | ||
| + | |||
| + | // get all links | ||
| + | $sql = " | ||
| + | FROM ${sb_pre}link | ||
| + | WHERE nid = $nid"; | ||
| + | |||
| + | $res = mysql_query($sql, | ||
| + | while ($row = mysql_fetch_array($res, | ||
| + | |||
| + | // determine link's privacy | ||
| + | if($private || $row[' | ||
| + | $stat = 2; | ||
| + | }else{ | ||
| + | $stat = 0; | ||
| + | } | ||
| + | print "$stat " | ||
| + | |||
| + | // build tags | ||
| + | $names = preg_replace('/ | ||
| + | $names = preg_replace('/, | ||
| + | $tags = explode(',', | ||
| + | |||
| + | $row = array_map(' | ||
| + | |||
| + | // insert into scuttle | ||
| + | $sql = " | ||
| + | SET bAddress | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | // add tags | ||
| + | $ins = mysql_insert_id($sc); | ||
| + | if($ins){ | ||
| + | foreach($tags as $tag){ | ||
| + | if ($tag != '' | ||
| + | $sql = " | ||
| + | SET bId = $ins, | ||
| + | tag = '" | ||
| + | |||
| + | | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | mysql_free_result($res); | ||
| + | |||
| + | // get all the subtrees | ||
| + | $sql = " | ||
| + | $res = mysql_query($sql, | ||
| + | while ($line = mysql_fetch_array($res, | ||
| + | $line[' | ||
| + | list_links($line[' | ||
| + | } | ||
| + | mysql_free_result($res); | ||
| + | |||
| + | } | ||
| + | |||
| + | ?> | ||
| + | </ | ||
