diff -r 000000000000 -r 902822492a68 plugins/ajim/ajim.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/ajim/ajim.php Wed Jun 13 16:03:00 2007 -0400
@@ -0,0 +1,825 @@
+'.$text);
+ }
+ /**
+ * Make a SQL query. This function contains some error correction that performs automatic database upgrades if needed.
+ * @param string $q - The query text to send to MySQL.
+ * @return resource - or, kills the connection and bails out if the query failed
+ */
+ function sql($q) {
+ $r = mysql_query($q, $this->conn);
+ if(!$r)
+ {
+ if(strstr(mysql_error(), 'Unknown column \'time_id\''))
+ {
+ $this->sql('ALTER TABLE '.$this->table_prefix.'ajim ADD COLUMN time_id int(11) NOT NULL DEFAULT 0;');
+ $r = mysql_query($q, $this->conn);
+ }
+ elseif(strstr(mysql_error(), 'Unknown column \'sid\''))
+ {
+ $this->sql('ALTER TABLE '.$this->table_prefix.'ajim ADD COLUMN sid varchar(40) NOT NULL DEFAULT \'\';');
+ $r = mysql_query($q, $this->conn);
+ }
+ elseif(strstr(mysql_error(), 'Unknown column \'ip_addr\''))
+ {
+ $this->sql('ALTER TABLE '.$this->table_prefix.'ajim ADD COLUMN ip_addr varchar(15) NOT NULL DEFAULT \'\';');
+ $r = mysql_query($q, $this->conn);
+ }
+ $this->kill('Error during query:
'.htmlspecialchars($q).'
MySQL said: '.mysql_error().'
Depending on the error, AjIM may be able to automatically repair it. Just hang tight for about ten seconds. Whatever you do, don\'t close this browser window!');
+ }
+ return $r;
+ }
+ /**
+ * Get the user's SID (unique ID used for editing authorization) or generate a new one.
+ * @return string
+ */
+ function get_sid()
+ {
+ // Tag the user with a unique ID that can be used to edit posts
+ // This is used to essentially track users, but only for the purpose of letting them edit posts
+ if(!isset($_COOKIE['ajim_sid']))
+ {
+ $hash = sha1(microtime());
+ setcookie('ajim_sid', $hash, time()+60*60*24*365); // Cookies last for one year
+ }
+ else
+ $hash = $_COOKIE['ajim_sid'];
+
+ return $hash;
+ }
+ /**
+ * Set the default value for a configuration field.
+ * @param string $key - name of the configuration key
+ * @param string $value - the default value
+ * @param array $confarray - needs to be the array passed as the first param on the constructor
+ */
+ function config_default($key, $value, &$confarray)
+ {
+ if(!isset($confarray[$key]))
+ $confarray[$key] = $value;
+ }
+ /**
+ * Set up some basic vars and a database connection
+ * @param array $config - a configuration array, with either the key db_connection_handle (a valid MySQL connection resource) or the keys dbhost, dbname, dbuser, and dbpass
+ * @param string $table_prefix - the text prepended to the "ajim" table, should match ^([A-z0-9_]+)$
+ * @param string $handler - URL to the backend script, for example in Enano this would be the plugin file plugins/ajim.php
+ * @param string $admin - string containing the MD5 hash of the user's password, IF AND ONLY IF the user should be allowed to use the moderation function. In all other cases this should be false.
+ * @param string $id - used to carry over the randomly generated instance ID between requests. Should be false if the class is being initialized for displaying the inital HTML, in all other cases should be the value of the class variable AjIM::$id
+ * @param bool $can_post - true if the user is allowed to post, false otherwise. Defaults to true.
+ * @param mixed $formatfunc - a string containing the name of a function that can be called to format text before posts are sent to the user. If you need to call a class method, this should be an array with key 0 being the class name and key 1 being the method name.
+ */
+ function __construct($config, $table_prefix, $handler, $admin = false, $id = false, $can_post = true, $formatfunc = false) {
+ // CONFIGURATION
+ // $this->prune: a limit on the number of posts in the chat box. Usually this should be set to 40 or 50. Default is 40.
+ // Set to -1 to disable pruning.
+ $this->prune = -1;
+
+ $this->get_sid();
+
+ if(!is_array($config))
+ $this->kill('$config passed to the AjIM constructor should be an associative array with either the keys dbhost, dbname, dbuser, and dbpass, or the key db_connection_handle.');
+ if(isset($config['db_connection_handle']))
+ {
+ if(!is_resource($config['db_connection_handle'])) $this->kill('$config[\'db_connection_handle\'] is not a valid resource');
+ $this->conn = $config['db_connection_handle'];
+ if(!$this->conn) $this->kill('Error verifying database connection: '.mysql_error());
+ } elseif(isset($config['dbhost']) && isset($config['dbname']) && isset($config['dbuser']) && isset($config['dbpass'])) {
+ $this->conn = mysql_connect($config['dbhost'], $config['dbuser'], $config['dbpass']);
+ if(!$this->conn) $this->kill('Error connecting to the database: '.mysql_error());
+ $this->sql('USE '.$config['dbname']);
+ }
+
+ $this->bad_words = Array('viagra', 'phentermine', 'pharma', 'rolex', 'genital', 'penis', 'ranitidine', 'prozac', 'acetaminophen', 'acyclovir', 'ionamin', 'denavir', 'nizoral', 'zoloft', 'estradiol', 'didrex', 'aciphex', 'seasonale', 'allegra', 'lexapro', 'famvir', 'propecia', 'nasacort');
+ if(isset($config['bad_words']) && is_array($config['bad_words']))
+ {
+ $this->bad_words = array_values(array_merge($this->bad_words, $config['bad_words']));
+ }
+
+ // Don't change these values here - change them by passing values to the config array in this constructor's params!
+ $this->config_default('sb_color_background', '#FFFFFF', $config);
+ $this->config_default('sb_color_foreground', '#000000', $config);
+ $this->config_default('sb_color_editlink', '#00C000', $config);
+ $this->config_default('sb_color_deletelink', '#FF0000', $config);
+ $this->config_default('sb_color_userlink', '#0000FF', $config);
+
+ $this->config = $config;
+
+ if($id) $this->id = $id;
+ else $this->id = 'ajim_'.time();
+ $this->admin = $admin;
+ $this->formatfunc = $formatfunc;
+ $this->can_post = $can_post;
+ $this->table_prefix = $table_prefix;
+ $this->sql('CREATE TABLE IF NOT EXISTS '.$this->table_prefix.'ajim(
+ post_id mediumint(8) NOT NULL auto_increment,
+ name text,
+ website text,
+ post text,
+ time_id int(11) NOT NULL DEFAULT 0,
+ PRIMARY KEY ( post_id )
+ );');
+ $this->iface = $handler;
+ if(isset($_GET['ajimmode'])) $this->handler();
+ }
+ /**
+ * A dummy function used for PHP4 compatibility.
+ * @see AjIM::__construct()
+ */
+ function ajim($config, $table_prefix, $handler, $admin = false, $id = false, $can_post = true, $formatfunc = false) {
+ $this->__construct($config, $table_prefix, $handler, $admin, $id, $can_post, $formatfunc);
+ }
+ /**
+ * Generates the initial HTML UI to be sent to the user, used internally.
+ * @access private
+ * @param string $ajimPath - path to the AjIM connector (not this file), relative to document root, with initial slash.
+ */
+ function html($ajimPath) {
+
+ $enstr = $this->can_post ? '' : ' disabled="disabled"';
+ $html = '';
+ $html .= '';
+ if($this->admin) {
+ $html.= '';
+ }
+ $html .= '
+ ';
+ // This is the post form div
+ if($this->can_post)
+ {
+ $html .= '