Beispiel #1
0
 public function display()
 {
     $vars = $this->getContent();
     // Trick : work with cached variables here (set by the module function)
     // Check if we've been through publications display
     if (!xarVarIsCached('Blocks.publications', 'current_id')) {
         return;
     }
     $links = 0;
     if ($vars['showpubtype']) {
         // Show publication type (for now)
         $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
         if (xarVarIsCached('Blocks.publications', 'ptid')) {
             $ptid = xarVarGetCached('Blocks.publications', 'ptid');
             if (!empty($ptid) && isset($pubtypes[$ptid]['description'])) {
                 $vars['pubtypelink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid));
                 $vars['pubtypename'] = $pubtypes[$ptid]['description'];
                 $links++;
             }
         }
     }
     if ($vars['showcategory']) {
         // Show categories (for now)
         if (xarVarIsCached('Blocks.publications', 'cids')) {
             $cids = xarVarGetCached('Blocks.publications', 'cids');
             // TODO: add related links
         }
     }
     if ($vars['showauthor']) {
         // Show author (for now)
         if (xarVarIsCached('Blocks.publications', 'author')) {
             $author = xarVarGetCached('Blocks.publications', 'author');
             if (!empty($author)) {
                 $vars['authorlink'] = xarModURL('publications', 'user', 'view', array('ptid' => !empty($ptid) ? $ptid : null, 'owner' => $author));
                 $vars['authorid'] = $author;
                 if (!empty($vars['showvalue'])) {
                     $vars['authorcount'] = xarModAPIFunc('publications', 'user', 'countitems', array('ptid' => !empty($ptid) ? $ptid : null, 'owner' => $author, 'state' => array(2, 3), 'enddate' => time()));
                 }
                 $links++;
             }
         }
     }
     // Populate block info and pass to theme
     if ($links > 0) {
         return $vars;
     }
     return;
 }
Beispiel #2
0
/**
 * get the number of publications per publication type
 * @param $args['state'] array of requested status(es) for the publications
 * @return array array(id => count), or false on failure
 */
function publications_userapi_getpubcount($args)
{
    if (!empty($args['state'])) {
        $statestring = 'all';
    } else {
        if (is_array($args['state'])) {
            sort($args['state']);
            $statestring = join('+', $args['state']);
        } else {
            $statestring = $args['state'];
        }
    }
    if (xarVarIsCached('Publications.PubCount', $statestring)) {
        return xarVarGetCached('Publications.PubCount', $statestring);
    }
    $pubcount = array();
    $dbconn = xarDB::getConn();
    $tables = xarDB::getTables();
    sys::import('xaraya.structures.query');
    $q = new Query('SELECT', $tables['publications']);
    $q->addfield('pubtype_id');
    $q->addfield('COUNT(state) AS count');
    $q->addgroup('pubtype_id');
    if (!empty($args['state'])) {
    } else {
        if (is_array($args['state'])) {
            $q->in('state', $args['state']);
        } else {
            $q->eq('state', $args['state']);
        }
    }
    //    $q->qecho();
    if (!$q->run()) {
        return;
    }
    $pubcount = array();
    foreach ($q->output() as $key => $value) {
        $pubcount[$value['pubtype_id']] = $value['count'];
    }
    xarVarSetCached('Publications.PubCount', $statestring, $pubcount);
    return $pubcount;
}
Beispiel #3
0
 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;
 }
