Пример #1
0
 function validate(Zikula_Form_View $view)
 {
     parent::validate($view);
     if (!$this->isValid) {
         return;
     }
     if ($this->text != '') {
         if (!is_dir($this->text) || !is_readable($this->text)) {
             $this->setError(__f('The path %s does not exist or is not readable by the webserver.', $this->text));
         } elseif ($this->writable == true && !is_writable($this->text)) {
             $this->setError(__f('The webserver cannot write to %s.', $this->text));
         } else {
             if ($this->removeSlash == true) {
                 do {
                     $hasSlash = false;
                     if (StringUtil::right($this->text, 1) == '/') {
                         $hasSlash = true;
                         $this->text = StringUtil::left($this->text, strlen($this->text) - 1);
                     }
                 } while ($hasSlash == true);
             }
         }
     } else {
         $this->setError(__('Error! Missing path.'));
     }
 }
Пример #2
0
 /**
  * Update item
  *
  * Takes info from edit form and passes to API
  * @author The Zikula Development Team
  * @param 'eid' Ephemeride id to delete
  * @param 'qauther' Author of item to delete
  * @param 'confirm' Delete confirmation
  * @return mixed HTML string if confirm is null, true otherwise
  */
 public function update($args)
 {
     // Confirm the forms authorisation key
     $this->checkCsrfToken();
     // get parameters from whatever input we need.
     $ephemerid = FormUtil::getPassedValue('ephemerid', isset($args['ephemerid']) ? $args['ephemerid'] : null, 'POST');
     $delcache = FormUtil::getPassedValue('delcache', isset($args['delcache']) ? $args['delcache'] : null, 'POST');
     // check to see if we have been passed $objectid, the generic item identifier.
     if (!empty($ephemerid['objectid'])) {
         $ephemerid['eid'] = $ephemerid['objectid'];
     }
     // add date names as in table
     $ephemerid['did'] = $ephemerid['Date_Day'];
     $ephemerid['mid'] = $ephemerid['Date_Month'];
     $ephemerid['yid'] = $ephemerid['Date_Year'];
     // notable by its absence there is no security check here.
     // update the ephemerid
     if (ModUtil::apiFunc($this->name, 'admin', 'update', $ephemerid)) {
         // success
         LogUtil::registerStatus($this->__('Done! Ephemeride updated.'));
         if ($delcache) {
             // delete respective block cache
             $cachedir = System::getVar('temp');
             if (StringUtil::right($cachedir, 1) != '/') {
                 $cachedir .= '/';
             }
             $cachedir .= ModUtil::getVar($this->name, 'cache_dir', 'any_cache');
             // delete all files matching a pattern
             array_map('unlink', glob($cachedir . '/ephem_*'));
         }
     }
     // this function generated no output, and so now it is complete we redirect
     // the user to an appropriate page for them to carry on their work
     return System::redirect(ModUtil::url($this->name, 'admin', 'view'));
 }
Пример #3
0
 /**
  * display block
  * @author       The Zikula Development Team
  */
 public function display($blockinfo)
 {
     // security check
     if (!SecurityUtil::checkPermission('Ephemerides:Ephemerideblock:', $blockinfo['bid'] . '::', ACCESS_READ)) {
         return;
     }
     // Get current content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     if (!isset($vars['category'])) {
         $vars['category'] = null;
     }
     // Implementation cached content: @nikp
     $enable_cache = true;
     $write_to_cache = false;
     # flag
     $cache_time = 3600;
     # seconds
     if (isset($vars['cache_time'])) {
         $cache_time = $vars['cache_time'];
     }
     $content = "";
     $title = $blockinfo['title'];
     if ($enable_cache and $cache_time > 0) {
         $cachefilestem = 'ephem_' . $blockinfo['bid'];
         $cachedir = System::getVar('temp');
         if (StringUtil::right($cachedir, 1) != '/') {
             $cachedir .= '/';
         }
         if (isset($vars['cache_dir']) and !empty($vars['cache_dir'])) {
             $cachedir .= $vars['cache_dir'];
         } else {
             $cachedir .= 'any_cache';
         }
         $cachefile = $cachedir . '/' . $cachefilestem . '_' . SecurityUtil::getSecurityLevel(SecurityUtil::getAuthInfo(), 'Ephemerides::', '::');
         $cachefile_title = $cachedir . '/' . $cachefilestem . '_t';
         // attempt to load from cache
         if (file_exists($cachefile)) {
             $file_time = filectime($cachefile);
             $now = time();
             $diff = $now - $file_time;
             if ($diff <= $cache_time) {
                 $content = file_get_contents($cachefile);
             }
             if (file_exists($cachefile_title)) {
                 $title = file_get_contents($cachefile_title);
             }
         }
         if (empty($content)) {
             $write_to_cache = true;
         }
         # not loaded, flag to write to cache later
     }
     if (empty($content)) {
         // Create output object
         $this->view->setCaching(false);
         // we implement caching other way
         $apiargs = array();
         $apiargs['status'] = 1;
         // Make a category filter only if categorization is enabled
         $enablecategorization = ModUtil::getVar($this->name, 'enablecategorization');
         if ($enablecategorization) {
             // load the categories system
             if (!Loader::loadClass('CategoryRegistryUtil')) {
                 return LogUtil::registerError(__f('Error! Could not load [%s] class.'), 'CategoryRegistryUtil');
             }
             // Get the registrered categories for the module
             $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'ephem');
             $this->view->assign('catregistry', $catregistry);
             $apiargs['catregistry'] = $catregistry;
             $apiargs['category'] = $vars['category'];
         }
         $this->view->assign('enablecategorization', $enablecategorization);
         $this->view->assign($vars);
         // assign the block vars
         if (!isset($vars['category']) || !is_array($vars['category'])) {
             $vars['category'] = array();
         }
         $this->view->assign('category', $vars['category']);
         // get items
         $items = ModUtil::apiFunc($this->name, 'user', 'gettoday', $apiargs);
         if (!$items) {
             return '';
             # do not display empty block: @nikp
         }
         $this->view->assign('items', $items);
         // Populate block info and pass to theme
         $content = $this->view->fetch('ephemerides_block_ephemeride.tpl');
         // loop to see if we have items of type=1 (events), if not - not to put title to the block (holidays only)
         $have_events = false;
         foreach ($items as $item) {
             if ($item['type'] == 1) {
                 $have_events = true;
                 break;
             }
         }
         if (!$have_events) {
             $title = "";
         }
     }
     if ($write_to_cache and !empty($content)) {
         // attempt to write to cache if not loaded before
         if (!file_exists($cachedir)) {
             mkdir($cachedir, 0777);
             # attempt to make the dir
         }
         if (file_put_contents($cachefile, $content)) {
             file_put_contents($cachefile_title, $title);
         } else {
             //echo "<br />Could not save data to cache. Please make sure your cache directory exists and is writable.<br />";
         }
     }
     $blockinfo['content'] = $content;
     $blockinfo['title'] = $title;
     // return the rendered block
     return BlockUtil::themeBlock($blockinfo);
 }
Пример #4
0
 /**
  * display block
  * @author       The Zikula Development Team
  */
 public function display($blockinfo)
 {
     // security check
     if (!SecurityUtil::checkPermission('Quotes:Quoteblock:', $blockinfo['bid'] . '::', ACCESS_READ)) {
         return;
     }
     // Get current content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     // filter desplay by hour of the day: @nikp
     $a_datetime = getdate();
     if (isset($vars['hourfrom']) and $vars['hourfrom'] > -1 and $a_datetime["hours"] < $vars['hourfrom']) {
         return "";
     }
     if (isset($vars['hourto']) and $vars['hourto'] > -1 and $a_datetime["hours"] > $vars['hourto']) {
         return "";
     }
     if (isset($vars['wdayfrom']) and $vars['wdayfrom'] > -1 and $a_datetime["wday"] < $vars['wdayfrom']) {
         return "";
     }
     if (isset($vars['wdayto']) and $vars['wdayto'] > -1 and $a_datetime["wday"] > $vars['wdayto']) {
         return "";
     }
     if (isset($vars['mdayfrom']) and $vars['mdayfrom'] > -1 and $a_datetime["mday"] < $vars['mdayfrom']) {
         return "";
     }
     if (isset($vars['mdayto']) and $vars['mdayto'] > -1 and $a_datetime["mday"] > $vars['mdayto']) {
         return "";
     }
     if (isset($vars['monfrom']) and $vars['monfrom'] > -1 and $a_datetime["mon"] < $vars['monfrom']) {
         return "";
     }
     if (isset($vars['monto']) and $vars['monto'] > -1 and $a_datetime["mon"] > $vars['monto']) {
         return "";
     }
     if (!isset($vars['category'])) {
         $vars['category'] = null;
     }
     if (isset($vars['ballooncolor'])) {
         $ballooncolor = $vars['ballooncolor'];
     } else {
         $ballooncolor = "grey";
     }
     // Implementation cached content: @nikp
     $enable_cache = true;
     $write_to_cache = false;
     # flag
     $cache_time = 240;
     # seconds
     if (isset($vars['cache_time'])) {
         $cache_time = $vars['cache_time'];
     }
     $content = "";
     if ($enable_cache and $cache_time > 0) {
         $cachefilestem = 'quote_' . $blockinfo['bid'];
         $cachedir = System::getVar('temp');
         if (StringUtil::right($cachedir, 1) != '/') {
             $cachedir .= '/';
         }
         if (isset($vars['cache_dir']) and !empty($vars['cache_dir'])) {
             $cachedir .= $vars['cache_dir'];
         } else {
             $cachedir .= 'any_cache';
         }
         $cachefile = $cachedir . '/' . $cachefilestem . '_' . SecurityUtil::getSecurityLevel(SecurityUtil::getAuthInfo(), 'Quotes::', '::');
         // attempt to load from cache
         if (file_exists($cachefile)) {
             $file_time = filectime($cachefile);
             $now = time();
             $diff = $now - $file_time;
             if ($diff <= $cache_time) {
                 $content = file_get_contents($cachefile);
             }
         }
         if (empty($content)) {
             $write_to_cache = true;
             # not loaded, flag to write to cache later
         }
     }
     if (empty($content)) {
         // Create output object
         $this->view->setCaching(false);
         // we implement caching other way
         mt_srand((double) microtime() * 1000000);
         $apiargs = array();
         $apiargs['status'] = 1;
         // Make a category filter only if categorization is enabled
         $enablecategorization = ModUtil::getVar($this->name, 'enablecategorization');
         if ($enablecategorization) {
             // load the categories system
             if (!Loader::loadClass('CategoryRegistryUtil')) {
                 return LogUtil::registerError(__f('Error! Could not load [%s] class.'), 'CategoryRegistryUtil');
             }
             // Get the registrered categories for the module
             $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'quotes');
             $this->view->assign('catregistry', $catregistry);
             $apiargs['catregistry'] = $catregistry;
             $apiargs['category'] = $vars['category'];
         }
         $this->view->assign('enablecategorization', $enablecategorization);
         $this->view->assign($vars);
         // assign the block vars
         if (!isset($vars['category']) || !is_array($vars['category'])) {
             $vars['category'] = array();
         }
         $this->view->assign('category', $vars['category']);
         $quote = ModUtil::apiFunc($this->name, 'user', 'getrandom', $apiargs);
         $this->view->assign('quote', $quote);
         $this->view->assign('bid', $blockinfo['bid']);
         $this->view->assign('ballooncolor', $ballooncolor);
         $content = $this->view->fetch('quotes_block_quote.tpl');
         # get the block output from the template
     }
     if ($write_to_cache and !empty($content)) {
         // attempt to write to cache if not loaded before
         if (!file_exists($cachedir)) {
             mkdir($cachedir, 0777);
             # attempt to make the dir
         }
         if (!file_put_contents($cachefile, $content)) {
             //echo "<br />Could not save data to cache. Please make sure your cache directory exists and is writable.<br />";
         }
     }
     $blockinfo['content'] = $content;
     // return the rendered block
     return BlockUtil::themeBlock($blockinfo);
 }
