Пример #1
0
/**
 * Config Option has changed. (use plugin api)
 *
 * @return  void
 */
function plugin_configchange_article($group, $changes = array())
{
    global $_TABLES, $_CONF;
    // If trim length changes then need to redo all related url's for articles
    if ($group == 'Core' && in_array('whats_related_trim', $changes)) {
        $sql = "SELECT sid, introtext, bodytext FROM {$_TABLES['stories']}";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            for ($x = 0; $x < $nrows; $x++) {
                $A = DB_fetchArray($result);
                // Should maybe retrieve through story service but just grab from database and apply any autotags
                // This is all the related story column should really need
                $fulltext = PLG_replaceTags($A['introtext']) . ' ' . PLG_replaceTags($A['bodytext']);
                $related = DB_escapeString(implode("\n", STORY_extractLinks($fulltext, $_CONF['whats_related_trim'])));
                if (!empty($related)) {
                    DB_query("UPDATE {$_TABLES['stories']} SET related = '{$related}' WHERE sid = '{$A['sid']}'");
                }
            }
        }
        // For if any articles are being cached
    } elseif ($group == 'Core' && (in_array('site_name', $changes) || in_array('contributedbyline', $changes) || in_array('allow_user_photo', $changes) || in_array('article_image_align', $changes) || in_array('related_topics', $changes) || in_array('related_topics_max', $changes) || in_array('allow_page_breaks', $changes) || in_array('page_break_comments', $changes) || in_array('url_rewrite', $changes) || in_array('url_routing', $changes) || in_array('hideviewscount', $changes) || in_array('hideemailicon', $changes) || in_array('loginrequired', $changes) || in_array('emailstoryloginrequired', $changes) || in_array('hideprintericon', $changes))) {
        // If any Article options changed then delete all article cache
        $cacheInstance = 'article__';
        CACHE_remove_instance($cacheInstance);
    }
}
Пример #2
0
 /**
  * Saves the story in it's final state to the database.
  *
  * Handles all the SID magic etc.
  * @return Integer status result from a constant list.
  */
 function saveToDatabase()
 {
     global $_TABLES;
     if (DB_getItem($_TABLES['topics'], 'tid', 'archive_flag=1') == $this->_tid) {
         $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()");
         }
     }
     $oldArticleExists = false;
     $currentSidExists = false;
     /* Fix up old sid => new sid stuff */
     $checksid = addslashes($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 = addslashes($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->_introtext} {$this->_bodytext}"));
     $sql = 'REPLACE INTO ' . $_TABLES['stories'] . ' (';
     $values = ' VALUES (';
     reset($this->_dbFields);
     /* 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;
             $sql .= $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 {
                 $values .= '\'' . addslashes($this->{$varname}) . '\', ';
             }
         }
     }
     $sql = substr($sql, 0, strlen($sql) - 2);
     $values = substr($values, 0, strlen($values) - 2);
     $sql .= ') ' . $values . ')';
     DB_query($sql);
     /* Clean up the old story */
     if ($oldArticleExists) {
         $sql = "DELETE FROM {$_TABLES['stories']} WHERE sid='{$checksid}'";
         DB_query($sql);
     }
     if ($this->type == 'submission') {
         /* there might be a submission, clean it up */
         DB_delete($_TABLES['storysubmission'], 'sid', $checksid);
     }
     return STORY_SAVED;
 }
