示例#1
0
 /**
  * Load a file from the specified location in the file tree
  *
  * @param fileName    The name of the file to load
  * @param path        The path prefix to use (optional) (default=null)
  * @param exitOnError whether or not exit upon error (optional) (default=true)
  * @param returnVar   The variable to return from the sourced file (optional) (default=null)
  *
  * @return string The file which was loaded
  */
 public static function loadFile($fileName, $path = null, $exitOnError = true, $returnVar = null)
 {
     if (!$fileName) {
         return z_exit(__f("Error! Invalid file specification '%s'.", $fileName));
     }
     $file = null;
     if ($path) {
         $file = "{$path}/{$fileName}";
     } else {
         $file = $fileName;
     }
     $file = DataUtil::formatForOS($file);
     if (is_file($file) && is_readable($file)) {
         if (include_once $file) {
             if ($returnVar) {
                 return ${$returnVar};
             } else {
                 return $file;
             }
         }
     }
     if ($exitOnError) {
         return z_exit(__f("Error! Could not load the file '%s'.", $fileName));
     }
     return false;
 }
示例#2
0
文件: User.php 项目: rmaiwald/BBSmile
 /**
  * transform text to images
  * 
  * @param string $args['text']
  */
 function transform($args)
 {
     $text = $args['text'];
     // check the user agent - if it is a bot, return immediately
     $robotslist = array("ia_archiver", "googlebot", "mediapartners-google", "yahoo!", "msnbot", "jeeves", "lycos");
     $useragent = System::serverGetVar('HTTP_USER_AGENT');
     for ($cnt = 0; $cnt < count($robotslist); $cnt++) {
         if (strpos(strtolower($useragent), $robotslist[$cnt]) !== false) {
             return $text;
         }
     }
     $smilies = $this->getVar('smilie_array');
     $remove_inactive = $this->getVar('remove_inactive');
     if (is_array($smilies) && count($smilies) > 0) {
         // sort smilies, see http://code.zikula.org/BBSmile/ticket/1
         uasort($smilies, array($this, 'cmp_smiliesort'));
         $imagepath = System::getBaseUrl() . DataUtil::formatForOS($this->getVar('smiliepath'));
         $imagepath_auto = System::getBaseUrl() . DataUtil::formatForOS($this->getVar('smiliepath_auto'));
         $auto_active = $this->getVar('activate_auto');
         // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
         // This is important!
         $text = ' ' . $text;
         foreach ($smilies as $smilie) {
             // check if smilie is active
             if ($smilie['active'] == 1) {
                 // check if alt is a define
                 $smilie['alt'] = defined($smilie['alt']) ? constant($smilie['alt']) : $smilie['alt'];
                 if ($smilie['type'] == 0) {
                     $text = str_replace($smilie['short'], ' <img src="' . $imagepath . '/' . $smilie['imgsrc'] . '" alt="' . $smilie['alt'] . '" /> ', $text);
                 } else {
                     if ($auto_active == 1) {
                         $text = str_replace($smilie['short'], ' <img src="' . $imagepath_auto . '/' . $smilie['imgsrc'] . '" alt="' . $smilie['alt'] . '" /> ', $text);
                     }
                 }
                 if (!empty($smilie['alias'])) {
                     $aliases = explode(",", trim($smilie['alias']));
                     if (is_array($aliases) && count($aliases) > 0) {
                         foreach ($aliases as $alias) {
                             if ($smilie['type'] == 0) {
                                 $text = str_replace($alias, ' <img src="' . $imagepath . '/' . $smilie['imgsrc'] . '" alt="' . $smilie['alt'] . '" /> ', $text);
                             } else {
                                 if ($auto_active == 1) {
                                     $text = str_replace($alias, ' <img src="' . $imagepath_auto . '/' . $smilie['imgsrc'] . '" alt="' . $smilie['alt'] . '" /> ', $text);
                                 }
                             }
                         }
                     }
                 }
             } else {
                 // End of if smilie is active
                 $text = str_replace($smilie['short'], '', $text);
             }
         }
         // foreach
         // Remove our padding from the string..
         $text = substr($text, 1);
     }
     // End of if smilies is array and not empty
     return $text;
 }
示例#3
0
文件: View.php 项目: rmaiwald/MUBoard
 /**
  * Utility method for managing view templates.
  *
  * @param Zikula_View $view       Reference to view object.
  * @param string      $type       Current type (admin, user, ...).
  * @param string      $objectType Name of treated entity type.
  * @param string      $func       Current function (main, view, ...).
  * @param array       $args       Additional arguments.
  *
  * @return mixed Output.
  */
 public static function processTemplate($view, $type, $objectType, $func, $args = array())
 {
     // create the base template name
     $template = DataUtil::formatForOS($type . '/' . $objectType . '/' . $func);
     // check for template extension
     $templateExtension = self::determineExtension($view, $type, $objectType, $func, $args);
     // check whether a special template is used
     $tpl = isset($args['tpl']) && !empty($args['tpl']) ? $args['tpl'] : FormUtil::getPassedValue('tpl', '', 'GETPOST', FILTER_SANITIZE_STRING);
     if (!empty($tpl) && $view->template_exists($template . '_' . DataUtil::formatForOS($tpl) . '.' . $templateExtension)) {
         $template .= '_' . DataUtil::formatForOS($tpl);
     }
     $template .= '.' . $templateExtension;
     // look whether we need output with or without the theme
     $raw = (bool) (isset($args['raw']) && !empty($args['raw'])) ? $args['raw'] : FormUtil::getPassedValue('raw', false, 'GETPOST', FILTER_VALIDATE_BOOLEAN);
     if (!$raw && in_array($templateExtension, array('csv', 'rss', 'atom', 'xml', 'pdf', 'vcard', 'ical', 'json'))) {
         $raw = true;
     }
     if ($raw == true) {
         // standalone output
         if ($templateExtension == 'pdf') {
             return self::processPdf($view, $template);
         } else {
             $view->display($template);
         }
         System::shutDown();
     }
     // normal output
     return $view->fetch($template);
 }
示例#4
0
    /**
     * display theme changing user interface
     */
    public function main()
    {
        // check if theme switching is allowed
        if (!System::getVar('theme_change')) {
            LogUtil::registerError($this->__('Notice: Theme switching is currently disabled.'));
            $this->redirect(ModUtil::url('Users', 'user', 'main'));
        }

        if (!SecurityUtil::checkPermission('Theme::', '::', ACCESS_COMMENT)) {
            return LogUtil::registerPermissionError();
        }

        // get our input
        $startnum = FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : 1, 'GET');

        // we need this value multiple times, so we keep it
        $itemsperpage = $this->getVar('itemsperpage');

        // get some use information about our environment
        $currenttheme = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));

        // get all themes in our environment
        $allthemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_USER);

        $previewthemes = array();
        $currentthemepic = null;
        foreach ($allthemes as $key => $themeinfo) {
            $themename = $themeinfo['name'];
            if (file_exists($themepic = 'themes/'.DataUtil::formatForOS($themeinfo['directory']).'/images/preview_medium.png')) {
                $themeinfo['previewImage'] = $themepic;
                $themeinfo['largeImage'] = 'themes/'.DataUtil::formatForOS($themeinfo['directory']).'/images/preview_large.png';
            } else {
                $themeinfo['previewImage'] = 'system/Theme/images/preview_medium.png';
                $themeinfo['largeImage'] = 'system/Theme/images/preview_large.png';
            }
            if ($themename == $currenttheme['name']) {
                $currentthemepic = $themepic;
                unset($allthemes[$key]);
            } else {
                $previewthemes[$themename] = $themeinfo;
            }
        }

        $previewthemes = array_slice($previewthemes, $startnum-1, $itemsperpage);

        $this->view->setCaching(Zikula_View::CACHE_DISABLED);

        $this->view->assign('currentthemepic', $currentthemepic)
                   ->assign('currenttheme', $currenttheme)
                   ->assign('themes', $previewthemes)
                   ->assign('defaulttheme', ThemeUtil::getInfo(ThemeUtil::getIDFromName(System::getVar('Default_Theme'))));

        // assign the values for the pager plugin
        $this->view->assign('pager', array('numitems' => sizeof($allthemes),
                                           'itemsperpage' => $itemsperpage));

        // Return the output that has been generated by this function
        return $this->view->fetch('theme_user_main.tpl');
    }
