Ejemplo n.º 1
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 "";
    }
}
Ejemplo n.º 2
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();
    }
}