<?php
/**
* Offering API calls for other handlers or the main application
* @package phlyMail Nahariya 4.0+ Default branch
* @subpackage Handler Bookmarks
* @copyright 2009 phlyLabs, Berlin (http://phlylabs.de)
* @version 0.0.2 2009-08-14
*/
// Only valid within phlyMail
if (!defined('_IN_PHM_')) die();
class api_bookmarks
{
private $DB = false;
private $errortext = false;
/**
* Constructor method, this special constructor also attempts to create the required
* docroot of the email storage for the given user
*
* @param array reference public settings structure
* @param int ID of the user to perform the operation for
* @return boolean true on success, false otherwise
* @since 0.0.1
*/
public function __construct(&$_PM_, $uid)
{
$this->_PM_ = $_PM_;
$this->uid = $uid;
require_once(dirname(__FILE__).'/driver.mysql.php');
$this->DB = new bookmarks_driver($uid);
return is_object($this->DB);
}
/**
* Returns errors which happened
* @param void
* @return string error message(s)
* @since 0.0.1
*/
public function get_errors() { return $this->errortext; }
/**
* Returns a list of existing folders for a given user
* @param bool If set to true, only local folders will be returned (no LDAP or others)
* @return array Folder list with various meta data
* @since 0.0.2
*/
public function give_folderlist($local_only = false)
{
// For a correct translation we unfortunately have to read in a messages file
$d = opendir(dirname(__FILE__));
while (false !== ($f = readdir($d))) {
if ('.' == $f) continue;
if ('..' == $f) continue;
if (preg_match('!^lang\.'.$GLOBALS['WP_msg']['language'].'(.*)\.php$!', $f)) {
require_once(dirname(__FILE__).'/'.$f);
break;
}
}
$return = array('root' => false);
foreach ($this->DB->get_folderlist(true) as $k => $v) {
$return[$k] = array
('folder_path' => $k
,'icon' => $this->_PM_['path']['theme'].'/icons/'.(($v['owner'] == 0) ? 'contactsfolder_global' : 'folder_def').'.png'
,'big_icon' => $this->_PM_['path']['theme'].'/icons/'.(($v['owner'] == 0) ? 'contactsfolder_global' : 'folder_def').'_big.gif'
,'foldername' => $v['name']
,'type' => 2
,'childof' => 'root'
,'has_folders' => 0
,'has_items' => 1
,'level' => $v['level']+1
,'unread' => 0
,'unseen' => 0
,'stale' => 0
,'visible' => 1
);
}
$return['root'] = array
('folder_path' => 0
,'icon' => $this->_PM_['path']['theme'].'/icons/bookmarks.png'
,'big_icon' => $this->_PM_['path']['theme'].'/icons/bookmarks_big.gif'
,'foldername' => $WP_msg['MainFoldername']
,'type' => 2
,'subdirs' => (!empty($return)) ? 1 : 0
,'has_folders' => (!empty($return)) ? 1 : 0
,'has_items' => 1
,'childof' => 0
,'level' => 0
);
return $return;
}
}
?>