示例#5
0
 function updateFile($orgFileReference, $newFilename)
 {
     $dom = ZLanguage::getModuleDomain('mediashare');
     $orgFilename = $this->storageDir . '/' . DataUtil::formatForOS($orgFileReference);
     if (!copy($newFilename, $orgFilename)) {
         return LogUtil::registerError(__f('Unable to copy the file from \'%1$s\' to \'%2$s\'', array($newFilename, $orgFileReference), $dom));
     }
     return true;
 }
示例#6
0
 /**
  * delete an avatar
  *
  */
 public function deleteavatar($args)
 {
     if (!SecurityUtil::checkPermission('Avatar::', '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError();
     }
     $osdir = DataUtil::formatForOS(ModUtil::getVar('Users', 'avatarpath'));
     $avatarfile = $osdir . '/' . DataUtil::formatForOS($args['avatar']);
     if (unlink($avatarfile) == false) {
         return LogUtil::registerError($this->__f('Error! Unable to delete avatar \'%s\'.', $avatarfile));
     }
     LogUtil::registerStatus($this->__f('Done! The Avatar \'%s\' has been deleted.', $avatarfile));
     return true;
 }
 /**
  * Step 1 - Check if the needed files exists and if they are writeable
  * @author Albert Pérez Monfort (aperezm@xtec.cat)
  * @return if they exist and are writeable user can jump to step 2
  */
 public function update()
 {
     $filesRealPath = FormUtil::getPassedValue('filesRealPath', isset($args['filesRealPath']) ? $args['filesRealPath'] : null, 'POST');
     $usersFolder = FormUtil::getPassedValue('usersFolder', isset($args['usersFolder']) ? $args['usersFolder'] : null, 'POST');
     if (!SecurityUtil::checkPermission('Files::', '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError();
     }
     $multisites = false;
     if (isset($GLOBALS['PNConfig']['Multisites']['multi']) && $GLOBALS['PNConfig']['Multisites']['multi'] == 1) {
         // create the needed folders for the site
         $siteDNS = isset($_GET['siteDNS']) ? DataUtil::formatForOS($_GET['siteDNS']) : null;
         $filesRealPath = $GLOBALS['PNConfig']['Multisites']['filesRealPath'] . '/' . $siteDNS . $GLOBALS['PNConfig']['Multisites']['siteFilesFolder'];
         if (!FileUtil::mkdirs($filesRealPath . '/' . $usersFolder, 0777, true)) {
             LogUtil::registerError($this->__('Directory creation error') . ': ' . $usersFolder);
             return false;
         }
         $multisites = true;
     }
     // check if the needed files are located in the correct places and they are writeable
     $file1 = false;
     $file2 = false;
     $fileWriteable1 = false;
     $fileWriteable2 = false;
     $path = $filesRealPath;
     if (file_exists($path)) {
         $file1 = true;
     }
     if (is_writeable($path)) {
         $fileWriteable1 = true;
     }
     $path = $filesRealPath . '/' . $usersFolder;
     if (file_exists($path)) {
         $file2 = true;
     }
     if (is_writeable($path)) {
         $fileWriteable2 = true;
     }
     if ($fileWriteable1 && $fileWriteable2) {
         ModUtil::setVar('Files', 'folderPath', $filesRealPath);
         ModUtil::setVar('Files', 'usersFolder', $usersFolder);
     }
     $this->view->assign('filesRealPath', $filesRealPath);
     $this->view->assign('usersFolder', $usersFolder);
     $this->view->assign('file1', $file1);
     $this->view->assign('file2', $file2);
     $this->view->assign('multisites', $multisites);
     $this->view->assign('fileWriteable1', $fileWriteable1);
     $this->view->assign('fileWriteable2', $fileWriteable2);
     $this->view->assign('step', 'check');
     return $this->view->fetch('Files_init.htm');
 }
/**
 * Smarty function to displaya modules online manual
 *
 * Admin
 * {adminonlinemanual}
 *
 * @see          function.admincategorymenu.php::smarty_function_admincategoreymenu()
 * @param        array       $params      All attributes passed to this function from the template
 * @param        object      $smarty     Reference to the Smarty object
 * @param        int         xhtml        if set, the link to the navtabs.css will be xhtml compliant
 * @return       string      the results of the module function
 */
function smarty_function_adminonlinemanual($params, $smarty)
{
    LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('adminonlinemanual')), E_USER_DEPRECATED);
    $lang = ZLanguage::transformFS(ZLanguage::getLanguageCode());
    $modinfo = ModUtil::getInfoFromName(ModUtil::getName());
    $modpath = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules';
    $file = DataUtil::formatForOS("{$modpath}/{$modinfo['directory']}/lang/{$lang}/manual.html");
    $man_link = '';
    if (is_readable($file)) {
        PageUtil::addVar('javascript', 'zikula.ui');
        $man_link = '<div style="margin-top: 20px; text-align:center">[ <a id="online_manual" href="' . $file . '">' . __('Online manual') . '</a> ]</div>' . "\n";
        $man_link .= '<script type="text/javascript">var online_manual = new Zikula.UI.Window($(\'online_manual\'),{resizable: true})</script>' . "\n";
    }
    return $man_link;
}
示例#9
0
 /**
  * Aggressively load models.
  *
  * This helper is required because we are using PEAR naming standards with
  * our own autoloading.  Doctrine's model loading doesn't take this into
  * account in non agressive modes.
  *
  * In general, this method is NOT required.
  *
  * @param string $modname Module name to load models for.
  *
  * @return void
  */
 public static function loadModels($modname)
 {
     $modname = isset($modname) ? strtolower((string) $modname) : '';
     $modinfo = ModUtil::getInfoFromName($modname);
     $osdir = DataUtil::formatForOS($modinfo['directory']);
     $base = $modinfo['type'] == ModUtil::TYPE_MODULE ? 'modules' : 'system';
     $dm = Doctrine_Manager::getInstance();
     $save = $dm->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING);
     $dm->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_AGGRESSIVE);
     $path = "{$base}/{$osdir}/lib/{$osdir}/Model";
     // prevent exception when model folder does not exist
     if (file_exists($path)) {
         Doctrine_Core::loadModels(realpath($path));
     }
     $dm->setAttribute(Doctrine::ATTR_MODEL_LOADING, $save);
 }
示例#10
0
    /**
     * display block
     *
     * @param  array  $blockinfo a blockinfo structure
     * @return output the rendered bock
     */
    public function display($blockinfo)
    {
        if (!SecurityUtil::checkPermission('fincludeblock::', "$blockinfo[title]::", ACCESS_READ)) {
            return;
        }

        // Get current content
        $vars = BlockUtil::varsFromContent($blockinfo['content']);

        // Defaults
        if (empty($vars['filo'])) {
            $vars['filo'] = 'relative/path/to/file.txt';
        }
        if (empty($vars['typo'])) {
            $vars['typo'] = 0;
        }

        if (!file_exists($vars['filo'])) {
            if (SecurityUtil::checkPermission('fincludeblock::', "$blockinfo[title]::", ACCESS_EDIT)) {
                $blockinfo['content'] = $this->__f("Error! The file '%s' was not found.", $vars['filo']);

                return BlockUtil::themeBlock($blockinfo);
            } else {
                return;
            }
        }

        $blockinfo['content'] = '';
        switch ($vars['typo']) {
            case 0:
                $blockinfo['content'] = /*nl2br(*/file_get_contents($vars['filo'])/*)*/;    // #155 (Blocktype finclude creates not needed line breaks)
                break;
            case 1:
                $blockinfo['content'] = DataUtil::formatForDisplay(file_get_contents($vars['filo']));
                break;
            case 2:
                ob_start();
                include DataUtil::formatForOS($vars['filo']);
                $blockinfo['content'] = ob_get_clean();
                break;
            default:
                return;
        }

        return BlockUtil::themeBlock($blockinfo);
    }
示例#11
0
 /**
  * Determines the view template for a certain method with given parameters.
  *
  * @param Zikula_View $view    Reference to view object.
  * @param string      $type    Current controller (name of currently treated entity).
  * @param string      $func    Current function (main, view, ...).
  * @param array       $args    Additional arguments.
  *
  * @return string name of template file.
  */
 public function getViewTemplate(Zikula_View $view, $type, $func, $args = array())
 {
     // create the base template name
     $template = DataUtil::formatForOS($type . '/' . $func);
     // check for template extension
     $templateExtension = $this->determineExtension($view, $type, $func, $args);
     // check whether a special template is used
     $tpl = isset($args['tpl']) && !empty($args['tpl']) ? $args['tpl'] : FormUtil::getPassedValue('tpl', '', 'GETPOST', FILTER_SANITIZE_STRING);
     $templateExtension = '.' . $templateExtension;
     if ($templateExtension != '.tpl') {
         $templateExtension .= '.tpl';
     }
     if (!empty($tpl) && $view->template_exists($template . '_' . DataUtil::formatForOS($tpl) . $templateExtension)) {
         $template .= '_' . DataUtil::formatForOS($tpl);
     }
     $template .= $templateExtension;
     return $template;
 }
示例#12
0
 /**
  * get all smilies
  */
 public function load_smilies()
 {
     // default smilies
     $icons = BBSmile_Util::getDefaultSmilies();
     if ($this->getVar('activate_auto') == 1) {
         $smiliepath_auto = DataUtil::formatForOS($this->getVar('smiliepath_auto'));
         $handle = opendir($smiliepath_auto);
         if ($handle != false) {
             while ($file = readdir($handle)) {
                 if ($file != '.' && $file != '..' && $file != 'index.tpl' && $file != 'CVS') {
                     if (preg_match("/(.*?)(.gif|.jpg|.jpeg|.png)\$/i", $file, $matches) != 0) {
                         $icons[$matches[1]] = array('type' => 1, 'imgsrc' => $matches[0], 'alt' => $matches[1], 'alias' => '', 'short' => ":" . $matches[1] . ":", 'active' => '1');
                     }
                 }
             }
         }
     }
     return $icons;
 }
示例#13
0
文件: User.php 项目: rmaiwald/BBSmile
 /**
  * bbsmiles
  * returns a html snippet with buttons for inserting bbsmiles into a text
  *
  * @param    $args['textfieldid']  id of the textfield for inserting smilies
  */
 public function bbsmiles($args)
 {
     if (!isset($args['textfieldid']) || empty($args['textfieldid'])) {
         return LogUtil::registerArgsError();
     }
     // if we have more than one textarea we need to distinguish them, so we simply use
     // a counter stored in a session var until we find a better solution
     $counter = SessionUtil::getVar('bbsmile_counter', 0);
     $counter++;
     SessionUtil::setVar('bbsmile_counter', $counter);
     $this->view->assign('counter', $counter);
     $this->view->assign('textfieldid', $args['textfieldid']);
     PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet('BBSmile'));
     $templatefile = DataUtil::formatForOS(ModUtil::getName()) . '.tpl';
     if ($this->view->template_exists($templatefile)) {
         return $this->view->fetch($templatefile);
     }
     $this->view->add_core_data();
     return $this->view->fetch('bbsmile_user_bbsmiles.tpl');
 }
示例#14
0
 function handleCommand(Zikula_Form_View $view, &$args)
 {
     if ($args['commandName'] == 'cancel') {
         $url = ModUtil::url('BBSmile', 'admin', 'main');
         return $view->redirect($url);
     }
     // Security check
     if (!SecurityUtil::checkPermission('BBSmile::', '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError(ModUtil::url('BBSmile', 'admin', 'main'));
     }
     // check for valid form
     if (!$view->isValid()) {
         return false;
     }
     $ok = true;
     $data = $view->getValues();
     $ossmiliepath = DataUtil::formatForOS($data['smiliepath']);
     if (!file_exists($ossmiliepath) || !is_readable($ossmiliepath)) {
         $ifield = $this->view->getPluginById('smiliepath');
         $ifield->setError(DataUtil::formatForDisplay($this->__('The path does not exists or the system cannot read it.')));
         $ok = false;
     }
     $osautosmiliepath = DataUtil::formatForOS($data['smiliepath_auto']);
     if (!file_exists($osautosmiliepath) || !is_readable($osautosmiliepath)) {
         $ifield = $this->view->getPluginById('smiliepath_auto');
         $ifield->setError(DataUtil::formatForDisplay($this->__('The path does not exists or the system cannot read it.')));
         $ok = false;
     }
     if ($ok == false) {
         return false;
     }
     $this->setVar('smiliepath', $data['smiliepath']);
     $this->setVar('smiliepath_auto', $data['smiliepath_auto']);
     $this->setVar('activate_auto', $data['activate_auto']);
     $this->setVar('remove_inactive', $data['remove_inactive']);
     LogUtil::registerStatus($this->__('BBSmile configuration updated'));
     return true;
 }
示例#15
0
 /**
  * Display a comment form
  *
  * This function displays a comment form, if you do not want users to
  * comment on the same page as the item is.
  *
  * @param $comment the comment (taken from HTTP put)
  * @param $mod the name of the module the comment is for (taken from HTTP put)
  * @param $objectid ID of the item the comment is for (taken from HTTP put)
  * @param $redirect URL to return to (taken from HTTP put)
  * @param $subject The subject of the comment (if any) (taken from HTTP put)
  * @param $replyto The ID of the comment for which this an anser to (taken from HTTP put)
  * @param $template The name of the template file to use (with extension)
  * @todo Check out it this function can be merged with _view!
  * @since 0.2
  */
 public function comment($args)
 {
     $mod = isset($args['mod']) ? $args['mod'] : FormUtil::getPassedValue('mod', null, 'POST');
     $objectid = isset($args['objectid']) ? $args['objectid'] : FormUtil::getPassedValue('objectid', null, 'POST');
     $areaid = isset($args['areaid']) ? $args['areaid'] : FormUtil::getPassedValue('areaid', null, 'POST');
     $redirect = isset($args['redirect']) ? $args['redirect'] : FormUtil::getPassedValue('redirect', null, 'POST');
     $useurl = isset($args['useurl']) ? $args['useurl'] : FormUtil::getPassedValue('useurl', null, 'POST');
     $comment = isset($args['comment']) ? $args['comment'] : FormUtil::getPassedValue('comment', null, 'POST');
     $subject = isset($args['subject']) ? $args['subject'] : FormUtil::getPassedValue('subject', null, 'POST');
     $replyto = isset($args['replyto']) ? $args['replyto'] : FormUtil::getPassedValue('replyto', null, 'POST');
     $order = isset($args['order']) ? $args['order'] : FormUtil::getPassedValue('order', null, 'POST');
     $owneruid = isset($args['owneruid']) ? $args['owneruid'] : FormUtil::getPassedValue('owneruid', null, 'POST');
     $template = isset($args['template']) ? $args['template'] : FormUtil::getPassedValue('template', null, 'POST');
     $stylesheet = isset($args['ezccss']) ? $args['ezccss'] : FormUtil::getPassedValue('ezccss', null, 'POST');
     if ($order == 1) {
         $sortorder = 'DESC';
     } else {
         $sortorder = 'ASC';
     }
     $status = 0;
     // check if commenting is setup for the input module
     if (!ModUtil::available($mod) || !ModUtil::isHooked('EZComments', $mod)) {
         return LogUtil::registerPermissionError();
     }
     // check if we're using the pager
     $enablepager = $this->getVar('enablepager');
     if ($enablepager) {
         $numitems = $this->getVar('commentsperpage');
         $startnum = FormUtil::getPassedValue('comments_startnum');
         if (!isset($startnum) && !is_numeric($startnum)) {
             $startnum = -1;
         }
     } else {
         $startnum = -1;
         $numitems = -1;
     }
     $items = ModUtil::apiFunc('EZComments', 'user', 'getall', compact('mod', 'objectid', 'sortorder', 'status', 'numitems', 'startnum'));
     if ($items === false) {
         return LogUtil::registerError($this->__('Internal Error.'), null, 'index.php');
     }
     $items = ModUtil::apiFunc('EZComments', 'user', 'prepareCommentsForDisplay', $items);
     if ($enablepager) {
         $commentcount = ModUtil::apiFunc('EZComments', 'user', 'countitems', compact('mod', 'objectid'));
     } else {
         $commentcount = count($items);
     }
     // don't use caching (for now...)
     $this->view->setCaching(false);
     $this->view->assign('comments', $items)->assign('commentcount', $commentcount)->assign('order', $sortorder)->assign('redirect', $redirect)->assign('allowadd', SecurityUtil::checkPermission('EZComments::', "{$mod}:{$objectid}: ", ACCESS_COMMENT))->assign('mod', DataUtil::formatForDisplay($mod))->assign('objectid', DataUtil::formatForDisplay($objectid))->assign('subject', DataUtil::formatForDisplay($subject))->assign('replyto', DataUtil::formatForDisplay($replyto))->assign('owneruid', $owneruid)->assign('useurl', $useurl)->assign(ModUtil::getVar('EZComments'))->assign('ezc_pager', array('numitems' => $commentcount, 'itemsperpage' => $numitems));
     // find out which template to use
     $templateset = isset($args['template']) ? $args['template'] : $template;
     $defaultcss = $this->getVar('css', 'style.css');
     if (!$this->view->template_exists(DataUtil::formatForOS($templateset) . '/ezcomments_user_comment.tpl')) {
         $templateset = $this->getVar('template', 'Standard');
     }
     $this->view->assign('template', $templateset);
     // include stylesheet if there is a style sheet
     $css = $stylesheet ? "{$stylesheet}.css" : $defaultcss;
     if ($css = ModUtil::apiFunc('EZComments', 'user', 'getStylesheet', array('path' => "{$templateset}/{$css}"))) {
         PageUtil::addVar('stylesheet', $css);
     }
     // FIXME comment template missing
     return $this->view->fetch(DataUtil::formatForOS($templateset) . '/ezcomments_user_view.tpl');
 }
示例#16
0
 /**
  * Get the user's theme.
  *
  * This function will return the current theme for the user.
  * Order of theme priority:
  *  - page-specific
  *  - category
  *  - user
  *  - system
  *
  * @param boolean $force True to ignore the cache.
  *
  * @return string           the name of the user's theme
  * @throws RuntimeException If this function was unable to calculate theme name.
  */
 public static function getTheme($force = false)
 {
     static $theme;
     if (isset($theme) && !$force) {
         return $theme;
     }
     // Page-specific theme
     $request = ServiceUtil::get('request');
     $pagetheme = $request->get('theme', null);
     $type = $request->attributes->get('_controller', null);
     if (!empty($pagetheme)) {
         $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($pagetheme));
         if ($themeinfo['state'] == ThemeUtil::STATE_ACTIVE && ($themeinfo['user'] || $themeinfo['system'] || $themeinfo['admin'] && $type == 'admin') && is_dir(ZIKULA_ROOT . '/themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
             return self::_getThemeFilterEvent($themeinfo['name'], 'page-specific');
         }
     }
     // check for an admin theme
     if (($type == 'admin' || $type == 'adminplugin') && SecurityUtil::checkPermission('::', '::', ACCESS_EDIT)) {
         $admintheme = ModUtil::getVar('Admin', 'admintheme');
         if (!empty($admintheme)) {
             $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($admintheme));
             if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir(ZIKULA_ROOT . '/themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
                 return self::_getThemeFilterEvent($themeinfo['name'], 'admin-theme');
             }
         }
     }
     // set a new theme for the user
     $session = $request->getSession();
     $newtheme = $request->get('newtheme');
     if (!empty($newtheme) && System::getVar('theme_change')) {
         $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($newtheme));
         if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir(ZIKULA_ROOT . '/themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
             if (self::isLoggedIn()) {
                 self::setVar('theme', $newtheme);
             } else {
                 $session->set('theme', $newtheme);
             }
             return self::_getThemeFilterEvent($themeinfo['name'], 'new-theme');
         }
     }
     // User theme
     if (System::getVar('theme_change') || SecurityUtil::checkPermission('::', '::', ACCESS_ADMIN)) {
         if (self::isLoggedIn()) {
             $usertheme = self::getVar('theme');
         } else {
             $usertheme = $session->get('theme');
         }
         $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($usertheme));
         if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir(ZIKULA_ROOT . '/themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
             return self::_getThemeFilterEvent($themeinfo['name'], 'user-theme');
         }
     }
     // default site theme
     $defaulttheme = System::getVar('Default_Theme');
     $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($defaulttheme));
     if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir(ZIKULA_ROOT . '/themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
         return self::_getThemeFilterEvent($themeinfo['name'], 'default-theme');
     }
     if (!System::isInstalling()) {
         throw new RuntimeException(__('UserUtil::getTheme() is unable to calculate theme name.'));
     }
 }
示例#17
0
 /**
  * Get system data directory path.
  *
  * @return string The path to the data directory.
  */
 public static function getDataDirectory()
 {
     return DataUtil::formatForOS(System::getVar('datadir'));
 }
示例#18
0
 /**
  * Selector for a module's tables.
  *
  * @param string  $modname       Module name.
  * @param string  $name          Select field name.
  * @param string  $selectedValue Selected value.
  * @param string  $defaultValue  Value for "default" option.
  * @param string  $defaultText   Text for "default" option.
  * @param boolean $submit        Submit on choose.
  * @param string  $remove        Remove string from table name.
  * @param boolean $disabled      Add Disabled attribute to select.
  * @param integer $nStripChars   Strip the first n characters.
  * @param integer $multipleSize  Size for multiple selects.
  *
  * @return string The rendered output.
  */
 public static function getSelector_ModuleTables($modname, $name, $selectedValue = '', $defaultValue = 0, $defaultText = '', $submit = false, $remove = '', $disabled = false, $nStripChars = 0, $multipleSize = 1)
 {
     if (!$modname) {
         return z_exit(__f('Invalid %1$s passed to %2$s.', array('modname', 'HtmlUtil::getSelector_ModuleTables')));
     }
     $modinfo = ModUtil::getInfo(ModUtil::getIdFromName($modname));
     $modpath = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules';
     $osdir = DataUtil::formatForOS($modinfo['directory']);
     $entityDir = "{$modpath}/{$osdir}/Entity/";
     $entities = array();
     if (file_exists($entityDir)) {
         $files = scandir($entityDir);
         foreach ($files as $file) {
             if ($file != '.' && $file != '..' && substr($file, -4) === '.php') {
                 $entities[] = $file;
             }
         }
     }
     $data = array();
     foreach ($entities as $entity) {
         $class = $modname . '\\Entity\\' . substr($entity, 0, strlen($entity) - 4);
         if (class_exists($class)) {
             $entityName = substr($entity, 0, strlen($entity) - 4);
             if ($remove) {
                 $entityName = str_replace($remove, '', $entityName);
             }
             if ($nStripChars) {
                 $entityName = ucfirst(substr($entityName, $nStripChars));
             }
             $data[$entityName] = $entityName;
         }
     }
     return self::getSelector_Generic($name, $data, $selectedValue, $defaultValue, $defaultText, null, null, $submit, $disabled, $multipleSize);
 }
示例#19
0
/**
 * Zikula_View function to provide easy access to an image
 *
 * This function provides an easy way to include an image. The function will return the
 * full source path to the image. It will as well provite the width and height attributes
 * if none are set.
 *
 * Available parameters:
 *   - src            The file name of the image
 *   - modname        The well-known name of a module (default: the current module)
 *   - modplugin      The name of the plugin in the passed module
 *   - sysplugin      The name of the system plugin
 *   - width, height  If set, they will be passed. If none is set, they are obtained from the image
 *   - alt            If not set, an empty string is being assigned
 *   - title          If set it will be passed as a title attribute
 *   - assign         If set, the results are assigned to the corresponding variable instead of printed out
 *   - optional       If set then the plugin will not return an error if an image is not found
 *   - default        If set then a default image is used should the requested image not be found (Note: full path required)
 *   - set            If modname is 'core' then the set parameter is set to define the directory in /images/
 *   - nostoponerror  If set and error ocurs (image not found or src is no image), do not trigger_error, but return false
 *   - retval         If set indicated the field to return instead the array of values (src, width, etc.)
 *   - fqurl          If set the image path is absolute, if not relative
 *   - all remaining parameters are passed to the image tag
 *
 * Example: {img src='heading.png'}
 * Output:  <img src="modules/Example/images/en/heading.png" alt="" width="261" height="69" />
 *
 * Example: {img src='heading.png' width='100' border='1' __alt='foobar'}
 * Output:  <img src="modules/Example/images/en/heading.png" width="100" border="1" alt="foobar" />
 *
 * Example: {img src='xhtml11.png' modname='core' set='powered'}
 * Output:  <img src="themes/Theme/images/powered/xhtml11.png" alt="" width="88" height="31" />
 *
 * Example: {img src='iconX.png' modname='ModName' modplugin='Plug1' set='icons'}
 * Output:  <img src="modules/ModName/plugins/Plug1/images/icons/iconX.png" alt="" width="16" height="16" />
 *
 * Example: {img src='iconY.png' sysplugin='Plug2' set='icons/small'}
 * Output:  <img src="plugins/Plug2/images/icons/small/iconY.png" alt="" width="16" height="16" />
 *
 * If the parameter assign is set, the results are assigned as an array. The components of
 * this array are the same as the attributes of the img tag; additionally an entry 'imgtag' is
 * set to the complete image tag.
 *
 * Example:
 * {img src="heading.png" assign="myvar"}
 * {$myvar.src}
 * {$myvar.width}
 * {$myvar.imgtag}
 *
 * Output:
 * modules/Example/images/en/heading.gif
 * 261
 * <img src="modules/Example/images/en/heading.gif" alt="" width="261" height="69"  />
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return string|void The img tag, null if $params['nostoponerror'] true and there is an error.
 */
