/** * Saves the cache content * @param string key Name of cache key. * @param string content Content stored in the cache * @returns boolean TRUE on success, FALSE otherwise */ public static function save($key, $content) { $key .= SITE_HASH . \Settings::get('Global', 'language'); if (!PHPWS_Cache::isEnabled()) { return; } if (!is_string($content)) { return PHPWS_Error::get(PHPWS_VAR_TYPE, 'core', __CLASS__ . '::' . __FUNCTION__); } $cache = PHPWS_Cache::initCache(); return $cache->save($content, md5($key)); }
/** * Returns a RSS feed. Cached result is returned if exists. */ public function view() { $cache_key = $this->module . '_cache_key'; $content = PHPWS_Cache::get($cache_key, RSS_CACHE_TIMEOUT); if (!empty($content)) { return $content; } if (empty($this->_feeds)) { $this->loadFeeds(); } $home_http = PHPWS_Core::getHomeHttp(); $template['CHANNEL_TITLE'] = $this->EncodeString($this->title); $template['CHANNEL_ADDRESS'] = $this->getAddress(); $template['HOME_ADDRESS'] = $home_http; $template['CHANNEL_DESCRIPTION'] = $this->EncodeString($this->description); $template['LANGUAGE'] = CURRENT_LANGUAGE; // change later $template['SEARCH_LINK'] = sprintf('%sindex.php?module=search&mod_title=%s&user=search', $home_http, $this->module); $template['SEARCH_DESCRIPTION'] = sprintf('Search in %s', $this->title); $template['SEARCH_NAME'] = 'search'; $template['COPYRIGHT'] = PHPWS_Settings::get('rss', 'copyright'); $template['WEBMASTER'] = PHPWS_Settings::get('rss', 'webmaster'); $template['MANAGING_EDITOR'] = PHPWS_Settings::get('rss', 'editor'); // $template['LAST_BUILD_DATE'] = $this->_last_build_date; $timezone = strftime('%z'); $timezone = substr($timezone, 0, 3) . ':' . substr($timezone, 3, 2); if ($this->_feeds) { foreach ($this->_feeds as $key) { $itemTpl = NULL; $url = preg_replace('/^\\.\\//', '', $key->url); $url = $home_http . preg_replace('/&(?!amp;)/', '&', $url); $itemTpl['ITEM_LINK'] = $url; $itemTpl['ITEM_TITLE'] = $this->EncodeString($key->title); $itemTpl['ITEM_GUID'] = $url; $itemTpl['ITEM_LINK'] = $url; $itemTpl['ITEM_SOURCE'] = sprintf('%sindex.php?module=rss&mod_title=%s', $home_http, $this->module); $itemTpl['ITEM_DESCRIPTION'] = strip_tags(trim($this->EncodeString($key->summary))); $itemTpl['ITEM_AUTHOR'] = $key->creator; // $itemTpl['ITEM_PUBDATE'] = $key->getCreateDate('%Y-%m-%d %H:%M:%S CST'); $itemTpl['ITEM_PUBDATE'] = $this->rssDate($key->create_date); $itemTpl['ITEM_DC_DATE'] = $key->getCreateDate('%Y-%m-%dT%H:%M:%S') . $timezone; $itemTpl['ITEM_DC_TYPE'] = 'Text'; //pull from db later $itemTpl['ITEM_DC_CREATOR'] = $key->creator; $itemTpl['ITEM_SOURCE_TITLE'] = $this->EncodeString($this->title); $template['item-listing'][] = $itemTpl; } } if (PHPWS_Settings::get('rss', 'rssfeed') == 2) { $tpl_file = 'rss20.tpl'; } else { $tpl_file = 'rss10.tpl'; } $content = PHPWS_Template::process($template, 'rss', $tpl_file); $content = utf8_encode($content); PHPWS_Cache::save($cache_key, $content); return $content; }
public function month_list() { if (PHPWS_Settings::get('calendar', 'use_calendar_style')) { Layout::addStyle('calendar'); } $month =& $this->calendar->int_month; $year =& $this->calendar->int_year; $day = 1; if ($this->calendar->schedule->public && !Current_User::isLogged() && PHPWS_Settings::get('calendar', 'cache_month_views')) { $cache_key = sprintf('list_%s_%s_%s', $month, $year, $this->calendar->schedule->id); } if (isset($cache_key)) { // Check cache $content = PHPWS_Cache::get($cache_key); if (!empty($content)) { return $content; } } // cache empty, make calendar $startdate = mktime(0, 0, 0, $month, 1, $year); $enddate = mktime(23, 59, 59, $month + 1, 0, $year); $date_pick = $this->getDatePick(); $this->calendar->loadEventList($startdate, $enddate); $tpl = new PHPWS_Template('calendar'); $tpl->setFile('view/month/list.tpl'); $events_found = false; $lvars = array('view' => 'day', 'schedule_id' => $this->calendar->schedule->id); $slink = new PHPWS_Link(null, 'calendar'); $slink->setNoFollow(PHPWS_Settings::get('calendar', 'no_follow')); for ($i = $startdate; $i <= $enddate; $i += 86400) { $day_result = $this->getDaysEvents($i, $tpl); $lvars['date'] = $i; $slink->clearValues(); $slink->addValues($lvars); if ($day_result) { $events_found = true; $slink->setLabel(strftime('%A', $i)); $day_tpl['FULL_WEEKDAY'] = $slink->get(); $slink->setLabel(strftime('%a', $i)); $day_tpl['ABBR_WEEKDAY'] = $slink->get(); $slink->setLabel(strftime('%e', $i)); $day_tpl['DAY_NUMBER'] = $slink->get(); $tpl->setCurrentBlock('days'); $tpl->setData($day_tpl); $tpl->parseCurrentBlock(); } } if (!$events_found) { $tpl->setVariable('MESSAGE', dgettext('calendar', 'No events this month.')); } $main_tpl = $this->viewLinks('list'); $main_tpl['FULL_MONTH_NAME'] = strftime('%B', mktime(0, 0, 0, $month, $day, $year)); $main_tpl['ABRV_MONTH_NAME'] = strftime('%b', mktime(0, 0, 0, $month, $day, $year)); $main_tpl['SCHEDULE_TITLE'] = $this->calendar->schedule->title; $main_tpl['FULL_YEAR'] = strftime('%Y', mktime(0, 0, 0, $month, $day, $year)); $main_tpl['ABRV_YEAR'] = strftime('%y', mktime(0, 0, 0, $month, $day, $year)); $main_tpl['SCHEDULE_PICK'] = $this->schedulePick(); $main_tpl['PICK'] = $date_pick; $main_tpl['DOWNLOAD'] = $this->downloadLink($startdate, $enddate); $main_tpl['SUGGEST'] = $this->suggestLink(); if ($this->calendar->schedule->checkPermissions()) { $main_tpl['ADD_EVENT'] = '<button class="add-event btn btn-success" data-schedule-id="' . $this->calendar->schedule->id . '" data-date="' . $this->calendar->current_date * 1000 . '"><i class="fa fa-plus"></i> Add event</button>'; } $tpl->setData($main_tpl); $content = $tpl->get(); if (isset($cache_key)) { PHPWS_Cache::save($cache_key, $content); } return $content; }
public static function admin() { if (!Current_User::allow('layout')) { Current_User::disallow(); } PHPWS_Core::initModClass('controlpanel', 'Panel.php'); $title = $content = null; $panel = Layout_Admin::adminPanel(); if (isset($_REQUEST['command'])) { $command = $_REQUEST['command']; } else { $command = $panel->getCurrentTab(); } switch ($command) { case 'arrange': $title = dgettext('layout', 'Arrange Layout'); $content[] = Layout_Admin::arrangeForm(); break; case 'turn_off_box_move': Layout::moveBoxes(false); PHPWS_Core::goBack(); break; case 'post_style_change': $result = Layout_Admin::postStyleChange(); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); } javascript('close_refresh'); break; case 'reset_boxes': if (!Current_User::authorized('layout')) { Current_User::disallow(); } Layout::resetDefaultBoxes(); unset($_SESSION['Layout_Settings']); PHPWS_Core::reroute('index.php?module=layout&action=admin&authkey=' . Current_User::getAuthKey()); break; case 'move_boxes_on': if (!Current_User::authorized('layout')) { Current_User::disallow(); } Layout::moveBoxes(true); PHPWS_Core::goBack(); break; case 'move_boxes_off': if (!Current_User::authorized('layout')) { Current_User::disallow(); } Layout::moveBoxes(false); PHPWS_Core::goBack(); break; case 'confirmThemeChange': $title = dgettext('layout', 'Themes'); if (isset($_POST['confirm'])) { Layout_Admin::changeTheme(); PHPWS_Core::reroute('index.php?module=layout&action=admin&tab=theme'); exit; } else { Layout::reset(); } $content[] = Layout_Admin::adminThemes(); break; case 'meta': $title = dgettext('layout', 'Edit Meta Tags'); $content[] = Layout_Admin::metaForm(); break; case 'clear_templates': if (!Current_User::authorized('layout')) { Current_User::disallow(); } $files = PHPWS_File::readDirectory(PHPWS_SOURCE_DIR . 'templates/cache', false, true); if (!empty($files) && is_array($files)) { foreach ($files as $fn) { $delete_cache_path = "templates/cache/{$fn}"; if (is_file($delete_cache_path)) { unlink('templates/cache/' . $fn); } } } PHPWS_Core::goBack(); break; case 'clear_cache': if (!Current_User::authorized('layout')) { Current_User::disallow(); } PHPWS_Cache::clearCache(); PHPWS_Core::goBack(); break; case 'moveBox': $result = Layout_Admin::moveBox(); PHPWS_Error::logIfError($result); javascript('close_refresh'); Layout::nakedDisplay(); break; case 'postMeta': if (!Current_User::authorized('layout')) { Current_User::disallow(); } Layout_Admin::postMeta(); if (isset($_POST['key_id'])) { javascript('close_refresh'); Layout::nakedDisplay(); exit; } Layout::reset(); $title = dgettext('layout', 'Edit Meta Tags'); $template['MESSAGE'] = dgettext('layout', 'Meta Tags updated.'); $content[] = Layout_Admin::metaForm(); break; case 'demo_fail': unset($_SESSION['Layout_Settings']); Layout::checkSettings(); PHPWS_Core::reroute('index.php?module=layout&action=admin&command=confirmThemeChange'); break; case 'demo_theme': $title = dgettext('layout', 'Confirm Theme Change'); $content[] = dgettext('layout', 'If you are happy with the change, click the appropiate button.'); $content[] = dgettext('layout', 'Failure to respond in ten seconds, reverts phpWebSite to the default theme.'); $content[] = Layout_Admin::confirmThemeChange(); break; case 'postTheme': if (!Current_User::authorized('layout')) { Current_User::disallow(); } if ($_POST['default_theme'] != $_SESSION['Layout_Settings']->current_theme) { Layout::reset($_POST['default_theme']); PHPWS_Core::reroute('index.php?module=layout&action=admin&command=demo_theme&authkey=' . Current_User::getAuthKey()); } else { PHPWS_Settings::set('layout', 'include_css_order', (int) $_POST['include_css_order']); PHPWS_Settings::save('layout'); $title = dgettext('layout', 'Themes'); $content[] = Layout_Admin::adminThemes(); } break; case 'theme': $title = dgettext('layout', 'Themes'); $content[] = Layout_Admin::adminThemes(); break; case 'js_style_change': $content = Layout_Admin::jsStyleChange(); if (empty($content)) { javascript('close_refresh'); } Layout::nakedDisplay($content, dgettext('layout', 'Change CSS')); break; case 'page_meta_tags': $content = Layout_Admin::pageMetaTags((int) $_REQUEST['key_id']); if (empty($content)) { javascript('close_refresh'); } Layout::nakedDisplay($content, dgettext('layout', 'Set meta tags')); break; case 'move_popup': if (!Current_User::authorized('layout')) { Current_User::disallow(); } Layout_Admin::moveBoxMenu(); break; } $template['TITLE'] = $title; if (isset($content)) { $template['CONTENT'] = implode('<br />', $content); } if (isset($message)) { $template['MESSAGE'] = $message; } $final = PHPWS_Template::process($template, 'layout', 'main.tpl'); $panel->setContent($final); Layout::add(PHPWS_ControlPanel::display($panel->display())); }
public function postSettings() { PHPWS_Settings::set('calendar', 'personal_schedules', (int) isset($_POST['personal_schedules'])); PHPWS_Settings::set('calendar', 'allow_submissions', (int) isset($_POST['allow_submissions'])); PHPWS_Settings::set('calendar', 'mini_event_link', (int) isset($_POST['mini_event_link'])); PHPWS_Settings::set('calendar', 'cache_month_views', (int) isset($_POST['cache_month_views'])); PHPWS_Settings::set('calendar', 'mini_grid', (int) isset($_POST['mini_grid'])); PHPWS_Settings::set('calendar', 'anon_ical', (int) isset($_POST['anon_ical'])); PHPWS_Settings::set('calendar', 'no_follow', (int) isset($_POST['no_follow'])); PHPWS_Settings::set('calendar', 'display_mini', (int) $_POST['display_mini']); PHPWS_Settings::set('calendar', 'starting_day', (int) $_POST['starting_day']); PHPWS_Settings::set('calendar', 'default_view', $_POST['default_view']); PHPWS_Settings::set('calendar', 'brief_grid', $_POST['brief_grid']); PHPWS_Settings::save('calendar'); PHPWS_Cache::clearCache(); }
public function uninstall() { PHPWS_Cache::clearCache(); $content = array(); if (!$this->isModules()) { return PHPWS_Error::get(BOOST_NO_MODULES_SET, 'boost', 'install'); } foreach ($this->modules as $title => $mod) { unset($GLOBALS['Modules'][$title]); $title = trim($title); if ($this->getStatus($title) == BOOST_DONE) { continue; } if ($this->getCurrent() != $title && $this->getStatus($title) == BOOST_NEW) { $this->setCurrent($title); $this->setStatus($title, BOOST_START); } // H 0120 $content[] = dgettext('boost', 'Uninstalling') . ' - ' . $mod->getProperName(); // $content[] = '<b>' . dgettext('boost', 'Uninstalling') . ' - ' . $mod->getProperName() .'</b>'; if ($this->getStatus($title) == BOOST_START && $mod->isImportSQL()) { $uninstall_file = $mod->getDirectory() . 'boost/uninstall.sql'; if (!is_file($uninstall_file)) { $content[] = dgettext('boost', 'Uninstall SQL not found.'); } else { $content[] = dgettext('boost', 'Importing SQL uninstall file.'); $result = PHPWS_Boost::importSQL($uninstall_file); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); $content[] = dgettext('boost', 'An import error occurred.'); $content[] = dgettext('boost', 'Check your logs for more information.'); return implode('<br />', $content); } else { $content[] = dgettext('boost', 'Import successful.'); } } } $result = (bool) $this->onUninstall($mod, $content); // ensure translate path if ($result === true) { $this->setStatus($title, BOOST_DONE); $this->removeDirectories($mod, $content); $this->unregisterModule($mod, $content); $this->removeDependencies($mod); $this->removeKeys($mod); // H 0120 // $content[] = '<hr />'; $content[] = dgettext('boost', 'Finished uninstalling module!'); break; } elseif ($result == -1) { $this->setStatus($title, BOOST_DONE); $this->removeDirectories($mod, $content); $this->unregisterModule($mod, $content); $this->removeDependencies($mod); $this->removeKeys($mod); } elseif ($result === false) { $this->setStatus($title, BOOST_PENDING); break; } elseif (PHPWS_Error::isError($result)) { $content[] = dgettext('boost', 'There was a problem in the installation file:'); $content[] = '<b>' . $result->getMessage() . '</b>'; $content[] = '<br />'; PHPWS_Error::log($result); } } // H 0120 + place into boost log also $this->addLog($title, implode("\n", str_replace('<br />', "\n", $content))); return implode('<br />', $content); }
public function save() { PHPWS_Core::initModClass('search', 'Search.php'); if (!$this->id) { $new = true; $this->create_date = time(); } else { $new = false; } $this->last_updated = time(); // If this page has a parent and the order is not set // then increment if (!$this->page_order && $this->parent_page) { $page_order = $this->getLastPage(); if (!PHPWS_Error::logIfError($page_order)) { $this->page_order = $page_order + 1; } else { $this->page_order = 1; } } $db = new PHPWS_DB('ps_page'); if (PHPWS_Error::logIfError($db->saveObject($this))) { return false; } $this->saveKey(); if ($new && Current_User::isRestricted('pagesmith')) { Current_User::giveItemPermission($this->_key); } $search = new Search($this->key_id); $search->resetKeywords(); $search->addKeywords($this->title); PHPWS_Error::logIfError($search->save()); foreach ($this->_sections as $section) { $section->pid = $this->id; PHPWS_Error::logIfError($section->save($this->key_id)); } PHPWS_Cache::remove($this->cacheKey()); }
public function postSettings() { PHPWS_Settings::set('pagesmith', 'auto_link', isset($_POST['auto_link'])); PHPWS_Settings::set('pagesmith', 'create_shortcuts', isset($_POST['create_shortcuts'])); PHPWS_Settings::set('pagesmith', 'back_to_top', isset($_POST['back_to_top'])); PHPWS_Settings::save('pagesmith'); PHPWS_Cache::clearCache(); }
function flushCache() { if (PHPWS_Cache::remove('whatsnew_cache_key')) { return true; } }
/** * Resets the cache on the RSS feed */ public function reset() { $cache_key = $this->address; PHPWS_Cache::remove($cache_key); }
/** * Clears Blog's anonymous cache */ public function resetCache() { for ($i = 1; $i <= MAX_BLOG_CACHE_PAGES; $i++) { PHPWS_Cache::remove(BLOG_CACHE_KEY . $i); } }
public function delete() { $table = $this->_schedule->getEventTable(); Key::drop($this->key_id); $db = new PHPWS_DB($table); $db->addWhere('id', $this->id); // Remove any possible children $db->addWhere('pid', $this->id, null, 'or'); PHPWS_Cache::clearCache(); return $db->delete(); }