/** * View the cart */ function shop_user_viewcart() { // If the user returns to the cart after taking other steps, unset any errors from earlier in the session. xarSession::delVar('errors'); sys::import('modules.dynamicdata.class.objects.master'); $subtotals = array(); $products = array(); $total = 0; // May want to display cust info with the cart... $cust = xarMod::APIFunc('shop', 'user', 'customerinfo'); $data['cust'] = $cust; $shop = xarSession::getVar('shop'); foreach ($shop as $pid => $val) { // If this post variable is set, we must need to update the quantity if (isset($_POST['qty' . $pid])) { unset($qty_new); // Have to unset this since we're in a foreach if (!xarVarFetch('qty' . $pid, 'isset', $qty_new, NULL, XARVAR_DONT_SET)) { return; } if ($qty_new == 0) { unset($shop[$pid]); } else { $shop[$pid]['qty'] = $qty_new; } } // If the quantity hasn't been set to zero, add it to the $products array... if (isset($shop[$pid])) { // Commas in the quantity seem to mess up our math $products[$pid]['qty'] = str_replace(',', '', $shop[$pid]['qty']); // Get the product info $object = DataObjectMaster::getObject(array('name' => 'shop_products')); $some_id = $object->getItem(array('itemid' => $pid)); $values = $object->getFieldValues(); $products[$pid]['title'] = xarVarPrepForDisplay($values['title']); $products[$pid]['price'] = $values['price']; $subtotal = $values['price'] * $products[$pid]['qty']; $subtotals[] = $subtotal; // so we can use array_sum() to add it all up if (substr($subtotal, 0, 1) == '.') { $subtotal = '0' . $subtotal; } $products[$pid]['subtotal'] = number_format($subtotal, 2); } } xarSession::setVar('shop', $shop); $total = array_sum($subtotals); // Add a zero to the front of the number if it starts with a decimal... if (substr($total, 0, 1) == '.') { $total = '0' . $total; } $total = number_format($total, 2); xarSession::setVar('products', $products); // update the session variable $data['products'] = $products; // don't want too much session stuff in the templates xarSession::setVar('total', $total); $data['total'] = $total; return $data; }
function calendar_admin_add_event() { // Security check if (!xarSecurityCheck('Admincalendar')) { return; } // Generate a one-time authorisation code for this operation $data = xarMod::apiFunc('calendar', 'admin', 'get_calendars'); $data['authid'] = xarSecGenAuthKey(); $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal')); // Variables from phpIcalendar config.inc.php $data['updatebutton'] = xarVarPrepForDisplay(xarML('Create event')); //TODO: should I include this stuff? --amoro /* $hooks = xarModCallHooks('module', 'modifyconfig', 'calendar', array('module' => 'calendar')); if (empty($hooks)) { $data['hooks'] = ''; } elseif (is_array($hooks)) { $data['hooks'] = join('', $hooks); } else { $data['hooks'] = $hooks; } */ // Return the template variables defined in this function return $data; }
/** * Modify 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; }
function calendar_admin_add_calendars() { // Security check // if (!xarSecurityCheck('AddCalendar',0,'Calendar')) return; if (!xarVarFetch('calid', 'int:0:', $calid, '0', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('calname', 'str', $calname, '', XARVAR_NOT_REQUIRED)) { return; } $data = xarMod::apiFunc('calendar', 'admin', 'get_calendars'); // Generate a one-time authorisation code for this operation $data['authid'] = xarSecGenAuthKey(); $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal')); $data['addbutton'] = xarVarPrepForDisplay(xarML('Add calendar')); $data['message'] = xarVarPrepForDisplay(xarML('Created calendar with name "#(1)", ID #(2)', $calname, $calid)); $data['calid'] = $calid; return $data; }
/** * 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); }
/** * Get the items currently in the cart */ function shop_userapi_getcartproducts($args) { sys::import('modules.dynamicdata.class.objects.master'); $total = 0; $shop = xarSession::getVar('shop'); if (empty($shop)) { return; } foreach ($shop as $pid => $val) { // if this post variable is set, we must need to update the quantity if (isset($_POST['qty' . $pid])) { unset($qty_new); if (!xarVarFetch('qty' . $pid, 'isset', $qty_new, NULL, XARVAR_DONT_SET)) { return; } $shop[$pid]['qty'] = $qty_new; } $products[$pid]['qty'] = $shop[$pid]['qty']; $object = DataObjectMaster::getObject(array('name' => 'shop_products')); $some_id = $object->getItem(array('itemid' => $pid)); $values = $object->getFieldValues(); $products[$pid]['title'] = xarVarPrepForDisplay($values['title']); $price = $values['price']; if (substr($price, 0, 1) == '.') { $price = '0' . $price; } $products[$pid]['price'] = $price; $subtotal = $values['price'] * $products[$pid]['qty']; $subtotals[] = $subtotal; $products[$pid]['subtotal'] = number_format($subtotal, 2); } xarSession::setVar('shop', $shop); $total = array_sum($subtotals); $total = number_format($total, 2); if (substr($total, 0, 1) == '.') { $total = '0' . $total; } $productinfo['products'] = $products; $productinfo['total'] = $total; return $productinfo; }
public function display() { $vars = $this->getContent(); if (!xarVarFetch($vars['paramname'], 'str', $glossaryterm, null, XARVAR_NOT_REQUIRED)) { return; } if (!$glossaryterm) { return; } $articlecriteria = array(); $articlecriteria['title'] = $glossaryterm; if (!empty($vars['ptid'])) { $articlecriteria['ptid'] = $vars['ptid']; } if (!empty($vars['cid'])) { $articlecriteria['withcids'] = true; } // Attempt to find an article with this title and optional category/pubtype. $article = xarModAPIfunc('publications', 'user', 'get', $articlecriteria); if (!empty($vars['cid']) && array_search($vars['cid'], $article['cids']) === NULL) { // Category not assigned to article. unset($article); } // Matching glossary item found. if (!empty($article)) { $vars['definition'] = $article['summary']; $vars['term'] = $glossaryterm; $vars['detailurl'] = xarModURL('publications', 'user', 'display', array('id' => $article['id'], 'ptid' => $article['pubtype_id'])); $vars['detailavailable'] = !empty($article['body']); } // Replace the string '{term}' in the block title with the term. // Note: the prep display prevents injected tags being rendered. // The title of a block does not go through any further tag stripping // because it is normally under admin control (the admin may wish to // add working tags to the title). $this->setTitle(str_replace('{term}', xarVarPrepForDisplay($glossaryterm), $this->title)); return $vars; }
/** * Display a transaction */ function shop_admin_transaction($args) { if (!xarVarFetch('itemid', 'id', $itemid, NULL, XARVAR_DONT_SET)) { return; } extract($args); 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_transactions')); $data['properties'] = $object->getProperties(); $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(); //We need to do this up here to avoid messing up the serialized array with xarVarPrepForDisplay $products = unserialize($values['products']); //$values is an associative array of property names and values, so... foreach ($values as $name => $value) { $data[$name] = xarVarPrepForDisplay($value); } $data['products'] = $products; 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); }
/** * get an array of child categories with links and optional counts * * @param $args['state'] array of requested status(es) for the publications * @param $args['ptid'] publication type ID * @param $args['cid'] parent category ID * @param $args['showcid'] false (default) means skipping the parent cid * @param $args['count'] true (default) means counting the number of publications * @param $args['filter'] additional categories we're filtering on (= catid) * @return array */ function publications_userapi_getchildcats($args) { extract($args); if (!isset($cid) || !is_numeric($cid)) { return array(); } if (empty($ptid)) { $ptid = null; } if (!isset($state)) { // frontpage or approved $state = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED); } if (!isset($showcid)) { $showcid = false; } if (!isset($count)) { $count = true; } if (!isset($filter)) { $filter = ''; } if (!xarModAPILoad('categories', 'visual')) { return; } // TODO: make sure permissions are taken into account here ! $list = xarModAPIFunc('categories', 'visual', 'listarray', array('cid' => $cid)); // get the counts for all child categories if ($count) { if (empty($filter)) { $seencid = array(); foreach ($list as $info) { $seencid[$info['id']] = 1; } $childlist = array_keys($seencid); $andcids = false; } else { // we'll combine the parent cid with the filter here $childlist = array('_' . $cid, $filter); $andcids = true; } $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'cids' => $childlist, 'andcids' => $andcids, 'ptid' => $ptid, 'reverse' => 1)); if (!empty($ptid)) { $curptid = $ptid; } else { $curptid = 'total'; } } $cats = array(); foreach ($list as $info) { if ($info['id'] == $cid && !$showcid) { continue; } if (!empty($filter)) { $catid = $filter . '+' . $info['id']; } else { $catid = $info['id']; } // TODO: show icons instead of (or in addition to) a link if available ? $info['link'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $catid)); $info['name'] = xarVarPrepForDisplay($info['name']); if ($count) { if (isset($pubcatcount[$info['id']][$curptid])) { $info['count'] = $pubcatcount[$info['id']][$curptid]; } elseif (!empty($filter) && isset($pubcatcount[$filter . '+' . $info['id']][$curptid])) { $info['count'] = $pubcatcount[$filter . '+' . $info['id']][$curptid]; } elseif (!empty($filter) && isset($pubcatcount[$info['id'] . '+' . $filter][$curptid])) { $info['count'] = $pubcatcount[$info['id'] . '+' . $filter][$curptid]; } else { $info['count'] = ''; } } else { $info['count'] = ''; } $cats[] = $info; } return $cats; }
public function display(array $data = array()) { $data = $this->getContent(); // see if we're currently displaying an article if (xarVarIsCached('Blocks.publications', 'id')) { $curid = xarVarGetCached('Blocks.publications', 'id'); } else { $curid = -1; } if (!empty($data['dynamictitle'])) { if ($data['toptype'] == 'rating') { $data['title'] = xarML('Top Rated'); } elseif ($data['toptype'] == 'hits') { $data['title'] = xarML('Top'); } else { $data['title'] = xarML('Latest'); } } if (!empty($data['nocatlimit'])) { // don't limit by category $cid = 0; $cidsarray = array(); } else { if (!empty($data['catfilter'])) { // use admin defined category $cidsarray = array($data['catfilter']); $cid = $data['catfilter']; } else { // use the current category // Jonn: this currently only works with one category at a time // it could be reworked to support multiple cids if (xarVarIsCached('Blocks.publications', 'cids')) { $curcids = xarVarGetCached('Blocks.publications', 'cids'); if (!empty($curcids)) { if ($curid == -1) { //$cid = $curcids[0]['name']; $cid = $curcids[0]; $cidsarray = array($curcids[0]); } else { $cid = $curcids[0]; $cidsarray = array($curcids[0]); } } else { $cid = 0; $cidsarray = array(); } } else { // pull from all categories $cid = 0; $cidsarray = array(); } } //echo $includechildren; if (!empty($data['includechildren']) && !empty($cidsarray[0]) && !strstr($cidsarray[0], '_')) { $cidsarray[0] = '_' . $cidsarray[0]; } if (!empty($cid)) { // if we're viewing all items below a certain category, i.e. catid = _NN $cid = str_replace('_', '', $cid); $thiscategory = xarModAPIFunc('categories', 'user', 'getcat', array('cid' => $cid, 'return_itself' => 'return_itself')); } if (!empty($cidsarray) && isset($thiscategory[0]['name']) && !empty($data['dynamictitle'])) { $data['title'] .= ' ' . $thiscategory[0]['name']; } } // Get publication types // MarieA - moved to always get pubtypes. $publication_types = xarModAPIFunc('publications', 'user', 'get_pubtypes'); if (!empty($data['nopublimit'])) { //don't limit by publication type $ptid = 0; if (!empty($data['dynamictitle'])) { $data['title'] .= ' ' . xarML('Content'); } } else { // MikeC: Check to see if admin has specified that only a specific // Publication Type should be displayed. If not, then default to original TopItems configuration. if ($data['pubtype_id'] == 0) { if (xarVarIsCached('Blocks.publications', 'ptid')) { $ptid = xarVarGetCached('Blocks.publications', 'ptid'); } if (empty($ptid)) { // default publication type $ptid = xarModVars::get('publications', 'defaultpubtype'); } } else { // MikeC: Admin Specified a publication type, use it. $ptid = $data['pubtype_id']; } if (!empty($data['dynamictitle'])) { if (!empty($ptid) && isset($publication_types[$ptid]['description'])) { $data['title'] .= ' ' . xarVarPrepForDisplay($publication_types[$ptid]['description']); } else { $data['title'] .= ' ' . xarML('Content'); } } } // frontpage or approved state if (empty($data['pubstate'])) { $statearray = array(2, 3); } elseif (!is_array($data['pubstate'])) { $statearray = preg_split('/,/', $data['pubstate']); } else { $statearray = $data['pubstate']; } // get cids for security check in getall $fields = array('id', 'title', 'pubtype_id', 'cids'); if ($data['toptype'] == 'rating' && xarModIsHooked('ratings', 'publications', $ptid)) { array_push($fields, 'rating'); $sort = 'rating'; } elseif ($data['toptype'] == 'hits' && xarModIsHooked('hitcount', 'publications', $ptid)) { array_push($fields, 'counter'); $sort = 'hits'; } else { array_push($fields, 'create_date'); $sort = 'date'; } if (!empty($data['showsummary'])) { array_push($fields, 'summary'); } if (!empty($data['showdynamic']) && xarModIsHooked('dynamicdata', 'publications', $ptid)) { array_push($fields, 'dynamicdata'); } $publications = xarModAPIFunc('publications', 'user', 'getall', array('ptid' => $ptid, 'cids' => $cidsarray, 'andcids' => 'false', 'state' => $statearray, 'create_date' => time(), 'fields' => $fields, 'sort' => $sort, 'numitems' => $data['numitems'])); if (!isset($publications) || !is_array($publications) || count($publications) == 0) { return; } $items = array(); foreach ($publications as $article) { $article['title'] = xarVarPrepHTMLDisplay($article['title']); if ($article['id'] != $curid) { // Use the filtered category if set, and not including children $article['link'] = xarModURL('publications', 'user', 'display', array('itemid' => $article['id'], 'catid' => !empty($data['linkcat']) && !empty($data['catfilter']) ? $data['catfilter'] : NULL)); } else { $article['link'] = ''; } if (!empty($data['showvalue'])) { if ($data['toptype'] == 'rating') { if (!empty($article['rating'])) { $article['value'] = intval($article['rating']); } else { $article['value'] = 0; } } elseif ($data['toptype'] == 'hits') { if (!empty($article['counter'])) { $article['value'] = $article['counter']; } else { $article['value'] = 0; } } else { // TODO: make user-dependent if (!empty($article['create_date'])) { //$article['value'] = strftime("%Y-%m-%d", $article['create_date']); $article['value'] = xarLocaleGetFormattedDate('short', $article['create_date']); } else { $article['value'] = 0; } } } else { $article['value'] = 0; } // MikeC: Bring the summary field back as $desc if (!empty($data['showsummary'])) { $article['summary'] = xarVarPrepHTMLDisplay($article['summary']); $article['transform'] = array('summary', 'title'); $article = xarModCallHooks('item', 'transform', $article['id'], $article, 'publications'); } else { $article['summary'] = ''; } // MarieA: Bring the pubtype description back as $descr if (!empty($data['nopublimit'])) { $article['pubtypedescr'] = $publication_types[$article['pubtype_id']]['description']; //jojodee: while we are here bring the pubtype name back as well $article['pubtypename'] = $publication_types[$article['pubtype_id']]['name']; } // this will also pass any dynamic data fields (if any) $items[] = $article; } $data['items'] = $items; if (!empty($data['dynamictitle'])) { $this->setTitle($data['title']); } return $data; }
/** * get an array of parent categories with links and counts * * @param $args['state'] array of requested status(es) for the publications * @param $args['ptid'] publication type ID * @param $args['cids'] array of category IDs * @param $args['showcids'] true (default) means keeping a link for the cids * @param $args['sort'] currently used only to override default start view * @param $args['count'] true (default) means counting the number of publications * @return array // TODO: specify return format */ function publications_userapi_getparentcats($args) { extract($args); if (!isset($cids) || !is_array($cids) || count($cids) == 0) { return array(); } if (empty($ptid)) { $ptid = null; } if (!isset($state)) { // frontpage or approved $state = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED); } if (!isset($showcids)) { $showcids = true; } if (!isset($sort)) { $sort = null; } if (!isset($count)) { $count = true; } // get the counts for all child categories if ($count) { $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => $state, 'cids' => $cids, 'ptid' => $ptid, 'reverse' => 1)); } if (!empty($ptid)) { $curptid = $ptid; } else { $curptid = 'total'; } $trails = array(); foreach ($cids as $cid) { $trailitem = array(); $trailitem['cid'] = $cid; // TODO : retrieve all parents in 1 call ? $trail = xarModAPIFunc('categories', 'user', 'getcat', array('cid' => $cid, 'return_itself' => true, 'getparents' => true)); if ($count && isset($pubcatcount[$cid][$curptid])) { $trailitem['cidcount'] = $pubcatcount[$cid][$curptid]; } else { $trailitem['cidcount'] = ''; } $trailitem['parentlinks'] = array(); $item = array(); $item['plink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'sort' => $sort)); $item['ptitle'] = xarML('All'); $item['pjoin'] = ' > '; $trailitem['parentlinks'][] = $item; // TODO: make sure permissions are taken into account here ! foreach ($trail as $info) { $item['plink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $info['cid'])); $item['ptitle'] = xarVarPrepForDisplay($info['name']); if ($info['cid'] == $cid) { // TODO: test for neighbourhood $trailitem['info'] = $info; $item['pjoin'] = ''; // remove link again in this case :-) if (!$showcids) { $item['plink'] = ''; } // TODO: improve the case where we have several icons :) if (!empty($info['image'])) { $trailitem['icon'] = array('image' => $info['image'], 'text' => $item['ptitle'], 'link' => xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $info['cid']))); } } else { $item['pjoin'] = ' > '; } $trailitem['parentlinks'][] = $item; } $trails[] = $trailitem; } return $trails; }
/** * 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_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); }
/** * get an array of root categories with links * * @param int $args['ptid'] publication type ID * @param $args['all'] boolean if we need to return all root categories when * ptid is empty (default false) * @return array * @TODO specify return format */ function publications_userapi_getrootcats($args) { extract($args); if (empty($ptid) || !is_numeric($ptid)) { $ptid = null; } // see which root categories we need to handle $rootcats = array(); if (!empty($ptid)) { $rootcats = unserialize(xarModUserVars::get('publications', 'basecids', $ptid)); } elseif (empty($all)) { $rootcats = unserialize(xarModVars::get('publications', 'basecids')); } else { // Get publication types $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); // get base categories for all publication types here $publist = array_keys($pubtypes); // add the defaults too, in case we have other base categories there $publist[] = ''; // build the list of root categories for all required publication types $catlist = array(); foreach ($publist as $pubid) { if (empty($pubid)) { $cidstring = xarModVars::get('publications', 'basecids'); } else { $cidstring = xarModUserVars::get('publications', 'basecids', $pubid); } if (!empty($cidstring)) { $rootcats = unserialize($cidstring); } else { $rootcats = array(); } foreach ($rootcats as $cid) { $catlist[$cid] = 1; } } if (count($catlist) > 0) { $rootcats = array_keys($catlist); } } if (empty($rootcats)) { $rootcats = array(); } if (count($rootcats) < 1) { return array(); } if (!xarModAPILoad('categories', 'user')) { return; } $isfirst = 1; $catlinks = array(); $catlist = xarModAPIFunc('categories', 'user', 'getcatinfo', array('cids' => $rootcats)); if (empty($catlist)) { return $catlinks; } // preserve order of root categories if possible foreach ($rootcats as $cid) { if (!isset($catlist[$cid])) { continue; } $info = $catlist[$cid]; $item = array(); $item['catid'] = $info['cid']; $item['cattitle'] = xarVarPrepForDisplay($info['name']); $item['catlink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $info['cid'])); if ($isfirst) { $item['catjoin'] = ''; $isfirst = 0; } else { $item['catjoin'] = ' | '; } $item['catleft'] = $info['left']; $item['catright'] = $info['right']; $catlinks[] = $item; } return $catlinks; }
/** * Manage definition of instances for privileges (unfinished) * * @return array for template */ function publications_admin_privileges($args) { extract($args); // fixed params if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('cid', 'isset', $cid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('uid', 'isset', $uid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('author', 'isset', $author, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('id', 'isset', $id, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('apply', 'isset', $apply, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('extpid', 'isset', $extpid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('extname', 'isset', $extname, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('extrealm', 'isset', $extrealm, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('extmodule', 'isset', $extmodule, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('extcomponent', 'isset', $extcomponent, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('extinstance', 'isset', $extinstance, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('extlevel', 'isset', $extlevel, NULL, XARVAR_DONT_SET)) { return; } sys::import('modules.dynamicdata.class.properties.master'); $categories = DataPropertyMaster::getProperty(array('name' => 'categories')); $cids = $categories->returnInput('privcategories'); if (!empty($extinstance)) { $parts = explode(':', $extinstance); if (count($parts) > 0 && !empty($parts[0])) { $ptid = $parts[0]; } if (count($parts) > 1 && !empty($parts[1])) { $cid = $parts[1]; } if (count($parts) > 2 && !empty($parts[2])) { $uid = $parts[2]; } if (count($parts) > 3 && !empty($parts[3])) { $id = $parts[3]; } } if (empty($ptid) || $ptid == 'All' || !is_numeric($ptid)) { $ptid = 0; if (!xarSecurityCheck('AdminPublications')) { return; } } else { if (!xarSecurityCheck('AdminPublications', 1, 'Publication', "{$ptid}:All:All:All")) { return; } } // TODO: do something with cid for security check // TODO: figure out how to handle more than 1 category in instances if (empty($cid) || $cid == 'All' || !is_numeric($cid)) { $cid = 0; } if (empty($cid) && isset($cids) && is_array($cids)) { foreach ($cids as $catid) { if (!empty($catid)) { $cid = $catid; // bail out for now break; } } } if (empty($id) || $id == 'All' || !is_numeric($id)) { $id = 0; } $title = ''; if (!empty($id)) { $article = xarModAPIFunc('publications', 'user', 'get', array('id' => $id, 'withcids' => true)); if (empty($article)) { $id = 0; } else { // override whatever other params we might have here $ptid = $article['pubtype_id']; // TODO: review when we can handle multiple categories and/or subtrees in privilege instances if (!empty($article['cids']) && count($article['cids']) == 1) { // if we don't have a category, or if we have one but this article doesn't belong to it if (empty($cid) || !in_array($cid, $article['cids'])) { // we'll take that category $cid = $article['cids'][0]; } } else { // we'll take no categories $cid = 0; } $uid = $article['owner']; $title = $article['title']; } } // TODO: figure out how to handle groups of users and/or the current user (later) if (strtolower($uid) == 'myself') { $uid = 'Myself'; $author = 'Myself'; } elseif (empty($uid) || $uid == 'All' || !is_numeric($uid) && strtolower($uid) != 'myself') { $uid = 0; if (!empty($author)) { $user = xarModAPIFunc('roles', 'user', 'get', array('name' => $author)); if (!empty($user) && !empty($user['uid'])) { if (strtolower($author) == 'myself') { $uid = 'Myself'; } else { $uid = $user['uid']; } } else { $author = ''; } } } else { $author = ''; /* $user = xarModAPIFunc('roles', 'user', 'get', array('uid' => $uid)); if (!empty($user) && !empty($user['name'])) { $author = $user['name']; } */ } // define the new instance $newinstance = array(); $newinstance[] = empty($ptid) ? 'All' : $ptid; $newinstance[] = empty($cid) ? 'All' : $cid; $newinstance[] = empty($uid) ? 'All' : $uid; $newinstance[] = empty($id) ? 'All' : $id; if (!empty($apply)) { // create/update the privilege $id = xarReturnPrivilege($extpid, $extname, $extrealm, $extmodule, $extcomponent, $newinstance, $extlevel); if (empty($id)) { return; } // throw back // redirect to the privilege xarController::redirect(xarModURL('privileges', 'admin', 'modifyprivilege', array('id' => $id))); return true; } // get the list of current authors $authorlist = xarModAPIFunc('publications', 'user', 'getauthors', array('ptid' => $ptid, 'cids' => empty($cid) ? array() : array($cid))); if (!empty($author) && isset($authorlist[$uid])) { $author = ''; } if (empty($id)) { $numitems = xarModAPIFunc('publications', 'user', 'countitems', array('ptid' => $ptid, 'cids' => empty($cid) ? array() : array($cid), 'owner' => $uid)); } else { $numitems = 1; } $data = array('ptid' => $ptid, 'cid' => $cid, 'uid' => $uid, 'author' => xarVarPrepForDisplay($author), 'authorlist' => $authorlist, 'id' => $id, 'title' => xarVarPrepForDisplay($title), 'numitems' => $numitems, 'extpid' => $extpid, 'extname' => $extname, 'extrealm' => $extrealm, 'extmodule' => $extmodule, 'extcomponent' => $extcomponent, 'extlevel' => $extlevel, 'extinstance' => xarVarPrepForDisplay(join(':', $newinstance))); // Get publication types $data['pubtypes'] = xarModAPIFunc('publications', 'user', 'get_pubtypes'); $catlist = array(); if (!empty($ptid)) { $basecats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid)); foreach ($basecats as $catid) { $catlist[$catid['id']] = 1; } if (empty($data['pubtypes'][$ptid]['config']['owner']['label'])) { $data['showauthor'] = 0; } else { $data['showauthor'] = 1; } } else { foreach (array_keys($data['pubtypes']) as $pubid) { $basecats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $pubid)); foreach ($basecats as $catid) { $catlist[$catid['id']] = 1; } } $data['showauthor'] = 1; } $seencid = array(); if (!empty($cid)) { $seencid[$cid] = 1; } $data['cids'] = $cids; $data['cats'] = $catlist; $data['refreshlabel'] = xarML('Refresh'); $data['applylabel'] = xarML('Finish and Apply to Privilege'); return $data; }
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']); }
/** * update item from publications_admin_modify */ function publications_admin_updatestate() { // Get parameters if (!xarVarFetch('ids', 'isset', $ids, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('state', 'isset', $state, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('catid', 'isset', $catid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) { return; } // Confirm authorisation code if (!xarSecConfirmAuthKey()) { return; } if (!isset($ids) || count($ids) == 0) { $msg = xarML('No publications selected'); throw new DataNotFoundException(null, $msg); } $states = xarModAPIFunc('publications', 'user', 'getstates'); if (!isset($state) || !is_numeric($state) || $state < -1 || $state != -1 && !isset($states[$state])) { $msg = xarML('Invalid state'); throw new BadParameterException(null, $msg); } $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); if (!empty($ptid)) { $descr = $pubtypes[$ptid]['description']; } else { $descr = xarML('Publications'); $ptid = null; } // We need to tell some hooks that we are coming from the update state screen // and not the update the actual article screen. Right now, the keywords vanish // into thin air. Bug 1960 and 3161 xarVarSetCached('Hooks.all', 'noupdate', 1); foreach ($ids as $id => $val) { if ($val != 1) { continue; } // Get original article information $article = xarModAPIFunc('publications', 'user', 'get', array('id' => $id, 'withcids' => 1)); if (!isset($article) || !is_array($article)) { $msg = xarML('Unable to find #(1) item #(2)', $descr, xarVarPrepForDisplay($id)); throw new BadParameterException(null, $msg); } $article['ptid'] = $article['pubtype_id']; // Security check $input = array(); $input['article'] = $article; if ($state < 0) { $input['mask'] = 'ManagePublications'; } else { $input['mask'] = 'EditPublications'; } if (!xarModAPIFunc('publications', 'user', 'checksecurity', $input)) { $msg = xarML('You have no permission to modify #(1) item #(2)', $descr, xarVarPrepForDisplay($id)); throw new ForbiddenOperationException(null, $msg); } if ($state < 0) { // Pass to API if (!xarModAPIFunc('publications', 'admin', 'delete', $article)) { return; // throw back } } else { // Update the state now $article['state'] = $state; // Pass to API if (!xarModAPIFunc('publications', 'admin', 'update', $article)) { return; // throw back } } } unset($article); // Return to the original admin view $lastview = xarSession::getVar('Publications.LastView'); if (isset($lastview)) { $lastviewarray = unserialize($lastview); if (!empty($lastviewarray['ptid']) && $lastviewarray['ptid'] == $ptid) { extract($lastviewarray); xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $ptid, 'catid' => $catid, 'state' => $state, 'startnum' => $startnum))); return true; } } if (empty($catid)) { $catid = null; } xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $ptid, 'catid' => $catid))); return true; }
/** * manage publication types (all-in-one function for now) */ function publications_admin_importpages() { if (!xarSecurityCheck('AdminPublications')) { return; } // Get parameters if (!xarVarFetch('basedir', 'isset', $basedir, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('filelist', 'isset', $filelist, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('refresh', 'isset', $refresh, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('content', 'isset', $content, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('title', 'isset', $title, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('filterhead', 'isset', $filterhead, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('filtertail', 'isset', $filtertail, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('findtitle', 'isset', $findtitle, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('numrules', 'isset', $numrules, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('search', 'isset', $search, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('replace', 'isset', $replace, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('test', 'isset', $test, NULL, XARVAR_DONT_SET)) { return; } if (!xarVarFetch('import', 'isset', $import, NULL, XARVAR_DONT_SET)) { return; } // Initialise the template variables $data = array(); if (empty($basedir)) { $data['basedir'] = realpath(sys::code() . 'modules/publications'); } else { $data['basedir'] = realpath($basedir); } $data['filelist'] = xarModAPIFunc('publications', 'admin', 'browse', array('basedir' => $data['basedir'], 'filetype' => 'html?')); if (isset($refresh) || isset($test) || isset($import)) { // Confirm authorisation code if (!xarSecConfirmAuthKey()) { return; } } $data['authid'] = xarSecGenAuthKey(); // Get current publication types $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); $data['pubtypes'] = $pubtypes; $data['fields'] = array(); $data['cats'] = array(); if (!empty($ptid)) { $data['ptid'] = $ptid; $pubfields = xarModAPIFunc('publications', 'user', 'getpubfields'); $pubfieldtypes = xarModAPIFunc('publications', 'user', 'getpubfieldtypes'); $pubfieldformats = xarModAPIFunc('publications', 'user', 'getpubfieldformats'); foreach ($pubfields as $field => $dummy) { if (($pubfieldtypes[$field] == 'text' || $pubfieldtypes[$field] == 'string') && !empty($pubtypes[$ptid]['config'][$field]['label']) && $pubtypes[$ptid]['config'][$field]['format'] != 'fileupload') { $data['fields'][$field] = $pubtypes[$ptid]['config'][$field]['label'] . ' [' . $pubfieldformats[$pubtypes[$ptid]['config'][$field]['format']] . ']'; } } $catlist = array(); $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid)); foreach ($rootcats as $catid) { $catlist[$catid['category_id']] = 1; } $seencid = array(); if (isset($cids) && is_array($cids)) { foreach ($cids as $catid) { if (!empty($catid)) { $seencid[$catid] = 1; } } } $cids = array_keys($seencid); foreach (array_keys($catlist) as $catid) { $data['cats'][] = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $catid, 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 1)); } } $data['selected'] = array(); if (!isset($refresh) && isset($filelist) && is_array($filelist) && count($filelist) > 0) { foreach ($filelist as $file) { if (!empty($file) && in_array($file, $data['filelist'])) { $data['selected'][$file] = 1; } } } if (isset($title) && isset($data['fields'][$title])) { $data['title'] = $title; } if (isset($content) && isset($data['fields'][$content])) { $data['content'] = $content; } if (!isset($filterhead)) { $data['filterhead'] = '#^.*<body[^>]*>#is'; } else { $data['filterhead'] = $filterhead; } if (!isset($filtertail)) { $data['filtertail'] = '#</body.*$#is'; } else { $data['filtertail'] = $filtertail; } if (!isset($findtitle)) { $data['findtitle'] = '#<title>(.*?)</title>#is'; } else { $data['findtitle'] = $findtitle; } if (!isset($numrules)) { $numrules = 3; } $data['search'] = array(); $data['replace'] = array(); for ($i = 0; $i < $numrules; $i++) { if (isset($search[$i])) { $data['search'][$i] = $search[$i]; if (isset($replace[$i])) { $data['replace'][$i] = $replace[$i]; } else { $data['replace'][$i] = ''; } } else { $data['search'][$i] = ''; $data['replace'][$i] = ''; } } if (isset($data['ptid']) && isset($data['content']) && count($data['selected']) > 0 && (isset($test) || isset($import))) { $mysearch = array(); $myreplace = array(); for ($i = 0; $i < $numrules; $i++) { if (!empty($data['search'][$i])) { $mysearch[] = $data['search'][$i]; if (!empty($data['replace'][$i])) { $myreplace[] = $data['replace'][$i]; } else { $myreplace[] = ''; } } } $data['logfile'] = ''; foreach (array_keys($data['selected']) as $file) { $curfile = realpath($basedir . '/' . $file); if (!file_exists($curfile) || !is_file($curfile)) { continue; } $page = @join('', file($curfile)); if (!empty($data['findtitle']) && preg_match($data['findtitle'], $page, $matches)) { $title = $matches[1]; } else { $title = ''; } if (!empty($data['filterhead'])) { $page = preg_replace($filterhead, '', $page); } if (!empty($data['filtertail'])) { $page = preg_replace($filtertail, '', $page); } if (count($mysearch) > 0) { $page = preg_replace($mysearch, $myreplace, $page); } $article = array('title' => ' ', 'summary' => '', 'body' => '', 'notes' => '', 'pubdate' => filemtime($curfile), 'state' => 2, 'ptid' => $data['ptid'], 'cids' => $cids, 'pubtype_id' => $data['ptid'], 'owner' => xarUserGetVar('id'), 'id' => 0); if (!empty($data['title']) && !empty($title)) { $article[$data['title']] = $title; } $article[$data['content']] = $page; if (isset($test)) { // preview the first file as a test $data['preview'] = xarModFunc('publications', 'user', 'display', array('article' => $article, 'preview' => true)); break; } else { $id = xarModAPIFunc('publications', 'admin', 'create', $article); if (empty($id)) { return; // throw back } else { $data['logfile'] .= xarML('File #(1) was imported as #(2) #(3)', $curfile, $pubtypes[$data['ptid']]['description'], $id); $data['logfile'] .= '<br />'; } } } } $data['filterhead'] = xarVarPrepForDisplay($data['filterhead']); $data['filtertail'] = xarVarPrepForDisplay($data['filtertail']); $data['findtitle'] = xarVarPrepForDisplay($data['findtitle']); for ($i = 0; $i < $numrules; $i++) { if (!empty($data['search'][$i])) { $data['search'][$i] = xarVarPrepForDisplay($data['search'][$i]); } if (!empty($data['replace'][$i])) { $data['replace'][$i] = xarVarPrepForDisplay($data['replace'][$i]); } } // Return the template variables defined in this function return $data; }
/** * delete calendar from database */ function calendar_admin_delete_calendar() { // Get parameters if (!xarVarFetch('calid', 'id', $calid)) { return; } if (!xarVarFetch('confirm', 'checkbox', $confirm, false, XARVAR_NOT_REQUIRED)) { return; } // Get calendar information $calendar = xarMod::apiFunc('calendar', 'user', 'get', array('calid' => $calid)); if (!isset($calendar) || $calendar == false) { $msg = xarML('Unable to find #(1) item #(2)', 'Calendar', xarVarPrepForDisplay($calid)); throw new Exception($msg); } // Security check $input = array(); $input['calendar'] = $calendar; $input['mask'] = 'DeleteCalendars'; /* TODO: security if (!xarMod::apiFunc('calendar','user','checksecurity',$input)) { $msg = xarML('You have no permission to delete item #(1)', xarVarPrepForDisplay($calid)); throw new Exception($msg); } */ // Check for confirmation if (!$confirm) { $data = array(); // Specify for which item you want confirmation $data['calid'] = $calid; // Use articles user GUI function (not API) for preview if (!xarMod::load('calendar', 'user')) { return; } $data['preview'] = xarMod::guiFunc('calendar', 'user', 'display', array('calid' => $calid)); // Add some other data you'll want to display in the template $data['confirmtext'] = xarML('Confirm deleting this calendar'); $data['confirmlabel'] = xarML('Confirm'); // Generate a one-time authorisation code for this operation $data['authid'] = xarSecGenAuthKey(); // Return the template variables defined in this function return $data; } // Confirmation present if (!xarSecConfirmAuthKey()) { return; } // Pass to API if (!xarMod::apiFunc('calendar', 'admin', 'delete_calendar', array('calid' => $calid))) { return; } // Success xarSession::setVar('statusmsg', xarML('Calendar Deleted')); // Return to the original admin view $lastview = xarSession::getVar('Calendar.LastView'); if (isset($lastview)) { $lastviewarray = unserialize($lastview); if (!empty($lastviewarray['ptid']) && $lastviewarray['ptid'] == $ptid) { extract($lastviewarray); xarController::redirect(xarModURL('calendar', 'admin', 'view_calendars')); return true; } } xarController::redirect(xarModURL('calendar', 'admin', 'view_calendars')); return true; }
/** * Import an object definition or an object item from XML */ function publications_adminapi_importpubtype($args) { // Security check - we require ADMIN rights here if (!xarSecurityCheck('AdminPublications')) { return; } extract($args); if (empty($xml) && empty($file)) { $msg = xarML('Missing import file or XML content'); throw new BadParameterException(null, $msg); } elseif (!empty($file) && (!file_exists($file) || !preg_match('/\\.xml$/', $file))) { $msg = xarML('Invalid import file'); throw new BadParameterException(null, $msg); } $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes'); $proptypes = DataPropertyMaster::getPropertyTypes(); $name2id = array(); foreach ($proptypes as $propid => $proptype) { $name2id[$proptype['name']] = $propid; } $prefix = xarDB::getPrefix(); $prefix .= '_'; if (!empty($file)) { $fp = @fopen($file, 'r'); if (!$fp) { $msg = xarML('Unable to open import file'); throw new BadParameterException(null, $msg); } } else { $lines = preg_split("/\r?\n/", $xml); $maxcount = count($lines); } $what = ''; $count = 0; $ptid = 0; $objectname2objectid = array(); $objectcache = array(); $objectmaxid = array(); while (!empty($file) && !feof($fp) || !empty($xml) && $count < $maxcount) { if (!empty($file)) { $line = fgets($fp, 4096); } else { $line = $lines[$count]; } $count++; if (empty($what)) { if (preg_match('#<object name="(\\w+)">#', $line, $matches)) { // in case we import the object definition $object = array(); $object['name'] = $matches[1]; $what = 'object'; } elseif (preg_match('#<items>#', $line)) { // in case we only import data $what = 'item'; } } elseif ($what == 'object') { if (preg_match('#<([^>]+)>(.*)</\\1>#', $line, $matches)) { $key = $matches[1]; $value = $matches[2]; if (isset($object[$key])) { if (!empty($file)) { fclose($fp); } $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)', 'object', xarVarPrepForDisplay($key), $count); throw new DuplicateException(null, $msg); } $object[$key] = $value; } elseif (preg_match('#<config>#', $line)) { if (isset($object['config'])) { if (!empty($file)) { fclose($fp); } $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)', 'object', 'config', $count); throw new DuplicateException(null, $msg); } $config = array(); $what = 'config'; } elseif (preg_match('#<properties>#', $line)) { if (empty($object['name']) || empty($object['moduleid'])) { if (!empty($file)) { fclose($fp); } $msg = xarML('Missing keys in object definition'); throw new BadParameterException(null, $msg); } // make sure we drop the object id, because it might already exist here unset($object['objectid']); $properties = array(); $what = 'property'; } elseif (preg_match('#<items>#', $line)) { $what = 'item'; } elseif (preg_match('#</object>#', $line)) { $what = ''; } else { // multi-line entries not relevant here } } elseif ($what == 'config') { if (preg_match('#<([^>]+)>(.*)</\\1>#', $line, $matches)) { $key = $matches[1]; $value = $matches[2]; if (isset($config[$key])) { if (!empty($file)) { fclose($fp); } $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)', 'config', xarVarPrepForDisplay($key), $count); throw new DuplicateException(null, $msg); } $config[$key] = $value; } elseif (preg_match('#</config>#', $line)) { // override default view if necessary $config['defaultview'] = 1; $object['config'] = serialize($config); $config = array(); $what = 'object'; } else { // multi-line entries not relevant here } } elseif ($what == 'property') { if (preg_match('#<property name="(\\w+)">#', $line, $matches)) { $property = array(); $property['name'] = $matches[1]; } elseif (preg_match('#</property>#', $line)) { if (empty($property['name']) || empty($property['type'])) { if (!empty($file)) { fclose($fp); } $msg = xarML('Missing keys in property definition'); throw new BadParameterException(null, $msg); } // make sure we drop the property id, because it might already exist here unset($property['id']); // TODO: watch out for multi-sites // replace default xar_* table prefix with local one $property['source'] = preg_replace("/^xar_/", $prefix, $property['source']); // add this property to the list $properties[] = $property; } elseif (preg_match('#<([^>]+)>(.*)</\\1>#', $line, $matches)) { $key = $matches[1]; $value = $matches[2]; if (isset($property[$key])) { if (!empty($file)) { fclose($fp); } $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)', 'property', xarVarPrepForDisplay($key), $count); throw new DuplicateException(null, $msg); } $property[$key] = $value; } elseif (preg_match('#</properties>#', $line)) { // 1. make sure we have a unique pubtype name foreach ($pubtypes as $pubid => $pubtype) { if ($object['name'] == $pubtype['name']) { $object['name'] .= '_' . time(); break; } } // 2. fill in the pubtype field config $fields = array(); $extra = array(); foreach ($properties as $property) { $field = $property['name']; switch ($field) { case 'id': case 'pubtype_id': // skip these break; case 'title': case 'summary': case 'body': case 'notes': case 'owner': case 'pubdate': case 'state': // convert property type to string if necessary if (is_numeric($property['type'])) { if (isset($proptypes[$property['type']])) { $property['type'] = $proptypes[$property['type']]['name']; } else { $property['type'] = 'static'; } } // reset disabled field labels to empty if (empty($property['state'])) { $property['label'] = ''; } if (!isset($property['validation'])) { $property['validation'] = ''; } $fields[$field] = array('label' => $property['label'], 'format' => $property['type'], 'input' => $property['input'], 'validation' => $property['validation']); break; default: // convert property type to numeric if necessary if (!is_numeric($property['type'])) { if (isset($name2id[$property['type']])) { $property['type'] = $name2id[$property['type']]; } else { $property['type'] = 1; } } $extra[] = $property; break; } } // 3. create the pubtype $ptid = xarModAPIFunc('publications', 'admin', 'createpubtype', array('name' => $object['name'], 'descr' => $object['label'], 'config' => $fields)); if (empty($ptid)) { return; } // 4. set the module variables xarModVars::set('publications', 'settings.' . $ptid, $object['config']); xarModVars::set('publications', 'number_of_categories.' . $ptid, 0); xarModVars::set('publications', 'mastercids.' . $ptid, ''); // 5. create a dynamic object if necessary if (count($extra) > 0) { $object['itemtype'] = $ptid; $object['config'] = ''; $object['isalias'] = 0; $objectid = xarModAPIFunc('dynamicdata', 'admin', 'createobject', $object); if (!isset($objectid)) { if (!empty($file)) { fclose($fp); } return; } // 6. create the dynamic properties foreach ($extra as $property) { $property['objectid'] = $objectid; $property['moduleid'] = $object['moduleid']; $property['itemtype'] = $object['itemtype']; $prop_id = xarModAPIFunc('dynamicdata', 'admin', 'createproperty', $property); if (!isset($prop_id)) { if (!empty($file)) { fclose($fp); } return; } } // 7. check if we need to enable DD hooks for this pubtype if (!xarModIsHooked('dynamicdata', 'publications')) { xarModAPIFunc('modules', 'admin', 'enablehooks', array('callerModName' => 'publications', 'callerItemType' => $ptid, 'hookModName' => 'dynamicdata')); } } $properties = array(); $what = 'object'; } elseif (preg_match('#<items>#', $line)) { $what = 'item'; } elseif (preg_match('#</object>#', $line)) { $what = ''; } else { // multi-line entries not relevant here } } elseif ($what == 'item') { /* skip this for publications if (preg_match('#<([^> ]+) itemid="(\d+)">#',$line,$matches)) { // find out what kind of item we're dealing with $objectname = $matches[1]; $itemid = $matches[2]; if (empty($objectname2objectid[$objectname])) { $objectinfo = DataObjectMaster::getObjectInfo(array('name' => $objectname)); if (isset($objectinfo) && !empty($objectinfo['objectid'])) { $objectname2objectid[$objectname] = $objectinfo['objectid']; } else { if (!empty($file)) fclose($fp); $msg = xarML('Unknown #(1) "#(2)" on line #(3)','object',xarVarPrepForDisplay($objectname),$count); throw new BadParameterException(null, $msg); } } $objectid = $objectname2objectid[$objectname]; $item = array(); // don't save the item id for now... // TODO: keep the item id if we set some flag //$item['itemid'] = $itemid; $closeitem = $objectname; $closetag = 'N/A'; } elseif (preg_match("#</$closeitem>#",$line)) { // let's create the item now... if (!isset($objectcache[$objectid])) { $objectcache[$objectid] = new DataObject(array('objectid' => $objectid)); } // set the item id to 0 // TODO: keep the item id if we set some flag $item['itemid'] = 0; // create the item $itemid = $objectcache[$objectid]->createItem($item); if (empty($itemid)) { if (!empty($file)) fclose($fp); return; } // keep track of the highest item id if (empty($objectmaxid[$objectid]) || $objectmaxid[$objectid] < $itemid) { $objectmaxid[$objectid] = $itemid; } $closeitem = 'N/A'; $closetag = 'N/A'; } elseif (preg_match('#<([^>]+)>(.*)</\1>#',$line,$matches)) { $key = $matches[1]; $value = $matches[2]; if (isset($item[$key])) { if (!empty($file)) fclose($fp); $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)','item',xarVarPrepForDisplay($key),$count); throw new DuplicateException(null, $msg); } $item[$key] = $value; $closetag = 'N/A'; } elseif (preg_match('#<([^/>]+)>(.*)#',$line,$matches)) { // multi-line entries *are* relevant here $key = $matches[1]; $value = $matches[2]; if (isset($item[$key])) { if (!empty($file)) fclose($fp); $msg = xarML('Duplicate definition for #(1) key #(2)','item',xarVarPrepForDisplay($key)); throw new DuplicateException(null, $msg); } $item[$key] = $value; $closetag = $key; } elseif (preg_match("#(.*)</$closetag>#",$line,$matches)) { // multi-line entries *are* relevant here $value = $matches[1]; if (!isset($item[$closetag])) { if (!empty($file)) fclose($fp); $msg = xarML('Undefined #(1) key #(2)','item',xarVarPrepForDisplay($closetag)); throw new BadParameterException(null, $msg); } $item[$closetag] .= $value; $closetag = 'N/A'; } elseif ($closetag != 'N/A') { // multi-line entries *are* relevant here if (!isset($item[$closetag])) { if (!empty($file)) fclose($fp); $msg = xarML('Undefined #(1) key #(2)','item',xarVarPrepForDisplay($closetag)); throw new BadParameterException(null, $msg); } $item[$closetag] .= $line; } elseif (preg_match('#</items>#',$line)) { skip this for publications */ if (preg_match('#</items>#', $line)) { $what = 'object'; } elseif (preg_match('#</object>#', $line)) { $what = ''; } else { } } else { } } if (!empty($file)) { fclose($fp); } return $ptid; }
function htmlUploadFile($fieldname, $size = 32, $maxsize = 1000000, $accesskey = '') { if (empty($fieldname)) { return; } $output = '<input type="hidden" name="MAX_FILE_SIZE" value="' . xarVarPrepForDisplay($maxsize) . '" />'; $output .= '<input' . ' type="file"' . ' name="' . xarVarPrepForDisplay($fieldname) . '"' . ' id="' . xarVarPrepForDisplay($fieldname) . '"' . ' size="' . xarVarPrepForDisplay($size) . '"' . (empty($accesskey) ? '' : ' accesskey="' . xarVarPrepForDisplay($accesskey) . '"') . ' />'; return $output; }
public function display() { $vars = $this->getContent(); if (!empty($vars) && is_array($vars)) { extract($vars); } // Get requested layout if (empty($layout)) { $layout = 1; // default tree here } if (!empty($startmodule)) { // static behaviour list($module, $itemtype, $rootcid) = explode('.', $startmodule); if (empty($rootcid)) { $rootcids = null; } elseif (strpos($rootcid, ' ')) { $rootcids = explode(' ', $rootcid); } elseif (strpos($rootcid, '+')) { $rootcids = explode('+', $rootcid); } else { $rootcids = explode('-', $rootcid); } } // TODO: for multi-module pages, we'll need some other reference point(s) // (e.g. cross-module categories defined in categories admin ?) // Get current module if (empty($module)) { if (xarVarIsCached('Blocks.categories', 'module')) { $modname = xarVarGetCached('Blocks.categories', 'module'); } if (empty($modname)) { $modname = xarModGetName(); } } else { $modname = $module; } $modid = xarModGetIDFromName($modname); if (empty($modid)) { return; } // Get current item type (if any) if (!isset($itemtype)) { if (xarVarIsCached('Blocks.categories', 'itemtype')) { $itemtype = xarVarGetCached('Blocks.categories', 'itemtype'); } else { // try to get itemtype from input xarVarFetch('itemtype', 'isset', $itemtype, NULL, XARVAR_DONT_SET); if (empty($itemtype)) { xarVarFetch('ptid', 'isset', $itemtype, NULL, XARVAR_DONT_SET); } // if } } if (empty($itemtype)) { $itemtype = null; } // Get current item id (if any) if (!isset($itemid)) { if (xarVarIsCached('Blocks.categories', 'itemid')) { $itemid = xarVarGetCached('Blocks.categories', 'itemid'); } else { // try to get itemid from input xarVarFetch('itemid', 'isset', $itemid, NULL, XARVAR_DONT_SET); if (empty($itemid)) { xarVarFetch('id', 'isset', $itemid, NULL, XARVAR_DONT_SET); } // if } } if (empty($itemid)) { $itemid = null; } if (isset($rootcids)) { $mastercids = $rootcids; } else { // Get number of categories for this module + item type $numcats = xarModAPIfunc('categories', 'user', 'countcatbases', array('module' => $modname, 'itemtype' => empty($itemtype) ? NULL : $itemtype)); if (empty($numcats)) { // no categories to show here -> return empty output return; } // Get master cids for this module + item type $mastercids = xarModAPIfunc('categories', 'user', 'getallcatbases', array('module' => $modname, 'format' => 'cids', 'order' => 'cid', 'itemtype' => empty($itemtype) ? NULL : $itemtype)); if (empty($mastercids)) { // no categories to show here -> return empty output return; } $mastercids = array_unique($mastercids); if (!empty($startmodule)) { $rootcids = $mastercids; } } // See if we need to show a count per category if (!isset($show_catcount)) { $show_catcount = 0; } // See if we need to show the children of current categories if (!isset($showchildren)) { $showchildren = 1; } // Get current category counts (optional array of cid => count) if (empty($show_catcount)) { $catcount = array(); } if (empty($showempty) || !empty($show_catcount)) { // A 'deep count' sums the totals at each node with the totals of all descendants. if (xarVarIsCached('Blocks.categories', 'deepcount')) { $deepcount = xarVarGetCached('Blocks.categories', 'deepcount'); } else { $deepcount = xarModAPIFunc('categories', 'user', 'deepcount', array('modid' => $modid, 'itemtype' => $itemtype)); xarVarSetCached('Blocks.categories', 'deepcount', $deepcount); } } if (!empty($show_catcount)) { if (xarVarIsCached('Blocks.categories', 'catcount')) { $catcount = xarVarGetCached('Blocks.categories', 'catcount'); } else { // Get number of items per category (for this module). // If show_catcount == 2 then add in all descendants too. if ($show_catcount == 1) { // We want to display only children category counts. $catcount = xarModAPIFunc('categories', 'user', 'groupcount', array('modid' => $modid, 'itemtype' => $itemtype)); } else { // We want to display the deep counts. $catcount =& $deepcount; } xarVarSetCached('Blocks.categories', 'catcount', $catcount); } } // Specify type=... & func = ... arguments for xarModURL() if (empty($type)) { if (xarVarIsCached('Blocks.categories', 'type')) { $type = xarVarGetCached('Blocks.categories', 'type'); } if (empty($type)) { $type = 'user'; } } if (empty($func)) { if (xarVarIsCached('Blocks.categories', 'func')) { $func = xarVarGetCached('Blocks.categories', 'func'); } if (empty($func)) { $func = 'view'; } } // Get current categories if (xarVarIsCached('Blocks.categories', 'catid')) { $catid = xarVarGetCached('Blocks.categories', 'catid'); } if (empty($catid)) { // try to get catid from input xarVarFetch('catid', 'isset', $catid, NULL, XARVAR_DONT_SET); } // turn $catid into $cids array (and set $andcids flag) $istree = 0; if (!empty($catid)) { // if we're viewing all items below a certain category, i.e. catid = _NN if (strstr($catid, '_')) { $catid = preg_replace('/_/', '', $catid); $istree = 1; } if (strpos($catid, ' ')) { $cids = explode(' ', $catid); $andcids = true; } elseif (strpos($catid, '+')) { $cids = explode('+', $catid); $andcids = true; } else { $cids = explode('-', $catid); $andcids = false; } } elseif (empty($cids)) { if (xarVarIsCached('Blocks.categories', 'cids')) { $cids = xarVarGetCached('Blocks.categories', 'cids'); } if (xarVarIsCached('Blocks.categories', 'andcids')) { $andcids = xarVarGetCached('Blocks.categories', 'andcids'); } if (empty($cids)) { // try to get cids from input xarVarFetch('cids', 'isset', $cids, NULL, XARVAR_DONT_SET); xarVarFetch('andcids', 'isset', $andcids, false, XARVAR_NOT_REQUIRED); if (empty($cids)) { $cids = array(); if ((empty($module) || $module == $modname) && !empty($itemid)) { $links = xarModAPIFunc('categories', 'user', 'getlinks', array('modid' => $modid, 'itemtype' => $itemtype, 'iids' => array($itemid))); if (!empty($links) && count($links) > 0) { $cids = array_keys($links); } } } } } if (count($cids) > 0) { $seencid = array(); foreach ($cids as $cid) { if (empty($cid) || !is_numeric($cid)) { continue; } $seencid[$cid] = 1; } $cids = array_keys($seencid); } $data = array(); $data['cids'] = $cids; // pass information about current module, item type and item id (if any) to template $data['module'] = $modname; $data['itemtype'] = $itemtype; $data['itemid'] = $itemid; // pass information about current function to template $data['type'] = $type; $data['func'] = $func; $blockinfo['content'] = ''; // Generate output switch ($layout) { case 3: // menu category $template = 'menu'; break; case 2: // crumbtrails $template = 'trails'; $data['cattrees'] = array(); if (empty($cids) || sizeof($cids) <= 0) { return; } // if $cid = current($cids); $data['cid'] = $cid; # Get category parents $parents = xarModAPIFunc('categories', 'user', 'getparents', array('cid' => $cid)); if (empty($parents)) { return; } // if $root = ''; $parentid = 0; foreach ($parents as $id => $info) { $publications = xarModAPIFunc('publications', 'user', 'getall', array('cid' => $info['cid'], 'ptid' => $itemtype, 'fields' => array('id', 'title'))); foreach ($publications as $k => $article) { $publications[$article['title']] = $article['id']; unset($publications[$k]); } // foreach $label = xarVarPrepForDisplay($info['name']); if (isset($publications[$label])) { $link = xarModURL($modname, $type, 'display', array('ptid' => $itemtype, 'catid' => $info['cid'], 'id' => $publications[$label])); } else { $link = xarModURL($modname, $type, $func, array('itemtype' => $itemtype, 'catid' => $info['cid'])); } // if if (empty($root)) { $link = xarModURL('', '', ''); $root = $label; } // if if (!empty($catcount[$info['cid']])) { $count = $catcount[$info['cid']]; } else { $count = 0; } // if $catparents[] = array('catlabel' => $label, 'catid' => $info['cid'], 'catlink' => $link, 'catcount' => $count); } // foreach $data['cattrees'][] = array('catparents' => $catparents); $data['crumbSeparator'] = ' > '; break; case 1: // tree // tree default: $template = 'tree'; $data['cattrees'] = array(); if (empty($cids) || sizeof($cids) <= 0) { return; } // if $cid = current($cids); $cat = xarModAPIFunc('categories', 'user', 'getcatinfo', array('cid' => $cid)); $blockinfo['title'] = xarVarPrepForDisplay($cat['name']); if (isset($cat['blockimage'])) { $data['catimage'] = $cat['blockimage']; } // if # Get child categories $childrenCategories = xarModAPIFunc('categories', 'user', 'getchildren', array('cid' => $cid)); # get all the pubtypes so we can digest the ids $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes', array()); # get immediate items in current category $items = xarModAPIFunc('publications', 'user', 'getall', array('cids' => array($cid), 'fields' => array('id', 'pubtype_id', 'title'))); $tmpPublications = array(); foreach ($items as $k => $item) { if (strtolower($item['title']) == strtolower($cat['name'])) { unset($items[$k]); } else { $label = xarVarPrepForDisplay($item['title']); $class = $item['id'] == $itemid ? 'xar-menu-item-current' : 'xar-menu-item'; $link = xarModURL($modname, $type, 'display', array('id' => $item['id'], 'itemtype' => $item['pubtype_id'], 'catid' => $cid)); $count = 0; $items[$k] = array('label' => $label, 'id' => $item['id'], 'class' => $class, 'link' => $link); $tmpPublications[$pubtypes[$item['pubtype_id']]['description']][] = $items[$k]; } // if } // foreach $items = $tmpPublications; unset($tmpPublications); if (empty($itemid) && empty($andcids)) { $link = ''; } $catitems = array(); if (!empty($childrenCategories) && count($childrenCategories) > 0) { foreach ($childrenCategories as $child) { $publications = xarModAPIFunc('publications', 'user', 'getall', array('cid' => $child['cid'], 'ptid' => $itemtype, 'fields' => array('id', 'title'))); foreach ($publications as $k => $article) { $publications[$article['title']] = $article['id']; unset($publications[$k]); } // foreach $clabel = xarVarPrepForDisplay($child['name']); if (isset($publications[$clabel])) { $clink = xarModURL($modname, $type, 'display', array('ptid' => $itemtype, 'catid' => $child['cid'], 'id' => $publications[$clabel])); } else { $clink = xarModURL($modname, $type, $func, array('itemtype' => $itemtype, 'catid' => $child['cid'])); } // if if (!empty($catcount[$child['cid']])) { $ccount = $catcount[$child['cid']]; } else { $ccount = 0; } $catitems[] = array('catlabel' => $clabel, 'catid' => $child['cid'], 'catlink' => $clink, 'catcount' => $ccount, 'catchildren' => array()); } // foreach } // if if (sizeof($catitems) > 0 || sizeof($items) > 0) { $data['cattrees'][] = array('catitems' => $catitems, 'items' => $items); } else { return; } // if break; } $data['blockid'] = $this->block_id; // The template base is set by this block if not already provided. // The base is 'nav-tree', 'nav-trails' or 'nav-prevnext', but allow // the admin to override this completely. $this->setTemplateBase('nav-' . $template); return $data; }