Пример #1
0
 /**
  * Check if the current version of the DB is updated to the latest version,
  * and update it if it isn't..
  *
  */
 function checkDBVersion()
 {
     global $PIVOTX, $dbversion;
     if ($PIVOTX['config']->get('db_version') >= $dbversion) {
         return;
     }
     $db_version = $PIVOTX['config']->get('db_version');
     $entriestable = safeString($PIVOTX['config']->get('db_prefix') . "entries", true);
     $categoriestable = safeString($PIVOTX['config']->get('db_prefix') . "categories", true);
     $commentstable = safeString($PIVOTX['config']->get('db_prefix') . "comments", true);
     $trackbackstable = safeString($PIVOTX['config']->get('db_prefix') . "trackbacks", true);
     $pagestable = safeString($PIVOTX['config']->get('db_prefix') . "pages", true);
     $extratable = safeString($PIVOTX['config']->get('db_prefix') . "extrafields", true);
     $tagstable = safeString($PIVOTX['config']->get('db_prefix') . "tags", true);
     // DB changes from PivotX 2.0 alpha 2 to alpha 3.
     if (intval($db_version) < 1) {
         debug("now updating DB to version 1..");
         // We need to set the URI's for all entries in the DB.
         $this->query("SELECT uid,title FROM {$entriestable}");
         while ($entry = $this->fetch_row()) {
             $uri = makeURI($entry['title']);
             $this->query("UPDATE {$entriestable} SET uri=" . $this->quote($uri) . " WHERE uid= " . $entry['uid']);
         }
         // Add fultext search for entries and pages..
         // $this->query("ALTER TABLE $entriestable ADD FULLTEXT(title, subtitle, introduction, body);");
         // $this->query("ALTER TABLE $pagestable ADD FULLTEXT(title, subtitle, introduction, body);");
         debug("Updated DB to version 1");
         $PIVOTX['config']->set('db_version', 1);
     }
     // DB changes introduced between Alpha 4 and Beta 1.
     if (intval($db_version) < 3) {
         debug("now updating DB to version 3..");
         // Add extrafields field for entries and pages..
         $this->query("CREATE TABLE {$extratable} (\n\t\t            uid INTEGER PRIMARY KEY,\n\t\t            contenttype TEXT NOT NULL,\n\t\t            target_uid INTEGER(11) NOT NULL DEFAULT 0,\n\t\t            fieldkey TEXT NOT NULL,\n\t\t            value TEXT NOT NULL\n\t\t          );");
         debug("Updated DB to version 3");
         $PIVOTX['config']->set('db_version', 3);
     }
     // DB changes from PivotX 2.0 beta 1 to beta 2.
     if (intval($db_version) < 4) {
         debug("now updating DB to version 4..");
         // Add fultext search for entries and pages..
         //$this->query("ALTER TABLE $entriestable DROP INDEX title;");
         //$this->query("ALTER TABLE $pagestable DROP INDEX title;");
         //$this->query("ALTER TABLE $entriestable ADD FULLTEXT(title, subtitle, introduction, body, keywords);");
         //$this->query("ALTER TABLE $pagestable ADD FULLTEXT(title, subtitle, introduction, body, keywords);");
         debug("Updated DB to version 4");
         $PIVOTX['config']->set('db_version', 4);
     }
     // DB changes for PivotX 2.0 RC 1d and up.
     if (intval($db_version) < 5) {
         // Add indices to speed up JOINs..
         //$this->query("ALTER TABLE $categoriestable ADD KEY `target_uid` (`target_uid`);");
         //$this->query("ALTER TABLE $commentstable ADD KEY `entry_uid` (`entry_uid`);");
         //$this->query("ALTER TABLE $commentstable ADD KEY `date` (`date`);");
         debug("Updated DB to version 5");
         $PIVOTX['config']->set('db_version', 5);
     }
     // DB changes for PivotX 2.1 and up.
     if (intval($db_version) < 6) {
         // Add column to store useragent for comments..
         //		        $this->query("ALTER TABLE $commentstable  ADD useragent TEXT NOT NULL AFTER ip;");
         $this->query("BEGIN TRANSACTION;");
         $this->query("CREATE TEMPORARY TABLE t1_backup (\n\t\t\t\t\t    \tuid INTEGER PRIMARY KEY,\n\t\t\t\t\t      entry_uid INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t\t      name TEXT NOT NULL,\n\t\t\t\t\t      email TEXT NOT NULL,\n\t\t\t\t\t      url TEXT NOT NULL,\n\t\t\t\t\t      ip TEXT NOT NULL,\n\t\t\t\t\t      date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t      comment TEXT NOT NULL,\n\t\t\t\t\t      registered INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t\t      notify INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t\t      discreet INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t\t      moderate INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t\t      spamscore INTEGER(4) NOT NULL DEFAULT 0\n\t\t\t\t\t    );");
         $this->query("INSERT INTO t1_backup SELECT uid,entry_uid,name,email,url,ip,date,comment,registered,notify,discreet,moderate,spamscore FROM {$commentstable};");
         $this->query("DROP TABLE {$commentstable};");
         $this->query("CREATE TABLE {$commentstable} (\n\t\t\t\t\t    \tuid INTEGER PRIMARY KEY,\n\t\t\t\t\t      entry_uid INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t\t      name TEXT NOT NULL,\n\t\t\t\t\t      email TEXT NOT NULL,\n\t\t\t\t\t      url TEXT NOT NULL,\n\t\t\t\t\t      ip TEXT NOT NULL,\n\t\t\t\t\t      useragent TEXT NOT NULL,\n\t\t\t\t\t      date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t      comment TEXT NOT NULL,\n\t\t\t\t\t      registered INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t\t      notify INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t\t      discreet INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t\t      moderate INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t\t      spamscore INTEGER(4) NOT NULL DEFAULT 0\n\t\t\t\t\t    );");
         $this->query("INSERT INTO {$commentstable} SELECT uid,entry_uid,name,email,url,ip,'',date,comment,registered,notify,discreet,moderate,spamscore FROM t1_backup;");
         $this->query("DROP TABLE t1_backup;");
         $this->query("COMMIT;");
         debug("Updated DB to version 6");
         $PIVOTX['config']->set('db_version', 6);
     }
     if (intval($db_version) < 7) {
         // Add column to store moderate for trackbacks..
         //$this->query("ALTER TABLE `$trackbackstable` ADD `moderate` TINYINT NOT NULL AFTER `excerpt` ;");
         $this->query("BEGIN TRANSACTION;");
         $this->query("CREATE TEMPORARY TABLE t1_backup (\n\t\t\t\t\t      uid INTEGER PRIMARY KEY,\n\t\t\t\t\t      entry_uid INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t\t      name TEXT NOT NULL,\n\t\t\t\t\t      title TEXT NOT NULL,\n\t\t\t\t\t      url TEXT NOT NULL,\n\t\t\t\t\t      ip TEXT NOT NULL,\n\t\t\t\t\t      date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t      excerpt TEXT NOT NULL,\n\t\t\t\t\t      spamscore INTEGER(4) NOT NULL default 0\n\t\t\t\t\t    \t);");
         $this->query("INSERT INTO t1_backup SELECT uid,entry_uid,name,title,url,ip,date,excerpt,spamscore FROM {$trackbackstable};");
         $this->query("DROP TABLE {$trackbackstable};");
         $this->query("CREATE TABLE {$trackbackstable} (\n\t\t\t\t\t      uid INTEGER PRIMARY KEY,\n\t\t\t\t\t      entry_uid INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t\t      name TEXT NOT NULL,\n\t\t\t\t\t      title TEXT NOT NULL,\n\t\t\t\t\t      url TEXT NOT NULL,\n\t\t\t\t\t      ip TEXT NOT NULL,\n\t\t\t\t\t      date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t      excerpt TEXT NOT NULL,\n\t\t\t\t\t      moderate INTEGER(4) NOT NULL default 0,\n\t\t\t\t\t      spamscore INTEGER(4) NOT NULL default 0\n\t\t\t\t\t    );");
         $this->query("INSERT INTO {$trackbackstable} SELECT uid,entry_uid,name,title,url,ip,date,excerpt,0,spamscore FROM t1_backup;");
         $this->query("DROP TABLE t1_backup;");
         $this->query("COMMIT;");
         debug("Updated DB to version 7");
         $PIVOTX['config']->set('db_version', 7);
     }
     if (intval($db_version) < 8) {
         // Add Indices to tags table...
         //$this->query("ALTER TABLE `$tagstable` ADD INDEX ( `target_uid` ) ;");
         //$this->query("ALTER TABLE `$tagstable` ADD INDEX ( `tag`(32) ) ;");
         debug("Updated DB to version 8");
         $PIVOTX['config']->set('db_version', 8);
     }
     if (intval($db_version) < 9) {
         // Add Indices to extrafields table...
         //$this->query("ALTER TABLE `$extratable` ADD INDEX ( `target_uid` ) ;");
         //$this->query("ALTER TABLE `$extratable` ADD INDEX ( `fieldkey`(16) ) ;");
         // Bob is a moran. Why in the name of sweet jeebus would someone ever define a column name like comment_COUNT as a tinytext. Sheeesh...
         //		        $this->query("ALTER TABLE  `$entriestable` CHANGE `comment_count` `comment_count` INT NOT NULL;");
         //		        $this->query("ALTER TABLE  `$entriestable` CHANGE `trackback_count` `trackback_count` INT NOT NULL;");
         $this->query("BEGIN TRANSACTION;");
         $this->query("CREATE TEMPORARY TABLE t1_backup (\n\t\t\t\t\t    \t uid INTEGER PRIMARY KEY,\t\t    \t \n\t\t\t\t\t\t\t\t title TEXT NOT NULL,\n\t\t\t\t\t       uri TEXT NOT NULL,\n\t\t\t\t\t\t\t\t subtitle TEXT NOT NULL,\n\t\t\t\t\t\t\t\t introduction TEXT NOT NULL,\n\t\t\t\t\t\t\t\t body TEXT NOT NULL,\n\t\t\t\t\t       convert_lb INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t\t\t\t\t status TEXT NOT NULL,\n\t\t\t\t\t\t\t\t date DATETIME NOT NULL,\n\t\t\t\t\t\t\t\t publish_date DATETIME NOT NULL,\n\t\t\t\t\t\t\t\t edit_date DATETIME NOT NULL,\n\t\t\t\t\t\t\t\t user TEXT NOT NULL,\n\t\t\t\t\t       allow_comments INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t\t\t\t\t keywords TEXT NOT NULL,\n\t\t\t\t\t\t\t\t via_link TEXT NOT NULL,\n\t\t\t\t\t\t\t\t via_title TEXT NOT NULL,\n\t\t\t\t\t\t\t\t comment_count INTEGER(11) NOT NULL,\n\t\t\t\t\t\t\t\t comment_names TEXT NOT NULL,\n\t\t\t\t\t\t\t\t trackback_count INTEGER(11) NOT NULL,\n\t\t\t\t\t\t\t\t trackback_names TEXT  NOT NULL,\n\t\t\t\t\t\t\t\t extrafields TEXT NOT NULL\n\t\t\t\t\t    \t);");
         $this->query("INSERT INTO t1_backup SELECT uid,title,uri,subtitle,introduction,body,convert_lb,status,date,publish_date,edit_date,user,allow_comments,keywords,via_link,via_title,comment_count,comment_names,trackback_count,trackback_names,extrafields FROM {$entriestable};");
         $this->query("DROP TABLE {$entriestable};");
         $this->query("CREATE TABLE {$entriestable} (\n\t\t\t\t\t    \t uid INTEGER PRIMARY KEY,\t\t    \t \n\t\t\t\t\t\t\t\t title TEXT NOT NULL,\n\t\t\t\t\t       uri TEXT NOT NULL,\n\t\t\t\t\t\t\t\t subtitle TEXT NOT NULL,\n\t\t\t\t\t\t\t\t introduction TEXT NOT NULL,\n\t\t\t\t\t\t\t\t body TEXT NOT NULL,\n\t\t\t\t\t       convert_lb INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t\t\t\t\t status TEXT NOT NULL,\n\t\t\t\t\t\t\t\t date DATETIME NOT NULL,\n\t\t\t\t\t\t\t\t publish_date DATETIME NOT NULL,\n\t\t\t\t\t\t\t\t edit_date DATETIME NOT NULL,\n\t\t\t\t\t\t\t\t user TEXT NOT NULL,\n\t\t\t\t\t       allow_comments INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t\t\t\t\t keywords TEXT NOT NULL,\n\t\t\t\t\t\t\t\t via_link TEXT NOT NULL,\n\t\t\t\t\t\t\t\t via_title TEXT NOT NULL,\n\t\t\t\t\t\t\t\t comment_count INTEGER(11) NOT NULL,\n\t\t\t\t\t\t\t\t comment_names TEXT NOT NULL,\n\t\t\t\t\t\t\t\t trackback_count INTEGER(11) NOT NULL,\n\t\t\t\t\t\t\t\t trackback_names TEXT  NOT NULL,\n\t\t\t\t\t\t\t\t extrafields TEXT NOT NULL\n\t\t\t\t\t    );");
         $this->query("INSERT INTO {$entriestable} SELECT uid,title,uri,subtitle,introduction,body,convert_lb,status,date,publish_date,edit_date,user,allow_comments,keywords,via_link,via_title,comment_count,comment_names,trackback_count,trackback_names,extrafields FROM t1_backup;");
         $this->query("DROP TABLE t1_backup;");
         $this->query("COMMIT;");
         debug("Updated DB to version 9");
         $PIVOTX['config']->set('db_version', 9);
     }
     if (intval($db_version) < 10) {
         // Add column to category for entrytypes..
         //		        $this->query("ALTER TABLE `$categoriestable` ADD `contenttype` TINYTEXT NOT NULL AFTER `uid` ;");
         //		        $this->query("UPDATE `$categoriestable` SET `contenttype` = 'entry' WHERE 1;");
         $this->query("BEGIN TRANSACTION;");
         $this->query("CREATE TEMPORARY TABLE t1_backup (\n\t\t\t\t      uid INTEGER PRIMARY KEY,\n\t\t\t\t      category TEXT NOT NULL,\n\t\t\t\t      target_uid INTEGER(11) NOT NULL DEFAULT '0'\n\t\t\t\t    \t);");
         $this->query("INSERT INTO t1_backup SELECT uid,category,target_uid FROM {$categoriestable};");
         $this->query("DROP TABLE {$categoriestable};");
         $this->query("CREATE TABLE {$categoriestable} (\n\t\t\t\t      uid INTEGER PRIMARY KEY,\n\t\t          contenttype TEXT NOT NULL,\n\t\t\t\t      category TEXT NOT NULL,\n\t\t\t\t      target_uid INTEGER(11) NOT NULL DEFAULT '0'\n\t\t\t\t    );");
         $this->query("INSERT INTO {$categoriestable} SELECT uid, 'entry', category, target_uid FROM t1_backup;");
         $this->query("DROP TABLE t1_backup;");
         $this->query("COMMIT;");
         // Add column to comments for entrytypes..
         //		        $this->query("ALTER TABLE `$commentstable` ADD `contenttype` TINYTEXT NOT NULL AFTER `uid` ;");
         //		        $this->query("UPDATE `$commentstable` SET `contenttype` = 'entry' WHERE 1;");
         $this->query("BEGIN TRANSACTION;");
         $this->query("CREATE TEMPORARY TABLE t1_backup (\n\t\t\t\t    \tuid INTEGER PRIMARY KEY,\n\t\t\t\t      entry_uid INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t      name TEXT NOT NULL,\n\t\t\t\t      email TEXT NOT NULL,\n\t\t\t\t      url TEXT NOT NULL,\n\t\t\t\t      ip TEXT NOT NULL,\n\t\t\t\t      useragent TEXT NOT NULL,\n\t\t\t\t      date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t      comment TEXT NOT NULL,\n\t\t\t\t      registered INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t      notify INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t      discreet INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t      moderate INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t      spamscore INTEGER(4) NOT NULL DEFAULT 0\n\t\t\t\t    \t);");
         $this->query("INSERT INTO t1_backup SELECT uid,entry_uid,name,email,url,ip,useragent,date,comment,registered,notify,discreet,moderate,spamscore FROM {$commentstable};");
         $this->query("DROP TABLE {$commentstable};");
         $this->query("CREATE TABLE {$commentstable} (\n\t\t\t\t    \tuid INTEGER PRIMARY KEY,\n\t\t      \t\tcontenttype TEXT NOT NULL,\n\t\t\t\t      entry_uid INTEGER(11) NOT NULL DEFAULT 0,\n\t\t\t\t      name TEXT NOT NULL,\n\t\t\t\t      email TEXT NOT NULL,\n\t\t\t\t      url TEXT NOT NULL,\n\t\t\t\t      ip TEXT NOT NULL,\n\t\t\t\t      useragent TEXT NOT NULL,\n\t\t\t\t      date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t      comment TEXT NOT NULL,\n\t\t\t\t      registered INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t      notify INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t      discreet INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t      moderate INTEGER(4) NOT NULL DEFAULT 0,\n\t\t\t\t      spamscore INTEGER(4) NOT NULL DEFAULT 0\n\t\t\t\t    );");
         $this->query("INSERT INTO {$commentstable} SELECT uid,'entry',entry_uid,name,email,url,ip,useragent,date,comment,registered,notify,discreet,moderate,spamscore FROM t1_backup;");
         $this->query("DROP TABLE t1_backup;");
         $this->query("COMMIT;");
         debug("Updated DB to version 10");
         $PIVOTX['config']->set('db_version', 10);
     }
     if (intval($db_version) < 11) {
         // Add indexes to extrafields..
         // This is a huge performance improvement when you query a lot of extrafields
         //$this->query("ALTER TABLE `$extratable` ADD INDEX (  `target_uid` );");
         // Most fields differ so we want a fulltext here
         //$this->query("ALTER TABLE `$extratable` ADD FULLTEXT (`value`);");
         debug("Updated DB to version 11");
         $PIVOTX['config']->set('db_version', 11);
     }
 }
