<?php // This script should be ran once an hour as a cronjob. // ----------------------------------------------------------------------------- // Update the search cache where needed. $seaResult = sql_query("SELECT `seaObject` FROM `searchcache` " . "WHERE `seaNeedsUpdate` = '1'"); while ($seaData = mysql_fetch_row($seaResult)) { updateSearchCache($seaData[0], true); } sql_free($seaResult); // ----------------------------------------------------------------------------- // Clean up old searches. sql_query("TRUNCATE `search`"); sql_query("TRUNCATE `searchItems`"); /* sql_where( array( "srcSubmitDate<!" => "DATE_SUB( NOW(), INTERVAL 1 HOUR )" )); $srcResult = sql_rowset( "search", "srcid" ); while( $srcData = sql_next( $srcResult )) { sql_where( array( "sriSearch" => $srcData[ "srcid" ])); sql_delete( "searchItems" ); } sql_free( $srcResult ); sql_where( array( "srcSubmitDate<!" => "DATE_SUB( NOW(), INTERVAL 1 HOUR )" )); sql_delete( "search" ); */ // -----------------------------------------------------------------------------
/** * Functions reads the POST data and adds a new comment to the database. */ function processCommentReply($objid, $objType) { global $_auth, $_config; $noEmoticons = isset($_POST["commentNoEmoticons"]) ? 1 : 0; $noSig = isset($_POST["commentNoSig"]) ? 1 : 0; $noBBCode = isset($_POST["commentNoBBCode"]) ? 1 : 0; $root_objid = $objid; $root_objType = $objType; $parent_objid = $objid; $parent_objType = $objType; if ($objType == "com") { $comResult = sql_query("SELECT `comRootObj`,`comRootObjType`,`comObj`,`comObjType` " . "FROM `comments`" . dbWhere(array("comid" => $objid))); if ($comData = mysql_fetch_row($comResult)) { $root_objid = $comData[0]; $root_objType = $comData[1]; $parent_objid = $comData[2]; $parent_objType = $comData[3]; } mysql_free_result($comResult); if ($parent_objid != $objid && $parent_objid != $root_objid) { $comResult = sql_query("SELECT `comObj`,`comObjType` " . "FROM `comments`" . dbWhere(array("comid" => $parent_objid))); if ($comData = mysql_fetch_row($comResult)) { $parent_objid = $comData[0]; $parent_objType = $comData[1]; } mysql_free_result($comResult); } } // 16000 characters maximum. $commentText = substr($_POST["comment"], 0, 16000); $userIp = getHexIp($_SERVER["REMOTE_ADDR"]); // Add the comment to the database. sql_query("INSERT INTO `comments`" . dbValues(array("comObj" => $objid, "comObjType" => $objType, "comRootObj" => $root_objid, "comRootObjType" => $root_objType, "comCreator" => $_auth["useid"], "comSubmitDate!" => "NOW()", "comComment" => $commentText, "comSubmitIp" => $userIp, "comEditIp" => $userIp, "comNoEmoticons" => $noEmoticons, "comNoSig" => $noSig, "comNoBBCode" => $noBBCode))); $comid = mysql_insert_id(); // Now let's find out who created the parent object for this comment // (that would be a user id). $parentCreator = 0; switch ($objType) { case "obj": $collab = 0; $result = sql_query("SELECT `objCreator`, `objCollab`, `objCollabConfirmed` " . "FROM `objects`, `objExtData`" . dbWhere(array("objid*" => "objEid", "objid" => $objid))); if ($data = mysql_fetch_assoc($result)) { $parentCreator = $data["objCreator"]; $collab = $data["objCollabConfirmed"] ? $data["objCollab"] : 0; // Also gather Fan-to-Artist statistics... $where = array("fanUser" => $_auth["useid"], "fanArtist" => $parentCreator); sql_where($where); if (sql_count("fans") == 0) { $where["fanNumComments"] = 1; sql_values($where); sql_insert("fans"); } else { sql_where($where); sql_values(array("fanNumComments!" => "`fanNumComments` + 1")); sql_update("fans"); } if ($collab > 0) { $where = array("fanUser" => $_auth["useid"], "fanArtist" => $collab); sql_where($where); if (sql_count("fans") == 0) { $where["fanNumComments"] = 1; sql_values($where); sql_insert("fans"); } else { sql_where($where); sql_values(array("fanNumComments!" => "`fanNumComments` + 1")); sql_update("fans"); } } } // If this submission is in user's updates, mark it as viewed // automatically. markAsRead(updTypeArt, $objid); updateSearchCache($objid); if ($collab > 0 && $collab != $_auth["useid"]) { addUpdate(updTypeComment, $collab, $comid, $_auth["useid"]); } break; case "ext": // extra objects $result = sql_query("SELECT `objCreator` FROM `extras` " . "WHERE `objid` = '{$objid}' LIMIT 1"); $parentCreator = mysql_num_rows($result) > 0 ? mysql_result($result, 0) : 0; // If this submission is in user's updates, mark it as viewed // automatically. markAsRead(updTypeArtExtra, $objid); break; case "com": // comments $result = sql_query("SELECT `comCreator` FROM `comments` " . "WHERE `comid` = '{$objid}' LIMIT 1"); $parentCreator = mysql_num_rows($result) > 0 ? mysql_result($result, 0) : 0; // If this comment is in user's updates, mark it as read automatically. markAsRead(updTypeComment, $objid); break; case "clu": // clubs $result = sql_query("SELECT `cluCreator` FROM `cluExtData` " . "WHERE `cluEid` = '{$objid}' LIMIT 1"); $parentCreator = mysql_num_rows($result) > 0 ? mysql_result($result, 0) : 0; break; case "jou": // journals $result = sql_query("SELECT `jouCreator` FROM `journals` " . "WHERE `jouCreatorType` = 'use' AND `jouid` = '{$objid}' LIMIT 1"); $parentCreator = mysql_num_rows($result) > 0 ? mysql_result($result, 0) : 0; if ($parentCreator == 0) { // Not found? Maybe that journal is actually an announcement. $result = sql_query("SELECT `jouAnnCreator` FROM `journals` " . "WHERE `jouCreatorType` = 'clu' AND `jouid` = '{$objid}' LIMIT 1"); $parentCreator = mysql_num_rows($result) > 0 ? mysql_result($result, 0) : 0; } // If this journal/announcement is in user's updates, mark it as read // automatically. markAsRead(updTypeJournal, $objid); break; case "pol": // polls $result = sql_query("SELECT `polCreator` FROM `polls` " . "WHERE `polid` = '{$objid}' LIMIT 1"); $parentCreator = mysql_num_rows($result) > 0 ? mysql_result($result, 0) : 0; // If this poll is in user's updates, mark it as read automatically. markAsRead(updTypeJournalPoll, $objid); break; case "new": // news // Those who posted news on the front page should not receive // comments on that news to their updates. $parentCreator = 0; break; case "use": // user pages $parentCreator = $objid; break; } // Notify the parent object's creator about the new comment on their creation. // If the creator is not the current user, of course. if ($parentCreator > 0 && $parentCreator != $_auth["useid"]) { addUpdate(updTypeComment, $parentCreator, $comid, $_auth["useid"]); } // Redirect to the same page to clean up POST variables. $focus = "#comment" . ($objType == "com" ? $objid : $comid); if (isset($_POST["refererURL"])) { if (preg_match('/\\/updates\\//', $_POST["refererURL"])) { $focus = ""; } redirect($_POST["refererURL"] . $focus); } else { redirect(url(".", array("replied" => "yes")) . $focus); } }
function submitModifiedTitle($objid, $title, $comment, $mature, $forClub, $folder = 0, $collab = 0, $gift = 0, $forClub2 = 0, $forClub3 = 0) { $oldCollab = 0; $collabConfirmed = 0; $objCreator = 0; $sql = "SELECT `objCollab`, `objCollabConfirmed`, `objCreator` " . "FROM `objects`, `objExtData`" . dbWhere(array("objid*" => "objEid", "objid" => $objid)); $objResult = sql_query($sql); if ($objData = mysql_fetch_assoc($objResult)) { $oldCollab = $objData["objCollab"]; $collabConfirmed = $objData["objCollabConfirmed"]; $objCreator = $objData["objCreator"]; } mysql_free_result($objResult); if ($forClub2 == $forClub) { $forClub2 = 0; } if ($forClub3 == $forClub || $forClub3 == $forClub2) { $forClub3 = 0; } sql_where(array("cloObject" => $objid)); sql_delete("clubObjects"); if ($forClub > 0) { sql_values(array("cloObject" => $objid, "cloClub" => $forClub)); sql_insert("clubObjects"); } if ($forClub2 > 0) { sql_values(array("cloObject" => $objid, "cloClub" => $forClub2)); sql_insert("clubObjects"); } if ($forClub3 > 0) { sql_values(array("cloObject" => $objid, "cloClub" => $forClub3)); sql_insert("clubObjects"); } $values = array("objTitle" => $title, "objMature" => $mature, "objForClub" => $forClub, "objForClub2" => $forClub2, "objForClub3" => $forClub3, "objFolder" => $folder); if (!$collabConfirmed || atLeastSModerator()) { $values["objCollab"] = $collab; } $values["objForUser"] = $gift; $sql = "UPDATE `objects`" . dbSet($values) . dbWhere(array("objid" => $objid)); sql_query($sql); $values = array("objComment" => $comment); if ($collab == 0 && atLeastSModerator()) { $values["objCollabConfirmed"] = 0; } $sql = "UPDATE `objExtData`" . dbSet($values) . dbWhere(array("objEid" => $objid)); sql_query($sql); updateSearchCache($objid); updateObjCount($objCreator); updateObjCount($collab); if ($collab != $oldCollab) { updateObjCount($oldCollab); } }
} if (!isset($_GET["first"]) || !isset($_GET["last"])) { redirect(url(".", array("first" => 1, "last" => 1000))); } $first = intval($_GET["first"]); $last = intval($_GET["last"]); $isFinished = false; $result = sql_query("SELECT MAX(`objid`) FROM `objects`"); if ($data = mysql_fetch_row($result)) { if ($last > $data[0]) { $last = $data[0]; $isFinished = true; } } for ($objid = $first; $objid <= $last; $objid++) { updateSearchCache($objid, true); } echo "Updating search cache for submissions from {$first} to {$last}..."; $_documentTitle = "{$first} to {$last}"; if (!$isFinished) { ?> <script type="text/javascript"> //<![CDATA[ window.setTimeout( "document.location='<?php echo url(".", array("first" => $last + 1, "last" => $last + 300), '&'); ?> ';", 1000); //]]