Пример #1
0
 /**
  * Prepares the body of a comment
  *
  * @ static
  */
 function prepareBody($body)
 {
     # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
     # original ereg_replace: ereg_replace("\n.\n.\n", "\n", $body);
     // convert Windows and Mac style 'returns' to *nix newlines
     $body = preg_replace("/\r\n/", "\n", $body);
     $body = preg_replace("/\r/", "\n", $body);
     // then remove newlines when too many in a row (3 or more newlines get converted to 1 newline)
     $body = preg_replace("/\n{3,}/", "\n\n", $body);
     // encode special characters as entities
     $body = htmlspecialchars($body);
     // trim away whitespace and newlines at beginning and end
     $body = trim($body);
     // add <br /> tags
     $body = addBreaks($body);
     // create hyperlinks for http:// addresses
     // there's a testcase for this in /build/testcases/urllinking.txt
     $replace_from = array('/([^:\\/\\/\\w]|^)((https:\\/\\/)([\\w\\.-]+)([\\/\\w+\\.~%&?@=_:;#,-]+))/i', '/([^:\\/\\/\\w]|^)((http:\\/\\/|www\\.)([\\w\\.-]+)([\\/\\w+\\.~%&?@=_:;#,-]+))/i', '/([^:\\/\\/\\w]|^)((ftp:\\/\\/|ftp\\.)([\\w\\.-]+)([\\/\\w+\\.~%&?@=_:;#,-]+))/i', '/([^:\\/\\/\\w]|^)(mailto:(([a-zA-Z\\@\\%\\.\\-\\+_])+))/i');
     $body = preg_replace_callback($replace_from, array('self', 'prepareBody_cb'), $body);
     return $body;
 }
Пример #2
0
 /**
  * Adds an item to this blog
  */
 function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft, $posted = '1')
 {
     global $manager;
     $blogid = intval($blogid);
     $authorid = intval($authorid);
     $title = $title;
     $body = $body;
     $more = $more;
     $catid = intval($catid);
     // convert newlines to <br />
     if ($this->convertBreaks()) {
         $body = addBreaks($body);
         $more = addBreaks($more);
     }
     if ($closed != '1') {
         $closed = '0';
     }
     if ($draft != '0') {
         $draft = '1';
     }
     if (!$this->isValidCategory($catid)) {
         $catid = $this->getDefaultCategory();
     }
     if ($timestamp > $this->getCorrectTime()) {
         $isFuture = 1;
     }
     $timestamp = date('Y-m-d H:i:s', $timestamp);
     $manager->notify('PreAddItem', array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid));
     $ititle = sql_real_escape_string($title);
     $ibody = sql_real_escape_string($body);
     $imore = sql_real_escape_string($more);
     $query = 'INSERT INTO ' . sql_table('item') . ' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT, IPOSTED) ' . "VALUES ('{$ititle}', '{$ibody}', '{$imore}', {$blogid}, {$authorid}, '{$timestamp}', {$closed}, {$draft}, {$catid}, {$posted})";
     sql_query($query);
     $itemid = sql_insert_id();
     $manager->notify('PostAddItem', array('itemid' => $itemid));
     if (!$draft) {
         $this->updateUpdateFile();
     }
     // send notification mail
     if (!$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem()) {
         $this->sendNewItemNotification($itemid, $title, $body);
     }
     return $itemid;
 }
Пример #3
0
 /**
  * Updates an item
  *
  * @static
  */
 function update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp = 0)
 {
     global $manager;
     $itemid = intval($itemid);
     // make sure value is 1 or 0
     if ($closed != 1) {
         $closed = 0;
     }
     // get destination blogid
     $new_blogid = getBlogIDFromCatID($catid);
     $old_blogid = getBlogIDFromItemID($itemid);
     // move will be done on end of method
     if ($new_blogid != $old_blogid) {
         $moveNeeded = 1;
     }
     // add <br /> before newlines
     $blog =& $manager->getBlog($new_blogid);
     if ($blog->convertBreaks()) {
         $body = addBreaks($body);
         $more = addBreaks($more);
     }
     // call plugins
     $manager->notify('PreUpdateItem', array('itemid' => $itemid, 'title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$blog, 'closed' => &$closed, 'catid' => &$catid));
     // update item itsself
     $query = 'UPDATE ' . sql_table('item') . ' SET' . " ibody='" . sql_real_escape_string($body) . "'," . " ititle='" . sql_real_escape_string($title) . "'," . " imore='" . sql_real_escape_string($more) . "'," . " iclosed=" . intval($closed) . "," . " icat=" . intval($catid);
     // if we received an updated timestamp in the past, but past posting is not allowed,
     // reject that date change (timestamp = 0 will make sure the current date is kept)
     if (!$blog->allowPastPosting() && $timestamp < $blog->getCorrectTime()) {
         $timestamp = 0;
     }
     if ($timestamp > $blog->getCorrectTime(time())) {
         $isFuture = 1;
         $query .= ', iposted=0';
     } else {
         $isFuture = 0;
         $query .= ', iposted=1';
     }
     if ($wasdraft && $publish) {
         // set timestamp to current date only if it's not a future item
         // draft items have timestamp == 0
         // don't allow timestamps in the past (unless otherwise defined in blogsettings)
         $query .= ', idraft=0';
         if ($timestamp == 0) {
             $timestamp = $blog->getCorrectTime();
         }
         // send new item notification
         if (!$isFuture && $blog->getNotifyAddress() && $blog->notifyOnNewItem()) {
             $blog->sendNewItemNotification($itemid, $title, $body);
         }
     }
     // save back to drafts
     if (!$wasdraft && !$publish) {
         $query .= ', idraft=1';
         // set timestamp back to zero for a draft
         $query .= ", itime=" . mysqldate($timestamp);
     }
     // update timestamp when needed
     if ($timestamp != 0) {
         $query .= ", itime=" . mysqldate($timestamp);
     }
     // make sure the correct item is updated
     $query .= ' WHERE inumber=' . $itemid;
     // off we go!
     sql_query($query);
     $manager->notify('PostUpdateItem', array('itemid' => $itemid));
     // when needed, move item and comments to new blog
     if ($moveNeeded) {
         ITEM::move($itemid, $catid);
     }
     //update the itemOptions
     $aOptions = requestArray('plugoption');
     NucleusPlugin::_applyPluginOptions($aOptions);
     $manager->notify('PostPluginOptionsUpdate', array('context' => 'item', 'itemid' => $itemid, 'item' => array('title' => $title, 'body' => $body, 'more' => $more, 'closed' => $closed, 'catid' => $catid)));
 }