Пример #2
0
/**
 * Make a link to any given $tag.
 *
 * @param string $tag
 * @param string $template
 * @return string
 */
function tagLink($tag, $template = "")
{
    global $PIVOTX;
    $Current_weblog = $PIVOTX['weblogs']->getCurrent();
    $tag = normalizeTag($tag);
    $site_url = getDefault($PIVOTX['weblogs']->get($Current_weblog, 'site_url'), $PIVOTX['paths']['site_url']);
    if ($PIVOTX['config']->get('mod_rewrite') == 0) {
        $link = $site_url . "?t=" . urlencode($tag);
        if (paraWeblogNeeded($Current_weblog)) {
            $link .= "&amp;w=" . para_weblog($Current_weblog);
        }
        if ($template != "") {
            $link .= "&amp;t={$template}";
        }
    } else {
        $prefix = getDefault($PIVOTX['config']->get('localised_tag_prefix'), 'tag');
        $link = $site_url . makeURI($prefix) . '/' . urlencode($tag);
        if (paraWeblogNeeded($Current_weblog)) {
            $link .= "/" . para_weblog($Current_weblog);
        }
        if ($template != "") {
            $link .= "/?t={$template}";
        }
    }
    // Check if there's a hook set, and if so call it.
    if ($PIVOTX['extensions'] && $PIVOTX['extensions']->hasHook('make_link#tag')) {
        $PIVOTX['extensions']->executeHook('make_link#tag', $link, array('tag' => $tag, 'w' => $Current_weblog));
    }
    return $link;
}
Пример #3
0
/**
 * Create a piece of HTML with links to the latest comments.
 *
 * @param array $params
 * @return string
 */
