예제 #1
0
/**
 * Adds an item to the XML feeds for the given entry ID.
 *
 * The function uses the global array $items_added to avoid
 * adding the same entry twice.
 *
 * @uses feedtemplate loads the item template for XML feeds.
 *
 * @param int $uid
 * @param string $orgdate
 * @param string $title
 * @param string $introduction
 * @param string $body
 * @param string $user
 * @param string $category
 */
function add_rss($uid, $orgdate, $title, $introduction, $body, $user, $category)
{
    global $db, $rss_items, $atom_items, $items_added, $Cfg, $Weblogs, $Current_weblog, $Allow_RSS, $Paths, $Users;
    if (!$Allow_RSS) {
        return;
    }
    // Checking if the item is already added to avoid duplication
    if (in_array($uid, $items_added)) {
        return;
    } else {
        $items_added[] = $uid;
    }
    $link = make_fileurl($uid, "", "");
    if (!siteurl_isset()) {
        $weblog = gethost() . $Paths['pivot_url'];
        // we strip off the 'www.' part. It may not always result in a valid URL, but the
        // guid isn't supposed to be one anyhow. This prevents problems in readers, when
        // the feed is sometimes generated from www.example.org, and sometimes from example.org.
        $weblog = str_replace("www.", "", $weblog);
    } else {
        $weblog = $Weblogs[$Current_weblog]['siteurl'];
    }
    $title = trim(unentify($db->entry['title']));
    $subtitle = trim(unentify($db->entry['subtitle']));
    // parse fields and remove scripting from the feed. Script in feed is bad..
    $introduction = parse_intro_or_body($db->entry['introduction']);
    $introduction = clean_rss_text($introduction);
    $body = parse_intro_or_body($db->entry['body']);
    $body = clean_rss_text($body);
    $tag = str_replace("_", "", strtolower(safe_string($Cfg['sitename'], TRUE))) . "," . date("Y") . ":" . str_replace("_", "", safe_string($Weblogs[$Current_weblog]['name'], TRUE)) . "." . $uid;
    $lang = str_replace("_utf8", "", snippet_lang());
    $date = format_date($orgdate, "%year%-%month%-%day%T%hour24%:%minute%:00") . rss_offset();
    $date_rfc = format_date($orgdate, "%english_dname%, %day% %english_monname% %year% %hour24%:%minute%:00 ") . rss_offset("rfc822");
    if ($db->entry['edit_date'] != "") {
        $edit_date = format_date($db->entry['edit_date'], "%year%-%month%-%day%T%hour24%:%minute%:00") . rss_offset();
    } else {
        // if the entry was never edited, use the entrydate
        $edit_date = $date;
    }
    $summary = unentify(strip_tags($introduction));
    $summary = trim(str_replace("&", "&", str_replace(" ", " ", $summary)));
    // Set content (Atom 1.0) and description (RSS 2.0) according to completeness settings
    if (isset($Weblogs[$Current_weblog]['rss_full']) && $Weblogs[$Current_weblog]['rss_full'] == 0) {
        // don't put anything in the content.
        $content = "";
        $description = trim($introduction);
        if (strlen($body) > 5) {
            $description .= snippet_more();
            $summary .= ' ...';
        }
    } else {
        // put the introduction and body in the content..
        $content = trim(str_replace(" ", " ", $introduction . $body));
        $description = trim($introduction . $body);
    }
    $rss_item = feedtemplate('feed_rss_template.xml', 'item');
    $atom_item = feedtemplate('feed_atom_template.xml', 'item');
    // Handling viatitle special to avoid validation errors
    if (!empty($db->entry['viatitle'])) {
        $viatitle = 'title="' . $db->entry['viatitle'] . '"';
    } else {
        $viatitle = "";
    }
    $from = array("%title%", "%subtitle%", "%link%", "%description%", "%summary%", "%author%", "%author-email%", "%author-nick%", "%guid%", "%date%", "%edit_date%", "%date_rfc%", "%category%", "%content%", "%tag%", "%lang%", "%vialink%", "%viatitle%");
    $to = array(htmlspecialchars(strip_tags($title)), htmlspecialchars(strip_tags($subtitle)), $link, RelativeToAbsoluteURLS($description), RelativeToAbsoluteURLS($summary), $user, $Users[$user]['email'], $Users[$user]['nick'], $uid . "@" . $weblog, $date, $edit_date, $date_rfc, htmlspecialchars(implode(", ", $category)), RelativeToAbsoluteURLS($content), $tag, $lang, $db->entry['vialink'], $viatitle);
    $rss_item = str_replace($from, $to, $rss_item);
    $atom_item = str_replace($from, $to, $atom_item);
    // We add the count($rss_items), because otherwise we can't have two items
    // that are posted at the same minute.
    $rss_items[$orgdate . "." . count($rss_items)] = $rss_item;
    $atom_items[$orgdate . "." . count($rss_items)] = $atom_item;
}
예제 #2
0
/**
 * Modifier to parse (as Smarty/PivotX template) a given tag or variable
 *
 * example:
 * [[ $page.introduction|parse ]]
 * [[ body|parse ]] <- note that this second example is not very useful, as 'body' is already parsed.
 *
 * @param string $html
 * @return string
 * 
 */
