/** * This method provides a item detail view. * * @param string $tpl Name of alternative template (to be used instead of the default template). * @param boolean $raw Optional way to display a template instead of fetching it (required for standalone output). * * @return mixed Output. */ public function display() { $legacyControllerType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING); System::queryStringSetVar('type', $legacyControllerType); $this->request->query->set('type', $legacyControllerType); $controllerHelper = new MUVideo_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = 'movie'; $utilArgs = array('controller' => 'movie', 'action' => 'display'); $permLevel = $legacyControllerType == 'admin' ? ACCESS_ADMIN : ACCESS_READ; $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission()); $entityClass = $this->name . '_Entity_' . ucwords($objectType); $repository = $this->entityManager->getRepository($entityClass); $repository->setControllerArguments(array()); $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType)); // retrieve identifier of the object we wish to view $idValues = $controllerHelper->retrieveIdentifier($this->request, array(), $objectType, $idFields); $hasIdentifier = $controllerHelper->isValidIdentifier($idValues); $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.')); $selectionArgs = array('ot' => $objectType, 'id' => $idValues); $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', $selectionArgs); $this->throwNotFoundUnless($entity != null, $this->__('No such item.')); unset($idValues); $entity->initWorkflow(); // build ModUrl instance for display hooks; also create identifier for permission check $currentUrlArgs = $entity->createUrlArgs(); $instanceId = $entity->createCompositeIdentifier(); $currentUrlArgs['id'] = $instanceId; // TODO remove this $currentUrlObject = new Zikula_ModUrl($this->name, 'movie', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs); $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', $instanceId . '::', $permLevel), LogUtil::getErrorMsgPermission()); $viewHelper = new MUVideo_Util_View($this->serviceManager); $templateFile = $viewHelper->getViewTemplate($this->view, $objectType, 'display', array()); // set cache id $component = $this->name . ':' . ucwords($objectType) . ':'; $instance = $instanceId . '::'; $accessLevel = ACCESS_READ; if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) { $accessLevel = ACCESS_COMMENT; } if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) { $accessLevel = ACCESS_EDIT; } $this->view->setCacheId($objectType . '|' . $instanceId . '|a' . $accessLevel); // assign output data to view object. $this->view->assign($objectType, $entity)->assign('currentUrlObject', $currentUrlObject)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs)); // initialize $youtubeId = ''; // we get the id from the url $youtubeId = explode('=', $entity['urlOfYoutube']); // assign to template $this->view->assign('youtubeId', $youtubeId[1]); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, $objectType, 'display', array(), $templateFile); }
/** * This method provides a handling of edit requests. * * @param string $ot Treated object type. * @param string $tpl Name of alternative template (to be used instead of the default template). * @param boolean $raw Optional way to display a template instead of fetching it (required for standalone output). * * @return mixed Output. */ public function getVideos() { $controllerHelper = new MUVideo_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = $this->request->query->filter('ot', 'collection', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'user', 'action' => 'getVideos'); if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) { $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs); } $permLevel = ACCESS_EDIT; $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission()); // redirect to entity controller System::queryStringSetVar('lct', 'user'); $this->request->query->set('lct', 'user'); return ModUtil::func($this->name, $objectType, 'getVideos', array('lct' => 'user')); }
/** * decode the custom url string * * @param array $args Arguments array. * * @return bool true if successful, false otherwise */ public function decodeurl($args) { // check we actually have some vars to work with... if (!isset($args['vars'])) { return LogUtil::registerArgsError(); } // define the available user functions $funcs = array('main', 'view', 'display'); // set the correct function name based on our input if (empty($args['vars'][2])) { System::queryStringSetVar('func', 'main'); } elseif (!in_array($args['vars'][2], $funcs)) { System::queryStringSetVar('func', 'display'); $nextvar = 2; } else { System::queryStringSetVar('func', $args['vars'][2]); $nextvar = 3; } // add the category info if (FormUtil::getPassedValue('func') == 'view' && isset($args['vars'][$nextvar])) { // get rid of unused vars $args['vars'] = array_slice($args['vars'], $nextvar); System::queryStringSetVar('prop', (string)$args['vars'][0]); if (isset ($args['vars'][1])) { // check if there's a page arg $varscount = count($args['vars']); ($args['vars'][$varscount-2] == 'startnum') ? $pagersize = 2 : $pagersize = 0; System::queryStringSetVar('startnum', $args['vars'][$varscount-1]); // extract the category path $cat = implode('/', array_slice($args['vars'], 1, $varscount - $pagersize - 1)); System::queryStringSetVar('cat', $cat); } } // identify the correct parameter to identify the page if (FormUtil::getPassedValue('func') == 'display') { // get rid of unused vars $args['vars'] = array_slice($args['vars'], $nextvar); $nextvar = 0; // remove any category path down to the leaf category $varscount = count($args['vars']); if (ModUtil::getVar('Pages', 'addcategorytitletopermalink') && !empty($args['vars'][$nextvar+1])) { ($args['vars'][$varscount-2] == 'page') ? $pagersize = 2 : $pagersize = 0; $category = array_slice($args['vars'], 0, $varscount - 1 - $pagersize); System::queryStringSetVar('cat', implode('/',$category)); array_splice($args['vars'], 0, $varscount - 1 - $pagersize); } if (is_numeric($args['vars'][$nextvar])) { System::queryStringSetVar('pageid', $args['vars'][$nextvar]); } else { System::queryStringSetVar('title', $args['vars'][$nextvar]); } $nextvar++; if (isset($args['vars'][$nextvar]) && $args['vars'][$nextvar] == 'page') { System::queryStringSetVar('page', (int)$args['vars'][$nextvar+1]); } } return true; }
/** * Decode the custom url string. * * @return bool true if successful, false otherwise. */ public function decodeurl($args) { // check we actually have some vars to work with... if (!isset($args['vars'])) { return LogUtil::registerArgsError(); } System::queryStringSetVar('type', 'user'); // define the available user functions $funcs = array('main', 'form', 'search', 'process', 'recent'); // set the correct function name based on our input if (empty($args['vars'][2])) { // Retain this for BC for older URLs that might be stored System::queryStringSetVar('func', 'main'); } elseif (!in_array($args['vars'][2], $funcs)) { System::queryStringSetVar('func', 'main'); $nextvar = 2; } else { if ($args['vars'][2] == 'process') { $args['vars'][2] = 'search'; } System::queryStringSetVar('func', $args['vars'][2]); $nextvar = 3; } if (FormUtil::getPassedValue('func') == 'recent' && isset($args['vars'][$nextvar])) { System::queryStringSetVar('startnum', $args['vars'][$nextvar]); } // identify the correct parameter to identify the page if (FormUtil::getPassedValue('func') == 'search' && isset($args['vars'][$nextvar]) && !empty($args['vars'][$nextvar])) { System::queryStringSetVar('q', $args['vars'][$nextvar]); $nextvar++; if (isset($args['vars'][$nextvar]) && $args['vars'][$nextvar] == 'page') { System::queryStringSetVar('page', (int)$args['vars'][$nextvar + 1]); } } return true; }
/** * Selects a list of objects with a given where clause and pagination parameters. * * @param string $where The where clause to use when retrieving the collection (optional) (default=''). * @param string $orderBy The order-by clause to use when retrieving the collection (optional) (default=''). * @param integer $currentPage Where to start selection * @param integer $resultsPerPage Amount of items to select * @param boolean $useJoins Whether to include joining related objects (optional) (default=true). * @param boolean $slimMode If activated only some basic fields are selected without using any joins (optional) (default=false). * * @return Array with retrieved collection and amount of total records affected by this query. */ public function selectWherePaginated($where = '', $orderBy = '', $currentPage = 1, $resultsPerPage = 25, $useJoins = true, $slimMode = false) { $qb = $this->genericBaseQuery($where, $orderBy, $useJoins, $slimMode); $page = $currentPage; // check if we have any filters set $parameters = $this->getViewQuickNavParameters('', array()); $hasFilters = false; foreach ($parameters as $k => $v) { if (!is_numeric($v) && $v != '' || is_numeric($v) && $v > 0) { $hasFilters = true; break; } } if (!$hasFilters) { if ($page > 1 || isset($_GET['pos'])) { // store current page in session SessionUtil::setVar('MUVideoMoviesCurrentPage', $page); } else { // restore current page from session $page = SessionUtil::getVar('MUVideoMoviesCurrentPage', 1); System::queryStringSetVar('pos', $page); } } list($query, $count) = $this->getSelectWherePaginatedQuery($qb, $page, $resultsPerPage); $result = $this->retrieveCollectionResult($query, $orderBy, true); return array($result, $count); }
/** * decode the custom url string * * @author Mark West * @return bool true if successful, false otherwise */ public function decodeurl($args) { // check we actually have some vars to work with if (!is_array($args) || !isset($args['vars']) || !is_array($args['vars']) || !count($args['vars'])) { throw new \InvalidArgumentException(__('Invalid arguments array received.')); } // define the available user functions $funcs = array('main', 'view', 'display', 'edit'); // return if function url scheme is not being customised $customFuncs = array('view', 'display'); // set the correct function name based on our input if (empty($args['vars'][2])) { // no func and no vars = main System::queryStringSetVar('func', 'main'); return true; } else { if (in_array($args['vars'][2], $funcs) && !in_array($args['vars'][2], $customFuncs)) { // normal url scheme, no need for special decoding return false; } } $func = $args['vars'][2]; // usually the language is in $args['vars'][0], except no mod name is in the url and we are set as start app $modInfo = ModUtil::getInfoFromName('Reviews'); $lang = strtolower($args['vars'][0]) == $modInfo['url'] ? $args['vars'][1] : $args['vars'][0]; // remove some unrequired parameters foreach ($_GET as $k => $v) { if (in_array($k, array('module', 'type', 'func', 'lang', 'ot', 'prop', 'cat')) === false) { unset($_GET[$k]); } } // process all args except language and module $urlVars = array_slice($args['vars'], 2); // all except [0] and [1] // get arguments as string $url = implode('/', $urlVars); // check if default view urls end with a trailing slash if ($func == 'view' && strpos($url, '.') === false && substr($url, -1) != '/') { // add missing trailing slash $url .= '/'; } $isDefaultModule = System::getVar('shorturlsdefaultmodule', '') == $modInfo['name']; if (!$isDefaultModule) { $url = $modInfo['url'] . '/' . $url; } // initialise url routing rules $routerFacade = new Reviews_RouterFacade(); // get router itself for convenience $router = $routerFacade->getRouter(); // read params out of url $parameters = $router->parse($url); //var_dump($parameters); if (!$parameters || !is_array($parameters)) { return false; } // post processing if (!isset($parameters['func'])) { $parameters['func'] = 'view'; } $func = $parameters['func']; // convert group folder to object type $parameters['ot'] = $routerFacade->getObjectTypeFromGroupingFolder($parameters['ot'], $func); // handle special templates $displayDefaultEnding = System::getVar('shorturlsext', ''); $endingPrefix = $func == 'view' ? '.' : ''; if (isset($parameters[$func . 'ending']) && !empty($parameters[$func . 'ending']) && $parameters[$func . 'ending'] != $endingPrefix . $displayDefaultEnding) { if ($func == 'view') { $parameters[$func . 'ending'] = str_replace($endingPrefix, '', $parameters[$func . 'ending']); } $parameters['use' . $parameters[$func . 'ending'] . 'ext'] = '1'; unset($parameters[$func . 'ending']); } // rename id to objid (primary key for display pages, optional filter id for view pages) /* may be obsolete now if (isset($parameters['id'])) { $parameters[strtolower($parameters['ot']) . 'id'] = $parameters['id']; unset($parameters['id']); }*/ // write vars to GET foreach ($parameters as $k => $v) { System::queryStringSetVar($k, $v); } return true; }
/** * view a page * * @param int pid Page ID * @param string name URL name, alternative for pid * @param bool preview Display preview * @param bool editmode Flag for enabling/disabling edit mode * * @return Renderer output */ public function view($args) { $pageId = isset($args['pid']) ? $args['pid'] : FormUtil::getPassedValue('pid'); $versionId = isset($args['vid']) ? $args['vid'] : FormUtil::getPassedValue('vid'); $urlname = isset($args['name']) ? $args['name'] : FormUtil::getPassedValue('name'); $preview = isset($args['preview']) ? $args['preview'] : FormUtil::getPassedValue('preview'); $editmode = isset($args['editmode']) ? $args['editmode'] : FormUtil::getPassedValue('editmode', null, 'GET'); if ($pageId === null && !empty($urlname)) { $pageId = ModUtil::apiFunc('Content', 'Page', 'solveURLPath', compact('urlname')); System::queryStringSetVar('pid', $pageId); } if ((bool) $this->getVar('inheritPermissions', false) === true) { $this->throwForbiddenUnless(ModUtil::apiFunc('Content', 'page', 'checkPermissionForPageInheritance', array('pageId' => $pageId, 'level' => ACCESS_READ)), LogUtil::getErrorMsgPermission()); } else { $this->throwForbiddenUnless(SecurityUtil::checkPermission('Content:page:', $pageId . '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); } $versionHtml = ''; $hasEditAccess = false; if ((bool) $this->getVar('inheritPermissions', false) === true) { $hasEditAccess = ModUtil::apiFunc('Content', 'page', 'checkPermissionForPageInheritance', array('pageId' => $pageId, 'level' => ACCESS_EDIT)); } else { $hasEditAccess = SecurityUtil::checkPermission('Content:page:', $pageId . '::', ACCESS_EDIT); } if ($versionId !== null && $hasEditAccess) { $preview = true; $version = ModUtil::apiFunc('Content', 'History', 'getPageVersion', array('id' => $versionId, 'preview' => $preview, 'includeContent' => true)); $versionData =& $version['data']; $page =& $versionData['page']; $pageId = $page['id']; $action = ModUtil::apiFunc('Content', 'History', 'contentHistoryActionTranslate', $version['action']); $translatable = array('revisionNo' => $version['revisionNo'], 'date' => $version['date'], 'action' => $action, 'userName' => $version['userName'], 'ipno' => $version['ipno']); $iconSrc = 'images/icons/extrasmall/clock.png'; $versionHtml = "<p class=\"content-versionpreview\"><img alt=\"\" src=\"{$iconSrc}\"/> " . $this->__f('Version #%1$s - %2$s - %3$s by %4$s from %5$s', $translatable) . "</p>"; } // now get the page up for display if ($pageId !== null && $versionId === null) { $page = ModUtil::apiFunc('Content', 'Page', 'getPage', array('id' => $pageId, 'preview' => $preview, 'includeContent' => true, 'filter' => array('checkActive' => !($preview && $hasEditAccess)))); } else { if ($versionId === null) { return LogUtil::registerArgsError(); } } if ($page === false) { return false; } if ($editmode !== null) { SessionUtil::setVar('ContentEditMode', $editmode); } else { $editmode = SessionUtil::getVar('ContentEditMode', null); } if ($editmode) { $this->view->setCaching(false); } $this->view->setCacheId("{$pageId}|{$versionId}"); if ($this->view->is_cached('user/page.tpl')) { return $this->view->fetch('user/page.tpl'); } // Register a page variable breadcrumbs with the Content page hierarchy as array of array(url, title) if ((bool) $this->getVar('registerBreadcrumbs', false) === true) { // first include self, then loop over parents until root is reached $breadcrumbs[] = array('url' => ModUtil::url('Content', 'user', 'view', array('pid' => $page['id'])), 'title' => $page['title']); $loopPageid = $page['parentPageId']; while ($loopPageid > 0) { $loopPage = ModUtil::apiFunc('Content', 'Page', 'getPage', array('id' => $loopPageid, 'includeContent' => false, 'includeLayout' => false, 'translate' => $this->translateTitles)); array_unshift($breadcrumbs, array('url' => ModUtil::url('Content', 'user', 'view', array('pid' => $loopPage['id'])), 'title' => $loopPage['title'])); $loopPageid = $loopPage['parentPageId']; } PageUtil::registerVar('breadcrumbs', false, $breadcrumbs); } $multilingual = ModUtil::getVar(ModUtil::CONFIG_MODULE, 'multilingual'); if ($page['language'] == ZLanguage::getLanguageCode()) { $multilingual = false; } // override the PageVar title if configued in the settings if ($this->getVar('overrideTitle')) { $pageTitle = html_entity_decode($page['title']); PageUtil::setVar('title', $preview ? $this->__("Preview") . ' - ' . $pageTitle : $pageTitle); } $this->view->assign('page', $page); $this->view->assign('preview', $preview); $this->view->assign('editmode', $editmode); $this->view->assign('multilingual', $multilingual); $this->view->assign('enableVersioning', $this->getVar('enableVersioning')); // add layout type and column count as page variables to the template // columncount can be used via plugin contentcolumncount, since it holds regular expressions that slow down $this->view->assign('contentLayoutType', $page['layout']); // add access parameters Content_Util::contentAddAccess($this->view, $pageId); // exclude writers from statistics if (!$hasEditAccess && !$preview && !$editmode && $this->getVar('countViews')) { // Check against session to see if user was already counted if (!SessionUtil::getVar("ContentRead" . $pageId)) { SessionUtil::setVar("ContentRead" . $pageId, $pageId); DBUtil::incrementObjectFieldByID('content_page', 'views', $pageId); } } return $versionHtml . $this->view->fetch('user/page.tpl'); }
/** * display article as pdf * * @author Erik Spaan * @param 'sid' The article ID * @param 'objectid' generic object id maps to sid if present * @return string HTML string */ public function displaypdf($args) { // Get parameters from whatever input we need $sid = (int)FormUtil::getPassedValue('sid', null, 'REQUEST'); $objectid = (int)FormUtil::getPassedValue('objectid', null, 'REQUEST'); $title = FormUtil::getPassedValue('title', null, 'REQUEST'); $year = FormUtil::getPassedValue('year', null, 'REQUEST'); $monthnum = FormUtil::getPassedValue('monthnum', null, 'REQUEST'); $monthname = FormUtil::getPassedValue('monthname', null, 'REQUEST'); $day = FormUtil::getPassedValue('day', null, 'REQUEST'); // User functions of this type can be called by other modules extract($args); // At this stage we check to see if we have been passed $objectid, the // generic item identifier if ($objectid) { $sid = $objectid; } // Validate the essential parameters if ((empty($sid) || !is_numeric($sid)) && (empty($title))) { return LogUtil::registerArgsError(); } if (!empty($title)) { unset($sid); } // we set TEMPLATE caching to false because we will utilize // FILE caching of pdf files instead $this->view->setCaching(false); // Get the news story if (isset($sid)) { $item = ModUtil::apiFunc('News', 'user', 'get', array('sid' => $sid, 'status' => 0)); } else { $item = ModUtil::apiFunc('News', 'user', 'get', array('title' => $title, 'year' => $year, 'monthname' => $monthname, 'monthnum' => $monthnum, 'day' => $day, 'status' => 0)); $sid = $item['sid']; System::queryStringSetVar('sid', $sid); } if ($item === false) { return LogUtil::registerError($this->__('Error! No such article found.'), 404); } // check for cached pdf file if ($this->getVar('pdflink_enablecache', true)) { $cachedPdf = $this->pdfIsCached($item['urltitle']); if ($cachedPdf) { $this->outputCachedPdf($cachedPdf); return true; } } // $info is array holding raw information. $info = ModUtil::apiFunc('News', 'user', 'getArticleInfo', $item); // $links is an array holding pure URLs to specific functions for this article. $links = ModUtil::apiFunc('News', 'user', 'getArticleLinks', $info); // $preformat is an array holding chunks of preformatted text for this article. $preformat = ModUtil::apiFunc('News', 'user', 'getArticlePreformat', array('info' => $info, 'links' => $links)); // Assign the story info arrays $this->view->assign(array('info' => $info, 'links' => $links, 'preformat' => $preformat)); // Store output in variable $articlehtml = $this->view->fetch('user/articlepdf.tpl'); // Include and configure the TCPDF class define('K_TCPDF_EXTERNAL_CONFIG', true); $classfile = DataUtil::formatForOS('modules/News/lib/vendor/tcpdf/tcpdf.php'); include_once $classfile; $lang = ZLanguage::getInstance(); $langcode = $lang->getLanguageCodeLegacy(); $langfile = DataUtil::formatForOS("modules/News/lib/vendor/tcpdf/config/lang/{$langcode}.php"); if (file_exists($langfile)) { include_once $langfile; } else { // default to english include_once DataUtil::formatForOS('modules/News/lib/vendor/tcpdf/config/lang/eng.php'); } $configfile = DataUtil::formatForOS('modules/News/lib/vendor/tcpdf_news_config.php'); require_once $configfile; // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set pdf document information $pdf->SetCreator(System::getVar('sitename')); $pdf->SetAuthor($info['contributor']); $pdf->SetTitle($info['title']); $pdf->SetSubject($info['cattitle']); //$pdf->SetKeywords($info['cattitle']); // set default header data //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); $sitename = System::getVar('sitename'); /* $pdf->SetHeaderData( $modvars['pdflink_headerlogo'], $modvars['pdflink_headerlogo_width'], $this->__f('Article %1$s by %2$s', array($info['title'], $info['contributor'])), $sitename . ' :: ' . $this->__('News publisher')); */ $pdf->SetHeaderData($this->getVar('pdflink_headerlogo'), $this->getVar('pdflink_headerlogo_width'), '', $sitename . ' :: ' . $info['cattitle'] . ' :: ' . $info['topicname']); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // $l is undefined??? TODO // set font, freeserif is big ! //$pdf->SetFont('freeserif', '', 10); // For Unicode data put dejavusans in tcpdf_config.php $pdf->SetFont(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN); // add a page $pdf->AddPage(); // output the HTML content $pdf->writeHTML($articlehtml, true, 0, true, 0); // reset pointer to the last page $pdf->lastPage(); if ($this->getVar('pdflink_enablecache', true)) { $pdfMode = "FI"; $dir = CacheUtil::getLocalDir('NewsPDF'); $pdfFileName = $dir . '/' . $info['urltitle'] . '.pdf'; } else { $pdfMode = "I"; $pdfFileName = $info['urltitle'] . '.pdf'; } //Close and output PDF document $pdf->Output($pdfFileName, $pdfMode); // Since the output doesn't need the theme wrapped around it, // let the theme know that the function is already finished return true; }
/** * Decode the custom url string. * * Parameters passed in the $args array: * ------------------------------------- * array vars The array of URL variables to decode; required. * * @param array $args All parameters passed to this function. * * @return bool true if successful, false otherwise */ public function decodeurl($args) { // check we actually have some vars to work with... if (!isset($args['vars'])) { return LogUtil::registerArgsError(); } // let the core handled everything except the view function if (!isset($args['vars'][2]) || empty($args['vars'][2]) || $args['vars'][2] != 'view') { return false; } System::queryStringSetVar('type', 'user'); System::queryStringSetVar('func', 'view'); // identify the correct parameter to identify the user if (isset($args['vars'][3])) { if (is_numeric($args['vars'][3])) { System::queryStringSetVar('uid', $args['vars'][3]); } else { System::queryStringSetVar('uname', $args['vars'][3]); } } if (isset($args['vars'][4])) { System::queryStringSetVar('page', $args['vars'][4]); } return true; }
/** * Parse a given url and return the params read out of it. * * @param string $url Input url. * * @return mixed array Eith determined params or false on error. */ public function matchesUrl($url) { // compile the regex if not already done if (!$this->compiled) { $this->compile(); } // check if the regex of this route instance does fit to given url if (!preg_match($this->regex, $url, $matches)) { return false; } // initialise list of parameters to be collected $parameters = array(); // check for * in urlPattern if (isset($matches['_star'])) { // process additional parameters $additionalArgs = explode('/', $matches['_star']); $tmp = $additionalArgs; for ($i = 0, $max = count($additionalArgs); $i < $max; $i += 2) { if (!empty($tmp[$i])) { $parameters[$tmp[$i]] = isset($tmp[$i + 1]) ? $tmp[$i + 1] : true; System::queryStringSetVar($tmp[$i], $parameters[$tmp[$i]]); } } // unset this match to exclude it in further processing unset($matches['_star']); } // add default values for all parameters $parameters = array_merge($parameters, $this->defaults); // process all matches and add according variables foreach ($matches as $key => $value) { if (!is_int($key)) { $parameters[$key] = $value; } } return $parameters; }
/** * This is a custom method. * * @Route("/%zikularoutesmodule.routing.route.plural%/reload/{stage}/{module}", * name = "zikularoutesmodule_route_reload", * methods = {"GET", "POST"} * ) * * @param Request $request Current request instance * @param int $stage * @param null $module * * @return mixed Output. * * @throws AccessDeniedException Thrown if the user doesn't have required permissions. * * This method has three stages: * 1. Showing the dropdown with all the bundles to the user. * 2. Clearing the annotation cache. * 3. Reloading routes. */ public function reloadAction(Request $request, $stage = 0, $module = null) { $objectType = 'route'; if (!SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', '::', ACCESS_ADMIN)) { throw new AccessDeniedException(); } $cacheClearer = $this->get('zikula.cache_clearer'); $controllerHelper = $this->get('zikularoutesmodule.controller_helper'); if ($stage == 0) { $legacyControllerType = 'admin'; \System::queryStringSetVar('type', $legacyControllerType); $request->query->set('type', $legacyControllerType); $viewHelper = $this->serviceManager->get('zikularoutesmodule.view_helper'); $templateFile = $viewHelper->getViewTemplate($this->view, $objectType, 'reload', $request); $this->view->setCacheId($objectType . '|reload'); $kernel = $this->get('kernel'); $modules = $kernel->getModules(); $options = array(array('text' => $this->__('All'), 'value' => -1)); foreach ($modules as $module) { $options[] = array('text' => $module->getName(), 'value' => $module->getName()); } $this->view->assign('options', $options); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, $objectType, 'reload', $request, $templateFile); } else { if ($stage == 1) { $cacheClearer->clear('symfony.annotations'); $module = $this->request->request->get('reload-module', "-1"); $redirectUrl = $this->serviceManager->get('router')->generate('zikularoutesmodule_route_reload', array('stage' => 2, 'module' => $module, 'lct' => 'admin'), UrlGeneratorInterface::ABSOLUTE_URL); return new RedirectResponse($redirectUrl); } } /** @var \Zikula\RoutesModule\Entity\Repository\Route $routeRepository */ $routeRepository = $this->entityManager->getRepository('ZikulaRoutesModule:RouteEntity'); if ($module == "-1") { $routeRepository->reloadAllRoutes($this->getContainer()); $request->getSession()->getFlashBag()->add('status', $this->__('Done! All routes reloaded.')); $hadRoutes = false; } else { $hadRoutes = $controllerHelper->reloadRoutesByModule($module); $request->getSession()->getFlashBag()->add('status', $this->__f('Done! Routes reloaded for %s.', '<strong>' . $module . '</strong>')); } $cacheClearer->clear("symfony.routing"); $this->view->clear_cache(); // reload **all** JS routes $result = $controllerHelper->dumpJsRoutes(); if ($result == '') { $request->getSession()->getFlashBag()->add('status', $this->__f('Done! Exposed JS Routes dumped to %s.', 'web/js/fos_js_routes.js')); } else { $request->getSession()->getFlashBag()->add('error', $this->__f('Error! There was an error dumping exposed JS Routes: %s', $result)); } $redirectUrl = $this->serviceManager->get('router')->generate('zikularoutesmodule_route_view', array('lct' => 'admin'), UrlGeneratorInterface::ABSOLUTE_URL); if ($hadRoutes) { // no need to pass through to nakedmessage if module previously had routes loaded. return new RedirectResponse($redirectUrl); } else { $this->view->assign('delay', 2); $this->view->assign('url', $redirectUrl); $response = new PlainResponse($this->view->fetch('Admin/nakedmessage.tpl')); return $response; } }
/** * This method provides a handling of simple delete requests. * * @param int $id Identifier of entity to be shown. * @param boolean $confirmation Confirm the deletion, else a confirmation page is displayed. * @param string $tpl Name of alternative template (to be used instead of the default template). * @param boolean $raw Optional way to display a template instead of fetching it (required for standalone output). * * @return mixed Output. */ public function delete() { $legacyControllerType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING); System::queryStringSetVar('type', $legacyControllerType); $this->request->query->set('type', $legacyControllerType); $controllerHelper = new MUVideo_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = 'movie'; $utilArgs = array('controller' => 'movie', 'action' => 'delete'); $permLevel = $legacyControllerType == 'admin' ? ACCESS_ADMIN : ACCESS_DELETE; $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission()); $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType)); // retrieve identifier of the object we wish to delete $idValues = $controllerHelper->retrieveIdentifier($this->request, array(), $objectType, $idFields); $hasIdentifier = $controllerHelper->isValidIdentifier($idValues); $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.')); $selectionArgs = array('ot' => $objectType, 'id' => $idValues); $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', $selectionArgs); $this->throwNotFoundUnless($entity != null, $this->__('No such item.')); $entity->initWorkflow(); // determine available workflow actions $workflowHelper = new MUVideo_Util_Workflow($this->serviceManager); $actions = $workflowHelper->getActionsForObject($entity); if ($actions === false || !is_array($actions)) { return LogUtil::registerError($this->__('Error! Could not determine workflow actions.')); } // check whether deletion is allowed $deleteActionId = 'delete'; $deleteAllowed = false; foreach ($actions as $actionId => $action) { if ($actionId != $deleteActionId) { continue; } $deleteAllowed = true; break; } if (!$deleteAllowed) { return LogUtil::registerError($this->__('Error! It is not allowed to delete this movie.')); } $confirmation = (bool) $this->request->request->filter('confirmation', false, FILTER_VALIDATE_BOOLEAN); if ($confirmation && $deleteAllowed) { $this->checkCsrfToken(); $hookAreaPrefix = $entity->getHookAreaPrefix(); $hookType = 'validate_delete'; // Let any hooks perform additional validation actions $hook = new Zikula_ValidationHook($hookAreaPrefix . '.' . $hookType, new Zikula_Hook_ValidationProviders()); $validators = $this->notifyHooks($hook)->getValidators(); if (!$validators->hasErrors()) { // execute the workflow action $success = $workflowHelper->executeAction($entity, $deleteActionId); if ($success) { $this->registerStatus($this->__('Done! Item deleted.')); } // Let any hooks know that we have created, updated or deleted the movie $hookType = 'process_delete'; $hook = new Zikula_ProcessHook($hookAreaPrefix . '.' . $hookType, $entity->createCompositeIdentifier()); $this->notifyHooks($hook); // The movie was deleted, so we clear all cached pages this item. $cacheArgs = array('ot' => $objectType, 'item' => $entity); ModUtil::apiFunc($this->name, 'cache', 'clearItemCache', $cacheArgs); if ($legacyControllerType == 'admin') { // redirect to the list of movies $redirectUrl = ModUtil::url($this->name, 'movie', 'view', array('lct' => $legacyControllerType)); } else { // redirect to the list of movies $redirectUrl = ModUtil::url($this->name, 'movie', 'view', array('lct' => $legacyControllerType)); } return $this->redirect($redirectUrl); } } $entityClass = $this->name . '_Entity_' . ucfirst($objectType); $repository = $this->entityManager->getRepository($entityClass); // set caching id $this->view->setCaching(Zikula_View::CACHE_DISABLED); // assign the object we loaded above $this->view->assign($objectType, $entity)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs)); // fetch and return the appropriate template $viewHelper = new MUVideo_Util_View($this->serviceManager); return $viewHelper->processTemplate($this->view, $objectType, 'delete', array()); }
/** * decode custom url string * * @author Philipp Niethammer * @return bool true if succeded false otherwise */ public function decodeurl($args) { $suffix = $this->getVar('shorturlsuffix'); $supportedfunctions = array('main', 'list', 'view', 'subpages', 'sitemap', 'extlist', 'categoriesList', 'pagelist'); $argsnum = count($args['vars']); if (!isset($args['vars'][2]) || empty($args['vars'][2])) { System::queryStringSetVar('func', 'sitemap'); return true; } if (in_array($args['vars'][2], $supportedfunctions)) { return false; } $lastarg = end($args['vars']); $urlname = ''; if (substr($lastarg, strlen($lastarg) - strlen($suffix)) == $suffix) { for ($i = 2; $i < $argsnum; $i++) { if (!empty($urlname)) { $urlname .= '/'; } $urlname .= $args['vars'][$i]; } if (($suffixLen = strlen($suffix)) > 0) { $urlname = substr($urlname, 0, -$suffixLen); } System::queryStringSetVar('func', 'view'); System::queryStringSetVar('name', $urlname); return true; } if (!isset($args['vars'][3]) || empty($args['vars'][3])) { $mainCategory = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $this->getVar('categoryPropPrimary'), 30); // 30 == /__SYSTEM__/Modules/Global //$cats = CategoryUtil::getCategoriesByParentID($mainCategory); $cats = CategoryUtil::getSubCategories($mainCategory); foreach ($cats as $cat) { if ($args['vars'][2] == $cat['name'] || $args['vars'][2] == DataUtil::formatForURL($cat['name'])) { System::queryStringSetVar('func', 'listpages'); System::queryStringSetVar('cat', $cat['id']); return true; } } } for ($i = 2; $i < $argsnum; $i++) { if (!empty($urlname)) { $urlname .= '/'; } $urlname .= $args['vars'][$i]; } System::queryStringSetVar('func', 'subpages'); System::queryStringSetVar('name', $urlname); return true; }
/** * decode a short url */ public function decodeurl($args) { // check we actually have some vars to work with... if (!isset($args['vars'])) { return LogUtil::registerArgsError(); } // define the available user functions $funcs = array('main', 'newitem', 'create', 'view', 'archives', 'display', 'categorylist', 'displaypdf'); // set the correct function name based on our input if (empty($args['vars'][2])) { System::queryStringSetVar('func', 'view'); $nextvar = 3; } elseif ($args['vars'][2] == 'page') { System::queryStringSetVar('func', 'view'); $nextvar = 3; } elseif (!in_array($args['vars'][2], $funcs)) { System::queryStringSetVar('func', 'display'); $nextvar = 2; } else { System::queryStringSetVar('func', $args['vars'][2]); $nextvar = 3; } System::queryStringSetVar('type', 'user'); $func = FormUtil::getPassedValue('func', 'view', 'GET'); // for now let the core handle the view function if (($func == 'view' || $func == 'main') && isset($args['vars'][$nextvar])) { System::queryStringSetVar('page', (int)$args['vars'][$nextvar]); } // add the category info if ($func == 'view' && isset($args['vars'][$nextvar])) { if ($args['vars'][$nextvar] == 'page') { System::queryStringSetVar('page', (int)$args['vars'][$nextvar+1]); } else { System::queryStringSetVar('prop', $args['vars'][$nextvar]); if (isset($args['vars'][$nextvar+1])) { $numargs = count($args['vars']); if ($args['vars'][$numargs-2] == 'page' && is_numeric($args['vars'][$numargs-1])) { System::queryStringSetVar('cat', (string)implode('/', array_slice($args['vars'], $nextvar+1, -2))); System::queryStringSetVar('page', (int)$args['vars'][$numargs-1]); } else { System::queryStringSetVar('cat', (string)implode('/', array_slice($args['vars'], $nextvar+1))); System::queryStringSetVar('page', 1); } } } } // identify the correct parameter to identify the news article if ($func == 'display' || $func == 'displaypdf') { // check the permalink structure and obtain any missing vars $permalinkkeys = array_flip(explode('/', $this->getVar('permalinkformat'))); // get rid of unused vars $args['vars'] = array_slice($args['vars'], $nextvar); // remove any category path down to the leaf category $permalinkkeycount = count($permalinkkeys); $varscount = count($args['vars']); ($args['vars'][$varscount-2] == 'page') ? $pagersize = 2 : $pagersize = 0 ; if (($permalinkkeycount + $pagersize) != $varscount) { array_splice($args['vars'], $permalinkkeys['%category%'], $varscount - $permalinkkeycount); } // get the story id or title foreach ($permalinkkeys as $permalinkvar => $permalinkkey) { System::queryStringSetVar(str_replace('%', '', $permalinkvar), $args['vars'][$permalinkkey]); } if (isset($permalinkkeys['%articleid%']) && isset($args['vars'][$permalinkkeys['%articleid%']]) && is_numeric($args['vars'][$permalinkkeys['%articleid%']])) { System::queryStringSetVar('sid', $args['vars'][$permalinkkeys['%articleid%']]); $nextvar = $permalinkkeys['%articleid%']+1; } else { System::queryStringSetVar('title', $args['vars'][$permalinkkeys['%articletitle%']]); $nextvar = $permalinkkeys['%articletitle%']+1; } if (isset($args['vars'][$nextvar]) && $args['vars'][$nextvar] == 'page') { System::queryStringSetVar('page', (int)$args['vars'][$nextvar+1]); } } // handle news archives if ($func == 'archives') { if (isset($args['vars'][$nextvar])) { System::queryStringSetVar('year', $args['vars'][$nextvar]); if (isset($args['vars'][$nextvar+1])) { System::queryStringSetVar('month', $args['vars'][$nextvar+1]); } } } return true; }
/** * 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); }
/** * add a variable/value pair into the query string * (really the _GET superglobal * This API also adds the variable to the _REQUEST superglobal for consistentcy * * @deprecated Deprecated since version 1.3.0. * @see System::queryStringSetVar() * * @return bool true if successful, false otherwise */ function pnQueryStringSetVar($name, $value) { LogUtil::log(__f('Warning! Function %1$s is deprecated. Please use %2$s instead.', array(__FUNCTION__, 'System::queryStringSetVar')), E_USER_DEPRECATED); return System::queryStringSetVar($name, $value); }