2009-09-22 08:37:29 +02:00
|
|
|
<?php
|
2007-12-12 17:29:16 +01:00
|
|
|
/***************************************************************************
|
2008-11-27 08:27:36 +01:00
|
|
|
Copyright (C) 2004 - 2006 Scuttle project
|
|
|
|
http://sourceforge.net/projects/scuttle/
|
|
|
|
http://scuttle.org/
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-11-27 08:27:36 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-11-27 08:27:36 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-11-27 08:27:36 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
***************************************************************************/
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2009-10-03 23:52:30 +02:00
|
|
|
require_once '../src/SemanticScuttle/header.php';
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
/* Service creation: only useful services are created */
|
2009-10-03 23:52:30 +02:00
|
|
|
$bookmarkservice =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark');
|
2008-11-25 16:57:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Managing all possible inputs */
|
|
|
|
// First input is $_FILES
|
|
|
|
// Other inputs
|
|
|
|
isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', '');
|
|
|
|
|
2008-11-27 11:13:29 +01:00
|
|
|
$countImportedBookmarks = 0;
|
|
|
|
$tplVars['msg'] = '';
|
2007-12-12 17:29:16 +01:00
|
|
|
|
|
|
|
if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) {
|
2008-11-27 08:27:36 +01:00
|
|
|
$userinfo = $userservice->getCurrentObjectUser();
|
|
|
|
|
|
|
|
if (is_numeric(POST_STATUS)) {
|
|
|
|
$status = intval(POST_STATUS);
|
|
|
|
} else {
|
|
|
|
$status = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// File handle
|
|
|
|
$html = file_get_contents($_FILES['userfile']['tmp_name']);
|
|
|
|
|
|
|
|
// Create link array
|
2008-11-27 11:13:29 +01:00
|
|
|
//preg_match_all('/<a\s+(.*?)\s*\/*>([^<]*)/si', $html, $matches);
|
|
|
|
preg_match_all('/<a\s+(.*?)>([^<]*?)<\/a>.*?(<dd>([^<]*)|<dt>)/si', $html, $matches);
|
|
|
|
|
|
|
|
//var_dump($matches);die();
|
|
|
|
|
|
|
|
|
2008-11-27 08:27:36 +01:00
|
|
|
$links = $matches[1];
|
|
|
|
$titles = $matches[2];
|
2008-11-27 11:13:29 +01:00
|
|
|
$descriptions = $matches[4];
|
2008-11-27 08:27:36 +01:00
|
|
|
|
|
|
|
$size = count($links);
|
|
|
|
for ($i = 0; $i < $size; $i++) {
|
|
|
|
|
|
|
|
// echo "<hr/>";
|
|
|
|
// echo $links[$i]."<br/>";
|
2008-11-27 11:13:29 +01:00
|
|
|
|
2008-11-27 08:27:36 +01:00
|
|
|
preg_match_all('/(\w*\s*=\s*"[^"]*")/', $links[$i], $attributes);
|
|
|
|
//$attributes = $attributes[0]; // we keep just one row
|
|
|
|
|
|
|
|
$bDatetime = ""; //bDateTime optional
|
|
|
|
$bCategories = ""; //bCategories optional
|
|
|
|
|
|
|
|
foreach ($attributes[0] as $attribute) {
|
|
|
|
$att = preg_split('/\s*=\s*/s', $attribute, 2);
|
|
|
|
$attrTitle = $att[0];
|
|
|
|
|
|
|
|
$attrVal = eregi_replace('"', '"', preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]));
|
|
|
|
|
|
|
|
switch ($attrTitle) {
|
|
|
|
case "HREF":
|
|
|
|
$bAddress = $attrVal;
|
|
|
|
break;
|
|
|
|
case "ADD_DATE":
|
|
|
|
$bDatetime = gmdate('Y-m-d H:i:s', $attrVal);
|
|
|
|
break;
|
|
|
|
case "TAGS":
|
|
|
|
$bCategories = $attrVal;
|
|
|
|
break;
|
2009-01-12 17:40:39 +01:00
|
|
|
case "NOTE":
|
|
|
|
$bPrivateNote = $attrVal;
|
2008-11-27 08:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
2008-11-27 11:13:29 +01:00
|
|
|
$bTitle = trim($titles[$i]);
|
|
|
|
$bDescription = trim($descriptions[$i]);
|
2008-11-27 08:27:36 +01:00
|
|
|
|
|
|
|
if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) {
|
2008-11-27 11:13:29 +01:00
|
|
|
$tplVars['error'] = T_('You have already submitted some of these bookmarks.');
|
2008-11-27 08:27:36 +01:00
|
|
|
} else {
|
|
|
|
// If bookmark is local (like javascript: or place: in Firefox3), do nothing
|
2008-11-27 11:13:29 +01:00
|
|
|
if(substr($bAddress, 0, 7) == "http://" || substr($bAddress, 0, 8) == "https://") {
|
2008-11-27 08:27:36 +01:00
|
|
|
|
|
|
|
// If bookmark claims to be from the future, set it to be now instead
|
|
|
|
if (strtotime($bDatetime) > time()) {
|
|
|
|
$bDatetime = gmdate('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
|
2009-01-12 17:40:39 +01:00
|
|
|
if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, $bPrivateNote, $status, $bCategories, $bDatetime, false, true)) {
|
2008-11-27 11:13:29 +01:00
|
|
|
$countImportedBookmarks++;
|
2008-11-27 08:27:36 +01:00
|
|
|
} else {
|
|
|
|
$tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-27 11:13:29 +01:00
|
|
|
//header('Location: '. createURL('bookmarks', $userinfo->getUsername()));
|
|
|
|
$templatename = 'importNetscape.tpl';
|
|
|
|
$tplVars['msg'].= T_('Bookmarks found: ').$size.' ';
|
|
|
|
$tplVars['msg'].= T_('Bookmarks imported: ').' '.$countImportedBookmarks;
|
|
|
|
$tplVars['subtitle'] = T_('Import Bookmarks from Browser File');
|
|
|
|
$tplVars['formaction'] = createURL('importNetscape');
|
|
|
|
$templateservice->loadTemplate($templatename, $tplVars);
|
2007-12-12 17:29:16 +01:00
|
|
|
} else {
|
2008-11-27 08:27:36 +01:00
|
|
|
$templatename = 'importNetscape.tpl';
|
|
|
|
$tplVars['subtitle'] = T_('Import Bookmarks from Browser File');
|
|
|
|
$tplVars['formaction'] = createURL('importNetscape');
|
|
|
|
$templateservice->loadTemplate($templatename, $tplVars);
|
2007-12-12 17:29:16 +01:00
|
|
|
}
|
|
|
|
?>
|