<?php
/*
* This file is part of the Booby project.
* The booby project is located at the following location:
* http://www.nauta.be/booby/
*
* Booby - Copyright (c) 2003 - 2004 Barry Nauta
*
* The Booby project is released under the General Public License
* More detailes in the file 'gpl.html' or on the following
* website: http://www.gnu.org and look for licenses
*
* Enjoy :-)
*/
require_once ('base/Controller.php');
require_once ('plugins/bookmarks/util/BookmarkUtils.php');
require_once ('plugins/bookmarks/model/BookmarkPreferences.php');
require_once ('plugins/bookmarks/model/BookmarkServices.php');
require_once ('plugins/bookmarks/model/BookmarkFactory.php');
require_class ('RightsManagerImpl', 'plugins/bookmarks/RightsManagerImpl.php'); // added by Michael
require_class ('RequestCast', 'base/util/request/RequestCast.class.php'); // added by Michael
/**
* The Bookmark Controller
*
* @package be.nauta.booby.plugins.bookmarks
* @author Barry Nauta July 2003
* @copyright
*
* Copyright (c) 2003 - 2004 Barry Nauta
*
* The Booby project is released under the General Public License
* More detailes on the following
* website: <code>http://www.gnu.org</code>
* and look for licenses
*/
class BookmarkController extends Controller
{
/**
* Constructor.
* Makes sure that the appropriate operations are instantiated.
*/
function BookmarkController ()
{
parent::Controller ();
$this->operations = new BookmarkServices ();
$this->preferences = new BookmarkPreferences ();
$this->itemFactory = new BookmarkFactory ();
$this->rightsManager = new RightsManagerImpl();
$this->pluginName = 'bookmarks';
$this->title = 'Booby - Bookmarks';
$this->itemName = 'Bookmark';
}
/**
* Returns the actions defined for this item only
* Modified by Michael : added navigationMode and rightsmanagement
*
* @return array an array of item specific actions (like search, import etc.)
*/
function getActions ()
{
$dictionary = $this->getDictionary ();
/*
* Actions
*/
$actions[0]['name'] = $dictionary['actions'];
if($this->rightsManager->isGranted($this->getParentId (), "add"))
$actions[0]['contents'][] = array(
'href' => 'BookmarkController.php?action=add&parentId='.$this->getParentId (),
'name' => $dictionary['add']
);
/* This works in my version with 1 template file, if you are interested, tell me. (Michael)
if($this->rightsManager->isGranted($this->getParentId (), "addFolder"))
$actions[0]['contents'][] = array(
'href' => 'BookmarkController.php?action=add&isParent=1&parentId='.$this->getParentId (),
'name' => $dictionary['addFolder']
);
if($this->rightsManager->isGranted($this->getParentId (), "addNode"))
$actions[0]['contents'][] = array(
'href' => 'BookmarkController.php?action=add&isParent=0&parentId='.$this->getParentId (),
'name' => $dictionary['addNode']
);
*/
if($this->rightsManager->isGranted($this->getParentId (), "multipleSelectPre"))
$actions[0]['contents'][] = array(
'href' => 'BookmarkController.php?action=multipleSelectPre&parentId='.$this->getParentId(),
'name' => $dictionary['multipleSelect']
);
if($this->rightsManager->isGranted($this->getParentId (), "import"))
$actions[0]['contents'][] = array(
'href' => 'BookmarkController.php?action=import',
'name' => $dictionary['import']
);
if($this->rightsManager->isGranted($this->getParentId (), "export"))
$actions[0]['contents'][] = array(
'href' => 'BookmarkController.php?action=export',
'name' => $dictionary['export']
);
if($this->rightsManager->isGranted($this->getParentId (), "search"))
$actions[0]['contents'][] = array(
'href' => 'BookmarkController.php?action=search',
'name' => $dictionary['search']
);
/*
* Views
*/
$actions[1]['name'] = $dictionary['view'];
if($this->rightsManager->isGranted($this->getParentId (), "view"))
{
$actions[1]['contents'][] = array('href' => 'BookmarkController.php?expand=*',
'name' => $dictionary['expand']);
$actions[1]['contents'][] = array('href' => 'BookmarkController.php?expand=0',
'name' => $dictionary['collapse']);
$actions[1]['contents'][] = array('href' => 'BookmarkController.php?action=setYahooTree&parentId='.$this->getParentId (),
'name' => $dictionary['yahooTree']);
$actions[1]['contents'][] = array('href' => 'BookmarkController.php?action=setExplorerTree&parentId='.$this->getParentId (),
'name' => $dictionary['explorerTree']);
$actions[1]['contents'][] = array('href' => 'BookmarkController.php?action=setModePublic&parentId='.$this->getParentId (),
'name' => $dictionary['setModePublic']);
$actions[1]['contents'][] = array('href' => 'BookmarkController.php?action=setModePrivate&parentId='.$this->getParentId (),
'name' => $dictionary['setModePrivate']);
}
/*
* Sort
*/
$actions[2]['name'] = $dictionary['sort'];
if($this->rightsManager->isGranted($this->getParentId (), "sort"))
{
$actions[2]['contents'][] = array('href'=> 'BookmarkController.php?action=sort&order=DESC&field=when_visited',
'name' => $dictionary['last_visited']);
$actions[2]['contents'][] = array('href'=> 'BookmarkController.php?action=sort&order=DESC&field=visitCount',
'name' => $dictionary['most_visited']);
$actions[2]['contents'][] = array('href'=> 'BookmarkController.php?action=sort&order=DESC&field=when_created',
'name' => $dictionary['last_created']);
$actions[2]['contents'][] = array('href'=> 'BookmarkController.php?action=sort&order=DESC&field=when_modified',
'name' => $dictionary['last_modified']);
}
/*
* Preferences
*/
if($this->rightsManager->isGranted($this->getParentId (), "preferences"))
{
$actions[3]['name'] = $dictionary['preferences'];
$actions[3]['contents'][] = array('href'=> 'BookmarkController.php?action=modifyPreferencesPre',
'name' => $dictionary['modify']);
}
return $actions;
}
/**
* Activate. Basically this means that the appropriate actions are executed and an optional result is returned
* to be processed/displayed
*/
function activate ()
{
switch ($this->getAction ())
{
// Modified by Michael. I wonder if this "directAction" I added is not nonsens...
case "add":
$this->directAction ($this->getAction ());
break;
// this is to show an Item in a special showItem Page
case "showItem":
$this->directAction ($this->getAction (), true);
break;
// Added by Michael. Default navigation mode. If used, change in other plugins.
case "setModePublic":
$_SESSION['navigationMode']='public';
$this->navigationMode ='public';
$this->getShowItemsParameters ();
break;
case "setModePrivate":
$_SESSION['navigationMode']='private';
$this->navigationMode ='private';
$this->getShowItemsParameters ();
break;
case "addBookmark":
$this->addItemAction ();
break;
case "modify":
$this->modifyAction ();
break;
case "modifyBookmark":
$this->modifyItemAction ();
$this->getShowItemsParameters ();
break;
case "move":
$this->moveAction ();
break;
case "moveItem":
$this->moveItemAction ();
$this->getShowItemsParameters ();
break;
case "import":
case "export":
case "search":
$this->renderer = $this->getAction ().'Bookmarks';
break;
case "searchBookmarks":
$this->searchItemAction ();
break;
case "deleteBookmark":
$this->deleteItemAction ();
$this->getShowItemsParameters ();
break;
case "quickmark":
$bookmark = new Bookmark (null, $this->getUserName (), 0, false,
$_GET['name'], null, 'private', null, null, null, null,
$_GET['locator'], 0);
$this->itemId = $this->operations->addItem ($this->getUserName (), $bookmark);
$this->getShowItemsParameters ();
break;
case "showBookmark":
$this->operations->updateVisiteCount ($this->getUserName (), $this->itemId);
$bookmark = $this->operations->getItem
($this->getUserName (), $this->itemId);
header ("Location: " . $bookmark->locator);
exit;
break;
case "importBookmarks":
$bookmarkUtils = new BookmarkUtils ();
// first set the execution time to zero: unlimited.
// Not that this has no effect if safe_mode is on
set_time_limit (0);
$importType=$_POST['importType'];
$parentId = $_POST['parentId'];
$importFile = $_FILES['importFile'];
if ($importType == 'Opera')
{
$bookmarkUtils->importOperaBookmarks
($this->getUserName (), $importFile['tmp_name'], $this, $parentId);
}
else if ($importType == 'Netscape')
{
$bookmarkUtils->importNetscapeBookmarks
($this->getUserName (), $importFile['tmp_name'], $this, $parentId);
}
else
{
die ($importType . " is not yet supported for importing bookmarks");
}
$this->getShowItemsParameters ();
// We need to force a redirection to this page, otherwise a reload means
// resending the POST data and your items will be imported twice
header ("Location: BookmarkController.php");
exit ();
break;
case "exportBookmarks":
$bookmarkUtils = new BookmarkUtils ();
$exportType=$_POST['exportType'];
$parentId = $_POST['parentId'];
if ($exportType == 'Opera')
{
Header ("Content-type: text/plain");
echo ("Opera Hotlist version 2.0\n\n");
$bookmarkUtils->exportOperaBookmarks
($this->getUserName (), $parentId, $this);
exit ();
}
else if ($exportType == 'Netscape')
{
Header ("Content-type: text/plain");
$bookmarkUtils->exportNetscapeBookmarks
($this->getUserName (), $parentId, $this);
exit ();
}
else
{
die ($exportType . " is not yet supported for exporting bookmarks");
}
break;
case "setYahooTree":
$_SESSION['bookmarkTree']='Yahoo';
$this->getShowItemsParameters ();
break;
case "setExplorerTree":
$_SESSION['bookmarkTree']='Explorer';
$this->getShowItemsParameters ();
break;
case "sort":
$field = $_GET['field'];
$order = $_GET['order'];
$this->sortAllAction ($field, $order);
break;
case "modifyPreferencesPre":
$this->renderObjects =
$this->preferences->getAllPreferences ($this->getUserName ());
$this->renderer = 'modifyPreferences';
break;
case "modifyPreferencesPost":
$this->preferences->setPreference ($this->getUserName (), $_POST['name'], $_POST['value']);
$_SESSION['bookmarkTree']=
$this->preferences->getPreferenceValue ($this->getUserName (), 'bookmarkTree');
$_SESSION['bookmarkOverlib']=
$this->preferences->getPreferenceValue ($this->getUserName (), 'bookmarkOverlib');
$_SESSION['bookmarkYahooTreeColumnCount']=
$this->preferences->getPreferenceValue ($this->getUserName (), 'bookmarkYahooTreeColumnCount');
$_SESSION['bookmarkNewWindowTarget']=
$this->preferences->getPreferenceValue ($this->getUserName (), 'bookmarkNewWindowTarget');
$this->getShowItemsParameters ();
break;
case "multipleSelectPre":
// Hmmm... one downside: we will show the expanded list afterwards...
$_SESSION['bookmarkExpand']= '*';
$this->multipleSelectAction ();
break;
case "multipleSelectPost":
$itemIds = array_keys ($_POST, "itemId");
if (isset ($_POST['move']))
{
$this->moveMultipleAction ($itemIds);
}
else if (isset ($_POST['delete']))
{
foreach ($itemIds as $itemId)
{
$this->operations->deleteItem ($this->getUserName (), $itemId);
}
$this->getShowItemsParameters ();
}
break;
case "moveMultipleItemsPost":
$itemIds = explode (",", $_GET['itemIds']);
$parentId = $_GET['parentId'];
foreach ($itemIds as $itemId)
{
//die ($itemId.'} '.$parentId);
$this->operations->moveItem ($this->getUserName (), $itemId, $parentId);
}
$this->getShowItemsParameters ();
break;
default:
if ($_SESSION['bookmarkTree'] == null)
{
$_SESSION['bookmarkTree']=
$this->preferences->getPreferenceValue ($this->getUserName (), 'bookmarkTree');
}
if ($_SESSION['bookmarkOverlib'] == null)
{
$_SESSION['bookmarkOverlib']=
$this->preferences->getPreferenceValue ($this->getUserName (), 'bookmarkOverlib');
}
if ($_SESSION['bookmarkYahooTreeColumnCount'] == null)
{
$_SESSION['bookmarkYahooTreeColumnCount']=
$this->preferences->getPreferenceValue ($this->getUserName (), 'bookmarkYahooTreeColumnCount');
}
if ($_SESSION['bookmarkNewWindowTarget'] == null)
{
$_SESSION['bookmarkNewWindowTarget']=
$this->preferences->getPreferenceValue ($this->getUserName (), 'bookmarkNewWindowTarget');
}
$this->getShowItemsParameters ();
break;
}
}
/**
* Returns the list of current expanded items for the controller
*
* @return string list of commanseperated item numbers
*/
function getExpanded ()
{
$expand=0;
if (isset ($_GET['expand']))
{
$expand = $_GET['expand'];
$_SESSION['bookmarkExpand']=$expand;
}
else if (isset ($_SESSION['bookmarkExpand']))
{
$expand = $_SESSION['bookmarkExpand'];
}
return $expand;
}
}
$controller = new BookmarkController ();
$controller -> activate ();
$controller -> display ();
?>