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_modify_pubtype($args) { if (!xarSecurityCheck('AdminPublications')) { return; } extract($args); // Get parameters if (!xarVarFetch('itemid', 'isset', $data['itemid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('returnurl', 'str:1', $data['returnurl'], 'view', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('name', 'str:1', $name, '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('tab', 'str:1', $data['tab'], '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) { return; } if (empty($name) && empty($itemid)) { return xarResponse::NotFound(); } // Get our object $data['object'] = DataObjectMaster::getObject(array('name' => 'publications_types')); if (!empty($data['itemid'])) { $data['object']->getItem(array('itemid' => $data['itemid'])); } else { $type_list = DataObjectMaster::getObjectList(array('name' => 'publications_types')); $where = 'name = ' . $name; $items = $type_list->getItems(array('where' => $where)); $item = current($items); $data['object']->getItem(array('itemid' => $item['id'])); } // Send the publication type and the object properties to the template $data['properties'] = $data['object']->getProperties(); // Get the settings of the publication type we are using $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['itemid'])); if ($data['confirm']) { // Check for a valid confirmation key if (!xarSecConfirmAuthKey()) { return; } // Get the data from the form $isvalid = $data['object']->checkInput(); if (!$isvalid) { // Bad data: redisplay the form with error messages return xarTplModule('publications', 'admin', 'modify_pubtype', $data); } else { // Good data: create the item $itemid = $data['object']->updateItem(array('itemid' => $data['itemid'])); // Jump to the next page xarController::redirect(xarModURL('publications', 'admin', 'view_pubtypes')); return true; } } return $data; }
/** * Modify a customer */ function shop_admin_modifycustomer() { if (!xarVarFetch('itemid', 'id', $data['itemid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) { return; } $objectname = 'shop_customers'; $data['objectname'] = $objectname; // Check if we still have no id of the item to modify. if (empty($data['itemid'])) { $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'item id', 'admin', 'modify', 'shop'); throw new Exception($msg); } if (!xarSecurityCheck('AdminShop', 1, 'Item', $data['itemid'])) { return; } sys::import('modules.dynamicdata.class.objects.master'); $object = DataObjectMaster::getObject(array('name' => $objectname)); $data['object'] = $object; $data['label'] = $object->label; $object->getItem(array('itemid' => $data['itemid'])); $values = $object->getFieldValues(); foreach ($values as $name => $value) { $data[$name] = xarVarPrepForDisplay($value); } $rolesobject = DataObjectMaster::getObject(array('name' => 'roles_users')); $rolesobject->getItem(array('itemid' => $data['itemid'])); if ($data['confirm']) { // Check for a valid confirmation key if (!xarSecConfirmAuthKey()) { return xarTplModule('privileges', 'user', 'errors', array('layout' => 'bad_author')); } // Get the data from the form $isvalid = $object->checkInput(); if (!$isvalid) { // Bad data: redisplay the form with the data we picked up and with error messages return xarTplModule('shop', 'admin', 'modifycustomer', $data); } elseif (isset($data['preview'])) { // Show a preview, same thing as the above essentially return xarTplModule('shop', 'admin', 'modifycustomer', $data); } else { $first_name = $object->properties['first_name']->getValue(); $last_name = $object->properties['last_name']->getValue(); $rolesobject->properties['name']->setValue($first_name . ' ' . $last_name); $rolesobject->updateItem(); $object->updateItem(); // Jump to the next page xarResponse::redirect(xarModURL('shop', 'admin', 'modifycustomer', array('itemid' => $data['itemid']))); return $data; } } else { // Get that specific item of the object $object->getItem(array('itemid' => $data['itemid'])); } // Return the template variables defined in this function return $data; }
/** * Create a new customer */ function shop_user_newcustomer() { if (!xarVarFetch('objectid', 'id', $data['objectid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('returnurl', 'str', $returnurl, NULL, XARVAR_NOT_REQUIRED)) { return; } sys::import('modules.dynamicdata.class.objects.master'); $rolesobject = DataObjectMaster::getObject(array('name' => 'roles_users')); $data['properties'] = $rolesobject->properties; // Check if we are in 'preview' mode from the input here - the rest is handled by checkInput() // Here we are testing for a button clicked, so we test for a string if (!xarVarFetch('preview', 'str', $data['preview'], NULL, XARVAR_DONT_SET)) { return; } // Check if we are submitting the form // Here we are testing for a hidden field we define as true on the template, so we can use a boolean (true/false) if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) { return; } if ($data['confirm']) { // Check for a valid confirmation key. The value is automatically gotten from the template if (!xarSecConfirmAuthKey()) { return xarTplModule('privileges', 'user', 'errors', array('layout' => 'bad_author')); } // Get the data from the form and see if it is all valid // Either way the values are now stored in the object $isvalid = $rolesobject->properties['email']->checkInput(); $isvalid2 = $rolesobject->properties['password']->checkInput(); if (!$isvalid || !$isvalid2) { // Bad data: redisplay the form with the data we picked up and with error messages return xarTplModule('shop', 'user', 'newcustomer', $data); } else { $email = $rolesobject->properties['email']->getValue(); $password = $rolesobject->properties['password']->getValue(); $rolesobject->properties['name']->setValue($email); $rolesobject->properties['email']->setValue($email); $rolesobject->properties['uname']->setValue($email); $rolesobject->properties['password']->setValue($password); $rolesobject->properties['state']->setValue(3); $authmodule = (int) xarMod::getID('shop'); $rolesobject->properties['authmodule']->setValue($authmodule); $uid = $rolesobject->createItem(); $custobject = DataObjectMaster::getObject(array('name' => 'shop_customers')); $custobject->createItem(array('id' => $uid)); if (isset($returnurl)) { xarMod::APIFunc('authsystem', 'user', 'login', array('uname' => $email, 'pass' => $password)); xarResponse::redirect($returnurl); } else { xarResponse::redirect(xarModURL('shop')); } // Always add the next line even if processing never reaches it return true; } } // Return the template variables defined in this function 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); }
/** * Overview displays standard Overview page */ function publications_admin_overview() { /* Security Check */ if (!xarSecurityCheck('EditPublications', 0)) { return; } $data = array(); /* if there is a separate overview function return data to it * else just call the main function that usually displays the overview */ return xarTplModule('publications', 'admin', 'main', $data, 'main'); }
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; }
/** * Create a new product */ function shop_admin_newproduct() { // See if the current user has the privilege to add an item. We cannot pass any extra arguments here if (!xarSecurityCheck('Addshop')) { return; } if (!xarVarFetch('objectid', 'id', $data['objectid'], NULL, XARVAR_DONT_SET)) { return; } $objectname = 'shop_products'; $data['objectname'] = $objectname; // Load the DD master object class. This line will likely disappear in future versions sys::import('modules.dynamicdata.class.objects.master'); $object = DataObjectMaster::getObject(array('name' => $objectname)); $data['label'] = $object->label; $data['object'] = $object; // Check if we are in 'preview' mode from the input here - the rest is handled by checkInput() // Here we are testing for a button clicked, so we test for a string if (!xarVarFetch('preview', 'str', $data['preview'], NULL, XARVAR_DONT_SET)) { return; } // Check if we are submitting the form // Here we are testing for a hidden field we define as true on the template, so we can use a boolean (true/false) if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) { return; } if ($data['confirm']) { // Check for a valid confirmation key. The value is automatically gotten from the template if (!xarSecConfirmAuthKey()) { return xarTplModule('privileges', 'user', 'errors', array('layout' => 'bad_author')); } // Get the data from the form and see if it is all valid // Either way the values are now stored in the object $isvalid = $data['object']->checkInput(); if (!$isvalid) { // Bad data: redisplay the form with the data we picked up and with error messages return xarTplModule('shop', 'admin', 'newproduct', $data); } elseif (isset($data['preview'])) { // Show a preview, same thing as the above essentially return xarTplModule('shop', 'admin', 'newproduct', $data); } else { $itemid = $data['object']->createItem(); // Jump to the next page xarResponse::redirect(xarModURL('shop', 'admin', 'products')); return true; } } // Return the template variables defined in this function return $data; }
function publications_admin_multiops() { // Get parameters if (!xarVarFetch('idlist', 'isset', $idlist, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('operation', 'isset', $operation, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('redirecttarget', 'isset', $redirecttarget, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('returnurl', 'str', $returnurl, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('objectname', 'str', $objectname, 'listings_listing', XARVAR_DONT_SET)) { return; } if (!xarVarFetch('localmodule', 'str', $module, 'listings', XARVAR_DONT_SET)) { return; } // Confirm authorisation code //if (!xarSecConfirmAuthKey()) return; // Catch missing params here, rather than below if (empty($idlist)) { return xarTplModule('publications', 'user', 'errors', array('layout' => 'no_items')); } if ($operation === '') { return xarTplModule('publications', 'user', 'errors', array('layout' => 'no_operation')); } $ids = explode(',', $idlist); switch ($operation) { case 0: foreach ($ids as $id => $val) { if (empty($val)) { continue; } // Get the item $item = $object->getItem(array('itemid' => $val)); // Update it if (!$object->deleteItem(array('state' => $operation))) { return; } } break; } return true; }
/** * Start the checkout process -- user can create account or log into existing account */ function shop_user_start() { // Redirects at the start of the user functions are just a way to make sure someone isn't where they don't need to be if (xarUserIsLoggedIn()) { xarResponse::redirect(xarModURL('shop', 'user', 'viewcart')); return true; } $shop = xarSession::getVar('shop'); if (empty($shop)) { xarResponse::redirect(xarModURL('shop', 'user', 'main')); return true; } sys::import('modules.dynamicdata.class.objects.master'); sys::import('modules.dynamicdata.class.properties.master'); $rolesobject = DataObjectMaster::getObject(array('name' => 'roles_users')); $properties = $rolesobject->properties; $data['properties'] = $properties; $isvalid = $rolesobject->properties['email']->checkInput(); $isvalid2 = $rolesobject->properties['password']->checkInput(); if ($isvalid && $isvalid2) { if (!xarSecConfirmAuthKey()) { // right time to do this?? return xarTplModule('privileges', 'user', 'errors', array('layout' => 'bad_author')); } // Create the role and the customer object and then log in $email = $rolesobject->properties['email']->getValue(); $password = $rolesobject->properties['password']->getValue(); $values['name'] = $email; $values['email'] = $email; $values['uname'] = $email; $values['password'] = $password; $values['state'] = 3; $rolesobject->setFieldValues($values, 1); $uid = $rolesobject->createItem(); $custobject = DataObjectMaster::getObject(array('name' => 'shop_customers')); $custobject->createItem(array('id' => $uid)); $name = 'dd_' . $properties['password']->id; $vals = $properties['password']->fetchValue($name); $pass = $vals[1][0]; $res = xarMod::APIFunc('authsystem', 'user', 'login', array('uname' => $email, 'pass' => $pass)); xarResponse::redirect(xarModURL('shop', 'user', 'shippingaddress')); return true; } else { // We don't yet have a valid email or password for registration... return xarTplModule('shop', 'user', 'start', $data); } }
/** * Display a product */ function shop_user_product($args) { if (!xarVarFetch('itemid', 'id', $itemid, NULL, XARVAR_DONT_SET)) { return; } extract($args); if (!empty($objectid)) { $itemid = $objectid; } if (empty($itemid)) { $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'item id', 'user', 'display', 'shop'); throw new Exception($msg); } // Make sure user has read privileges for the item if (!xarSecurityCheck('ReadShop', 1, 'Item', $itemid)) { return; } // Load the DD master object class. This line will likely disappear in future versions sys::import('modules.dynamicdata.class.objects.master'); // Get the object definition we'll be working with $object = DataObjectMaster::getObject(array('name' => 'shop_products')); $data['object'] = $object; //We don't really have the item until we call getItem() $some_id = $object->getItem(array('itemid' => $itemid)); //Make sure we got something if (!isset($some_id) || $some_id != $itemid) { return; } //Get the property names and values for the item with the getFieldValues() method $values = $object->getFieldValues(); $data['itemid'] = $itemid; //$values is an associative array of property names and values, so... foreach ($values as $name => $value) { $data[$name] = xarVarPrepForDisplay($value); } $data['editurl'] = ''; if (xarSecurityCheck('EditShop', 1)) { $data['editurl'] = xarModURL('shop', 'admin', 'modify', array('itemid' => $itemid, 'name' => 'shop_products')); } return xarTplModule('shop', 'user', 'product', $data); }
function publications_user_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) { // Preview or bad data: redisplay the form $data['properties'] = $data['object']->getProperties(); if ($data['preview']) { $data['tab'] = 'preview'; } return xarTplModule('publications', 'user', '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')) { xarResponse::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid']))); } else { xarResponse::redirect(xarModURL('publications', 'user', 'view', array('ptid' => $data['ptid']))); } return true; }
function wurfl_admin_modify() { if (!xarSecurityCheck('EditWurfl')) { return; } if (!xarVarFetch('name', 'str', $name, 'wurfl_wurfl', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('itemid', 'int', $data['itemid'], 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) { return; } $data['object'] = DataObjectMaster::getObject(array('name' => $name)); $data['object']->getItem(array('itemid' => $data['itemid'])); $data['tplmodule'] = 'wurfl'; $data['authid'] = xarSecGenAuthKey('wurfl'); if ($data['confirm']) { // Check for a valid confirmation key if (!xarSecConfirmAuthKey()) { return; } // Get the data from the form $isvalid = $data['object']->checkInput(); if (!$isvalid) { // Bad data: redisplay the form with error messages return xarTplModule('wurfl', 'admin', 'modify', $data); } else { // Good data: create the item $itemid = $data['object']->updateItem(array('itemid' => $data['itemid'])); // Jump to the next page xarController::redirect(xarModURL('wurfl', 'admin', 'view')); return true; } } return $data; }
function wurfl_admin_new() { if (!xarSecurityCheck('AddWurfl')) { return; } if (!xarVarFetch('name', 'str', $name, 'wurfl_wurfl', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) { return; } $data['object'] = DataObjectMaster::getObject(array('name' => $name)); $data['tplmodule'] = 'wurfl'; $data['authid'] = xarSecGenAuthKey('wurfl'); if ($data['confirm']) { // we only retrieve 'preview' from the input here - the rest is handled by checkInput() if (!xarVarFetch('preview', 'str', $preview, NULL, XARVAR_DONT_SET)) { return; } // Check for a valid confirmation key if (!xarSecConfirmAuthKey()) { return; } // Get the data from the form $isvalid = $data['object']->checkInput(); if (!$isvalid) { // Bad data: redisplay the form with error messages return xarTplModule('wurfl', 'admin', 'new', $data); } else { // Good data: create the item $itemid = $data['object']->createItem(); // Jump to the next page xarController::redirect(xarModURL('wurfl', 'admin', 'view')); return true; } } return $data; }
/** * 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); }
/** * 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 publications_user_modify($args) { if (!xarSecurityCheck('UserEditPublications')) { return; } extract($args); // Get parameters if (!xarVarFetch('itemid', 'isset', $data['itemid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('returnurl', 'str:1', $data['returnurl'], 'view', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('name', 'str:1', $name, '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('tab', 'str:1', $data['tab'], '', XARVAR_NOT_REQUIRED)) { return; } if (empty($name) && empty($ptid)) { return xarResponse::NotFound(); } if (!empty($ptid)) { $publication_type = DataObjectMaster::getObjectList(array('name' => 'publications_types')); $where = 'id = ' . $ptid; $items = $publication_type->getItems(array('where' => $where)); $item = current($items); $name = $item['name']; } // Get our object $data['object'] = DataObjectMaster::getObject(array('name' => $name)); $data['object']->getItem(array('itemid' => $data['itemid'])); $data['ptid'] = $data['object']->properties['itemtype']->value; // Send the publication type and the object properties to the template $data['properties'] = $data['object']->getProperties(); // Get the settings of the publication type we are using $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid'])); // If creating a new translation get an empty copy if ($data['tab'] == 'newtranslation') { $data['object']->properties['id']->setValue(0); $data['object']->properties['parent']->setValue($data['itemid']); $data['items'][0] = $data['object']->getFieldValues(array(), 1); $data['tab'] = ''; } else { $data['items'] = array(); } // Get the base document. If this itemid is not the base doc, // then first find the correct itemid $data['object']->getItem(array('itemid' => $data['itemid'])); $fieldvalues = $data['object']->getFieldValues(array(), 1); if (!empty($fieldvalues['parent'])) { $data['itemid'] = $fieldvalues['parent']; $data['object']->getItem(array('itemid' => $data['itemid'])); $fieldvalues = $data['object']->getFieldValues(array(), 1); } $data['items'][$data['itemid']] = $fieldvalues; // Get any translations of the base document $data['objectlist'] = DataObjectMaster::getObjectList(array('name' => $name)); $where = "parent = " . $id; $items = $data['objectlist']->getItems(array('where' => $where)); foreach ($items as $key => $value) { $data['object']->getItem(array('itemid' => $key)); $data['items'][$key] = $data['object']->getFieldValues(array(), 1); } if (!empty($ptid)) { $template = $item['name']; } else { // TODO: allow templates per category ? $template = null; } // Send the publication type and the object properties to the tempate $data['properties'] = $data['object']->getProperties(); $data['ptid'] = $data['properties']['itemtype']->value; // Get the settings of the publication type we are using $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid'])); return xarTplModule('publications', 'user', 'modify', $data, $template); }
function publications_admin_updateconfig() { // Confirm authorisation code if (!xarSecConfirmAuthKey()) { return; } // Get parameters //A lot of these probably are bools, still might there be a need to change the template to return //'true' and 'false' to use those... if (!xarVarFetch('settings', 'array', $settings, array(), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('usetitleforurl', 'int', $usetitleforurl, xarModVars::get('publications', 'usetitleforurl'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('defaultstate', 'isset', $defaultstate, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('defaultsort', 'isset', $defaultsort, 'date', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('usealias', 'int', $usealias, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('ptid', 'isset', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('multilanguage', 'int', $multilanguage, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('tab', 'str:1:10', $data['tab'], 'global', XARVAR_NOT_REQUIRED)) { return; } if (!xarSecurityCheck('AdminPublications', 1, 'Publication', "{$ptid}:All:All:All")) { return; } if ($data['tab'] == 'global') { if (!xarVarFetch('defaultpubtype', 'isset', $defaultpubtype, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('sortpubtypes', 'isset', $sortpubtypes, 'id', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('defaultlanguage', 'str:1:100', $defaultlanguage, xarModVars::get('publications', 'defaultlanguage'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('debugmode', 'checkbox', $debugmode, xarModVars::get('publications', 'debugmode'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('defaultfrontpage', 'str', $defaultfrontpage, xarModVars::get('publications', 'defaultfrontpage'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('defaultbackpage', 'str', $defaultbackpage, xarModVars::get('publications', 'defaultbackpage'), XARVAR_NOT_REQUIRED)) { return; } xarModVars::set('publications', 'defaultpubtype', $defaultpubtype); xarModVars::set('publications', 'sortpubtypes', $sortpubtypes); xarModVars::set('publications', 'defaultlanguage', $defaultlanguage); xarModVars::set('publications', 'debugmode', $debugmode); xarModVars::set('publications', 'usealias', $usealias); xarModVars::set('publications', 'usetitleforurl', $usetitleforurl); xarModVars::set('publications', 'defaultfrontpage', $defaultfrontpage); xarModVars::set('publications', 'defaultbackpage', $defaultbackpage); // Allow multilanguage only if the languages property is present sys::import('modules.dynamicdata.class.properties.registration'); $types = PropertyRegistration::Retrieve(); if (isset($types[30039])) { xarModVars::set('publications', 'multilanguage', $multilanguage); } else { xarModVars::set('publications', 'multilanguage', 0); } // Get the special pages. foreach (array('defaultpage', 'errorpage', 'notfoundpage', 'noprivspage') as $special_name) { unset($special_id); if (!xarVarFetch($special_name, 'id', $special_id, 0, XARVAR_NOT_REQUIRED)) { return; } xarModVars::set('publications', $special_name, $special_id); } if (xarDB::getType() == 'mysql') { if (!xarVarFetch('fulltext', 'isset', $fulltext, '', XARVAR_NOT_REQUIRED)) { return; } $oldval = xarModVars::get('publications', 'fulltextsearch'); $index = 'i_' . xarDB::getPrefix() . '_publications_fulltext'; if (empty($fulltext) && !empty($oldval)) { // Get database setup $dbconn = xarDB::getConn(); $xartable = xarDB::getTables(); $publicationstable = $xartable['publications']; // Drop fulltext index on publications table $query = "ALTER TABLE {$publicationstable} DROP INDEX {$index}"; $result =& $dbconn->Execute($query); if (!$result) { return; } xarModVars::set('publications', 'fulltextsearch', ''); } elseif (!empty($fulltext) && empty($oldval)) { $searchfields = array('title', 'description', 'summary', 'body1', 'notes'); // $searchfields = explode(',',$fulltext); // Get database setup $dbconn = xarDB::getConn(); $xartable = xarDB::getTables(); $publicationstable = $xartable['publications']; // Add fulltext index on publications table $query = "ALTER TABLE {$publicationstable} ADD FULLTEXT {$index} (" . join(', ', $searchfields) . ")"; $result =& $dbconn->Execute($query); if (!$result) { return; } xarModVars::set('publications', 'fulltextsearch', join(',', $searchfields)); } } // Module settings $data['module_settings'] = xarMod::apiFunc('base', 'admin', 'getmodulesettings', array('module' => 'publications')); $data['module_settings']->setFieldList('items_per_page, use_module_alias, module_alias_name, enable_short_urls, user_menu_link', 'use_module_icons'); $isvalid = $data['module_settings']->checkInput(); if (!$isvalid) { return xarTplModule('base', 'admin', 'modifyconfig', $data); } else { $itemid = $data['module_settings']->updateItem(); } // Pull the base category ids from the template and save them $picker = DataPropertyMaster::getProperty(array('name' => 'categorypicker')); $picker->checkInput('basecid'); } elseif ($data['tab'] == 'pubtypes') { // Get the publication type for this display and save the settings to it $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $ptid)); $configsettings = $pubtypeobject->properties['configuration']->getValue(); $checkbox = DataPropertyMaster::getProperty(array('name' => 'checkbox')); $boxes = array('show_hitount', 'show_ratings', 'show_keywords', 'show_comments', 'show_prevnext', 'show_archives', 'show_publinks', 'show_pubcount', 'show_map', 'prevnextart', 'dot_transform', 'title_transform', 'show_categories', 'show_catcount', 'show_prevnext', 'allow_translations'); foreach ($boxes as $box) { $isvalid = $checkbox->checkInput($box); if ($isvalid) { $settings[$box] = $checkbox->value; } } // foreach ($configsettings as $key => $value) // if (!isset($settings[$key])) $settings[$key] = 0; $isvalid = true; // Get the default access rules $access = DataPropertyMaster::getProperty(array('name' => 'access')); $validprop = $access->checkInput("access_add"); $addaccess = $access->value; $isvalid = $isvalid && $validprop; $validprop = $access->checkInput("access_display"); $displayaccess = $access->value; $isvalid = $isvalid && $validprop; $validprop = $access->checkInput("access_modify"); $modifyaccess = $access->value; $isvalid = $isvalid && $validprop; $validprop = $access->checkInput("access_delete"); $deleteaccess = $access->value; $isvalid = $isvalid && $validprop; $allaccess = array('add' => $addaccess, 'display' => $displayaccess, 'modify' => $modifyaccess, 'delete' => $deleteaccess); $pubtypeobject->properties['access']->setValue(serialize($allaccess)); $pubtypeobject->properties['configuration']->setValue(serialize($settings)); $pubtypeobject->updateItem(array('itemid' => $ptid)); $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); if ($usealias) { xarModSetAlias($pubtypes[$ptid]['name'], 'publications'); } else { xarModDelAlias($pubtypes[$ptid]['name'], 'publications'); } } elseif ($data['tab'] == 'redirects') { $redirects = DataPropertyMaster::getProperty(array('name' => 'array')); $redirects->display_column_definition['value'] = array(array("From", "To"), array(2, 2), array("", ""), array("", "")); $isvalid = $redirects->checkInput("redirects"); xarModVars::set('publications', 'redirects', $redirects->value); } xarController::redirect(xarModURL('publications', 'admin', 'modifyconfig', array('ptid' => $ptid, 'tab' => $data['tab']))); return true; }
function publications_admin_update() { // Get parameters if (!xarVarFetch('itemid', 'isset', $data['itemid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('items', 'str', $items, '', XARVAR_DONT_SET)) { return; } if (!xarVarFetch('ptid', 'isset', $data['ptid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('modify_cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('preview', 'isset', $data['preview'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('quit', 'isset', $data['quit'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('front', 'isset', $data['front'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('tab', 'str:1', $data['tab'], '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('returnurl', 'str:1', $data['returnurl'], 'view', XARVAR_NOT_REQUIRED)) { return; } // Confirm authorisation code // This has been disabled for now // if (!xarSecConfirmAuthKey()) return; $items = explode(',', $items); $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); // First we need to check all the data on the template // If checkInput fails, don't bail $itemsdata = array(); $isvalid = true; foreach ($items as $prefix) { $data['object']->setFieldPrefix($prefix); // Disable the celkoposition property according if this is not the base document $fieldname = $prefix . '_dd_' . $data['object']->properties['parent']->id; $data['object']->properties['parent']->checkInput($fieldname); if (empty($data['object']->properties['parent']->value)) { $data['object']->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISPLAYONLY); } else { $data['object']->properties['position']->setDisplayStatus(DataPropertyMaster::DD_DISPLAYSTATE_DISABLED); } // Now get the input from the form $thisvalid = $data['object']->checkInput(); $isvalid = $isvalid && $thisvalid; // Store each item for later processing $itemsdata[$prefix] = $data['object']->getFieldValues(array(), 1); } 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'; } $data['items'] = $itemsdata; // Get the settings of the publication type we are using $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid'])); return xarTplModule('publications', 'admin', 'modify', $data); } // call transform input hooks $article['transform'] = array('summary', 'body', 'notes'); $article = xarModCallHooks('item', 'transform-input', $data['itemid'], $article, 'publications', $data['ptid']); // Now talk to the database. Loop through all the translation pages foreach ($itemsdata as $id => $itemdata) { // Get the data for this item $data['object']->setFieldValues($itemdata, 1); // Save or create the item (depends whether this translation is new) if (empty($id)) { $item = $data['object']->createItem(); } else { $item = $data['object']->updateItem(); } // Check if we have an alias and set it as an alias of the publications module $alias_flag = $data['object']->properties['alias_flag']->value; if ($alias_flag == 1) { $alias = $data['object']->properties['alias']->value; if (!empty($alias)) { xarModAlias::set($alias, 'publications'); } } elseif ($alias_flag == 2) { $alias = $data['object']->properties['name']->value; if (!empty($alias)) { xarModAlias::set($alias, 'publications'); } } // Clear the itemid property in preparation for the next round unset($data['object']->itemid); } // Success xarSession::setVar('statusmsg', xarML('Publication Updated')); // If quitting, go to admin view; otherwise redisplay the page if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) { if ($data['quit']) { // Redirect if we came from somewhere else $current_listview = xarSession::getVar('publications_current_listview'); if (!empty($current_listview)) { xarController::redirect($current_listview); } xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid']))); } elseif ($data['front']) { xarController::redirect(xarModURL('publications', 'user', 'display', array('name' => $pubtypeobject->properties['name']->value, 'itemid' => $data['itemid']))); } else { xarController::redirect(xarModURL('publications', 'admin', 'modify', array('name' => $pubtypeobject->properties['name']->value, 'itemid' => $data['itemid']))); } return true; } }
/** * Select existing payment method or create new one to use for this transaction */ function shop_user_paymentmethod() { // Redirects at the start of the user functions are just a way to make sure someone isn't where they don't need to be $shippingaddress = xarSession::getVar('shippingaddress'); if (empty($shippingaddress)) { xarResponse::redirect(xarModURL('shop', 'user', 'shippingaddress')); return true; } $shop = xarSession::getVar('shop'); if (!xarUserIsLoggedIn() || empty($shop)) { xarResponse::redirect(xarModURL('shop', 'user', 'main')); return true; } if (!xarVarFetch('proceedsaved', 'str', $proceedsaved, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('proceednew', 'str', $proceednew, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('paymentmethod', 'str', $paymentmethod, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('remove', 'str', $remove, NULL, XARVAR_NOT_REQUIRED)) { return; } $cust = xarMod::APIFunc('shop', 'user', 'customerinfo'); $data['cust'] = $cust; sys::import('modules.dynamicdata.class.objects.master'); sys::import('modules.dynamicdata.class.properties.master'); $shippingobject = DataObjectMaster::getObject(array('name' => 'shop_shippingaddresses')); $shippingobject->getItem(array('itemid' => xarSession::getVar('shippingaddress'))); $shippingvals = $shippingobject->getFieldValues(); $data['shippingvals'] = $shippingvals; // Get the saved payment methods, if any exist $mylist = DataObjectMaster::getObjectList(array('name' => 'shop_paymentmethods')); $filters = array('status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'where' => 'customer eq ' . xarUserGetVar('id')); $paymentmethods = $mylist->getItems($filters); $data['paymentmethods'] = $paymentmethods; $data['paymentobject'] = DataObjectMaster::getObject(array('name' => 'shop_paymentmethods')); $data['paymentobject']->properties['name']->display_show_salutation = false; $data['paymentobject']->properties['name']->display_show_middlename = false; $data['paymentobject']->properties['address']->display_rows = 1; $data['paymentobject']->properties['address']->display_show_country = false; $data['properties'] = $data['paymentobject']->getProperties(); if ($remove) { if ($remove == xarSession::getVar('paymentmethod')) { xarSession::delVar('paymentmethod'); } $data['paymentobject']->getItem(array('itemid' => $remove)); $data['paymentobject']->deleteItem(); xarResponse::redirect(xarModURL('shop', 'user', 'paymentmethod')); return true; } $selectedpaymentmethod = xarSession::getVar('paymentmethod'); if (!empty($selectedpaymentmethod)) { $data['paymentmethod'] = $selectedpaymentmethod; } // If we're using a saved payment method... if ($proceedsaved) { xarSession::setVar('paymentmethod', $paymentmethod); xarResponse::redirect(xarModURL('shop', 'user', 'order')); return true; } elseif ($proceednew) { // We're not using a saved payment method... $isvalid = $data['paymentobject']->checkInput(); if (isset($exp_date)) { $exp_month = substr($exp_date, 0, 2); $exp_year = substr($exp_date, 2, 4); $reverse_date = $exp_year . $exp_month; $minimum_date = date('ym', time()); if ($minimum_date > $reverse_date) { $errors['exp_date'] = true; } } if (isset($errors)) { xarSession::setVar('errors', $errors); } if (!$isvalid) { return xarTplModule('shop', 'user', 'paymentmethod', $data); } else { xarSession::setVar('paymentmethod', $data['paymentobject']->createItem()); xarResponse::redirect(xarModURL('shop', 'user', 'order')); return true; } } return $data; }
function publications_admin_display($args) { // Get parameters from user // this is used to determine whether we come from a pubtype-based view or a // categories-based navigation // Note we support both id and itemid if (!xarVarFetch('name', 'str', $name, '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('ptid', 'id', $ptid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('itemid', 'id', $itemid, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('id', 'id', $id, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('page', 'int:1', $page, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('translate', 'int:1', $translate, 1, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('layout', 'str:1', $layout, 'detail', XARVAR_NOT_REQUIRED)) { return; } // Override xarVarFetch extract($args); //The itemid var takes precedence if it exiata if (isset($itemid)) { $id = $itemid; } # -------------------------------------------------------- # # If no ID supplied, try getting the id of the default page. # if (empty($id)) { $id = xarModVars::get('publications', 'defaultpage'); } # -------------------------------------------------------- # # Get the ID of the translation if required # // First save the "untranslated" id xarVarSetCached('Blocks.publications', 'current_base_id', $id); if ($translate) { $id = xarMod::apiFunc('publications', 'user', 'gettranslationid', array('id' => $id)); } # -------------------------------------------------------- # # If still no ID, check if we are trying to display a pubtype # if (empty($name) && empty($ptid) && empty($id)) { // Nothing to be done $id = xarModVars::get('publications', 'notfoundpage'); } elseif (empty($id)) { // We're missing an id but can get a pubtype: jump to the pubtype view xarController::redirect(xarModURL('publications', 'user', 'view')); } # -------------------------------------------------------- # # If still no ID, we have come to the end of the line # if (empty($id)) { return xarResponse::NotFound(); } # -------------------------------------------------------- # # We have an ID, now first get the page # // Here we get the publication type first, and then from that the page // Perhaps more efficient to get the page directly? $ptid = xarMod::apiFunc('publications', 'user', 'getitempubtype', array('itemid' => $id)); // An empty publication type means the page does not exist if (empty($ptid)) { return xarResponse::NotFound(); } /* if (empty($name) && empty($ptid)) return xarResponse::NotFound(); if(empty($ptid)) { $publication_type = DataObjectMaster::getObjectList(array('name' => 'publications_types')); $where = 'name = ' . $name; $items = $publication_type->getItems(array('where' => $where)); $item = current($items); $ptid = $item['id']; } */ $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $ptid)); $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); // $id = xarMod::apiFunc('publications','user','gettranslationid',array('id' => $id)); $itemid = $data['object']->getItem(array('itemid' => $id)); # -------------------------------------------------------- # # Are we allowed to see this page? # $accessconstraints = unserialize($data['object']->properties['access']->value); $access = DataPropertyMaster::getProperty(array('name' => 'access')); $allow = $access->check($accessconstraints['display']); $nopublish = time() < $data['object']->properties['start_date']->value || time() > $data['object']->properties['end_date']->value && !$data['object']->properties['no_end']->value; // If no access, then bail showing a forbidden or an empty page if (!$allow || $nopublish) { if ($accessconstraints['display']['failure']) { return xarResponse::Forbidden(); } else { return xarTplModule('publications', 'user', 'empty'); } } # -------------------------------------------------------- # # If this is a redirect page, then send it on its way now # $redirect_type = $data['object']->properties['redirect_flag']->value; if ($redirect_type == 1) { // This is a simple redirect to another page try { $url = $data['object']->properties['redirect_url']->value; // Check if this is a Xaraya function $pos = strpos($url, 'xar'); if ($pos === 0) { eval('$url = ' . $url . ';'); } xarController::redirect($url, 301); } catch (Exception $e) { return xarResponse::NotFound(); } } elseif ($redirect_type == 2) { // This displays a page of a different module // If this is from a link of a redirect child page, use the child param as new URL if (!xarVarFetch('child', 'str', $child, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!empty($child)) { // Turn entities into amps $url = urldecode($child); } else { $url = $data['object']->properties['proxy_url']->value; } // Bail if the URL is bad try { // Check if this is a Xaraya function $pos = strpos($url, 'xar'); if ($pos === 0) { eval('$url = ' . $url . ';'); } $params = parse_url($url); $params['query'] = preg_replace('/&/', '&', $params['query']); } catch (Exception $e) { return xarResponse::NotFound(); } // If this is an external link, show it without further processing if (!empty($params['host']) && $params['host'] != xarServer::getHost() && $params['host'] . ":" . $params['port'] != xarServer::getHost()) { xarController::redirect($url, 301); } else { parse_str($params['query'], $info); $other_params = $info; unset($other_params['module']); unset($other_params['type']); unset($other_params['func']); unset($other_params['child']); try { $page = xarMod::guiFunc($info['module'], 'user', $info['func'], $other_params); } catch (Exception $e) { return xarResponse::NotFound(); } // Debug // echo xarModURL($info['module'],'user',$info['func'],$other_params); # -------------------------------------------------------- # # For proxy pages: the transform of the subordinate function's template # // Find the URLs in submits $pattern = '/(action)="([^"\\r\\n]*)"/'; preg_match_all($pattern, $page, $matches); $pattern = array(); $replace = array(); foreach ($matches[2] as $match) { $pattern[] = '%</form%'; $replace[] = '<input type="hidden" name="return_url" id="return_url" value="' . urlencode(xarServer::getCurrentURL()) . '"/><input type="hidden" name="child" value="' . urlencode($match) . '"/></form'; } $page = preg_replace($pattern, $replace, $page); $pattern = '/(action)="([^"\\r\\n]*)"/'; $page = preg_replace_callback($pattern, create_function('$matches', 'return $matches[1]."=\\"".xarServer::getCurrentURL()."\\"";'), $page); // Find the URLs in links $pattern = '/(href)="([^"\\r\\n]*)"/'; $page = preg_replace_callback($pattern, create_function('$matches', 'return $matches[1]."=\\"".xarServer::getCurrentURL(array("child" => urlencode($matches[2])))."\\"";'), $page); return $page; } } # -------------------------------------------------------- # # If this is a bloccklayout page, then process it # if ($data['object']->properties['pagetype']->value == 2) { // Get a copy of the compiler sys::import('xaraya.templating.compiler'); $blCompiler = XarayaCompiler::instance(); // Get the data fields $fields = array(); $sourcefields = array('title', 'description', 'summary', 'body1', 'body2', 'body3', 'body4', 'body5', 'notes'); $prefix = strlen('publications.') - 1; foreach ($data['object']->properties as $prop) { if (in_array(substr($prop->source, $prefix), $sourcefields)) { $fields[] = $prop->name; } } // Run each template field through the compiler foreach ($fields as $field) { try { $tplString = '<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout">'; $tplString .= xarMod::apiFunc('publications', 'user', 'prepareforbl', array('string' => $data['object']->properties[$field]->value)); $tplString .= '</xar:template>'; $tplString = $blCompiler->compilestring($tplString); // We don't allow passing $data to the template for now $tpldata = array(); $tplString = xarTplString($tplString, $tpldata); } catch (Exception $e) { var_dump($tplString); } $data['object']->properties[$field]->value = $tplString; } } # -------------------------------------------------------- # # Get the complete tree for this section of pages. We need this for blocks etc. # $tree = xarMod::apiFunc('publications', 'user', 'getpagestree', array('tree_contains_pid' => $id, 'key' => 'id', 'status' => 'ACTIVE,FRONTPAGE,PLACEHOLDER')); // If this page is of type PLACEHOLDER, then look in its descendents if ($data['object']->properties['state']->value == 5) { // Scan for a descendent that is ACTIVE or FRONTPAGE if (!empty($tree['pages'][$id]['child_keys'])) { foreach ($tree['pages'][$id]['child_keys'] as $scan_key) { // If the page is displayable, then treat it as the new page. if ($tree['pages'][$scan_key]['status'] == 3 || $tree['pages'][$scan_key]['status'] == 4) { $id = $tree['pages'][$scan_key]['id']; $id = xarMod::apiFunc('publications', 'user', 'gettranslationid', array('id' => $id)); $itemid = $data['object']->getItem(array('itemid' => $id)); break; } } } } # -------------------------------------------------------- # # Additional data # // Pass the layout to the template $data['layout'] = $layout; // Get the settings for this publication type; $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $ptid)); // The name of this object $data['objectname'] = $data['object']->name; # -------------------------------------------------------- # # Set the theme if needed # if (!empty($data['object']->properties['theme']->value)) { xarTplSetThemeName($data['object']->properties['theme']->value); } # -------------------------------------------------------- # # Set the page template from the pubtype if needed # if (!empty($data['settings']['page_template'])) { $pagename = $data['settings']['page_template']; $position = strpos($pagename, '.'); if ($position === false) { $pagetemplate = $pagename; } else { $pagetemplate = substr($pagename, 0, $position); } xarTpl::setPageTemplateName($pagetemplate); } // It can be overridden by the page itself if (!empty($data['object']->properties['page_template']->value)) { $pagename = $data['object']->properties['page_template']->value; $position = strpos($pagename, '.'); if ($position === false) { $pagetemplate = $pagename; } else { $pagetemplate = substr($pagename, 0, $position); } xarTpl::setPageTemplateName($pagetemplate); } # -------------------------------------------------------- # # Cache data for blocks # // Now we can cache all this data away for the blocks. // The blocks should have access to most of the same data as the page. xarVarSetCached('Blocks.publications', 'pagedata', $tree); // The 'serialize' hack ensures we have a proper copy of the // paga data, which is a self-referencing array. If we don't // do this, then any changes we make will affect the stored version. $data = unserialize(serialize($data)); // Save some values. These are used by blocks in 'automatic' mode. xarVarSetCached('Blocks.publications', 'current_id', $id); xarVarSetCached('Blocks.publications', 'ptid', $ptid); xarVarSetCached('Blocks.publications', 'author', $data['object']->properties['author']->value); # -------------------------------------------------------- # # Make the properties available to the template # $data['properties'] =& $data['object']->properties; return $data; /* // TEST - highlight search terms if(!xarVarFetch('q', 'str', $q, NULL, XARVAR_NOT_REQUIRED)) {return;} */ // Override if needed from argument array (e.g. preview) extract($args); // Defaults if (!isset($page)) { $page = 1; } // via arguments only if (!isset($preview)) { $preview = 0; } /* if ($preview) { if (!isset($publication)) { return xarML('Invalid publication'); } $id = $publication->properties['id']->value; } elseif (!isset($id) || !is_numeric($id) || $id < 1) { return xarML('Invalid publication ID'); } */ /* // Get publication if (!$preview) { $publication = xarModAPIFunc('publications', 'user', 'get', array('id' => $id, 'withcids' => true)); } if (!is_array($publication)) { $msg = xarML('Failed to retrieve publication in #(3)_#(1)_#(2).php', 'userapi', 'get', 'publications'); throw new DataNotFoundException(null, $msg); } // Get publication types $pubtypes = xarModAPIFunc('publications','user','get_pubtypes'); // Check that the publication type is valid, otherwise use the publication's pubtype if (!empty($ptid) && !isset($pubtypes[$ptid])) { $ptid = $publication['pubtype_id']; } */ // keep original ptid (if any) // $ptid = $publication['pubtype_id']; // $pubtype_id = $publication->properties['itemtype']->value; // $owner = $publication->properties['author']->value; /* if (!isset($publication['cids'])) { $publication['cids'] = array(); } $cids = $publication['cids']; */ // Get the publication settings for this publication type if (empty($ptid)) { $settings = unserialize(xarModVars::get('publications', 'settings')); } else { $settings = unserialize(xarModVars::get('publications', 'settings.' . $ptid)); } // show the number of publications for each publication type if (!isset($show_pubcount)) { if (!isset($settings['show_pubcount']) || !empty($settings['show_pubcount'])) { $show_pubcount = 1; // default yes } else { $show_pubcount = 0; } } // show the number of publications for each category if (!isset($show_catcount)) { if (empty($settings['show_catcount'])) { $show_catcount = 0; // default no } else { $show_catcount = 1; } } // Initialize the data array $data = $publication->getFieldValues(); $data['ptid'] = $ptid; // navigation pubtype $data['pubtype_id'] = $pubtype_id; // publication pubtype // TODO: improve the case where we have several icons :) $data['topic_icons'] = ''; $data['topic_images'] = array(); $data['topic_urls'] = array(); $data['topic_names'] = array(); /* if (count($cids) > 0) { if (!xarModAPILoad('categories', 'user')) return; $catlist = xarModAPIFunc('categories', 'user', 'getcatinfo', array('cids' => $cids)); foreach ($catlist as $cat) { $link = xarModURL('publications','user','view', array(//'state' => array(PUBLICATIONS_STATE_FRONTPAGE,PUBLICATIONS_STATE_APPROVED). 'ptid' => $ptid, 'catid' => $cat['cid'])); $name = xarVarPrepForDisplay($cat['name']); $data['topic_urls'][] = $link; $data['topic_names'][] = $name; if (!empty($cat['image'])) { $image = xarTplGetImage($cat['image'],'categories'); $data['topic_icons'] .= '<a href="'. $link .'">'. '<img src="'. $image . '" alt="'. $name .'" />'. '</a>'; $data['topic_images'][] = $image; break; } } } */ // multi-page output for 'body' field (mostly for sections at the moment) $themeName = xarVarGetCached('Themes.name', 'CurrentTheme'); if ($themeName != 'print') { if (strstr($publication->properties['body']->value, '<!--pagebreak-->')) { if ($preview) { $publication['body'] = preg_replace('/<!--pagebreak-->/', '<hr/><div style="text-align: center;">' . xarML('Page Break') . '</div><hr/>', $publication->properties['body']->value); $data['previous'] = ''; $data['next'] = ''; } else { $pages = explode('<!--pagebreak-->', $publication->properties['body']->value); // For documents with many pages, the pages can be // arranged in blocks. $pageBlockSize = 10; // Get pager information: one item per page. $pagerinfo = xarTplPagerInfo(empty($page) ? 1 : $page, count($pages), 1, $pageBlockSize); // Retrieve current page and total pages from the pager info. // These will have been normalised to ensure they are in range. $page = $pagerinfo['currentpage']; $numpages = $pagerinfo['totalpages']; // Discard everything but the current page. $publication['body'] = $pages[$page - 1]; unset($pages); if ($page > 1) { // Don't count page hits after the first page. xarVarSetCached('Hooks.hitcount', 'nocount', 1); } // Pass in the pager info so a complete custom pager // can be created in the template if required. $data['pagerinfo'] = $pagerinfo; // Get the rendered pager. // The pager template (last parameter) could be an // option for the publication type. $urlmask = xarModURL('publications', 'user', 'display', array('ptid' => $ptid, 'id' => $id, 'page' => '%%')); $data['pager'] = xarTplGetPager($page, $numpages, $urlmask, 1, $pageBlockSize, 'multipage'); // Next two assignments for legacy templates. // TODO: deprecate them? $data['next'] = xarTplGetPager($page, $numpages, $urlmask, 1, $pageBlockSize, 'multipagenext'); $data['previous'] = xarTplGetPager($page, $numpages, $urlmask, 1, $pageBlockSize, 'multipageprev'); } } else { $data['previous'] = ''; $data['next'] = ''; } } else { $publication['body'] = preg_replace('/<!--pagebreak-->/', '', $publication['body']); } // TEST if (isset($prevnextart)) { $settings['prevnextart'] = $prevnextart; } if (!empty($settings['prevnextart']) && $preview == 0) { if (!array_key_exists('defaultsort', $settings)) { $settings['defaultsort'] = 'id'; } $prevart = xarModAPIFunc('publications', 'user', 'getprevious', array('id' => $id, 'ptid' => $ptid, 'sort' => $settings['defaultsort'], 'state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'enddate' => time())); if (!empty($prevart['id'])) { //Make all previous publication info available to template $data['prevartinfo'] = $prevart; $data['prevart'] = xarModURL('publications', 'user', 'display', array('ptid' => $prevart['pubtype_id'], 'id' => $prevart['id'])); } else { $data['prevart'] = ''; } $nextart = xarModAPIFunc('publications', 'user', 'getnext', array('id' => $id, 'ptid' => $ptid, 'sort' => $settings['defaultsort'], 'state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'enddate' => time())); if (!empty($nextart['id'])) { //Make all next art info available to template $data['nextartinfo'] = $nextart; $data['nextart'] = xarModURL('publications', 'user', 'display', array('ptid' => $nextart['pubtype_id'], 'id' => $nextart['id'])); } else { $data['nextart'] = ''; } } else { $data['prevart'] = ''; $data['nextart'] = ''; } // Display publication unset($publication); // temp. fix to include dynamic data fields without changing templates if (xarModIsHooked('dynamicdata', 'publications', $pubtype_id)) { list($properties) = xarModAPIFunc('dynamicdata', 'user', 'getitemfordisplay', array('module' => 'publications', 'itemtype' => $pubtype_id, 'itemid' => $id, 'preview' => $preview)); if (!empty($properties) && count($properties) > 0) { foreach (array_keys($properties) as $field) { $data[$field] = $properties[$field]->getValue(); // POOR mans flagging for transform hooks try { $configuration = $properties[$field]->configuration; if (substr($configuration, 0, 10) == 'transform:') { $data['transform'][] = $field; } } catch (Exception $e) { } // TODO: clean up this temporary fix $data[$field . '_output'] = $properties[$field]->showOutput(); } } } // Let any transformation hooks know that we want to transform some text. // You'll need to specify the item id, and an array containing all the // pieces of text that you want to transform (e.g. for autolinks, wiki, // smilies, bbcode, ...). $data['itemtype'] = $pubtype_id; // TODO: what about transforming DDfields ? // <mrb> see above for a hack, needs to be a lot better. // Summary is always included, is that handled somewhere else? (publication config says i can ex/include it) // <mikespub> publications config allows you to call transforms for the publications summaries in the view function if (!isset($title_transform)) { if (empty($settings['title_transform'])) { $data['transform'][] = 'summary'; $data['transform'][] = 'body'; $data['transform'][] = 'notes'; } else { $data['transform'][] = 'title'; $data['transform'][] = 'summary'; $data['transform'][] = 'body'; $data['transform'][] = 'notes'; } } $data = xarModCallHooks('item', 'transform', $id, $data, 'publications'); return xarTplModule('publications', 'user', 'display', $data); if (!empty($data['title'])) { // CHECKME: <rabbit> Strip tags out of the title - the <title> tag shouldn't have any other tags in it. $title = strip_tags($data['title']); xarTplSetPageTitle(xarVarPrepForDisplay($title), xarVarPrepForDisplay($pubtypes[$data['itemtype']]['description'])); // Save some variables to (temporary) cache for use in blocks etc. xarVarSetCached('Comments.title', 'title', $data['title']); } /* if (!empty($q)) { // TODO: split $q into search terms + add style (cfr. handlesearch in search module) foreach ($data['transform'] as $field) { $data[$field] = preg_replace("/$q/","<span class=\"xar-search-match\">$q</span>",$data[$field]); } } */ // Navigation links $data['publabel'] = xarML('Publication'); $data['publinks'] = array(); //xarModAPIFunc('publications','user','getpublinks', // array('state' => array(PUBLICATIONS_STATE_FRONTPAGE,PUBLICATIONS_STATE_APPROVED), // 'count' => $show_pubcount)); if (isset($show_map)) { $settings['show_map'] = $show_map; } if (!empty($settings['show_map'])) { $data['maplabel'] = xarML('View Publication Map'); $data['maplink'] = xarModURL('publications', 'user', 'viewmap', array('ptid' => $ptid)); } if (isset($show_archives)) { $settings['show_archives'] = $show_archives; } if (!empty($settings['show_archives'])) { $data['archivelabel'] = xarML('View Archives'); $data['archivelink'] = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid)); } if (isset($show_publinks)) { $settings['show_publinks'] = $show_publinks; } if (!empty($settings['show_publinks'])) { $data['show_publinks'] = 1; } else { $data['show_publinks'] = 0; } $data['show_catcount'] = $show_catcount; // Tell the hitcount hook not to display the hitcount, but to save it // in the variable cache. if (xarModIsHooked('hitcount', 'publications', $pubtype_id)) { xarVarSetCached('Hooks.hitcount', 'save', 1); $data['dohitcount'] = 1; } else { $data['dohitcount'] = 0; } // Tell the ratings hook to save the rating in the variable cache. if (xarModIsHooked('ratings', 'publications', $pubtype_id)) { xarVarSetCached('Hooks.ratings', 'save', 1); $data['doratings'] = 1; } else { $data['doratings'] = 0; } // Retrieve the current hitcount from the variable cache if ($data['dohitcount'] && xarVarIsCached('Hooks.hitcount', 'value')) { $data['counter'] = xarVarGetCached('Hooks.hitcount', 'value'); } else { $data['counter'] = ''; } // Retrieve the current rating from the variable cache if ($data['doratings'] && xarVarIsCached('Hooks.ratings', 'value')) { $data['rating'] = intval(xarVarGetCached('Hooks.ratings', 'value')); } else { $data['rating'] = ''; } // Save some variables to (temporary) cache for use in blocks etc. xarVarSetCached('Blocks.publications', 'title', $data['title']); // Generating keywords from the API now instead of setting the entire // body into the cache. $keywords = xarModAPIFunc('publications', 'user', 'generatekeywords', array('incomingkey' => $data['body'])); xarVarSetCached('Blocks.publications', 'body', $keywords); xarVarSetCached('Blocks.publications', 'summary', $data['summary']); xarVarSetCached('Blocks.publications', 'id', $id); xarVarSetCached('Blocks.publications', 'ptid', $ptid); xarVarSetCached('Blocks.publications', 'cids', $cids); xarVarSetCached('Blocks.publications', 'owner', $owner); if (isset($data['author'])) { xarVarSetCached('Blocks.publications', 'author', $data['author']); } // TODO: add this to publications configuration ? //if ($shownavigation) { $data['id'] = $id; $data['cids'] = $cids; xarVarSetCached('Blocks.categories', 'module', 'publications'); xarVarSetCached('Blocks.categories', 'itemtype', $ptid); xarVarSetCached('Blocks.categories', 'itemid', $id); xarVarSetCached('Blocks.categories', 'cids', $cids); if (!empty($ptid) && !empty($pubtypes[$ptid]['description'])) { xarVarSetCached('Blocks.categories', 'title', $pubtypes[$ptid]['description']); } // optional category count if ($show_catcount && !empty($ptid)) { $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'ptid' => $ptid)); if (!empty($pubcatcount[$ptid])) { xarVarSetCached('Blocks.categories', 'catcount', $pubcatcount[$ptid]); } } else { // xarVarSetCached('Blocks.categories','catcount',array()); } //} // Module template depending on publication type $template = $pubtypes[$pubtype_id]['name']; // Page template depending on publication type (optional) // Note : this cannot be overridden in templates if (empty($preview) && !empty($settings['page_template'])) { xarTplSetPageTemplateName($settings['page_template']); } // Specific layout within a template (optional) if (isset($layout)) { $data['layout'] = $layout; } $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $ptid)); $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $id = xarMod::apiFunc('publications', 'user', 'getranslationid', array('id' => $id)); $data['object']->getItem(array('itemid' => $id)); return xarTplModule('publications', 'user', 'display', $data, $template); }
/** * New account info (ship address) */ function shop_user_shippingaddress() { // Redirects at the start of the user functions are just a way to make sure someone isn't where they don't need to be $shop = xarSession::getVar('shop'); if (!xarUserIsLoggedIn() || empty($shop)) { xarResponse::redirect(xarModURL('shop', 'user', 'main')); return true; } if (!xarVarFetch('proceed', 'str', $proceed, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('shipto', 'str', $shipto, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('remove', 'str', $remove, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('next', 'str', $data['next'], NULL, XARVAR_NOT_REQUIRED)) { return; } sys::import('modules.dynamicdata.class.objects.master'); $data['shippingobject'] = DataObjectMaster::getObject(array('name' => 'shop_shippingaddresses')); $data['shippingobject']->properties['name']->display_show_salutation = false; $data['shippingobject']->properties['name']->display_show_middlename = false; $data['shippingobject']->properties['address']->display_rows = 1; $data['shippingobject']->properties['address']->display_show_country = false; $data['properties'] = $data['shippingobject']->properties; if ($shipto) { xarSession::setVar('shippingaddress', $shipto); if (isset($data['next']) && !empty($data['next'])) { $func = $data['next']; } else { $func = 'paymentmethod'; } xarResponse::redirect(xarModURL('shop', 'user', $func)); return true; } if ($remove) { if ($remove == xarSession::getVar('shippingaddress')) { xarSession::delVar('shippingaddress'); } $data['shippingobject']->getItem(array('itemid' => $remove)); $data['shippingobject']->deleteItem(); xarResponse::redirect(xarModURL('shop', 'user', 'shippingaddress')); return true; } if ($proceed) { $isvalid = $data['shippingobject']->checkInput(); if (!$isvalid) { return xarTplModule('shop', 'user', 'shippingaddress', $data); } // Save the customer data $custobject = DataObjectMaster::getObject(array('name' => 'shop_customers')); $custobject->getItem(array('itemid' => xarUserGetVar('id'))); $name = $data['shippingobject']->properties['name']->value; $custobject->properties['name']->setValue($name); $custobject->updateItem(); // Save the shipping address $itemid = $data['shippingobject']->createItem(); xarSession::setVar('shippingaddress', $itemid); // update the name field in roles to use first and last name instead of email $rolesobject = xarCurrentRole(); $rolesobject->properties['name']->value = $name; $rolesobject->updateItem(); xarResponse::redirect(xarModURL('shop', 'user', 'paymentmethod')); return true; xarSession::setVar('errors', $errors); } 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_admin_delete_pubtype() { if (!xarSecurityCheck('AdminPublications')) { return; } if (!xarVarFetch('confirmed', 'int', $confirmed, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('itemid', 'str', $itemid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('idlist', 'str', $idlist, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('returnurl', 'str', $returnurl, NULL, XARVAR_DONT_SET)) { return; } if (!empty($itemid)) { $idlist = $itemid; } $ids = explode(',', trim($idlist, ',')); if (empty($idlist)) { if (isset($returnurl)) { xarController::redirect($returnurl); } else { xarController::redirect(xarModURL('publications', 'admin', 'view')); } } $data['message'] = ''; $data['itemid'] = $itemid; /*------------- Ask for Confirmation. If yes, action ----------------------------*/ sys::import('modules.dynamicdata.class.objects.master'); $pubtype = DataObjectMaster::getObject(array('name' => 'publications_types')); if (!isset($confirmed)) { $data['idlist'] = $idlist; if (count($ids) > 1) { $data['title'] = xarML("Delete Publication Types"); } else { $data['title'] = xarML("Delete Publication Type"); } $data['authid'] = xarSecGenAuthKey(); $items = array(); foreach ($ids as $i) { $pubtype->getItem(array('itemid' => $i)); $item = $pubtype->getFieldValues(); $items[] = $item; } $data['items'] = $items; $data['yes_action'] = xarModURL('publications', 'admin', 'delete_pubtype', array('idlist' => $idlist)); return xarTplModule('publications', 'admin', 'delete_pubtype', $data); } else { if (!xarSecConfirmAuthKey()) { return; } foreach ($ids as $id) { $itemid = $pubtype->deleteItem(array('itemid' => $id)); $data['message'] = "Publication Type deleted [ID {$id}]"; } if (isset($returnurl)) { xarController::redirect($returnurl); } else { xarController::redirect(xarModURL('publications', 'admin', 'view_pubtypes', $data)); } return true; } return true; }
function publications_user_update() { // Get parameters if (!xarVarFetch('itemid', 'isset', $itemid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('items', 'str', $items, '', XARVAR_DONT_SET)) { return; } if (!xarVarFetch('ptid', 'isset', $data['ptid'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('modify_cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('preview', 'isset', $data['preview'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('quit', 'isset', $data['quit'], NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('tab', 'str:1', $data['tab'], '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('returnurl', 'str:1', $data['returnurl'], 'view', XARVAR_NOT_REQUIRED)) { return; } // Confirm authorisation code // This has been disabled for now // if (!xarSecConfirmAuthKey()) return; $items = explode(',', $items); $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(); // First we need to check all the data on the template // If checkInput fails, don't bail $itemsdata = array(); $isvalid = true; /*foreach ($items as $prefix) { $data['object']->setFieldPrefix($prefix); $thisvalid = $data['object']->checkInput(); $isvalid = $isvalid && $thisvalid; // Store each item for later processing $itemsdata[$prefix] = $data['object']->getFieldValues(array(),1); }*/ if ($data['preview'] || !$isvalid) { // Preview or bad data: redisplay the form $data['properties'] = $data['object']->getProperties(); if ($data['preview']) { $data['tab'] = 'preview'; } $data['items'] = $itemsdata; // Get the settings of the publication type we are using $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid'])); return xarTplModule('publications', 'user', 'modify', $data); } // call transform input hooks $article['transform'] = array('summary', 'body', 'notes'); $article = xarModCallHooks('item', 'transform-input', $itemid, $article, 'publications', $data['ptid']); // Now talk to the database /*foreach ($itemsdata as $itemid => $itemdata) { $data['object']->setFieldValues($itemdata); if (empty($itemid)) $item = $data['object']->createItem(); else $item = $data['object']->updateItem(); // Clear the itemid property in preparation for the next round unset($data['object']->itemid); }*/ if (empty($itemid)) { $item = $data['object']->createItem(); } else { $item = $data['object']->updateItem(); } // Success xarSession::setVar('statusmsg', xarML('Publication Updated')); // if we can edit publications, go to admin view, otherwise go to user view if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) { if ($data['quit']) { xarController::redirect(xarModURL('publications', 'user', 'view', array('ptid' => $data['ptid']))); return true; } else { xarController::redirect(xarModURL('publications', 'user', 'modify', array('name' => $pubtypeobject->properties['name']->value, 'itemid' => $itemid))); return true; } } return true; }
function publications_user_view($args) { // Get parameters if (!xarVarFetch('ptid', 'id', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('startnum', 'int:0', $startnum, NULL, XARVAR_NOT_REQUIRED)) { return; } 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; } if (!xarVarFetch('itemtype', 'id', $itemtype, NULL, XARVAR_NOT_REQUIRED)) { return; } // TODO: put the query string through a proper parser, so searches on multiple words can be done. if (!xarVarFetch('q', 'pre:trim:passthru:str:1:200', $q, NULL, XARVAR_NOT_REQUIRED)) { return; } // can't use list enum here, because we don't know which sorts might be used // True - but we can provide some form of validation and normalisation. // The original 'regexp:/^[\w,]*$/' lets through *any* non-space character. // This validation will accept a list of comma-separated words, and will lower-case, trim // and strip out non-alphanumeric characters from each word. if (!xarVarFetch('sort', 'strlist:,:pre:trim:lower:alnum', $sort, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('numcols', 'int:0', $numcols, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('owner', 'id', $owner, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('pubdate', 'str:1', $pubdate, NULL, XARVAR_NOT_REQUIRED)) { return; } // This may not be set via user input, only e.g. via template tags, API calls, blocks etc. // if(!xarVarFetch('startdate','int:0', $startdate, NULL, XARVAR_NOT_REQUIRED)) {return;} // if(!xarVarFetch('enddate', 'int:0', $enddate, NULL, XARVAR_NOT_REQUIRED)) {return;} // if(!xarVarFetch('where', 'str', $where, NULL, XARVAR_NOT_REQUIRED)) {return;} // Added to impliment an Alpha Pager if (!xarVarFetch('letter', 'pre:lower:passthru:str:1:20', $letter, NULL, XARVAR_NOT_REQUIRED)) { return; } // Override if needed from argument array (e.g. ptid, numitems etc.) extract($args); $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); // We need a valid pubtype number here if (!is_numeric($ptid) || !isset($pubtypes[$ptid])) { return xarResponse::NotFound(); } // Constants used throughout. // // publications module ID $c_modid = xarMod::getID('publications'); // state: front page or approved $c_posted = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED); // Default parameters if (!isset($startnum)) { $startnum = 1; } // Check if we want the default 'front page' if (!isset($catid) && !isset($cids) && empty($ptid) && !isset($owner)) { $ishome = true; // default publication type $ptid = xarModVars::get('publications', 'defaultpubtype'); // frontpage state $state = array(PUBLICATIONS_STATE_FRONTPAGE); } else { $ishome = false; // frontpage or approved state $state = $c_posted; } // Get the publication type for this display $data['pubtypeobject'] = DataObjectMaster::getObject(array('name' => 'publications_types')); $data['pubtypeobject']->getItem(array('itemid' => $ptid)); // Get the settings of this publication type $data['settings'] = xarMod::apiFunc('publications', 'user', 'getsettings', array('ptid' => $ptid)); // Get the template for this publication type if ($ishome) { $data['template'] = 'frontpage'; } else { $data['template'] = $data['pubtypeobject']->properties['template']->getValue(); } $isdefault = 0; // check default view for this type of publications if (empty($catid) && empty($cids) && empty($owner) && empty($sort)) { if (substr($data['settings']['defaultview'], 0, 1) == 'c') { $catid = substr($data['settings']['defaultview'], 1); } } // Do not transform titles if we are not transforming output at all. if (empty($data['settings']['do_transform'])) { $data['settings']['dotitletransform'] = 0; } // Page template for frontpage or depending on publication type (optional) // Note : this cannot be overridden in templates if (!empty($data['settings']['page_template'])) { xarTplSetPageTemplateName($data['settings']['page_template']); } if (empty($data['settings']['defaultsort'])) { $defaultsort = 'date'; } else { $defaultsort = $data['settings']['defaultsort']; } if (empty($sort)) { $sort = $defaultsort; } // TODO: show this *after* category list when we start from categories :) // Navigation links $data['publabel'] = xarML('Publication'); $data['publinks'] = xarModAPIFunc('publications', 'user', 'getpublinks', array('ptid' => $ishome ? '' : $ptid, 'state' => $c_posted, 'count' => $data['settings']['show_pubcount'])); $data['pager'] = ''; // Add Sort to data passed to template so that we can automatically turn on alpha pager, if needed $data['sort'] = $sort; // Add current display letter, so that we can highlight the current filter in the alpha pager $data['letter'] = $letter; // Get the users requested number of stories per page. // If user doesn't care, use the site default if (xarUserIsLoggedIn()) { // TODO: figure how to let users specify their settings // COMMENT: if the settings were split into separate module variables, // then they could all be individually over-ridden by each user. //$numitems = xarModUserGetVar('items_per_page'); } if (empty($numitems)) { if (!empty($settings['items_per_page'])) { $numitems = $settings['items_per_page']; } else { $numitems = 20; } } // 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; } elseif (strpos($catid, '-')) { $cids = explode('-', $catid); $andcids = false; } else { $cids = array($catid); if (strstr($catid, '_')) { $andcids = false; // don't combine with current category } else { $andcids = true; } } } else { if (empty($cids)) { $cids = array(); } if (!isset($andcids)) { $andcids = true; } } // rebuild $catid in standard format again $catid = null; if (count($cids) > 0) { $seencid = array(); foreach ($cids as $cid) { // make sure cids are numeric if (!empty($cid) && preg_match('/^_?[0-9]+$/', $cid)) { $seencid[$cid] = 1; } } $cids = array_keys($seencid); sort($cids, SORT_NUMERIC); if ($andcids) { $catid = join('+', $cids); } else { $catid = join('-', $cids); } } // every field you always wanted to know about but were afraid to ask for :) $extra = array(); // $extra[] = 'author'; // Note: we always include cids for security checks now (= performance impact if show_categories was 0) $extra[] = 'cids'; if ($data['settings']['show_hitcount']) { $extra[] = 'counter'; } if ($data['settings']['show_ratings']) { $extra[] = 'rating'; } $now = time(); if (empty($startdate) || !is_numeric($startdate) || $startdate > $now) { $startdate = null; } if (empty($enddate) || !is_numeric($enddate) || $enddate > $now) { $enddate = $now; } if (empty($pubdate) || !preg_match('/^\\d{4}(-\\d+(-\\d+|)|)$/', $pubdate)) { $pubdate = null; } if (empty($where)) { $where = null; } // Modify the where clause if an Alpha filter has been specified. if (!empty($letter)) { // We will allow up to three initial letters, anything more than that is assumed to be 'Other'. // Need to also be very wary of SQL injection, since we are not using bind variables here. // TODO: take into account international characters. if (preg_match('/^[a-z]{1,3}$/i', $letter)) { $extrawhere = "title LIKE '{$letter}%'"; } else { // Loop through the alphabet for the 'not in' part. $letterwhere = array(); for ($i = ord('a'); $i <= ord('z'); $i++) { $letterwhere[] = "title NOT LIKE '" . chr($i) . "%'"; } $extrawhere = implode(' and ', $letterwhere); } if ($where == null) { $where = $extrawhere; } else { $where .= $extrawhere; } } // Get publications $publications = xarModAPIFunc('publications', 'user', 'getall', array('startnum' => $startnum, 'cids' => $cids, 'andcids' => $andcids, 'ptid' => isset($ptid) ? $ptid : null, 'owner' => $owner, 'state' => $state, 'sort' => $sort, 'extra' => $extra, 'where' => $where, 'search' => $q, 'numitems' => $numitems, 'pubdate' => $pubdate, 'startdate' => $startdate, 'enddate' => $enddate)); if (!is_array($publications)) { throw new Exception('Failed to retrieve publications'); } // TODO : support different 'index' templates for different types of publications // (e.g. News, Sections, ...), depending on what "view" the user // selected (per category, per publication type, a combination, ...) ? if (!empty($owner)) { $data['author'] = xarUserGetVar('name', $owner); if (empty($data['author'])) { xarErrorHandled(); $data['author'] = xarML('Unknown'); } } if (!empty($pubdate)) { $data['pubdate'] = $pubdate; } // Save some variables to (temporary) cache for use in blocks etc. xarVarSetCached('Blocks.publications', 'ptid', $ptid); xarVarSetCached('Blocks.publications', 'cids', $cids); xarVarSetCached('Blocks.publications', 'owner', $owner); if (isset($data['author'])) { xarVarSetCached('Blocks.publications', 'author', $data['author']); } if (isset($data['pubdate'])) { xarVarSetCached('Blocks.publications', 'pubdate', $data['pubdate']); } // TODO: add this to publications configuration ? if ($ishome) { $data['ptid'] = null; if (xarSecurityCheck('SubmitPublications', 0)) { $data['submitlink'] = xarModURL('publications', 'admin', 'new'); } } else { $data['ptid'] = $ptid; if (!empty($ptid)) { $curptid = $ptid; } else { $curptid = 'All'; } if (count($cids) > 0) { foreach ($cids as $cid) { if (xarSecurityCheck('SubmitPublications', 0, 'Publication', "{$curptid}:{$cid}:All:All")) { $data['submitlink'] = xarModURL('publications', 'admin', 'new', array('ptid' => $ptid, 'catid' => $catid)); break; } } } elseif (xarSecurityCheck('SubmitPublications', 0, 'Publication', "{$curptid}:All:All:All")) { $data['submitlink'] = xarModURL('publications', 'admin', 'new', array('ptid' => $ptid)); } } $data['cids'] = $cids; $data['catid'] = $catid; xarVarSetCached('Blocks.categories', 'module', 'publications'); xarVarSetCached('Blocks.categories', 'itemtype', $ptid); xarVarSetCached('Blocks.categories', 'cids', $cids); if (!empty($ptid) && !empty($pubtypes[$ptid]['description'])) { xarVarSetCached('Blocks.categories', 'title', $pubtypes[$ptid]['description']); // Note : this gets overriden by the categories navigation if necessary xarTplSetPageTitle(xarVarPrepForDisplay($pubtypes[$ptid]['description'])); } // optional category count if ($data['settings']['show_catcount']) { if (!empty($ptid)) { $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => $c_posted, 'ptid' => $ptid)); if (isset($pubcatcount[$ptid])) { xarVarSetCached('Blocks.categories', 'catcount', $pubcatcount[$ptid]); } unset($pubcatcount); } else { $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => $c_posted, 'reverse' => 1)); if (isset($pubcatcount) && count($pubcatcount) > 0) { $catcount = array(); foreach ($pubcatcount as $cat => $count) { $catcount[$cat] = $count['total']; } xarVarSetCached('Blocks.categories', 'catcount', $catcount); } unset($pubcatcount); } } else { // xarVarSetCached('Blocks.categories','catcount',array()); } // retrieve the number of comments for each article if (xarModIsAvailable('coments')) { if ($data['settings']['show_comments']) { $idlist = array(); foreach ($publications as $article) { $idlist[] = $article['id']; } $numcomments = xarModAPIFunc('comments', 'user', 'get_countlist', array('modid' => $c_modid, 'objectids' => $idlist)); } } // retrieve the keywords for each article if (xarModIsAvailable('coments')) { if ($data['settings']['show_keywords']) { $idlist = array(); foreach ($publications as $article) { $idlist[] = $article['id']; } $keywords = xarModAPIFunc('keywords', 'user', 'getmultiplewords', array('modid' => $c_modid, 'objectids' => $idlist, 'itemtype' => $ptid)); } } /* ------------------------------------------------------------ // 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 // get base categories for all if needed $catroots = xarModAPIFunc('publications', 'user', 'getrootcats', array('ptid' => $ptid, 'all' => true) ); } foreach ($catinfo as $cid => $info) { $catinfo[$cid]['name'] = xarVarPrepForDisplay($info['name']); $catinfo[$cid]['link'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, '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['catleft'] && $info['left'] < $rootcat['catright']) { // only needed when sorting by root category id $catinfo[$cid]['root'] = $rootcat['catid']; // only needed when sorting by root category order $catinfo[$cid]['order'] = $rootidx; break; } $rootidx++; } } // needed for sort function below $GLOBALS['artviewcatinfo'] = $catinfo; } $number = 0; foreach ($publications as $article) { // TODO: don't include ptid and catid if we don't use short URLs // link to article $article['link'] = xarModURL('publications', 'user', 'display', // don't include pubtype id if we're navigating by category array( 'ptid' => empty($ptid) ? null : $article['pubtype_id'], 'catid' => $catid, 'id' => $article['id'] ) ); // N words/bytes more in article if (!empty($article['body'])) { // note : this is only an approximate number $wordcount = count(preg_split("/\s+/", strip_tags($article['body']), -1, PREG_SPLIT_NO_EMPTY)); $article['words'] = $wordcount; // byte-count is less CPU-intensive -> make configurable ? $article['bytes'] = strlen($article['body']); } else { $article['words'] = 0; $article['bytes'] = 0; } // current publication type $curptid = $article['pubtype_id']; // TODO: make configurable? $article['redirect'] = xarModURL('publications', 'user', 'redirect', array('ptid' => $curptid, 'id' => $article['id']) ); // multi-column display (default from left to right, then from top to bottom) $article['number'] = $number; if (!empty($settings['number_of_columns'])) { $col = $number % $settings['number_of_columns']; } else { $col = 0; } // RSS Processing $current_theme = xarVarGetCached('Themes.name', 'CurrentTheme'); if (($current_theme == 'rss') or ($current_theme == 'atom')){ $article['rsstitle'] = htmlspecialchars($article['title']); //$article['rssdate'] = strtotime($article['date']); $article['rsssummary'] = preg_replace('<br />', "\n", $article['summary']); $article['rsssummary'] = xarVarPrepForDisplay(strip_tags($article['rsssummary'])); $article['rsscomment'] = xarModURL('comments', 'user', 'display', array('modid' => $c_modid, 'objectid' => $article['id'])); // $article['rsscname'] = htmlspecialchars($item['cname']); // <category>#$rsscname#</category> } // TODO: clean up depending on field format if ($do_transform) { $article['itemtype'] = $article['pubtype_id']; // TODO: what about transforming DD fields? if ($title_transform) { $article['transform'] = array('title', 'summary', 'body', 'notes'); } else { $article['transform'] = array('summary', 'body', 'notes'); } $article = xarModCallHooks('item', 'transform', $article['id'], $article, 'publications'); } $data['titles'][$article['id']] = $article['title']; // fill in the summary template for this article $summary_template = $pubtypes[$article['pubtype_id']]['name']; $number++;echo $number; } ------------------------------------------------------------ */ unset($publications); // TODO: verify for other URLs as well if ($ishome) { if (!empty($numcols) && $numcols > 1) { // if we're currently showing more than 1 column $data['showcols'] = 1; } else { $defaultcols = $data['settings']['number_of_columns']; if ($defaultcols > 1) { // if the default number of columns is more than 1 $data['showcols'] = $defaultcols; } } } // Specific layout within a template (optional) if (isset($layout)) { $data['layout'] = $layout; } // Get the publications we want to view $data['object'] = DataObjectMaster::getObject(array('name' => $data['pubtypeobject']->properties['name']->value)); $data['objectname'] = $data['pubtypeobject']->properties['name']->value; $data['ptid'] = $ptid; // $object = DataObjectMaster::getObjectList(array('name' => $data['pubtypeobject']->properties['name']->value)); // $data['items'] = $object->getItems(); $data['object'] = DataObjectMaster::getObjectList(array('name' => $data['pubtypeobject']->properties['name']->value)); // Get the items here // $items = $data['object']->getItems(); /* We're doing this in the template now // Only show top level documents, not translations sys::import('xaraya.structures.query'); $q = new Query(); $q->eq('parent_id',0); $q->eq('pubtype_id',$ptid); $q->eq('state',3); // Suppress deleted items // Remove this once listing property works with dataobject access $q->ne('state',0); $data['conditions'] = $q; */ // Set the page template if needed if (!empty($data['settings']['page_template'])) { $pagename = $data['settings']['page_template']; $position = strpos($pagename, '.'); if ($position === false) { $pagetemplate = $pagename; } else { $pagetemplate = substr($pagename, 0, $position); } xarTpl::setPageTemplateName($pagetemplate); } // Throw all the relevant settings we are using into the cache // $data['settings']['pubtypeobject'] = $data['pubtypeobject']->properties['configuration']->getValue(); // xarCore::setCached('publications', 'context' . $ptid, $data['settings']); return xarTplModule('publications', 'user', 'view', $data, $data['template']); }
/** * show monthly archive (Archives-like) */ function publications_user_archive($args) { // Get parameters from user if (!xarVarFetch('ptid', 'id', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('sort', 'enum:d:t:1:2', $sort, 'd', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('month', 'str', $month, '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('catid', 'str', $catid, '', XARVAR_NOT_REQUIRED)) { return; } // Override if needed from argument array extract($args); // Get publication types $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); // Check that the publication type is valid if (empty($ptid) || !isset($pubtypes[$ptid])) { $ptid = null; } if (empty($ptid)) { if (!xarSecurityCheck('ViewPublications', 0, 'Publication', 'All:All:All:All')) { return xarML('You have no permission to view these items'); } } elseif (!xarSecurityCheck('ViewPublications', 0, 'Publication', $ptid . ':All:All:All')) { return xarML('You have no permission to view these items'); } $state = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED); $seencid = array(); $andcids = false; // 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; } elseif (strpos($catid, '-')) { $cids = explode('-', $catid); $andcids = false; } else { $cids = array($catid); if (strstr($catid, '_')) { $andcids = false; // don't combine with current category } else { $andcids = true; } } } if (isset($cids) && is_array($cids)) { foreach ($cids as $cid) { if (!empty($cid) && preg_match('/^_?[0-9]+$/', $cid)) { $seencid[$cid] = 1; } } $cids = array_keys($seencid); sort($cids, SORT_NUMERIC); if (empty($catid) && count($cids) > 1) { $andcids = true; } } else { $cids = null; } // QUESTION: work with user-dependent time settings or not someday ? // Set the start and end date for that month if (!empty($month) && preg_match('/^(\\d{4})-(\\d+)$/', $month, $matches)) { $startdate = gmmktime(0, 0, 0, $matches[2], 1, $matches[1]); // PHP allows month > 12 :-) $enddate = gmmktime(0, 0, 0, $matches[2] + 1, 1, $matches[1]); if ($enddate > time()) { $enddate = time(); } } else { $startdate = ''; $enddate = time(); if (!empty($month) && $month != 'all') { $month = ''; } } // Load API if (!xarModAPILoad('publications', 'user')) { return; } if (!empty($ptid) && !empty($pubtypes[$ptid]['config']['pubdate']['label'])) { $showdate = 1; } else { $showdate = 0; foreach (array_keys($pubtypes) as $pubid) { if (!empty($pubtypes[$pubid]['config']['pubdate']['label'])) { $showdate = 1; break; } } } // Get monthly statistics $monthcount = xarModAPIFunc('publications', 'user', 'getmonthcount', array('ptid' => $ptid, 'state' => $state, 'enddate' => time())); if (empty($monthcount)) { $monthcount = array(); } krsort($monthcount); reset($monthcount); $months = array(); $total = 0; foreach ($monthcount as $thismonth => $count) { if ($thismonth == $month) { $mlink = ''; } else { $mlink = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $thismonth)); } $months[] = array('month' => $thismonth, 'mcount' => $count, 'mlink' => $mlink); $total += $count; } if (empty($ptid)) { $thismonth = xarML('All Publications'); } else { $thismonth = xarML('All') . ' ' . $pubtypes[$ptid]['description']; } if ($month == 'all') { $mlink = ''; } else { $mlink = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => 'all')); } $months[] = array('month' => $thismonth, 'mcount' => $total, 'mlink' => $mlink); // Load API if (!xarModAPILoad('categories', 'user')) { return; } // Get the list of root categories for this publication type if (!empty($ptid)) { $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid)); } else { $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => 0)); } $catlist = array(); $catinfo = array(); $catsel = array(); if (!empty($rootcats)) { // TODO: do this in categories API ? $count = 1; foreach ($rootcats as $cid) { if (empty($cid)) { continue; } // save the name and root category for each child $cats = xarModAPIFunc('categories', 'user', 'getcat', array('cid' => $cid['category_id'], 'return_itself' => true, 'getchildren' => true)); foreach ($cats as $info) { $item = array(); $item['name'] = $info['name']; $item['root'] = $cid['category_id']; $catinfo[$info['cid']] = $item; } // don't allow sorting by category when viewing all publications //if ($sort == $count || $month == 'all') { if ($sort == $count) { $link = ''; } else { $link = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $month, 'sort' => $count)); } // catch more faulty categories assignments if (isset($catinfo[$cid['category_id']])) { $catlist[] = array('cid' => $cid['category_id'], 'name' => $catinfo[$cid['category_id']]['name'], 'link' => $link); $catsel[] = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $cid['category_id'], 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 0)); $count++; } } } // Get publications if ($month == 'all' || $startdate && $enddate) { $publications = xarModAPIFunc('publications', 'user', 'getall', array('ptid' => isset($ptid) ? $ptid : null, 'startdate' => $startdate, 'enddate' => $enddate, 'state' => $state, 'cids' => $cids, 'andcids' => $andcids, 'fields' => array('id', 'title', 'start_date', 'pubtype_id', 'cids'))); if (!is_array($publications)) { $msg = xarML('Failed to retrieve publications in #(3)_#(1)_#(2).php', 'user', 'getall', 'publications'); throw new DataNotFoundException(null, $msg); } } else { $publications = array(); } // TODO: add print / recommend_us link for each article ? // TODO: add view count to table/query/template someday ? foreach ($publications as $key => $article) { $publications[$key]['link'] = xarModURL('publications', 'user', 'display', array('ptid' => isset($ptid) ? $publications[$key]['pubtype_id'] : null, 'id' => $publications[$key]['id'])); if (empty($publications[$key]['title'])) { $publications[$key]['title'] = xarML('(none)'); } /* TODO: move date formatting to template, delete this code after testing if ($showdate && !empty($publications[$key]['pubdate'])) { $publications[$key]['date'] = xarLocaleFormatDate("%Y-%m-%d %H:%M:%S", $publications[$key]['pubdate']); } else { $publications[$key]['date'] = ''; } */ // TODO: find some better way to do this... $list = array(); // get all the categories for that article and put them under the // right root category if (!isset($publications[$key]['cids'])) { $publications[$key]['cids'] = array(); } foreach ($publications[$key]['cids'] as $cid) { // skip unknown categories (e.g. when not under root categories) if (!isset($catinfo[$cid])) { continue; } if (!isset($list[$catinfo[$cid]['root']])) { $list[$catinfo[$cid]['root']] = array(); } array_push($list[$catinfo[$cid]['root']], $cid); } // fill in the column corresponding to each root category $publications[$key]['cats'] = array(); foreach ($catlist as $cat) { if (isset($list[$cat['cid']])) { $descr = ''; // TODO: add links to category someday ? foreach ($list[$cat['cid']] as $cid) { if (!empty($descr)) { $descr .= '<br />'; } $descr .= $catinfo[$cid]['name']; } $publications[$key]['cats'][] = array('list' => $descr); } else { $publications[$key]['cats'][] = array('list' => '-'); } } } // sort publications as requested if ($sort == 2 && count($catlist) > 1) { usort($publications, 'publications_archive_sortbycat10'); } elseif ($sort == 1) { if (count($catlist) > 1) { usort($publications, 'publications_archive_sortbycat01'); } elseif (count($catlist) > 0) { usort($publications, 'publications_archive_sortbycat0'); } } elseif ($sort == 't') { usort($publications, 'publications_archive_sortbytitle'); } else { $sort = 'd'; // default sort by date is already done in getall() function } // add title header if ($sort == 't') { $link = ''; } else { $link = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $month, 'sort' => 't')); } $catlist[] = array('cid' => 0, 'name' => xarML('Title'), 'link' => $link); $catsel[] = '<input type="submit" value="' . xarML('Filter') . '" />'; if ($showdate) { // add date header if ($sort == 'd') { $link = ''; } else { $link = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $month)); } $catlist[] = array('cid' => 0, 'name' => xarML('Date'), 'link' => $link); $catsel[] = ' '; } // Save some variables to (temporary) cache for use in blocks etc. xarVarSetCached('Blocks.publications', 'ptid', $ptid); if (!empty($cids)) { xarVarSetCached('Blocks.publications', 'cids', $cids); } //if ($shownavigation) { xarVarSetCached('Blocks.categories', 'module', 'publications'); xarVarSetCached('Blocks.categories', 'itemtype', $ptid); if (!empty($ptid) && !empty($pubtypes[$ptid]['description'])) { xarVarSetCached('Blocks.categories', 'title', $pubtypes[$ptid]['description']); xarTplSetPageTitle(xarML('Archive'), $pubtypes[$ptid]['description']); } else { xarTplSetPageTitle(xarML('Archive')); } //} if (!empty($ptid)) { $settings = unserialize(xarModVars::get('publications', 'settings.' . $ptid)); } else { $string = xarModVars::get('publications', 'settings'); if (!empty($string)) { $settings = unserialize($string); } } if (!isset($show_publinks)) { if (!empty($settings['show_publinks'])) { $show_publinks = 1; } else { $show_publinks = 0; } } // show the number of publications for each publication type if (!isset($show_pubcount)) { if (!isset($settings['show_pubcount']) || !empty($settings['show_pubcount'])) { $show_pubcount = 1; // default yes } else { $show_pubcount = 0; } } // $show_catcount = 0; // unused here // return template out $data = array('months' => $months, 'publications' => $publications, 'catlist' => $catlist, 'catsel' => $catsel, 'ptid' => $ptid, 'month' => $month, 'curlink' => xarModURL('publications', 'user', 'archive', array('ptid' => $ptid, 'month' => $month, 'sort' => $sort)), 'showdate' => $showdate, 'show_publinks' => $show_publinks, 'publabel' => xarML('Publication'), 'publinks' => xarModAPIFunc('publications', 'user', 'getpublinks', array('ptid' => $ptid, 'state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'count' => $show_pubcount, 'func' => 'archive')), 'maplabel' => xarML('View Publication Map'), 'maplink' => xarModURL('publications', 'user', 'viewmap', array('ptid' => $ptid)), 'viewlabel' => empty($ptid) ? xarML('Back to Publications') : xarML('Back to') . ' ' . $pubtypes[$ptid]['description'], 'viewlink' => xarModURL('publications', 'user', 'view', array('ptid' => $ptid))); if (!empty($ptid)) { $template = $pubtypes[$ptid]['name']; } else { // TODO: allow templates per category ? $template = null; } return xarTplModule('publications', 'user', 'archive', $data, $template); }
/** * Docs */ function shop_admin_docs() { return xarTplModule('shop', 'admin', 'docs'); }