2007-12-12 16:29:16 +00:00
< ? php
/***************************************************************************
2008-11-25 15:57:29 +00:00
Copyright ( C ) 2004 - 2006 Scuttle project
http :// sourceforge . net / projects / scuttle /
http :// scuttle . org /
2007-12-12 16:29:16 +00:00
2008-11-25 15:57:29 +00: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 16:29:16 +00:00
2008-11-25 15:57:29 +00: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 16:29:16 +00:00
2008-11-25 15:57:29 +00: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 16:29:16 +00:00
2010-02-08 07:32:34 +00:00
require_once 'www-header.php' ;
2007-12-12 16:29:16 +00:00
2008-11-25 15:57:29 +00:00
/* Service creation: only useful services are created */
2009-10-23 17:13:16 +00:00
$bookmarkservice = SemanticScuttle_Service_Factory :: get ( 'Bookmark' );
$cacheservice = SemanticScuttle_Service_Factory :: get ( 'Cache' );
2007-12-12 16:29:16 +00:00
2008-11-25 15:57:29 +00:00
/* Managing all possible inputs */
isset ( $_GET [ 'action' ]) ? define ( 'GET_ACTION' , $_GET [ 'action' ]) : define ( 'GET_ACTION' , '' );
isset ( $_POST [ 'submitted' ]) ? define ( 'POST_SUBMITTED' , $_POST [ 'submitted' ]) : define ( 'POST_SUBMITTED' , '' );
2015-09-13 01:33:39 +00:00
// define does not support arrays before PHP version 7
isset ( $_GET [ 'title' ]) ? $TITLE = $_GET [ 'title' ] : $TITLE = array ();
//isset($_GET['title']) ? define('GET_TITLE', $_GET['title']): define('GET_TITLE', '');
isset ( $_GET [ 'address' ]) ? $ADDRESS = $_GET [ 'address' ] : $ADDRESS = array ();
//isset($_GET['address']) ? define('GET_ADDRESS', $_GET['address']): define('GET_ADDRESS', '');
2008-11-25 15:57:29 +00:00
isset ( $_GET [ 'description' ]) ? define ( 'GET_DESCRIPTION' , $_GET [ 'description' ]) : define ( 'GET_DESCRIPTION' , '' );
2009-01-12 16:40:39 +00:00
isset ( $_GET [ 'privateNote' ]) ? define ( 'GET_PRIVATENOTE' , $_GET [ 'privateNote' ]) : define ( 'GET_PRIVATENOTE' , '' );
2008-11-25 15:57:29 +00:00
isset ( $_GET [ 'tags' ]) ? define ( 'GET_TAGS' , $_GET [ 'tags' ]) : define ( 'GET_TAGS' , '' );
2009-02-16 09:49:51 +00:00
isset ( $_GET [ 'copyOf' ]) ? define ( 'GET_COPYOF' , $_GET [ 'copyOf' ]) : define ( 'GET_COPYOF' , '' );
2008-11-25 15:57:29 +00:00
2015-09-13 01:33:39 +00:00
// define does not support arrays before PHP version 7
isset ( $_POST [ 'title' ]) ? $TITLE = $_POST [ 'title' ] : $TITLE = array ();
//isset($_POST['title']) ? define('POST_TITLE', $_POST['title']): define('POST_TITLE', '');
isset ( $_POST [ 'address' ]) ? $ADDRESS = $_POST [ 'address' ] : $ADDRESS = array ();
//isset($_POST['address']) ? define('POST_ADDRESS', $_POST['address']): define('POST_ADDRESS', '');
2008-11-25 15:57:29 +00:00
isset ( $_POST [ 'description' ]) ? define ( 'POST_DESCRIPTION' , $_POST [ 'description' ]) : define ( 'POST_DESCRIPTION' , '' );
2009-01-12 16:40:39 +00:00
isset ( $_POST [ 'privateNote' ]) ? define ( 'POST_PRIVATENOTE' , $_POST [ 'privateNote' ]) : define ( 'POST_PRIVATENOTE' , '' );
2008-11-25 15:57:29 +00:00
isset ( $_POST [ 'status' ]) ? define ( 'POST_STATUS' , $_POST [ 'status' ]) : define ( 'POST_STATUS' , '' );
2009-02-04 14:00:16 +00:00
isset ( $_POST [ 'referrer' ]) ? define ( 'POST_REFERRER' , $_POST [ 'referrer' ]) : define ( 'POST_REFERRER' , '' );
2008-11-25 15:57:29 +00:00
isset ( $_GET [ 'popup' ]) ? define ( 'GET_POPUP' , $_GET [ 'popup' ]) : define ( 'GET_POPUP' , '' );
isset ( $_POST [ 'popup' ]) ? define ( 'POST_POPUP' , $_POST [ 'popup' ]) : define ( 'POST_POPUP' , '' );
isset ( $_GET [ 'page' ]) ? define ( 'GET_PAGE' , $_GET [ 'page' ]) : define ( 'GET_PAGE' , 0 );
isset ( $_GET [ 'sort' ]) ? define ( 'GET_SORT' , $_GET [ 'sort' ]) : define ( 'GET_SORT' , '' );
2007-12-12 16:29:16 +00:00
2011-03-17 07:46:15 +00:00
if ( ! isset ( $_POST [ 'tags' ])) {
$_POST [ 'tags' ] = array ();
}
//echo '<p>' . var_export($_POST, true) . '</p>';die();
2015-09-13 01:33:39 +00:00
if ( ! is_array ( $ADDRESS )) {
$ADDRESS = array ( $ADDRESS );
}
2007-12-12 16:29:16 +00:00
2015-09-13 01:33:39 +00:00
if ( ! is_array ( $TITLE )) {
$TITLE = array ( $TITLE );
}
2008-11-25 15:57:29 +00:00
if (( GET_ACTION == " add " ) && ! $userservice -> isLoggedOn ()) {
$loginqry = str_replace ( " ' " , '%27' , stripslashes ( $_SERVER [ 'QUERY_STRING' ]));
header ( 'Location: ' . createURL ( 'login' , '?' . $loginqry ));
exit ();
}
2007-12-12 16:29:16 +00:00
if ( $userservice -> isLoggedOn ()) {
2008-12-05 07:25:04 +00:00
$currentUser = $userservice -> getCurrentObjectUser ();
$currentUserID = $currentUser -> getId ();
$currentUsername = $currentUser -> getUsername ();
2007-12-12 16:29:16 +00:00
}
2008-11-25 15:57:29 +00:00
@ list ( $url , $user , $cat ) = isset ( $_SERVER [ 'PATH_INFO' ]) ? explode ( '/' , $_SERVER [ 'PATH_INFO' ]) : NULL ;
2007-12-12 16:29:16 +00:00
$endcache = false ;
if ( $usecache ) {
2008-11-25 15:57:29 +00:00
// Generate hash for caching on
$hash = md5 ( $_SERVER [ 'REQUEST_URI' ] . $user );
// Don't cache if its users' own bookmarks
if ( $userservice -> isLoggedOn ()) {
if ( $currentUsername != $user ) {
// Cache for 5 minutes
$cacheservice -> Start ( $hash );
$endcache = true ;
}
} else {
// Cache for 30 minutes
$cacheservice -> Start ( $hash , 1800 );
$endcache = true ;
}
2007-12-12 16:29:16 +00:00
}
$pagetitle = $rssCat = $catTitle = '' ;
if ( $user ) {
2008-11-25 15:57:29 +00:00
if ( is_int ( $user )) {
$userid = intval ( $user );
} else {
if ( ! ( $userinfo = $userservice -> getUserByUsername ( $user ))) {
$tplVars [ 'error' ] = sprintf ( T_ ( 'User with username %s was not found' ), $user );
$templateservice -> loadTemplate ( 'error.404.tpl' , $tplVars );
exit ();
} else {
2013-03-20 19:00:25 +00:00
$userid = $userinfo [ 'uId' ];
2008-11-25 15:57:29 +00:00
}
}
$pagetitle .= ': ' . $user ;
2007-12-12 16:29:16 +00:00
}
if ( $cat ) {
2008-11-25 15:57:29 +00:00
$catTitle = ': ' . str_replace ( '+' , ' + ' , $cat );
2009-02-17 09:36:20 +00:00
$catTitleWithUrls = ': ' ;
$titleTags = explode ( '+' , filter ( $cat ));
2008-12-18 22:11:03 +00:00
for ( $i = 0 ; $i < count ( $titleTags ); $i ++ ) {
$catTitleWithUrls .= $titleTags [ $i ] . '<a href="' . createUrl ( 'bookmarks' , $user . '/' . aggregateTags ( $titleTags , '+' , $titleTags [ $i ])) . '" title="' . T_ ( 'Remove the tag from the selection' ) . '">*</a> + ' ;
}
$catTitleWithUrls = substr ( $catTitleWithUrls , 0 , strlen ( $catTitleWithUrls ) - strlen ( ' + ' ));
$pagetitle .= $catTitleWithUrls ;
2007-12-12 16:29:16 +00:00
}
2009-05-22 15:15:00 +00:00
else
{
$catTitleWithUrls = '' ;
}
2007-12-12 16:29:16 +00:00
$pagetitle = substr ( $pagetitle , 2 );
// Header variables
$tplVars [ 'loadjs' ] = true ;
// ADD A BOOKMARK
$saved = false ;
$templatename = 'bookmarks.tpl' ;
2008-11-25 15:57:29 +00:00
if ( $userservice -> isLoggedOn () && POST_SUBMITTED != '' ) {
2015-09-13 01:33:39 +00:00
if ( ! $TITLE || ! $ADDRESS ) {
2008-11-25 15:57:29 +00:00
$tplVars [ 'error' ] = T_ ( 'Your bookmark must have a title and an address' );
$templatename = 'editbookmark.tpl' ;
2015-09-13 01:33:39 +00:00
}
else {
$address = array_map ( 'trim' , $ADDRESS );
$valid = 1 ;
foreach ( $address as $value ) {
if ( ! SemanticScuttle_Model_Bookmark :: isValidUrl ( $value )) {
$tplVars [ 'error' ] = T_ ( 'This bookmark URL may not be added' + $value );
$templatename = 'editbookmark.tpl' ;
$valid = 0 ;
break ;
}
}
if ( $valid ) {
$title = array_map ( 'trim' , $TITLE );
$description = trim ( POST_DESCRIPTION );
$privateNote = trim ( POST_PRIVATENOTE );
$status = intval ( POST_STATUS );
$categories = explode ( ',' , $_POST [ 'tags' ]);
$saved = true ;
foreach ( $address as $index => $value ) {
if ( $bookmarkservice -> bookmarkExists ( $value , $currentUserID )) {
// If the bookmark exists already, edit the original
$bookmark = $bookmarkservice -> getBookmarkByAddress ( $value );
$bId = intval ( $bookmark [ 'bId' ]);
$row = $bookmarkservice -> getBookmark ( $bId , true );
$categories = array_unique ( array_merge ( $row [ 'tags' ], $categories ));
if ( ! $bookmarkservice -> updateBookmark ( $bId , $value , $title [ $index ], $description , $privateNote , $status , $categories )) {
$tplvars [ 'error' ] = T_ ( 'Error while saving this bookmark : ' + $value );
$templatename = 'editbookmark.tpl' ;
$saved = false ;
break ;
}
}
// If it's new, save it
elseif ( ! $bookmarkservice -> addBookmark ( $value , $title [ $index ], $description , $privateNote , $status , $categories )) {
$tplVars [ 'error' ] = T_ ( 'There was an error saving this bookmark : ' + $value + ' Please try again or contact the administrator.' );
$templatename = 'editbookmark.tpl' ;
$saved = false ;
break ;
}
}
if ( $saved ) {
if ( POST_POPUP != '' ) {
$tplVars [ 'msg' ] = '<script type="text/javascript">window.close();</script>' ;
}
else {
$tplVars [ 'msg' ] = T_ ( 'Bookmark saved' ) . ' <a href="javascript:history.go(-2)">' . T_ ( '(Come back to previous page.)' ) . '</a>' ;
}
}
}
2008-11-25 15:57:29 +00:00
}
2007-12-12 16:29:16 +00:00
}
2008-11-25 15:57:29 +00:00
if ( GET_ACTION == " add " ) {
// If the bookmark exists already, edit the original
2015-09-13 01:33:39 +00:00
if ( count ( $ADDRESS ) === 1 ) {
if ( $bookmarkservice -> bookmarkExists ( stripslashes ( $ADDRESS [ 0 ]), $currentUserID )) {
$bookmark =& $bookmarkservice -> getBookmarks ( 0 , NULL , $currentUserID , NULL , NULL , NULL , NULL , NULL , NULL , $bookmarkservice -> getHash ( stripslashes ( $ADDRESS [ 0 ])));
$popup = ( GET_POPUP != '' ) ? '?popup=1' : '' ;
header ( 'Location: ' . createURL ( 'edit' , $bookmark [ 'bookmarks' ][ 0 ][ 'bId' ] . $popup ));
exit ();
}
2008-11-25 15:57:29 +00:00
}
$templatename = 'editbookmark.tpl' ;
2007-12-12 16:29:16 +00:00
}
2008-11-25 15:57:29 +00:00
2007-12-12 16:29:16 +00:00
if ( $templatename == 'editbookmark.tpl' ) {
2008-11-25 15:57:29 +00:00
if ( $userservice -> isLoggedOn ()) {
$tplVars [ 'formaction' ] = createURL ( 'bookmarks' , $currentUsername );
if ( POST_SUBMITTED != '' ) {
$tplVars [ 'row' ] = array (
2015-09-13 01:33:39 +00:00
'bTitle' => array_map ( 'stripslashes' , $TITLE ),
'bAddress' => array_map ( 'stripslashes' , $ADDRESS ),
2008-11-25 15:57:29 +00:00
'bDescription' => stripslashes ( POST_DESCRIPTION ),
2015-09-13 01:33:39 +00:00
'bPrivateNote' => stripslashes ( POST_PRIVATENOTE ),
2011-03-17 07:46:15 +00:00
'tags' => ( $_POST [ 'tags' ] ? $_POST [ 'tags' ] : array ()),
2011-03-15 06:53:39 +00:00
'bStatus' => $GLOBALS [ 'defaults' ][ 'privacy' ],
2008-11-25 15:57:29 +00:00
);
2011-03-17 07:46:15 +00:00
$tplVars [ 'tags' ] = $_POST [ 'tags' ];
2009-02-17 09:36:20 +00:00
} else {
if ( GET_COPYOF != '' ) { //copy from bookmarks page
2009-10-29 09:05:37 +00:00
$tplVars [ 'row' ] = $bookmarkservice -> getBookmark ( intval ( GET_COPYOF ), true );
2009-02-17 09:36:20 +00:00
if ( ! $currentUser -> isAdmin ()) {
$tplVars [ 'row' ][ 'bPrivateNote' ] = '' ; //only admin can copy private note
}
} else { //copy from pop-up bookmarklet
$tplVars [ 'row' ] = array (
2015-09-13 01:33:39 +00:00
'bTitle' => array_map ( 'stripslashes' , $TITLE ),
//'bTitle' => stripslashes(GET_TITLE),
'bAddress' => array_map ( 'stripslashes' , $ADDRESS ),
//'bAddress' => stripslashes(GET_ADDRESS),
'bDescription' => stripslashes ( GET_DESCRIPTION ),
'bPrivateNote' => stripslashes ( GET_PRIVATENOTE ),
'tags' => ( GET_TAGS ? explode ( ',' , stripslashes ( GET_TAGS )) : array ()),
'bStatus' => $GLOBALS [ 'defaults' ][ 'privacy' ]
2009-02-17 09:36:20 +00:00
);
}
2008-11-25 15:57:29 +00:00
}
$title = T_ ( 'Add a Bookmark' );
2009-09-17 12:31:53 +00:00
$tplVars [ 'referrer' ] = '' ;;
if ( isset ( $_SERVER [ 'HTTP_REFERER' ])) {
$tplVars [ 'referrer' ] = $_SERVER [ 'HTTP_REFERER' ];
}
2008-11-25 15:57:29 +00:00
$tplVars [ 'pagetitle' ] = $title ;
$tplVars [ 'subtitle' ] = $title ;
$tplVars [ 'btnsubmit' ] = T_ ( 'Add Bookmark' );
$tplVars [ 'popup' ] = ( GET_POPUP != '' ) ? GET_POPUP : null ;
} else {
$tplVars [ 'error' ] = T_ ( 'You must be logged in before you can add bookmarks.' );
}
} else if ( $user && GET_POPUP == '' ) {
2008-12-05 07:25:04 +00:00
$tplVars [ 'sidebar_blocks' ] = array ( 'watchstatus' );
2008-11-25 15:57:29 +00:00
2009-02-10 11:40:07 +00:00
if ( ! $cat ) { //user page without tags
2011-06-27 21:03:31 +00:00
$rssTitle = " My Bookmarks " ;
2008-11-25 15:57:29 +00:00
$cat = NULL ;
$tplVars [ 'currenttag' ] = NULL ;
2009-02-10 11:40:07 +00:00
//$tplVars['sidebar_blocks'][] = 'menu2';
2009-06-18 15:02:52 +00:00
$tplVars [ 'sidebar_blocks' ][] = 'linked' ;
2009-02-10 11:40:07 +00:00
$tplVars [ 'sidebar_blocks' ][] = 'popular' ;
} else { //pages with tags
2011-06-27 21:03:31 +00:00
$rssTitle = " Tags " . $catTitle ;
2008-11-25 15:57:29 +00:00
$rssCat = '/' . filter ( $cat , 'url' );
$tplVars [ 'currenttag' ] = $cat ;
$tplVars [ 'sidebar_blocks' ][] = 'tagactions' ;
2009-02-10 11:40:07 +00:00
//$tplVars['sidebar_blocks'][] = 'menu2';
2008-11-25 15:57:29 +00:00
$tplVars [ 'sidebar_blocks' ][] = 'linked' ;
$tplVars [ 'sidebar_blocks' ][] = 'related' ;
2009-02-10 11:40:07 +00:00
/*$tplVars['sidebar_blocks'][] = 'menu';*/
2008-11-25 15:57:29 +00:00
}
2009-05-05 09:58:44 +00:00
$tplVars [ 'sidebar_blocks' ][] = 'menu2' ;
2008-11-25 15:57:29 +00:00
$tplVars [ 'popCount' ] = 30 ;
2008-12-19 00:22:32 +00:00
//$tplVars['sidebar_blocks'][] = 'popular';
2008-11-25 15:57:29 +00:00
$tplVars [ 'userid' ] = $userid ;
2013-03-20 19:00:25 +00:00
$tplVars [ 'userinfo' ] = $userinfo ;
2008-11-25 15:57:29 +00:00
$tplVars [ 'user' ] = $user ;
$tplVars [ 'range' ] = 'user' ;
// Pagination
2009-05-19 15:59:55 +00:00
$perpage = getPerPageCount ( $currentUser );
2008-11-25 15:57:29 +00:00
if ( intval ( GET_PAGE ) > 1 ) {
2009-10-29 09:05:37 +00:00
$page = intval ( GET_PAGE );
2008-11-25 15:57:29 +00:00
$start = ( $page - 1 ) * $perpage ;
} else {
$page = 0 ;
$start = 0 ;
}
// Set template vars
$tplVars [ 'rsschannels' ] = array (
2011-06-27 21:03:31 +00:00
array (
sprintf ( T_ ( '%s: %s' ), $sitename , $rssTitle ),
createURL ( 'rss' , filter ( $user , 'url' ))
. $rssCat . '?sort=' . getSortOrder ()
)
2008-11-25 15:57:29 +00:00
);
2011-05-17 04:24:43 +00:00
if ( $userservice -> isLoggedOn ()) {
$currentUsername = $currentUser -> getUsername ();
if ( $userservice -> isPrivateKeyValid ( $currentUser -> getPrivateKey ())) {
array_push (
$tplVars [ 'rsschannels' ],
array (
2011-06-27 21:03:31 +00:00
sprintf (
T_ ( '%s: %s (+private %s)' ),
$sitename , $rssTitle , $currentUsername
),
createURL ( 'rss' , filter ( $currentUsername , 'url' ))
. $rssCat
. '?sort=' . getSortOrder ()
. '&privateKey=' . $currentUser -> getPrivateKey ()
2011-05-17 04:24:43 +00:00
)
);
}
}
2008-11-25 15:57:29 +00:00
$tplVars [ 'page' ] = $page ;
$tplVars [ 'start' ] = $start ;
$tplVars [ 'bookmarkCount' ] = $start + 1 ;
2013-03-20 19:00:25 +00:00
$bookmarks = $bookmarkservice -> getBookmarks ( $start , $perpage , $userid , $cat , null , getSortOrder ());
2008-11-25 15:57:29 +00:00
$tplVars [ 'total' ] = $bookmarks [ 'total' ];
2013-03-20 19:00:25 +00:00
$tplVars [ 'bookmarks' ] = $bookmarks [ 'bookmarks' ];
2008-11-25 15:57:29 +00:00
$tplVars [ 'cat_url' ] = createURL ( 'bookmarks' , '%s/%s' );
$tplVars [ 'nav_url' ] = createURL ( 'bookmarks' , '%s/%s%s' );
if ( $userservice -> isLoggedOn () && $user == $currentUsername ) {
2008-12-18 22:11:03 +00:00
$tplVars [ 'pagetitle' ] = T_ ( 'My Bookmarks' ) . $catTitle ;
2011-08-18 14:18:28 +00:00
$tplVars [ 'subtitlehtml' ] = T_ ( 'My Bookmarks' ) . $catTitleWithUrls ;
2008-11-25 15:57:29 +00:00
} else {
2012-01-21 11:10:33 +00:00
$tplVars [ 'pagetitle' ] = $user . ': ' . $cat ;
$tplVars [ 'subtitlehtml' ] = $user . $catTitleWithUrls ;
2008-11-25 15:57:29 +00:00
}
2007-12-12 16:29:16 +00:00
}
2008-01-23 14:47:35 +00:00
$tplVars [ 'summarizeLinkedTags' ] = true ;
2008-05-14 08:55:38 +00:00
$tplVars [ 'pageName' ] = PAGE_BOOKMARKS ;
2008-01-23 14:47:35 +00:00
2009-02-04 14:00:16 +00:00
2007-12-12 16:29:16 +00:00
$templateservice -> loadTemplate ( $templatename , $tplVars );
if ( $usecache && $endcache ) {
2008-11-25 15:57:29 +00:00
// Cache output if existing copy has expired
$cacheservice -> End ( $hash );
2007-12-12 16:29:16 +00:00
}
?>