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; }
/** * Get products */ function shop_userapi_getproducts($args) { $startnum = 1; extract($args); if (!xarSecurityCheck('ViewShop')) { return; } if (!isset($items_per_page)) { $items_per_page = xarModVars::get('shop', 'items_per_page'); } $data['items_per_page'] = $items_per_page; // Load the DD master object class. This line will likely disappear in future versions sys::import('modules.dynamicdata.class.objects.master'); sys::import('modules.dynamicdata.class.properties.master'); // Get the object we'll be working with. Note this is a so called object list $mylist = DataObjectMaster::getObjectList(array('name' => 'shop_products')); $data['sort'] = xarMod::ApiFunc('shop', 'admin', 'sort', array('sortfield_fallback' => 'id', 'ascdesc_fallback' => 'ASC')); // We have some filters for the items $filters = array('startnum' => $startnum, 'status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'sort' => $data['sort']); if (isset($where)) { $filters['where'] = $where; } // Get the items $products = $mylist->getItems($filters); // return the products $data['products'] = $products; // Return the template variables defined in this function return $data; }
function publications_user_new($args) { extract($args); // Get parameters if (!xarVarFetch('ptid', 'id', $data['ptid'], xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('itemtype', 'id', $itemtype, NULL, XARVAR_NOT_REQUIRED)) { return; } $data['items'] = array(); $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $data['properties'] = $data['object']->getProperties(); if (!empty($data['ptid'])) { $template = $pubtypeobject->properties['template']->value; } else { // TODO: allow templates per category ? $template = null; } // Get the settings of the publication type we are using $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid'])); return xarTplModule('publications', 'admin', 'new', $data, $template); }
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; }
/** * List the product attributes */ function shop_admin_attributes() { if (!xarVarFetch('startnum', 'isset', $data['startnum'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('user_id', 'isset', $user_id, NULL, XARVAR_DONT_SET)) { return; } $objectname = 'shop_attributes'; $data['objectname'] = $objectname; // Security check - important to do this as early as possible to avoid // potential security holes or just too much wasted processing if (!xarSecurityCheck('AdminShop')) { return; } $data['items_per_page'] = xarModVars::get('shop', 'items_per_page'); // Load the DD master object class. This line will likely disappear in future versions sys::import('modules.dynamicdata.class.objects.master'); // Get the object label for the template $object = DataObjectMaster::getObject(array('name' => $objectname)); $data['label'] = $object->label; // Get the fields to display in the admin interface $config = $object->configuration; if (!empty($config['adminfields'])) { $data['adminfields'] = $config['adminfields']; } else { $data['adminfields'] = array_keys($object->getProperties()); } // Get the object we'll be working with. Note this is a so called object list $mylist = DataObjectMaster::getObjectList(array('name' => $objectname)); // Load the DD master property class. This line will likely disappear in future versions sys::import('modules.dynamicdata.class.properties.master'); $data['sort'] = xarMod::ApiFunc('shop', 'admin', 'sort', array('sortfield_fallback' => 'ID', 'ascdesc_fallback' => 'ASC')); // We have some filters for the items $filters = array('startnum' => $data['startnum'], 'status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'sort' => $data['sort']); if (isset($user_id)) { $filters['where'] = 'user_id eq ' . $user_id; } // Get the items $items = $mylist->getItems($filters); if (isset($user_id)) { // Get the object we'll be working with. Note this is a so called object list $mylist2 = DataObjectMaster::getObjectList(array('name' => 'shop_customers')); $filters = array(); if (isset($user_id)) { $filters['where'] = 'ID eq ' . $user_id; } $items2 = $mylist2->getItems($filters); $data['fname'] = $items2[$user_id]['FirstName']; $data['lname'] = $items2[$user_id]['LastName']; } $data['mylist'] = $mylist; // Return the template variables defined in this function return $data; }
/** * Used to get the current view the calendar is in (Day, Week, Month, Year) */ function calendar_userapi_currentView() { xarVarFetch('func', 'str::', $func, 'main', XARVAR_NOT_REQUIRED); $valid = array('day', 'week', 'month', 'year'); $func = strtolower($func); if (!in_array($func, $valid)) { return xarModVars::get('calendar', 'default_view'); } else { return $func; } }
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; }
/** * Main admin GUI function, entry point * */ function wurfl_admin_main() { if (!xarSecurityCheck('ManageWurfl')) { return; } if (xarModVars::get('modules', 'disableoverview') == 0) { return array(); } else { xarController::redirect(xarModURL('wurfl', 'admin', 'modifyconfig')); } // success return true; }
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; }
function publications_admin_create() { if (!xarVarFetch('ptid', 'id', $data['ptid'])) { return; } if (!xarVarFetch('new_cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('preview', 'str', $data['preview'], NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('save', 'str', $save, NULL, XARVAR_NOT_REQUIRED)) { return; } // Confirm authorisation code // This has been disabled for now // if (!xarSecConfirmAuthKey()) return; $data['items'] = array(); $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $isvalid = $data['object']->checkInput(); $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid'])); if ($data['preview'] || !$isvalid) { // Show debug info if called for if (!$isvalid && xarModVars::get('publications', 'debugmode') && in_array(xarUserGetVar('uname'), xarConfigVars::get(null, 'Site.User.DebugAdmins'))) { var_dump($data['object']->getInvalids()); } // Preview or bad data: redisplay the form $data['properties'] = $data['object']->getProperties(); if ($data['preview']) { $data['tab'] = 'preview'; } return xarTplModule('publications', 'admin', 'new', $data); } // Create the object $id = $data['object']->createItem(); // if we can edit publications, go to admin view, otherwise go to user view if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) { // Redirect if we came from somewhere else $cuurent_listview = xarSession::getVar('publications_current_listview'); if (!empty($cuurent_listview)) { xarController::redirect($cuurent_listview); } xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid']))); } else { xarController::redirect(xarModURL('publications', 'user', 'view', array('ptid' => $data['ptid']))); } return true; }
function shop_adminapi_handlepgresponse($args) { extract($args); $pg = xarModVars::get('shop', 'payment_gateway'); $trans_id = false; $pg_response = xarSession::getVar('pg_response'); switch ($pg) { case 1: // demo mode $trans_id = rand(1000, 99999999); // fake trans id break; case 2: // authorize.net $response = xarMod::APIFunc('shop', 'admin', 'authorizenet', $transfields); if ($response[1] == 1) { $trans_id = $response[7]; } else { $num = $response[1]; $authorizenet_codes = array(1 => 'Approved', 2 => 'Declined', 3 => 'Error', 4 => 'Held for Review'); $msg = $response[4]; $msg .= ' Response code: ' . $authorizenet_codes[$num]; $pg_response['msg'] = $msg; } break; case 3: // paypal web payments pro $args['transfields'] = $transfields; $args['methodName_'] = 'DoDirectPayment'; $response = xarMod::APIFunc('shop', 'admin', 'paypal', $args); if ($response['ACK'] == 'Success') { $trans_id = $response['TRANSACTIONID']; } else { $msg = $response['ACK']; $msg .= '. Response: ' . urldecode($response['L_LONGMESSAGE0']); $pg_response['msg'] = $msg; } break; case 4: // something else // your code break; } if (isset($pg_response)) { xarSession::setVar('pg_response', $pg_response); } $response['trans_id'] = $trans_id; return $response; }
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; }
function createItem(array $args = array()) { // Save the access property $this->properties['access']->setInputStatus(DataPropertyMaster::DD_INPUTSTATE_ADDMODIFY); // If multilanguages is not enabled just save the default language value if (!xarModVars::get('publications', 'multilanguage')) { if (isset($this->properties['locale'])) { $this->properties['locale']->setInputStatus(DataPropertyMaster::DD_INPUTSTATE_ADDMODIFY); } } // Ignore the position if this isn't the base document if (empty($this->properties['parent']->value)) { $this->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISPLAYONLY); } else { $this->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISABLED); } $this->fieldlist = array(); return parent::createItem($args); }
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; }
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; }
/** * Display func. * @param $blockinfo array * @returns $blockinfo array */ function display(array $data = array()) { $data = parent::display($data); if (empty($data)) { return; } if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', xarModVars::get('calendar', 'pearcalendar_root')); } include_once CALENDAR_ROOT . 'Calendar.php'; $tplData['form_action'] = xarModURL('calendar', 'user', 'changecalnav'); $tplData['blockid'] = $data['bid']; if (xarServer::getVar('REQUEST_METHOD') == 'GET') { // URL of this page $tplData['return_url'] = xarServer::getCurrentURL(); } else { // Base URL of the site $tplData['return_url'] = xarServer::getBaseURL(); } $data['content'] = $tplData; return $data; }
/** * Connect to authorize.net */ function shop_adminapi_authorizenet($args) { extract($args); $post_url = "https://test.authorize.net/gateway/transact.dll"; $post_values = array("x_login" => xarModVars::get('shop', 'pg_id'), "x_tran_key" => xarModVars::get('shop', 'pg_key'), "x_version" => "3.1", "x_delim_data" => "TRUE", "x_delim_char" => "|", "x_relay_response" => "FALSE", "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_card_num" => $card_num, "x_exp_date" => $exp_date, "x_amount" => $total, "x_description" => $products, "x_first_name" => $first_name, "x_last_name" => $last_name, "x_address" => $street_addr, "x_state" => $state_addr, "x_zip" => $postal_code); // This section takes the input fields and converts them to the proper format // for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4" $post_string = ""; foreach ($post_values as $key => $value) { $post_string .= "{$key}=" . urlencode($value) . "&"; } $post_string = rtrim($post_string, "& "); // This sample code uses the CURL library for php to establish a connection, // submit the post, and record the response. // If you receive an error, you may want to ensure that you have the curl // library enabled in your php configuration $request = curl_init($post_url); // initiate curl object curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. $post_response = curl_exec($request); // execute curl post and store results in $post_response // additional options may be required depending upon your server configuration // you can find documentation on curl options at http://www.php.net/curl_setopt curl_close($request); // close curl object $array = array(0 => ''); // This line takes the response and breaks it into an array using the specified delimiting character $response_array = explode($post_values["x_delim_char"], $post_response); //to make things consistent with the authorize.net documentation, we want the authorize.net values to start with a key of 1 $response_array = array_merge($array, $response_array); return $response_array; }
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; }
/** * search publications (called as hook from search module, or directly with pager) * * @param $args['objectid'] could be the query ? (currently unused) * @param $args['extrainfo'] all other parameters ? (currently unused) * @return array output */ function publications_user_search($args) { // pager stuff if (!xarVarFetch('startnum', 'int:0', $startnum, NULL, XARVAR_NOT_REQUIRED)) { return; } // categories stuff if (!xarVarFetch('cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('andcids', 'str', $andcids, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) { return; } // single publication type when called via the pager if (!xarVarFetch('ptid', 'id', $ptid, NULL, XARVAR_NOT_REQUIRED)) { return; } // multiple publication types when called via search hooks if (!xarVarFetch('ptids', 'array', $ptids, NULL, XARVAR_NOT_REQUIRED)) { return; } // date stuff via forms if (!xarVarFetch('publications_startdate', 'str', $startdate, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('publications_enddate', 'str', $enddate, NULL, XARVAR_NOT_REQUIRED)) { return; } // date stuff via URLs if (!xarVarFetch('start', 'int:0', $start, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('end', 'int:0', $end, NULL, XARVAR_NOT_REQUIRED)) { return; } // search button was pressed if (!xarVarFetch('search', 'str', $search, NULL, XARVAR_NOT_REQUIRED)) { return; } // select by article state (array or string) if (!xarVarFetch('state', 'isset', $state, NULL, XARVAR_NOT_REQUIRED)) { return; } // yes, this is the query if (!xarVarFetch('q', 'str', $q, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('author', 'str', $author, NULL, XARVAR_NOT_REQUIRED)) { return; } // filter by category if (!xarVarFetch('by', 'str', $by, NULL, XARVAR_NOT_REQUIRED)) { return; } // can't use list enum here, because we don't know which sorts might be used if (!xarVarFetch('sort', 'regexp:/^[\\w,]*$/', $sort, NULL, XARVAR_NOT_REQUIRED)) { return; } // boolean AND/OR for words (no longer used) //if(!xarVarFetch('bool', 'str', $bool, NULL, XARVAR_NOT_REQUIRED)) {return;} // search in specific fields if (!xarVarFetch('publications_fields', 'isset', $fields, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('searchtype', 'isset', $searchtype, NULL, XARVAR_NOT_REQUIRED)) { return; } if (isset($args['objectid'])) { $ishooked = 1; } else { $ishooked = 0; if (empty($fields)) { // search in specific fields via URLs if (!xarVarFetch('fields', 'isset', $fields, NULL, XARVAR_NOT_REQUIRED)) { return; } } } // TODO: could we need this someday ? if (isset($args['extrainfo'])) { extract($args['extrainfo']); } // TODO: clean up this copy & paste stuff :-) // Default parameters if (!isset($startnum)) { $startnum = 1; } if (!isset($numitems)) { $numitems = 20; } if (!xarModAPILoad('publications', 'user')) { return; } // Get publication types $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); if (xarSecurityCheck('AdminPublications', 0)) { $isadmin = true; } else { $isadmin = false; } // frontpage or approved state if (!$isadmin || !isset($state)) { $state = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED); } elseif (is_string($state)) { if (strpos($state, ' ')) { $state = explode(' ', $state); } elseif (strpos($state, '+')) { $state = explode('+', $state); } else { $state = array($state); } } $seenstate = array(); foreach ($state as $that) { if (empty($that) || !is_numeric($that)) { continue; } $seenstate[$that] = 1; } $state = array_keys($seenstate); if (count($state) != 2 || !in_array(PUBLICATIONS_STATE_APPROVED, $state) || !in_array(PUBLICATIONS_STATE_FRONTPAGE, $state)) { $stateline = implode('+', $state); } else { $stateline = null; } if (!isset($sort)) { $sort = null; } // default publication type(s) to search in if (!empty($ptid) && isset($pubtypes[$ptid])) { $ptids = array($ptid); $settings = unserialize(xarModVars::get('publications', 'settings.' . $ptid)); if (empty($settings['show_categories'])) { $show_categories = 0; } else { $show_categories = 1; } } elseif (!empty($ptids) && count($ptids) > 0) { foreach ($ptids as $curptid) { // default view doesn't apply here ?! } $show_categories = 1; } elseif (!isset($ptids)) { // $ptids = array(xarModVars::get('publications','defaultpubtype')); $ptids = array(); foreach ($pubtypes as $pubid => $pubtype) { $ptids[] = $pubid; } $show_categories = 1; } else { // TODO: rethink this when we're dealing with multi-pubtype categories $show_categories = 0; } // turn $catid into $cids array (and set $andcids flag) if (!empty($catid)) { if (strpos($catid, ' ')) { $cids = explode(' ', $catid); $andcids = true; } elseif (strpos($catid, '+')) { $cids = explode('+', $catid); $andcids = true; } else { $cids = explode('-', $catid); $andcids = false; } } $seencid = array(); $catid = null; if (isset($cids) && is_array($cids)) { foreach ($cids as $cid) { if (empty($cid) || !preg_match('/^_?[0-9]+$/', $cid)) { continue; } $seencid[$cid] = 1; } $cids = array_keys($seencid); if ($andcids) { $catid = join('+', $cids); } else { $catid = join('-', $cids); } } $seenptid = array(); if (isset($ptids) && is_array($ptids)) { foreach ($ptids as $curptid) { if (empty($curptid) || !isset($pubtypes[$curptid])) { continue; } $seenptid[$curptid] = 1; } $ptids = array_keys($seenptid); } /* Ensure whitespace alone not passed to api -causes errors */ if (isset($q) && trim($q) === '') { $q = null; } // Find the id of the author we're looking for if (!empty($author)) { // Load API if (!xarModAPILoad('roles', 'user')) { return; } $user = xarModAPIFunc('roles', 'user', 'get', array('name' => $author)); if (!empty($user['uid'])) { $owner = $user['uid']; } else { $owner = null; $author = null; } } else { $owner = null; $author = null; } if (isset($start) && is_numeric($start)) { $startdate = xarLocaleFormatDate("%Y-%m-%d %H:%M:%S", $start); } if (isset($end) && is_numeric($end)) { $enddate = xarLocaleFormatDate("%Y-%m-%d %H:%M:%S", $end); } if (empty($fields)) { $fieldlist = array('title', 'description', 'summary', 'body1'); } else { $fieldlist = array_keys($fields); // don't pass fields via URLs if we stick to the default list if (count($fields) == 3 && isset($fields['title']) && isset($fields['description']) && isset($fields['summary']) && isset($fields['body1'])) { $fields = null; } } // Set default searchtype to 'fulltext' if necessary $fulltext = xarModVars::get('publications', 'fulltextsearch'); if (!isset($searchtype) && !empty($fulltext)) { $searchtype = 'fulltext'; } // FIXME: fulltext only supports searching in all configured text fields ! if (empty($fields) && !empty($fulltext) && !empty($searchtype) && $searchtype == 'fulltext') { $fieldlist = explode(',', $fulltext); } $data = array(); $data['results'] = array(); $data['state'] = ''; $data['ishooked'] = $ishooked; // TODO: MichelV: $ishooked is never empty, but either 0 or 1 if (empty($ishooked)) { $data['q'] = isset($q) ? xarVarPrepForDisplay($q) : null; $data['author'] = isset($author) ? xarVarPrepForDisplay($author) : null; $data['searchtype'] = $searchtype; } if ($isadmin) { $states = xarModAPIFunc('publications', 'user', 'getstates'); $data['statelist'] = array(); foreach ($states as $id => $name) { $data['statelist'][] = array('id' => $id, 'name' => $name, 'checked' => in_array($id, $state)); } } // TODO: show field labels when we're dealing with only 1 pubtype $data['fieldlist'] = array(array('id' => 'title', 'name' => xarML('title'), 'checked' => in_array('title', $fieldlist)), array('id' => 'description', 'name' => xarML('description'), 'checked' => in_array('description', $fieldlist)), array('id' => 'summary', 'name' => xarML('summary'), 'checked' => in_array('summary', $fieldlist)), array('id' => 'body1', 'name' => xarML('body1'), 'checked' => in_array('body1', $fieldlist)), array('id' => 'notes', 'name' => xarML('notes'), 'checked' => in_array('notes', $fieldlist))); $data['publications'] = array(); foreach ($pubtypes as $pubid => $pubtype) { if (!empty($seenptid[$pubid])) { $checked = ' checked="checked"'; } else { $checked = ''; } $data['publications'][] = array('id' => $pubid, 'description' => xarVarPrepForDisplay($pubtype['description']), 'checked' => $checked); } $data['categories'] = array(); if (!empty($by) && $by == 'cat') { $catarray = array(); foreach ($ptids as $curptid) { // get root categories for this publication type $catlinks = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $curptid)); foreach ($catlinks as $cat) { $catarray[$cat['category_id']] = $cat['name']; } } foreach ($catarray as $cid => $title) { $select = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $cid, 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 1)); $data['categories'][] = array('cattitle' => $title, 'catselect' => $select); } $data['searchurl'] = xarModURL('search', 'user', 'main'); } else { $data['searchurl'] = xarModURL('search', 'user', 'main', array('by' => 'cat')); } $now = time(); if (empty($startdate)) { $startdate = null; $data['startdate'] = 'N/A'; } else { if (!preg_match('/[a-zA-Z]+/', $startdate)) { $startdate .= ' GMT'; } $startdate = strtotime($startdate); // adjust for the user's timezone offset $startdate -= xarMLS_userOffset() * 3600; if ($startdate > $now && !$isadmin) { $startdate = $now; } $data['startdate'] = $startdate; } if (empty($enddate)) { $enddate = $now; $data['enddate'] = 'N/A'; } else { if (!preg_match('/[a-zA-Z]+/', $enddate)) { $enddate .= ' GMT'; } $enddate = strtotime($enddate); // adjust for the user's timezone offset $enddate -= xarMLS_userOffset() * 3600; if ($enddate > $now && !$isadmin) { $enddate = $now; } $data['enddate'] = $enddate; } if (!empty($q) || !empty($author) && isset($owner) || !empty($search) || !empty($ptid) || !empty($startdate) || $enddate != $now || !empty($catid)) { $getfields = array('id', 'title', 'start_date', 'pubtype_id', 'cids'); // Return the relevance when using MySQL full-text search //if (!empty($search) && !empty($searchtype) && substr($searchtype,0,8) == 'fulltext') { // $getfields[] = 'relevance'; //} $count = 0; // TODO: allow combination of searches ? foreach ($ptids as $curptid) { $publications = xarModAPIFunc('publications', 'user', 'getall', array('startnum' => $startnum, 'cids' => $cids, 'andcids' => $andcids, 'ptid' => $curptid, 'owner' => $owner, 'sort' => $sort, 'numitems' => $numitems, 'state' => $state, 'start_date' => $startdate, 'end_date' => $enddate, 'searchfields' => $fieldlist, 'searchtype' => $searchtype, 'search' => $q, 'fields' => $getfields)); // TODO: re-use article output code from elsewhere (view / archive / admin) if (!empty($publications) && count($publications) > 0) { // retrieve the categories for each article $catinfo = array(); if ($show_categories) { $cidlist = array(); foreach ($publications as $article) { if (!empty($article['cids']) && count($article['cids']) > 0) { foreach ($article['cids'] as $cid) { $cidlist[$cid] = 1; } } } if (count($cidlist) > 0) { $catinfo = xarModAPIFunc('categories', 'user', 'getcatinfo', array('cids' => array_keys($cidlist))); // get root categories for this publication type $catroots = xarModAPIFunc('publications', 'user', 'getrootcats', array('ptid' => $curptid)); $catroots = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $curptid)); } foreach ($catinfo as $cid => $info) { $catinfo[$cid]['name'] = xarVarPrepForDisplay($info['name']); $catinfo[$cid]['link'] = xarModURL('publications', 'user', 'view', array('ptid' => $curptid, 'catid' => $catid && $andcids ? $catid . '+' . $cid : $cid)); // only needed when sorting by root category id $catinfo[$cid]['root'] = 0; // means not found under a root category // only needed when sorting by root category order $catinfo[$cid]['order'] = 0; // means not found under a root category $rootidx = 1; foreach ($catroots as $rootcat) { // see if we're a child category of this rootcat (cfr. Celko model) if ($info['left'] >= $rootcat['left_id'] && $info['left'] < $rootcat['right_id']) { // only needed when sorting by root category id $catinfo[$cid]['root'] = $rootcat['category_id']; // only needed when sorting by root category order $catinfo[$cid]['order'] = $rootidx; break; } $rootidx++; } } } // needed for sort function below $GLOBALS['artsearchcatinfo'] = $catinfo; $items = array(); foreach ($publications as $article) { $count++; $curptid = $article['pubtype_id']; $link = xarModURL('publications', 'user', 'display', array('ptid' => $article['pubtype_id'], 'itemid' => $article['id'])); // publication date of article (if needed) if (!empty($pubtypes[$curptid]['config']['startdate']['label']) && !empty($article['startdate'])) { $date = xarLocaleFormatDate('%a, %d %B %Y %H:%M:%S %Z', $article['startdate']); $startdate = $article['startdate']; } else { $date = ''; $startdate = 0; } if (empty($article['title'])) { $article['title'] = xarML('(none)'); } // categories this article belongs to $categories = array(); if ($show_categories && !empty($article['cids']) && is_array($article['cids']) && count($article['cids']) > 0) { $cidlist = $article['cids']; // order cids by root category order usort($cidlist, 'publications_search_sortbyorder'); // order cids by root category id //usort($cidlist,'publications_search_sortbyroot'); // order cids by position in Celko tree //usort($cidlist,'publications_search_sortbyleft'); $join = ''; foreach ($cidlist as $cid) { $item = array(); if (!isset($catinfo[$cid])) { // oops continue; } $categories[] = array('cname' => $catinfo[$cid]['name'], 'clink' => $catinfo[$cid]['link'], 'cjoin' => $join); if (empty($join)) { $join = ' | '; } } } $items[] = array('title' => xarVarPrepHTMLDisplay($article['title']), 'link' => $link, 'date' => $date, 'startdate' => $startdate, 'relevance' => isset($article['relevance']) ? $article['relevance'] : null, 'categories' => $categories); } unset($publications); // Pager // TODO: make count depend on locale in the future sys::import('modules.base.class.pager'); $pager = xarTplPager::getPager($startnum, xarModAPIFunc('publications', 'user', 'countitems', array('cids' => $cids, 'andcids' => $andcids, 'ptid' => $curptid, 'owner' => $owner, 'state' => $state, 'startdate' => $startdate, 'enddate' => $enddate, 'searchfields' => $fieldlist, 'searchtype' => $searchtype, 'search' => $q)), xarModURL('publications', 'user', 'search', array('ptid' => $curptid, 'catid' => $catid, 'q' => isset($q) ? $q : null, 'author' => isset($author) ? $author : null, 'start' => $startdate, 'end' => $enddate != $now ? $enddate : null, 'state' => $stateline, 'sort' => $sort, 'fields' => $fields, 'searchtype' => !empty($searchtype) ? $searchtype : null, 'startnum' => '%%')), $numitems); if (strlen($pager) > 5) { if (!isset($sort) || $sort == 'date') { $othersort = 'title'; } else { $othersort = null; } $sortlink = xarModURL('publications', 'user', 'search', array('ptid' => $curptid, 'catid' => $catid, 'q' => isset($q) ? $q : null, 'author' => isset($author) ? $author : null, 'start' => $startdate, 'end' => $enddate != $now ? $enddate : null, 'state' => $stateline, 'fields' => $fields, 'searchtype' => !empty($searchtype) ? $searchtype : null, 'sort' => $othersort)); if (!isset($othersort)) { $othersort = 'date'; } $pager .= '  <a href="' . $sortlink . '">' . xarML('sort by') . ' ' . xarML($othersort) . '</a>'; } $data['results'][] = array('description' => xarVarPrepForDisplay($pubtypes[$curptid]['description']), 'items' => $items, 'pager' => $pager); } } unset($catinfo); unset($items); unset($GLOBALS['artsearchcatinfo']); if ($count > 0) { // bail out, we have what we needed return xarTplModule('publications', 'user', 'search', $data); } $data['state'] = xarML('No pages found matching this search'); } return xarTplModule('publications', 'user', 'search', $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_userapi_gettranslationid($args) { if (!isset($args['id'])) { throw new BadParameterException('id'); } if (empty($args['id'])) { return 0; } // We can check on a full locale or just a partial one (excluding charset) if (empty($args['partiallocale'])) { $args['partiallocale'] = 0; } // We can look for a specific translation if (empty($args['locale'])) { $locale = xarUserGetNavigationLocale(); } else { $locale = $args['locale']; } sys::import('xaraya.structures.query'); if ($args['partiallocale']) { $parts = explode('.', $locale); $locale = $parts[0]; } $xartable = xarDB::getTables(); if (empty($args['locale'])) { // Return the id of the translation if it exists, or else the base document $q = new Query('SELECT', $xartable['publications']); $q->addfield('id'); $q->eq('locale', $locale); $c[] = $q->peq('id', $args['id']); $c[] = $q->peq('parent_id', $args['id']); $q->qor($c); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } elseif ($args['locale'] == xarUserGetNavigationLocale()) { // No need to look further return $args['id']; } elseif ($args['locale'] == xarModVars::get('publications', 'defaultlanguage')) { // Force getting the base document $q = new Query('SELECT', $xartable['publications']); $q->addfield('parent_id'); $q->eq('id', $args['id']); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } // If this was already the base document, return its ID if (empty($result['parent_id'])) { return $args['id']; } // Else return the parent ID return $result['parent_id']; } else { // Force getting another translation $q = new Query('SELECT'); $q->addtable($xartable['publications'], 'p1'); $q->addtable($xartable['publications'], 'p2'); $q->join('p2.parent_id', 'p1.parent_id'); $q->addfield('p2.id'); $q->eq('p2.locale', $locale); $q->eq('p1.id', $args['id']); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } if (xarUserGetVar('uname') == 'random') { $xartable = xarDB::getTables(); $q = new Query('SELECT'); $q->addtable($xartable['publications'], 'p1'); $q->addtable($xartable['publications'], 'p2'); $q->join('p2.id', 'p1.parent_id'); $q->addfield('p1.id'); $c[] = $q->peq('p1.id', $args['id']); $c[] = $q->peq('p1.parent_id', $args['id']); $c[] = $q->peq('p2.id', $args['id']); $q->qor($c); $d[] = $q->peq('p1.locale', $args['locale']); $d[] = $q->peq('p2.locale', $args['locale']); $q->qor($d); if (!$q->run()) { return $args['id']; } $q->qecho(); $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } }
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); }
public function display(array $data = array()) { $data = $this->getContent(); // see if we're currently displaying an article if (xarVarIsCached('Blocks.publications', 'id')) { $curid = xarVarGetCached('Blocks.publications', 'id'); } else { $curid = -1; } if (!empty($data['dynamictitle'])) { if ($data['toptype'] == 'rating') { $data['title'] = xarML('Top Rated'); } elseif ($data['toptype'] == 'hits') { $data['title'] = xarML('Top'); } else { $data['title'] = xarML('Latest'); } } if (!empty($data['nocatlimit'])) { // don't limit by category $cid = 0; $cidsarray = array(); } else { if (!empty($data['catfilter'])) { // use admin defined category $cidsarray = array($data['catfilter']); $cid = $data['catfilter']; } else { // use the current category // Jonn: this currently only works with one category at a time // it could be reworked to support multiple cids if (xarVarIsCached('Blocks.publications', 'cids')) { $curcids = xarVarGetCached('Blocks.publications', 'cids'); if (!empty($curcids)) { if ($curid == -1) { //$cid = $curcids[0]['name']; $cid = $curcids[0]; $cidsarray = array($curcids[0]); } else { $cid = $curcids[0]; $cidsarray = array($curcids[0]); } } else { $cid = 0; $cidsarray = array(); } } else { // pull from all categories $cid = 0; $cidsarray = array(); } } //echo $includechildren; if (!empty($data['includechildren']) && !empty($cidsarray[0]) && !strstr($cidsarray[0], '_')) { $cidsarray[0] = '_' . $cidsarray[0]; } if (!empty($cid)) { // if we're viewing all items below a certain category, i.e. catid = _NN $cid = str_replace('_', '', $cid); $thiscategory = xarModAPIFunc('categories', 'user', 'getcat', array('cid' => $cid, 'return_itself' => 'return_itself')); } if (!empty($cidsarray) && isset($thiscategory[0]['name']) && !empty($data['dynamictitle'])) { $data['title'] .= ' ' . $thiscategory[0]['name']; } } // Get publication types // MarieA - moved to always get pubtypes. $publication_types = xarModAPIFunc('publications', 'user', 'get_pubtypes'); if (!empty($data['nopublimit'])) { //don't limit by publication type $ptid = 0; if (!empty($data['dynamictitle'])) { $data['title'] .= ' ' . xarML('Content'); } } else { // MikeC: Check to see if admin has specified that only a specific // Publication Type should be displayed. If not, then default to original TopItems configuration. if ($data['pubtype_id'] == 0) { if (xarVarIsCached('Blocks.publications', 'ptid')) { $ptid = xarVarGetCached('Blocks.publications', 'ptid'); } if (empty($ptid)) { // default publication type $ptid = xarModVars::get('publications', 'defaultpubtype'); } } else { // MikeC: Admin Specified a publication type, use it. $ptid = $data['pubtype_id']; } if (!empty($data['dynamictitle'])) { if (!empty($ptid) && isset($publication_types[$ptid]['description'])) { $data['title'] .= ' ' . xarVarPrepForDisplay($publication_types[$ptid]['description']); } else { $data['title'] .= ' ' . xarML('Content'); } } } // frontpage or approved state if (empty($data['pubstate'])) { $statearray = array(2, 3); } elseif (!is_array($data['pubstate'])) { $statearray = preg_split('/,/', $data['pubstate']); } else { $statearray = $data['pubstate']; } // get cids for security check in getall $fields = array('id', 'title', 'pubtype_id', 'cids'); if ($data['toptype'] == 'rating' && xarModIsHooked('ratings', 'publications', $ptid)) { array_push($fields, 'rating'); $sort = 'rating'; } elseif ($data['toptype'] == 'hits' && xarModIsHooked('hitcount', 'publications', $ptid)) { array_push($fields, 'counter'); $sort = 'hits'; } else { array_push($fields, 'create_date'); $sort = 'date'; } if (!empty($data['showsummary'])) { array_push($fields, 'summary'); } if (!empty($data['showdynamic']) && xarModIsHooked('dynamicdata', 'publications', $ptid)) { array_push($fields, 'dynamicdata'); } $publications = xarModAPIFunc('publications', 'user', 'getall', array('ptid' => $ptid, 'cids' => $cidsarray, 'andcids' => 'false', 'state' => $statearray, 'create_date' => time(), 'fields' => $fields, 'sort' => $sort, 'numitems' => $data['numitems'])); if (!isset($publications) || !is_array($publications) || count($publications) == 0) { return; } $items = array(); foreach ($publications as $article) { $article['title'] = xarVarPrepHTMLDisplay($article['title']); if ($article['id'] != $curid) { // Use the filtered category if set, and not including children $article['link'] = xarModURL('publications', 'user', 'display', array('itemid' => $article['id'], 'catid' => !empty($data['linkcat']) && !empty($data['catfilter']) ? $data['catfilter'] : NULL)); } else { $article['link'] = ''; } if (!empty($data['showvalue'])) { if ($data['toptype'] == 'rating') { if (!empty($article['rating'])) { $article['value'] = intval($article['rating']); } else { $article['value'] = 0; } } elseif ($data['toptype'] == 'hits') { if (!empty($article['counter'])) { $article['value'] = $article['counter']; } else { $article['value'] = 0; } } else { // TODO: make user-dependent if (!empty($article['create_date'])) { //$article['value'] = strftime("%Y-%m-%d", $article['create_date']); $article['value'] = xarLocaleGetFormattedDate('short', $article['create_date']); } else { $article['value'] = 0; } } } else { $article['value'] = 0; } // MikeC: Bring the summary field back as $desc if (!empty($data['showsummary'])) { $article['summary'] = xarVarPrepHTMLDisplay($article['summary']); $article['transform'] = array('summary', 'title'); $article = xarModCallHooks('item', 'transform', $article['id'], $article, 'publications'); } else { $article['summary'] = ''; } // MarieA: Bring the pubtype description back as $descr if (!empty($data['nopublimit'])) { $article['pubtypedescr'] = $publication_types[$article['pubtype_id']]['description']; //jojodee: while we are here bring the pubtype name back as well $article['pubtypename'] = $publication_types[$article['pubtype_id']]['name']; } // this will also pass any dynamic data fields (if any) $items[] = $article; } $data['items'] = $items; if (!empty($data['dynamictitle'])) { $this->setTitle($data['title']); } return $data; }
/** * view article map */ function publications_user_viewmap($args) { // Get parameters if (!xarVarFetch('ptid', 'id', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('by', 'enum:pub:cat:grid', $by, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('go', 'str', $go, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) { return; } // Override if needed from argument array extract($args); $default = xarModVars::get('publications', 'defaultpubtype'); if (empty($by)) { if (empty($default) && empty($ptid)) { $by = 'cat'; } else { $by = 'pub'; } } // turn $catid into $cids array (and set $andcids flag) if (!empty($catid)) { if (strpos($catid, ' ')) { $cids = explode(' ', $catid); $andcids = true; } elseif (strpos($catid, '+')) { $cids = explode('+', $catid); $andcids = true; } else { $cids = explode('-', $catid); $andcids = false; } } $seencid = array(); if (isset($cids) && is_array($cids)) { foreach ($cids as $cid) { // make sure cids are numeric if (!empty($cid) && is_numeric($cid)) { $seencid[$cid] = 1; } } $cids = array_keys($seencid); sort($cids, SORT_NUMERIC); } // Get publication types sys::import('modules.dynamicdata.class.objects.master'); $object = DataObjectMaster::getObjectList(array('name' => 'publications_types')); $data['pubtypes'] = $object->getItems(); // redirect to filtered view if (!empty($go) && (!empty($ptid) || $by == 'cat')) { if (is_array($cids) && count($cids) > 0) { $catid = join('+', $cids); } else { $catid = NULL; } $url = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $catid)); xarController::redirect($url); return; } $data['catfilter'] = array(); $data['cattree'] = array(); $data['catgrid'] = array(); $dump = ''; $publinks = array(); if ($by == 'cat') { $data['maplink'] = xarModURL('publications', 'user', 'viewmap', array('by' => 'cat')); // TODO: re-evaluate this after user feedback... // *trick* Use the 'default' categories here, instead of all rootcats $basecats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications')); $catlist = array(); foreach ($basecats as $basecat) { $catlist[$basecat['category_id']] = 1; } $data['basecids'] = array_keys($catlist); // create the category tree for each root category // TODO: make sure permissions are taken into account here ! foreach ($catlist as $cid => $val) { if (empty($val)) { continue; } $data['cattree'][$cid] = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_APPROVED, PUBLICATIONS_STATE_FRONTPAGE), 'cid' => $cid, 'ptid' => null, 'showcid' => true)); } } elseif ($by == 'grid') { $data['catgrid'][0] = array(); $data['catgrid'][0][0] = ''; // Get the base categories if (!empty($ptid)) { $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid)); } else { $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => 0)); $ptid = null; } if (count($rootcats) != 2) { $data['catgrid'][0][0] = xarML('You need 2 base categories in order to use this grid view'); } else { $catlist = array(); if (!empty($rootcats) && is_array($rootcats)) { foreach ($rootcats as $cid) { $catlist[$catid['category_id']] = 1; } } $cattree = array(); // Get the category tree for each base category foreach ($catlist as $cid => $val) { if (empty($val)) { continue; } $cattree[$cid] = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'cid' => $cid, 'ptid' => $ptid, 'showcid' => true)); } // Find out which category tree is the shortest if (count($cattree[$rootcats[0]]) > count($cattree[$rootcats[1]])) { $rowcat = $rootcats[0]; $colcat = $rootcats[1]; } else { $rowcat = $rootcats[1]; $colcat = $rootcats[0]; } // Fill in the column headers $row = 0; $col = 1; $colcid = array(); foreach ($cattree[$colcat] as $info) { $data['catgrid'][$row][$col] = '<a href="' . $info['link'] . '">' . $info['name'] . '</a>'; $colcid[$info['id']] = $col; $col++; } $maxcol = $col; // Fill in the row headers $row = 1; $col = 0; $data['catgrid'][$row] = array(); $rowcid = array(); foreach ($cattree[$rowcat] as $info) { $data['catgrid'][$row][$col] = '<a href="' . $info['link'] . '">' . $info['name'] . '</a>'; $rowcid[$info['id']] = $row; $row++; } $maxrow = $row; // Initialise the rest of the array for ($row = 1; $row < $maxrow; $row++) { if (!isset($data['catgrid'][$row])) { $data['catgrid'][$row] = array(); } for ($col = 1; $col < $maxcol; $col++) { $data['catgrid'][$row][$col] = ''; } } // Get the counts for all groups of (N) categories $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'ptid' => $ptid, 'groupcids' => 2, 'reverse' => 1)); if (!empty($ptid)) { $what = $ptid; } else { $what = 'total'; } // Fill in the count values foreach ($pubcatcount as $cids => $counts) { list($ca, $cb) = explode('+', $cids); if (isset($rowcid[$ca]) && isset($colcid[$cb])) { $link = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $ca . '+' . $cb)); $data['catgrid'][$rowcid[$ca]][$colcid[$cb]] = '<a href="' . $link . '"> ' . $counts[$what] . ' </a>'; } if (isset($rowcid[$cb]) && isset($colcid[$ca])) { $link = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $cb . '+' . $ca)); $data['catgrid'][$rowcid[$cb]][$colcid[$ca]] = '<a href="' . $link . '"> ' . $counts[$what] . ' </a>'; } } } if (!empty($ptid)) { $descr = $data['pubtypes'][$ptid]['description']; } } else { $data['maplink'] = xarModURL('publications', 'user', 'viewmap', array('by' => 'pub')); // get the links and counts for all publication types $publinks = xarModAPIFunc('publications', 'user', 'getpublinks', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'all' => 1)); // build the list of root categories for all publication types // and save results in publinks as well $catlist = array(); for ($i = 0; $i < count($publinks); $i++) { $pubid = $publinks[$i]['pubid']; $cidstring = xarModVars::get('publications', 'mastercids.' . $pubid); if (!empty($cidstring)) { $rootcats = explode(';', $cidstring); foreach ($rootcats as $cid) { $catlist[$cid] = 1; } $publinks[$i]['rootcats'] = $rootcats; } else { $publinks[$i]['rootcats'] = array(); } } // for all publication types for ($i = 0; $i < count($publinks); $i++) { $publinks[$i]['cats'] = array(); $pubid = $publinks[$i]['pubid']; // for each root category of this publication type foreach ($publinks[$i]['rootcats'] as $cid) { // add the category tree to the list of categories to show $childcats = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'cid' => $cid, 'ptid' => $pubid, 'showcid' => true)); $publinks[$i]['cats'][] = $childcats; } } $array = array(); if (empty($ptid)) { $ptid = $default; } if (!empty($ptid)) { for ($i = 0; $i < count($publinks); $i++) { if ($ptid == $publinks[$i]['pubid']) { $array = $publinks[$i]['rootcats']; } } } foreach ($publinks as $pub) { if ($pub['pubid'] == $ptid) { $descr = $pub['pubtitle']; } } } if (empty($descr)) { $descr = xarML('Publications'); $data['descr'] = ''; } else { $data['descr'] = $descr; } // Save some variables to (temporary) cache for use in blocks etc. xarVarSetCached('Blocks.publications', 'ptid', $ptid); //if ($shownavigation) { xarVarSetCached('Blocks.categories', 'module', 'publications'); xarVarSetCached('Blocks.categories', 'itemtype', $ptid); if (!empty($descr)) { xarVarSetCached('Blocks.categories', 'title', $descr); xarTplSetPageTitle(xarML('Map'), xarVarPrepForDisplay($descr)); } //} if (empty($ptid)) { $ptid = null; } $data['publinks'] = $publinks; $data['ptid'] = $ptid; $data['viewlabel'] = xarML('Back to') . ' ' . $descr; $data['viewlink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid)); $data['archivelabel'] = xarML('View Archives'); $data['archivelink'] = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid)); $data['dump'] = $dump; if (count($data['catfilter']) == 2) { } if (!empty($ptid)) { $object = DataObjectMaster::getObject(array('name' => 'publications_types')); $object->getItem(array('itemid' => $ptid)); $template = $object->properties['template']->value; } else { // TODO: allow templates per category ? $template = null; } // Pass the type of map to the template, so we can decide what links to show $data['by'] = $by; return xarTplModule('publications', 'user', 'viewmap', $data, $template); }
function mailer_admin_modifyconfig() { // Security Check if (!xarSecurityCheck('AdminMailer')) { 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; } 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': if (!xarVarFetch('itemsperpage', 'int', $itemsperpage, xarModVars::get('mailer', 'itemsperpage'), XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY)) { return; } if (!xarVarFetch('shorturls', 'checkbox', $shorturls, false, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('modulealias', 'checkbox', $useModuleAlias, xarModVars::get('mailer', 'useModuleAlias'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('aliasname', 'str', $aliasname, xarModVars::get('mailer', 'aliasname'), XARVAR_NOT_REQUIRED)) { return; } xarModVars::set('mailer', 'itemsperpage', $itemsperpage); xarModVars::set('mailer', 'SupportShortURLs', $shorturls); xarModVars::set('mailer', 'useModuleAlias', $useModuleAlias); xarModVars::set('mailer', 'aliasname', $aliasname); break; case 'tab2': break; case 'tab3': break; default: break; } xarController::redirect(xarModURL('mailer', 'admin', 'modifyconfig', array('tab' => $data['tab']))); // Return return true; break; } $data['authid'] = xarSecGenAuthKey(); return $data; }
/** * 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; }
<?php include "usaepaylib.php"; $tran = new umTransaction(); $tran->key = xarModVars::get('shop', 'pg_key'); $tran->ip = $_SERVER['REMOTE_ADDR']; // This allows fraud blocking on the customers ip address $tran->usesandbox = true; $tran->ignoresslcerterrors = true; $tran->card = "4000200011112222"; // card number, no dashes, no spaces $tran->exp = "1212"; // expiration date 4 digits no / $tran->amount = "1.00"; // charge amount in dollars $tran->invoice = "1234"; // invoice number. must be unique. $tran->cardholder = "Test T Jones"; // name of card holder $tran->street = "1234 Main Street"; // street address $tran->zip = "05673"; // zip code $tran->description = "Online Order"; // description of charge $tran->cvv2 = "435"; // cvv2 code echo "<h1>Please wait one moment while we process your card...<br>\n"; flush(); if ($tran->Process()) { echo "<b>Card Approved</b><br>";
/** * This is a standard function to update the configuration parameters of the * module given the information passed back by the modification form */ function calendar_admin_updateconfig() { // Get parameters from whatever input we need. All arguments to this // function should be obtained from xarVarFetch(), xarVarCleanFromInput // is a degraded function. xarVarFetch allows the checking of the input // variables as well as setting default values if needed. Getting vars // from other places such as the environment is not allowed, as that makes // assumptions that will not hold in future versions of Xaraya if (!xarVarFetch('shorturls', 'checkbox', $shorturls, false, XARVAR_NOT_REQUIRED)) { return; } // Variables from phpIcalendar config.inc.php if (!xarVarFetch('default_view', 'isset', $default_view, 'Week', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('minical_view', 'isset', $minical_view, 'Week', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('default_cal', 'isset', $default_cal, array(), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('cal_sdow', 'int:0:6', $cal_sdow, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('day_start', 'isset', $day_start, '0800', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('day_end', 'isset', $day_end, '2100', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('gridLength', 'int:0', $gridLength, 15, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('num_years', 'int:0', $num_years, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('month_event_lines', 'int:0', $month_event_lines, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('tomorrows_events_lines', 'int:0', $tomorrows_events_lines, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('allday_week_lines', 'int:0', $allday_week_lines, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('week_events_lines', 'int:0', $week_events_lines, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('second_offset', 'int:0', $second_offset, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('bleed_time', 'int:0', $bleed_time, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('display_custom_goto', 'checkbox', $display_custom_goto, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('display_ical_list', 'checkbox', $display_ical_list, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('allow_webcals', 'checkbox', $allow_webcals, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('this_months_events', 'checkbox', $this_months_events, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('use_color_cals', 'checkbox', $use_color_cals, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('daysofweek_dayview', 'checkbox', $daysofweek_dayview, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('enable_rss', 'checkbox', $enable_rss, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('show_search', 'checkbox', $show_search, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('allow_preferences', 'checkbox', $allow_preferences, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('printview_default', 'checkbox', $printview_default, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('show_todos', 'checkbox', $show_todos, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('show_completed', 'checkbox', $show_completed, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('allow_login', 'checkbox', $allow_login, 0, XARVAR_NOT_REQUIRED)) { return; } // Confirm authorisation code. This checks that the form had a valid // authorisation code attached to it. If it did not then the function will // proceed no further as it is possible that this is an attempt at sending // in false data to the system if (!xarSecConfirmAuthKey()) { return; } // Update module variables. Note that the default values are set in // xarVarFetch when recieving the incoming values, so no extra processing // is needed when setting the variables here. xarModVars::set('calendar', 'SupportShortURLs', $shorturls); // Variables from phpIcalendar config.inc.php xarModVars::set('calendar', 'default_view', $default_view); xarModVars::set('calendar', 'minical_view', $minical_view); xarModVars::set('calendar', 'default_cal', serialize($default_cal)); xarModVars::set('calendar', 'cal_sdow', $cal_sdow); xarModVars::set('calendar', 'day_start', $day_start); xarModVars::set('calendar', 'day_end', $day_end); xarModVars::set('calendar', 'gridLength', $gridLength); xarModVars::set('calendar', 'num_years', $num_years); xarModVars::set('calendar', 'month_event_lines', $month_event_lines); xarModVars::set('calendar', 'tomorrows_events_lines', $tomorrows_events_lines); xarModVars::set('calendar', 'allday_week_lines', $allday_week_lines); xarModVars::set('calendar', 'week_events_lines', $week_events_lines); xarModVars::set('calendar', 'second_offset', $second_offset); xarModVars::set('calendar', 'bleed_time', $bleed_time); xarModVars::set('calendar', 'display_custom_goto', $display_custom_goto); xarModVars::set('calendar', 'display_ical_list', $display_ical_list); xarModVars::set('calendar', 'allow_webcals', $allow_webcals); xarModVars::set('calendar', 'this_months_events', $this_months_events); xarModVars::set('calendar', 'use_color_cals', $use_color_cals); xarModVars::set('calendar', 'daysofweek_dayview', $daysofweek_dayview); xarModVars::set('calendar', 'enable_rss', $enable_rss); xarModVars::set('calendar', 'show_search', $show_search); xarModVars::set('calendar', 'allow_preferences', $allow_preferences); xarModVars::set('calendar', 'printview_default', $printview_default); xarModVars::set('calendar', 'show_todos', $show_todos); xarModVars::set('calendar', 'show_completed', $show_completed); xarModVars::set('calendar', 'allow_login', $allow_login); xarModCallHooks('module', 'updateconfig', 'calendar', array('module' => 'calendar')); // This function generated no output, and so now it is complete we redirect // the user to an appropriate page for them to carry on their work xarController::redirect(xarModURL('calendar', 'admin', 'modifyconfig')); // Return return true; }
/** * get an array of root categories with links * * @param int $args['ptid'] publication type ID * @param $args['all'] boolean if we need to return all root categories when * ptid is empty (default false) * @return array * @TODO specify return format */ function publications_userapi_getrootcats($args) { extract($args); if (empty($ptid) || !is_numeric($ptid)) { $ptid = null; } // see which root categories we need to handle $rootcats = array(); if (!empty($ptid)) { $rootcats = unserialize(xarModUserVars::get('publications', 'basecids', $ptid)); } elseif (empty($all)) { $rootcats = unserialize(xarModVars::get('publications', 'basecids')); } else { // Get publication types $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); // get base categories for all publication types here $publist = array_keys($pubtypes); // add the defaults too, in case we have other base categories there $publist[] = ''; // build the list of root categories for all required publication types $catlist = array(); foreach ($publist as $pubid) { if (empty($pubid)) { $cidstring = xarModVars::get('publications', 'basecids'); } else { $cidstring = xarModUserVars::get('publications', 'basecids', $pubid); } if (!empty($cidstring)) { $rootcats = unserialize($cidstring); } else { $rootcats = array(); } foreach ($rootcats as $cid) { $catlist[$cid] = 1; } } if (count($catlist) > 0) { $rootcats = array_keys($catlist); } } if (empty($rootcats)) { $rootcats = array(); } if (count($rootcats) < 1) { return array(); } if (!xarModAPILoad('categories', 'user')) { return; } $isfirst = 1; $catlinks = array(); $catlist = xarModAPIFunc('categories', 'user', 'getcatinfo', array('cids' => $rootcats)); if (empty($catlist)) { return $catlinks; } // preserve order of root categories if possible foreach ($rootcats as $cid) { if (!isset($catlist[$cid])) { continue; } $info = $catlist[$cid]; $item = array(); $item['catid'] = $info['cid']; $item['cattitle'] = xarVarPrepForDisplay($info['name']); $item['catlink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $info['cid'])); if ($isfirst) { $item['catjoin'] = ''; $isfirst = 0; } else { $item['catjoin'] = ' | '; } $item['catleft'] = $info['left']; $item['catright'] = $info['right']; $catlinks[] = $item; } return $catlinks; }