Beispiel #4
0
 /**
  * Display func.
  * @param none
  * @returns $data array of template data
  * @todo Option to display the menu even when not on a relevant page
  * @FIXME: if blocks are called before the main module is loaded their values are always empty
  * @FIXME: the calls to cache have no fallbacks and assume module is current main module.
  */
 function display()
 {
     $vars = $this->getContent();
     if (!empty($vars['root_ids']) && is_array($vars['root_ids'])) {
         $root_ids = $vars['root_ids'];
     } else {
         $root_ids = array();
     }
     // To start with, we need to know the current page.
     // It could be set (fixed) for the block, passed in
     // via the page cache, or simply not present.
     $id = 1;
     // Automatic: that means look at the page cache.
     if (xarVarIsCached('Blocks.publications', 'current_id')) {
         $id = xarVarGetCached('Blocks.publications', 'current_id');
         // Make sure it is numeric.
         if (!isset($id) || !is_numeric($id)) {
             $id = 0;
         }
     }
     // If we don't have a current page, then there is no trail to display.
     if (empty($id)) {
         return;
     }
     // The page details may have been cached, if
     // we have several
     // blocks on the same page showing the same tree.
     if (xarVarIsCached('Blocks.publications', 'pagedata')) {
         // Pages are cached?
         // 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.
         $pagedata = unserialize(serialize(xarVarGetCached('Blocks.publications', 'pagedata')));
         // If the cached tree does not contain the current page,
         // then we cannot use it.
         if (!isset($pagedata['pages'][$id])) {
             $pagedata = array();
         }
     }
     // If there is no pid, then we have no page or tree to display.
     //        if (empty($pagedata)) {return;}
     // If necessary, check whether the current page is under one of the
     // of the allowed root pids.
     if (!empty($root_ids)) {
         if (!xarMod::apiFunc('publications', 'user', 'pageintrees', array('pid' => $id, 'tree_roots' => $root_ids))) {
             return;
         }
     }
     // If we don't have any page data, then there is nothing to display.
     if (empty($pagedata)) {
         return;
     }
     // Here we add the various flags to the pagedata, based on
     // the current page.
     $pagedata = xarMod::apiFunc('publications', 'user', 'addcurrentpageflags', array('pagedata' => $pagedata, 'id' => $id, 'root_ids' => $root_ids));
     // If we don't want to include the root page in the crumbs, then shift it off now.
     if (empty($vars['include_root'])) {
         array_shift($pagedata['ancestors']);
     }
     // We may not have any ancestors left after shifting off the first one.
     if (empty($pagedata['ancestors'])) {
         return;
     }
     // Pass the page data into the block.
     // Merge it in with the existing block details.
     $data = array_merge($vars, $pagedata);
     return $data;
 }
Beispiel #5
0
 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'] = '&#160;>&#160;';
             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;
 }
