Created
October 5, 2015 21:45
-
-
Save tobru/499e8019c39bcd17b613 to your computer and use it in GitHub Desktop.
Helper to migrate links from lobsters to Shaarli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$GLOBALS['config']['DATADIR'] = 'data'; // Data subdirectory | |
$GLOBALS['config']['CONFIG_FILE'] = $GLOBALS['config']['DATADIR'].'/config.php'; // Configuration file (user login/password) | |
$GLOBALS['config']['DATASTORE'] = $GLOBALS['config']['DATADIR'].'/datastore.php'; // Data storage file. | |
$GLOBALS['config']['CACHEDIR'] = 'cache'; // Cache directory for thumbnails for SLOW services (like flickr) | |
$GLOBALS['config']['PAGECACHE'] = 'pagecache'; // Page cache directory. | |
// User configuration | |
if (is_file($GLOBALS['config']['CONFIG_FILE'])) { | |
require_once $GLOBALS['config']['CONFIG_FILE']; | |
} | |
// Shaarli library | |
require_once 'application/Cache.php'; | |
require_once 'application/CachedPage.php'; | |
require_once 'application/HttpUtils.php'; | |
require_once 'application/LinkDB.php'; | |
require_once 'application/TimeZone.php'; | |
require_once 'application/Url.php'; | |
require_once 'application/Utils.php'; | |
require_once 'application/Config.php'; | |
$LINKSDB = new LinkDB($GLOBALS['config']['DATASTORE'],true,false); | |
// get data from lobsters db | |
$DB_NAME="mylobstersdbname"; | |
$DB_USER="mylobstersdbuser"; | |
$DB_PASSWORD="supersecret"; | |
$DB_HOST="localhost"; | |
$conn = mysqli_connect($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_NAME); | |
$sql = "SELECT stories.*, GROUP_CONCAT(tags.tag SEPARATOR ' ') as tags FROM stories, tags, taggings WHERE taggings.story_id = stories.id AND taggings.tag_id = tags.id GROUP BY stories.id;"; | |
$result = mysqli_query($conn, $sql); | |
if (mysqli_num_rows($result) > 0) { | |
while($row = mysqli_fetch_assoc($result)) { | |
$linkdate = date('Ymd_His',strtotime($row["created_at"])); | |
$link = array('title'=>$row["title"],'url'=>$row["url"],'description'=>$row["description"],'private'=>0, | |
'linkdate'=>$linkdate,'tags'=>$row["tags"]); | |
$LINKSDB[$linkdate] = $link; | |
} | |
} else { | |
echo "0 results"; | |
} | |
mysqli_close($conn); | |
// put data into shaarli | |
// print_r($LINKSDB); | |
$LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // Save to disk. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment