/** * Creates the file that holds the last trackbacks. Just returns * if we're using SQL. * * @param array $temptrack * @return void */ function generateLastTrackbacks($temptrack) { global $PIVOTX; // If we're using MySQL, there's no need for the last trackbacks file.. if ($PIVOTX['db']->db_type != "flat") { return ""; } $lasttrack_file = $PIVOTX['paths']['db_path'] . 'ser_lasttrack.php'; // if it exists, load it if (file_exists($lasttrack_file)) { $lasttrack = loadSerialize($lasttrack_file, true, true); } else { $lasttrack = array(); } $lasttrack[] = array('title' => $temptrack['title'], 'excerpt' => trimText($temptrack['excerpt'], 250), 'name' => $temptrack['name'], 'url' => $temptrack['url'], 'date' => $temptrack['date'], 'entry_uid' => $temptrack['entry_uid'], 'uid' => makeTrackbackUID($temptrack), 'category' => $PIVOTX['db']->entry['category'], 'ip' => $temptrack['ip']); if (count($lasttrack) > intval($PIVOTX['config']->get('lastcomm_amount_max'))) { array_shift($lasttrack); } saveSerialize($lasttrack_file, $lasttrack); }
/** * Get a single page by its uid * * @param integer $uid * @return array */ function getPage($uid) { global $PIVOTX; $page = loadSerialize($PIVOTX['paths']['db_path'] . "pages/page_{$uid}.php"); $page['link'] = makePageLink($page['uri']); if ($page['title'] == '') { $page['title'] = __('No title..'); } // Set the chapter name and description (in addition to just the chapter's ID) $chapters = $PIVOTX['pages']->getIndex(); $page['chaptername'] = $chapters[$page['chapter']]['chaptername']; $page['chapterdesc'] = $chapters[$page['chapter']]['description']; return $page; }
function getNewWeblogForm() { global $PIVOTX; $form = new Form("newweblog", "", __("Save")); $form->html['start'] = <<<EOM <form enctype='multipart/form-data' name='%name%' id='%name%' action="%action%" method='post'> <fieldset style="display: none"> %hidden_fields% </fieldset> <table border='0' cellspacing='0' cellpadding='4' class='formclass' style="border-width: 0px !important; width: 750px;"> EOM; $form->add(array('type' => "csrf", 'cookie' => "pivotxsession", 'sessionvariable' => "pivotxsession")); $form->add(array('type' => 'text', 'name' => 'name', 'label' => __('Weblog Name'), 'error' => __('Error'), 'size' => 30, 'isrequired' => 1, 'validation' => 'string|minlen=2|maxlen=40', 'extra' => "onKeyUp=\"setSafename('name','internal');\" onChange=\"setSafename('name','internal');\"")); // include the weblog's internal name $form->add(array('type' => "text_readonly", 'name' => "internal", 'label' => __('Internal Name'), 'size' => 30, 'text' => makeJtip(__('Internal Name'), __('The internal name can consist of only lowercase letters, numbers and underscore (a-z,0-9,_). While the Weblog Name can be changed later on, the Internal Name will always stay the same.')))); $options = array("blank" => "<strong>" . __('Start from scratch') . "</strong>"); $themes = themeList(); foreach ($themes as $themename) { $html = ""; $imgname = str_replace(".theme", ".jpg", $themename); if (file_exists($imgname)) { // In case an absolute path is used, we replace the file system path with the corresponding URL. $imgname = str_replace($PIVOTX['paths']['pivotx_path'], $PIVOTX['paths']['pivotx_url'], $imgname); $html = sprintf("<img src='%s' width='200' height='133' alt='screenshot' align='left' style='border: 1px solid #666; margin-right: 10px;' />", $imgname); } $theme = loadSerialize($themename); $html .= sprintf("<strong>%s</strong><br /><br />%s", $theme['name'], $theme['payoff']); $options[$themename] = $html; } $form->add(array('type' => "radio", 'name' => "theme", 'label' => __('Theme'), 'options' => $options, 'text' => makeJtip(__('Theme'), __('Select the theme you\'d like to base your weblog on. All options can be changed later on.')))); return $form; }
private function loadCache() { /* Get the timestamps for the config files. config_local defaults to '0', because if it isn't present, it shouldn't trigger an update for the cache, while the others should. */ $timestamps = array(file_exists(BOLT_CONFIG_DIR . '/config.yml') ? filemtime(BOLT_CONFIG_DIR . '/config.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/taxonomy.yml') ? filemtime(BOLT_CONFIG_DIR . '/taxonomy.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/contenttypes.yml') ? filemtime(BOLT_CONFIG_DIR . '/contenttypes.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/menu.yml') ? filemtime(BOLT_CONFIG_DIR . '/menu.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/routing.yml') ? filemtime(BOLT_CONFIG_DIR . '/routing.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/permissions.yml') ? filemtime(BOLT_CONFIG_DIR . '/permissions.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/config_local.yml') ? filemtime(BOLT_CONFIG_DIR . '/config_local.yml') : 0); if (file_exists($this->app['resources']->getPath('cache') . '/config_cache.php')) { $cachetimestamp = filemtime($this->app['resources']->getPath('cache') . '/config_cache.php'); } else { $cachetimestamp = 0; } if ($cachetimestamp > max($timestamps)) { $this->data = loadSerialize($this->app['resources']->getPath('cache') . '/config_cache.php'); // Check if we loaded actual data. if (count($this->data) < 4 || empty($this->data['general'])) { return false; } // Check to make sure the version is still the same. If not, effectively invalidate the // cached config to force a reload. if (!isset($this->data['version']) || $this->data['version'] != $this->app->getVersion()) { return false; } // Trigger the config loaded event on the resource manager $this->app['resources']->initializeConfig($this->data); // Yup, all seems to be right. return true; } return false; }
/** * Get the default weblog. We need this for setting up PivotX: if the file is * not present, we use this to recreate it. * * Also, if we're creating a new weblog from scratch, we can use this to do so. * */ function getDefaultWeblog() { global $PIVOTX; // Use the skinny/skinny.theme as the template for the new Weblog. $weblog = loadSerialize(dirname(__FILE__) . "/templates/skinny/skinny.theme"); $weblog['language'] = $PIVOTX['config']->get('language'); $weblog['payoff'] = __('Welcome to your new online presence!'); return $weblog; }
/** * Process a comment for moderation. Action 1 = allow, * action 2 = delete. * * When allowed, the comment is changed in the entry, so it is displayed, and it * is added to the latest_comments. Whene deleted it'll be deleted from the entry * * @param array $comm * @param integer $action */ function moderateProcessComment($comm, $action) { global $PIVOTX; if (!isset($db)) { $db = new db(); } if ($action == 1) { // Allow comment. // First, get the entry.. $entry = $PIVOTX['db']->read_entry($comm['entry_uid']); $send_notification = false; foreach ($entry['comments'] as $key => $loopcomm) { if ($loopcomm['name'] == $comm['name'] && $loopcomm['date'] == $comm['date']) { // fix the entry.. $entry['comments'][$key]['moderate'] = 0; // Store the comment that's approved. We need it a bit later on to send the notifications $modcomment = $entry['comments'][$key]; // Save it.. $PIVOTX['db']->set_entry($entry); $PIVOTX['db']->save_entry(); // Remove the compiled/parsed pages from the cache. if ($PIVOTX['config']->get('smarty_cache')) { $PIVOTX['template']->clear_cache(); } $lastcommfile = $PIVOTX['paths']['db_path'] . "ser_lastcomm.php"; // Add it to the 'latest comments'.. if (file_exists($lastcommfile)) { $lastcomm = loadSerialize($lastcommfile, true, true); } else { $lastcomm = array(); } $lastcomm[] = $comm; saveSerialize($lastcommfile, $lastcomm); $send_notification = true; } } if ($send_notification && $PIVOTX['config']->get('dont_send_mail_notification') != 1) { // Handle the users that want to be notified via email.. sendMailNotification('comment', array($entry, $modcomment)); } } else { if ($action == 2) { // Delete comment. // First, get the entry.. $entry = $PIVOTX['db']->read_entry($comm['entry_uid']); foreach ($entry['comments'] as $key => $loopcomm) { if ($loopcomm['name'] == $comm['name'] && $loopcomm['date'] == $comm['date']) { // fix the entry.. unset($entry['comments'][$key]); // Save it.. $PIVOTX['db']->set_entry($entry); $PIVOTX['db']->save_entry(); } } // Remove the compiled/parsed pages from the cache. if ($PIVOTX['config']->get('smarty_cache')) { $PIVOTX['template']->clear_cache(); } } } }
function Events() { global $PIVOTX; $this->filename = "ser_events.php"; $this->edittimeout = 60; $this->maxevents = getDefault($PIVOTX['config']->get('eventlog_length'), 200); $this->data = loadSerialize($PIVOTX['paths']['db_path'] . $this->filename, true); // Make sure we have a proper $this->maxevents.. if (intval($this->maxevents) < 10) { $this->maxevents = 200; } // Make sure $this->data is set. if (empty($this->data) || !is_array($this->data)) { $this->data = array(); } }
/** * Get the TagCosmos. Flat file version. * * Preferably use the cached version, otherwise just make it * on the fly. (and then we store the cached version) * * The $weblogname parameter is used to return tags for a single weblog. * A value of '_all_' returns the tags for all weblogs combined. * If $max is given, it will return at most that many tags, ordered by size. * * Returns an array with the following elements: * 'minvalue' => minimum value of a tag * 'maxvalue' => maximum value of a tag * 'amount' => number of tags * 'tags' => array of the tags. The indices are the tags, the values the number of occurences * * @param integer $max * @param string $weblogname * @return array * @see getTagCosmos * */ function getTagCosmosFlat($max = 0, $weblogname, $match, $exclude = array()) { global $PIVOTX; // If the cached version is fresh enough, we restore that if (file_exists($PIVOTX['paths']['db_path'] . "ser_tags.php") && filectime($PIVOTX['paths']['db_path'] . "ser_tags.php") > time() - 60 * $PIVOTX['config']->get('tag_cache_timeout')) { // Just load it.. $data = loadSerialize($PIVOTX['paths']['db_path'] . "ser_tags.php"); $tagcosmos = $data[$weblogname]; } else { // We have to compute it.. $tagcosmos = array(); $tagcosmos['tags'] = array(); $multi_weblog = false; if (count($PIVOTX['weblogs']->getWeblogNames()) > 1) { $multi_weblog = true; foreach ($PIVOTX['weblogs']->getWeblogNames() as $name) { $tagcosmos[$name] = array(); } $temp_db = new db(FALSE); } $tagdir = dir($PIVOTX['paths']['db_path'] . "tagdata/"); // Read all tags, build the tag index and save it or later. while (false !== ($entry = $tagdir->read())) { if (getExtension($entry) == "tag") { list($tagname) = explode(".", $entry); $tagname = urldecode($tagname); $tagfile = implode("", file($PIVOTX['paths']['db_path'] . "tagdata/" . $entry)); $tagfile = explode(",", $tagfile); if (!in_array($tagname, $exclude)) { if ($tagname != "") { $tagcosmos['_all_']['tags'][$tagname] = count($tagfile); if ($multi_weblog) { foreach ($tagfile as $entrycode) { $temp_entry = $temp_db->read_entry($entrycode); $cat_weblogs = $PIVOTX['weblogs']->getWeblogsWithCat($temp_entry['category']); foreach ($cat_weblogs as $cat_weblog) { $tagcosmos[$cat_weblog]['tags'][$tagname]++; } } } } } } } $tagdir->close(); saveSerialize($PIVOTX['paths']['db_path'] . "ser_tags.php", $tagcosmos); $tagcosmos = $tagcosmos[$weblogname]; } if (isset($tagcosmos['tags'])) { $tagcosmos['amount'] = count($tagcosmos['tags']); } else { $tagcosmos['amount'] = 0; $tagcosmos['tags'] = array(); } if ($tagcosmos['amount'] > 0) { // if $max is given, we need to filter out the smaller tags, until the required size is reached. if ($max != 0 && $max < count($tagcosmos['tags'])) { arsort($tagcosmos['tags']); $tagcosmos['tags'] = array_slice($tagcosmos['tags'], 0, $max); } } return $tagcosmos; }
/** * Show / Edit a file in the ajaxy editor.. * */ public static function ext_view() { global $PIVOTX; $PIVOTX['session']->minLevel(PIVOTX_UL_ADMIN); // TODO: Check if the file is writable before showing the editor. if (empty($_GET['basedir'])) { die('Basedir is empty.'); } else { $basedir = cleanPath(base64_decode($_GET['basedir'])); } // Don't allow opening files outside $PIVOTX['paths']['home_path']. // This is consistent with the file explorer functions in pages.php. if (strpos($basedir, $PIVOTX['paths']['home_path']) === 0) { $filename = cleanPath($basedir . $_GET['file']); } else { die('Basedir outside home_path. Hacking attempt?'); } if ($contents = loadSerialize($filename)) { // Get the output in a buffer.. ob_start(); print_r($contents); $contents = ob_get_contents(); ob_end_clean(); echo "<pre>\n"; echo htmlentities($contents, ENT_QUOTES, "UTF-8"); echo "</pre>\n"; } else { $extension = getExtension($filename); $contents = implode("", file($filename)); $contents = preg_replace('/<textarea/i', '<*textarea', $contents); $contents = preg_replace('/<\\/textarea/i', '<*/textarea', $contents); echo "<form id='editor' class='formclass' method='post' action='' style='border: 0px;'>"; echo "<input type='hidden' value='" . $_GET['basedir'] . "' id='editBasedir'>"; echo "<input type='hidden' value='" . $_GET['file'] . "' id='editFile'>"; echo "<textarea style='width: 759px; border: 1px inset #999; height: 380px;' id='editContents' name='editContents' class='Editor' >"; echo htmlentities($contents, ENT_QUOTES, 'UTF-8'); echo "</textarea>"; if (in_array($extension, array('html', 'htm', 'tpl', 'xml', 'css'))) { echo '<script language="javascript" type="text/javascript">' . "\n"; echo 'jQuery(function($) {' . "\n"; echo ' $("#editContents").markItUp(markituphtml);' . "\n"; echo '});' . "\n"; echo '</script>' . "\n"; } else { echo '<script language="javascript" type="text/javascript">' . "\n"; echo 'jQuery(function($) {' . "\n"; echo ' $("#editContents").css("height", "384px");' . "\n"; echo '});' . "\n"; echo '</script>' . "\n"; } printf('<p class="buttons" style="margin: 0 0 6px 0; clear: both;"><a href="#" onclick="saveEdit();"><img src="pics/accept.png" alt="" />%s</a>', __('Save')); printf('<a href="#" onclick="saveEditAndContinue();"><img src="pics/accept.png" alt="" />%s</a>', __('Save and continue editing')); printf('<a href="#" onclick="closeEdit();" class="negative" style="margin-left: 20px;"><img src="pics/delete.png" alt="" />%s</a></p>', __('Cancel')); if ($PIVOTX['config']->get('smarty_cache') || $PIVOTX['config']->get('minify_frontend')) { $msg = __("You have Caching and/or Minify enabled. If your changes do not show up immediately, %click here% and disable Caching and Minify while you're working on your site."); $msg = preg_replace('/%(.*)%/i', "<a href='index.php?page=configuration#section-1'>\\1</a>", $msg); echo "\n\n<p class='small' style='width: 500px;clear: both;'>" . $msg . "</p>\n"; } echo "</form>"; } }
function read_entry_filename($filename, $updateindex = TRUE, $force = FALSE) { if ($entry = loadSerialize($filename, TRUE, $force)) { $this->entry = $entry; $this->update_index(FALSE); return TRUE; } else { return FALSE; } }
/** * Returns an array with user info if a registered visitor is logged in, * else false. */ function isLoggedIn() { global $PIVOTX; if (isset($_COOKIE['piv_reguser'])) { list($name, $hash) = explode("|", $_COOKIE['piv_reguser']); $name_md5 = strtolower(md5(strtolower($name))); if ($this->isUser($name)) { $user = loadSerialize($PIVOTX['paths']['db_path'] . 'users/' . $name_md5 . '.php', true); if (md5($user['pass']) == $hash) { return $user; } } } return false; }
private function loadCache() { /* Get the timestamps for the config files. config_local defaults to '0', because if it isn't present, it shouldn't trigger an update for the cache, while the others should. */ $timestamps = array(file_exists(BOLT_CONFIG_DIR . '/config.yml') ? filemtime(BOLT_CONFIG_DIR . '/config.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/taxonomy.yml') ? filemtime(BOLT_CONFIG_DIR . '/taxonomy.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/contenttypes.yml') ? filemtime(BOLT_CONFIG_DIR . '/contenttypes.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/menu.yml') ? filemtime(BOLT_CONFIG_DIR . '/menu.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/routing.yml') ? filemtime(BOLT_CONFIG_DIR . '/routing.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/permissions.yml') ? filemtime(BOLT_CONFIG_DIR . '/permissions.yml') : 10000000000, file_exists(BOLT_CONFIG_DIR . '/config_local.yml') ? filemtime(BOLT_CONFIG_DIR . '/config_local.yml') : 0); $cachetimestamp = file_exists(__DIR__ . "/../../cache/config_cache.php") ? filemtime(__DIR__ . "/../../cache/config_cache.php") : 0; //\util::var_dump($timestamps); //\util::var_dump($cachetimestamp); if ($cachetimestamp > max($timestamps)) { $this->data = loadSerialize(__DIR__ . "/../../cache/config_cache.php"); // Check if we loaded actual data. if (count($this->data) > 3 && !empty($this->data['general'])) { return true; } } return false; }
/** * Load all keys */ protected function load_keys() { global $PIVOTX; self::$keys = false; $fname = $PIVOTX['paths']['db_path'] . 'ser_spamkiller.php'; if (is_file($fname) && filesize($fname) > self::MAX_KEYFILESIZE) { // we assume something is terribly wrong if the maximum filesize is reached @unlink($fname); } self::$keys = loadSerialize($fname, true); if (!is_array(self::$keys)) { self::$keys = array(); } if (count(self::$keys) > self::MAX_KEYS) { // first we clean the keys self::$keys = $this->clean_keys(self::$keys); if (count(self::$keys) > self::MAX_KEYS) { // still have too many keys, we just throw away the old ones array_splice(self::$keys, self::MAX_KEYS); } // note: we only save keys when we get a store request } }