function smarty_parse($html)
{
    $html = parse_intro_or_body($html);
    return $html;
}
예제 #3
0
/**
 * Get Entries/Pages with a certain Tag
 *
 * @param string $tag
 * @param integer $skip
 * @return unknown
 */
function getEntriesWithTag($tag, $skip = 0)
{
    global $PIVOTX;
    // How the entries are formated in the list
    $format_entry = "<li><a href='%link%'>%title%</a><br /><span>%excerpt%</span></li>\n";
    $filename = urlencode($tag) . '.tag';
    $tag = str_replace(" ", "+", $tag);
    if ($PIVOTX['config']->get('db_model') == "flat") {
        // Getting tags for flat files..
        if (file_exists($PIVOTX['paths']['db_path'] . "tagdata/{$filename}")) {
            $sEntriesString = file_get_contents($PIVOTX['paths']['db_path'] . "tagdata/{$filename}");
        } else {
            return "";
        }
        $aEntries = explode(",", $sEntriesString);
        rsort($aEntries);
        $aLinks = array();
        foreach ($aEntries as $nThisEntry) {
            $PIVOTX['db']->read_entry($nThisEntry);
            // Skip entries that aren't published - in case the tag index isn't up to date.
            if ($PIVOTX['db']->entry['status'] != 'publish') {
                continue;
            }
            $excerpt = makeExcerpt(parse_intro_or_body($PIVOTX['db']->entry['introduction'] . " " . $PIVOTX['db']->entry['body'], false, $PIVOTX['db']->entry['convert_lb']), 170);
            if ($PIVOTX['db']->entry["code"] != $skip) {
                $aLink = $format_entry;
                $aLink = str_replace("%link%", makeFileLink($PIVOTX['db']->entry["code"], '', ''), $aLink);
                $aLink = str_replace("%title%", $PIVOTX['db']->entry["title"], $aLink);
                $aLink = str_replace("%excerpt%", $excerpt, $aLink);
                $aLinks[] = $aLink;
            }
        }
    } else {
        // Getting tags for MySQL
        $tagtable = safeString($PIVOTX['config']->get('db_prefix') . "tags", true);
        $entriestable = safeString($PIVOTX['config']->get('db_prefix') . "entries", true);
        $pagestable = safeString($PIVOTX['config']->get('db_prefix') . "pages", true);
        // [JAN]
        // Set up DB factory
        $sqlFactory = new sqlFactory($PIVOTX['config']->get('db_model'), $PIVOTX['config']->get('db_databasename'), $PIVOTX['config']->get('db_hostname'), $PIVOTX['config']->get('db_username'), $PIVOTX['config']->get('db_password'));
        // Get a DB connection..
        $sql = $sqlFactory->getSqlInstance();
        //        $sql = new sql('mysql',
        //$PIVOTX['config']->get('db_databasename'),
        //                $PIVOTX['config']->get('db_hostname'),
        //                $PIVOTX['config']->get('db_username'),
        //                $PIVOTX['config']->get('db_password')
        //            );
        // [/JAN]
        $qry = array();
        $qry['select'] = "t.*";
        $qry['from'] = $tagtable . " AS t";
        $qry['order'] = "target_uid DESC";
        $qry['where'][] = "tag LIKE " . $sql->quote($tag);
        $qry['leftjoin'][$entriestable . " AS e"] = "t.target_uid = e.uid";
        $qry['leftjoin'][$pagestable . " AS p"] = "t.target_uid = p.uid";
        $qry['group'][] = "t.target_uid";
        $qry['group'][] = "t.contenttype";
        $sql->build_select($qry);
        $sql->query();
        //echo nl2br(htmlentities($sql->get_last_query()));
        $rows = $sql->fetch_all_rows();
        foreach ($rows as $row) {
            if ($row['contenttype'] == "entry") {
                $PIVOTX['db']->read_entry($row['target_uid']);
                // Skip entries that aren't published.
                if ($PIVOTX['db']->entry['status'] != "publish") {
                    continue;
                }
                $excerpt = makeExcerpt(parse_intro_or_body($PIVOTX['db']->entry['introduction'] . " " . $PIVOTX['db']->entry['body'], false, $PIVOTX['db']->entry['convert_lb']), 170);
                if ($PIVOTX['db']->entry["code"] != $skip) {
                    $aLink = $format_entry;
                    $aLink = str_replace("%link%", makeFileLink($PIVOTX['db']->entry["code"], '', ''), $aLink);
                    $aLink = str_replace("%title%", $PIVOTX['db']->entry["title"], $aLink);
                    $aLink = str_replace("%excerpt%", $excerpt, $aLink);
                    $aLinks[] = $aLink;
                }
            } else {
                if ($row['contenttype'] == "page") {
                    $page = $PIVOTX['pages']->getPage($row['target_uid']);
                    // Skip pages that aren't published.
                    if ($page['status'] != "publish") {
                        continue;
                    }
                    $title = $page['title'];
                    $excerpt = makeExcerpt(parse_intro_or_body($page['introduction'] . " " . $page['body'], false, $page['convert_lb']), 170);
                    $aLinks[] = "<li><a href=\"" . makePagelink($page['uri']) . "\">" . $title . "</a><br />\n{$excerpt}</li>\n";
                }
            }
        }
    }
    if (count($aLinks) > 0) {
        $sLinkList = "<ul class='taglist'>\n";
        $sLinkList .= implode("\n", $aLinks);
        $sLinkList .= "</ul>\n";
        return $sLinkList;
    } else {
        return "";
    }
}
예제 #4
0
/**
 * Edit a page in the mobile interface.
 */