function smarty_latest_comments($params)
{
    global $PIVOTX;
    $params = cleanParams($params);
    $latest_comments_format = getDefault($params['format'], "<a href='%url%' title='%date%'><b>%name%</b></a> (%title%): %comm%<br />");
    $latest_comments_length = getDefault($params['length'], 100);
    $latest_comments_trim = getDefault($params['trim'], 16);
    $latest_comments_count = getDefault($params['count'], 6);
    $toread_comments_count = $latest_comment_count * 2;
    if ($toread_comments_count < 50) {
        $toread_comments_count = 50;
    }
    if (!empty($params['category']) && $params['category'] != "*") {
        $cats = explode(",", safeString($params['category']));
        $cats = array_map("trim", $cats);
    } else {
        if ($PIVOTX['db']->db_type == 'flat') {
            $cats = $PIVOTX['weblogs']->getCategories();
        } else {
            // Don't filter on cats by default, as it is _very_
            // bad for SQL performance.
            $cats = array();
        }
    }
    $comments = $PIVOTX['db']->read_latestcomments(array('cats' => $cats, 'count' => $toread_comments_count, 'moderated' => 1));
    // Adding the filter that we ignored because of SQL performance problems.
    if (empty($params['category']) && $PIVOTX['db']->db_type != 'flat') {
        $cats = $PIVOTX['weblogs']->getCategories();
        $com_db = new db(false);
        foreach ($comments as $key => $comment) {
            $entry = $com_db->read_entry($comment['entry_uid']);
            $comments[$key]['category'] = $entry['category'];
        }
    }
    $output = '';
    $count = 0;
    // Initialise the IP blocklist.
    $blocklist = new IPBlock();
    $weblog = $PIVOTX['weblogs']->getWeblog();
    if (count($comments) > 0) {
        foreach ($comments as $comment) {
            // if it's in a category that's published on the frontpage, and the user is not blocked, we display it.
            if ((empty($comment['category']) || count(array_intersect($comment['category'], $cats)) > 0 || !empty($params['category'])) && !$blocklist->isBlocked(trim($comment['ip']))) {
                $id = makeURI(html_entity_decode($comment['name'], ENT_COMPAT, 'UTF-8')) . "-" . formatDate($comment["date"], "%ye%%month%%day%%hour24%%minute%");
                $url = makeFileLink($comment['entry_uid'], '', $id);
                $comment['name'] = trimText(stripslashes($comment['name']), $latest_comments_trim);
                $comment['title'] = trimText(stripslashes($comment['title']), $latest_comments_trim);
                $comment['comment'] = commentFormat($comment["comment"]);
                // Remove the [name:1] part in the 'latest comments'..
                $comment['comment'] = preg_replace("/\\[(.*):([0-9]+)\\]/iU", '', $comment['comment']);
                $comment['comment'] = trimText(stripslashes($comment['comment']), $latest_comments_length);
                $comment['comment'] = wordwrapHTMLEntities($comment['comment'], 26, ' ', true);
                if ($weblog['comment_pop'] == 1) {
                    $popup = sprintf("onclick=\"window.open('%s', 'popuplink', 'width=%s,height=%s,directories=no,location=no,scrollbars=yes,menubar=no,status=yes,toolbar=no,resizable=yes'); return false\"", $url, $weblog['comment_width'], $weblog['comment_height']);
                } else {
                    $popup = '';
                }
                $thisline = $latest_comments_format;
                $thisline = str_replace("%name%", $comment['name'], $thisline);
                $thisline = str_replace("%date%", $comment['date'], $thisline);
                $thisline = str_replace("%title%", $comment['title'], $thisline);
                $thisline = str_replace("%url%", $url, $thisline);
                $thisline = str_replace("%popup%", $popup, $thisline);
                $thisline = str_replace("%comm%", $comment['comment'], $thisline);
                $thisline = formatDate($comment["date"], $thisline);
                $output .= "\n" . $thisline;
                $count++;
                if ($count >= $latest_comments_count) {
                    break;
                }
            }
        }
    }
    return entifyAmpersand($output);
}
Пример #4
0
 /**
  * Creates a feed of comments.
  *
  * @todo Do not display comments that haven't been moderated/approved.
  * @param string $feed_template
  * @param array $comment
  * @return string
  */
 function _renderFeedComments($feed_template, $amount = 10, $comments)
 {
     global $PIVOTX;
     $i = 0;
     $feed_items = "";
     // Loop through the comments..
     foreach ($comments as $comment) {
         $tag = safeString($PIVOTX['config']->get('sitename'), TRUE) . "," . date("Y") . ":" . safeString($PIVOTX['weblogs']->get('', 'name'), TRUE);
         $tag .= '.entry%uid%.comment' . $i;
         $tag = str_replace("_", "", strtolower($tag));
         $date = formatDate($comment['date'], "%year%-%month%-%day%T%hour24%:%minute%:00") . $this->_rssOffset();
         $date_rfc = formatDate($comment['date'], "%english_dname%, %day% %english_monname% %year% %hour24%:%minute%:00 ") . $this->_rssOffset("rfc822");
         $summary = unentify(strip_tags($comment['comment']));
         $summary = trim(str_replace("&", "&amp;", str_replace("&nbsp;", " ", $summary)));
         $summary = relativeToAbsoluteURLS($summary);
         if (strlen($summary) > 32) {
             $title = substr($summary, 0, 35) . '...';
         } else {
             $title = $summary;
         }
         // Make the link..
         $id = makeURI(html_entity_decode($comment['name'], ENT_COMPAT, 'UTF-8')) . "-" . formatDate($comment['date'], "%ye%%month%%day%%hour24%%minute%");
         $url = makeFileURL($comment['entry_uid'], '', $id);
         $replace = array("%title%" => htmlspecialchars(strip_tags($title)), "%link%" => $url, "%summary%" => $summary, "%content%" => $summary, "%description%" => $summary, "%author%" => $comment['name'], "%guid%" => $url, "%date%" => $date, "%date_rfc%" => $date_rfc, "%tag%" => $tag, "%lang%" => smarty_lang());
         // Execute the 'feed_comment' hook, if present.
         $PIVOTX['extensions']->executeHook('feed_comment', $replace);
         // Replace all items in $replace, unless it's an empty array. This way the feed_comment
         // hook can set $replace to an empty array, in order to skip it entirely.
         if (!empty($replace)) {
             $item = str_replace(array_keys($replace), array_values($replace), $feed_template);
             // Handling email and url separately.
             if (isEmail($comment['email'])) {
                 $item = str_replace('%author-email%', $comment['email'], $item);
             } else {
                 $item = str_replace('<email>%author-email%</email>', '', $item);
             }
             if (isUrl($comment['url'])) {
                 if (strpos($comment["url"], "ttp://") < 1) {
                     $comment["url"] = "http://" . $comment["url"];
                 }
                 $item = str_replace('%author-link%', $comment['url'], $item);
             } else {
                 $item = str_replace('<uri>%author-link%</uri>', '', $item);
             }
             $feed_items .= $item;
         }
     }
     return $feed_items;
 }