function smarty_function_img($params, Zikula_View $view)
{
    $nostoponerror = isset($params['nostoponerror']) && $params['nostoponerror'] ? true : false;
    if (!isset($params['src']) || !$params['src']) {
        if (!$nostoponerror) {
            $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('img', 'src')));
            return;
        } else {
            return false;
        }
    }
    // process the image location
    $modname = isset($params['modname']) ? $params['modname'] : $view->toplevelmodule;
    $modplugin = isset($params['modplugin']) ? $params['modplugin'] : null;
    $sysplugin = isset($params['sysplugin']) ? $params['sysplugin'] : null;
    // process the image set
    $set = isset($params['set']) ? $params['set'] : null;
    $osset = DataUtil::formatForOS($set);
    // if the module name is 'core'
    if ($modname == 'core') {
        if (System::isLegacyMode() && (strpos($osset, 'icons/') !== false || strpos($osset, 'global/') !== false) && strpos($params['src'], '.gif')) {
            LogUtil::log(__f('Core image %s does not exist, please use the png format (called from %s).', array($params['src'], $view->getTemplatePath())), E_USER_DEPRECATED);
            $params['src'] = str_replace('.gif', '.png', $params['src']);
        }
    }
    // always provide an alt attribute.
    // if none is set, assign an empty one.
    $params['alt'] = isset($params['alt']) ? $params['alt'] : '';
    // prevent overwriting surrounding titles (#477)
    if (isset($params['title']) && empty($params['title'])) {
        unset($params['title']);
    }
    // language
    $lang = ZLanguage::transformFS(ZLanguage::getLanguageCode());
    if ($sysplugin) {
        $osplugdir = DataUtil::formatForOS($sysplugin);
        $pluglangpath = "plugins/{$osplugdir}/images/{$lang}";
        $plugpath = "plugins/{$osplugdir}/images";
        // form the array of paths
        $paths = array($pluglangpath, $plugpath);
    } else {
        // module directory
        if ($modname != 'core') {
            $modinfo = ModUtil::getInfoFromName($modname);
            $osmoddir = DataUtil::formatForOS($modinfo['directory']);
            $moduleDir = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules';
        }
        if ($modplugin) {
            $osmodplugdir = DataUtil::formatForOS($modplugin);
            $modpluglangpath = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/Resources/public/images/{$lang}";
            $modplugpath = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/Resources/public/images";
            $modpluglangpathOld = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/images/{$lang}";
            $modplugpathOld = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/images";
            // form the array of paths
            $paths = array($modpluglangpath, $modplugpath, $modpluglangpathOld, $modplugpathOld);
        } else {
            // theme directory
            $ostheme = DataUtil::formatForOS(UserUtil::getTheme());
            $theme = ThemeUtil::getTheme($ostheme);
            $themePath = null === $theme ? '' : $theme->getRelativePath() . '/Resources/public/images';
            $themepath = $themePath;
            $corethemepath = "themes/{$ostheme}/images";
            if ($modname == 'core') {
                $modpath = "images";
                $paths = array($themepath, $corethemepath, $modpath);
            } else {
                $osmodname = DataUtil::formatForOS($modname);
                $themelangpath = "{$themePath}/{$lang}";
                $themelangpathOld = "themes/{$ostheme}/templates/modules/{$osmodname}/images/{$lang}";
                $themepathOld = "themes/{$ostheme}/templates/modules/{$osmodname}/images";
                $module = ModUtil::getModule($modinfo['name']);
                $moduleBasePath = null === $module ? '' : $module->getRelativePath() . '/Resources/public/images';
                $modlangpath = "{$moduleBasePath}/{$lang}";
                $modpath = $moduleBasePath;
                $modlangpathOld = "{$moduleDir}/{$osmoddir}/images/{$lang}";
                $modpathOld = "{$moduleDir}/{$osmoddir}/images";
                $modlangpathOld2 = "{$moduleDir}/{$osmoddir}/pnimages/{$lang}";
                $modpathOld2 = "{$moduleDir}/{$osmoddir}/pnimages";
                // form the array of paths
                if (preg_match('/^admin.(png|gif|jpg)$/', $params['src'])) {
                    // special processing for modules' admin icon
                    $paths = array($modlangpath, $modpath, $modlangpathOld, $modpathOld, $modlangpathOld, $modpathOld, $modlangpathOld2, $modpathOld2);
                } else {
                    $paths = array($themelangpath, $themepath, $themelangpathOld, $themepathOld, $corethemepath, $modlangpath, $modpath, $modlangpathOld, $modpathOld, $modlangpathOld2, $modpathOld2);
                }
            }
        }
    }
    $ossrc = DataUtil::formatForOS($params['src']);
    // search for the image
    $imgsrc = '';
    foreach ($paths as $path) {
        $fullpath = $path . ($osset ? "/{$osset}/" : '/') . $ossrc;
        if (is_readable($fullpath)) {
            $imgsrc = $fullpath;
            break;
        }
    }
    if ($imgsrc == '' && isset($params['default'])) {
        $imgsrc = $params['default'];
    }
    // default for the optional flag
    $optional = isset($params['optional']) ? $params['optional'] : true;
    if ($imgsrc == '') {
        if ($optional) {
            if (!$nostoponerror) {
                $view->trigger_error(__f("%s: Image '%s' not found", array('img', DataUtil::formatForDisplay(($set ? "{$set}/" : '') . $params['src']))));
                return;
            } else {
                return false;
            }
        }
        return;
    }
    // If neither width nor height is set, get these parameters.
    // If one of them is set, we do NOT obtain the real dimensions.
    // This way it is easy to scale the image to a certain dimension.
    if (!isset($params['width']) && !isset($params['height'])) {
        if (!($_image_data = @getimagesize($imgsrc))) {
            if (!$nostoponerror) {
                $view->trigger_error(__f("%s: Image '%s' is not a valid image file", array('img', DataUtil::formatForDisplay(($set ? "{$set}/" : '') . $params['src']))));
                return;
            } else {
                return false;
            }
        }
        $params['width'] = $_image_data[0];
        $params['height'] = $_image_data[1];
    }
    $basepath = isset($params['fqurl']) && $params['fqurl'] ? System::getBaseUrl() : System::getBaseUri();
    $params['src'] = $basepath . '/' . $imgsrc;
    $retval = isset($params['retval']) ? $params['retval'] : null;
    $assign = isset($params['assign']) ? $params['assign'] : null;
    unset($params['modname']);
    unset($params['retval']);
    unset($params['assign']);
    if (isset($params['altml'])) {
        // legacy
        unset($params['altml']);
    }
    if (isset($params['titleml'])) {
        // legacy
        unset($params['titleml']);
    }
    unset($params['optional']);
    unset($params['default']);
    unset($params['set']);
    unset($params['nostoponerror']);
    unset($params['fqurl']);
    $imgtag = '<img ';
    foreach ($params as $key => $value) {
        $imgtag .= $key . '="' . $value . '" ';
    }
    $imgtag .= '/>';
    if (!empty($retval) && isset($params[$retval])) {
        return $params[$retval];
    } elseif (!empty($assign)) {
        $params['imgtag'] = $imgtag;
        $view->assign($assign, $params);
    } else {
        return $imgtag;
    }
}
示例#20
0
 /**
 * Determine the module admin image path.
 *
 * This function searches for the admin image of a module at several places.
 * If no image is found, a default image path is returned.
 *
 * @param string $moduleName Module name.
 *
 * @return string Returns module admin image path.
 */
 public static function getModuleImagePath($moduleName)
 {
     if ($moduleName == '') {
         return false;
     }
     $modinfo = self::getInfoFromName($moduleName);
     $modpath = $modinfo['type'] == self::TYPE_SYSTEM ? 'system' : 'modules';
     $osmoddir = DataUtil::formatForOS($modinfo['directory']);
     $paths = array($modpath . '/' . $osmoddir . '/images/admin.png', $modpath . '/' . $osmoddir . '/images/admin.jpg', $modpath . '/' . $osmoddir . '/images/admin.gif', $modpath . '/' . $osmoddir . '/pnimages/admin.gif', $modpath . '/' . $osmoddir . '/pnimages/admin.jpg', $modpath . '/' . $osmoddir . '/pnimages/admin.jpeg', $modpath . '/' . $osmoddir . '/pnimages/admin.png', 'system/Admin/images/default.gif');
     foreach ($paths as $path) {
         if (is_readable($path)) {
             break;
         }
     }
     return $path;
 }
示例#21
0
    public function display($blockinfo)
    {
        // check if the module is available
        if (!ModUtil::available('Theme')) {
            return;
        }

        // check if theme switching is allowed
        if (!System::getVar('theme_change')) {
            return;
        }

        // security check
        if (!SecurityUtil::checkPermission( "Themeswitcherblock::", "$blockinfo[title]::", ACCESS_READ)) {
            return;
        }

        // Get variables from content block
        $vars = BlockUtil::varsFromContent($blockinfo['content']);

        // Defaults
        if (empty($vars['format'])) {
            $vars['format'] = 1;
        }

        // get some use information about our environment
        $currenttheme = UserUtil::getTheme();

        // get all themes in our environment
        $themes = ThemeUtil::getAllThemes();

        // get some use information about our environment
        $currenttheme = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));

        // get all themes in our environment
        $themes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_USER);

        $previewthemes = array();
        $currentthemepic = null;
        foreach ($themes as $themeinfo) {
            $themename = $themeinfo['name'];
            if (file_exists($themepic = 'themes/'.DataUtil::formatForOS($themeinfo['directory']).'/images/preview_small.png')) {
                $themeinfo['previewImage'] = $themepic;
            } else {
                $themeinfo['previewImage'] = 'system/Theme/images/preview_small.png';
            }
            $previewthemes[$themename] = $themeinfo;
            if ($themename == $currenttheme['name']) {
                $currentthemepic = $themeinfo['previewImage'];
            }
        }

        $this->view->assign($vars)
                   ->assign('currentthemepic', $currentthemepic)
                   ->assign('currenttheme', $currenttheme)
                   ->assign('themes', $previewthemes);

        $blockinfo['content'] = $this->view->fetch('theme_block_themeswitcher.tpl');

        return BlockUtil::themeBlock($blockinfo);
    }
