コード例 #1
0
ファイル: story.class.php プロジェクト: mystralkk/geeklog
 /**
  * Saves the story in it's final state to the database.
  * Handles all the SID magic etc.
  *
  * @return int status result from a constant list.
  */
 public function saveToDatabase()
 {
     global $_TABLES, $_DB_dbms;
     $tids = TOPIC_getTopicIdsForObject('topic');
     $archive_tid = DB_getItem($_TABLES['topics'], 'tid', 'archive_flag=1');
     if (!empty($tids) && !empty($archive_tid)) {
         if (in_array($archive_tid, $tids)) {
             $this->_featured = 0;
             $this->_frontpage = 0;
             $this->_statuscode = STORY_ARCHIVE_ON_EXPIRE;
         }
     }
     /* if a featured, non-draft, that goes live straight away, unfeature
      * other stories in same topic:
      */
     if ($this->_featured == '1') {
         // there can only be one non-draft featured story
         if ($this->_draft_flag == 0 and $this->_date <= time()) {
             if ($this->_frontpage == 1) {
                 // un-feature any featured frontpage story
                 DB_query("UPDATE {$_TABLES['stories']} SET featured = 0 WHERE featured = 1 AND draft_flag = 0 AND frontpage = 1 AND date <= NOW()");
             }
             // un-feature any featured story in the same topic
             //DB_query("UPDATE {$_TABLES['stories']} SET featured = 0 WHERE featured = 1 AND draft_flag = 0 AND tid = '{$this->_tid}' AND date <= NOW()");
             $tids = TOPIC_getTopicIdsForObject('topic');
             if (!empty($tids)) {
                 DB_query("UPDATE {$_TABLES['stories']} s, {$_TABLES['topic_assignments']} ta SET s.featured = 0 WHERE s.featured = 1 AND s.draft_flag = 0 AND (ta.tid IN ('" . implode("','", $tids) . "')) AND ta.type = 'article' AND ta.id = s.sid AND s.date <= NOW()");
             }
         }
     }
     $oldArticleExists = false;
     $currentSidExists = false;
     // Fix up old sid => new sid stuff
     $checkSid = DB_escapeString($this->_originalSid);
     // needed below
     if ($this->_sid != $this->_originalSid) {
         /* The sid has changed. Load from request will have
          * ensured that if the new sid exists an error has
          * been thrown, but we need to know if the old sid
          * actually existed (as opposed to being a generated
          * sid that was then thrown away) to reduce the sheer
          * number of SQL queries we do.
          */
         $newSid = DB_escapeString($this->_sid);
         $sql = "SELECT 1 FROM {$_TABLES['stories']} WHERE sid='{$checkSid}'";
         $result = DB_query($sql);
         if ($result && DB_numRows($result) > 0) {
             $oldArticleExists = true;
         }
         if ($oldArticleExists) {
             // Move Comments
             $sql = "UPDATE {$_TABLES['comments']} SET sid='{$newSid}' WHERE type='article' AND sid='{$checkSid}'";
             DB_query($sql);
             // Move Images
             $sql = "UPDATE {$_TABLES['article_images']} SET ai_sid = '{$newSid}' WHERE ai_sid = '{$checkSid}'";
             DB_query($sql);
             // Move trackbacks
             $sql = "UPDATE {$_TABLES['trackback']} SET sid='{$newSid}' WHERE sid='{$checkSid}' AND type='article'";
             DB_query($sql);
         }
     }
     // Acquire Comment Count
     $sql = "SELECT COUNT(1) FROM {$_TABLES['comments']} WHERE type='article' AND sid='{$this->_sid}'";
     $result = DB_query($sql);
     if ($result && DB_numRows($result) == 1) {
         $array = DB_fetchArray($result);
         $this->_comments = $array[0];
     } else {
         $this->_comments = 0;
     }
     /* Format dates for storage: */
     /*
      * Doing this here would use the webserver's timezone, but we need
      * to use the DB server's timezone so that ye olde timezone hack
      * still works. See use of FROM_UNIXTIME in the SQL below.
      *
      * $this->_date = date('Y-m-d H:i:s', $this->_date);
      * $this->_expire = date('Y-m-d H:i:s', $this->_expire);
      *
      */
     // Get the related URLs
     $this->_related = implode("\n", STORY_extractLinks($this->DisplayElements('introtext') . ' ' . $this->DisplayElements('bodytext')));
     $fields = '';
     $values = '';
     reset($this->_dbFields);
     $this->_text_version = GLTEXT_LATEST_VERSION;
     // Apply HTML filter to the text just before save
     // with the permissions of current editor
     $this->_introtext = GLText::applyHTMLFilter($this->_introtext, $this->_postmode, 'story.edit', $this->_text_version);
     $this->_bodytext = GLText::applyHTMLFilter($this->_bodytext, $this->_postmode, 'story.edit', $this->_text_version);
     /* This uses the database field array to generate a SQL Statement. This
      * means that when adding new fields to save and load, all we need to do
      * is add the field name to the array, and the code will magically cope.
      */
     while (list($fieldName, $save) = each($this->_dbFields)) {
         if ($save === 1) {
             $varName = '_' . $fieldName;
             $fields .= $fieldName . ', ';
             if ($fieldName === 'date' || $fieldName === 'expire' || $fieldName === 'comment_expire') {
                 // let the DB server do this conversion (cf. timezone hack)
                 $values .= 'FROM_UNIXTIME(' . $this->{$varName} . '), ';
             } else {
                 if ($this->{$varName} === '') {
                     $values .= "'', ";
                 } else {
                     if (is_numeric($this->{$varName})) {
                         $values .= DB_escapeString($this->{$varName}) . ', ';
                     } else {
                         $values .= '\'' . DB_escapeString($this->{$varName}) . '\', ';
                     }
                 }
             }
         }
     }
     $fields = substr($fields, 0, strlen($fields) - 2);
     $values = substr($values, 0, strlen($values) - 2);
     DB_save($_TABLES['stories'], $fields, $values);
     // Save Topics selected
     TOPIC_saveTopicSelectionControl('article', $this->_sid);
     if ($oldArticleExists) {
         // Clean up the old story
         DB_delete($_TABLES['stories'], 'sid', $checkSid);
         // Delete Topic Assignments for this old article id since we just created new ones
         TOPIC_deleteTopicAssignments('article', $checkSid);
     }
     if ($this->type === 'submission') {
         // there might be a submission, clean it up
         DB_delete($_TABLES['storysubmission'], 'sid', $checkSid);
     }
     return STORY_SAVED;
 }
