public function search(){ // Check permission $this->throwForbiddenUnless(SecurityUtil::checkPermission('Llicencies::', '::', ACCESS_READ)); //path to zk jquery lib $js = new JCSSUtil; $scripts = $js->scriptsMap(); $jquery = $scripts['jquery']['path']; // Omplim les llistes desplegables del fromulari $cursos = ModUtil::apiFunc('Llicencies', 'user', 'getYears'); $temes = ModUtil::apiFunc('Llicencies', 'user', 'getTopicList'); $subtemes = ModUtil::apiFunc('Llicencies', 'user', 'getSubtopicList'); $tipus = ModUtil::apiFunc('Llicencies', 'user', 'getTypeList'); $view = Zikula_View::getInstance($this->name); $view->assign('jquery' , $jquery); $view->assign('cursos' , $cursos); $view->assign('temes' , $temes); $view->assign('subtemes', $subtemes); $view->assign('tipus' , $tipus); $view->assign('admin' , false); // Carreagr el formulari per a fer la cerca de llicències d'estudi return $this->view->display('Llicencies_main.tpl'); }
/** * Inject header assets into the head of the raw source of a page (before </head>) * Inject footer assets into the foot of the raw source of a page (before </body>) * * @param string $source * @param array $js * @param array $css * @return string */ public function filter($source, $js = array(), $css = array()) { if (!empty($css)) { $this->cssResolver->getBag()->add($css); } if (!empty($js)) { $this->jsResolver->getBag()->add($js); } // compile and replace head $header = $this->cssResolver->compile(); $header .= \JCSSUtil::getJSConfig(); // must be included before other scripts because it defines `Zikula` JS namespace $header .= $this->scriptPosition == 'head' ? $this->jsResolver->compile() : ''; $header .= implode("\n", $this->headers->all()) . "\n"; $header .= trim(implode("\n", \PageUtil::getVar('header')) . "\n"); // @todo legacy - remove at Core-2.0 if (strripos($source, '</head>')) { $source = str_replace('</head>', $header . "\n</head>", $source); } // compile and replace foot $footer = $this->scriptPosition == 'foot' ? $this->jsResolver->compile() : ''; $footer .= trim(implode("\n", $this->footers->all()) . "\n"); $footer .= trim(implode("\n", \PageUtil::getVar('footer')) . "\n"); // @todo legacy - remove at Core-2.0 if (false === empty($footer)) { $source = str_replace('</body>', $footer . "\n</body>", $source); } return $source; }
/** * This method cares for a redirect within an inline frame. */ public function handleInlineRedirect() { $itemId = (int) $this->request->getGet()->filter('id', 0, FILTER_VALIDATE_INT); $idPrefix = $this->request->getGet()->filter('idp', '', FILTER_SANITIZE_STRING); $commandName = $this->request->getGet()->filter('com', '', FILTER_SANITIZE_STRING); if (empty($idPrefix)) { return false; } $this->view->assign('itemId', $itemId)->assign('idPrefix', $idPrefix)->assign('commandName', $commandName)->assign('jcssConfig', JCSSUtil::getJSConfig())->display('user/inlineRedirectHandler.tpl'); return true; }
/** * Filter the Response to add page assets and vars and return. * @param Response $response * @return Response */ private function filter(Response $response) { // @todo START legacy block - remove at Core-2.0 $baseUri = \System::getBaseUri(); $jsAssets = []; $javascripts = \JCSSUtil::prepareJavascripts(\PageUtil::getVar('javascript')); $i = 60; $legacyAjaxScripts = 0; foreach ($javascripts as $javascript) { $javascript = !empty($baseUri) && false === strpos($javascript, $baseUri) ? "{$baseUri}/{$javascript}" : "{$javascript}"; $javascript = $javascript[0] == '/' ? $javascript : "/{$javascript}"; // add slash to start if not present. // Add legacy ajax scripts (like prototype/scriptaculous) at the lightest weight (0) and in order from there. // Add others after core default assets (like jQuery) but before pageAddAsset default weight (100) and in order from there. $jsAssets[$javascript] = false !== strpos($javascript, 'javascript/ajax/') ? $legacyAjaxScripts++ : $i++; } $cssAssets = []; $stylesheets = \PageUtil::getVar('stylesheet'); $i = 60; foreach ($stylesheets as $stylesheet) { $stylesheet = $baseUri . '/' . $stylesheet; $cssAssets[$stylesheet] = $i++; // add before pageAddAsset default weight (100) } // @todo END legacy block - remove at Core-2.0 $filteredContent = $this->filterService->filter($response->getContent(), $jsAssets, $cssAssets); $response->setContent($filteredContent); return $response; }
/** * Inserts the common ajax javascript files in page header. * * Insert the common ajax javascript files (prototype, scriptaculous) in the * page header using page vars. <i>All other javascript files have to be added * manually on-demand using the {@link smarty_function_pageaddvar() pageaddvar} plugin.</i> * * Available attributes: * - modname (string) the module name in which to look for the base javascript file for the module; defaults to top level module when used in a block template. * - filename (string) (optional) filename to load (default ajax.js) * - noscriptaculous (mixed) (optional) does not include scriptaculous.js if set * - validation (mixed) (optional) includes validation.js if set * - lightbox (mixed) (optional) includes lightbox.js if set (loads scriptaculous effects if noscriptaculous is set) * - imageviewer (mixed) (optional) includes Zikula.ImageViewer.js if set (loads scriptaculous effects and dragdrop if noscriptaculous is set) * - assign (string) (optional) the name of the template variable to which the script tag string is assigned, <i>instead of</i> * adding them to the page variables through PageUtil::addVar * * * Examples: * * <samp>{ajaxheader modname='Example' filename='example.js'}</samp> * * <samp>{ajaxheader modname='Example' noscriptaculous=1}</samp> * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * * @return void */ function smarty_function_ajaxheader($params, Zikula_View $view) { // use supplied modname or top level module $modname = (isset($params['modname'])) ? $params['modname'] : ModUtil::getName(); // define the default filename $filename = (isset($params['filename'])) ? $params['filename'] : 'Zikula.js'; $validation = (isset($params['validation'])) ? true : false; $lightbox = (isset($params['lightbox'])) ? true : false; $ui = (isset($params['ui'])) ? true : false; $imageviewer = (isset($params['imageviewer'])) ? true : false; // create an empty return $return = ''; // we always need those $scripts = array('prototype', 'zikula'); if ($validation) { $scripts[] = 'validation'; } if ($ui) { $scripts[] = 'livepipe'; $scripts[] = 'zikula.ui'; } if ($lightbox) { // check if lightbox is present - if not, load ImageViewer instead if (is_readable('javascript/ajax/lightbox.js')) { $scripts[] = 'javascript/ajax/lightbox.js'; if (isset($params['assign'])) { $return = '<link rel="stylesheet" href="javascript/ajax/lightbox/lightbox.css" type="text/css" media="screen" />'; } else { PageUtil::addVar('stylesheet', 'javascript/ajax/lightbox/lightbox.css'); } } else { $imageviewer = true; } } if ($imageviewer) { $scripts[] = 'zikula.imageviewer'; if (isset($params['assign'])) { $return = '<link rel="stylesheet" href="javascript/helpers/ImageViewer/ImageViewer.css" type="text/css" media="screen" />'; } } $modinfo = ModUtil::getInfoFromName($modname); if ($modinfo !== false) { $osdirectory = DataUtil::formatForOS($modinfo['directory']); $osfilename = DataUtil::formatForOS($filename); $base = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules'; if (file_exists($file = "$base/$osdirectory/javascript/$osfilename") || file_exists($file = "$base/$osdirectory/pnjavascript/$osfilename")) { $scripts[] = DataUtil::formatForDisplay($file); } } if (isset($params['assign'])) { // create script tags now $scripts = JCSSUtil::prepareJavascripts($scripts); foreach ($scripts as $script) { $return .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n"; } $view->assign($params['assign'], $return); } else { PageUtil::addVar('javascript', $scripts); } return; }
/** * List the files in server folder * @author: Albert Pérez Monfort * @param: args the folder name where to list the files and subfolders * @return: The list of files and folders */ public function getFiles($args) { $hook = FormUtil::getPassedValue('hook', isset($args['hook']) ? $args['hook'] : 0, 'GET'); $editor = FormUtil::getPassedValue('editor', isset($args['editor']) ? $args['editor'] : false, 'GET'); PageUtil::AddVar('javascript', 'modules/Files/javascript/getFiles.js'); // get arguments $root = FormUtil::getPassedValue('root', isset($args['root']) ? $args['root'] : null, 'REQUEST'); $lastFolder = isset($_SESSION['filesModuleLastFolder']) ? $_SESSION['filesModuleLastFolder'] : null; $folder = FormUtil::getPassedValue('folder', isset($args['folder']) ? $args['folder'] : null, 'REQUEST'); $folder = (is_null($folder) && !is_null($lastFolder) && is_null($root)) ? $lastFolder : $folder; $_SESSION['filesModuleLastFolder'] = $folder; $folder = str_replace("|", "/", $folder); // security check if (!SecurityUtil::checkPermission( 'Files::', '::', ACCESS_ADD) || !UserUtil::isLoggedIn()) { $errorMsg = $this->__('Sorry! You have not been granted access to this page.'); $this->view->assign('errorMsg', $errorMsg); $this->view->assign('external', 1); $this->view->display('Files_user_errorMsg.tpl'); exit; } $oFolder = $folder; // gets root folder for the user $check = ModUtil::func('Files', 'user', 'checkingModule'); if ($check['status'] != 'ok') { $this->view->assign('check', $check); return $this->view->fetch('Files_user_failedConf.tpl'); } $initFolderPath = $check['initFolderPath']; // check if the root folder exists if(!file_exists($initFolderPath)){ $errorMsg = $this->__('The server directory does not exist. Contact with the website administrator to solve this problem.'); $this->view->assign('errorMsg', $errorMsg); $this->view->assign('external', 1); $this->view->display('Files_user_errorMsg.tpl'); exit; } // protection. User can not navigate out their root folder if($folder == ".." || $folder == "."){ $errorMsg = $this->__('Invalid folder') . ': ' . $folder; $this->view->assign('errorMsg', $errorMsg); $this->view->assign('external', 1); $this->view->display('Files_user_errorMsg.tpl'); exit; } // get folder name $folderName = str_replace($initFolderPath . '/' , '', $folder); $folder = $initFolderPath . '/' . $folder; // users can not browser the thumbnails folders if(strpos($folder, '.tbn') !== false) { LogUtil::registerError($this->__('It is not possible to browse this folder')); return System::redirect(ModUtil::url('Files', 'external', 'getFiles', array('folder' => substr($folderName, 0, strrpos($folderName, '/'))))); } // needed arguments // check if the folder exists if(!file_exists($folder)){ $errorMsg = $this->__('Invalid folder').': '.$folderName; $this->view->assign('errorMsg', $errorMsg); $this->view->assign('external', 1); $this->view->display('Files_user_errorMsg.tpl'); exit; } // get user's disk use $userDiskUse = ModUtil::apiFunc('Files', 'user', 'get'); $usedSpace = $userDiskUse['diskUse']; // get user's allowed space $userAllowedSpace = ModUtil::func('Files', 'user', 'getUserQuota'); $maxDiskSpace = round($userAllowedSpace * 1024 * 1024); $percentage = round($usedSpace * 100 / $maxDiskSpace); $widthUsage = ($percentage > 100) ? 100 : $percentage; $usedSpaceArray = array('maxDiskSpace' => ModUtil::func('Files', 'user', 'diskUseFormat', array('value' => $maxDiskSpace)), 'percentage' => $percentage, 'usedDiskSpace' => ModUtil::func('Files', 'user', 'diskUseFormat', array('value' => $usedSpace)), 'widthUsage' => $widthUsage); // create output object $this->view = Zikula_View::getInstance('Files', false); // get folder files and subfolders $fileList = ModUtil::func('Files', 'user', 'dir_list', array('folder' => $folder, 'external' => 1, 'hook' => $hook, 'editor' => $editor)); sort($fileList['dir']); sort($fileList['file']); $notwriteable = (!is_writable($folder)) ? true : false; // check if it is a public directori $is_public = (!file_exists($folder.'/.locked')) ? true : false ; $this->view->assign('publicFolder', $is_public); $this->view->assign('folderPrev', substr($folderName, 0 , strrpos($folderName, '/'))); $folderPath = (SecurityUtil::checkPermission( 'Files::', '::', ACCESS_ADMIN)) ? $folderName : ModUtil::getVar('Files', 'usersFolder') . '/' . strtolower(substr(UserUtil::getVar('uname'), 0 , 1)) . '/' . UserUtil::getVar('uname') . '/' .$folderName; $imagesArray = array(); // get folder files and subfolders if(file_exists($folder . '/.tbn')) { $images = ModUtil::func('Files', 'user', 'dir_list', array('folder' => $folder . '/.tbn', 'external' => 1)); foreach($images['file'] as $file) { $fileExtension = FileUtil::getExtension($file['name']); if(in_array(strtolower($fileExtension), array('gif','png','jpg','jpeg'))) { list($width, $height) = getimagesize($folder . '/' . $file['name']); list($newWidth, $newHeight) = getimagesize($folder . '/.tbn/' . $file['name']); $factor = round($width/$newWidth,2); $imagesArray[] = array('name' => $file['name'], 'viewWidth' => $newWidth, 'width' => $width, 'viewHeight' => $newHeight, 'height' => $height, 'factor' => $factor); } } } $scribite_v4 = ModUtil::getVar('Files', 'scribite_v4'); $this->view->assign('scribite_v4', $scribite_v4); $scribite_v5 = ModUtil::getVar('Files', 'scribite_v5'); $this->view->assign('scribite_v5', $scribite_v5); $scribite_v4_name = ModUtil::getVar('Files', 'scribite_v4_name'); $this->view->assign('scribite_v4_name', $scribite_v4_name); $scribite_v5_name = ModUtil::getVar('Files', 'scribite_v5_name'); $this->view->assign('scribite_v5_name', $scribite_v5_name); $defaultPublic = ModUtil::getVar('Files', 'defaultPublic'); $this->view->assign('defaultPublic', $defaultPublic); $this->view->assign('editor', $editor); $this->view->assign('folderPath', DataUtil::formatForDisplay($folderPath)); $this->view->assign('folderName', DataUtil::formatForDisplay($folderName)); $this->view->assign('fileList', $fileList); $this->view->assign('hook', $hook); $this->view->assign('imagesArray', DataUtil::formatForDisplay($imagesArray)); $this->view->assign('usedSpace', $usedSpaceArray); $this->view->assign('notwriteable', $notwriteable); //path to zk jquery lib $js =new JCSSUtil; $scripts = $js->scriptsMap(); $jquery = $scripts['jquery']['path']; $this->view->assign('jquery',$jquery); return $this->view->display('Files_external_getFiles.tpl'); }
/** * Zikula_View outputfilter to add page variables and additional header global into page header * * By default this output filter places page variable output immediately prior to the closing * head tag (</head>). The output can, optionally, be placed anywhere in the template by adding * the HTML comment <!-- pagevars --> to the page template. Note that this must always be in * the header for the output to function correctly. * * @param string $source Output source. * @param Zikula_View $view Reference to Zikula_View instance. * * @return string */ function smarty_outputfilter_pagevars($source, $view) { $return = ''; $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme())); $cssjscombine = ModUtil::getVar('ZikulaThemeModule', 'cssjscombine', false); $type = $view->getRequest()->get('type'); $zkType = $view->getRequest()->attributes->get('_zkType'); $isAdminController = $type == 'admin' || $zkType == 'admin'; // get list of stylesheets and scripts from JCSSUtil $jcss = JCSSUtil::prepareJCSS($cssjscombine, $view->cache_dir, $themeinfo, $isAdminController); if (is_array($jcss['stylesheets']) && !empty($jcss['stylesheets'])) { foreach ($jcss['stylesheets'] as $stylesheet) { if (empty($stylesheet)) { continue; } // check if the stylesheets is in the additional_header array if ($themeinfo['xhtml']) { $return .= '<link rel="stylesheet" href="' . DataUtil::formatForDisplay($stylesheet) . '" type="text/css" />' . "\n"; } else { $return .= '<link rel="stylesheet" href="' . DataUtil::formatForDisplay($stylesheet) . '" type="text/css">' . "\n"; } } } // get inline js config and print it just before any script tag $jsConfig = JCSSUtil::getJSConfig(); if (!empty($jsConfig)) { $return .= $jsConfig; } if (is_array($jcss['javascripts']) && !empty($jcss['javascripts'])) { foreach ($jcss['javascripts'] as $j => $javascript) { if (empty($javascript)) { unset($jcss['javascripts'][$j]); continue; } // check if the javascript is in the additional_header array $return .= '<script type="text/javascript" src="' . DataUtil::formatForDisplay($javascript) . '"></script>' . "\n"; } } $headerContent = PageUtil::getVar('header'); if (is_array($headerContent) && !empty($headerContent)) { $return .= implode("\n", $headerContent) . "\n"; } // if we've got some page vars to add the header wrap the output in // suitable identifying comments when in development mode $return = trim($return); if (!empty($return) && System::getVar('development') != 0) { $return = "<!-- zikula pagevars -->\n" . $return . "\n<!-- /zikula pagevars -->"; } // get any body page vars $bodyvars = PageUtil::getVar('body'); if (!empty($bodyvars)) { $bodyattribs = '<body ' . @implode(' ', $bodyvars) . '>'; $source = str_replace('<body>', $bodyattribs, $source); } // get any footer page vars $footervars = PageUtil::getVar('footer'); if (!empty($footervars)) { $footersource = @implode("\n", $footervars) . "\n</body>"; $source = str_replace('</body>', $footersource, $source); } // replace the string in the template source if (stripos($source, '<!-- pagevars -->')) { $source = str_replace('<!-- pagevars -->', $return, $source); } else { $headPos = stripos($source, '</head>'); if ($headPos !== false) { if ($headPos == strripos($source, '</head>')) { // Position of the first </head> matches the last </head> so str_replace is safe $source = str_replace('</head>', $return . "\n</head>", $source); } else { // Position of the first </head> does not match the last </head> so str_replace is NOT safe // There was probably a {zdebug} tag opening a _dbgconsole. // Need to use preg_replace so we can limit to the first. preg_replace('#</head>#i', $return . "\n</head>", $source, 1); } } } // return the modified source return $source; }