/** * display block * * @author The Zikula Development Team * @param array $blockinfo a blockinfo structure * @return output the rendered bock */ public function display($blockinfo) { // security check if (!SecurityUtil::checkPermission('Storiesblock::', $blockinfo['bid'].'::', ACCESS_OVERVIEW)) { return; } // Break out options from our content field $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (!isset($vars['storiestype'])) { $vars['storiestype'] = 2; } if (!isset($vars['limit'])) { $vars['limit'] = 10; } // work out the paraemters for the api all $apiargs = array(); switch ($vars['storiestype']) { case 1: // non index page articles $apiargs['displayonindex'] = 0; break; case 3: // index page articles $apiargs['displayonindex'] = 1; break; // all - doesn't need displayonindex } $apiargs['numitems'] = $vars['limit']; $apiargs['status'] = News_Api_User::STATUS_PUBLISHED; $apiargs['ignorecats'] = true; if (isset($vars['category']) && !empty($vars['category'])) { $cat = CategoryUtil::getCategoryByID($vars['category']); $categories = CategoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $apiargs['category'] = array('Main' => $catstofilter); } $apiargs['filterbydate'] = true; // call the api $items = ModUtil::apiFunc('News', 'user', 'getall', $apiargs); // check for an empty return if (empty($items)) { return; } // create the output object $this->view->setCaching(false); // loop through the items $storiesoutput = array(); foreach ($items as $item) { $storyreadperm = false; if (SecurityUtil::checkPermission('News::', "$item[cr_uid]::$item[sid]", ACCESS_READ)) { $storyreadperm = true; } $this->view->assign('readperm', $storyreadperm); $this->view->assign($item); $storiesoutput[] = $this->view->fetch('block/stories_row.tpl', $item['sid'], null, false, false); } // assign the results $this->view->assign('stories', $storiesoutput); $blockinfo['content'] = $this->view->fetch('block/stories.tpl'); return BlockUtil::themeBlock($blockinfo); }
/** * view items * * @author Mark West * @param $args['prop'] category property * @param $args['cat'] category id * @param $args['page'] starting number for paged view * @param $args['itemsperpage'] the number of items on a page * @param $args['page'] starting number for paged view * @param $args['displayonindex'] show only newsitems marked for display on the index page * @param $args['giventemplate'] Template file to use * @return string HTML string */ public function view($args = array()) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', '::', ACCESS_OVERVIEW), LogUtil::getErrorMsgPermission()); // clean the session preview data SessionUtil::delVar('newsitem'); // get all module vars for later use $modvars = $this->getVars(); // Get parameters from whatever input we need $prop = isset($args['prop']) ? $args['prop'] : (string)FormUtil::getPassedValue('prop', null, 'GET'); $cat = isset($args['cat']) ? $args['cat'] : (string)FormUtil::getPassedValue('cat', null, 'GET'); $page = isset($args['page']) ? $args['page'] : (int)FormUtil::getPassedValue('page', 1, 'GET'); $displayModule = FormUtil::getPassedValue('module', 'X', 'GET'); // storyhome nrofitems is only used when News is the homepage module $defaultItemsPerPage = ($displayModule == 'X') ? $modvars['storyhome'] : $modvars['itemsperpage']; $itemsperpage = isset($args['itemsperpage']) ? $args['itemsperpage'] : (int)FormUtil::getPassedValue('itemsperpage', $defaultItemsPerPage, 'GET'); $displayonindex = isset($args['displayonindex']) ? (int)$args['displayonindex'] : FormUtil::getPassedValue('displayonindex', null, 'GET'); $giventemplate = isset($args['giventemplate']) ? $args['giventemplate'] : 'view.tpl'; // pages start at 1 if ($page < 1) { LogUtil::registerError($this->__('Error! Invalid page passed.')); } // work out page size from page number $startnum = (($page - 1) * $itemsperpage) + 1; $lang = ZLanguage::getLanguageCode(); // check if categorization is enabled if ($modvars['enablecategorization']) { // get the categories registered for News $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); $properties = array_keys($catregistry); // validate the property // and build the category filter - mateo if (!empty($prop) && in_array($prop, $properties) && !empty($cat)) { if (!is_numeric($cat)) { $rootCat = CategoryUtil::getCategoryByID($catregistry[$prop]); $cat = CategoryUtil::getCategoryByPath($rootCat['path'] . '/' . $cat); } else { $cat = CategoryUtil::getCategoryByID($cat); } $catname = isset($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name']; if (!empty($cat) && isset($cat['path'])) { // include all it's subcategories and build the filter $categories = CategoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $catFilter = array($prop => $catstofilter); } else { LogUtil::registerError($this->__('Error! Invalid category passed.')); } } } // get matching news articles $items = ModUtil::apiFunc('News', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $itemsperpage, 'status' => News_Api_User::STATUS_PUBLISHED, 'displayonindex' => $displayonindex, 'filterbydate' => true, 'category' => isset($catFilter) ? $catFilter : null, // get all method doesn't appear to want a category arg 'catregistry' => isset($catregistry) ? $catregistry : null)); if ($items == false) { if ($modvars['enablecategorization'] && isset($catFilter)) { LogUtil::registerStatus($this->__f('No articles currently published under the \'%s\' category.', $catname)); } else { LogUtil::registerStatus($this->__('No articles currently published.')); } } // assign various useful template variables $this->view->assign('startnum', $startnum); $this->view->assign('lang', $lang); // assign the root category $this->view->assign('category', $cat); $this->view->assign('catname', isset($catname) ? $catname : ''); $this->view->assign('catimagepath', $this->getVar('catimagepath')); $accesslevel = ACCESS_READ; if (SecurityUtil::checkPermission('News::', "::", ACCESS_COMMENT)) $accesslevel = ACCESS_COMMENT; if (SecurityUtil::checkPermission('News::', "::", ACCESS_EDIT)) $accesslevel = ACCESS_EDIT; $accesslevel = '|a'.$accesslevel; $newsitems = array(); // Loop through each item and display it foreach ($items as $item) { // display if it's published and the displayonindex match (if set) if (($item['published_status'] == 0) && (!isset($displayonindex) || $item['displayonindex'] == $displayonindex)) { $template = 'user/index.tpl'; if (!$this->view->is_cached($template, $item['sid'])) { // $info is array holding raw information. // Used below and also passed to the theme - jgm $info = ModUtil::apiFunc('News', 'user', 'getArticleInfo', $item); // $links is an array holding pure URLs to // specific functions for this article. // Used below and also passed to the theme - jgm $links = ModUtil::apiFunc('News', 'user', 'getArticleLinks', $info); // $preformat is an array holding chunks of // preformatted text for this article. // Used below and also passed to the theme - jgm $preformat = ModUtil::apiFunc('News', 'user', 'getArticlePreformat', array('info' => $info, 'links' => $links)); $this->view->assign(array( 'info' => $info, 'links' => $links, 'preformat' => $preformat)); } $newsitems[] = $this->view->fetch($template, $item['sid'].$accesslevel); } } // The items that are displayed on this overview page depend on the individual // user permissions. Therefor, we can not cache the whole page. // The single entries are cached, though. $this->view->setCaching(false); // Display the entries $this->view->assign('newsitems', $newsitems); // Assign the values for the smarty plugin to produce a pager $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('News', 'user', 'countitems', array('status' => 0, 'filterbydate' => true, 'displayonindex' => $displayonindex, 'category' => isset($catFilter) ? $catFilter : null)), 'itemsperpage' => $itemsperpage)); // Return the output that has been generated by this function return $this->view->fetch('user/'.$giventemplate); }
/** * display block * * @author The Zikula Development Team * @param array $blockinfo a blockinfo structure * @return output the rendered bock */ public function display($blockinfo) { // security check if (!SecurityUtil::checkPermission('Slideshowblock::', $blockinfo['bid'].'::', ACCESS_OVERVIEW)) { return; } // Break out options from our content field $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (!isset($vars['limit'])) { $vars['limit'] = 4; } // work out the parameters for the api all $apiargs = array(); $apiargs['numitems'] = $vars['limit']; $apiargs['status'] = News_Api_User::STATUS_PUBLISHED; $apiargs['ignorecats'] = true; if (isset($vars['category']) && !empty($vars['category'])) { $cat = CategoryUtil::getCategoryByID($vars['category']); $categories = CategoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $apiargs['category'] = array('Main' => $catstofilter); } $apiargs['filterbydate'] = true; // call the api $items = ModUtil::apiFunc('News', 'user', 'getall', $apiargs); // check for an empty return if (empty($items)) { return; } // create the output object $this->view->setCaching(false); // loop through the items $picupload_uploaddir = ModUtil::getVar('News', 'picupload_uploaddir'); $picupload_maxpictures = ModUtil::getVar('News', 'picupload_maxpictures'); $slideshowoutput = array(); $count = 0; foreach ($items as $item) { $count++; if ($item['pictures'] > 0) { $this->view->assign('readperm', SecurityUtil::checkPermission('News::', "$item[cr_uid]::$item[sid]", ACCESS_READ)); $this->view->assign('count', $count); $this->view->assign('picupload_uploaddir', $picupload_uploaddir); $this->view->assign($item); $slideshowoutput[] = $this->view->fetch('block/slideshow_row.tpl', $item['sid'], null, false, false); } } // assign the results $this->view->assign('slideshow', $slideshowoutput); $blockinfo['content'] = $this->view->fetch('block/slideshow.tpl'); return BlockUtil::themeBlock($blockinfo); }