aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/export_gcs.php5
-rw-r--r--api/export_html.php8
-rw-r--r--api/httpauth.inc.php42
-rw-r--r--api/posts_add.php2
-rw-r--r--api/posts_all.php8
-rw-r--r--api/posts_dates.php8
-rw-r--r--api/posts_delete.php3
-rw-r--r--api/posts_get.php7
-rw-r--r--api/posts_recent.php7
-rw-r--r--api/posts_update.php5
-rw-r--r--api/tags_get.php3
-rw-r--r--api/tags_rename.php2
12 files changed, 44 insertions, 56 deletions
diff --git a/api/export_gcs.php b/api/export_gcs.php
index 1040dd4..6f1f4c2 100644
--- a/api/export_gcs.php
+++ b/api/export_gcs.php
@@ -12,8 +12,9 @@ if($GLOBALS['enableGoogleCustomSearch'] == false) {
die;
}
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
+
/*
// Restrict to admins?
@@ -36,8 +37,6 @@ $tag = NULL;
// Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag, NULL, getSortOrder());
-$currentuser = $userservice->getCurrentUser();
-$currentusername = $currentuser[$userservice->getFieldName('username')];
// Set up the plain file and output all the posts.
header('Content-Type: text/plain');
diff --git a/api/export_html.php b/api/export_html.php
index b422b4b..79ade0a 100644
--- a/api/export_html.php
+++ b/api/export_html.php
@@ -7,9 +7,9 @@
// Force HTTP authentication first!
require_once('httpauth.inc.php');
require_once('../header.inc.php');
-
+
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
// Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
@@ -20,8 +20,6 @@ else
// Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, getSortOrder());
-$currentuser = $userservice->getCurrentUser();
-$currentusername = $currentuser[$userservice->getFieldName('username')];
// Set up the XML file and output all the posts.
header('Content-Type: text/html');
@@ -29,7 +27,7 @@ echo '<!DOCTYPE NETSCAPE-Bookmark-file-1>'."\r\n";
echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">';
echo '<!-- This is an automatically generated file. -->'."\r\n";
echo '<TITLE>Bookmarks</TITLE>'."\r\n";
-echo '<H1 LAST_MODIFIED="'. date('U') .'">Bookmarks for '. htmlspecialchars($currentusername) .''. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') ." from " . $sitename ."</H1>\r\n";
+echo '<H1 LAST_MODIFIED="'. date('U') .'">Bookmarks for '. htmlspecialchars($currentUser->getUsername()) .''. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') ." from " . $sitename ."</H1>\r\n";
echo '<DL><p>'."\r\n";
diff --git a/api/httpauth.inc.php b/api/httpauth.inc.php
index d0198fd..5dd7444 100644
--- a/api/httpauth.inc.php
+++ b/api/httpauth.inc.php
@@ -1,37 +1,33 @@
<?php
require_once('../header.inc.php');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
// Provides HTTP Basic authentication of a user, and sets two variables, sId and username,
// with the user's info.
function authenticate() {
- header('WWW-Authenticate: Basic realm="SemanticScuttle API"');
- header('HTTP/1.0 401 Unauthorized');
-
- die(T_("Use of the API calls requires authentication."));
+ header('WWW-Authenticate: Basic realm="SemanticScuttle API"');
+ header('HTTP/1.0 401 Unauthorized');
+
+ die(T_("Use of the API calls requires authentication."));
}
if(!$userservice->isLoggedOn()) {
- /* Maybe we have caught authentication data in $_SERVER['REMOTE_USER']
- ( Inspired by http://www.yetanothercommunitysystem.com/article-321-regle-comment-utiliser-l-authentification-http-en-php-chez-ovh ) */
- if((!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
- && preg_match('/Basic\s+(.*)$/i', $_SERVER['REMOTE_USER'], $matches)) {
- list($name, $password) = explode(':', base64_decode($matches[1]));
- $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
- $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
- }
-
- if (!isset($_SERVER['PHP_AUTH_USER'])) {
- authenticate();
- } else {
- require_once('../header.inc.php');
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ /* Maybe we have caught authentication data in $_SERVER['REMOTE_USER']
+ ( Inspired by http://www.yetanothercommunitysystem.com/article-321-regle-comment-utiliser-l-authentification-http-en-php-chez-ovh ) */
+ if((!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
+ && preg_match('/Basic\s+(.*)$/i', $_SERVER['REMOTE_USER'], $matches)) {
+ list($name, $password) = explode(':', base64_decode($matches[1]));
+ $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
+ $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
+ }
- $login = $userservice->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
- if (!$login) {
- authenticate();
+ if (!isset($_SERVER['PHP_AUTH_USER'])) {
+ authenticate();
+ } else {
+ $login = $userservice->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
+ if (!$login) {
+ authenticate();
+ }
}
- }
}
?>
diff --git a/api/posts_add.php b/api/posts_add.php
index 77c3288..e27fc99 100644
--- a/api/posts_add.php
+++ b/api/posts_add.php
@@ -13,8 +13,8 @@
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
// Get all the bookmark's passed-in information
if (isset($_REQUEST['url']) && (trim($_REQUEST['url']) != ''))
diff --git a/api/posts_all.php b/api/posts_all.php
index 03026c4..4ecbd7e 100644
--- a/api/posts_all.php
+++ b/api/posts_all.php
@@ -8,8 +8,9 @@
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
+
// Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
@@ -20,13 +21,10 @@ else
// Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
-$currentuser = $userservice->getCurrentUser();
-$currentusername = $currentuser[$userservice->getFieldName('username')];
-
// Set up the XML file and output all the posts.
header('Content-Type: text/xml');
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
-echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" user="'. htmlspecialchars($currentusername) .'"'. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n";
+echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" user="'. htmlspecialchars($currentUser->getUsername()) .'"'. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n";
foreach($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
diff --git a/api/posts_dates.php b/api/posts_dates.php
index 7098756..d4962ff 100644
--- a/api/posts_dates.php
+++ b/api/posts_dates.php
@@ -6,8 +6,9 @@
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
+
// Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
@@ -18,13 +19,10 @@ else
// Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
-$currentuser = $userservice->getCurrentUser();
-$currentusername = $currentuser[$userservice->getFieldName('username')];
-
// Set up the XML file and output all the tags.
header('Content-Type: text/xml');
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
-echo '<dates tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentusername, 'xml') ."\">\r\n";
+echo '<dates tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n";
$lastdate = NULL;
foreach($bookmarks['bookmarks'] as $row) {
diff --git a/api/posts_delete.php b/api/posts_delete.php
index 737a4fb..d24ba59 100644
--- a/api/posts_delete.php
+++ b/api/posts_delete.php
@@ -10,8 +10,9 @@
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
+
// Note that del.icio.us only errors out if no URL was passed in; there's no error on attempting
// to delete a bookmark you don't have.
diff --git a/api/posts_get.php b/api/posts_get.php
index 8be067b..34d192e 100644
--- a/api/posts_get.php
+++ b/api/posts_get.php
@@ -13,8 +13,9 @@
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
+
// Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
@@ -32,13 +33,11 @@ $dtend = date('Y-m-d H:i:s', strtotime($dtstart .'+1 day'));
// Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, NULL, NULL, $dtstart, $dtend);
-$currentuser = $userservice->getCurrentUser();
-$currentusername = $currentuser[$userservice->getFieldName('username')];
// Set up the XML file and output all the tags.
header('Content-Type: text/xml');
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
-echo '<posts'. (is_null($dtstart) ? '' : ' dt="'. $dtstart .'"') .' tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentusername, 'xml') ."\">\r\n";
+echo '<posts'. (is_null($dtstart) ? '' : ' dt="'. $dtstart .'"') .' tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n";
foreach($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
diff --git a/api/posts_recent.php b/api/posts_recent.php
index 22fc2bd..daa9d39 100644
--- a/api/posts_recent.php
+++ b/api/posts_recent.php
@@ -10,8 +10,9 @@ $countMax = 100;
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
+
// Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
@@ -33,13 +34,11 @@ if (isset($_REQUEST['count']) && (intval($_REQUEST['count']) != 0)) {
// Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, $count, $userservice->getCurrentUserId(), $tag);
-$currentuser = $userservice->getCurrentUser();
-$currentusername = $currentuser[$userservice->getFieldName('username')];
// Set up the XML file and output all the tags.
header('Content-Type: text/xml');
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
-echo '<posts tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentusername, 'xml') ."\">\r\n";
+echo '<posts tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n";
foreach($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
diff --git a/api/posts_update.php b/api/posts_update.php
index de379d2..6ea50e2 100644
--- a/api/posts_update.php
+++ b/api/posts_update.php
@@ -8,14 +8,13 @@
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
+
// Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, 1, $userservice->getCurrentUserId());
-$currentuser = $userservice->getCurrentUser();
-$currentusername = $currentuser[$userservice->getFieldName('username')];
// Set up the XML file and output all the tags.
header('Content-Type: text/xml');
diff --git a/api/tags_get.php b/api/tags_get.php
index 172dd0a..cee36ee 100644
--- a/api/tags_get.php
+++ b/api/tags_get.php
@@ -8,8 +8,9 @@
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
+
// Get the tags relevant to the passed-in variables.
$tags =& $b2tservice->getTags($userservice->getCurrentUserId());
diff --git a/api/tags_rename.php b/api/tags_rename.php
index fc4f2ad..dd16339 100644
--- a/api/tags_rename.php
+++ b/api/tags_rename.php
@@ -8,8 +8,8 @@
require_once('httpauth.inc.php');
require_once('../header.inc.php');
+/* Service creation: only useful services are created */
$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService');
-$userservice =& ServiceFactory::getServiceInstance('UserService');
// Get the tag info.
if (isset($_REQUEST['old']) && (trim($_REQUEST['old']) != ''))