コード例 #2
0
 function _saveToDatabase($mode = '')
 {
     global $_CONF, $_TABLES;
     $sql_additions = '';
     if (version_compare(VERSION, '2.1.0') >= 0) {
         $this->_text_version = GLTEXT_LATEST_VERSION;
         $text_version = $this->_text_version;
         $sql_additions = "text_version='{$text_version}', ";
         // Apply HTML filter to the text just before save
         // with the permissions of current editor
         require_once $_CONF['path_system'] . 'classes/gltext.class.php';
         $description = GLText::applyHTMLFilter($this->_description, $this->_postmode, 'story.edit', $this->_text_version);
         $detail = GLText::applyHTMLFilter($this->_detail, $this->_postmode, 'story.edit', $this->_text_version);
     } else {
         $description = $this->_description;
         $detail = $this->_detail;
     }
     $lid = addslashes($this->_lid);
     $cid = addslashes($this->_cid);
     $title = addslashes($this->_title);
     $url = addslashes($this->_url);
     $homepage = addslashes($this->_homepage);
     $version = addslashes($this->_version);
     $size = (int) $this->_size;
     $md5 = addslashes($this->_md5);
     $logourl = addslashes($this->_logourl);
     $mg_autotag = addslashes($this->_mg_autotag);
     $tags = addslashes($this->_tags);
     $date = (int) $this->_date;
     $commentcode = (int) $this->_commentcode;
     $project = addslashes($this->_project);
     $description = addslashes($description);
     $detail = addslashes($detail);
     $owner_id = (int) $this->_owner_id;
     $postmode = addslashes($this->_postmode);
     $is_released = (int) $this->_is_released;
     $is_listing = (int) $this->_is_listing;
     $createddate = addslashes($this->_createddate);
     $table = empty($mode) ? $_TABLES['downloads'] : $_TABLES['downloadsubmission'];
     DB_query("UPDATE {$table} " . "SET lid='{$lid}', cid='{$cid}', title='{$title}', url='{$url}', mg_autotag='{$mg_autotag}', tags='{$tags}', " . "homepage='{$homepage}', project='{$project}', description='{$description}', detail='{$detail}', " . "version='{$version}', size={$size}, md5='{$md5}', commentcode={$commentcode}, owner_id={$owner_id}, " . "postmode='{$postmode}', logourl='{$logourl}', is_released={$is_released}, is_listing={$is_listing}, " . $sql_additions . "date={$date}, createddate='{$createddate}' " . "WHERE lid='{$this->_old_lid}'");
     if ($this->_old_lid == $this->_lid) {
         PLG_itemSaved($this->_lid, 'downloads');
     } else {
         DB_change($_TABLES['comments'], 'sid', addslashes($this->_lid), array('sid', 'type'), array(addslashes($this->_old_lid), 'downloads'));
         PLG_itemSaved($this->_lid, 'downloads', $this->_old_lid);
     }
     COM_rdfUpToDateCheck('downloads', $this->_cid, $this->_lid);
 }