function pagem_editpage()
{
    global $PIVOTX;
    $PIVOTX['session']->minLevel(PIVOTX_UL_NORMAL);
    if ($_GET['uid'] == "") {
        $PIVOTX['template']->assign('title', __('Write a new Page'));
    } else {
        $PIVOTX['template']->assign('title', __('Edit Page'));
    }
    $currentuser = $PIVOTX['users']->getUser($PIVOTX['session']->currentUsername());
    if (!empty($_GET['uid'])) {
        // Editing a page.. Get it from the DB..
        $page = $PIVOTX['pages']->getPage($_GET['uid']);
        $PIVOTX['events']->add('edit_entry', intval($_GET['uid']), $entry['title']);
        if (!$PIVOTX['users']->allowEdit('page', $page['user'])) {
            $PIVOTX['template']->assign('heading', __("PivotX encountered an error"));
            $PIVOTX['template']->assign('html', "<p>" . __("You are not allowed to edit this entry.") . "</p>");
            renderTemplate('mobile/generic.tpl');
            return;
        }
        // Make sure we tweak the </textarea> in the intro or body text (since
        // that would break our own textarea, if we didn't)..
        $page['introduction'] = str_replace("<textarea", "&lt;textarea", $page['introduction']);
        $page['introduction'] = str_replace("</textarea", "&lt;/textarea", $page['introduction']);
        $page['body'] = str_replace("<textarea", "&lt;textarea", $page['body']);
        $page['body'] = str_replace("</textarea", "&lt;/textarea", $page['body']);
        // If the entry was written in  'markdown', and is now
        // being edited in the mobile editor, we must convert it.
        if ($page['convert_lb'] == "3") {
            $page['introduction'] = parse_intro_or_body($page['introduction'], false, $page['convert_lb'], true);
            $page['body'] = parse_intro_or_body($page['body'], false, $page['convert_lb'], true);
        }
        // Otherwise, if the entry was written in 'Plain XHTML' or 'WYSIWYG', and is now
        // being edited, there is not much more we
        // can do than strip out the <p> and <br/> tags to replace with linebreaks.
        if ($page['convert_lb'] == "0" || $page['convert_lb'] == "5") {
            $page['introduction'] = unparse_intro_or_body($page['introduction']);
            $page['body'] = unparse_intro_or_body($page['body']);
        }
        list($page['link'], $page['link_end']) = explode($page['uri'], $page['link']);
    } else {
        // Make a new entry.
        $page = array();
        if ($_GET['chapter'] != "") {
            $page['chapter'] = intval($_GET['chapter']);
        }
        $user = $PIVOTX['session']->currentUser();
        $page['user'] = $user['username'];
        $page['sortorder'] = 10;
        if ($PIVOTX['config']->get('default_post_status') != "") {
            $page['status'] = $PIVOTX['config']->get('default_post_status');
        }
        $page['link'] = makePagelink("xxx");
        list($page['link'], $page['link_end']) = explode('xxx', $page['link']);
    }
    $templates = templateOptions(templateList(), 'page', array('_sub_', '_aux_'));
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        // Show the screen..
        // Show the screen..
        $PIVOTX['template']->assign('templates', $templates);
        $PIVOTX['template']->assign('page', $page);
        $PIVOTX['template']->assign('chapters', $PIVOTX['pages']->getIndex());
        $PIVOTX['template']->assign('pivotxsession', $PIVOTX['session']->getCSRF());
        $PIVOTX['template']->assign('users', $PIVOTX['users']->getUsers());
        $PIVOTX['template']->assign('pageuser', $PIVOTX['users']->getUser($entry['user']));
        $PIVOTX['template']->assign("active", "pages");
        renderTemplate('mobile/editpage.tpl');
    } else {
        if ($_POST['code'] != $_GET['uid']) {
            $PIVOTX['events']->add('fatal_error', intval($_GET['uid']), "Tried to fake editing an entry");
            echo "Code is wrong! B0rk!";
            die;
        }
        // Make sure the current user is properly logged in, and that the request is legitimate
        $PIVOTX['session']->checkCSRF($_POST['pivotxsession']);
        // Sanitize the $_POST into an entry we can store
        $page = sanitizePostedPage($page);
        $page['convert_lb'] = "2";
        // Make sure it's processed as 'Textile'
        $PIVOTX['extensions']->executeHook('page_edit_beforesave', $page);
        $new_id = $PIVOTX['pages']->savePage($page);
        $PIVOTX['extensions']->executeHook('page_edit_aftersave', $page);
        $PIVOTX['messages']->addMessage(sprintf(__('Your page "%s" was successfully saved.'), '<em>' . trimText($page['title'], 25) . '</em>'));
        // Remove the frontpages and entrypages from the cache.
        if ($PIVOTX['config']->get('smarty_cache')) {
            $PIVOTX['template']->clear_cache();
        }
        // Update the search index for this page, but only if we're using flat files.
        if ($PIVOTX['db']->db_type == "flat") {
            $page['code'] = $page['uid'] = $new_id;
            updateSearchIndex($page, 'p');
        }
        pagem_Pages();
    }
}
예제 #5
0
function snippet_body($strip = "")
{
    global $db, $Weblogs, $Current_weblog;
    $output = '<a id="body"></a>' . parse_intro_or_body($db->entry['body'], $strip);
    return $output;
}
예제 #6
0
 /**
  * Creates a feed of entries.
  *
  * @param string $feed_template
  * @param array $entries
  * @return string
  */
 function _renderFeedEntries($feed_template, $entries)
 {
     global $PIVOTX;
     // Getting category display names
     $categories = $PIVOTX['categories']->getCategories();
     $categories = makeValuepairs($categories, 'name', 'display');
     // Loop through the entries..
     foreach ($entries as $entry) {
         // Get the full entry..
         $entry = $PIVOTX['db']->read_entry($entry['code']);
         $link = makeFileURL($entry['uid'], "", "");
         $title = trim(unentify($entry['title']));
         $subtitle = trim(unentify($entry['subtitle']));
         // parse fields and remove scripting from the feed. Script in feed is bad..
         $introduction = parse_intro_or_body($entry['introduction'], false, $entry['convert_lb']);
         $introduction = $this->_cleanFeedText($introduction);
         $body = parse_intro_or_body($entry['body'], false, $entry['convert_lb']);
         $body = $this->_cleanFeedText($body);
         $year = formatDate($entry['date'], "%year%");
         $tag = safeString($PIVOTX['config']->get('sitename'), TRUE) . "," . $year . ":" . safeString($PIVOTX['weblogs']->get('', 'name'), TRUE) . "." . $entry['uid'];
         $tag = str_replace("_", "", strtolower($tag));
         $date = formatDate($entry['date'], "%year%-%month%-%day%T%hour24%:%minute%:00") . $this->_rssOffset();
         $date_rfc = formatDate($entry['date'], "%english_dname%, %day% %english_monname% %year% %hour24%:%minute%:00 ") . $this->_rssOffset("rfc822");
         if ($PIVOTX['db']->entry['edit_date'] != "") {
             $edit_date = formatDate($entry['edit_date'], "%year%-%month%-%day%T%hour24%:%minute%:00") . $this->_rssOffset();
         } else {
             // if the entry was never edited, use the entrydate
             $edit_date = $date;
         }
         $summary = unentify(strip_tags($introduction));
         $summary = trim(str_replace("&", "&amp;", str_replace("&nbsp;", " ", $summary)));
         // Set content (Atom 1.0) and description (RSS 2.0) according to completeness settings
         if ($PIVOTX['weblogs']->get('', 'rss_full') == 0) {
             // don't put anything in the content.
             $content = "";
             $description = trim($introduction);
             if (strlen($body) > 5) {
                 $description .= makeMoreLink($entry, '', array('html' => true));
                 $summary .= ' ...';
             }
         } else {
             // put the introduction and body in the content..
             $content = trim(str_replace("&nbsp;", " ", $introduction . $body));
             $description = trim($introduction . $body);
         }
         // Handling viatitle special to avoid validation errors
         if (!empty($entry['viatitle'])) {
             $viatitle = 'title="' . addslashes($entry['viatitle']) . '"';
         } else {
             $viatitle = "";
         }
         // Getting user information..
         $user = $PIVOTX['users']->getUser($entry['user']);
         if (!$user) {
             $user = array('username' => $entry['user'], 'email' => '', 'nickname' => $entry['user']);
         }
         // Setting the category display names
         $cat_display = array();
         foreach ($entry['category'] as $cat) {
             if (!empty($categories[$cat])) {
                 $cat_display[] = $categories[$cat];
             }
         }
         $replace = array("%title%" => htmlspecialchars(strip_tags($title)), "%subtitle%" => htmlspecialchars(strip_tags($subtitle)), "%link%" => $link, "%description%" => relativeToAbsoluteURLS($description), "%summary%" => relativeToAbsoluteURLS($summary), "%author%" => $user['username'], "%author-email%" => $user['email'], "%author-nick%" => $user['nickname'], "%guid%" => $entry['uid'] . "@" . str_replace('http://', '', $PIVOTX['paths']['canonical_host']) . $PIVOTX['paths']['site_url'], "%date%" => $date, "%edit_date%" => $edit_date, "%date_rfc%" => $date_rfc, "%category%" => htmlspecialchars(implode(", ", $cat_display)), "%categorynames%" => htmlspecialchars(implode(", ", $entry['category'])), "%content%" => relativeToAbsoluteURLS($content), "%tag%" => $tag, "%lang%" => $PIVOTX['languages']->getCode(), "%vialink%" => $PIVOTX['db']->entry['vialink'], "%viatitle%" => $viatitle);
         // Execute the 'feed_entry' hook, if present.
         $PIVOTX['extensions']->executeHook('feed_entry', $replace);
         // Replace all items in $replace, unless it's an empty array. This way the feed_entry
         // hook can set $replace to an empty array, in order to skip it entirely.
         if (!empty($replace)) {
             $feed .= str_replace(array_keys($replace), array_values($replace), $feed_template);
         }
     }
     return $feed;
 }