Beispiel #6
0
 /**
  * Display func.
  * @param $blockinfo array
  * @returns $blockinfo array
  * @todo Option to display the menu even when not on a relevant page
  */
 function display(array $data = array())
 {
     // TODO:
     // We want a few facilities:
     // 1. Set a root higher than the real tree root. Pages will only
     //    be displayed once that root is reached. Effectively set one
     //    or more trees, at any depth, that this menu will cover. [DONE]
     // 2. Set a 'max depth' value, so only a preset max number of levels
     //    are rendered in a tree. [DONE]
     // [1 and 2 are a kind of "view window" for levels]
     // 3. Set behaviour when no current page in the Publications module is
     //    displayed, e.g. hide menu, show default tree or page etc. [DONE]
     // 4. Allow the page tree to be pruned at arbitrary specified
     //    pages. That would allow sections of the tree to be pruned
     //    from one menu and added to another (i.e. split menus).
     //    This will also move the current page, if it happens to be in the
     //    pruned section, down to the pruning page. [done]
     $data = $this->getContent();
     // Pointer to simplify referencing.
     $vars =& $data;
     if (!empty($data['root_ids']) && is_array($data['root_ids'])) {
         $root_ids = $data['root_ids'];
     } else {
         $root_ids = array();
     }
     if (!empty($data['prune_ids']) && is_array($data['prune_ids'])) {
         $prune_ids = $data['prune_ids'];
     } else {
         $prune_ids = array();
     }
     // To start with, we need to know the current page.
     // It could be set (fixed) for the block, passed in
     // via the page cache, or simply not present.
     $id = 0;
     if (empty($data['current_source']) || $data['current_source'] == 'AUTO' || $data['current_source'] == 'AUTODEFAULT') {
         // Automatic: that means look at the page cache.
         if (xarVarIsCached('Blocks.publications', 'current_id')) {
             $cached_id = xarVarGetCached('Blocks.publications', 'current_id');
             // Make sure it is numeric.
             if (isset($cached_id) && is_numeric($cached_id)) {
                 $id = $cached_id;
             }
         }
     }
     // Now we may or may not have a page ID.
     // If the page is not set, then check for a default.
     if (empty($id) && !empty($data['default_id'])) {
         // Set the current page to be the default.
         $id = $data['default_id'];
     }
     // The page details *may* have been cached, if
     // we are in the Publications module, or have several
     // blocks on the same page showing the same tree.
     if (xarVarIsCached('Blocks.publications', 'pagedata')) {
         // Pages are cached?
         // 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.
         $pagedata = unserialize(serialize(xarVarGetCached('Blocks.publications', 'pagedata')));
         //$pagedata = unserialize(serialize($pagedata));
         // If the cached tree does not contain the current page,
         // then we cannot use it.
         if (!isset($pagedata['pages'][$id])) {
             $pagedata = array();
         }
     }
     // If there is no id, then we have no page or tree to display.
     if (empty($id)) {
         return;
     }
     // If necessary, check whether the current page is under one of the
     // of the allowed root ids.
     if (!empty($root_ids)) {
         if (!xarMod::apiFunc('publications', 'user', 'pageintrees', array('id' => $id, 'tree_roots' => $root_ids))) {
             // Not under a root.
             // If the mode is AUTO then leave the menu blank.
             if ($data['current_source'] == 'AUTO' || $data['current_source'] == 'DEFAULT' || empty($data['default_id'])) {
                 return;
             } else {
                 // Use the default page instead.
                 $id = $data['default_id'];
                 $pagedata = array();
             }
         }
     }
     // If we don't have any page data, then fetch it now.
     if (empty($pagedata)) {
         // Get the page data here now.
         $pagedata = xarMod::apiFunc('publications', 'user', 'getpagestree', array('tree_contains_id' => $id, 'dd_flag' => true, 'key' => 'id', 'status' => 'ACTIVE,EMPTY'));
         // If $pagedata is empty, then we have an invalid ID or
         // no permissions. Return NULL if so, suppressing the block.
         if (empty($pagedata['pages'])) {
             return;
         }
         // Cache the data now we have gone to the trouble of fetching the tree.
         // Only cache it if the cache is empty to start with. We only cache a complete
         // tree here, so if any other blocks need it, it contains all possible
         // pages we could need in that tree.
         if (!xarVarIsCached('Blocks.publications', 'pagedata')) {
             xarVarSetCached('Blocks.publications', 'pagedata', $pagedata);
         }
     }
     // If the user has set a 'start level' then make sure the page sits at that level or above.
     // TODO: take into account the options that allow default pages to be displayed when
     // the current page does not fit into the specified range.
     // If the start level is greater than 0, then work back through ancestors to find
     // the implied root page.
     if (!empty($data['start_level'])) {
         // FIXME: '+1' only needed if the root page is being hidden. Maybe.
         if ($pagedata['pages'][$id]['depth'] + (!empty($data['multi_homed']) ? 1 : 0) < $data['start_level']) {
             // We are outside the start level.
             // Hide the block if there is no default page to set.
             return;
         } else {
             // We are within a start level.
             // Scan through ancestors, and find the one with the specified level,
             // and add it to the root ids list.
             $scan_id = $id;
             while (true) {
                 if (empty($pagedata['pages'][$scan_id]['parent_id'])) {
                     break;
                 }
                 if ($pagedata['pages'][$scan_id]['depth'] < $data['start_level']) {
                     $root_ids[] = $scan_id;
                     break;
                 }
                 $scan_id = $pagedata['pages'][$scan_id]['parent_id'];
             }
             // If the root id has no children, we should hide the block.
             if (!empty($data['multi_homed']) && empty($pagedata['pages'][$scan_id]['child_keys'])) {
                 return;
             }
         }
     }
     // TODO: handle privileges for pages somewhere. The user/display
     // function handles it for the current page, but there is no
     // point the block providing links to pages that cannot be
     // accessed.
     // Optionally prune branches from the tree.
     // TODO: Make sure we only prune above the root nodes. Trust the user for now to do that.
     //$prune_ids = array(15);
     if (!empty($prune_ids)) {
         foreach ($prune_ids as $prune_id) {
             if (isset($pagedata['pages'][$prune_id])) {
                 // The page exists.
                 // Move the current page if necessary.
                 if ($pagedata['pages'][$id]['left'] > $pagedata['pages'][$prune_id]['left'] && $pagedata['pages'][$id]['left'] < $pagedata['pages'][$prune_id]['right']) {
                     // Move the current page down from within the pruned section, to
                     // the current pruning point.
                     $id = $prune_id;
                 }
                 // Reset any of the pruning point's children.
                 $pagedata['pages'][$prune_id]['child_keys'] = array();
                 $pagedata['pages'][$prune_id]['has_children'] = false;
                 //var_dump($pagedata);
             }
         }
     }
     // transform to the format we need for displaying the menu
     $temp = array();
     foreach ($pagedata['pages'] as $k => $v) {
         $temp[$v['id']] = $v;
     }
     $pagedata['pages'] = $temp;
     // Here we add the various flags to the pagedata, based on
     // the current page.
     $pagedata = xarMod::apiFunc('publications', 'user', 'addcurrentpageflags', array('pagedata' => $pagedata, 'id' => $id, 'root_ids' => $root_ids));
     // If not multi-homed, then create a 'root root' page - a virtual page
     // one step back from the displayed root page. This makes the template
     // much easier to implement. The templates need never display the
     // root page passed into them, and always start with the children of
     // that root page.
     if (empty($data['multi_homed'])) {
         $pagedata['pages'][0] = array('child_keys' => array($pagedata['root_page']['key']), 'has_children' => true, 'is_ancestor' => true);
         unset($pagedata['root_page']);
         $pagedata['root_page'] =& $pagedata['pages'][0];
     }
     // Pass the page data into the block.
     // Merge it in with the existing block details.
     // TODO: It may be quicker to do the merge the other way around?
     $data = array_merge($data, $pagedata);
     return $data;
 }
