/** * Delete a topic * * @param string $tid Topic ID * @return string HTML redirect */ function deleteTopic($tid) { global $_CONF, $_TABLES, $_USER, $_TOPICS; $result = DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['topics']} WHERE tid ='{$tid}'"); $A = DB_fetchArray($result); $access = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']); if ($access < 3) { COM_accessLog("User {$_USER['username']} tried to illegally delete topic {$tid}."); COM_redirect($_CONF['site_admin_url'] . '/topic.php'); } // Update any child topics to root and un hide them DB_query("UPDATE {$_TABLES['topics']} SET parent_id = '" . TOPIC_ROOT . "', hidden = 0 WHERE parent_id = '{$tid}'"); // same with feeds DB_query("UPDATE {$_TABLES['syndication']} SET topic = '::all', is_enabled = 0 WHERE topic = '{$tid}'"); // Need to cycle through stories from topic // Only delete story if only this one topic // Make sure to check if this topic is default for story. If is make another topic default. $object_tables[] = $_TABLES['stories']; $object_tables[] = $_TABLES['storysubmission']; $object_tables[] = $_TABLES['blocks']; $object_tables_id[$_TABLES['stories']] = 'sid'; $object_tables_id[$_TABLES['storysubmission']] = 'sid'; $object_tables_id[$_TABLES['blocks']] = 'bid'; $object_type[$_TABLES['stories']] = 'article'; $object_type[$_TABLES['storysubmission']] = 'article'; $object_type[$_TABLES['blocks']] = 'block'; foreach ($object_tables as $object_table) { $sql = "SELECT {$object_tables_id[$object_table]}, ta.tdefault\n FROM {$object_table}, {$_TABLES['topic_assignments']} ta\n WHERE ta.type = '{$object_type[$object_table]}' AND ta.id = CAST({$object_tables_id[$object_table]} AS CHAR) AND ta.tid = '{$tid}'"; $result = DB_query($sql); $numStories = DB_numRows($result); for ($i = 0; $i < $numStories; $i++) { $A = DB_fetchArray($result); // Now check if another topic exists for this story $sql = "SELECT {$object_tables_id[$object_table]}, ta.tid\n FROM {$object_table}, {$_TABLES['topic_assignments']} ta\n WHERE ta.type = '{$object_type[$object_table]}' AND ta.id = {$object_tables_id[$object_table]}\n AND ta.tid <> '{$tid}' AND {$object_tables_id[$object_table]} = '{$A[$object_tables_id[$object_table]]}'"; $resultB = DB_query($sql); $numTopics = DB_numRows($resultB); if ($numTopics == 0) { // Delete comments, trackbacks, images associated with stories in this topic since only topic if ($object_table == $_TABLES['stories'] || $object_table == $_TABLES['storysubmission']) { STORY_deleteImages($A['sid']); DB_delete($_TABLES['comments'], array('sid', 'type'), array($A['sid'], 'article')); DB_delete($_TABLES['trackback'], array('sid', 'type'), array($A['sid'], 'article')); if ($object_table == $_TABLES['stories']) { PLG_itemDeleted($A['sid'], 'article'); } } DB_delete($object_table, $object_tables_id[$object_table], $A[$object_tables_id[$object_table]]); } else { // Story still exists for other topics so make sure one is default if ($object_table == $_TABLES['stories'] || $object_table == $_TABLES['storysubmission']) { if ($A['tdefault'] == 1) { $B = DB_fetchArray($resultB); $sql = "UPDATE {$_TABLES['topic_assignments']} SET tdefault = 1 WHERE type = 'article' AND tid = '{$B['tid']}' AND id = '{$B['sid']}'"; DB_query($sql); } } } } } // Notify of Delete topic so other plugins can deal with their items without topics PLG_itemDeleted($tid, 'topic'); // delete these DB_delete($_TABLES['topic_assignments'], 'tid', $tid); DB_delete($_TABLES['topics'], 'tid', $tid); // Reorder Topics, Delete topic cache and reload topic tree reorderTopics(); // update feed(s) COM_rdfUpToDateCheck('article'); COM_redirect($_CONF['site_admin_url'] . '/topic.php?msg=14'); }
/** * Delete a topic * * @param string $tid Topic ID * @return string HTML redirect * */ function deleteTopic($tid) { global $_CONF, $_TABLES, $_USER; $result = DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['topics']} WHERE tid ='{$tid}'"); $A = DB_fetchArray($result); $access = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']); if ($access < 3) { COM_accessLog("User {$_USER['username']} tried to illegally delete topic {$tid}."); return COM_refresh($_CONF['site_admin_url'] . '/topic.php'); } // don't delete topic blocks - assign them to 'all' and disable them DB_query("UPDATE {$_TABLES['blocks']} SET tid = 'all', is_enabled = 0 WHERE tid = '{$tid}'"); // same with feeds DB_query("UPDATE {$_TABLES['syndication']} SET topic = '::all', is_enabled = 0 WHERE topic = '{$tid}'"); // delete comments, trackbacks, images associated with stories in this topic $result = DB_query("SELECT sid FROM {$_TABLES['stories']} WHERE tid = '{$tid}'"); $numStories = DB_numRows($result); for ($i = 0; $i < $numStories; $i++) { $A = DB_fetchArray($result); STORY_deleteImages($A['sid']); DB_delete($_TABLES['comments'], array('sid', 'type'), array($A['sid'], 'article')); DB_delete($_TABLES['trackback'], array('sid', 'type'), array($A['sid'], 'article')); } // delete these DB_delete($_TABLES['stories'], 'tid', $tid); DB_delete($_TABLES['storysubmission'], 'tid', $tid); DB_delete($_TABLES['topics'], 'tid', $tid); // update feed(s) and Older Stories block COM_rdfUpToDateCheck('article'); COM_olderStuff(); return COM_refresh($_CONF['site_admin_url'] . '/topic.php?msg=14'); }
/** * Delete a story and related data immediately. * Note: For internal use only! To delete a story, use STORY_deleteStory (see * above), which will do permission checks and eventually end up here. * * @param string $sid ID of the story to delete * @internal For internal use only! */ function STORY_doDeleteThisStoryNow($sid) { global $_CONF, $_TABLES; require_once $_CONF['path_system'] . 'lib-comment.php'; STORY_deleteImages($sid); DB_delete($_TABLES['comments'], array('sid', 'type'), array($sid, 'article')); DB_delete($_TABLES['trackback'], array('sid', 'type'), array($sid, 'article')); DB_delete($_TABLES['stories'], 'sid', $sid); TOPIC_deleteTopicAssignments('article', $sid); // notify plugins PLG_itemDeleted($sid, 'article'); // update RSS feed COM_rdfUpToDateCheck('article'); COM_rdfUpToDateCheck('comment'); STORY_updateLastArticlePublished(); CMT_updateCommentcodes(); }
/** * Delete a story and related data immediately. * * Note: For internal use only! To delete a story, use STORY_deleteStory (see * above), which will do permission checks and eventually end up here. * * @param string $sid ID of the story to delete * @internal For internal use only! * */ function STORY_doDeleteThisStoryNow($sid) { global $_CONF, $_TABLES; require_once $_CONF['path_system'] . 'lib-comment.php'; STORY_deleteImages($sid); DB_delete($_TABLES['comments'], array('sid', 'type'), array($sid, 'article')); DB_delete($_TABLES['trackback'], array('sid', 'type'), array($sid, 'article')); DB_delete($_TABLES['stories'], 'sid', $sid); // notify plugins PLG_itemDeleted($sid, 'article'); // update RSS feed and Older Stories block COM_rdfUpToDateCheck(); COM_olderStuff(); CMT_updateCommentcodes(); }
} else { $asql .= ' OR statuscode = ' . STORY_ARCHIVE_ON_EXPIRE . ") AND tid != '" . DB_escapeString($archivetid) . "'"; } $expiresql = DB_query($asql); while (list($sid, $expiretopic, $title, $expire, $statuscode) = DB_fetchArray($expiresql)) { if ($statuscode == STORY_ARCHIVE_ON_EXPIRE) { if (!empty($archivetid)) { COM_errorLOG("Archive Story: {$sid}, Topic: {$archivetid}, Title: {$title}, Expired: {$expire}"); DB_query("UPDATE {$_TABLES['stories']} SET tid = '" . DB_escapeString($archivetid) . "', frontpage = '0', featured = '0' WHERE sid='" . DB_escapeString($sid) . "'"); CACHE_remove_instance('story_' . $sid); CACHE_remove_instance('whatsnew'); } } else { if ($statuscode == STORY_DELETE_ON_EXPIRE) { COM_errorLOG("Delete Story and comments: {$sid}, Topic: {$expiretopic}, Title: {$title}, Expired: {$expire}"); STORY_deleteImages($sid); DB_query("DELETE FROM {$_TABLES['comments']} WHERE sid='" . DB_escapeString($sid) . "' AND type = 'article'"); DB_query("DELETE FROM {$_TABLES['stories']} WHERE sid='" . DB_escapeString($sid) . "'"); CACHE_remove_instance('story_' . $sid); CACHE_remove_instance('whatsnew'); } } } } $sql = " (date <= NOW()) AND (draft_flag = 0)"; if (empty($topic)) { $sql .= COM_getLangSQL('tid', 'AND', 's'); } // if a topic was provided only select those stories. if (!empty($topic)) { $sql .= " AND (s.tid = '" . DB_escapeString($topic) . "' OR s.alternate_tid = '" . DB_escapeString($topic) . "') ";
/** * Delete an existing story * * @param array args Contains all the data provided by the client * @param string &output OUTPUT parameter containing the returned text * @return int Response code as defined in lib-plugins.php */ function service_delete_story($args, &$output, &$svc_msg) { global $_CONF, $_TABLES, $_USER; if (empty($args['sid']) && !empty($args['id'])) { $args['sid'] = $args['id']; } if ($args['gl_svc']) { $args['sid'] = COM_applyBasicFilter($args['sid']); } $sid = $args['sid']; $result = DB_query("SELECT tid,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['stories']} WHERE sid = '" . DB_escapeString($sid) . "'"); $A = DB_fetchArray($result); $access = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']); $access = min($access, SEC_hasTopicAccess($A['tid'])); if ($access < 3) { COM_accessLog("User {$_USER['username']} tried to illegally delete story {$sid}."); $output = COM_refresh($_CONF['site_admin_url'] . '/story.php'); if ($_USER['uid'] > 1) { return PLG_RET_PERMISSION_DENIED; } else { return PLG_RET_AUTH_FAILED; } } STORY_deleteImages($sid); DB_query("DELETE FROM {$_TABLES['comments']} WHERE sid = '" . DB_escapeString($sid) . "' AND type = 'article'"); DB_delete($_TABLES['stories'], 'sid', DB_escapeString($sid)); // delete Trackbacks DB_query("DELETE FROM {$_TABLES['trackback']} WHERE sid = '" . DB_escapeString($sid) . "' AND type = 'article';"); PLG_itemDeleted($sid, 'article'); // update RSS feed and Older Stories block COM_rdfUpToDateCheck(); COM_olderStuff(); COM_setMessage(10); $output = COM_refresh($_CONF['site_admin_url'] . '/story.php'); return PLG_RET_OK; }