Пример #5
0
 /**
  * Display block
  */
 public function display($blockinfo)
 {
     if (!SecurityUtil::checkPermission('ZphpBB2_Lastposts::', $blockinfo[bid] . "::", ACCESS_READ)) {
         return;
     }
     if (!ModUtil::available('ZphpBB2')) {
         return;
     }
     // Get variables from content block
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     // Implementation cached content
     $enable_cache = true;
     $write_to_cache = false;
     # flag
     $cache_time = 180;
     # seconds
     if (isset($vars['cache_time'])) {
         $cache_time = $vars['cache_time'];
     }
     $content = "";
     if ($enable_cache and $cache_time > 0) {
         $cachefilestem = 'ZphpBB2_' . $blockinfo['bid'];
         $cachedir = System::getVar('temp');
         if (StringUtil::right($cachedir, 1) != '/') {
             $cachedir .= '/';
         }
         if (isset($vars['cache_dir']) and !empty($vars['cache_dir'])) {
             $cachedir .= $vars['cache_dir'];
         } else {
             $cachedir .= 'any_cache';
         }
         $cachefile = $cachedir . '/' . $cachefilestem;
         // attempt to load from cache
         if (file_exists($cachefile)) {
             $file_time = filectime($cachefile);
             $now = time();
             $diff = $now - $file_time;
             if ($diff <= $cache_time) {
                 $content = file_get_contents($cachefile);
             }
         }
         if (empty($content)) {
             $write_to_cache = true;
         }
         # not loaded, flag to write to cache later
     }
     if (empty($content)) {
         // Create output object
         $connection = Doctrine_Manager::getInstance()->getCurrentConnection();
         $table_prefix = ModUtil::getVar('ZphpBB2', 'table_prefix', 'phpbb_');
         // include some files
         define('IN_PHPBB', true);
         $phpbb_root_path = 'modules/ZphpBB2/vendor/phpBB2/';
         include_once $phpbb_root_path . "includes/constants.php";
         $blockinfo['content'] = "";
         // Defaults some things if they are empty!
         $vars['last_X_posts'] = $vars['last_X_posts'] ? $vars['last_X_posts'] : "5";
         //do we want every topic to appear just once?
         $connkeys = $vars['group_topics'] ? "" . TOPICS_TABLE . ".topic_last_post_id = " . POSTS_TABLE . ".post_id" : "" . TOPICS_TABLE . ".topic_id = " . POSTS_TABLE . ".topic_id";
         //limit to certain forums?
         if (!is_null($vars['excluded_forums']) && is_array($vars['excluded_forums'])) {
             $excluded_forums = in_array("", $vars['excluded_forums']) ? "" : "AND " . FORUMS_TABLE . ".forum_id NOT IN (" . implode(", ", $vars['excluded_forums']) . ")";
         }
         $lastvisit = 0;
         //list of forums user can see if private
         $viewforums = "";
         //list of forums user can look into if private
         $readforums = "";
         //list of forums where user is moderator
         $modforums = "";
         //just for guests
         $userstate = 0;
         if (UserUtil::isLoggedIn()) {
             $uid = UserUtil::getVar('uid');
             //permission level for registered users
             $userstate = AUTH_REG;
             //are you an board admin?
             $query = "SELECT user_level, user_lastvisit FROM   " . USERS_TABLE . " WHERE  user_id = {$uid}";
             $stmt = $connection->prepare($query);
             $stmt->execute();
             $result = $stmt->fetchAll(Doctrine_Core::FETCH_ASSOC);
             list($level, $lastvisit) = $result[0];
             if ($level == ADMIN) {
                 //user have complete access
                 $userstate = AUTH_ADMIN;
             } else {
                 $query = "SELECT " . AUTH_ACCESS_TABLE . ".forum_id,\n                        max(" . AUTH_ACCESS_TABLE . ".auth_view), \n                        max(" . AUTH_ACCESS_TABLE . ".auth_read), \n                        max(" . AUTH_ACCESS_TABLE . ".auth_mod)\n                        FROM   " . USER_GROUP_TABLE . " INNER JOIN " . AUTH_ACCESS_TABLE . " ON " . USER_GROUP_TABLE . ".group_id = " . AUTH_ACCESS_TABLE . ".group_id\n                        WHERE  " . USER_GROUP_TABLE . ".user_id = {$uid}\n                        GROUP BY " . AUTH_ACCESS_TABLE . ".forum_id";
                 $stmt = $connection->prepare($query);
                 $stmt->execute();
                 $result = $stmt->fetchAll(Doctrine_Core::FETCH_ASSOC);
                 foreach ($result as $r) {
                     list($forum_id, $auth_view, $auth_read, $auth_mod) = $r;
                     //let's make a nice list of forums the user is allowed to view, read and moderate
                     if ($auth_read | $auth_mod) {
                         $readforums .= empty($readforums) ? $forum_id : ", " . $forum_id;
                     }
                     if ($auth_view | $auth_mod) {
                         $viewforums .= empty($viewforums) ? $forum_id : ", " . $forum_id;
                     }
                     ", " . $forum_id;
                     if ($auth_mod) {
                         $modforums .= empty($modforums) ? $forum_id : ", " . $forum_id;
                     }
                     ", " . $forum_id;
                 }
             }
         }
         //let's see if we can optimize the query
         $view_private = !empty($viewforums) ? " OR (" . FORUMS_TABLE . ".auth_view = " . AUTH_ACL . " AND " . TOPICS_TABLE . ".forum_id IN ({$viewforums})) " : "";
         $read_private = !empty($readforums) ? " OR (" . FORUMS_TABLE . ".auth_read = " . AUTH_ACL . " AND " . TOPICS_TABLE . ".forum_id IN ({$readforums})) " : "";
         if (!empty($modforums)) {
             $view_mod = " OR (" . FORUMS_TABLE . ".auth_view = " . AUTH_MOD . " AND " . TOPICS_TABLE . ".forum_id IN ({$modforums})) ";
             $read_mod = " OR (" . FORUMS_TABLE . ".auth_read = " . AUTH_MOD . " AND " . TOPICS_TABLE . ".forum_id IN ({$modforums})) ";
         } else {
             $view_mod = $read_mod = "";
         }
         //now for the main query
         $query = "SELECT " . TOPICS_TABLE . ".topic_title, \n                       " . TOPICS_TABLE . ".topic_replies, \n                         " . TOPICS_TABLE . ".topic_views, \n                         " . TOPICS_TABLE . ".topic_id, \n                         " . USERS_TABLE . ".username, \n                         " . POSTS_TABLE . ".post_id, \n                         " . POSTS_TABLE . ".poster_id, \n                         " . POSTS_TABLE . ".post_time, \n                         " . FORUMS_TABLE . ".forum_id, \n                         " . FORUMS_TABLE . ".forum_name,\n                         " . CATEGORIES_TABLE . ".cat_title \n                         FROM ((" . TOPICS_TABLE . " \n                         INNER JOIN " . POSTS_TABLE . " ON {$connkeys}) \n                         INNER JOIN " . USERS_TABLE . " ON " . USERS_TABLE . ".user_id = " . POSTS_TABLE . ".poster_id) \n                         INNER JOIN " . FORUMS_TABLE . " ON " . FORUMS_TABLE . ".forum_id = " . TOPICS_TABLE . ".forum_id \n                         INNER JOIN " . CATEGORIES_TABLE . " ON " . CATEGORIES_TABLE . ".cat_id = " . FORUMS_TABLE . ".cat_id \n                         WHERE (" . FORUMS_TABLE . ".auth_view <= {$userstate} {$view_private} {$view_mod})\n                         AND   (" . FORUMS_TABLE . ".auth_read <= {$userstate} {$read_private} {$read_mod}) {$excluded_forums} \n                         AND   " . TOPICS_TABLE . ".topic_status <> " . TOPIC_MOVED . "\n                         ORDER BY post_time DESC LIMIT " . $vars['last_X_posts'];
         $stmt = $connection->prepare($query);
         $stmt->execute();
         $items = $stmt->fetchAll(Doctrine_Core::FETCH_ASSOC);
         if (!$items) {
             $blockinfo['content'] = '';
             return BlockUtil::themesideblock($blockinfo);
         }
         // get module information
         $modinfo = ModUtil::getInfoFromName("ZphpBB2");
         //foreach ($items as $r) {
         foreach (array_keys($items) as $k) {
             $items[$k]['replyicon'] = 'modules/' . $modinfo['directory'] . '/images/' . ($lastvisit > 0 && $items[$k]['post_time'] > $lastvisit ? "icon_newest_reply.gif" : "icon_latest_reply.gif");
             $items[$k]['post_username'] = $items[$k]['poster_id'] != ANONYMOUS ? $items[$k]['username'] : $this->__('Guest');
             $items[$k]['profile_url'] = $items[$k]['poster_id'] != ANONYMOUS ? ModUtil::url('ZphpBB2', 'user', 'profile', array('mode' => 'viewprofile', 'u' => $items[$k]['poster_id'])) : "";
         }
     }
     $render_template = 'blocks/lastposts.tpl';
     if ($this->view->is_cached($render_template)) {
         $blockinfo['content'] = $this->view->fetch($render_template);
     } else {
         $this->view->assign($vars);
         $this->view->assign('items', $items);
         $this->view->assign('phpbb_root_path', $phpbb_root_path);
         $blockinfo['content'] = $this->view->fetch($render_template);
     }
     $content = BlockUtil::themesideblock($blockinfo);
     if ($write_to_cache and !empty($content)) {
         // attempt to write to cache if not loaded before
         if (!file_exists($cachedir)) {
             mkdir($cachedir, 0777);
             # attempt to make the dir
         }
         if (!file_put_contents($cachefile, $content)) {
             //echo "<br />Could not save data to cache. Please make sure your cache directory exists and is writable.<br />";
         }
     }
     return $content;
 }