Exemple #1
0
/**
 * Loads a serialized file, unserializes it, and returns it.
 *
 * If the file isn't readable (or doesn't exist) or reading it fails,
 * false is returned.
 *
 * @param string $filename
 * @param boolean $silent Set to true if you want an visible error.
 * @return mixed
 */
function loadSerialize($filename, $silent = false)
{
    $filename = fixpath($filename);
    if (!is_readable($filename)) {
        // If we're setting up PivotX, we can't set the paths before we initialise
        // the configuration and vice-versa. So, we just bail out if the paths aren't
        // set yet.
        if (empty($PIVOTX['paths']['pivotx_path'])) {
            return;
        }
        if (is_readable($PIVOTX['paths']['pivotx_path'] . $filename)) {
            $filename = $PIVOTX['paths']['pivotx_path'] . $filename;
        } else {
            $filename = "../" . $filename;
        }
    }
    if (!is_readable($filename)) {
        if ($silent) {
            return false;
        }
        $format = __("<p>The following file could not be read:</p>%s" . "<p>Try logging in with your ftp-client and make the file readable. " . "Else try to go <a href='javascript:history.go(-1)'>back</a> to the last page.</p>");
        $message = sprintf($format, '<pre>' . htmlspecialchars($filename) . '</pre>');
        renderErrorpage(__("File is not readable!"), $message);
    }
    $serialized_data = trim(implode("", file($filename)));
    $serialized_data = str_replace("<?php /* bolt */ die(); ?" . ">", "", $serialized_data);
    // new-style JSON-encoded data; detect automatically
    if (substr($serialized_data, 0, 5) === 'json:') {
        $serialized_data = substr($serialized_data, 5);
        $data = json_decode($serialized_data, true);
        return $data;
    }
    // old-style serialized data; to be phased out, but leaving intact for
    // backwards-compatibility
    @($data = unserialize($serialized_data));
    if (is_array($data)) {
        return $data;
    } else {
        $temp_serialized_data = preg_replace("/\r\n/", "\n", $serialized_data);
        if (@($data = unserialize($temp_serialized_data))) {
            return $data;
        } else {
            $temp_serialized_data = preg_replace("/\n/", "\r\n", $serialized_data);
            if (@($data = unserialize($temp_serialized_data))) {
                return $data;
            } else {
                return false;
            }
        }
    }
}
Exemple #2
0
/**
 * Loads a serialized file, unserializes it, and returns it.
 *
 * If the file isn't readable (or doesn't exist) or reading it fails,
 * false is returned.
 *
 * @param string $filename
 * @param boolean $silent
 *            Set to true if you want an visible error.
 * @return mixed
 */
function loadSerialize($filename, $silent = false)
{
    $filename = fixpath($filename);
    if (!is_readable($filename)) {
        if ($silent) {
            return false;
        }
        $part = __('Try logging in with your ftp-client and make the file readable. ' . 'Else try to go <a>back</a> to the last page.');
        $message = '<p>' . __('The following file could not be read:') . '</p>' . '<pre>' . htmlspecialchars($filename) . '</pre>' . '<p>' . str_replace('<a>', '<a href="javascript:history.go(-1)">', $part) . '</p>';
        renderErrorpage(__('File is not readable!'), $message);
    }
    $serialized_data = trim(implode("", file($filename)));
    $serialized_data = str_replace("<?php /* bolt */ die(); ?" . ">", "", $serialized_data);
    // new-style JSON-encoded data; detect automatically
    if (substr($serialized_data, 0, 5) === 'json:') {
        $serialized_data = substr($serialized_data, 5);
        $data = json_decode($serialized_data, true);
        return $data;
    }
    // old-style serialized data; to be phased out, but leaving intact for
    // backwards-compatibility. Up until Bolt 1.5, we used to serialize certain
    // fields, so reading in those old records will still use the code below.
    @($data = unserialize($serialized_data));
    if (is_array($data)) {
        return $data;
    } else {
        $temp_serialized_data = preg_replace("/\r\n/", "\n", $serialized_data);
        if (@($data = unserialize($temp_serialized_data))) {
            return $data;
        } else {
            $temp_serialized_data = preg_replace("/\n/", "\r\n", $serialized_data);
            if (@($data = unserialize($temp_serialized_data))) {
                return $data;
            } else {
                return false;
            }
        }
    }
}
Exemple #3
0
/**
 * Loads a serialized file, unserializes it, and returns it.
 *
 * If the file isn't readable (or doesn't exist) or reading it fails,
 * false is returned.
 *
 * @param string $filename
 * @param boolean $silent Set to true if you want an visible error.
 * @return mixed
 */
