function init__chat() { global $MEMBERS_BEFRIENDED; $MEMBERS_BEFRIENDED = NULL; global $EFFECT_SETTINGS_ROWS; $EFFECT_SETTINGS_ROWS = NULL; if (!defined('CHAT_ACTIVITY_PRUNE')) { define('CHAT_ACTIVITY_PRUNE', 25); define('CHAT_BACKLOG_TIME', 60 * 5); // 5 minutes of messages if you enter an existing room define('CHAT_EVENT_PRUNE', 60 * 24); } if (get_page_name() == 'chat') { require_code('developer_tools'); destrictify(false); } }
function get_dropbox_dir() { require_code('developer_tools'); destrictify(); //get/set login details $hash = get_param('hash'); $dbemail = get_value('db_username_' . $hash); $dbpassword = get_value('db_password_' . $hash); $sub_dir = get_value('db_sub_dir_' . $hash); $sub_dir_new = get_param('sub_dir', ''); $sub_dir = isset($sub_dir_new) && strlen($sub_dir_new) > 0 ? $sub_dir_new : $sub_dir; $dbdir = ''; set_value('db_username_' . $hash, $dbemail); set_value('db_password_' . $hash, $dbpassword); set_value('db_sub_dir_' . $hash, $sub_dir); //include DropboxConnection class if (file_exists(get_file_base() . '/sources_custom/DropboxConnection.php')) { require get_file_base() . '/sources_custom/DropboxConnection.php'; } //remove "/" at the end of $sub_dir if any while (preg_match('/\\/$/', $sub_dir)) { $sub_dir = substr($sub_dir, 0, mb_strlen($sub_dir) - 1); } echo "You are here: " . $sub_dir . "<hr>"; try { $db_connection = new DropboxConnection($dbemail, $dbpassword); $directories = $db_connection->getdirs($dbdir . "/" . $sub_dir); if (isset($sub_dir)) { $parent_dir_array = explode("/", $sub_dir); $parent_dir = ''; for ($x = 0; $x < count($parent_dir_array) - 1; $x++) { $parent_dir .= $parent_dir_array[$x] . "/"; } echo "<a href='" . find_script('dropbox_list') . "?sub_dir=" . $parent_dir . "&hash=" . $hash . "'>../</a><br>"; } foreach ($directories as $directory) { echo "DIR - <a href='" . find_script('dropbox_list') . "?hash=" . $hash . "&sub_dir=" . $sub_dir . "/" . $directory . "'>" . $directory . "</a><br>"; } $files = $db_connection->getfiles($dbdir . "/" . $sub_dir); foreach ($files as $file) { echo "<a href='" . find_script('dropbox_get') . "?hash=" . $hash . "&get=" . $sub_dir . "/" . $file[0] . "&w=" . $file[1] . "'>" . $file[0] . "</a><br>"; } } catch (Exception $e) { echo '<span style="color: red">Error: ' . htmlspecialchars($e->getMessage()) . '</span>'; } }
function StrToNum($Str, $Check, $Magic) { // This is external code which doesn't live up to ocPortal's strictness level require_code('developer_tools'); destrictify(); $Int32Unit = 4294967296; // 2^32 $length = strlen($Str); for ($i = 0; $i < $length; $i++) { $Check *= $Magic; //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), // the result of converting to integer is undefined // refer to http://www.php.net/manual/en/language.types.integer.php if ($Check >= $Int32Unit) { $Check = $Check - $Int32Unit * intval($Check / $Int32Unit); //if the check less than -2^31 $Check = $Check < -2147483648 ? $Check + $Int32Unit : $Check; } $Check += ord($Str[$i]); } return $Check; }
<?php require_code('developer_tools'); destrictify(); require_code('twitter'); require_lang('twitter'); $title = get_page_title('TWITTER_OAUTH'); $api_key = get_option('twitter_api_key', true); $api_secret = get_option('twitter_api_secret', true); if (is_null($api_key)) { require_code('database_action'); add_config_option('TWITTER_API_KEY', 'twitter_api_key', 'line', 'return \'\';', 'FEATURE', 'TWITTER_SYNDICATION'); add_config_option('TWITTER_API_SECRET', 'twitter_api_secret', 'line', 'return \'\';', 'FEATURE', 'TWITTER_SYNDICATION'); $api_key = ''; $api_secret = ''; } if ($api_key == '' || $api_secret == '') { $config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => 'FEATURE', 'redirect' => get_self_url(true)), '_SELF', NULL, false, false, false, 'group_TWITTER_SYNDICATION'); require_code('site2'); assign_refresh($config_url, 0.0); $echo = do_template('REDIRECT_SCREEN', array('URL' => $config_url, 'TITLE' => $title, 'TEXT' => do_lang_tempcode('TWITTER_SETUP_FIRST'))); $echo->evaluate_echo(); return; } require_code('hooks/systems/syndication/twitter'); $ob = new Hook_Syndication_twitter(); $result = $ob->auth_set(NULL, get_self_url(false, false, array('oauth_in_progress' => 1))); if ($result) { $out = do_lang_tempcode('TWITTER_OAUTH_SUCCESS'); } else { $out = do_lang_tempcode('SOME_ERRORS_OCCURRED');
/** * Log varible to Firebug * * @see http://www.firephp.org/Wiki/Reference/Fb * @param mixed $Object The variable to be logged * @return true Return TRUE if message was added to headers, FALSE otherwise * @throws Exception */ function fb($Object) { require_code('developer_tools'); destrictify(); if (!$this->enabled) { return false; } /*if (headers_sent($filename, $linenum)) { trigger_error('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.'); }*/ $Type = null; $Label = null; $Options = array(); if (func_num_args() == 1) { } else { if (func_num_args() == 2) { switch (func_get_arg(1)) { case FirePHP_LOG: case FirePHP_INFO: case FirePHP_WARN: case FirePHP_ERROR: case FirePHP_DUMP: case FirePHP_TRACE: case FirePHP_TABLE: case FirePHP_GROUP_START: case FirePHP_GROUP_END: $Type = func_get_arg(1); break; default: $Label = func_get_arg(1); break; } } else { if (func_num_args() == 3) { $Type = func_get_arg(2); $Label = func_get_arg(1); } else { if (func_num_args() == 4) { $Type = func_get_arg(2); $Label = func_get_arg(1); $Options = func_get_arg(3); } else { trigger_error('Wrong number of arguments to fb() function!'); } } } } if (!$this->detectClientExtension()) { return false; } $meta = array(); $skipFinalObjectEncode = false; if ($Type == FirePHP_TRACE) { $trace = debug_backtrace(); if (!$trace) { return false; } for ($i = 0; $i < sizeof($trace); $i++) { if (isset($trace[$i]['class']) && isset($trace[$i]['file']) && ($trace[$i]['class'] == 'FirePHP' || $trace[$i]['class'] == 'FB') && (substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php' || substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php')) { /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ } else { if (isset($trace[$i]['class']) && isset($trace[$i + 1]['file']) && $trace[$i]['class'] == 'FirePHP' && substr($this->_standardizePath($trace[$i + 1]['file']), -18, 18) == 'FirePHPCore/fb.php') { /* Skip fb() */ } else { if ($trace[$i]['function'] == 'fb' || $trace[$i]['function'] == 'trace' || $trace[$i]['function'] == 'send') { $Object = array('Class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : '', 'Type' => isset($trace[$i]['type']) ? $trace[$i]['type'] : '', 'Function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : '', 'Message' => $trace[$i]['args'][0], 'File' => isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : '', 'Line' => isset($trace[$i]['line']) ? $trace[$i]['line'] : '', 'Args' => isset($trace[$i]['args']) ? $this->encodeObject($trace[$i]['args']) : '', 'Trace' => $this->_escapeTrace(array_splice($trace, $i + 1))); $skipFinalObjectEncode = true; $meta['file'] = isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : ''; $meta['line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; break; } } } } } else { if ($Type == FirePHP_TABLE) { if (isset($Object[0]) && is_string($Object[0])) { $Object[1] = $this->encodeTable($Object[1]); } else { $Object = $this->encodeTable($Object); } $skipFinalObjectEncode = true; } else { if ($Type == FirePHP_GROUP_START) { if (!$Label) { trigger_error('You must specify a label for the group!'); } } else { if ($Type === null) { $Type = FirePHP_LOG; } } } } if ($this->options['includeLineNumbers']) { if (!isset($meta['file']) || !isset($meta['line'])) { $trace = debug_backtrace(); for ($i = 0; $trace && $i < sizeof($trace); $i++) { if (isset($trace[$i]['class']) && isset($trace[$i]['file']) && ($trace[$i]['class'] == 'FirePHP' || $trace[$i]['class'] == 'FB') && (substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php' || substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php')) { /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ } else { if (isset($trace[$i]['class']) && isset($trace[$i + 1]['file']) && $trace[$i]['class'] == 'FirePHP' && substr($this->_standardizePath($trace[$i + 1]['file']), -18, 18) == 'FirePHPCore/fb.php') { /* Skip fb() */ } else { if (isset($trace[$i]['file']) && substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php') { /* Skip FB::fb() */ } else { $meta['file'] = isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : ''; $meta['line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; break; } } } } } } else { unset($meta['file']); unset($meta['line']); } $this->setHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); $this->setHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/' . FirePHP_VERSION); $structure_index = 1; if ($Type == FirePHP_DUMP) { $structure_index = 2; $this->setHeader('X-Wf-1-Structure-2', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); } else { $this->setHeader('X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); } if ($Type == FirePHP_DUMP) { $msg = '{"' . $Label . '":' . $this->jsonEncode($Object, $skipFinalObjectEncode) . '}'; } else { $msg_meta = $Options; $msg_meta['Type'] = $Type; if ($Label !== null) { $msg_meta['Label'] = $Label; } if (isset($meta['file']) && !isset($msg_meta['File'])) { $msg_meta['File'] = $meta['file']; } if (isset($meta['line']) && !isset($msg_meta['Line'])) { $msg_meta['Line'] = $meta['line']; } $msg = '[' . $this->jsonEncode($msg_meta) . ',' . $this->jsonEncode($Object, $skipFinalObjectEncode) . ']'; } $parts = explode("\n", chunk_split($msg, 5000, "\n")); for ($i = 0; $i < count($parts); $i++) { $part = $parts[$i]; if ($part) { if (count($parts) > 2) { // Message needs to be split into multiple parts $this->setHeader('X-Wf-1-' . strval($structure_index) . '-' . '1-' . strval($this->messageIndex), ($i == 0 ? strlen($msg) : '') . '|' . $part . '|' . ($i < count($parts) - 2 ? '\\' : '')); } else { $this->setHeader('X-Wf-1-' . strval($structure_index) . '-' . '1-' . strval($this->messageIndex), strval(strlen($part)) . '|' . $part . '|'); } $this->messageIndex++; if ($this->messageIndex > 99999) { trigger_error('Maximum number (99,999) of messages reached!'); } } } $this->setHeader('X-Wf-1-Index', strval($this->messageIndex - 1)); return true; }
function _send($token, $secret, $row) { require_lang('twitter'); require_code('twitter'); list($message) = render_activity($row, false); $link = static_evaluate_tempcode(pagelink_to_tempcode($row['a_pagelink_1'])); // Shorten message for Twitter purposes $chopped_message = html_entity_decode(strip_tags($message->evaluate()), ENT_COMPAT, get_charset()); $max_length = 255; $shortened_link = mixed(); if ($link != '') { $shortened_link = http_download_file('http://is.gd/api.php?longurl=' . urlencode($link)); $max_length -= strlen($shortened_link) + 1; } if (strlen($chopped_message) > $max_length) { $chopped_message = substr($chopped_message, 0, $max_length - 3) . '...'; } if ($link != '') { $chopped_message .= ' ' . $shortened_link; } require_code('character_sets'); $chopped_message = convert_to_internal_encoding($chopped_message, get_charset(), 'utf-8'); require_code('developer_tools'); destrictify(); // Initiate Twitter connection $api_key = get_option('twitter_api_key'); $api_secret = get_option('twitter_api_secret'); $twitter = new Twitter($api_key, $api_secret); $twitter->setOAuthToken($token); $twitter->setOAuthTokenSecret($secret); // Send message try { $twitter->statusesUpdate($chopped_message); } catch (TwitterException $e) { attach_message($e->getMessage(), 'warn'); return false; } return true; }
/** * Handle hooks supported bot commands. Note multiple bots may support the same commands, and all respond. It is recommended all bots support the command 'help'. * * @param AUTO_LINK The ID of the chat room * @param string The command used. This is just the chat message, so you can encode and recognise your own parameter scheme if you like. * @return ?string Bot reply (NULL: bot does not handle the command) */ function handle_commands($room_id, $string) { require_code('developer_tools'); destrictify(); if ($string == '((SHAKE))') { return NULL; } if (file_exists(get_custom_file_base() . '/sources_custom/programe')) { if (get_value('octavius_installed') !== '1') { disable_php_memory_limit(); if (function_exists('set_time_limit')) { @set_time_limit(600); } $GLOBALS['SITE_DB']->query("DROP TABLE bot", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE bots", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE conversationlog", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE dstore", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE gmcache", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE gossip", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE patterns", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE templates", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE thatindex", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE thatstack", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE bot (\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t bot tinyint(4) NOT NULL default '0',\n\t\t\t\t name varchar(255) NOT NULL default '',\n\t\t\t\t value text NOT NULL,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY botname (bot,name)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE bots (\n\t\t\t\t id tinyint(3) unsigned NOT NULL auto_increment,\n\t\t\t\t botname varchar(255) NOT NULL default '',\n\t\t\t\t PRIMARY KEY (botname),\n\t\t\t\t KEY id (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE conversationlog (\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t input text,\n\t\t\t\t response text,\n\t\t\t\t uid varchar(255) default NULL,\n\t\t\t\t enteredtime timestamp(14) NOT NULL,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY botid (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE dstore (\n\t\t\t\t uid varchar(255) default NULL,\n\t\t\t\t name text,\n\t\t\t\t value text,\n\t\t\t\t enteredtime timestamp(14) NOT NULL,\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY nameidx (name(40))\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE gmcache (\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t template int(11) NOT NULL default '0',\n\t\t\t\t inputstarvals text,\n\t\t\t\t thatstarvals text,\n\t\t\t\t topicstarvals text,\n\t\t\t\t patternmatched text,\n\t\t\t\t inputmatched text,\n\t\t\t\t combined text NOT NULL,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY combined (bot,combined(255))\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE gossip (\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t gossip text,\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY botidx (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE patterns (\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t word varchar(255) default NULL,\n\t\t\t\t ordera tinyint(4) NOT NULL default '0',\n\t\t\t\t parent int(11) NOT NULL default '0',\n\t\t\t\t isend tinyint(4) NOT NULL default '0',\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY wordparent (parent,word),\n\t\t\t\t KEY botid (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE templates (\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t id int(11) NOT NULL default '0',\n\t\t\t\t template text NOT NULL,\n\t\t\t\t pattern varchar(255) default NULL,\n\t\t\t\t that varchar(255) default NULL,\n\t\t\t\t topic varchar(255) default NULL,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY bot (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE thatindex (\n\t\t\t\t uid varchar(255) default NULL,\n\t\t\t\t enteredtime timestamp(14) NOT NULL,\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t PRIMARY KEY (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE thatstack (\n\t\t\t\t thatid int(11) NOT NULL default '0',\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t value varchar(255) default NULL,\n\t\t\t\t enteredtime timestamp(14) NOT NULL,\n\t\t\t\t PRIMARY KEY (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $fp = ""; $templatesinserted = 0; $depth = array(); $whaton = ""; $pattern = ""; $topic = ""; $that = ""; $template = ""; $startupwhich = ""; $splitterarray = array(); $inputarray = array(); $genderarray = array(); $personarray = array(); $person2array = array(); require_code('programe/botloaderfuncs'); loadstartup(); makesubscode(); set_value('octavius_installed', '1'); } require_code('programe/respond'); $response = replybotname(str_replace('?', '.', $string), get_session_id(), 'octavius'); restrictify(); if (is_null($response) || $response->response == '') { return NULL; } return '[html]' . $response->response . '[/html]'; } // Eliza... // setup initial variables and values $kwarray = array(); $vararray = array(); $resparray = array(); $priarray = array(); $wordarray = array(); $kwcount = 0; $varcount = 0; $respcount = 0; $syncount = 0; mt_srand((double) microtime() * 1000000); // load knowledge file $lines_array = file(get_custom_file_base() . "/sources_custom/hooks/modules/chat_bots/knowledge.txt"); $count = count($lines_array); // This for loop goes through the entire knowledge file and places // the elements into arrays. This later allows us to pull the information // (ie. key words, variances on the keywords, and responses) out of the // arrays. for ($x = 0; $x < $count; $x++) { $lines_array[$x] = trim($lines_array[$x]); $lines_array[$x] = ereg_replace("[\\]", "", $lines_array[$x]); if (strstr($lines_array[$x], "key:")) { eregi("key: (.*)", $lines_array[$x], $kw); $kwarray[$kwcount] = strtoupper($kw[1]); $currentkw = $kwcount; $kwcount++; $varcount = 0; // reset varcount to null $respcount = 0; // reset respcount to null $pricount = 0; // reset pricount to null } else { if (strstr($lines_array[$x], "var:")) { eregi("var: (.*)", $lines_array[$x], $variance); $vararray[$currentkw][$varcount] = strtoupper($variance[1]); $varcurrent = $varcount; $varcount++; $respcount = 0; } else { if (strstr($lines_array[$x], "pri:")) { eregi("pri: (.*)", $lines_array[$x], $priority); $priarray[$currentkw] = $priority[1]; } else { if (strstr($lines_array[$x], "resp:")) { eregi("resp: (.*)", $lines_array[$x], $response); $resparray[$currentkw][$varcurrent][$respcount] = $response[1]; $respcount++; } else { if (strstr($lines_array[$x], "syn:")) { eregi("syn: (.*)", $lines_array[$x], $synonym); $synonymarray[$syncount] = strtoupper($synonym[1]); $syncount++; } else { if (strstr($lines_array[$x], "goto:")) { eregi("goto: (.*)", $lines_array[$x], $goto); $goto = strtoupper($goto[1]); // find the keyword for ($zcount = 0; $zcount < count($kwarray); $zcount++) { // if the keyword already exists if (eregi($goto, $kwarray[$zcount])) { // then we assign properties of the keyword $vararray[$currentkw][0] = $kwarray[$currentkw]; $resparray[$currentkw] = $resparray[$zcount]; } } } } } } } } } $y = 0; $z = 0; $v = 0; $bestpriority = -2; $originalstring = $string; if (!$string) { $string = "hello"; } $string = strtoupper($string); // Figures out what word in the string has the most priority. // It can then check words to the left/right of this word depending // upon settings in the knowledge.txt file. while ($y < count($kwarray)) { // remove beginning and trailing white space, breaks, etc $string = trim($string); // remove puncuation from string $string = ereg_replace('[!?,.]', '', $string); // split the string up into seperate words $wordarray = explode(" ", $string); while ($v < count($wordarray)) { if (eregi($wordarray[$v] . "\$", $kwarray[$y])) { // find which word holds the most weight in the sentance if ($bestpriority == -2) { $bestpriority = $y; } else { if ($priarray[$bestpriority] < $priarray[$y]) { $bestpriority = $y; } } } $v++; } $v = 0; $y++; } // find the variance with the most matching words $vcount = 0; while ($vcount < count($vararray[$bestpriority])) { if (strstr($vararray[$bestpriority][$vcount], "@")) { eregi("@(.*)", $vararray[$bestpriority][$vcount], $syn); // fix this $syn = $syn[1]; for ($x = 0; $x < count($synonymarray); $x++) { if (eregi($syn, strtoupper($synonymarray[$x]))) { $sarray = explode(" ", $synonymarray[$x]); for ($f = 0; $f < count($sarray); $f++) { $newstring = ereg_replace("@(.*)\$", $sarray[$f], $vararray[$bestpriority][$vcount]); // works to this point if (eregi($newstring . "\$", $string)) { $varray = explode(" ", $vararray[$bestpriority][$vcount]); if (count($varray) > $pvarray) { $bestvariance = $vcount; $pvarray = count($varray); } } } } } } else { if (ereg($vararray[$bestpriority][$vcount], $string)) { $varray = explode(" ", $vararray[$bestpriority][$vcount]); if (count($varray) > $pvarray) { $bestvariance = $vcount; $pvarray = count($varray); } } } $vcount++; } // Using the bestpriority (aka the keyword (key:) with the most weight in the sentence) // and the bestvariance (aka, the variance (var:) phrase that most fits the context of // the original sentence, we form a response. if (count($resparray[$bestpriority][$bestvariance]) > 1) { $random = mt_rand(0, count($resparray[$bestpriority][$bestvariance]) - 1); } else { $random = 0; } $response = $resparray[$bestpriority][$bestvariance][$random]; if ($response == "") { $response = "Sorry, I don't understand what you're trying to say."; } $originalstring = ereg_replace("[\\]", "", $originalstring); restrictify(); return $response; }
/** * Render a code box. * * @param string The data type (e.g. file extension) we are rendering. * @param tempcode Contents (code) to render. * @param boolean Whether to show line numbers. * @param boolean Whether what we have came from inside a semihtml tag * @param boolean Whether what we have came from semihtml mode * @return array A pair: The tempcode for the code box, and the title of the box */ function do_code_box($type, $embed, $numbers = true, $in_semihtml = false, $is_all_semihtml = false) { $_embed = mixed(); $title = mixed(); if (file_exists(get_file_base() . '/sources/geshi/' . filter_naughty(strtolower($type)) . '.php') || file_exists(get_file_base() . '/sources_custom/geshi/' . filter_naughty($type) . '.php')) { $evaluated = $embed->evaluate(); if ($in_semihtml || $is_all_semihtml) { require_code('comcode_from_html'); $evaluated = semihtml_to_comcode($evaluated, true); } require_code('geshi'); if (class_exists('GeSHi')) { require_code('developer_tools'); destrictify(); $geshi = new GeSHi($evaluated, strtolower($type)); $geshi->set_header_type(GESHI_HEADER_DIV); if ($numbers) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } require_lang('comcode'); $title = do_lang_tempcode('comcode:CODE_IN_LANGUAGE', escape_html($type)); require_code('xhtml'); $_embed = xhtmlise_html($geshi->parse_code()); restrictify(); } } else { switch (strtolower($type)) { case 'php': if (!function_exists('highlight_string')) { break; } $evaluated = $embed->evaluate(); if ($in_semihtml || $is_all_semihtml) { require_code('comcode_from_html'); $evaluated = semihtml_to_comcode($evaluated); } if (strpos($evaluated, '<' . '?php') === false) { $strip = true; $evaluated = "<" . "?php\n" . $evaluated . "\n?" . ">"; } else { $strip = false; } require_code('xhtml'); if (defined('HIPHOP_PHP')) { $h_result = nl2br(escape_html($evaluated)); } else { ob_start(); highlight_string($evaluated); $h_result = ob_get_contents(); ob_end_clean(); } $_embed = xhtmlise_html($h_result); if ($strip) { $_embed = str_replace('<?php<br />', '', $_embed); $_embed = str_replace('?>', '', $_embed); } $title = do_lang_tempcode('PHP_CODE'); break; } } return array($_embed, $title); }
/** * Get the block object for a given block codename. * * @param ID_TEXT The block name * @param ?array The block parameter map (NULL: no parameters) * @return mixed Either the block object, or the string output of a miniblock */ function do_block_hunt_file($codename, $map = NULL) { global $BLOCKS_AT_CACHE; $codename = filter_naughty_harsh($codename); $file_base = get_file_base(); global $_REQUIRED_CODE; if (isset($BLOCKS_AT_CACHE[$codename]) && !in_safe_mode() && $BLOCKS_AT_CACHE[$codename] == 'sources_custom/blocks' || !isset($BLOCKS_AT_CACHE[$codename]) && is_file($file_base . '/sources_custom/blocks/' . $codename . '.php')) { if (!isset($_REQUIRED_CODE['blocks/' . $codename])) { require_once $file_base . '/sources_custom/blocks/' . $codename . '.php'; } $_REQUIRED_CODE['blocks/' . $codename] = 1; if (!isset($BLOCKS_AT_CACHE[$codename])) { $BLOCKS_AT_CACHE[$codename] = 'sources_custom/blocks'; if (function_exists('persistant_cache_set')) { persistant_cache_set('BLOCKS_AT', $BLOCKS_AT_CACHE, true); } } } elseif (isset($BLOCKS_AT_CACHE[$codename]) && $BLOCKS_AT_CACHE[$codename] == 'sources/blocks' || !isset($BLOCKS_AT_CACHE[$codename]) && is_file($file_base . '/sources/blocks/' . $codename . '.php')) { if (!isset($_REQUIRED_CODE['blocks/' . $codename])) { require_once $file_base . '/sources/blocks/' . $codename . '.php'; } $_REQUIRED_CODE['blocks/' . $codename] = 1; if (!isset($BLOCKS_AT_CACHE[$codename])) { $BLOCKS_AT_CACHE[$codename] = 'sources/blocks'; if (function_exists('persistant_cache_set')) { persistant_cache_set('BLOCKS_AT', $BLOCKS_AT_CACHE, true); } } } else { if (isset($BLOCKS_AT_CACHE[$codename]) && !in_safe_mode() && $BLOCKS_AT_CACHE[$codename] == 'sources_custom/miniblocks' || !isset($BLOCKS_AT_CACHE[$codename]) && is_file($file_base . '/sources_custom/miniblocks/' . $codename . '.php')) { require_code('developer_tools'); destrictify(); ob_start(); if (defined('HIPHOP_PHP')) { require 'sources_custom/miniblocks/' . $codename . '.php'; } else { require $file_base . '/sources_custom/miniblocks/' . $codename . '.php'; } $object = ob_get_contents(); if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($object); } ob_end_clean(); restrictify(); if (!isset($BLOCKS_AT_CACHE[$codename])) { $BLOCKS_AT_CACHE[$codename] = 'sources_custom/miniblocks'; if (function_exists('persistant_cache_set')) { persistant_cache_set('BLOCKS_AT', $BLOCKS_AT_CACHE, true); } } } elseif (isset($BLOCKS_AT_CACHE[$codename]) && $BLOCKS_AT_CACHE[$codename] == 'sources/miniblocks' || !isset($BLOCKS_AT_CACHE[$codename]) && is_file($file_base . '/sources/miniblocks/' . $codename . '.php')) { require_code('developer_tools'); destrictify(); ob_start(); if (defined('HIPHOP_PHP')) { require 'sources/miniblocks/' . $codename . '.php'; } else { require $file_base . '/sources/miniblocks/' . $codename . '.php'; } $object = ob_get_contents(); if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($object); } ob_end_clean(); restrictify(); if (!isset($BLOCKS_AT_CACHE[$codename])) { $BLOCKS_AT_CACHE[$codename] = 'sources/miniblocks'; if (function_exists('persistant_cache_set')) { persistant_cache_set('BLOCKS_AT', $BLOCKS_AT_CACHE, true); } } } elseif (is_null($map) || !array_key_exists('failsafe', $map) || $map['failsafe'] != '1') { $temp = paragraph(do_lang_tempcode('MISSING_BLOCK_FILE', escape_html($codename)), '90dfdlksds8d7dyddssdds', 'error_marker'); return $temp->evaluate(); } else { $object = ''; } return $object; } $_object = object_factory('Block_' . $codename); return $_object; }
/** * Standard login provider hook. * * @param ?MEMBER Member ID already detected as logged in (NULL: none). May be a guest ID. * @return ?MEMBER Member ID now detected as logged in (NULL: none). May be a guest ID. */ function try_login($member) { // Some kind of OpenID provider try { require_code('openid'); require_code('developer_tools'); if (!isset($_REQUEST['openid_mode'])) { if (array_key_exists('openid_identifier', $_POST)) { destrictify(); $openid = new LightOpenID(); $openid->identity = $_POST['openid_identifier']; $openid->required = array('namePerson/friendly', 'namePerson', 'contact/email', 'birthDate', 'pref/language', 'media/image/default'); header('Location: ' . $openid->authUrl()); exit; } } elseif ($_GET['openid_mode'] == 'cancel') { destrictify(); require_code('site'); require_code('site2'); attach_message('You cancelled your OpenID login, so you are not logged into the site.', 'inform'); } else { destrictify(); $openid = new LightOpenID(); if ($openid->validate()) { $attributes = $openid->getAttributes(); // If member already existed, no action needed - just create a session to existing record $member = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_password_compat_scheme' => 'openid', 'm_pass_hash_salted' => $openid->identity)); if (!is_null($member)) { require_code('users_inactive_occasionals'); create_session($member, 1, isset($_COOKIE[get_member_cookie() . '_invisible']) && $_COOKIE[get_member_cookie() . '_invisible'] == '1'); // This will mark it as confirmed return $member; } require_code('ocf_members'); require_code('ocf_groups'); require_lang('ocf'); if (running_script('index') || running_script('execute_temp')) { require_code('ocf_members_action'); require_code('ocf_members_action2'); $email = ''; if (array_key_exists('contact/email', $attributes)) { $email = $attributes['contact/email']; } $username = $openid->identity; // Yuck, we'll try and build on this if (array_key_exists('namePerson/friendly', $attributes)) { $username = $attributes['namePerson/friendly']; } elseif (array_key_exists('namePerson', $attributes)) { $username = $attributes['namePerson']; } elseif ($email != '') { $username = substr($email, 0, strpos($email, '@')); } if ($username != '') { $_username = $username; $i = 1; do { $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $_username)); if (!is_null($test)) { $i++; $_username = $username . ' (' . strval($i) . ')'; } } while (!is_null($test)); $username = $_username; } $dob = ''; if (array_key_exists('birthDate', $attributes)) { $dob = $attributes['birthDate']; } $dob_day = mixed(); $dob_month = mixed(); $dob_year = mixed(); if ($dob != '') { $dob_bits = explode('-', $dob); $dob_day = intval($dob_bits[2]); $dob_month = intval($dob_bits[1]); $dob_year = intval($dob_bits[0]); } $language = mixed(); if (array_key_exists('pref/language', $attributes)) { if (file_exists(get_file_base() . '/lang_custom/' . $attributes['pref/language'])) { $language = $attributes['pref/language']; } } require_code('config2'); set_option('maximum_password_length', '1000'); $member = ocf_member_external_linker($username, $openid->identity, 'openid', false, $email, $dob_day, $dob_month, $dob_year, NULL, $language); $avatar = ''; if (array_key_exists('media/image/default', $attributes)) { $avatar = $attributes['media/image/default']; } ocf_member_choose_avatar($avatar, $member); } if (!is_null($member)) { require_code('users_inactive_occasionals'); create_session($member, 1, isset($_COOKIE[get_member_cookie() . '_invisible']) && $_COOKIE[get_member_cookie() . '_invisible'] == '1'); // This will mark it as confirmed } } else { require_code('site'); require_code('site2'); attach_message('An unknown error occurred during OpenID login.', 'warn'); } } } catch (ErrorException $e) { require_code('site'); require_code('site2'); attach_message($e->getMessage(), 'warn'); } return $member; }