Beispiel #7
0
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('/&amp;/', '&', $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);
}
Beispiel #8
0
 public function display()
 {
     $data = $this->getContent();
     // defaults
     $featuredid = $data['featuredid'];
     $fields = array('id', 'title', 'cids');
     $fields[] = 'dynamicdata';
     // Initialize arrays
     $data['feature'] = array();
     $data['items'] = array();
     // Setup featured item
     if ($featuredid > 0) {
         if (xarModIsHooked('uploads', 'publications', $data['pubtype_id'])) {
             xarVarSetCached('Hooks.uploads', 'ishooked', 1);
         }
         if ($featart = xarModAPIFunc('publications', 'user', 'getall', array('ids' => array($featuredid), 'extra' => array('cids', 'dynamicdata')))) {
             foreach ($featart as $featuredart) {
                 $fieldlist = array('id', 'title', 'summary', 'owner', 'pubdate', 'pubtype_id', 'notes', 'state', 'body', 'cids');
                 $featuredlink = xarModURL('publications', 'user', 'display', array('id' => $featuredart['id'], 'itemtype' => !empty($data['linkpubtype']) ? $featuredart['pubtype_id'] : NULL, 'catid' => !empty($data['linkcat']) && !empty($data['catfilter']) ? $data['catfilter'] : NULL));
                 if (empty($data['showfeaturedbod'])) {
                     $data['showfeaturedbod'] = false;
                 }
                 if (!isset($featuredart['cids'])) {
                     $featuredart['cids'] = "";
                 }
                 $feature = array('featuredname' => $featuredart['name'], 'featuredlabel' => $featuredart['title'], 'featuredlink' => $featuredlink, 'alttitle' => $data['alttitle'], 'altsummary' => $data['altsummary'], 'showfeaturedsum' => $data['showfeaturedsum'], 'showfeaturedbod' => $data['showfeaturedbod'], 'featureddesc' => $featuredart['summary'], 'featuredcids' => $featuredart['cids'], 'pubtype_id' => $featuredart['pubtype_id'], 'featuredid' => $featuredart['id'], 'featureddate' => $featuredart['start_date']);
                 // Get rid of the default fields so all we have left are the DD ones
                 foreach ($fieldlist as $field) {
                     if (isset($featuredart[$field])) {
                         unset($featuredart[$field]);
                     }
                 }
                 // now add the DD fields to the featuredart
                 $feature = array_merge($featuredart, $feature);
                 $data['feature'][] = $feature;
             }
         }
         // Setup additional items
         $fields = array('id', 'title', 'pubtype_id', 'cids');
         // Added the 'summary' field to the field list.
         if (!empty($data['showsummary'])) {
             $fields[] = 'summary';
         }
         if ($data['toptype'] == 'rating') {
             $fields[] = 'rating';
             $sort = 'rating';
         } elseif ($data['toptype'] == 'hits') {
             $fields[] = 'counter';
             $sort = 'hits';
         } elseif ($data['toptype'] == 'date') {
             $fields[] = 'pubdate';
             $sort = 'date';
         } else {
             $sort = $data['toptype'];
         }
         if (!empty($data['moreitems'])) {
             $publications = xarModAPIFunc('publications', 'user', 'getall', array('ids' => $data['moreitems'], 'enddate' => time(), 'fields' => $fields, 'sort' => $sort));
             // See if we're currently displaying an article
             if (xarVarIsCached('Blocks.publications', 'id')) {
                 $curid = xarVarGetCached('Blocks.publications', 'id');
             } else {
                 $curid = -1;
             }
             foreach ($publications as $article) {
                 if ($article['id'] != $curid) {
                     $link = xarModURL('publications', 'user', 'display', array('id' => $article['id'], 'itemtype' => !empty($vars['linkpubtype']) ? $article['pubtype_id'] : NULL, 'catid' => !empty($data['linkcat']) && !empty($data['catfilter']) ? $data['catfilter'] : NULL));
                 } else {
                     $link = '';
                 }
                 $count = '';
                 // TODO: find a nice clean way to show all sort types
                 if ($data['showvalue']) {
                     if ($data['toptype'] == 'rating') {
                         $count = intval($article['rating']);
                     } elseif ($data['toptype'] == 'hits') {
                         $count = $article['counter'];
                     } elseif ($data['toptype'] == 'date') {
                         // TODO: make user-dependent
                         if (!empty($article['pubdate'])) {
                             $count = strftime("%Y-%m-%d", $article['pubdate']);
                         } else {
                             $count = 0;
                         }
                     } else {
                         $count = 0;
                     }
                 } else {
                     $count = 0;
                 }
                 if (isset($article['cids'])) {
                     $cids = $article['cids'];
                 } else {
                     $cids = '';
                 }
                 if (isset($article['pubdate'])) {
                     $pubdate = $article['pubdate'];
                 } else {
                     $pubdate = '';
                 }
                 // Pass $desc to items[] array so that the block template can render it
                 $data['items'][] = array('label' => $article['title'], 'link' => $link, 'count' => $count, 'cids' => $cids, 'pubdate' => $pubdate, 'desc' => !empty($data['showsummary']) && !empty($article['summary']) ? $article['summary'] : '', 'id' => $article['id']);
             }
         }
     }
     if (empty($data['feature']) && empty($data['items'])) {
         // Nothing to display.
         return;
     }
     return $data;
 }