/** * Setup form. * * @param Zikula_Form_View $view Current Zikula_Form_View instance. * * @return boolean */ public function initialize(Zikula_Form_View $view) { // load and assign registred categories $categories = CategoryRegistryUtil::getRegisteredModuleCategories('ExampleDoctrine', 'User', 'id'); $view->assign('registries', $categories); $id = FormUtil::getPassedValue('id', null, "GET", FILTER_SANITIZE_NUMBER_INT); if ($id) { // load user with id $user = $this->entityManager->find('ExampleDoctrine_Entity_User', $id); if ($user) { // switch to edit mode $this->_id = $id; } else { return LogUtil::registerError($this->__f('User with id %s not found', $id)); } } else { $user = new ExampleDoctrine_Entity_User(); } $userData = $user->toArray(); // overwrite attributes array entry with a form compitable format $field1 = $user->getAttributes()->get('field1') ? $user->getAttributes()->get('field1')->getValue() : ''; $field2 = $user->getAttributes()->get('field2') ? $user->getAttributes()->get('field2')->getValue() : ''; $userData['attributes'] = array('field1' => $field1, 'field2' => $field2); // assign current values to form fields $view->assign('user', $user)->assign('meta', $user->getMetadata() != null ? $user->getMetadata()->toArray() : array())->assign($userData); $this->_user = $user; return true; }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('title', 'text')->add('urltitle', 'text', array('required' => false, 'label' => __('PermaLink URL title')))->add($builder->create('metadescription', 'textarea', array('required' => false))->addModelTransformer(new NullToEmptyTransformer()))->add($builder->create('metakeywords', 'textarea', array('required' => false))->addModelTransformer(new NullToEmptyTransformer()))->add('content')->add('displaywrapper', 'checkbox', array('required' => false, 'label' => __('Display additional information')))->add('displaytitle', 'checkbox', array('required' => false, 'label' => __('Display page title')))->add('displaycreated', 'checkbox', array('required' => false, 'label' => __('Display page creation date')))->add('displayupdated', 'checkbox', array('required' => false, 'label' => __('Display page update date')))->add('displaytextinfo', 'checkbox', array('required' => false, 'label' => __('Display page text statistics')))->add('displayprint', 'checkbox', array('required' => false, 'label' => __('Display page print link')))->add($builder->create('language', 'choice', array('choices' => \ZLanguage::getInstalledLanguageNames(), 'required' => false, 'placeholder' => __('All')))->addModelTransformer(new NullToEmptyTransformer()))->add('obj_status', 'checkbox', array('required' => false, 'label' => __('Page is active')))->add('save', 'submit', array('label' => 'Create Page')); $entityCategoryRegistries = \CategoryRegistryUtil::getRegisteredModuleCategories('ZikulaPagesModule', 'PageEntity', 'id'); foreach ($entityCategoryRegistries as $registryId => $parentCategoryId) { $builder->add('categories', new CategoryType($registryId, $parentCategoryId), array('multiple' => true)); } }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->prependClientTransformer(new CategoriesCollectionTransformer($options['entityCategoryClass']))->addEventSubscriber(new CategoriesMergeCollectionListener()); $registries = \CategoryRegistryUtil::getRegisteredModuleCategories($options['module'], $options['entity'], 'id'); foreach ($registries as $registryId => $categoryId) { $builder->add('registry_' . $registryId, 'entity', array('class' => 'ZikulaCategoriesModule:CategoryEntity', 'property' => 'name', 'query_builder' => function (EntityRepository $repo) use($categoryId) { //TODO: (move to)/use own entity repository after CategoryUtil migration return $repo->createQueryBuilder('e')->where('e.parent = :parentId')->setParameter('parentId', (int) $categoryId); })); } }
public function buildForm(FormBuilderInterface $builder, array $options) { if (empty($options['entityCategoryClass']) || empty($options['module']) || empty($options['entity'])) { throw new \InvalidArgumentException('empty argument!'); } $registries = \CategoryRegistryUtil::getRegisteredModuleCategories($options['module'], $options['entity'], 'id'); foreach ($registries as $registryId => $categoryId) { $builder->add('registry_' . $registryId, 'entity', ['required' => $options['required'], 'multiple' => $options['multiple'], 'class' => 'ZikulaCategoriesModule:CategoryEntity', 'property' => 'name', 'query_builder' => function (EntityRepository $repo) use($categoryId) { //TODO: (move to)/use own entity repository after CategoryUtil migration return $repo->createQueryBuilder('e')->where('e.parent = :parentId')->setParameter('parentId', (int) $categoryId); }]); } $builder->addViewTransformer(new CategoriesCollectionTransformer($options), true); $builder->addEventSubscriber(new CategoriesMergeCollectionListener()); }
public function prepare(&$groups) { if (!self::$filter) { $filter = array('__META__' => array('module' => 'TimeIt')); $items = $this->getItems($groups); // load the categories system if (!($class = Loader::loadClass('CategoryRegistryUtil'))) { z_exit('Unable to load class [CategoryRegistryUtil] ...'); } $properties = CategoryRegistryUtil::getRegisteredModuleCategories('TimeIt', 'TimeIt_events'); foreach ($properties as $prop => $catid) { $filter[$prop] = $items; } self::$filter = DBUtil::generateCategoryFilterWhere('TimeIt_events', false, $filter); } }
/** * modify block settings * * @author The Zikula Development Team * @param array $blockinfo a blockinfo structure * @return output the bock form */ public function modify($blockinfo) { // Get current content $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (!isset($vars['cache_time'])) { $vars['cache_time'] = 600; } if (!isset($vars['cache_dir'])) { $vars['cache_dir'] = 'any_cache'; } if (!isset($vars['enablefacebookshare'])) { $vars['enablefacebookshare'] = false; } // Create output object $this->view->caching = false; # Admin output changes often, we do not want caching // Select categories only if enabled for the module $enablecategorization = ModUtil::getVar($this->name, 'enablecategorization'); if ($enablecategorization) { // load the categories system if (!Loader::loadClass('CategoryRegistryUtil')) { return LogUtil::registerError(__f('Error! Could not load [%s] class.'), 'CategoryRegistryUtil'); } // Get the registrered categories for the module $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'ephem'); $this->view->assign('catregistry', $catregistry); } $this->view->assign('enablecategorization', $enablecategorization); $this->view->assign($vars); // assign the block vars if (!isset($vars['category']) || !is_array($vars['category'])) { $vars['category'] = array(); } $this->view->assign('category', $vars['category']); // return the output return $this->view->fetch('ephemerides_block_ephemeride_modify.tpl'); }
/** * Displays all available events. * * @return string HTML Code */ public function view() { // check object type $objectType = FormUtil::getPassedValue('ot', 'event', 'GET'); $this->throwNotFoundUnless(in_array($objectType, TimeIt_Util::getObjectTypes('view')), $this->__f('Unkown object type %s.', DataUtil::formatForDisplay($objectType))); // load filter $filter = TimeIt_Filter_Container::getFilterFormGETPOST($objectType); $this->view->assign('modvars', ModUtil::getVar('TimeIt')); // vars $tpl = null; $theme = null; $domain = $this->serviceManager->getService('timeit.manager.' . $objectType); // load the data if ($objectType == 'event') { $calendarId = (int) FormUtil::getPassedValue('cid', ModUtil::getVar('TimeIt', 'defaultCalendar'), 'GETPOST'); $calendar = $this->serviceManager->getService('timeit.manager.calendar')->getObject($calendarId); $this->throwNotFoundIf(empty($calendar), $this->__f('Calendar [%s] not found.', $calendarId)); $year = (int) FormUtil::getPassedValue('year', date("Y"), 'GETPOST'); $month = (int) FormUtil::getPassedValue('month', date("n"), 'GETPOST'); $day = (int) FormUtil::getPassedValue('day', date("j"), 'GETPOST'); $tpl = FormUtil::getPassedValue('viewType', FormUtil::getPassedValue('viewtype', $calendar['config']['defaultView'], 'GETPOST'), 'GETPOST'); $firstDayOfWeek = (int) FormUtil::getPassedValue('firstDayOfWeek', -1, 'GETPOST'); $theme = FormUtil::getPassedValue('template', $calendar['config']['defaultTemplate'], 'GETPOST'); // backward compatibility if ($theme == 'default') { $theme = 'table'; } // check for a valid $tpl if ($tpl != 'year' && $tpl != 'month' && $tpl != 'week' && $tpl != 'day') { $tpl = $calendar['config']['defaultView']; } $tpl = 'month'; $theme = 'table'; $this->view->assign('template', $theme); $this->view->assign('viewed_day', $day); $this->view->assign('viewed_month', $month); $this->view->assign('viewed_year', $year); $this->view->assign('viewType', $tpl); $this->view->assign('calendar', $calendar); $this->view->assign('viewed_date', DateUtil::getDatetime(mktime(0, 0, 0, $month, $day, $year), DATEONLYFORMAT_FIXED)); $this->view->assign('date_today', DateUtil::getDatetime(null, DATEONLYFORMAT_FIXED)); $this->view->assign('month_startDate', DateUtil::getDatetime(mktime(0, 0, 0, $month, 1, $year), DATEONLYFORMAT_FIXED)); $this->view->assign('month_endDate', DateUtil::getDatetime(mktime(0, 0, 0, $month, DateUtil::getDaysInMonth($month, $year), $year), DATEONLYFORMAT_FIXED)); $this->view->assign('filter_obj_url', $filter->toURL()); $this->view->assign('firstDayOfWeek', $firstDayOfWeek); $this->view->assign('selectedCats', array()); $categories = CategoryRegistryUtil::getRegisteredModuleCategories('TimeIt', 'TimeIt_events'); foreach ($categories as $property => $cid) { $cat = CategoryUtil::getCategoryByID($cid); if (isset($cat['__ATTRIBUTES__']['calendarid']) && !empty($cat['__ATTRIBUTES__']['calendarid'])) { if ($cat['__ATTRIBUTES__']['calendarid'] != $calendar['id']) { unset($categories[$property]); } } } $this->view->assign('categories', $categories); // load event data switch ($tpl) { case 'year': $objectData = $domain->getYearEvents($year, $calendar['id'], $firstDayOfWeek); break; case 'month': $objectData = $domain->getMonthEvents($year, $month, $day, $calendar['id'], $firstDayOfWeek, $filter); break; case 'week': $objectData = $domain->getWeekEvents($year, $month, $day, $calendar['id'], $filter); break; case 'day': $objectData = $domain->getDayEvents($year, $month, $day, $calendar['id'], $filter); break; } } // assign the data $this->view->assign('objectArray', $objectData); // render the html return $this->_renderTemplate($this->view, $objectType, 'user', 'view', $theme, $tpl, 'table'); }
/** * display available categories in News * * @author Erik Spaan [espaan] * @return string HTML string */ public function categorylist($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', '::', ACCESS_OVERVIEW), LogUtil::getErrorMsgPermission()); $enablecategorization = $this->getVar('enablecategorization'); if (UserUtil::isLoggedIn()) { $uid = UserUtil::getVar('uid'); } else { $uid = 0; } if ($enablecategorization) { // Get the categories registered for News $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); $properties = array_keys($catregistry); $propertiesdata = array(); foreach ($properties as $property) { $rootcat = CategoryUtil::getCategoryByID($catregistry[$property]); if (!empty($rootcat)) { $rootcat['path'] .= '/'; // Get all categories in this category property $catcount = $this->_countcategories($rootcat, $property, $catregistry, $uid); $rootcat['news_articlecount'] = $catcount['category']['news_articlecount']; $rootcat['news_totalarticlecount'] = $catcount['category']['news_totalarticlecount']; $rootcat['news_yourarticlecount'] = $catcount['category']['news_yourarticlecount']; $rootcat['subcategories'] = $catcount['subcategories']; // Store data per property for listing in the overview $propertiesdata[] = array('name' => $property, 'category' => $rootcat); } } // Assign property & category related vars $this->view->assign('propertiesdata', $propertiesdata); } // Assign the config vars $this->view->assign('enablecategorization', $enablecategorization); $this->view->assign('shorturls', System::getVar('shorturls', false)); $this->view->assign('lang', ZLanguage::getLanguageCode()); $this->view->assign('catimagepath', $this->getVar('catimagepath')); // Return the output that has been generated by this function return $this->view->fetch('user/categorylist.tpl'); }
/** * modify block settings * * @author Erik Spaan [espaan] * @param array $blockinfo a blockinfo structure * @return output the bock form */ public function modify($blockinfo) { // Break out options from our content field $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (!isset($vars['category'])) { $vars['category'] = array(); } if (!isset($vars['show'])) { $vars['show'] = 1; } if (!isset($vars['status'])) { $vars['status'] = 0; } if (!isset($vars['order'])) { $vars['order'] = 0; } if (!isset($vars['limit'])) { $vars['limit'] = 5; } // Maximum article age in days if (!isset($vars['dayslimit'])) { $vars['dayslimit'] = 0; } // Maximum title length if (!isset($vars['maxtitlelength'])) { $vars['maxtitlelength'] = 0; } if (!isset($vars['titlewraptxt'])) { $vars['titlewraptxt'] = '...'; } if (!isset($vars['showemptyresult'])) { $vars['showemptyresult'] = 0; } // Override templates for the block and row display if (!isset($vars['blocktemplate'])) { $vars['blocktemplate'] = ''; } if (!isset($vars['rowtemplate'])) { $vars['rowtemplate'] = ''; } // Display optional article information $vars['dispuname'] = (!isset($vars['dispuname'])) ? false : !empty($vars['dispuname']); $vars['dispdate'] = (!isset($vars['dispdate'])) ? true : !empty($vars['dispdate']); if (!isset($vars['dateformat'])) { $vars['dateformat'] = '%x'; } $vars['dispreads'] = (!isset($vars['dispreads'])) ? false : !empty($vars['dispreads']); $vars['dispcomments'] = (!isset($vars['dispcomments'])) ? false : !empty($vars['dispcomments']); if (!isset($vars['dispsplitchar'])) { $vars['dispsplitchar'] = ', '; } // Display (part of) the hometext of the article if (!isset($vars['disphometext'])) { $vars['disphometext'] = false; } if (!isset($vars['maxhometextlength'])) { $vars['maxhometextlength'] = 0; } if (!isset($vars['hometextwraptxt'])) { $vars['hometextwraptxt'] = '...'; } // Display of a new story image if (!isset($vars['dispnewimage'])) { $vars['dispnewimage'] = false; } if (!isset($vars['newimagelimit'])) { $vars['newimagelimit'] = 3; } if (!isset($vars['newimageset'])) { $vars['newimageset'] = 'icons/extrasmall'; } if (!isset($vars['newimagesrc'])) { $vars['newimagesrc'] = 'favorites.png'; } // display the items in a scrolling box, pausing, fading or marquee if (!isset($vars['scrolling'])) { $vars['scrolling'] = 1; } if (!isset($vars['scrollstyle'])) { $vars['scrollstyle'] = '%DIVID% { width:inherit; overflow:hidden; position:relative; padding:2px; border:0px solid black; background:transparent; /* IE: Height + 2*padding + 2*border */ height:54px; voice-family: "\"}\""; voice-family:inherit; /* regular height */ height:50px; } /* Opera browser */ html>body %DIVID% { height:50px; }'; } if (!isset($vars['scrolldelay'])) { $vars['scrolldelay'] = 3000; } if (!isset($vars['scrollmspeed'])) { $vars['scrollmspeed'] = 2; } // Get the News categorization setting $enablecategorization = ModUtil::getVar('News', 'enablecategorization'); // As Admin output changes often, we do not want caching. $this->view->setCaching(false); // Select categories only if enabled for the News module, otherwise selector will not be shown in modify template if ($enablecategorization) { // Get the registrered categories for the News module $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); $this->view->assign('catregistry', $catregistry); $this->view->assign('category', $vars['category']); } $this->view->assign('enablecategorization', $enablecategorization); // assign the block vars $this->view->assign($vars); $this->view->assign('dom'); // Return the output that has been generated by this function return $this->view->fetch('block/storiesext/modify.tpl'); }
/** * Edit Ephemeride * @author The Zikula Development Team * @param 'eid' Ephemeride id to delete * @param 'confirm' Delete confirmation * @return mixed HTML string if confirm is null, true otherwise */ public function modify($args) { // get parameters from whatever input we need. $eid = FormUtil::getPassedValue('eid', isset($args['eid']) ? $args['eid'] : null, 'GET'); $objectid = FormUtil::getPassedValue('objectid', isset($args['objectid']) ? $args['objectid'] : null, 'GET'); $delcache = FormUtil::getPassedValue('delcache', isset($args['delcache']) ? $args['delcache'] : null, 'GET'); // check to see if we have been passed $objectid, the generic item identifier. if (!empty($objectid)) { $eid = $objectid; } // get the item $item = ModUtil::apiFunc($this->name, 'user', 'get', array('eid' => $eid)); if (!$item) { return DataUtil::formatForDisplayHTML($this->__('No such Ephemeride found.')); } // calulate date for use in template $item['date'] = $item['yid'] . '-' . $item['mid'] . '-' . $item['did']; // security check if (!SecurityUtil::checkPermission($this->name . '::', "::{$eid}", ACCESS_EDIT)) { return LogUtil::registerPermissionError(); } // get all module vars $modvars = ModUtil::getVar($this->name); if ($modvars['enablecategorization']) { // load the category registry util $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'ephem'); $this->view->assign('catregistry', $catregistry); } // assign the item and module vars $this->view->assign($item); $this->view->assign($modvars); $this->view->assign('delcache', $delcache); // return the output that has been generated by this function return $this->view->fetch('ephemerides_admin_modify.tpl'); }
/** * modify a news entry (incl. delete) via ajax * * @author Frank Schummertz * @param 'sid' int the story id * @param 'page' int the story page * @return string HTML string */ public function modify() { $this->checkAjaxToken(); $sid = $this->request->getPost()->get('sid'); $page = $this->request->getPost()->get('page', 1); // Get the news article $item = ModUtil::apiFunc('News', 'User', 'get', array('sid' => $sid)); if ($item == false) { throw new Zikula_Exception_NotFound($this->__('Error! No such article found.')); } // Security check $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', "{$item['cr_uid']}::$sid", ACCESS_EDIT)); // Get the format types. 'home' string is bits 0-1, 'body' is bits 2-3. $item['hometextcontenttype'] = ($item['format_type'] % 4); $item['bodytextcontenttype'] = (($item['format_type'] / 4) % 4); // Set the publishing date options. if (!isset($item['to'])) { if (DateUtil::getDatetimeDiff_AsField($item['from'], $item['cr_date'], 6) >= 0 && is_null($item['to'])) { $item['unlimited'] = 1; $item['tonolimit'] = 1; } elseif (DateUtil::getDatetimeDiff_AsField($item['from'], $item['cr_date'], 6) < 0 && is_null($item['to'])) { $item['unlimited'] = 0; $item['tonolimit'] = 1; } } else { $item['unlimited'] = 0; $item['tonolimit'] = 0; } Zikula_AbstractController::configureView(); $this->view->setCaching(false); $modvars = $this->getVars(); if ($modvars['enablecategorization']) { $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); $this->view->assign('catregistry', $catregistry); } $this->view->assign('accessadd', 0); if (SecurityUtil::checkPermission('News::', '::', ACCESS_ADD)) { $this->view->assign('accessadd', 1); $this->view->assign('accesspicupload', 1); $this->view->assign('accesspubdetails', 1); } else { $this->view->assign('accesspicupload', SecurityUtil::checkPermission('News:pictureupload:', '::', ACCESS_ADD)); $this->view->assign('accesspubdetails', SecurityUtil::checkPermission('News:publicationdetails:', '::', ACCESS_ADD)); } // Assign the item to the template $this->view->assign('item', $item); // Assign the current page $this->view->assign('page', $page); // Assign the default languagecode $this->view->assign('lang', ZLanguage::getLanguageCode()); // Assign the content format $formattedcontent = ModUtil::apiFunc('News', 'User', 'isformatted', array('func' => 'modify')); $this->view->assign('formattedcontent', $formattedcontent); //lock the page so others cannot edit it if (ModUtil::available('PageLock')) { $returnUrl = ModUtil::url('News', 'admin', 'view'); ModUtil::apiFunc('PageLock', 'user', 'pageLock', array('lockName' => "Newsnews{$item['sid']}", 'returnUrl' => $returnUrl)); } // Return the output that has been generated by this function return new Zikula_Response_Ajax(array('result' => $this->view->fetch('ajax/modify.tpl'))); }
/** * This is a standard function to update the configuration parameters of the * module given the information passed back by the modification form * @author Mark West * @param int 'itemsperpage' number of articles per page * @return bool true */ public function updateconfig() { $this->checkCsrfToken(); $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', '::', ACCESS_ADMIN), LogUtil::getErrorMsgPermission()); // Update module variables $modvars = array(); $refereronprint = (int)FormUtil::getPassedValue('refereronprint', 0, 'POST'); if ($refereronprint != 0 && $refereronprint != 1) { $refereronprint = 0; } $modvars['refereronprint'] = $refereronprint; $modvars['itemsperpage'] = (int)FormUtil::getPassedValue('itemsperpage', 25, 'POST'); $modvars['itemsperadminpage'] = (int)FormUtil::getPassedValue('itemsperadminpage', 15, 'POST'); $modvars['storyhome'] = (int)FormUtil::getPassedValue('storyhome', 10, 'POST'); $modvars['storyorder'] = (int)FormUtil::getPassedValue('storyorder', 1, 'POST'); $modvars['enablecategorization'] = (bool)FormUtil::getPassedValue('enablecategorization', false, 'POST'); $modvars['enableattribution'] = (bool)FormUtil::getPassedValue('enableattribution', false, 'POST'); $catimagepath = FormUtil::getPassedValue('catimagepath', '/images/categories/', 'POST'); if (substr($catimagepath, -1) != '/') { $catimagepath .= '/'; // add slash if needed } $modvars['catimagepath'] = $catimagepath; $modvars['enableajaxedit'] = (bool)FormUtil::getPassedValue('enableajaxedit', false, 'POST'); $modvars['enablemorearticlesincat'] = (bool)FormUtil::getPassedValue('enablemorearticlesincat', false, 'POST'); $modvars['morearticlesincat'] = (int)FormUtil::getPassedValue('morearticlesincat', 0, 'POST'); $modvars['enabledescriptionvar'] = (bool)FormUtil::getPassedValue('enabledescriptionvar', false, 'POST'); $modvars['descriptionvarchars'] = (int)FormUtil::getPassedValue('descriptionvarchars', 250, 'POST'); $modvars['enablecategorybasedpermissions'] = (bool)FormUtil::getPassedValue('enablecategorybasedpermissions', false, 'POST'); $modvars['notifyonpending'] = (bool)FormUtil::getPassedValue('notifyonpending', false, 'POST'); $modvars['notifyonpending_fromname'] = FormUtil::getPassedValue('notifyonpending_fromname', '', 'POST'); $modvars['notifyonpending_fromaddress'] = FormUtil::getPassedValue('notifyonpending_fromaddress', '', 'POST'); $modvars['notifyonpending_toname'] = FormUtil::getPassedValue('notifyonpending_toname', '', 'POST'); $modvars['notifyonpending_toaddress'] = FormUtil::getPassedValue('notifyonpending_toaddress', '', 'POST'); $modvars['notifyonpending_subject'] = FormUtil::getPassedValue('notifyonpending_subject', '', 'POST'); $modvars['notifyonpending_html'] = (bool)FormUtil::getPassedValue('notifyonpending_html', true, 'POST'); $modvars['pdflink'] = (bool)FormUtil::getPassedValue('pdflink', false, 'POST'); $modvars['pdflink_tcpdfpath'] = FormUtil::getPassedValue('pdflink_tcpdfpath', '', 'POST'); $modvars['pdflink_tcpdflang'] = FormUtil::getPassedValue('pdflink_tcpdflang', '', 'POST'); $modvars['pdflink_headerlogo'] = FormUtil::getPassedValue('pdflink_headerlogo', '', 'POST'); $modvars['pdflink_headerlogo_width'] = FormUtil::getPassedValue('pdflink_headerlogo_width', '', 'POST'); $modvars['pdflink_enablecache'] = (bool)FormUtil::getPassedValue('pdflink_enablecache', false, 'POST'); $modvars['picupload_enabled'] = (bool)FormUtil::getPassedValue('picupload_enabled', false, 'POST'); $modvars['picupload_allowext'] = str_replace(array(' ', '.'), '', FormUtil::getPassedValue('picupload_allowext', 'jpg,gif,png', 'POST')); $modvars['picupload_index_float'] = FormUtil::getPassedValue('picupload_index_float', 'left', 'POST'); $modvars['picupload_article_float'] = FormUtil::getPassedValue('picupload_article_float', 'left', 'POST'); $modvars['picupload_maxfilesize'] = (int)FormUtil::getPassedValue('picupload_maxfilesize', '500000', 'POST'); $modvars['picupload_maxpictures'] = (int)FormUtil::getPassedValue('picupload_maxpictures', 3, 'POST'); $modvars['picupload_sizing'] = FormUtil::getPassedValue('picupload_sizing', '0', 'POST'); $modvars['picupload_picmaxwidth'] = (int)FormUtil::getPassedValue('picupload_picmaxwidth', 600, 'POST'); $modvars['picupload_picmaxheight'] = (int)FormUtil::getPassedValue('picupload_picmaxheight', 600, 'POST'); $modvars['picupload_thumbmaxwidth'] = (int)FormUtil::getPassedValue('picupload_thumbmaxwidth', 150, 'POST'); $modvars['picupload_thumbmaxheight'] = (int)FormUtil::getPassedValue('picupload_thumbmaxheight', 150, 'POST'); $modvars['picupload_thumb2maxwidth'] = (int)FormUtil::getPassedValue('picupload_thumb2maxwidth', 200, 'POST'); $modvars['picupload_thumb2maxheight'] = (int)FormUtil::getPassedValue('picupload_thumb2maxheight', 200, 'POST'); $modvars['picupload_uploaddir'] = FormUtil::getPassedValue('picupload_uploaddir', '', 'POST'); $createfolder = (bool)FormUtil::getPassedValue('picupload_createfolder', false, 'POST'); // create picture upload folder if needed if ($modvars['picupload_enabled']) { if ($createfolder && !empty($modvars['picupload_uploaddir'])) { News_ImageUtil::mkdir($modvars['picupload_uploaddir']); } } $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); $properties = array_keys($catregistry); $topicproperty = FormUtil::getPassedValue('topicproperty', null, 'POST'); $modvars['topicproperty'] = $properties[$topicproperty]; $permalinkformat = FormUtil::getPassedValue('permalinkformat', null, 'POST'); if ($permalinkformat == 'custom') { $permalinkformat = FormUtil::getPassedValue('permalinkstructure', null, 'POST'); } $modvars['permalinkformat'] = $permalinkformat; $modvars['shorturls26x'] = (bool)FormUtil::getPassedValue('shorturls26x', false, 'POST'); $this->setVars($modvars); // the module configuration has been updated successfuly LogUtil::registerStatus($this->__('Done! Saved module settings.')); return $this->redirect(ModUtil::url('News', 'admin', 'view')); }
/** * Fill some variables before the editing of the plugin parameters */ public function startEditing() { // Get the News categorization setting $enablecategorization = ModUtil::getVar('News', 'enablecategorization'); // Select categories only if enabled for the News module, otherwise selector will not be shown in modify template if ($enablecategorization) { // Get the registrered categories for the News module $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); $this->view->assign('catregistry', $catregistry); } $this->view->assign('enablecategorization', $enablecategorization); $showoptions = array( array('value' => 1, 'text' => $this->__('Show all news articles')), array('value' => 2, 'text' => $this->__('Show only articles set for index page listing')), array('value' => 3, 'text' => $this->__('Show only articles not set for index page listing')) ); $statusoptions = array( array('value' => 0, 'text' => $this->__('Published')), array('value' => 1, 'text' => $this->__('Rejected')), array('value' => 2, 'text' => $this->__('Pending Review')), array('value' => 3, 'text' => $this->__('Archived')) /* , array('value' => 4, 'text' => $this->__('Draft')) */ ); $orderoptions = array( array('value' => 0, 'text' => $this->__('News publisher setting')), array('value' => 1, 'text' => $this->__('Number of pageviews')), array('value' => 2, 'text' => $this->__('Article weight')), array('value' => 3, 'text' => $this->__('Random')) ); $this->view->assign('showoptions', $showoptions); $this->view->assign('statusoptions', $statusoptions); $this->view->assign('orderoptions', $orderoptions); }
/** * view items * * @param int $startnum the start item id for the pager * @return string HTML output */ public function view($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('Pages::', '::', ACCESS_EDIT), LogUtil::getErrorMsgPermission()); // initialize sort array - used to display sort classes and urls $sort = array(); $fields = array('pageid', 'title', 'cr_date'); // possible sort fields foreach ($fields as $field) { $sort['class'][$field] = 'z-order-unsorted'; // default values } // Get parameters from whatever input we need. $startnum = (int)FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : null, 'GETPOST'); $language = FormUtil::getPassedValue('language', isset($args['language']) ? $args['language'] : null, 'POST'); $purge = FormUtil::getPassedValue('purge', false, 'GET'); $orderby = FormUtil::getPassedValue('orderby', isset($args['orderby']) ? $args['orderby'] : 'pageid', 'GETPOST'); $original_sdir = FormUtil::getPassedValue('sdir', isset($args['sdir']) ? $args['sdir'] : 1, 'GETPOST'); $this->view->assign('startnum', $startnum); $this->view->assign('orderby', $orderby); $this->view->assign('sdir', $original_sdir); $sdir = $original_sdir ? 0 : 1; //if true change to false, if false change to true // change class for selected 'orderby' field to asc/desc if ($sdir == 0) { $sort['class'][$orderby] = 'z-order-desc'; $orderdir = 'DESC'; } if ($sdir == 1) { $sort['class'][$orderby] = 'z-order-asc'; $orderdir = 'ASC'; } $filtercats = FormUtil::getPassedValue('pages', null, 'GETPOST'); $filtercats_serialized = FormUtil::getPassedValue('filtercats_serialized', false, 'GET'); $filtercats = $filtercats_serialized ? unserialize($filtercats_serialized) : $filtercats; $catsarray = Pages_Util::formatCategoryFilter($filtercats); // complete initialization of sort array, adding urls foreach ($fields as $field) { $sort['url'][$field] = ModUtil::url('Pages', 'admin', 'view', array( 'language' => $language, 'filtercats_serialized' => serialize($filtercats), 'orderby' => $field, 'sdir' => $sdir)); } $this->view->assign('sort', $sort); $this->view->assign('filter_active', (empty($language) && empty($catsarray)) ? false : true); if ($purge) { if (ModUtil::apiFunc('Pages', 'admin', 'purgepermalinks')) { LogUtil::registerStatus($this->__('Purging of the pemalinks was successful')); } else { LogUtil::registerError($this->__('Purging of the pemalinks has failed')); } return System::redirect(strpos(System::serverGetVar('HTTP_REFERER'), 'purge') ? ModUtil::url('Pages', 'admin', 'view') : System::serverGetVar('HTTP_REFERER')); } // get module vars $modvars = $this->getVars(); if ($modvars['enablecategorization']) { $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Pages', 'pages'); $this->view->assign('catregistry', $catregistry); } $multilingual = System::getVar('multilingual', false); // Get all matching pages $items = ModUtil::apiFunc('Pages', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $modvars['itemsperpage'], 'order' => $orderby, 'orderdir' => $orderdir, 'ignoreml' => ($multilingual ? false : true), 'language' => $language, 'category' => null, 'catfilter' => isset($catsarray) ? $catsarray : null, 'catregistry' => isset($catregistry) ? $catregistry : null)); if (!$items) { $items = array(); } $pages = array(); foreach ($items as $key => $item) { $options = array(); $options[] = array('url' => ModUtil::url('Pages', 'user', 'display', array('pageid' => $item['pageid'])), 'image' => 'kview.png', 'title' => $this->__('View')); if (SecurityUtil::checkPermission('Pages::', "$item[title]::$item[pageid]", ACCESS_EDIT)) { $options[] = array('url' => ModUtil::url('Pages', 'admin', 'modify', array('pageid' => $item['pageid'])), 'image' => 'xedit.png', 'title' => $this->__('Edit')); if (SecurityUtil::checkPermission('Pages::', "$item[title]::$item[pageid]", ACCESS_DELETE)) { $options[] = array('url' => ModUtil::url('Pages', 'admin', 'delete', array('pageid' => $item['pageid'])), 'image' => '14_layer_deletelayer.png', 'title' => $this->__('Delete')); } } // Add the calculated menu options to the item array $item['options'] = $options; $pages[] = $item; } // Assign the items to the template $this->view->assign('pages', $pages); // Assign the default language $this->view->assign('lang', ZLanguage::getLanguageCode()); $this->view->assign('language', $language); // Assign the information required to create the pager $this->view->assign('pager', array( 'numitems' => ModUtil::apiFunc('Pages', 'user', 'countitems', array('catfilter' => isset($catsarray) ? $catsarray : null)), 'itemsperpage' => $modvars['itemsperpage'])); $selectedcategories = array(); if (is_array($filtercats)) { $catsarray = $filtercats['__CATEGORIES__']; foreach ($catsarray as $propname => $propid) { if ($propid > 0) { $selectedcategories[$propname] = $propid; // removes categories set to 'all' } } } $this->view->assign('selectedcategories', $selectedcategories); // Return the output that has been generated by this function return $this->view->fetch('admin/view.tpl'); }
/** * 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('Pastblock::', "$blockinfo[bid]::", ACCESS_READ)) { return; } // get the number of stories shown on the frontpage $storyhome = $this->getVar('storyhome', 10); // Break out options from our content field $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (empty($vars['limit'])) { $vars['limit'] = 10; } if ($this->getVar('enablecategorization')) { $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); } // call the API $articles = ModUtil::apiFunc('News', 'user', 'getall', array( 'displayonindex' => 1, 'order' => 'from', 'status' => News_Api_User::STATUS_PUBLISHED, 'startnum' => $storyhome + 1, 'numitems' => $vars['limit'], 'catregistry' => isset($catregistry) ? $catregistry : null)); if (($articles === false) || (empty($articles))) { return; } // loop round the return articles grouping by date $count = 0; $news = array(); $newscumul = array(); $limitreached = false; foreach ($articles as $article) { $info = ModUtil::apiFunc('News', 'user', 'getArticleInfo', $article); $links = ModUtil::apiFunc('News', 'user', 'getArticleLinks', $info); if (SecurityUtil::checkPermission('News::', "$info[cr_uid]::$info[sid]", ACCESS_READ)) { $preformat['title'] = "<a href=\"$links[fullarticle]\">$info[title]</a>"; } else { $preformat['title'] = $info['title']; } $daydate = DateUtil::formatDatetime(strtotime($info['from']), '%Y-%m-%d'); // Reset the time if (!isset($currentday)) { $currentday = $daydate; } // If it's a different date, save the cumul and continue if ($currentday != $daydate) { $news[$currentday] = $newscumul; $newscumul = array(); $currentday = $daydate; } $newscumul[] = array('info' => $info, 'links' => $links, 'preformat' => $preformat); } if (!isset($news[$currentday])) { $news[$currentday] = $newscumul; } $this->view->assign('news', $news); if (empty($blockinfo['title'])) { //! default past block title $blockinfo['title'] = $this->__('Past articles'); } $blockinfo['content'] = $this->view->fetch('block/past.tpl'); return BlockUtil::themeBlock($blockinfo); }
/** * get a specific item * @author Mark West * @param $args['sid'] id of news item to get * @return mixed item array, or false on failure */ public function get($args) { // optional arguments if (isset($args['objectid'])) { $args['sid'] = $args['objectid']; } // Argument check if ((!isset($args['sid']) || !is_numeric($args['sid'])) && !isset($args['title'])) { return LogUtil::registerArgsError(); } // Check for caching of the DBUtil calls (needed for AJAX editing) if (!isset($args['SQLcache'])) { $args['SQLcache'] = true; } // form a date using some ofif present... // step 1 - convert month name into if (isset($args['monthname']) && !empty($args['monthname'])) { $months = explode(' ', $this->__('Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec')); $keys = array_flip($months); $args['monthnum'] = $keys[ucfirst($args['monthname'])] + 1; } // step 2 - convert to a timestamp and back to a db format if (isset($args['year']) && !empty($args['year']) && isset($args['monthnum']) && !empty($args['monthnum']) && isset($args['day']) && !empty($args['day'])) { // use PHP strftime directly, since DateUtil translates dateformat strings, which is not ok in this case $timestring = strftime('%Y-%m-%d', mktime(0, 0, 0, $args['monthnum'], $args['day'], $args['year'])); } $permFilter = array(); $permFilter[] = array('realm' => 0, 'component_left' => 'News', 'component_middle' => '', 'component_right' => '', 'instance_left' => 'cr_uid', 'instance_middle' => '', 'instance_right' => 'sid', 'level' => ACCESS_READ); if (isset($args['sid']) && is_numeric($args['sid'])) { $item = DBUtil::selectObjectByID('news', $args['sid'], 'sid', null, $permFilter, null, $args['SQLcache']); } elseif (isset($timestring)) { $tables = DBUtil::getTables(); $col = $tables['news_column']; $where = "{$col['urltitle']} = '".DataUtil::formatForStore($args['title'])."' AND {$col['from']} LIKE '{$timestring}%'"; $item = DBUtil::selectObject('news', $where, null, $permFilter, null, $args['SQLcache']); } else { $item = DBUtil::selectObjectByID('news', $args['title'], 'urltitle', null, $permFilter, null, $args['SQLcache']); } if (empty($item)) return false; // Sanity check for the published status if required if (isset($args['status'])) { if ($item['published_status'] != $args['status']) { return false; } } // process the relative paths of the categories if ($this->getVar('enablecategorization') && !empty($item['__CATEGORIES__'])) { static $registeredCats; if (!isset($registeredCats)) { $registeredCats = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); } ObjectUtil::postProcessExpandedObjectCategories($item['__CATEGORIES__'], $registeredCats); if (!CategoryUtil::hasCategoryAccess($item['__CATEGORIES__'], 'News')) { return false; } } return $item; }
/** * Get the categories registered for the Pages * * @return array */ private function getCategories() { $categoryRegistry = \CategoryRegistryUtil::getRegisteredModuleCategories('ZikulaPagesModule', 'PageEntity'); $properties = array_keys($categoryRegistry); $propertiesdata = array(); foreach ($properties as $property) { $rootcat = CategoryUtil::getCategoryByID($categoryRegistry[$property]); if (!empty($rootcat)) { $rootcat['path'] .= '/'; // add this to make the relative paths of the subcategories with ease - mateo $subcategories = CategoryUtil::getCategoriesByParentID($rootcat['id']); foreach ($subcategories as $k => $category) { $subcategories[$k]['count'] = $this->countItems(array('category' => $category['id'], 'property' => $property)); } $propertiesdata[] = array('name' => $property, 'rootcat' => $rootcat, 'subcategories' => $subcategories); } } return array($properties, $propertiesdata); }
/** * modify block settings * * @author The Zikula Development Team * @param array $blockinfo a blockinfo structure * @return output the bock form */ public function modify($blockinfo) { // Get current content $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (!isset($vars['hourfrom'])) { $vars['hourfrom'] = -1; } if (!isset($vars['hourto'])) { $vars['hourto'] = -1; } if (!isset($vars['monfrom'])) { $vars['monfrom'] = -1; } if (!isset($vars['monto'])) { $vars['monto'] = -1; } if (!isset($vars['mdayfrom'])) { $vars['mdayfrom'] = -1; } if (!isset($vars['mdayto'])) { $vars['mdayto'] = -1; } if (!isset($vars['wdayfrom'])) { $vars['wdayfrom'] = -1; } if (!isset($vars['wdayto'])) { $vars['wdayto'] = -1; } if (!isset($vars['cache_time'])) { $vars['cache_time'] = 120; } if (!isset($vars['cache_dir'])) { $vars['cache_dir'] = 'any_cache'; } if (!isset($vars['ballooncolor'])) { $vars['ballooncolor'] = 'grey'; } $ballooncolor = $vars['ballooncolor']; $this->view->assign('balloonselected' . $ballooncolor, 'selected="selected"'); if (!isset($vars['enablefacebookshare'])) { $vars['enablefacebookshare'] = false; } // Create output object $this->view->caching = false; // Select categories only if enabled for the module $enablecategorization = ModUtil::getVar($this->name, 'enablecategorization'); if ($enablecategorization) { // load the categories system if (!Loader::loadClass('CategoryRegistryUtil')) { return LogUtil::registerError(__f('Error! Could not load [%s] class.'), 'CategoryRegistryUtil'); } // Get the registrered categories for the module $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'quotes'); $this->view->assign('catregistry', $catregistry); } $this->view->assign('enablecategorization', $enablecategorization); $this->view->assign($vars); // assign the block vars if (!isset($vars['category']) || !is_array($vars['category'])) { $vars['category'] = array(); } $this->view->assign('category', $vars['category']); $this->view->assign('hours', range(0, 23)); $this->view->assign('months', range(1, 12)); $this->view->assign('wdays', range(1, 7)); $this->view->assign('mdays', range(1, 31)); // return the output return $this->view->fetch('quotes_block_quote_modify.tpl'); }
/** * display item * * @param $args array Arguments array. * * @return string html string */ public function display($args) { $pageid = FormUtil::getPassedValue('pageid', isset($args['pageid']) ? $args['pageid'] : null, 'REQUEST'); $title = FormUtil::getPassedValue('title', isset($args['title']) ? $args['title'] : null, 'REQUEST'); $page = FormUtil::getPassedValue('page', isset($args['page']) ? $args['page'] : null, 'REQUEST'); $objectid = FormUtil::getPassedValue('objectid', isset($args['objectid']) ? $args['objectid'] : null, 'REQUEST'); if (!empty($objectid)) { $pageid = $objectid; } // Validate the essential parameters if ((empty($pageid) || !is_numeric($pageid)) && empty($title)) { return LogUtil::registerArgsError(); } if (!empty($title)) { unset($pageid); } // Set the default page number if (empty($page) || $page < 1 || !is_numeric($page)) { $page = 1; } $accesslevel = ACCESS_READ; if (SecurityUtil::checkPermission('Pages::', "::", ACCESS_COMMENT)) { $accesslevel = ACCESS_COMMENT; } if (SecurityUtil::checkPermission('Pages::', "::", ACCESS_EDIT)) { $accesslevel = ACCESS_EDIT; } // Regardless of caching, we need to increment the read count and set the cache ID if (isset($pageid)) { $this->view->setCacheId($pageid.'|'.$page.'_a'.$accesslevel); $incrementresult = ModUtil::apiFunc('Pages', 'user', 'incrementreadcount', array('pageid' => $pageid)); } else { $this->view->setCacheId($title.'|'.$page.'_a'.$accesslevel); $incrementresult = ModUtil::apiFunc('Pages', 'user', 'incrementreadcount', array('title' => $title)); } if ($incrementresult === false) { return LogUtil::registerError($this->__('No such page found.'), 404); } // get the categories registered for the Pages $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Pages', 'pages'); // Get the page if (isset($pageid)) { $params = array('pageid' => $pageid, 'catregistry' => (isset($catregistry)) ? $catregistry : null); $item = ModUtil::apiFunc('Pages', 'user', 'get', $params); } else { $params = array('title' => $title, 'catregistry' => (isset($catregistry)) ? $catregistry : null); $item = ModUtil::apiFunc('Pages', 'user', 'get', $params); System::queryStringSetVar('pageid', $item['pageid']); $pageid = $item['pageid']; } // determine which template to render this page with // A specific template may exist for this page (based on page id) if (isset($pageid) && $this->view->template_exists('user/display_' . $pageid . '.tpl')) { $template = 'user/display_' . $pageid . '.tpl'; } else { $template = 'user/display.tpl'; } // check if the contents are cached. if ($this->view->is_cached($template)) { return $this->view->fetch($template); } // The return value of the function is checked here if ($item === false) { return LogUtil::registerError($this->__('No such page found.'), 404); } // Explode the review into an array of seperate pages $allpages = explode('<!--pagebreak-->', $item['content'] ); // validates that the requested page exists if (!isset($allpages[$page-1])) { return LogUtil::registerError($this->__('No such page found.'), 404); } // Set the item bodytext to be the required page // nb arrays start from zero pages from one $item['content'] = trim($allpages[$page-1]); $numitems = count($allpages); unset($allpages); // Display Admin Edit Link if (SecurityUtil::checkPermission('Pages::Page', "{$item['title']}::{$item['pageid']}", ACCESS_EDIT)) { $item['displayeditlink'] = true; } else { $item['displayeditlink'] = false; } // Assign details of the item. $this->view->assign('item', $item); $this->view->assign('lang', ZLanguage::getLanguageCode()); // Now lets assign the informatation to create a pager for the review $pager = array('numitems' => $numitems, 'itemsperpage' => 1); $this->view->assign('pager', $pager); return $this->view->fetch($template); }
/** * Returns a list of all registries with main category for a given object type. * * @param string $args['ot'] The object type to retrieve (optional) * @param string $args['arraykey'] Key for the result array (optional) * * @return array list of the registries (registry id as key, main category id as value). */ public function getAllPropertiesWithMainCat(array $args = array()) { $objectType = $this->determineObjectType($args, 'getAllPropertiesWithMainCat'); if (!isset($args['arraykey'])) { $args['arraykey'] = ''; } $registryInfo = CategoryRegistryUtil::getRegisteredModuleCategories($this->name, ucfirst($objectType), $args['arraykey']); return $registryInfo; }
/** * view items * * @return string HTML output */ public function view() { // Security check if (!SecurityUtil::checkPermission('Reviews::', '::', ACCESS_OVERVIEW)) { return LogUtil::registerPermissionError(); } $controllerHelper = new Reviews_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = $this->request->query->filter('ot', 'review', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'user', 'action' => 'view'); if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) { $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs); } $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); $entityClass = $this->name . '_Entity_' . ucwords($objectType); $repository = $this->entityManager->getRepository($entityClass); $repository->setControllerArguments(array()); $viewHelper = new Reviews_Util_View($this->serviceManager); // parameter for used sorting field $sort = $this->request->query->filter('sort', '', FILTER_SANITIZE_STRING); if (empty($sort) || !in_array($sort, $repository->getAllowedSortingFields())) { $sort = $repository->getDefaultSortingField(); } // parameter for used sort order $sdir = $this->request->query->filter('sortdir', '', FILTER_SANITIZE_STRING); $sdir = strtolower($sdir); if ($sdir != 'asc' && $sdir != 'desc') { $sdir = 'asc'; } // convenience vars to make code clearer $currentUrlArgs = array('ot' => $objectType); $where = ''; // we check for letter $letter = $this->request->query->filter('letter', NULL); if ($letter != NULL) { $where = 'tbl.title LIKE \'' . DataUtil::formatForStore($letter) . '%\''; } $selectionArgs = array('ot' => $objectType, 'where' => $where, 'orderBy' => $sort . ' ' . $sdir); $showOwnEntries = (int) $this->request->query->filter('own', $this->getVar('showOnlyOwnEntries', 0), FILTER_VALIDATE_INT); $showAllEntries = (int) $this->request->query->filter('all', 0, FILTER_VALIDATE_INT); if (!$showAllEntries) { $csv = (int) $this->request->query->filter('usecsvext', 0, FILTER_VALIDATE_INT); if ($csv == 1) { $showAllEntries = 1; } } $this->view->assign('showOwnEntries', $showOwnEntries)->assign('showAllEntries', $showAllEntries); if ($showOwnEntries == 1) { $currentUrlArgs['own'] = 1; } if ($showAllEntries == 1) { $currentUrlArgs['all'] = 1; } // prepare access level for cache id $accessLevel = ACCESS_READ; $component = 'Reviews:' . ucwords($objectType) . ':'; $instance = '::'; if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) { $accessLevel = ACCESS_COMMENT; } if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) { $accessLevel = ACCESS_EDIT; } $templateFile = $viewHelper->getViewTemplate($this->view, 'user', $objectType, 'view', array()); $cacheId = 'view|ot_' . $objectType . '_sort_' . $sort . '_' . $sdir; $resultsPerPage = 0; if ($showAllEntries == 1) { // set cache id $this->view->setCacheId($cacheId . '_all_1_own_' . $showOwnEntries . '_' . $accessLevel); // if page is cached return cached content if ($this->view->is_cached($templateFile)) { return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); } // retrieve item list without pagination $entities = ModUtil::apiFunc($this->name, 'selection', 'getEntities', $selectionArgs); } else { // the current offset which is used to calculate the pagination $currentPage = (int) $this->request->query->filter('pos', 1, FILTER_VALIDATE_INT); // the number of items displayed on a page for pagination $resultsPerPage = (int) $this->request->query->filter('num', 0, FILTER_VALIDATE_INT); if ($resultsPerPage == 0) { $resultsPerPage = $this->getVar('pagesize', 10); } // set cache id $this->view->setCacheId($cacheId . '_amount_' . $resultsPerPage . '_page_' . $currentPage . '_own_' . $showOwnEntries . '_' . $accessLevel); // if page is cached return cached content if ($this->view->is_cached($templateFile)) { return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); } // retrieve item list with pagination $selectionArgs['currentPage'] = $currentPage; $selectionArgs['resultsPerPage'] = $resultsPerPage; list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs); $this->view->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage)); } foreach ($entities as $k => $entity) { $entity->initWorkflow(); } // build ModUrl instance for display hooks $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'view', ZLanguage::getLanguageCode(), $currentUrlArgs); // assign the object data, sorting information and details for creating the pager $this->view->assign('items', $entities)->assign('sort', $sort)->assign('sdir', $sdir)->assign('pageSize', $resultsPerPage)->assign('currentUrlObject', $currentUrlObject)->assign('shorturls', System::getVar('shorturls'))->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs)); $modelHelper = new Reviews_Util_Model($this->serviceManager); $this->view->assign('canBeCreated', $modelHelper->canBeCreated($objectType)); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); ///////////////////////Alter Code // Get parameters from whatever input we need $cat = (string) FormUtil::getPassedValue('cat', isset($args['cat']) ? $args['cat'] : null, 'GET'); $prop = (string) FormUtil::getPassedValue('prop', isset($args['prop']) ? $args['prop'] : null, 'GET'); $letter = (string) FormUtil::getPassedValue('letter', null, 'REQUEST'); $page = (int) FormUtil::getPassedValue('page', isset($args['page']) ? $args['page'] : 1, 'GET'); // get all module vars for later use $modvars = ModUtil::getVar('Reviews'); // defaults and input validation if (!is_numeric($page) || $page < 0) { $page = 1; } $startnum = ($page - 1) * $modvars['itemsperpage'] + 1; // check if categorisation is enabled if ($modvars['enablecategorization']) { // get the categories registered for Reviews $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Reviews', 'reviews'); $properties = array_keys($catregistry); // validate the property // and build the category filter - mateo if (!empty($properties) && in_array($prop, $properties)) { // if the property and the category are specified // means that we'll list the reviews that belongs to that category if (!empty($cat)) { if (!is_numeric($cat)) { $rootCat = CategoryUtil::getCategoryByID($catregistry[$prop]); $cat = CategoryUtil::getCategoryByPath($rootCat['path'] . '/' . $cat); } else { $cat = CategoryUtil::getCategoryByID($cat); } 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->__('Invalid category passed.')); } } } } // Get all matching reviews /*$items = ModUtil::apiFunc('Reviews', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $modvars['itemsperpage'], 'letter' => $letter, 'category' => isset($catFilter) ? $catFilter : null, 'catregistry' => isset($catregistry) ? $catregistry : null)); // assign all the necessary template variables $this->view->assign('items', $items); $this->view->assign('category', $cat); $this->view->assign('lang', ZLanguage::getLanguageCode()); $this->view->assign($modvars); $this->view->assign('shorturls', System::getVar('shorturls')); $this->view->assign('shorturlstype', System::getVar('shorturlstype')); // Assign the values for the smarty plugin to produce a pager $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Reviews', 'user', 'countitems', array('letter' => $letter, 'category' => isset($catFilter) ? $catFilter : null)), 'itemsperpage' => $modvars['itemsperpage'])); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); */ }
/** * view items */ public function view($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('Feeds::', "::", ACCESS_EDIT), LogUtil::getErrorMsgPermission()); $startnum = FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : null, 'GET'); $property = FormUtil::getPassedValue('feeds_property', isset($args['feeds_property']) ? $args['feeds_property'] : null, 'POST'); $category = FormUtil::getPassedValue("feeds_{$property}_category", isset($args["feeds_{$property}_category"]) ? $args["feeds_{$property}_category"] : null, 'POST'); $clear = FormUtil::getPassedValue('clear', false, 'POST'); $purge = FormUtil::getPassedValue('purge', false, 'GET'); if (!PluginUtil::isAvailable('systemplugin.simplepie')) { LogUtil::registerError($this->__('<strong>Fatal error: The required SimplePie system plugin is not available.</strong><br /><br />Zikula ships with the SimplePie plugin located in the docs/examples/plugins/ExampleSystemPlugin/SimplePie directory. It must be copied (or symlinked) from there and pasted into the /plugins directory. The plugin must then be installed. This is done via the Extensions module. Click on the System Plugins menu item and install the SimplePie plugin.')); } if ($purge) { if (ModUtil::apiFunc('Feeds', 'admin', 'purgepermalinks')) { LogUtil::registerStatus($this->__('Purging of the pemalinks was successful')); } else { LogUtil::registerError($this->__('Purging of the pemalinks has failed')); } return System::redirect(strpos(System::serverGetVar('HTTP_REFERER'), 'purge') ? ModUtil::url('Feeds', 'admin', 'view') : System::serverGetVar('HTTP_REFERER')); } if ($clear) { $property = null; $category = null; } // get module vars for later use $modvars = ModUtil::getVar('Feeds'); if ($modvars['enablecategorization']) { // load the category registry util $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Feeds', 'feeds'); $properties = array_keys($catregistry); // Validate and build the category filter - mateo if (!empty($property) && in_array($property, $properties) && !empty($category)) { $catFilter = array($property => $category); } // Assign a default property - mateo if (empty($property) || !in_array($property, $properties)) { $property = $properties[0]; } // plan ahead for ML features $propArray = array(); foreach ($properties as $prop) { $propArray[$prop] = $prop; } } // Get all the feeds $items = ModUtil::apiFunc('Feeds', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $modvars['itemsperpage'], 'order' => 'fid', 'category' => isset($catFilter) ? $catFilter : null, 'catregistry' => isset($catregistry) ? $catregistry : null)); $feedsitems = array(); foreach ($items as $item) { if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_READ)) { // Options for the item $options = array(); if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_EDIT)) { $options[] = array('url' => ModUtil::url('Feeds', 'user', 'display', array('fid' => $item['fid'])), 'image' => 'kview.png', 'title' => $this->__('View')); $options[] = array('url' => ModUtil::url('Feeds', 'admin', 'modify', array('fid' => $item['fid'])), 'image' => 'xedit.png', 'title' => $this->__('Edit')); if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_DELETE)) { $options[] = array('url' => ModUtil::url('Feeds', 'admin', 'delete', array('fid' => $item['fid'])), 'image' => '14_layer_deletelayer.png', 'title' => $this->__('Delete')); } } $item['options'] = $options; $feedsitems[] = $item; } } // Assign the items and modvars to the template $this->view->assign('feedsitems', $feedsitems); $this->view->assign($modvars); // Assign the default language $this->view->assign('lang', ZLanguage::getLanguageCode()); // Assign the categories information if enabled if ($modvars['enablecategorization']) { $this->view->assign('catregistry', $catregistry); $this->view->assign('numproperties', count($propArray)); $this->view->assign('properties', $propArray); $this->view->assign('property', $property); $this->view->assign("category", $category); } // Assign the values for the smarty plugin to produce a pager $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Feeds', 'user', 'countitems', array('category' => isset($catFilter) ? $catFilter : null)), 'itemsperpage' => $modvars['itemsperpage'])); // Return the output that has been generated by this function return $this->view->fetch('admin/view.tpl'); }
public function categories() { $this->throwForbiddenUnless(SecurityUtil::checkPermission('AddressBook::', '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); $this->view->setCacheId('main'); if ($this->view->is_cached('user/main.tpl')) { return $this->view->fetch('user/main.tpl'); } // Create output object $enablecategorization = ModUtil::getVar('AddressBook', 'enablecategorization'); if ($enablecategorization) { // get the categories registered for the AddressBook $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('AddressBook', 'addressbook_address'); $properties = array_keys($catregistry); $propertiesdata = array(); foreach ($properties as $property) { $rootcat = CategoryUtil::getCategoryByID($catregistry[$property]); if (!empty($rootcat)) { $rootcat['path'] .= '/'; // add this to make the relative paths of the subcategories with ease - mateo $subcategories = CategoryUtil::getCategoriesByParentID($rootcat['id']); $propertiesdata[] = array('name' => $property, 'rootcat' => $rootcat, 'subcategories' => $subcategories); } } // Assign some useful vars to customize the main $this->view->assign('properties', $properties); $this->view->assign('propertiesdata', $propertiesdata); } return $this->view->fetch('user_categories.tpl'); }
/** * Return some useful News links * * Syntax used in menutree * {ext:Blocks:news:[flat=BOOL&links=view,add,cat,arch|ALL]} * Params in [] are optional and * flat - true or false, if set to true links are ungrouped (default is false) * links - list of elements, default is ALL, avaiable items: * - view - link to main News view * - add - link do Submit News form * - cat - list of News categories * - arch - link to News archive * Items are displayed in order provided in menutree * * @param array $args['item'] menu node to be replaced * @param string $args['lang'] current menu language * @param string $args['extrainfo'] additional params * @return mixed array of links if successful, false otherwise */ public function news($args) { $dom = ZLanguage::getModuleDomain('menutree'); $item = isset($args['item']) && !empty($args['item']) ? $args['item'] : null; $lang = isset($args['lang']) && !empty($args['lang']) ? $args['lang'] : null; $bid = isset($args['bid']) && !empty($args['bid']) ? $args['bid'] : null; $extrainfo = isset($args['extrainfo']) && !empty($args['extrainfo']) ? $args['extrainfo'] : null; // $item ang lang params are required if (!$item || !$lang) { return false; } // is there is extrainfo - convert it into array, parse_str is quite handy if ($extrainfo) { parse_str($extrainfo, $extrainfo); } $extrainfo['flat'] = isset($extrainfo['flat']) ? (bool) $extrainfo['flat'] : false; $extrainfo['links'] = isset($extrainfo['links']) ? explode(',', $extrainfo['links']) : array('all'); // get id for first element, use api func to aviod id conflicts inside menu $idoffset = Blocks_MenutreeUtil::getIdOffset($item['id']); $lineno = 0; // load plugin language file $modinfo = ModUtil::getInfo(ModUtil::getIdFromName('News')); $links = array(); // build some link // you may use associative array keys if (!$extrainfo['flat']) { $links['news'] = array($lang => array('id' => $idoffset++, 'name' => $item['name'], 'href' => ModUtil::url('News'), 'title' => $item['title'], 'className' => $item['className'], 'state' => $item['state'], 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $item['parent'])); } $parentNode = !$extrainfo['flat'] ? $links['news'][$lang]['id'] : $item['parent']; if (in_array('all', $extrainfo['links']) || in_array('view', $extrainfo['links'])) { $links['view'] = array($lang => array('id' => $idoffset++, 'name' => $modinfo['displayname'], 'href' => ModUtil::url('News'), 'title' => __('View news', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('arch', $extrainfo['links'])) { $links['arch'] = array($lang => array('id' => $idoffset++, 'name' => __('Archive', $dom), 'href' => ModUtil::url('News', 'user', 'archives'), 'title' => __('Archive', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('add', $extrainfo['links'])) { $links['add'] = array($lang => array('id' => $idoffset++, 'name' => __('Submit news', $dom), 'href' => ModUtil::url('News', 'user', 'new'), 'title' => __('Submit news', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('cat', $extrainfo['links'])) { if (!$extrainfo['flat']) { $links['cat'] = array($lang => array('id' => $idoffset++, 'name' => __('Categories', $dom), 'href' => ModUtil::url('News'), 'title' => __('Categories', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } $catParentNode = !$extrainfo['flat'] ? $links['cat'][$lang]['id'] : $item['parent']; Loader::loadClass('CategoryRegistryUtil'); Loader::loadClass('CategoryUtil'); $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'stories'); if (!empty($catregistry)) { $multicategory = count($catregistry) > 1; $catLinks = array(); foreach ($catregistry as $prop => $catid) { if ($multicategory && !$extrainfo['flat']) { $parentCategory = CategoryUtil::getCategoryByID($catid); $catLinks[$catid] = array($lang => array('id' => $idoffset++, 'name' => isset($parentCategory['display_name'][$lang]) && !empty($parentCategory['display_name'][$lang]) ? $parentCategory['display_name'][$lang] : $parentCategory['name'], 'href' => '', 'title' => isset($parentCategory['display_name'][$lang]) && !empty($parentCategory['display_name'][$lang]) ? $parentCategory['display_name'][$lang] : $parentCategory['name'], 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $catParentNode)); } $categories = CategoryUtil::getSubCategories($catid); foreach ($categories as $cat) { $catLinks[$cat['id']] = array($lang => array('id' => $idoffset++, 'name' => isset($cat['display_name'][$lang]) && !empty($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name'], 'href' => ModUtil::url('News', 'user', 'view', array('prop' => $prop, 'cat' => $cat['name'])), 'title' => isset($cat['display_name'][$lang]) && !empty($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name'], 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => isset($catLinks[$cat['parent_id']]) ? $catLinks[$cat['parent_id']][$lang]['id'] : $catParentNode)); } } } elseif (!$extrainfo['flat']) { unset($links['cat']); } } // sort links in order provided in menutree if (!in_array('all', $extrainfo['links'])) { $sortedLinks = array(); if (!$extrainfo['flat']) { $sortedLinks[] = $links['news']; } foreach ($extrainfo['links'] as $l) { if (isset($links[$l]) && !empty($links[$l])) { $sortedLinks[] = $links[$l]; } if ($l == 'cat') { $sortedLinks = array_merge((array) $sortedLinks, (array) $catLinks); } } $links = $sortedLinks; } return $links; }