Пример #3
0
/**
* Moderates an item
*
* This will actually perform moderation (approve or delete) one or more items
*
* @param    array   $mid        Array of items
* @param    array   $action     Array of actions to perform on items
* @param    string  $type       Type of items ('story', etc.)
* @param    int     $count      Number of items to moderate
* @return   string              HTML for "command and control" page
*
*/
function moderation($mid, $action, $type, $count)
{
    global $_CONF, $_TABLES;
    $retval = '';
    switch ($type) {
        case 'story':
            $id = 'sid';
            $table = $_TABLES['stories'];
            $submissiontable = $_TABLES['storysubmission'];
            $fields = 'sid,uid,tid,title,introtext,date,postmode';
            break;
        case 'comment':
            $id = 'cid';
            $submissiontable = $_TABLES['commentsubmissions'];
            $sidArray[] = '';
            break;
        default:
            if (strlen($type) <= 0) {
                // something is terribly wrong, bail
                $retval .= COM_errorLog("Unable to find type of {$type} in moderation() in moderation.php");
                return $retval;
            }
            list($id, $table, $fields, $submissiontable) = PLG_getModerationValues($type);
    }
    // Set true if an valid action other than delete_all is selected
    $formaction = false;
    for ($i = 0; $i < $count; $i++) {
        if (isset($action[$i]) and $action[$i] != '') {
            $formaction = true;
        } else {
            continue;
        }
        switch ($action[$i]) {
            case 'delete':
                if (!empty($type) && $type != 'story' && $type != 'draft') {
                    // There may be some plugin specific processing that needs to
                    // happen first.
                    $retval .= PLG_deleteSubmission($type, $mid[$i]);
                }
                if (empty($mid[$i])) {
                    $retval .= COM_errorLog("moderation.php just tried deleting everything in table {$submissiontable} because it got an empty id.  Please report this immediately to your site administrator");
                    return $retval;
                }
                if ($type == 'draft') {
                    STORY_deleteStory($mid[$i]);
                } else {
                    DB_delete($submissiontable, "{$id}", $mid[$i]);
                }
                break;
            case 'approve':
                if ($type == 'story') {
                    $result = DB_query("SELECT * FROM {$_TABLES['storysubmission']} WHERE sid = '{$mid[$i]}'");
                    $A = DB_fetchArray($result);
                    $A['related'] = addslashes(implode("\n", STORY_extractLinks($A['introtext'])));
                    $A['owner_id'] = $A['uid'];
                    $A['title'] = addslashes($A['title']);
                    $A['introtext'] = addslashes($A['introtext']);
                    $A['bodytext'] = addslashes($A['bodytext']);
                    $result = DB_query("SELECT group_id,perm_owner,perm_group,perm_members,perm_anon,archive_flag FROM {$_TABLES['topics']} WHERE tid = '{$A['tid']}'");
                    $T = DB_fetchArray($result);
                    if ($T['archive_flag'] == 1) {
                        $frontpage = 0;
                    } else {
                        if (isset($_CONF['frontpage'])) {
                            $frontpage = $_CONF['frontpage'];
                        } else {
                            $frontpage = 1;
                        }
                    }
                    DB_save($_TABLES['stories'], 'sid,uid,tid,title,introtext,bodytext,related,date,show_topic_icon,commentcode,trackbackcode,postmode,frontpage,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon', "'{$A['sid']}',{$A['uid']},'{$A['tid']}','{$A['title']}','{$A['introtext']}','{$A['bodytext']}','{$A['related']}','{$A['date']}','{$_CONF['show_topic_icon']}','{$_CONF['comment_code']}','{$_CONF['trackback_code']}','{$A['postmode']}',{$frontpage},{$A['owner_id']},{$T['group_id']},{$T['perm_owner']},{$T['perm_group']},{$T['perm_members']},{$T['perm_anon']}");
                    DB_delete($_TABLES['storysubmission'], "{$id}", $mid[$i]);
                    PLG_itemSaved($A['sid'], 'article');
                    COM_rdfUpToDateCheck();
                    COM_olderStuff();
                } else {
                    if ($type == 'draft') {
                        DB_query("UPDATE {$_TABLES['stories']} SET draft_flag = 0 WHERE sid = '{$mid[$i]}'");
                        COM_rdfUpToDateCheck();
                        COM_olderStuff();
                    } else {
                        if ($type == 'comment') {
                            $sid = CMT_approveModeration($mid[$i]);
                            if (!in_array($sid, $sidArray)) {
                                $sidArray[$i] = $sid;
                            }
                        } else {
                            // This is called in case this is a plugin. There may be some
                            // plugin specific processing that needs to happen.
                            DB_copy($table, $fields, $fields, $submissiontable, $id, $mid[$i]);
                            $retval .= PLG_approveSubmission($type, $mid[$i]);
                        }
                    }
                }
                break;
        }
    }
    // after loop update comment tree and count for each story
    if (isset($sidArray)) {
        foreach ($sidArray as $sid) {
            CMT_rebuildTree($sid);
            //update comment count of stories;
            $comments = DB_count($_TABLES['comments'], 'sid', $sid);
            DB_change($_TABLES['stories'], 'comments', $comments, 'sid', $sid);
        }
    }
    //Add new comment users to group comment.submit group
    if (isset($_POST['publishfuture'])) {
        for ($i = 0; $i < count($_POST['publishfuture']); $i++) {
            $uid = COM_applyFilter($_POST['publishfuture'][$i], true);
            if ($uid > 1 && !SEC_inGroup('Comment Submitters', $uid)) {
                SEC_addUserToGroup($uid, 'Comment Submitters');
            }
        }
    }
    // Check if there was no direct action used on the form
    // and if the delete_all submit action was used
    if (!$formaction and isset($_POST['delitem'])) {
        foreach ($_POST['delitem'] as $delitem) {
            $delitem = COM_applyFilter($delitem);
            if (!empty($type) && $type != 'story' && $type != 'draft') {
                // There may be some plugin specific processing that needs to
                // happen first.
                $retval .= PLG_deleteSubmission($type, $delitem);
            }
            if ($type == 'draft') {
                STORY_deleteStory($delitem);
            } else {
                DB_delete($submissiontable, "{$id}", $delitem);
            }
        }
    }
    $retval .= commandcontrol(SEC_createToken());
    return $retval;
}
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 /**
  * Saves the story in it's final state to the database.
  *
  * Handles all the SID magic etc.
  * @return Integer status result from a constant list.
  */
 function saveToDatabase()
 {
     global $_TABLES, $_CONF;
     if (DB_getItem($_TABLES['topics'], 'tid', "archive_flag=1") == $this->_tid) {
         $this->_featured = 0;
         $this->_frontpage = 0;
         $this->_statuscode = STORY_ARCHIVE_ON_EXPIRE;
     }
     if ($this->_featured != 1) {
         $this->_featured = 0;
     }
     if ($this->_statuscode == '') {
         $this->_statuscode = 0;
     }
     if ($this->_owner_id == '') {
         $this->_owner_id = 1;
     }
     /* 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()");
         }
     }
     $oldArticleExists = false;
     $currentSidExists = false;
     /* Fix up old sid => new sid stuff */
     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.
          */
         $checksid = DB_escapeString($this->_originalSid);
         $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);
             /* Move ratings */
             $sql = "UPDATE {$_TABLES['rating']} SET item_id='{$newsid}' WHERE item_id='{$checksid}' AND type='article'";
             DB_query($sql);
             $sql = "UPDATE {$_TABLES['rating_votes']} SET item_id='{$newsid}' WHERE item_id='{$checksid}' AND type='article'";
             DB_query($sql);
             CACHE_remove_instance('story_' . $this->_originalSid);
         }
     }
     /* Acquire Comment Count */
     $sql = "SELECT count(1) FROM {$_TABLES['comments']} WHERE type='article' AND sid='" . DB_escapeString($this->_sid) . "'";
     $result = DB_query($sql);
     if ($result && DB_numRows($result) == 1) {
         $array = DB_fetchArray($result);
         $this->_comments = $array[0];
     } else {
         $this->_comments = 0;
     }
     /* Acquire Rating / Votes */
     list($rating_id, $rating, $votes) = RATING_getRating('article', $this->_sid);
     $this->_rating = $rating;
     $this->_votes = $votes;
     //@TODO - remove this call on save
     // Get the related URLs
     $this->_related = implode("\n", STORY_extractLinks("{$this->_introtext} {$this->_bodytext}"));
     $sql = 'REPLACE INTO ' . $_TABLES['stories'] . ' (';
     $values = ' VALUES (';
     $fields = '';
     reset($this->_dbFields);
     /* 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;
             $sql .= $fieldname . ', ';
             if ($fieldname == 'date' || $fieldname == 'expire' || $fieldname == 'comment_expire') {
                 // let the DB server do this conversion
                 if (!empty($this->{$varname})) {
                     $values .= 'FROM_UNIXTIME(' . $this->{$varname} . '), ';
                 } else {
                     $values .= "'0000-00-00 00:00:00', ";
                 }
             } else {
                 $values .= '\'' . DB_escapeString($this->{$varname}) . '\', ';
             }
         }
     }
     $sql = substr($sql, 0, strlen($sql) - 2);
     $values = substr($values, 0, strlen($values) - 2);
     $sql .= ') ' . $values . ')';
     DB_query($sql);
     CACHE_remove_instance('story_' . $this->_sid);
     /* Clean up the old story */
     if ($oldArticleExists && !empty($checksid)) {
         $sql = "DELETE FROM {$_TABLES['stories']} WHERE sid='{$checksid}'";
         DB_query($sql);
         CACHE_remove_instance('story_' . $this->_originalSid);
     }
     if ($this->type == 'submission') {
         if (!empty($checksid)) {
             DB_delete($_TABLES['storysubmission'], 'sid', $checksid);
         } else {
             DB_delete($_TABLES['storysubmission'], 'sid', DB_escapeString($this->_sid));
         }
     }
     CACHE_remove_instance('whatsnew');
     CACHE_remove_instance('stmenu');
     return STORY_SAVED;
 }
