close_feedback_on_old_entries(); This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class MT_Workbench_Core { /* Sample settings for a mt_workbench.php file: // the machine hosting the MySQL server var $database_server = "localhost"; // the MySQL user with access to the database var $database_name = "movable"; // the MySQL user password var $database_password = "swordfish"; // the path to Perl on the server var $perl_path = "/usr/bin/perl"; // the path to mt-rebuild.pl on the server var $mt_rebuild_path = "/etc/httpd/cgi-bin/mt-rebuild.pl"; */ // EDIT VARIABLES BELOW THIS LINE AT YOUR OWN RISK var $software_version = "0.1"; var $software_plugin_id = "http://workbench.cadenhead.org/mt-workbench"; var $debug = false; // set up a MT_Workbench_Core object function MT_Workbench_Core() { $this->set_last_run_date(); } // connect to the MySQL database function connect_to_database() { $db = mysql_connect($this->database_server, $this->database_name, $this->database_password); if (!$db) { error_log("Error: Could not connect to database."); return false; } else { mysql_select_db($this->database_name); return true; } } // close comments, trackback on old entries function close_feedback_on_old_entries($just_one_week = true) { if ($just_one_week) { $where_clause = "entry_created_on < date_add(curdate(), interval -7 day) AND entry_created_on > date_add(curdate(), interval -14 day) AND entry_allow_comments != 2 AND entry_allow_pings != 0"; } else { $where_clause = "entry_created_on < date_add(curdate(), interval -14 day)"; } // retrieve entries that will be updated $select_query = "SELECT entry_id, entry_blog_id FROM mt_entry WHERE $where_clause"; if ($this->debug) error_log($select_query); $this->connect_to_database(); $select_result = mysql_query($select_query); // update entries $update_query = "UPDATE mt_entry SET entry_allow_comments = 2, entry_allow_pings = 0 WHERE $where_clause"; if ($this->debug) error_log($update_query); $update_result = mysql_query($update_query); // rebuild entries that were updated while ($row = mysql_fetch_array($select_result)) { $this->rebuild_entry($row["entry_id"], $row["entry_blog_id"]); } return true; } // rebuild an entry to reflect closure of comments and trackback function rebuild_entry($entry_id, $entry_blog_id) { $command = "$this->perl_path $this->mt_rebuild_path -mode=\"entry\" -blog_id=$entry_blog_id -entry_id=$entry_id"; if ($this->debug) error_log($command); system($command); } // store last-run data in mt_plugindata database function set_last_run_date() { $info = $this->get_last_run_date(); $info["last_run"] = date("Y-m-d H:i:s"); $info["times_run"] = $info["times_run"] + 1; if ($info["times_run"] == 1) { $this->close_feedback_on_old_entries(false); while ($item = current($info)) { $query = "INSERT INTO mt_plugindata VALUES(0, '$this->software_plugin_id', '" . key($info) . "', '$item')"; if ($this->debug) error_log($query); $result = mysql_query($query); next($info); } } else { while ($item = current($info)) { $query = "UPDATE mt_plugindata SET plugindata_data = '$item' WHERE plugindata_plugin = '$this->software_plugin_id' AND plugindata_key = '" . key($info) . "'"; if ($this->debug) error_log($query); $result = mysql_query($query); next($info); } } } // retrieve last-run data in mt_plugindata database function get_last_run_date() { $query = "SELECT * from mt_plugindata WHERE plugindata_plugin = '$this->software_plugin_id'"; $this->connect_to_database(); $info = array(); if ($this->debug) error_log($query); $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $row = mysql_fetch_array($result); $info[$row["plugindata_key"]] = $row["plugindata_data"]; } return $info; } } ?>