function loadSerialize($filename, $silent = false)
{
    $filename = fixpath($filename);
    if (!is_readable($filename)) {
        // If we're setting up PivotX, we can't set the paths before we initialise
        // the configuration and vice-versa. So, we just bail out if the paths aren't
        // set yet.
        if (empty($PIVOTX['paths']['pivotx_path'])) {
            return;
        }
        if (is_readable($PIVOTX['paths']['pivotx_path'] . $filename)) {
            $filename = $PIVOTX['paths']['pivotx_path'] . $filename;
        } else {
            $filename = "../" . $filename;
        }
    }
    if (!is_readable($filename)) {
        if ($silent) {
            return FALSE;
        }
        $message = sprintf(__("<p>The following file could not be read:</p>%s" . "<p>Try logging in with your ftp-client and make the file readable. " . "Else try to go <a href='javascript:history.go(-1)'>back</a> to the last page.</p>"), '<pre>' . htmlspecialchars($filename) . '</pre>');
        renderErrorpage(__("File is not readable!"), $message);
    }
    $serialized_data = trim(implode("", file($filename)));
    $serialized_data = str_replace("<?php /* bolt */ die(); ?>", "", $serialized_data);
    @($data = unserialize($serialized_data));
    if (is_array($data)) {
        return $data;
    } else {
        $temp_serialized_data = preg_replace("/\r\n/", "\n", $serialized_data);
        if (@($data = unserialize($temp_serialized_data))) {
            return $data;
        } else {
            $temp_serialized_data = preg_replace("/\n/", "\r\n", $serialized_data);
            if (@($data = unserialize($temp_serialized_data))) {
                return $data;
            } else {
                return FALSE;
            }
        }
    }
}
function snippet_weblog($sub = '', $count = '')
{
    renderErrorpage("'weblog' is a block in PivotX", "Read the <a href='http://book.pivotx.net/?page=4-1#anchor-step-4-setting-up-templates'>documentation</a>.");
}
 /**
  * Render a 'Feed' page, using our own templates.
  *
  * @see $Parser::render
  */
 function renderFeed()
 {
     global $build, $PIVOTX;
     // Execute a hook, if present.
     // $dummy = array(); // because we pass by reference, PHP complains if the parameter is not a variable..
     // $PIVOTX['extensions']->executeHook('before_feedparse', $dummy );
     $link_params = array();
     if ($this->modifier['feedcontent'] == 'entries') {
         $template = 'feed_%type%_template.xml';
         $append_to_link = "";
     } else {
         if ($this->modifier['feedcontent'] == 'comments') {
             $template = 'feed_comments_%type%_template.xml';
             $link_params['content'] = 'comments';
         }
     }
     if ($this->modifier['feedtype'] == "rss") {
         $template = str_replace('%type%', 'rss', $template);
         $mime_type = "application/rss+xml";
         $link_self = makeFeedLink("rss", $link_params);
     } else {
         $template = str_replace('%type%', 'atom', $template);
         $mime_type = "application/atom+xml";
         $link_self = makeFeedLink("atom", $link_params);
     }
     // Perhaps override the template, if we're allowed to do so.
     if (!empty($this->modifier['template']) && $PIVOTX['config']->get('allow_template_override') == 1) {
         $template = $this->modifier['template'];
     }
     $preamble = $this->_feedTemplate($template, 'head');
     $feed_item = $this->_feedTemplate($template, 'item');
     $footer = $this->_feedTemplate($template, 'footer');
     $error = __('Feed error - selected %s doesn\'t exists!');
     $error_info = __('The %s "%s" given by the "%s" parameter in the URL, doesn\'t exist');
     // Special case: if category modifier is '*', we show all categories, regardless of weblog
     if ($this->modifier['category'] == "*") {
         $this->modifier['category'] = implode(",", $PIVOTX['categories']->getCategorynames());
     }
     // Try to set current weblog intelligently.
     if (isset($this->modifier['weblog'])) {
         if (!$PIVOTX['weblogs']->setCurrent($this->modifier['weblog'])) {
             renderErrorpage(sprintf($error, __('weblog')), sprintf($error_info, __('weblog'), htmlspecialchars($this->modifier['weblog']), 'w'));
         }
     } else {
         if (isset($this->modifier['category'])) {
             // Since we allow the category modifier to be a comma separated list
             // we need some code to handle it here too.
             $categories = array_map('trim', explode(',', $this->modifier['category']));
             list($thisweblog, $dummy) = $PIVOTX['weblogs']->getWeblogsWithCat($categories);
             $PIVOTX['weblogs']->setCurrent($thisweblog);
         } else {
             if (isset($this->modifier['entry'])) {
                 $entry = $PIVOTX['db']->read_entry($this->modifier['entry']);
                 if (empty($entry) || $entry['uid'] == '') {
                     renderErrorpage(sprintf($error, __('entry')), sprintf($error_info, __('entry'), htmlspecialchars($this->modifier['entry']), 'e'));
                 }
                 list($thisweblog, $dummy) = $PIVOTX['weblogs']->getWeblogsWithCat($entry['category']);
                 $PIVOTX['weblogs']->setCurrent($thisweblog);
             } else {
                 $PIVOTX['weblogs']->setCurrent();
             }
         }
     }
     $thisweblog = $PIVOTX['weblogs']->getWeblog();
     // tally up the categories and number of entries displayed in the
     // current weblog ..
     $thiscategories = array();
     $thisamount = 0;
     foreach ($thisweblog['sub_weblog'] as $sub_weblog) {
         // Make sure the categories are in an array..
         if (!is_array($sub_weblog['categories'])) {
             $sub_weblog['categories'] = array($sub_weblog['categories']);
         }
         $thiscategories = array_merge($thiscategories, $sub_weblog['categories']);
         $thisamount += $sub_weblog['num_entries'];
     }
     $thisuser = '';
     // Check what content to display
     if ($this->modifier['feedcontent'] == 'entries') {
         if (isset($this->modifier['category'])) {
             $thiscategories = array_map('trim', explode(',', $this->modifier['category']));
         }
         if (isset($this->modifier['user'])) {
             $thisuser = array_map('trim', explode(',', $this->modifier['user']));
         }
         if (isset($this->modifier['number'])) {
             $thisamount = $this->modifier['number'];
         }
     } else {
         if ($this->modifier['feedcontent'] == 'comments') {
             $thisamount = 10;
             if (isset($this->modifier['number'])) {
                 $thisamount = $this->modifier['number'];
             }
         } else {
             die('This can not happen');
         }
     }
     /**
      * First we'll make the head section of the feed..
      *
      */
     if (strlen($PIVOTX['weblogs']->get('', 'rss_link')) > 2) {
         $link = trim($PIVOTX['weblogs']->get('', 'rss_link'));
     } else {
         // determine the value ourselves..
         $link = getHost() . $PIVOTX['paths']['site_url'];
     }
     if (strlen($PIVOTX['weblogs']->get('', 'rss_img')) > 2) {
         $image = trim($PIVOTX['weblogs']->get('', 'rss_img'));
     } else {
         // if no image is set, we will also have to remove the <image> .. </image>
         // part from the RSS feed and the <logo> .. </logo> part from
         // the Atom feed. Bit hackish, but it works.
         $image = "";
         $preamble = preg_replace("/<(image|logo)>(.*)<\\/\\1>/msi", "", $preamble);
     }
     // Get the first user, for in the heading of the atom feed. Perhaps override it with 'hidden settings'.
     $userdata = $PIVOTX['users']->getUsers();
     $userdata = current($userdata);
     $adminemail = getDefault($PIVOTX['config']->get('feededitor_email'), $userdata['email']);
     $adminname = getDefault($PIVOTX['config']->get('feededitor_name'), $userdata['username']);
     $adminnick = getDefault($PIVOTX['config']->get('feededitor_name'), $userdata['nickname']);
     $replace = array("%sitename%" => $PIVOTX['config']->get('sitename'), "%title%" => str_replace("&", "&amp;", $PIVOTX['weblogs']->get('', 'name')), "%sitename_safe%" => strtolower(str_replace("_", "", safeString($PIVOTX['config']->get('sitename'), TRUE))), "%title_safe%" => str_replace("_", "", safeString($PIVOTX['weblogs']->get('', 'name'), TRUE)), "%link%" => $link, "%link_self%" => $link_self, "%description%" => str_replace("&", "&amp;", $PIVOTX['weblogs']->get('', 'payoff')), "%author%" => $adminname, "%admin-email%" => $adminemail, "%admin-nick%" => $adminnick, "%year%" => date("Y"), "%date%" => date("Y-m-d\\TH:i:s") . $this->_rssOffset(), "%date_rfc%" => getRfcDate(mktime()), "%genagent%" => "http://www.pivotx.net/?ver=" . urlencode(strip_tags($build)), "%version%" => strip_tags($build), "%lang%" => $PIVOTX['languages']->getCode(), "%image%" => $image);
     // Execute the 'feed_head' hook, if present.
     $PIVOTX['extensions']->executeHook('feed_head', $replace);
     $feed = str_replace(array_keys($replace), array_values($replace), $preamble);
     /**
      * Then we'll add the feed items.
      */
     if ($this->modifier['feedcontent'] == 'entries') {
         $entries = $PIVOTX['db']->read_entries(array('show' => $thisamount, 'cats' => $thiscategories, 'user' => $thisuser, 'status' => 'publish', 'order' => 'desc'));
         $feed .= $this->_renderFeedEntries($feed_item, $entries);
     } else {
         if (isset($this->modifier['entry'])) {
             // Comment feed for a single entry..
             $feed .= $this->_renderFeedComments($feed_item, $thisamount, array_reverse($entry['comments']));
         } else {
             // Comment feed for a weblog.
             $cats = $PIVOTX['weblogs']->getCategories();
             $comments = $PIVOTX['db']->read_latestcomments(array('cats' => $cats, 'count' => $thisamount, 'moderated' => 1));
             $feed .= $this->_renderFeedComments($feed_item, $thisamount, $comments);
         }
     }
     /**
      * And last, but certainly not least, we add a footer to the feed, and output it.
      */
     $feed .= $footer;
     header('Content-Type: ' . $mime_type . '; charset=utf-8');
     // Execute the 'feed_finish' hook, if present.
     $PIVOTX['extensions']->executeHook('feed_finish', $feed);
     // Before we echo, make sure there's nothing in the buffer already..
     ob_end_clean();
     echo $feed;
     // We are done. (No need to wait for the output function call in render.php.)
     die;
 }