示例#22
0
文件: Theme.php 项目: rmaiwald/core
 /**
  * Get a concrete filename for automagically created content.
  *
  * Generates a filename path like: Theme / auto_id [/ source_dir / filename-l{lang}.ext]
  * the final part gets generated only if $auto_source is specified.
  *
  * @param string $path        The base path.
  * @param string $auto_source The file name (optional).
  * @param string $auto_id     The ID (optional).
  *
  * @return string The concrete path and file name to the content.
  */
 public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null)
 {
     // enables a flags to detect when is treating compiled templates
     $tocompile = $path == $this->compile_dir ? true : false;
     // format auto_source for os to make sure that id does not contain 'ugly' characters
     $auto_source = DataUtil::formatForOS($auto_source);
     // add the Theme name as first folder
     if (empty($themedir)) {
         $path .= '/' . $this->directory;
     } else {
         $path .= '/' . $themedir;
     }
     // the last folder is the cache_id if set
     $path .= !empty($auto_id) ? '/' . $auto_id : '';
     // takes in account the source subdirectory
     $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : '';
     // make sure the path exists to write the compiled/cached template there
     if (!file_exists($path)) {
         mkdir($path, $this->serviceManager['system.chmod_dir'], true);
     }
     // if there's a explicit source, it
     if ($auto_source) {
         $path .= '/';
         $extension = FileUtil::getExtension($auto_source);
         // isolates the filename on the source path passed
         $path .= FileUtil::getFilebase($auto_source);
         // if we are compiling we do not include cache variables
         if (!$tocompile) {
             // add the variable stuff only if $auto_source is present
             // to allow a easy flush cache for all the languages (if needed)
             $path .= '-l';
             if (System::getVar('multilingual') == 1) {
                 $path .= $this->language;
             }
             // end with a suffix convention of filename--Themename-lang.ext
             $path .= $extension ? ".{$extension}" : '';
         }
     }
     return $path;
 }
示例#23
0
 /**
  * Remove a directory from zikula's local cache directory.
  *
  * @param string $dir      The name of the directory to remove.
  * @param bool   $absolute Whether to process the passed dir as an absolute path or not.
  *
  * @return boolean true if successful, false otherwise.
  */
 public static function removeLocalDir($dir, $absolute = false)
 {
     $path = DataUtil::formatForOS(System::getVar('temp'), true) . '/' . $dir;
     return FileUtil::deldir($path, $absolute);
 }
示例#24
0
 protected function checkImage(&$link)
 {
     if (!empty($link['image'])) {
         $osimg = DataUtil::formatForOS($link['image']);
         if (is_readable($osimg)) {
             $link['image'] = $osimg;
             $link['imagedata'] = @getimagesize($osimg);
         } else {
             $link['errors'][] = DataUtil::formatForDisplay($link['image']) . ': invalid image data';
             $link['image'] = '';
             $link['imagedata'] = false;
         }
     }
     return;
 }
示例#25
0
    /**
     * Load all blocks.
     *
     * @return array Array of blocks.
     */
    public static function loadAll()
    {
        static $blockdirs = array();

        // Load new-style blocks from system and modules tree
        $mods = ModUtil::getAllMods();

        foreach ($mods as $mod) {
            $modname = $mod['name'];
            $moddir = DataUtil::formatForOS($mod['directory']);

            if (!isset($blockdirs[$modname])) {
                $blockdirs[$modname] = array();
                $blockdirs[$modname][] = "system/$moddir/lib/$moddir/Block";
                $blockdirs[$modname][] = "modules/$moddir/lib/$moddir/Block";
                $blockdirs[$modname][] = "modules/$moddir/pnblocks";

                foreach ($blockdirs[$modname] as $dir) {
                    if (is_dir($dir) && is_readable($dir)) {
                        $dh = opendir($dir);
                        while (($f = readdir($dh)) !== false) {
                            if (substr($f, -4) == '.php') {
                                $block = substr($f, 0, -4);
                                self::load($modname, $block);
                            }
                        }
                        closedir($dh);
                    }
                }
            }
        }

        // Return information gathered
        return $GLOBALS['blocks_modules'];
    }
示例#26
0
 /**
  * Get the user's theme.
  *
  * This function will return the current theme for the user.
  * Order of theme priority:
  *  - page-specific
  *  - category
  *  - user
  *  - system
  *
  * @param boolean $force True to ignore the cache.
  *
  * @return string           the name of the user's theme
  * @throws RuntimeException If this function was unable to calculate theme name.
  */
 public static function getTheme($force = false)
 {
     static $theme;
     if (isset($theme) && !$force) {
         return $theme;
     }
     if (CookieUtil::getCookie('zikulaMobileTheme') == '1' && ModUtil::getVar('Theme', 'enable_mobile_theme', false)) {
         $pagetheme = 'Mobile';
     } else {
         if (CookieUtil::getCookie('zikulaMobileTheme') != '2' && ModUtil::getVar('Theme', 'enable_mobile_theme', false)) {
             include_once "system/Theme/lib/vendor/Mobile_Detect.php";
             $detect = new Mobile_Detect();
             if ($detect->isMobile()) {
                 $pagetheme = 'Mobile';
             }
         } else {
             $pagetheme = FormUtil::getPassedValue('theme', null, 'GETPOST');
         }
     }
     // Page-specific theme
     $type = FormUtil::getPassedValue('type', null, 'GETPOST');
     $qstring = System::serverGetVar('QUERY_STRING');
     if (!empty($pagetheme)) {
         $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($pagetheme));
         if ($themeinfo['state'] == ThemeUtil::STATE_ACTIVE && ($themeinfo['user'] || $themeinfo['system'] || $themeinfo['admin'] && $type == 'admin') && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
             return self::_getThemeFilterEvent($themeinfo['name'], 'page-specific');
         }
     }
     // check for an admin theme
     if (($type == 'admin' || $type == 'adminplugin') && SecurityUtil::checkPermission('::', '::', ACCESS_EDIT)) {
         $admintheme = ModUtil::getVar('Admin', 'admintheme');
         if (!empty($admintheme)) {
             $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($admintheme));
             if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
                 return self::_getThemeFilterEvent($themeinfo['name'], 'admin-theme');
             }
         }
     }
     // set a new theme for the user
     $newtheme = FormUtil::getPassedValue('newtheme', null, 'GETPOST');
     if (!empty($newtheme) && System::getVar('theme_change')) {
         $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($newtheme));
         if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
             if (self::isLoggedIn()) {
                 self::setVar('theme', $newtheme);
             } else {
                 SessionUtil::setVar('theme', $newtheme);
             }
             return self::_getThemeFilterEvent($themeinfo['name'], 'new-theme');
         }
     }
     // User theme
     if (System::getVar('theme_change') || SecurityUtil::checkPermission('::', '::', ACCESS_ADMIN)) {
         if (self::isLoggedIn()) {
             $usertheme = self::getVar('theme');
         } else {
             $usertheme = SessionUtil::getVar('theme');
         }
         $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($usertheme));
         if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
             return self::_getThemeFilterEvent($themeinfo['name'], 'user-theme');
         }
     }
     // default site theme
     $defaulttheme = System::getVar('Default_Theme');
     $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($defaulttheme));
     if ($themeinfo && $themeinfo['state'] == ThemeUtil::STATE_ACTIVE && is_dir('themes/' . DataUtil::formatForOS($themeinfo['directory']))) {
         return self::_getThemeFilterEvent($themeinfo['name'], 'default-theme');
     }
     if (!System::isInstalling()) {
         throw new RuntimeException(__('UserUtil::getTheme() is unable to calculate theme name.'));
     }
 }
