function calendar_admin_add_event() { // Security check if (!xarSecurityCheck('Admincalendar')) { return; } // Generate a one-time authorisation code for this operation $data = xarMod::apiFunc('calendar', 'admin', 'get_calendars'); $data['authid'] = xarSecGenAuthKey(); $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal')); // Variables from phpIcalendar config.inc.php $data['updatebutton'] = xarVarPrepForDisplay(xarML('Create event')); //TODO: should I include this stuff? --amoro /* $hooks = xarModCallHooks('module', 'modifyconfig', 'calendar', array('module' => 'calendar')); if (empty($hooks)) { $data['hooks'] = ''; } elseif (is_array($hooks)) { $data['hooks'] = join('', $hooks); } else { $data['hooks'] = $hooks; } */ // Return the template variables defined in this function return $data; }
/** * Modify Function to the Blocks Admin * @author Jason Judge * @param $blockinfo array containing title,content */ public function modify(array $data = array()) { $data = $this->getContent(); // Get a list of all pages for the drop-downs. // Get the tree of all pages, without the DD for speed. $data['all_pages'] = xarMod::apiFunc('publications', 'user', 'getpagestree', array('dd_flag' => false, 'key' => 'pid')); // Implode the names for each page into a path for display. // TODO: move this into getpagestree foreach ($data['all_pages']['pages'] as $key => $page) { $data['all_pages']['pages'][$key]['slash_separated'] = '/' . implode('/', $page['namepath']); } // Get the descriptions together for the current root ids. // TODO: we could prune the 'add root page' list so it only includes // the pages which are not yet under one of the selected root pages. // That would just be an extra little usability touch. $data['root_ids'] = array_flip($data['root_ids']); foreach ($data['root_ids'] as $key => $value) { if (isset($data['all_pages']['pages'][$key])) { $data['root_ids'][$key] = $data['all_pages']['pages'][$key]['slash_separated']; } else { $data['root_ids'][$key] = xarML('Unknown'); } } $data['prune_ids'] = array_flip($data['prune_ids']); foreach ($data['prune_ids'] as $key => $value) { if (isset($data['all_pages']['pages'][$key])) { $data['prune_ids'][$key] = $data['all_pages']['pages'][$key]['slash_separated']; } else { $data['prune_ids'][$key] = xarML('Unknown'); } } // $vars['bid'] = $blockinfo['bid']; return $data; }
/** * Publications Module * * @package modules * @subpackage publications module * @category Third Party Xaraya Module * @version 2.0.0 * @copyright (C) 2011 Netspan AG * @license GPL {@link http://www.gnu.org/licenses/gpl.html} * @author Marc Lutolf <*****@*****.**> */ function publications_user_view_pages($args) { extract($args); if (!xarSecurityCheck('ManagePublications')) { return; } // Accept a parameter to allow selection of a single tree. xarVarFetch('contains', 'id', $contains, 0, XARVAR_NOT_REQUIRED); $data = xarMod::apiFunc('publications', 'user', 'getpagestree', array('key' => 'index', 'dd_flag' => false, 'tree_contains_pid' => $contains)); if (empty($data['pages'])) { // TODO: pass to template. return $data; //xarML('NO PAGES DEFINED'); } else { $data['pages'] = xarMod::apiFunc('publications', 'tree', 'array_maptree', $data['pages']); } $data['contains'] = $contains; // Check modify and delete privileges on each page. // EditPage - allows basic changes, but no moving or renaming (good for sub-editors who manage content) // AddPage - new pages can be added (further checks may limit it to certain page types) // DeletePage - page can be renamed, moved and deleted if (!empty($data['pages'])) { // Bring in the access property for security checks sys::import('modules.dynamicdata.class.properties.master'); $accessproperty = DataPropertyMaster::getProperty(array('name' => 'access')); $accessproperty->module = 'publications'; $accessproperty->component = 'Page'; foreach ($data['pages'] as $key => $page) { $thisinstance = $page['name'] . ':' . $page['ptid']['name']; // Do we have admin access? $args = array('instance' => $thisinstance, 'level' => 800); $adminaccess = $accessproperty->check($args); // Decide whether this page can be modified by the current user /*try { $args = array( 'instance' => $thisinstance, 'group' => $page['access']['modify_access']['group'], 'level' => $page['access']['modify_access']['level'], ); } catch (Exception $e) { $args = array(); }*/ $data['pages'][$key]['edit_allowed'] = $adminaccess || $accessproperty->check($args); /* // Decide whether this page can be deleted by the current user try { $args = array( 'instance' => $thisinstance, 'group' => $page['access']['delete_access']['group'], 'level' => $page['access']['delete_access']['level'], ); } catch (Exception $e) { $args = array(); }*/ $data['pages'][$key]['delete_allowed'] = $adminaccess || $accessproperty->check($args); } } return $data; }
function wurfl_admin_modifyconfig() { // Security Check if (!xarSecurityCheck('AdminWurfl')) { return; } if (!xarVarFetch('phase', 'str:1:100', $phase, 'modify', XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY)) { return; } if (!xarVarFetch('tab', 'str:1:100', $data['tab'], 'general', XARVAR_NOT_REQUIRED)) { return; } $data['module_settings'] = xarMod::apiFunc('base', 'admin', 'getmodulesettings', array('module' => 'wurfl')); $data['module_settings']->setFieldList('items_per_page, use_module_alias, module_alias_name, enable_short_urls'); $data['module_settings']->getItem(); switch (strtolower($phase)) { case 'modify': default: switch ($data['tab']) { case 'general': break; case 'tab2': break; case 'tab3': break; default: break; } break; case 'update': // Confirm authorisation code if (!xarSecConfirmAuthKey()) { return; } switch ($data['tab']) { case 'general': $isvalid = $data['module_settings']->checkInput(); if (!$isvalid) { return xarTplModule('wurfl', 'admin', 'modifyconfig', $data); } else { $itemid = $data['module_settings']->updateItem(); } break; case 'tab2': break; case 'tab3': break; default: break; } xarController::redirect(xarModURL('wurfl', 'admin', 'modifyconfig', array('tab' => $data['tab']))); // Return return true; break; } $data['authid'] = xarSecGenAuthKey(); return $data; }
function calendar_admin_viewevents($args) { if (!xarSecurityCheck('EditCalendar')) { return; } $data['object'] = xarMod::apiFunc('dynamicdata', 'user', 'getobjectlist', array('name' => 'calendar_event')); $data['object']->getItems(); return xarTplModule('calendar', 'admin', 'view', $data); }
function publications_admin_templates_page($args) { if (!xarSecurityCheck('AdminPublications')) { return; } extract($args); if (!xarVarFetch('confirm', 'int', $confirm, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('ptid', 'id', $data['ptid'], 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('itemid', 'id', $data['itemid'], 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('file', 'str', $data['file'], 'summary', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('source_data', 'str', $data['source_data'], '', XARVAR_NOT_REQUIRED)) { return; } if (empty($data['itemid']) || empty($data['ptid'])) { return xarResponse::NotFound(); } $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $pubtype = explode('_', $pubtypeobject->properties['name']->value); $pubtype = isset($pubtype[1]) ? $pubtype[1] : $pubtype[0]; $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $basepath = sys::code() . "modules/publications/xartemplates/objects/" . $pubtype; $sourcefile = $basepath . "/" . $data['file'] . "_" . $data['itemid'] . ".xt"; $overridepath = "themes/" . xarModVars::get('themes', 'default_theme') . "/modules/publications/objects/" . $pubtype; $overridefile = $overridepath . "/" . $data['file'] . "-" . $data['itemid'] . ".xt"; // If we are saving, write the file now if ($confirm && !empty($data['source_data'])) { xarMod::apiFunc('publications', 'admin', 'write_file', array('file' => $overridefile, 'data' => $data['source_data'])); } // Let the template know what kind of file this is if (file_exists($overridefile)) { $data['filetype'] = 'theme'; $filepath = $overridefile; $data['writable'] = is_writable($overridefile); } else { $data['filetype'] = 'module'; $filepath = $sourcefile; $data['writable'] = is_writeable_dir($overridepath); } $data['source_data'] = trim(xarMod::apiFunc('publications', 'admin', 'read_file', array('file' => $filepath))); // Initialize the template if (empty($data['source_data'])) { $data['source_data'] = '<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout">'; $data['source_data'] .= "\n"; $data['source_data'] .= "\n" . '</xar:template>'; } $data['files'] = array(array('id' => 'summary', 'name' => 'summary display'), array('id' => 'detail', 'name' => 'detail display')); return $data; }
function calendar_user_year() { $data = xarMod::apiFunc('calendar', 'user', 'getUserDateTimeInfo'); $Year = new Calendar_Year($data['cal_year']); $Year->build(); // TODO: find a better way to handle this $data['Year'] =& $Year; $data['cal_sdow'] = CALENDAR_FIRST_DAY_OF_WEEK; return $data; }
function publications_admin_stylesheet_type($args) { if (!xarSecurityCheck('AdminPublications')) { return; } extract($args); if (!xarVarFetch('confirm', 'int', $confirm, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('ptid', 'id', $data['ptid'], xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('file', 'str', $data['file'], '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('source_data', 'str', $data['source_data'], '', XARVAR_NOT_REQUIRED)) { return; } $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $pubtype = explode('_', $pubtypeobject->properties['name']->value); $pubtype = isset($pubtype[1]) ? $pubtype[1] : $pubtype[0]; $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $basepath = sys::code() . "modules/publications/xarstyles"; $sourcefile = $basepath . "/" . $data['file'] . ".css"; $overridepath = "themes/" . xarModVars::get('themes', 'default_theme') . "/modules/publications/style"; $overridefile = $overridepath . "/" . $data['file'] . ".css"; // If we are saving, write the file now if ($confirm && !empty($data['file']) && !empty($data['source_data'])) { xarMod::apiFunc('publications', 'admin', 'write_file', array('file' => $overridefile, 'data' => $data['source_data'])); } // Let the template know what kind of file this is if (empty($data['file'])) { $data['filetype'] = 'empty'; $filepath = ''; $data['writable'] = 0; } elseif (file_exists($overridefile)) { $data['filetype'] = 'theme'; $filepath = $overridefile; $data['writable'] = is_writable($overridefile); } elseif (file_exists($sourcefile)) { $data['filetype'] = 'module'; $filepath = $sourcefile; $data['writable'] = is_writeable_dir($overridepath); } else { $data['filetype'] = 'unknown'; $filepath = $overridefile; $data['writable'] = is_writeable_dir($overridepath); } $data['source_data'] = trim(xarMod::apiFunc('publications', 'admin', 'read_file', array('file' => $filepath))); return $data; }
function calendar_admin_view_calendars() { // Security check if (!xarSecurityCheck('Admincalendar')) { return; } // Generate a one-time authorisation code for this operation $data['authid'] = xarSecGenAuthKey(); $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal')); // Return the template variables defined in this function $data['calendars'] = xarMod::apiFunc('calendar', 'user', 'getall'); return $data; }
/** * Show some predefined form field in a template * * @param $args array containing the definition of the field (object, itemid, property, value, ...) * @return string containing the HTML (or other) text to output in the BL template */ function publications_userapi_fieldoutput($args) { extract($args); if (!isset($object) || !isset($itemid) || !isset($field)) { return ''; } sys::import('modules.dynamicdata.class.objects.master'); $object = DataObjectMaster::getObject(array('name' => $object)); $itemid = xarMod::apiFunc('publications', 'user', 'gettranslationid', array('id' => $itemid)); $object->getItem(array('itemid' => $itemid)); $field = $object->properties[$field]->getValue(); return $field; }
/** * Check a user agent identiication against the requesting device * */ function wurfl_userapi_check_device($args = array()) { if (empty($args['agent'])) { $args['agent'] = 'generic'; } if (empty($args['mode'])) { $args['mode'] = 'performance'; } $requestingDevice = xarMod::apiFunc('wurfl', 'user', 'get_device', array('mode' => $args['mode'])); $device_id = $requestingDevice->id; $check = preg_match("/" . $args['agent'] . "/i", $device_id); return $check; }
function calendar_userapi_getMonthNameLong($args) { extract($args); unset($args); if (!isset($month)) { $month = date('m'); } // make sure we have a valid month value if (!xarVarValidate('int:1:12', $month)) { return; } $c = xarMod::apiFunc('calendar', 'user', 'factory', 'calendar'); return $c->MonthLong($month); }
function calendar_admin_create_calendars() { // Get parameters // TODO HELPNEEDED here: how do I handle this (e.g. missing calname should return a // message if (!xarVarFetch('add_calendar', 'isset', $add_calendar)) { return; } if (!xarVarFetch('calname', 'str:1:', $calname)) { return; } if (!xarVarFetch('addtype', 'str:1:', $addtype)) { return; } if (!xarVarFetch('location', 'str:1:', $location, '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('uri', 'str:1:', $uri, '', XARVAR_NOT_REQUIRED)) { return; } // Confirm Auth Key if (!xarSecConfirmAuthKey()) { return; } // Security Check // TODO // if(!xarSecurityCheck('AddCalendar', 0, 'Calendar')) {return;} // Check if module name has already been used. $checkname = xarMod::apiFunc('calendar', 'user', 'get', array('calname' => $calname)); if (!empty($checkname)) { $msg = xarML('Calendar name "#(1)" already exists. Please go back and enter a different name', $calname); throw new Exception($msg); } if ($addtype == 'db') { $fileuri = 'a'; } elseif ($addtype == 'file') { $fileuri = $location; } elseif ($addtype == 'uri') { $fileuri = $uri; } // Pass to API $calid = xarMod::apiFunc('calendar', 'admin', 'create_calendars', array('calname' => $calname, 'fileuri' => $fileuri, 'addtype' => $addtype)); if (!$calid) { return; } // Go on and edit the new instance xarController::redirect(xarModURL('calendar', 'admin', 'add_calendars', array('calid' => $calid, 'calname' => $calname))); }
function display(array $data = array()) { $data = parent::display($data); if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', xarModVars::get('calendar', 'pearcalendar_root')); } include_once CALENDAR_ROOT . 'Month/Weekdays.php'; include_once CALENDAR_ROOT . 'Decorator/Textual.php'; sys::import("modules.calendar.class.Calendar.Decorator.Xaraya"); // Build the month $data['content'] = xarMod::apiFunc('calendar', 'user', 'getuserdatetimeinfo'); $data['content']['MonthCal'] = new Calendar_Month_Weekdays($data['content']['cal_year'], $data['content']['cal_month'], CALENDAR_FIRST_DAY_OF_WEEK); $data['content']['MonthCal']->build(); return $data; }
public function display() { $data = $this->getContent(); // Setup featured item if ($data['fillerid'] > 0) { $fillerid = xarMod::apiFunc('publications', 'user', 'gettranslationid', array('id' => $data['fillerid'])); $ptid = xarMod::apiFunc('publications', 'user', 'getitempubtype', array('itemid' => $data['fillerid'])); $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $ptid)); $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $data['object']->getItem(array('itemid' => $data['fillerid'])); return $data; } return; }
/** * Wrapper for the dayIs method of the calendar class * @author Roger Raymond <*****@*****.**> * @version $Id: dayis.php,v 1.2 2003/06/24 21:23:06 roger Exp $ * @param int $day 0 - 6 [Sun - Sat] * @param int $date valid date YYYYMMDD * @return bool true/false depending on day looking for and the date */ function calendar_userapi_dayIs($args) { extract($args); unset($args); // make sure we have a valid day value if (!xarVarValidate('int:0:7', $day)) { return; } // TODO: Revisit this later and make a new validator for it // make sure we have a valid date if (!xarVarValidate('int::', $date)) { return; } $c = xarMod::apiFunc('calendar', 'user', 'factory', 'calendar'); return $c->dayIs($day, $date); }
function calendar_userapi_getmonthstructure($args = array()) { extract($args); unset($args); if (!isset($month)) { return; } if (!isset($year)) { return; } xarVarValidate('int:1:12', $month); xarVarValidate('int::', $year); xarVarFetch('cal_sdow', 'int:0:6', $cal_sdow, 0); $c = xarMod::apiFunc('calendar', 'user', 'factory', 'calendar'); $c->setStartDayOfWeek($cal_sdow); // echo the content to the screen return $c->getCalendarMonth($year . $month); }
function calendar_admin_add_calendars() { // Security check // if (!xarSecurityCheck('AddCalendar',0,'Calendar')) return; if (!xarVarFetch('calid', 'int:0:', $calid, '0', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('calname', 'str', $calname, '', XARVAR_NOT_REQUIRED)) { return; } $data = xarMod::apiFunc('calendar', 'admin', 'get_calendars'); // Generate a one-time authorisation code for this operation $data['authid'] = xarSecGenAuthKey(); $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal')); $data['addbutton'] = xarVarPrepForDisplay(xarML('Add calendar')); $data['message'] = xarVarPrepForDisplay(xarML('Created calendar with name "#(1)", ID #(2)', $calname, $calid)); $data['calid'] = $calid; return $data; }
/** * Call a test page * */ function wurfl_admin_test() { if (!xarSecurityCheck('ManageWurfl')) { return; } sys::import('modules.wurfl.wurfl_init'); $wurflManager = wurfl_init(); $data['wurflInfo'] = $wurflManager->getWURFLInfo(); if (!xarVarFetch('ua', 'str', $data['ua'], '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('mode', 'str', $data['mode'], 'performance', XARVAR_NOT_REQUIRED)) { return; } $data['requestingDevice'] = xarMod::apiFunc('wurfl', 'user', 'get_device', array('ua' => $data['ua'], 'mode' => $data['mode'])); if (empty($data['ua'])) { $data['ua'] = $_SERVER['HTTP_USER_AGENT']; } return $data; }
function calendar_user_submit() { xarVarFetch('cal_sdow', 'int:0:6', $cal_sdow, 0); xarVarFetch('cal_date', 'int::', $cal_date, 0); $c = xarMod::apiFunc('calendar', 'user', 'factory', 'calendar'); $c->setStartDayOfWeek($cal_sdow); $data = xarMod::apiFunc('calendar', 'user', 'getUserDateTimeInfo'); $data['cal_sdow'] =& $c->getStartDayOfWeek(); $data['shortDayNames'] =& $c->getShortDayNames($c->getStartDayOfWeek()); $data['mediumDayNames'] =& $c->getMediumDayNames($c->getStartDayOfWeek()); $data['longDayNames'] =& $c->getLongDayNames($c->getStartDayOfWeek()); $data['calendar'] =& $c; // return the event data xarVarFetch('event_id', 'int::', $event_id, 0); $e = xarMod::apiFunc('calendar', 'user', 'factory', 'event'); $e->buildEvent($event_id); // remember to pass in the existing array so it can be appended too $e->getEventDataForBL($data); // echo the content to the screen return $data; }
function calendar_user_week() { $data = xarMod::apiFunc('calendar', 'user', 'getUserDateTimeInfo'); $WeekEvents = new Calendar_Week($data['cal_year'], $data['cal_month'], $data['cal_day'], CALENDAR_FIRST_DAY_OF_WEEK); $start_time = $WeekEvents->thisWeek; $end_time = $WeekEvents->nextWeek; $q = new Query('SELECT'); $a[] = $q->plt('start_time', $start_time); $a[] = $q->pge('start_time + duration', $start_time); $b[] = $q->plt('start_time', $end_time); $b[] = $q->pge('start_time + duration', $end_time); $c[] = $q->pgt('start_time', $start_time); $c[] = $q->ple('start_time + duration', $end_time); $d[] = $q->pqand($a); $d[] = $q->pqand($b); $d[] = $q->pqand($c); $q->qor($d); $q->eq('role_id', xarSession::getVar('role_id')); $data['conditions'] = $q; return $data; }
function calendar_user_month() { $data = xarMod::apiFunc('calendar', 'user', 'getUserDateTimeInfo'); $MonthEvents = new Calendar_Month_Weekdays($data['cal_year'], $data['cal_month'] + 1, xarModVars::get('calendar', 'cal_sdow')); $end_time = $MonthEvents->getTimestamp(); $MonthEvents = new Calendar_Month_Weekdays($data['cal_year'], $data['cal_month'], xarModVars::get('calendar', 'cal_sdow')); $start_time = $MonthEvents->getTimestamp(); $q = new Query('SELECT'); $a[] = $q->plt('start_time', $start_time); $a[] = $q->pge('start_time + duration', $start_time); $b[] = $q->plt('start_time', $end_time); $b[] = $q->pge('start_time + duration', $end_time); $c[] = $q->pgt('start_time', $start_time); $c[] = $q->ple('start_time + duration', $end_time); $d[] = $q->pqand($a); $d[] = $q->pqand($b); $d[] = $q->pqand($c); $q->qor($d); $q->eq('role_id', xarSession::getVar('role_id')); $data['conditions'] = $q; return $data; }
function wurfl_init() { xarRegisterMask('ViewWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_OVERVIEW'); xarRegisterMask('ReadWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_READ'); xarRegisterMask('CommentWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_COMMENT'); xarRegisterMask('ModerateWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_MODERATE'); xarRegisterMask('EditWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_EDIT'); xarRegisterMask('AddWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_ADD'); xarRegisterMask('ManageWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_DELETE'); xarRegisterMask('AdminWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_ADMIN'); # -------------------------------------------------------- # # Set up privileges # xarRegisterPrivilege('ViewWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_OVERVIEW'); xarRegisterPrivilege('ReadWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_READ'); xarRegisterPrivilege('CommentWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_COMMENT'); xarRegisterPrivilege('ModerateWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_MODERATE'); xarRegisterPrivilege('EditWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_EDIT'); xarRegisterPrivilege('AddWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_ADD'); xarRegisterPrivilege('ManageWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_DELETE'); xarRegisterPrivilege('AdminWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_ADMIN'); # -------------------------------------------------------- # # Set up modvars # $module_settings = xarMod::apiFunc('base', 'admin', 'getmodulesettings', array('module' => 'wurfl')); $module_settings->initialize(); // Add variables like this next one when creating utility modules // This variable is referenced in the xaradmin/modifyconfig-utility.php file // This variable is referenced in the xartemplates/includes/defaults.xd file xarModVars::set('wurfl', 'defaultmastertable', 'wurfl_wurfl'); # -------------------------------------------------------- # # Set up hooks # return true; }
public function setup($timeframe, $role_id) { $data = xarMod::apiFunc('calendar', 'user', 'getUserDateTimeInfo'); switch ($timeframe) { case 'week': $WeekEvents = new Calendar_Week($data['cal_year'], $data['cal_month'], $data['cal_day'], CALENDAR_FIRST_DAY_OF_WEEK); $start_time = $WeekEvents->thisWeek; $end_time = $WeekEvents->nextWeek; $events = $this->getEvents($start_time, $end_time, $role_id); $WeekDecorator = new WeekEvent_Decorator($WeekEvents); $WeekDecorator->build($events); $data['Week'] =& $WeekDecorator; $data['cal_sdow'] = CALENDAR_FIRST_DAY_OF_WEEK; break; case 'month': $MonthEvents = new Calendar_Month_Weekdays($data['cal_year'], $data['cal_month'] + 1, xarModVars::get('calendar', 'cal_sdow')); $end_time = $MonthEvents->getTimestamp(); $MonthEvents = new Calendar_Month_Weekdays($data['cal_year'], $data['cal_month'], xarModVars::get('calendar', 'cal_sdow')); $start_time = $MonthEvents->getTimestamp(); $events = $this->getEvents($start_time, $end_time, $role_id); $MonthDecorator = new MonthEvent_Decorator($MonthEvents); $MonthDecorator->build($events); $data['Month'] =& $MonthDecorator; break; case 'year': $Year = new Calendar_Year($data['cal_year'] + 1); $end_time = $Year->getTimestamp(); $Year = new Calendar_Year($data['cal_year']); $start_time = $Year->getTimestamp(); $events = $this->getEvents($start_time, $end_time, $role_id); $YearDecorator = new YearEvent_Decorator($Year); $YearDecorator->build($events); $data['Year'] =& $YearDecorator->calendar; $data['cal_sdow'] = CALENDAR_FIRST_DAY_OF_WEEK; break; } return $data; }
/** * Get pages relative to a given page * * Filters: * Add an arg of the type $args['filter_foo'] = bar * will add a condition to the SELECT as * WHERE foo = bar * */ function publications_userapi_get_sitemap_pages($args) { if (empty($args['itemid'])) { $args['itemid'] = 0; } if (empty($args['scope'])) { $args['scope'] = 'descendants'; } if ($args['itemid'] == 0 && $args['scope'] == 'descendants') { $args['scope'] = 'all'; } if (empty($args['sort'])) { $args['sort'] = 0; } // Make sure we have the base translation id if (!empty($args['itemid'])) { $args['itemid'] = xarMod::apiFunc('publications', 'user', 'gettranslationid', array('id' => $args['itemid'], 'locale' => xarModVars::get('publications', 'defaultlanguage'))); } // Identify any filters $filters = array(); foreach ($args as $k => $v) { if (strpos($k, 'filter_') === 0) { $argname = substr($k, 7); $filters[$argname] = $v; } } $xartable = xarDB::getTables(); sys::import('xaraya.structures.query'); $q = new Query(); $q->addtable($xartable['publications'], 'p'); switch ($args['scope']) { case 'all': $q->gt('p.leftpage_id', 0); break; case 'descendants': $q->addtable($xartable['publications'], 'root'); $q->eq('root.id', $args['itemid']); $q->le('root.leftpage_id', 'expr:p.leftpage_id'); $q->ge('root.rightpage_id', 'expr:p.rightpage_id'); break; case 'children': $q->eq('p.parentpage_id', $args['itemid']); break; case 'siblings': $q->addtable($xartable['publications'], 'p1'); $q->join('p.parentpage_id', 'p1.parentpage_id'); $q->eq('p1.id', $args['itemid']); break; } if (!empty($args['itemtype'])) { $q->eq('p.pubtype_id', $args['itemtype']); } $q->eq('p.sitemap_flag', 1); $q->gt('p.state', 2); $q->addfield('p.id AS id'); $q->addfield('p.name AS name'); $q->addfield('p.title AS title'); $q->addfield('p.description AS description'); $q->addfield('p.sitemap_source_flag AS sitemap_source_flag'); $q->addfield('p.sitemap_alias AS sitemap_alias'); $q->addfield('p.pubtype_id AS pubtype_id'); $q->addfield('p.rightpage_id AS rightpage_id'); // Add any fiters we found foreach ($filters as $k => $v) { $q->eq('p.' . $k, $v); } // We can force alpha sorting, or else sort according to tree position if ($args['sort']) { $q->setorder('p.title'); } else { $q->setorder('p.leftpage_id'); } // $q->qecho(); $q->run(); $pages = $q->output(); $depthstack = array(); foreach ($pages as $key => $page) { // Calculate the relative nesting level. // 'depth' is 0-based. Top level (root node) is zero. if (!empty($depthstack)) { while (!empty($depthstack) && end($depthstack) < $page['rightpage_id']) { array_pop($depthstack); } } $depthstack[$page['id']] = $page['rightpage_id']; $pages[$key]['depth'] = empty($depthstack) ? 0 : count($depthstack) - 1; // This item is the path for each page, based on page IDs. // It is effectively a list of ancestor IDs for a page. // FIXME: some paths seem to get a '0' root ID. They should only have real page IDs. $pages[$key]['idpath'] = array_keys($depthstack); $pathstack[$key] = $page['name']; // This item is the path for each page, based on names. // Imploding it can give a directory-style path, which is handy // in admin pages and reports. $pages[$key]['namepath'] = $pathstack; } // If we are looking for translations rather than base documents, then find what translations are available and substitute them // CHECKME: is there a better way? // If there is no translation the base document remains. Is this desired outcome? if (!empty($pages) && xarModVars::get('publications', 'defaultlanguage') != xarUserGetNavigationLocale()) { $indexedpages = array(); foreach ($pages as $v) { $indexedpages[$v['id']] = $v; } $ids = array_keys($indexedpages); $q = new Query(); $q->addtable($xartable['publications']); $q->addfield('id'); $q->addfield('parent_id'); $q->addfield('name'); $q->addfield('title'); $q->addfield('description'); $q->addfield('sitemap_source_flag'); $q->addfield('sitemap_alias'); $q->addfield('pubtype_id'); $q->in('parent_id', $ids); $q->eq('locale', xarUserGetNavigationLocale()); // Add any fiters we found foreach ($filters as $k => $v) { $q->eq($k, $v); } $q->run(); foreach ($q->output() as $row) { // Copy the name and id paths so we don't have to recalculate them $row['depth'] = $indexedpages[$row['parent_id']]['depth']; $row['idpath'] = $indexedpages[$row['parent_id']]['idpath']; $row['namepath'] = $indexedpages[$row['parent_id']]['namepath']; // Add the entire row to the result pages $indexedpages[$row['parent_id']] = $row; } $pages =& $indexedpages; } return $pages; }
function publications_treeapi_insertprep($args) { // An insertion point (an ID in the table) is required. // Special insertion point ID is 0, which refers to the // virtual root of all trees. An item can not be // inserted on the same level as the virtual root. extract($args); // TODO: validate params: insertpoint, offset, tablename, idname // Default operation is 'before' - i.e. put the new item in the place // of the insertpoint and move everything to the right one place. if (!xarVarValidate('enum:before:after:firstchild:lastchild', $offset, true)) { $offset = 'firstchild'; } if (!isset($insertpoint)) { $insertpoint = 0; } if (!isset($idname)) { $idname = 'xar_id'; } // Cannot insert on the same level as the virtual root. if ($insertpoint == 0) { if ($offset == 'before') { $offset = 'firstchild'; } if ($offset == 'after') { $offset = 'lastchild'; } } $dbconn = xarDB::getConn(); $result = xarMod::apiFunc('publications', 'tree', 'getleftright', array('tablename' => $tablename, 'idname' => $idname, 'id' => $insertpoint)); if (!$result) { return; } extract($result); // Locate the new insert point. if ($offset == 'before') { $shift = $left; } if ($offset == 'after') { $shift = $right + 1; } if ($offset == 'firstchild') { $shift = $left + 1; $parent = $insertpoint; } if ($offset == 'lastchild') { $shift = $right; $parent = $insertpoint; } // Create a space of two traversal points. // The new item will not have children, so the traversal // points will be sequential. $query = 'UPDATE ' . $tablename . ' SET xar_left = xar_left + 2 ' . ' WHERE xar_left >= ?'; $result = $dbconn->execute($query, array($shift)); if (!$result) { return; } $query = 'UPDATE ' . $tablename . ' SET xar_right = xar_right + 2 ' . ' WHERE xar_right >= ?'; $result = $dbconn->execute($query, array($shift)); if (!$result) { return; } // Return the new parent/left/right values return array('parent' => $parent, 'left' => $shift, 'right' => $shift + 1); }
/** * Publications Module * * @package modules * @subpackage publications module * @category Third Party Xaraya Module * @version 2.0.0 * @copyright (C) 2011 Netspan AG * @license GPL {@link http://www.gnu.org/licenses/gpl.html} * @author Marc Lutolf <*****@*****.**> */ function publications_userapi_getpagestree($args) { // First get the set of pages. // Check out 'getpages' for the complete range of parameters that can be // passed in to restrict the pages retrieved. // We only want the base pages // $args['baseonly'] = 1; $pages = xarMod::apiFunc('publications', 'user', 'getpages', $args); // Return if no pages found. if (empty($pages)) { return array('pages' => array(), 'children' => array()); } // Inititalise the return value. $tree = array(); // Create a children list, so the tree can be walked recursively by page key index. // Three forms are available, useful in different circumstances: // - children_ids: page IDs only // - children_ids: linked to the page keys (in the pages array) // - children_names: children organised by page name // - children_pages: children linked to page records (i.e. the array keys) // Note the pages version contains linked references to each page, to save memory // and allow changes made to the main 'pages' array to be visible in the 'pages' // children array. $children_ids = array(); $children_keys = array(); $children_names = array(); $children_pages = array(); $depthstack = array(); $pathstack = array(); $translations = array(); // Create some additional arrays to help navigate the [flat] pages array. foreach ($pages as $key => $page) { // Assign where the locale info will be placed if ($page['base_id']) { $translations[$page['base_id']][] = substr($page['locale'], 0, 2); } else { $translations[$page['id']][] = substr($page['locale'], 0, 2); } // Put links in the pages themselves. // Ensure each page has at least an empty array of child keys. if (!isset($pages[$key]['child_keys'])) { $pages[$key]['child_keys'] = array(); } // Each page has a children array, based on the array keys. // If this page has a parent, then add this key to that parent page. if ($page['parent_key'] > 0 && isset($pages[$page['parent_key']])) { $pages[$page['parent_key']]['child_keys'][$key] = $key; } // Additional arrays that stand separately to the pages. // Add an entry to the children array of pages. // Create a new 'parent' page if it does not exist. if (!isset($children_keys[$page['parent_key']])) { $children_keys[$page['parent_key']] = array(); $children_names[$page['parent_key']] = array(); $children_pages[$page['parent_key']] = array(); } // Don't allow item 0 to loop back onto itself. // Item 0 points to all the root pages retrieved. // FIXME: set 'has_children' for the root page too, if necessary. if ($key != 0 || $page['parent_key'] != 0) { // Set flag for menus. // FIXME: the isset() is necessary because some parent pages // are not there. Why not? It shouldn't happen. if (isset($pages[$page['parent_key']])) { $pages[$page['parent_key']]['has_children'] = true; } // Create the references. $children_keys[$page['parent_key']][$key] = $key; $children_names[$page['parent_key']][$page['name']] = $key; $children_pages[$page['parent_key']][$key] =& $pages[$key]; } // Calculate the relative nesting level. // 'depth' is 0-based. Top level (root node) is zero. if (!empty($depthstack)) { while (!empty($depthstack) && end($depthstack) < $page['right']) { array_pop($depthstack); array_pop($pathstack); } } $depthstack[$page['id']] = $page['right']; $pages[$key]['depth'] = empty($depthstack) ? 0 : count($depthstack) - 1; // This item is the path for each page, based on page IDs. // It is effectively a list of ancestor IDs for a page. // FIXME: some paths seem to get a '0' root ID. They should only have real page IDs. $pages[$key]['idpath'] = array_keys($depthstack); $pathstack[$key] = $page['name']; // This item is the path for each page, based on names. // Imploding it can give a directory-style path, which is handy // in admin pages and reports. $pages[$key]['namepath'] = $pathstack; } // Now remove all pages that are not base pages and add the locales $finishedpages = array(); foreach ($pages as $key => $page) { if ($page['base_id']) { continue; } if (isset($translations[$page['id']])) { $page['translations'] = $translations[$page['id']]; } $finishedpages[] = $page; } $tree['pages'] =& $finishedpages; $tree['child_refs'] = array('keys' => $children_keys, 'names' => $children_names, 'pages' => $children_pages); return $tree; }
/** * Publish a calendar */ function calendar_user_publish($args) { extract($args); xarVarFetch('calid', 'id', $calid, 0, XARVAR_NOT_REQUIRED); xarVarFetch('calname', 'str:1:', $calname, '', XARVAR_NOT_REQUIRED); // test xarModVars::set('calendar', 'SupportShortURLs', 1); // TODO: security et al. if (!empty($calid) || !empty($calname)) { /* TEST: protect remote calendar access with basic authentication // cfr. notes at http://www.php.net/features.http-auth for IIS or CGI support if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW']) || // is this a valid user/password ? !xarUserLogIn($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) || // does this user have access to this calendar ? !xarSecurityCheck('ViewCalendar',0,'All',$calname)) { $realm = xarModVars::get('themes','SiteName'); header('WWW-Authenticate: Basic realm="'.$realm.'"'); //header('HTTP/1.0 401 Unauthorized'); header("Status: 401 Access Denied"); echo xarML('You must enter a valid username and password to access this calendar'); exit; } */ $calendars = xarMod::apiFunc('calendar', 'user', 'get', array('calid' => $calid, 'calname' => $calname)); if (!isset($calendars)) { return; } // we found a calendar if (count($calendars) == 1) { if (empty($calendars[0]['cpath'])) { // TODO: retrieve entries from database and create ics file } else { $curdir = sys::varpath() . '/calendar'; $curfile = $curdir . '/' . $calendars[0]['cpath']; if (file_exists($curfile) && filesize($curfile) > 0) { if ($_SERVER['REQUEST_METHOD'] != 'PUT') { // return the .ics file header('Content-Type: text/calendar'); @readfile($curfile); // TODO: use webdavserver instead ? // Cfr. phpicalendar/calendars/publish.php (doesn't seem to work for PHP < 4.3) // publishing } else { // get calendar data $data = ''; if ($fp = fopen('php://input', 'r')) { while ($chunk = fgets($fp, 4096)) { $data .= $chunk; } /* while(!@feof($fp)) { $data .= fgets($fp,4096); } */ @fclose($fp); } else { xarLogMessage('failed opening standard input'); } if (!empty($data)) { //xarLogMessage($data); // write to file if ($fp = fopen($curfile, 'w+')) { fputs($fp, $data, strlen($data)); @fclose($fp); } else { xarLogMessage('couldnt open file ' . $curfile); } } else { xarLogMessage('failed getting any data'); } } // we're done here exit; } } } } $data = array(); $data['calendars'] = xarMod::apiFunc('calendar', 'user', 'getall'); return $data; }
public function encode(xarRequest $request) { if ($request->getType() == 'admin') { return parent::encode($request); } $params = $request->getFunctionArgs(); $path = array(); switch ($request->getFunction()) { case 'search': $path[] = 'search'; $path = array_merge($path, $params); break; case 'view': $path[] = 'view'; if (isset($params['ptid'])) { if (xarModVars::get('publications', 'usetitleforurl')) { // Get all publication types present if (empty($this->pubtypes)) { $this->pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); } // Match to the function token foreach ($this->pubtypes as $id => $pubtype) { if ($params['ptid'] == $id) { $path[] = strtolower($pubtype['description']); break; } } } else { $path[] = $params['ptid']; } } unset($params['ptid']); break; case 'viewmap': $path[] = 'viewmap'; $params = array(); break; case 'display': if (isset($params['itemid'])) { sys::import('xaraya.structures.query'); xarModLoad('publications'); $xartables = xarDB::getTables(); $q = new Query('SELECT', $xartables['publications']); $q->eq('id', $params['itemid']); $q->addfield('pubtype_id'); $q->addfield('name'); $q->addfield('id'); $q->run(); $result = $q->row(); if (xarModVars::get('publications', 'usetitleforurl')) { // Get all publication types present if (empty($this->pubtypes)) { $this->pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); } if (!empty($result['pubtype_id'])) { $path[] = strtolower($this->pubtypes[$result['pubtype_id']]['description']); } if (!empty($result['name'])) { $path[] = strtolower($result['name']); } } else { if (!empty($result['id'])) { $path[] = $result['id']; } } } $params = array(); break; case 'main': // We need a page ID to continue, for now. // TODO: allow this to be expanded to page names. if (empty($params['pid'])) { return; } static $pages = NULL; // The components of the path. // $get = $args; // Get the page tree that includes this page. // TODO: Do some kind of cacheing on a tree-by-tree basis to prevent // fetching this too many times. Every time any tree is fetched, anywhere // in this module, it should be added to the cache so it can be used again. // For now we are going to fetch all pages, without DD, to cut down on // the number of queries, although we are making an assumption that the // number of pages is not going to get too high. if (empty($pages)) { // Fetch all pages, with no DD required. $pages = xarMod::apiFunc('publications', 'user', 'getpages', array('dd_flag' => false, 'key' => 'pid')); } // Check that the pid is a valid page. if (!isset($pages[$params['pid']])) { return; } $use_shortest_paths = xarModVars::get('publications', 'shortestpath'); // Consume the pid from the get parameters. $pid = $params['pid']; unset($params['pid']); // 'Consume' the function now we know we have enough information. // unset($params['func']); // Follow the tree up to the root. $pid_follow = $pid; while ($pages[$pid_follow]['parent_key'] != 0) { // TODO: could do with an API to get all aliases for a given module in one go. if (!empty($use_shortest_paths) && xarModGetAlias($pages[$pid_follow]['name']) == 'publications') { break; } array_unshift($path, $pages[$pid_follow]['name']); $pid_follow = $pages[$pid_follow]['parent_key']; } // Do the final path part. array_unshift($path, $pages[$pid_follow]['name']); // If the base path component is not the module alias, then add the // module name to the start of the path. if (xarModGetAlias($pages[$pid_follow]['name']) != 'publications') { // array_unshift($path, 'publications'); } // Now we have the basic path, we can check if there are any custom // URL handlers to handle the remainder of the GET parameters. // The handler is placed into the xarencodeapi API directory, and will // return two arrays: 'path' with path components and 'get' with // any unconsumed (or new) get parameters. if (!empty($pages[$pid]['encode_url'])) { $extra = xarMod::apiFunc('publications', 'encode', $pages[$pid]['encode_url'], $get, false); if (!empty($extra)) { // The handler has supplied some further short URL path components. if (!empty($extra['path'])) { $path = array_merge($path, $extra['path']); } // Assume it has consumed some GET parameters too. // Take what is left (i.e. unconsumed). if (isset($extra['get']) && is_array($extra['get'])) { $get = $extra['get']; } } } break; default: return; break; } // Encode the processed params $request->setFunction($this->getFunction($path)); // Send the unprocessed params back $request->setFunctionArgs($params); return parent::encode($request); }
/** * Returns the day the calendar starts on (0=Sunday through 6=Saturday) * @return bool if the day is */ function dayIs($dow = 0, $date = null) { if (!isset($date)) { $date = xarMod::apiFunc('calendar', 'user', 'createUserDateTime', 'Ymd'); } $year = substr($date, 0, 4); $month = substr($date, 4, 2); $day = substr($date, 6, 2); if ($dow == date('w', mktime(0, 0, 0, $month, $day, $year))) { return true; } return false; }