Пример #6
0
/**
* Moderates a single item
*
* This will actually perform moderation (approve or delete) one or more items
*
* @param    string  $action     Action to perform ('delete' or 'approve')
* @param    string  $type       Type of item ('user', 'draftstory', 'story', etc.)
* @param    string  $id         ID of item to approve or delete
* @return   string              HTML for "command and control" page
*
*/
function MODERATE_item($action = '', $type = '', $id = '')
{
    global $_CONF, $_TABLES;
    $retval = '';
    if (empty($action)) {
        // null action
        $retval .= COM_errorLog("Submissions Error: An attempt was made to moderate an item with a null action.");
        return $retval;
    }
    if (empty($type)) {
        // null item type
        $retval .= COM_errorLog("Submissions Error: An attempt was made to moderate a null item type.");
        return $retval;
    }
    if (empty($id)) {
        // null item type
        $retval .= COM_errorLog("Submissions Error: An attempt was made to moderate an item with a null id.");
        return $retval;
    }
    list($key, $table, $fields, $submissiontable) = PLG_getModerationValues($type);
    switch ($action) {
        case 'delete':
            switch ($type) {
                case 'user':
                    // user
                    if ($id > 1) {
                        USER_deleteAccount($id);
                    }
                    break;
                case 'story':
                    // story (needs to move to a plugin)
                    DB_delete($submissiontable, "{$key}", $id);
                    break;
                case 'draftstory':
                    // draft story
                    STORY_deleteStory($id);
                    break;
                default:
                    // plugin
                    $retval .= PLG_deleteSubmission($type, $id);
                    DB_delete($submissiontable, "{$key}", $id);
                    break;
            }
            break;
        case 'approve':
            switch ($type) {
                case 'story':
                    // story (needs to move to a plugin)
                    $result = DB_query("SELECT * FROM {$submissiontable} WHERE {$key} = '{$id}'");
                    $A = DB_fetchArray($result);
                    $A['related'] = DB_escapeString(implode("\n", STORY_extractLinks($A['introtext'])));
                    $A['owner_id'] = $A['uid'];
                    $A['title'] = DB_escapeString($A['title']);
                    $A['introtext'] = DB_escapeString($A['introtext']);
                    $A['bodytext'] = DB_escapeString($A['bodytext']);
                    $result = DB_query("SELECT group_id,perm_owner,perm_group,perm_members,perm_anon,archive_flag FROM {$_TABLES['topics']} WHERE tid = '{$A['tid']}'");
                    $T = DB_fetchArray($result);
                    if ($T['archive_flag'] == 1) {
                        $frontpage = 0;
                    } else {
                        if (isset($_CONF['frontpage'])) {
                            $frontpage = $_CONF['frontpage'];
                        } else {
                            $frontpage = 1;
                        }
                    }
                    DB_save($table, 'sid,uid,tid,title,introtext,bodytext,related,date,show_topic_icon,commentcode,trackbackcode,postmode,frontpage,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon', "'{$A['sid']}',{$A['uid']},'{$A['tid']}','{$A['title']}','{$A['introtext']}','{$A['bodytext']}','{$A['related']}','{$A['date']}','{$_CONF['show_topic_icon']}','{$_CONF['comment_code']}','{$_CONF['trackback_code']}','{$A['postmode']}',{$frontpage},{$A['owner_id']},{$T['group_id']},{$T['perm_owner']},{$T['perm_group']},{$T['perm_members']},{$T['perm_anon']}");
                    DB_delete($submissiontable, "{$key}", $id);
                    PLG_itemSaved($A['sid'], 'article');
                    COM_rdfUpToDateCheck();
                    COM_olderStuff();
                    break;
                case 'draftstory':
                    // draft story
                    DB_query("UPDATE {$table} SET draft_flag = 0 WHERE {$key} = '{$id}'");
                    COM_rdfUpToDateCheck();
                    COM_olderStuff();
                    break;
                case 'user':
                    // user
                    $result = DB_query("SELECT {$fields} FROM {$table} WHERE {$key} = '{$id}'");
                    $nrows = DB_numRows($result);
                    if ($nrows == 1) {
                        $A = DB_fetchArray($result);
                        if ($_CONF['registration_type'] == 1) {
                            $sql = "UPDATE {$table} SET status=" . USER_ACCOUNT_AWAITING_VERIFICATION . " WHERE {$key} = '{$A['uid']}'";
                        } else {
                            $sql = "UPDATE {$table} SET status=" . USER_ACCOUNT_AWAITING_ACTIVATION . " WHERE {$key} = '{$A['uid']}'";
                        }
                        DB_query($sql);
                        USER_createAndSendPassword($A['username'], $A['email'], $A['uid']);
                    }
                    break;
                default:
                    // plugin
                    DB_copy($table, $fields, $fields, $submissiontable, $key, $id);
                    $retval .= PLG_approveSubmission($type, $id);
                    break;
            }
            break;
    }
    // switch ($action)
    return $retval;
}