Пример #5
0
 function DataTree($table, $options, $fields)
 {
     if (!isset($options['nouns']['top'])) {
         $this->title = 'Не задано поле иерархии';
         return '<p>Пожалуйста, укажите поле иерахии для таблицы «' . $table . '». Это поле используется для соотношения подразделов к разделам, как правило, называется top, parent и т.д. Задается в секции «nouns» аргументов метода DataTree.</p>';
     }
     //Собираем данные о полях таблицы
     $syscolumns = $this->TableColumns($table);
     $deleted_field_exist = false;
     if (isset($options['nouns']['deleted'])) {
         foreach ($syscolumns as $i) {
             if ($i['Field'] == $options['nouns']['deleted']) {
                 $deleted_field_exist = true;
             }
         }
     }
     //Добавление
     if (isset($_GET['create'])) {
         //Фикс для if_empty_make_uri
         $insert_uri_fields = '';
         $insert_uri_values = '';
         foreach ($fields as $field => $helpers) {
             if (isset($helpers['if_empty_make_uri']) && $helpers['if_empty_make_uri'] == $options['nouns']['name']) {
                 $insert_uri_fields .= ', `' . $field . '`';
                 $insert_uri_values .= ", '" . q(makeURI($_POST['name'])) . "'";
             }
         }
         //$id = (int)$_POST['id'];
         $name = $_POST['name'];
         $ref_id = (int) $_POST['ref_id'];
         switch ($_POST['type']) {
             case 'before':
                 $new_top = $this->db->rows("SELECT `" . $options['nouns']['top'] . "` FROM `prefix_{$table}` WHERE `id` = {$ref_id}");
                 $new_top = $new_top[0][0];
                 $this->db->query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t`" . $options['nouns']['id'] . "`,\n\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "`\n\t\t\t\t\t\tFROM `prefix_{$table}`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$new_top}\n\t\t\t\t\t\tORDER BY `" . $options['nouns']['order'] . "`\n\t\t\t\t\t");
                 $branch = array();
                 while ($i = $this->db->fetch()) {
                     $branchItems[$i[$options['nouns']['id']]] = $i[$options['nouns']['order']];
                 }
                 //Расчет будущего порядка order
                 //$branchItems[0] = $branchItems[$ref_id] - 0.5;
                 asort($branchItems);
                 $i = 0;
                 foreach ($branchItems as $k => $v) {
                     if ($k == $ref_id) {
                         $this->db->query("\n\t\t\t\t\t\t\t\tINSERT INTO `prefix_{$table}`\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t`" . $options['nouns']['name'] . "`,\n\t\t\t\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "`,\n\t\t\t\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "`,\n\t\t\t\t\t\t\t\t\t\t`" . $options['nouns']['created'] . "`\n\t\t\t\t\t\t\t\t\t\t{$insert_uri_fields}\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t\t'" . q($name) . "',\n\t\t\t\t\t\t\t\t\t" . $i++ . ",\n\t\t\t\t\t\t\t\t\t{$new_top},\n\t\t\t\t\t\t\t\t\tNOW()\n\t\t\t\t\t\t\t\t\t{$insert_uri_values}\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t");
                         echo $this->db->last_insert_id();
                     }
                     $this->db->query("\n\t\t\t\t\t\t\tUPDATE `prefix_{$table}`\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$new_top},\n\t\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "` = " . $i++ . "\n\t\t\t\t\t\t\tWHERE `" . $options['nouns']['id'] . "` = {$k}\n\t\t\t\t\t\t");
                 }
                 break;
             case 'after':
                 $new_top = $this->db->rows("SELECT `" . $options['nouns']['top'] . "` FROM `prefix_{$table}` WHERE `id` = {$ref_id}");
                 $new_top = $new_top[0][0];
                 $this->db->query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t`" . $options['nouns']['id'] . "`,\n\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "`\n\t\t\t\t\t\tFROM `prefix_{$table}`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$new_top}\n\t\t\t\t\t\tORDER BY `" . $options['nouns']['order'] . "`\n\t\t\t\t\t");
                 $branch = array();
                 while ($i = $this->db->fetch()) {
                     $branchItems[$i[$options['nouns']['id']]] = $i[$options['nouns']['order']];
                 }
                 //Расчет будущего порядка order
                 //$branchItems[0] = $branchItems[$ref_id] - 0.5;
                 asort($branchItems);
                 $i = 0;
                 foreach ($branchItems as $k => $v) {
                     if ($k == $ref_id) {
                         $this->db->query("\n\t\t\t\t\t\t\t\tINSERT INTO `prefix_{$table}`\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t`" . $options['nouns']['name'] . "`,\n\t\t\t\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "`,\n\t\t\t\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "`,\n\t\t\t\t\t\t\t\t\t\t`" . $options['nouns']['created'] . "`\n\t\t\t\t\t\t\t\t\t\t{$insert_uri_fields}\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t\t'" . q($name) . "',\n\t\t\t\t\t\t\t\t\t" . (2 + $i++) . ",\n\t\t\t\t\t\t\t\t\t{$new_top},\n\t\t\t\t\t\t\t\t\tNOW()\n\t\t\t\t\t\t\t\t\t{$insert_uri_values}\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t");
                         echo $this->db->last_insert_id();
                     }
                     $this->db->query("\n\t\t\t\t\t\t\tUPDATE `prefix_{$table}`\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$new_top},\n\t\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "` = " . $i++ . "\n\t\t\t\t\t\t\tWHERE `" . $options['nouns']['id'] . "` = {$k}\n\t\t\t\t\t\t");
                 }
                 break;
             case 'inside':
                 $this->db->query("\n\t\t\t\t\t\tINSERT INTO `prefix_{$table}`\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t`" . $options['nouns']['name'] . "`,\n\t\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "`,\n\t\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "`,\n\t\t\t\t\t\t\t\t`" . $options['nouns']['created'] . "`\n\t\t\t\t\t\t\t\t{$insert_uri_fields}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t'" . q($name) . "',\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t{$ref_id},\n\t\t\t\t\t\t\tNOW()\n\t\t\t\t\t\t\t{$insert_uri_values}\n\t\t\t\t\t\t)\n\t\t\t\t\t");
                 echo $this->db->last_insert_id();
                 break;
         }
         exit;
     }
     //Удаление
     if (isset($_GET['delete'])) {
         $id = (int) $_POST['id'];
         //Собираем внутренние топики для удаления
         $recDelTopics = function ($topic_id, $options, $table, $recDelTopics) {
             $db = db();
             $topics_id = array();
             $db->query("SELECT `{$options['nouns']['id']}` FROM `prefix_{$table}` WHERE `{$options['nouns']['top']}` = {$topic_id}");
             while ($i = $db->fetch()) {
                 $topics_id[] = $i[$options['nouns']['id']];
                 $topics_id = array_merge($topics_id, $recDelTopics($i[$options['nouns']['id']], $options, $table, $recDelTopics));
             }
             return $topics_id;
         };
         $toDelTopics = $recDelTopics($id, $options, $table, $recDelTopics);
         //Добавляем указанный верхний к удалению
         $toDelTopics[] = $id;
         //Удаление топиков
         if ($deleted_field_exist) {
             $this->db->query("UPDATE `prefix_{$table}` SET `{$options['nouns']['deleted']}` = 'Y' WHERE `{$options['nouns']['id']}` IN (" . implode(',', $toDelTopics) . ")");
         } else {
             $this->db->query("DELETE FROM `prefix_{$table}` WHERE `{$options['nouns']['id']}` IN (" . implode(',', $toDelTopics) . ")");
         }
         //Удаление записей подопечной таблицы
         if (isset($options['inner']['table'])) {
             if (isset($options['inner']['deleted'])) {
                 $this->db->query("UPDATE `prefix_{$options['inner']['table']}` SET `{$options['inner']['deleted']}` = 'Y' WHERE `{$options['inner']['top_key']}` IN (" . implode(',', $toDelTopics) . ")");
             } else {
                 $this->db->query("DELETE FROM `prefix_{$options['inner']['table']}` WHERE `{$options['inner']['top_key']}` IN (" . implode(',', $toDelTopics) . ")");
             }
         }
         exit;
     }
     //Переименование
     if (isset($_GET['rename'])) {
         //Фикс для if_empty_make_uri
         $update_uri_fields = '';
         foreach ($fields as $field => $helpers) {
             if (isset($helpers['if_empty_make_uri']) && $helpers['if_empty_make_uri'] == $options['nouns']['name']) {
                 $update_uri_fields .= ", `{$field}` = '" . makeURI($_POST['name']) . "'";
             }
         }
         $id = (int) $_POST['id'];
         $name = $_POST['name'];
         $this->db->query("\n\t\t\t\tUPDATE `prefix_{$table}`\n\t\t\t\tSET\n\t\t\t\t\t`" . $options['nouns']['name'] . "` = '" . q($name) . "'\n\t\t\t\t\t{$update_uri_fields}\n\t\t\t\tWHERE `" . $options['nouns']['id'] . "` = {$id}\n\t\t\t");
         exit;
     }
     //Смена сортировки или перемещение
     if (isset($_GET['move'])) {
         $id = (int) $_POST['id'];
         $ref_id = (int) $_POST['ref_id'];
         switch ($_POST['type']) {
             case 'before':
                 $new_top = $this->db->rows("SELECT `" . $options['nouns']['top'] . "` FROM `prefix_{$table}` WHERE `id` = {$ref_id}");
                 $new_top = $new_top[0][0];
                 $this->db->query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t`" . $options['nouns']['id'] . "`,\n\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "`\n\t\t\t\t\t\tFROM `prefix_{$table}`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$new_top}\n\t\t\t\t\t\tORDER BY `" . $options['nouns']['order'] . "`\n\t\t\t\t\t");
                 $branch = array();
                 while ($i = $this->db->fetch()) {
                     $branchItems[$i[$options['nouns']['id']]] = $i[$options['nouns']['order']];
                 }
                 //Вставка итема, который мы переносим (-0.5 как бы намекает что перед нужным итемом)
                 $branchItems[$id] = $branchItems[$ref_id] - 0.5;
                 asort($branchItems);
                 $i = 0;
                 foreach ($branchItems as $k => $v) {
                     $this->db->query("\n\t\t\t\t\t\t\tUPDATE `prefix_{$table}`\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$new_top},\n\t\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "` = " . $i++ . "\n\t\t\t\t\t\t\tWHERE `" . $options['nouns']['id'] . "` = {$k}\n\t\t\t\t\t\t");
                 }
                 break;
             case 'after':
                 $new_top = $this->db->rows("SELECT `" . $options['nouns']['top'] . "` FROM `prefix_{$table}` WHERE `id` = {$ref_id}");
                 $new_top = $new_top[0][0];
                 $this->db->query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t`" . $options['nouns']['id'] . "`,\n\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "`\n\t\t\t\t\t\tFROM `prefix_{$table}`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$new_top}\n\t\t\t\t\t\tORDER BY `" . $options['nouns']['order'] . "`\n\t\t\t\t\t");
                 $branch = array();
                 while ($i = $this->db->fetch()) {
                     $branchItems[$i[$options['nouns']['id']]] = $i[$options['nouns']['order']];
                 }
                 //Вставка итема, который мы переносим (+0.5 как бы намекает что после нужного итема)
                 $branchItems[$id] = $branchItems[$ref_id] + 0.5;
                 asort($branchItems);
                 $i = 0;
                 foreach ($branchItems as $k => $v) {
                     $this->db->query("\n\t\t\t\t\t\t\tUPDATE `prefix_{$table}`\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$new_top},\n\t\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "` = " . $i++ . "\n\t\t\t\t\t\t\tWHERE `" . $options['nouns']['id'] . "` = {$k}\n\t\t\t\t\t\t");
                 }
                 break;
             case 'inside':
                 $this->db->query("\n\t\t\t\t\t\tUPDATE `prefix_{$table}`\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`" . $options['nouns']['top'] . "` = {$ref_id},\n\t\t\t\t\t\t\t`" . $options['nouns']['order'] . "` = 0\n\t\t\t\t\t\tWHERE `" . $options['nouns']['id'] . "` = {$id}\n\t\t\t\t\t");
                 break;
         }
         exit;
     }
     //JSON для дерева
     if (isset($_GET['json'])) {
         //Строим дерево
         if (isset($options['nouns']['order'])) {
             $order = $options['nouns']['order'];
         } else {
             $order = $options['nouns']['id'];
         }
         $where = '';
         if ($deleted_field_exist) {
             $where .= " AND `{$options['nouns']['deleted']}` = 'N'";
         }
         $this->db->query("SELECT * FROM `prefix_{$table}` WHERE 1 {$where} ORDER BY `{$order}`");
         $branches = array();
         while ($i = $this->db->fetch()) {
             $branches[$i[$options['nouns']['top']]][$i[$options['nouns']['id']]] = $i;
             $tree_list[$i[$options['nouns']['id']]] = $i;
         }
         //Количества подопечной таблицы
         if (isset($options['inner']['table']) && isset($options['inner']['top_key'])) {
             if (isset($options['inner']['deleted'])) {
                 $inner_where = "AND `" . $options['inner']['deleted'] . "` = 'N'";
             } else {
                 $inner_where = '';
             }
             $this->db->query("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`" . $options['inner']['top_key'] . "`,\n\t\t\t\t\t\tCOUNT(*) AS `counts`\n\t\t\t\t\tFROM `prefix_" . $options['inner']['table'] . "`\n\t\t\t\t\tWHERE 1 {$inner_where}\n\t\t\t\t\tGROUP BY `" . $options['inner']['top_key'] . "`");
             $innerList = array();
             while ($i = $this->db->fetch()) {
                 $innerList[$i[$options['inner']['top_key']]] = $i['counts'];
             }
         }
         function treeBuild($branches, $options, $branch_id = 0, $innerList = array())
         {
             $branch = array();
             foreach ($branches[$branch_id] as $b) {
                 //Количества подопечной таблицы
                 if (isset($options['inner']['table']) && isset($options['inner']['top_key'])) {
                     if (isset($innerList[$b[$options['nouns']['id']]]) && $innerList[$b[$options['nouns']['id']]] > 0) {
                         $add_count = ' (' . $innerList[$b[$options['nouns']['id']]] . ')';
                     } else {
                         $add_count = '';
                     }
                 } else {
                     $add_count = '';
                 }
                 //Если запись — узел (ветка)
                 if (isset($branches[$b[$options['nouns']['id']]])) {
                     $branch[] = array('data' => array('title' => $b[$options['nouns']['name']] . $add_count, 'attributes' => array('id' => 't' . $b[$options['nouns']['id']])), 'children' => treeBuild($branches, $options, $b[$options['nouns']['id']], $innerList));
                 } else {
                     $branch[] = array('data' => array('title' => $b[$options['nouns']['name']] . $add_count, 'attributes' => array('id' => 't' . $b[$options['nouns']['id']])));
                 }
             }
             return $branch;
         }
         $tree = treeBuild($branches, $options, 0, $innerList);
         $json_tree = json_encode($tree);
         echo $json_tree;
         exit;
     }
     if (isset($options['controls'])) {
         $listLink = $options['controls']['list'];
     } else {
         $listLink = '';
     }
     $tree_html = tpl('widgets/tree', array('table' => $table, 'link' => $this->GetLink(), 'listLink' => $listLink));
     //Форма добавления/редактирования jQueryUI
     $edit = $this->DataTable_AddEdit($_SERVER['REQUEST_URI'], $table, $options, NULL, $fields);
     return $tree_html . $edit;
 }
Пример #6
0
 function update_index($update = TRUE)
 {
     global $PIVOTX;
     $this->check_current_index();
     if (strlen($this->entry['title']) > 1) {
         $title = $this->entry['title'];
         $title = strip_tags($title);
     } else {
         $title = substr($this->entry['introduction'], 0, 300);
         $title = strip_tags($title);
         $title = str_replace("\n", "", $title);
         $title = str_replace("\r", "", $title);
         $title = substr($title, 0, 60);
     }
     // Make sure we have an URI. Old (converted from 1.x) entries don't have them, so we make them.
     if (empty($this->entry['uri'])) {
         $this->entry['uri'] = makeURI($this->entry['title']);
     }
     $size = strlen($this->entry['introduction']) + strlen($this->entry['body']);
     unset($commnames);
     if (isset($this->entry['comments'])) {
         // Initialise the IP blocklist.
         $blocklist = new IPBlock();
         foreach ($this->entry['comments'] as $comment) {
             if (!$blocklist->isBlocked($comment['ip'])) {
                 if ($comment['moderate'] != 1) {
                     $commnames[] = stripslashes($comment['name']);
                 } else {
                     // if moderation is on, we add the name as '-'..
                     $commnames[] = '-';
                 }
             }
         }
         if (isset($commnames) && count($commnames) > 0) {
             $this->entry['commnames'] = implode(", ", array_unique($commnames));
             $commcount = count($commnames);
         } else {
             $this->entry['commnames'] = "";
             $commcount = 0;
         }
     } else {
         unset($this->entry['comments']);
         $commcount = 0;
         $this->entry['commnames'] = "";
     }
     $this->entry['commcount'] = $commcount;
     if ($commcount == 0) {
         $commcount_str = __('No comments');
     } else {
         if ($commcount == 1) {
             $commcount_str = __('%num% comment');
         } else {
             $commcount_str = __('%num% comments');
         }
     }
     $this->entry['commcount_str'] = str_replace("%num%", $PIVOTX['locale']->getNumber($commcount), $commcount_str);
     $this->entry['commcount_str'] = str_replace("%n%", $commcount, $commcount_str);
     unset($tracknames);
     if (isset($this->entry['trackbacks'])) {
         foreach ($this->entry['trackbacks'] as $trackback) {
             $tracknames[] = stripslashes($trackback['name']);
         }
         if (isset($tracknames) && count($tracknames) > 0) {
             $this->entry['tracknames'] = implode(", ", array_unique($tracknames));
             $trackcount = count($tracknames);
         } else {
             $this->entry['tracknames'] = "";
             $trackcount = 0;
         }
     } else {
         unset($this->entry['trackbacks']);
         $trackcount = 0;
         $this->entry['tracknames'] = "";
     }
     $this->entry['trackcount'] = $trackcount;
     if ($trackcount == 0) {
         $trackcount_str = __('No trackbacks');
     } else {
         if ($trackcount == 1) {
             $trackcount_str = __('%num% trackback');
         } else {
             $trackcount_str = __('%num% trackbacks');
         }
     }
     $this->entry['trackcount_str'] = str_replace("%num%", $PIVOTX['locale']->getNumber($trackcount), $trackcount_str);
     $this->entry['trackcount_str'] = str_replace("%n%", $trackcount, $trackcount_str);
     if (!isset($this->entry['status'])) {
         $this->entry['status'] = 'publish';
     }
     $this->entry['excerpt'] = makeExcerpt($this->entry['introduction']);
     // Remove non-existing categories from entry before indexing
     if (count($this->all_cats) > 0) {
         $category = array_values(array_intersect($this->all_cats, $this->entry['category']));
     } else {
         $category = $this->entry['category'];
     }
     if (is_array($this->entry['extrafields'])) {
         $extrafields = array_keys($this->entry['extrafields']);
     } else {
         $extrafields = array();
     }
     $index_line = array('code' => $this->entry['code'], 'date' => addslashes($this->entry['date']), 'user' => $this->entry['user'], 'title' => addslashes($title), 'uri' => $this->entry['uri'], 'size' => $size, 'commcount' => $this->entry['commcount'], 'cnames' => $this->entry['commnames'], 'trackcount' => $this->entry['trackcount'], 'tnames' => $this->entry['tracknames'], 'category' => $category, 'extrafields' => $extrafields, 'status' => $this->entry['status'], 'excerpt' => $this->entry['excerpt']);
     if ($this->entry['code'] != "") {
         $this->entry_index[$this->entry['code']] = $index_line;
         $this->date_index[$this->entry['code']] = $this->entry['date'];
         $this->cat_index[$this->entry['code']] = $category;
         $this->uri_index[$this->entry['code']] = $this->entry['uri'];
     }
     if ($update) {
         $this->updated = TRUE;
     }
 }
Пример #7
0
 /**
  * Saves the current entry - sql implementation.
  *
  * Returns true if successfully saved. Current implementation
  * seems to return true no matter what...
  *
  * @param boolean $update_index Whether to update the date index.
  * @return boolean
  */
 function save_entry($update_index = TRUE)
 {
     // Set the 'commcount', 'commnames'..
     unset($commnames);
     if (isset($this->entry['comments'])) {
         // Initialise the IP blocklist.
         $blocklist = new IPBlock();
         foreach ($this->entry['comments'] as $comment) {
             if (!$blocklist->isBlocked($comment['ip'])) {
                 if ($comment[moderate] != 1) {
                     $commnames[] = stripslashes($comment['name']);
                 } else {
                     // if moderation is on, we add the name as '-'..
                     $commnames[] = '-';
                 }
             }
         }
         if (isset($commnames) && count($commnames) > 0) {
             $this->entry['comment_names'] = implode(", ", array_unique($commnames));
             $this->entry['comment_count'] = count($commnames);
         } else {
             $this->entry['comment_names'] = "";
             $this->entry['comment_count'] = 0;
         }
     } else {
         unset($this->entry['comments']);
         $this->entry['comment_names'] = "";
         $this->entry['comment_count'] = 0;
     }
     // Set the 'trackcount', 'tracknames'..
     unset($tracknames);
     if (isset($this->entry['trackbacks'])) {
         foreach ($this->entry['trackbacks'] as $trackback) {
             $tracknames[] = stripslashes($trackback['name']);
         }
         if (isset($tracknames) && count($tracknames) > 0) {
             $this->entry['trackback_names'] = implode(", ", array_unique($tracknames));
             $this->entry['trackback_count'] = count($tracknames);
         } else {
             $this->entry['trackback_names'] = "";
             $this->entry['trackback_count'] = 0;
         }
     } else {
         unset($this->entry['trackbacks']);
         $this->entry['trackback_names'] = "";
         $this->entry['trackback_count'] = 0;
     }
     // Make sure we have an URI
     if (empty($this->entry['uri'])) {
         $this->entry['uri'] = makeURI($this->entry['title']);
     }
     $values = array('title' => $this->entry['title'], 'uri' => $this->entry['uri'], 'subtitle' => $this->entry['subtitle'], 'introduction' => $this->entry['introduction'], 'body' => $this->entry['body'], 'convert_lb' => intval($this->entry['convert_lb']), 'status' => $this->entry['status'], 'date' => $this->entry['date'], 'publish_date' => $this->entry['publish_date'], 'edit_date' => date("Y-m-d H:i:s", getCurrentDate()), 'user' => $this->entry['user'], 'allow_comments' => $this->entry['allow_comments'], 'keywords' => $this->entry['keywords'], 'via_link' => $this->entry['vialink'], 'via_title' => $this->entry['viatitle'], 'comment_count' => $this->entry['comment_count'], 'comment_names' => $this->entry['comment_names'], 'trackback_count' => $this->entry['trackback_count'], 'trackback_names' => $this->entry['trackback_names'], 'extrafields' => $this->entry['extrafields']);
     // Check if the entry exists
     $this->sql->query("SELECT uid FROM " . $this->entriestable . " WHERE uid=" . intval($this->entry['uid']));
     if (is_array($this->sql->fetch_row())) {
         // It exists, we do an update..
         $qry = array();
         $qry['update'] = $this->entriestable;
         $qry['value'] = $values;
         $qry['where'] = "uid=" . intval($this->entry['uid']);
         $this->sql->build_update($qry);
         $this->sql->query();
     } else {
         // New entry.
         // Add the UID to the values array if it is already set (for
         // example when importing entries).
         if ($this->entry['uid'] != '') {
             $values['uid'] = $this->entry['uid'];
         }
         $qry = array();
         $qry['into'] = $this->entriestable;
         $qry['value'] = $values;
         $this->sql->build_insert($qry);
         $this->sql->query();
         // Set the UID to the last inserted ID if it isn't already set
         // (which is normally the case for new entries).
         if ($this->entry['uid'] == '') {
             $this->entry['uid'] = $this->sql->get_last_id();
         }
         // A bit of a nasty hack, but needed when we have to insert tags for a new entry,
         // and $db is not yet aware of the new $uid.
         $GLOBALS['db']->entry['uid'] = $this->entry['uid'];
     }
     // We will also need to save the comments and trackbacks.. We should
     // try to prevent doing unneeded queries, so we only insert comments
     // and trackbacks which have no ['uid'] yet. (because these are either
     // new, or are being converted from flat files)
     if (!empty($this->entry['comments'])) {
         foreach ($this->entry['comments'] as $comment) {
             if ($comment['uid'] == "") {
                 // Ah, let's insert it.
                 $comment['entry_uid'] = $this->entry['uid'];
                 $comment['contenttype'] = 'entry';
                 // make sure we don't try to add the 'remember info' or 'allowedit' fields..
                 if (isset($comment['rememberinfo'])) {
                     unset($comment['rememberinfo']);
                 }
                 if (isset($comment['allowedit'])) {
                     unset($comment['allowedit']);
                 }
                 // Registered, Notify, etc. have to be integer values.
                 $comment['registered'] = intval($comment['registered']);
                 $comment['notify'] = intval($comment['notify']);
                 $comment['discreet'] = intval($comment['discreet']);
                 $comment['moderate'] = intval($comment['moderate']);
                 $comment['entry_uid'] = intval($comment['entry_uid']);
                 $qry = array();
                 $qry['into'] = $this->commentstable;
                 $qry['value'] = $comment;
                 $this->sql->build_insert($qry);
                 $this->sql->query();
             }
         }
     }
     if (!empty($this->entry['comments'])) {
         foreach ($this->entry['trackbacks'] as $trackback) {
             if ($trackback['uid'] == "") {
                 // Ah, let's insert it.
                 $trackback['entry_uid'] = $this->entry['uid'];
                 $qry = array();
                 $qry['into'] = $this->trackbackstable;
                 $qry['value'] = $trackback;
                 $this->sql->build_insert($qry);
                 $this->sql->query();
             }
         }
     }
     // Delete the keywords / tags..
     $qry = array();
     $qry['delete'] = $this->tagstable;
     $qry['where'] = "contenttype='entry' AND target_uid=" . intval($this->entry['uid']);
     $this->sql->build_delete($qry);
     $this->sql->query();
     $tags = getTags(false, $this->entry['introduction'] . $this->entry['body'], $this->entry['keywords']);
     // Add the keywords / tags..
     foreach ($tags as $tag) {
         $qry = array();
         $qry['into'] = $this->tagstable;
         $qry['value'] = array('tag' => $tag, 'contenttype' => 'entry', 'target_uid' => $this->entry['uid']);
         $this->sql->build_insert($qry);
         $this->sql->query();
     }
     // Delete the categories..
     $qry = array();
     $qry['delete'] = $this->categoriestable;
     $qry['where'][] = "contenttype='entry'";
     $qry['where'][] = "target_uid=" . intval($this->entry['uid']);
     $this->sql->build_delete($qry);
     $this->sql->query();
     // Add the Categories..
     foreach ($this->entry['category'] as $cat) {
         $qry = array();
         $qry['into'] = $this->categoriestable;
         $qry['value'] = array('category' => safeString($cat, true), 'contenttype' => 'entry', 'target_uid' => $this->entry['uid']);
         $this->sql->build_insert($qry);
         $this->sql->query();
     }
     // Store the 'extra fields'
     if (!is_array($this->entry['extrafields'])) {
         $this->entry['extrafields'] = array();
     }
     $extrakeys = array();
     foreach ($this->entry['extrafields'] as $key => $value) {
         $extrakeys[] = $this->sql->quote($key);
         // No need to store empty values
         if (empty($value)) {
             unset($this->entry['extrafields'][$key]);
         }
         // Serialize any arrays..
         if (is_array($value)) {
             $this->entry['extrafields'][$key] = serialize($value);
         }
     }
     if (count($extrakeys) > 0) {
         $qry = array();
         $qry['delete'] = $this->extrafieldstable;
         $qry['where'][] = "target_uid=" . intval($this->entry['uid']);
         $qry['where'][] = "contenttype='entry'";
         $qry['where'][] = "fieldkey IN (" . implode(", ", $extrakeys) . ")";
         $this->sql->build_delete($qry);
         $this->sql->query();
     }
     foreach ($this->entry['extrafields'] as $key => $value) {
         $qry = array();
         $qry['into'] = $this->extrafieldstable;
         $qry['value'] = array('fieldkey' => safeString($key, true), 'value' => $value, 'contenttype' => 'entry', 'target_uid' => $this->entry['uid']);
         $this->sql->build_insert($qry);
         $this->sql->query();
     }
     //echo "<pre>\n"; print_r($extrakeys); echo "</pre>\n";
     //echo "<pre>\n"; print_r($this->entry['extrafields']); echo "</pre>\n";
     return TRUE;
 }
Пример #8
0
 /**
  * Helper function for scanExtensions, to check if files are extensions.
  *
  * @param string $file
  * @return array
  * @see Extensions::scanExtensions
  */
 function __scanFile($file)
 {
     global $PIVOTX;
     $base = basename($file);
     $ext = getExtension($base);
     // Only .php files can be extensions:
     if ($ext != "php") {
         return false;
     }
     // Check if the name matches one of the four types of extensions:
     if (strpos($base, "admin_") === 0) {
         $type = "admin";
     } else {
         if (strpos($base, "hook_") === 0) {
             $type = "hook";
         } else {
             if (strpos($base, "snippet") === 0) {
                 $type = "snippet";
             } else {
                 if (strpos($base, "widget_") === 0) {
                     $type = "widget";
                 } else {
                     // Nope, this is not an extension.
                     return false;
                 }
             }
         }
     }
     // If we get to here, it's most likely an extension. See if
     // we can parse the info from it.
     $contents = implode("", file($file));
     // Do a regular expression match for "// - something: something"..
     if (preg_match_all('/\\/\\/ - ([a-z]+):(.*)/i', $contents, $match)) {
         $info = array();
         foreach ($match[1] as $i => $key) {
             $info[trim(strtolower($match[1][$i]))] = trim($match[2][$i]);
         }
         // Do some last checks to see if we have at least a name, author and description..
         if (isset($info['extension']) && isset($info['author']) && isset($info['description'])) {
             $basefile = str_replace($PIVOTX['paths']['extensions_path'], "", $file);
             // Shizzle, we have an extension!
             $info['type'] = $type;
             $info['name'] = safeString($info['extension'], true);
             $info['file'] = $basefile;
             $info['active'] = in_array($info['name'], $this->active) || in_array($info['identifier'], $this->active) ? 1 : 0;
             $info['description'] = $this->__scanDocumentation($info, $info['name']);
             if (!isset($info['priority'])) {
                 $info['priority'] = 100;
             }
             if (empty($info['identifier'])) {
                 $info['identifier'] = makeURI($info['extension']);
             } else {
                 $info['identifier'] = makeURI($info['identifier']);
             }
             return $info;
         }
     } else {
         // Nope, not an extension..
         return false;
     }
 }