示例#27
0
 private function _pageLockRequireAccess()
 {
     global $PageLockAccessCount;
     if ($PageLockAccessCount == null) {
         $PageLockAccessCount = 0;
     }
     if ($PageLockAccessCount == 0) {
         global $PageLockFile;
         $ostemp = DataUtil::formatForOS(System::getVar('temp'), true);
         $PageLockFile = fopen($ostemp . '/pagelock.lock', "w+");
         flock($PageLockFile, LOCK_EX);
         fwrite($PageLockFile, "This is a locking file for synchronizing access to the PageLock module. Please do not delete.");
         fflush($PageLockFile);
     }
     ++$PageLockAccessCount;
 }
示例#28
0
 /**
  * Get the timestamp of the last change of the $tpl_name file.
  *
  * @param string $tpl_name Template name.
  * @param string      &$tpl_timestamp Template timestamp.
  * @param Zikula_View $view Reference to Smarty instance.
  *
  * @return boolean
  */
 public static function z_get_timestamp($tpl_name, &$tpl_timestamp, $view)
 {
     // get path, checks also if tpl_name file_exists and is_readable
     $tpl_path = $view->get_template_path($tpl_name);
     if ($tpl_path !== false) {
         $tpl_timestamp = filemtime(DataUtil::formatForOS($tpl_path . '/' . $tpl_name));
         return true;
     }
     return false;
 }
示例#29
0
    /**
     * Checks which path to use for required template.
     *
     * @param string $template Template name.
     *
     * @return string Template path.
     */
    public function get_template_path($template)
    {
        static $cache = array();

        if (isset($cache[$template])) {
            return $cache[$template];
        }

        // the current module
        //$modname = ModUtil::getName();

        foreach ($this->module as $module => $modinfo) {
            // prepare the values for OS
            $module = $modinfo['name'];
            $os_module = DataUtil::formatForOS($module);
            //$os_theme = DataUtil::formatForOS($this->theme);
            $os_dir = ($modinfo['type'] == ModUtil::TYPE_MODULE) ? 'modules' : 'system';

            $ostemplate = DataUtil::formatForOS($template);

            // check the module for which we're looking for a template is the
            // same as the top level mods. This limits the places to look for
            // templates.
            $base = ($modinfo['type'] == ModUtil::TYPE_CORE) ? '' : "$os_dir/$os_module/";
            //$configPath = ($modinfo['type'] == ModUtil::TYPE_CORE) ? 'zikula/' : "$os_module/";
            $search_path = array(
                        //"config/plugins/$configPath/{$this->pluginName}/templates", //global path
                        "{$base}plugins/{$this->pluginName}/templates"
            );

            foreach ($search_path as $path) {
                if (is_readable("$path/$ostemplate")) {
                    $cache[$template] = $path;
                    return $path;
                }
            }
        }

        // when we arrive here, no path was found
        return false;
    }
/**
 * Zikula_View function to include module specific javascripts
 *
 * Available parameters:
 *  - modname     module name (if not set, the current module is assumed)
 *                if modname="" than we will look into the main javascript folder
 *  - script      name of the external javascript file (mandatory)
 *  - modonly     javascript will only be included when the the current module is $modname
 *  - onload      function to be called with onLoad handler in body tag, makes sense with assign set only, see example #2
 *  - assign      if set, the tag and the script filename are returned
 *
 * Example: {modulejavascript modname=foobar script=module_admin_config.js modonly=1 }
 * Output:  <script type="text/javascript" src="modules/foobar/javascript/module_admin_config.js">
 *
 * Example: {modulejavascript modname=foobar script=module_admin_config.js modonly=1 onload="dosomething()" assign=myjs }
 * Output: nothing, but assigns a variable containing several values:
 *      $myjs.scriptfile = "modules/foobar/javascript/module_admin_config.js"
 *      $myjs.tag = "<script type=\"text/javascript\" src=\"modules/foobar/javascript/module_admin_config.js\"></script>"
 *      $myjs.onload = "onLoad=\"dosomething()\"";
 *      Possible code in master.tpl would be:
 *
 *      ...
 *      { $myjs.tag }
 *      </head>
 *      <body { $myjs.onload } >
 *      ...
 *
 *      which results in
 *
 *      ...
 *      <script type="text/javascript" src="modules/foobar/javascript/module_admin_config.js"></script>
 *      </head>
 *      <body onLoad="dosomething()" >
 *      ...
 *
 *      if foobar is the current module.
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return string The tag.
 */
function smarty_function_modulejavascript($params, Zikula_View $view)
{
    // check if script is set (mandatory)
    if (!isset($params['script'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modulejavascript', 'script')));
        return false;
    }
    // check if modname is set and if not, if $modonly is set
    if (!isset($params['modname'])) {
        if (isset($params['modonly'])) {
            // error - we want $modonly only with $modname
            $view->trigger_error(__f('Error! in %1$s: parameter \'%2$s\' only supported together with \'%3$s\' set.', array('modulejavascript', 'modonly', 'modname')));
            return;
        }
        // we use the current module name
        $params['modname'] = ModUtil::getName();
    }
    if (isset($params['modonly']) && $params['modname'] != ModUtil::getName()) {
        // current module is not $modname - do nothing and return silently
        return;
    }
    // if modname is empty, we will search the main javascript folder
    if ($params['modname'] == '') {
        $searchpaths = array('javascript', 'javascript/ajax');
    } else {
        // theme directory
        $theme = DataUtil::formatForOS(UserUtil::getTheme());
        $osmodname = DataUtil::formatForOS($params['modname']);
        $themepath = "themes/{$theme}/javascript/{$osmodname}";
        // module directory
        $modinfo = ModUtil::getInfoFromName($params['modname']);
        $osmoddir = DataUtil::formatForOS($modinfo['directory']);
        $modpath = "modules/{$osmoddir}/javascript";
        $syspath = "system/{$osmoddir}/javascript";
        $modpathOld = "modules/{$osmoddir}/pnjavascript";
        $syspathOld = "system/{$osmoddir}/pnjavascript";
        $searchpaths = array($themepath, $modpath, $syspath, $modpathOld, $syspathOld);
    }
    $osscript = DataUtil::formatForOS($params['script']);
    // search for the javascript
    $scriptsrc = '';
    foreach ($searchpaths as $path) {
        if (is_readable("{$path}/{$osscript}")) {
            $scriptsrc = "{$path}/{$osscript}";
            break;
        }
    }
    // if no module javascript has been found then return no content
    $tag = empty($scriptsrc) ? '' : '<script type="text/javascript" src="' . $scriptsrc . '"></script>';
    // onLoad event handler used?
    $onload = isset($params['onload']) ? 'onLoad="' . $params['onload'] . '"' : '';
    if (isset($params['assign'])) {
        $return = array();
        $return['scriptfile'] = $scriptsrc;
        $return['tag'] = $tag;
        $return['onload'] = $onload;
        $view->assign($params['assign'], $return);
    } else {
        return $tag;
    }
}