function _markov($params) { $user = $params['user']; $channel = $params['channel']; $msg = Utils::cmdout($params); $data = DB::get()->val("SELECT data FROM presence WHERE data <> '' AND cssclass='' AND data NOT LIKE '%<%' AND user_id = :user_id ORDER BY RAND() LIMIT 1", array('user_id' => $user->id)); list($word, ) = explode(' ', $data, 2); $output = $word . ' '; for ($z = 0; $z < 20; $z++) { $data = DB::get()->val("SELECT data FROM presence WHERE data LIKE :chain AND cssclass='' AND data NOT LIKE '%<%' AND user_id = :user_id ORDER BY RAND() LIMIT 1", array('user_id' => $user->id, 'chain' => '%' . $word . '%')); if ($data) { $words = explode(' ', $data); $index = array_search($word, $words); if ($index !== false) { if ($word = $words[$index + 1]) { $output .= $word . ' '; } } } else { break; } } $msg .= trim($output); Status::create()->data($msg)->user_id($user->id)->cssclass('markov')->channel($channel)->insert(); return true; }
function _eagles($params) { $user = $params['user']; $channel = $params['channel']; $rmsg = $params['eagles']; if (trim($rmsg) == '') { $rmsg = ''; } $schedule = array(array("week" => "Playoffs", "date" => "January 9", "team" => "Green Bay", "stadium" => "Lincoln Financial Field", "time" => "4:30 PM", "tv" => "FOX", "score" => "21 - 16", "result" => "loss"), array("week" => "1", "date" => "September 11", "team" => "St. Louis Rams", "stadium" => "Edward Jones Dome", "time" => "1:00 PM", "tv" => "FOX"), array("week" => "2", "date" => "September 18", "team" => "Atlanta Falcons", "stadium" => "Georgia Dome", "time" => "8:20 PM", "tv" => "NBC"), array("week" => "3", "date" => "September 25", "team" => "New York Giants", "stadium" => "Lincoln Financial Field", "time" => "1:00 PM", "tv" => "FOX"), array("week" => "4", "date" => "October 2", "team" => "San Fransisco 49ers", "stadium" => "Lincoln Financial Field", "time" => "1:00 PM", "tv" => "FOX"), array("week" => "5", "date" => "October 9", "team" => "Buffalo Bills", "stadium" => "Ralph Wilson Stadium", "time" => "1:00 PM", "tv" => "FOX"), array("week" => "6", "date" => "October 16", "team" => "Washington Redskins", "stadium" => "FedEx Field", "time" => "1:00 PM", "tv" => "FOX"), array("week" => "7", "date" => "October 23", "team" => "Bye", "stadium" => "", "time" => "", "tv" => ""), array("week" => "8", "date" => "October 30", "team" => "Dallas Cowboys", "stadium" => "Lincoln Financial Field", "time" => "8:20 PM", "tv" => "NBC"), array("week" => "9", "date" => "November 7", "team" => "Chicago Bears", "stadium" => "Lincoln Financial Field", "time" => "8:30 PM", "tv" => "ESPN"), array("week" => "10", "date" => "November 13", "team" => "Arizona Cardinals", "stadium" => "Lincoln Financial Field", "time" => "1:00 PM", "tv" => "FOX"), array("week" => "11", "date" => "November 20", "team" => "New York Giants", "stadium" => "New Meadowlands Stadium", "time" => "8:20 PM", "tv" => "NBC"), array("week" => "12", "date" => "November 27", "team" => "New England Patriots", "stadium" => "Lincoln Financial Field", "time" => "4:15 PM", "tv" => "CBS"), array("week" => "13", "date" => "December 1", "team" => "Seattle Seahawks", "stadium" => "Qwest Field", "time" => "8:20 PM", "tv" => "NFL Network"), array("week" => "14", "date" => "December 11", "team" => "Miami Dolphins", "stadium" => "Sun Life Stadium", "time" => "1:00 PM", "tv" => "FOX"), array("week" => "15", "date" => "December 18", "team" => "New York Jets", "stadium" => "Lincoln Financial Field", "time" => "4:15 PM", "tv" => "CBS"), array("week" => "16", "date" => "December 24", "team" => "Dallas Cowboys", "stadium" => "Cowboys Stadium", "time" => "4:15 PM", "tv" => "FOX"), array("week" => "17", "date" => "January 1", "team" => "Washington Redskins", "stadium" => "Lincoln Financial Field", "time" => "1:00 PM", "tv" => "FOX")); $announcement = ""; foreach ($schedule as $key => $row) { if (time() < strtotime($row['date'])) { if ($row['team'] == "Bye") { $announcement .= "<div class='next_game'>Week Off</div>"; } else { $announcement .= "<div class='next_game'><div class='label'>Next Game: </div> <div class='date'>" . $row['date'] . "</div> <div class='time'>" . $row['time'] . "</div> <div class='team'>" . $row['team'] . "</div> <div class='stadium'>" . $row['stadium'] . "</div> <div class='tv'>" . $row['tv'] . "</div></div>"; } break; } else { if ($row['team'] == "Bye") { $announcement = "<div class='last_game'>Week Off</div>"; } else { $announcement = "<div class='last_game'><div class='label'>Last Game: </div> <div class='score " . $row['result'] . "'>" . $row['score'] . "</div> <div class='date'>" . $row['date'] . "</div> <div class='time'>" . $row['time'] . "</div> <div class='team'>" . $row['team'] . "</div> <div class='stadium'>" . $row['stadium'] . "</div> <div class='tv'>" . $row['tv'] . "</div></div>"; } } } $rmsg = $announcement; $rmsg .= "<br><br>"; $rmsg .= '<button onclick="play(\'/plugins/eagles/eagles.mp3\');">Play</button>'; $js = 'bareffect(function(){play("/plugins/eagles/eagles.mp3");});'; Status::create()->data($rmsg)->user_id($user->id)->cssclass('eagles')->channel($channel)->js($js)->insert(); return true; }
public function run() { Status::create(['title' => 'Open']); Status::create(['title' => 'In Progress']); Status::create(['title' => 'On Hold']); Status::create(['title' => 'Closed']); }
function _retreat($params) { $user = $params['user']; $channel = $params['channel']; $inchannels = DB::get()->col('SELECT name FROM channels WHERE user_id = :user_id', array('user_id' => $user->id)); $join = 'office:' . $user->username; $joinalias = $this->_room_alias($join); foreach ($inchannels as $partchan) { DB::get()->query('DELETE FROM channels WHERE name = :name AND user_id = :user_id;', array('name' => $partchan, 'user_id' => $user->id)); if (preg_match('%^search:(?P<criteria>.+)$%i', $partchan, $searchmatches)) { DB::get()->query("DELETE FROM options WHERE name = :name AND grouping = 'searches' AND user_id = :user_id;", array('name' => $searchmatches['criteria'], 'user_id' => $user->id)); } else { if ($partchan != $join) { Status::create()->data("{$user->username} has retreated to <a href=\"#\" onclick=\"joinRoom('" . addslashes($join) . "');return false;\">{$joinalias}</a> from {$partchan}")->type('part')->channel($partchan)->insert(); } } } DB::get()->query('INSERT INTO channels (name, user_id, last) VALUES (:name, :user_id, NOW());', array('name' => $join, 'user_id' => $user->id)); if (!($herald = DB::get()->val("SELECT value FROM options WHERE user_id = :user_id AND name = :name AND grouping = :grouping", array('user_id' => $user->id, 'name' => 'Herald', 'grouping' => 'Identity')))) { $herald = '{$nickname} has joined {$room}'; } $js = ''; $cssclass = ''; $packed = Plugin::call('herald', array('herald' => $herald, 'js' => $js, 'cssclass' => $cssclass)); extract($packed); $herald = str_replace('{$nickname}', $user->nickname, $herald); $herald = str_replace('{$room}', $joinalias, $herald); $msg = htmlspecialchars($herald); Status::create()->data($msg)->type('join')->cssclass($cssclass)->channel($join)->js($js)->insert(); Immediate::create()->laststatus()->js('setRoom("' . addslashes($join) . '");'); return true; }
function _retcon($params) { include_once "Text/Diff.php"; include_once "Text/Diff/Renderer.php"; include_once "Text/Diff/Renderer/inline.php"; $user = $params['user']; $channel = $params['channel']; $query = $params['query']; $status = $params['status']; /* $output = Utils::cmdout($params); $output .= htmlspecialchars($query); Status::create() ->data($output) ->user_id($user->id) ->channel($channel) ->insert(); //*/ $statusok = DB::get()->assoc("SELECT status, data FROM presence WHERE user_id = :user_id AND type = 'message' AND data <> '' AND status = :status ORDER BY msgtime DESC LIMIT 10", array('user_id' => $user->id, 'status' => $status)); if ($statusok) { $data = reset($statusok); $diff =& new Text_Diff(explode("\n", $data), explode("\n", htmlspecialchars_decode($query))); $renderer =& new Text_Diff_Renderer_inline(); $replacement = $renderer->render($diff); $replacement = addslashes($replacement); $replacement = str_replace("\n", '\\n', $replacement); $js = <<<REPLJS retcon({$status}, '{$replacement}'); REPLJS; Status::create()->user_id($user->id)->js($js)->channel($channel)->insert(); } return true; }
public function run() { $faker = Faker::create(); $userIds = User::lists('id'); foreach (range(1, 1000) as $index) { Status::create(['user_id' => $faker->randomElement($userIds), 'body' => $faker->sentence(), 'created_at' => $faker->dateTimeBetween($startDate = '-9 months', $endDate = 'now')]); } }
public function run() { DB::table('statuses')->delete(); $stamp = date('Y-m-d H:i:s'); $statuses_array = array(array('statuses_name' => 'Open', 'created_at' => $stamp, 'updated_at' => $stamp), array('statuses_name' => 'In Progress', 'created_at' => $stamp, 'updated_at' => $stamp), array('statuses_name' => 'On Hold', 'created_at' => $stamp, 'updated_at' => $stamp), array('statuses_name' => 'Closed', 'created_at' => $stamp, 'updated_at' => $stamp)); foreach ($statuses_array as $added_row) { Status::create($added_row); } }
function _jar($params) { $jar = $params['jar']; $criteria = $params['criteria']; $user = $params['user']; $channel = $params['channel']; $msg = Utils::cmdout($params); $msg .= "send this to the jar : " . $criteria; Status::create()->data($msg)->user_id($user->id)->cssclass('brainjar')->channel($channel)->insert(); return true; }
function _calc($params) { $user = $params['user']; $channel = $params['channel']; $query = $params['query']; $query = html_entity_decode($query); $calc = new Calc($query); echo htmlspecialchars($expression) . "\n"; echo $calc->infix() . " = " . $calc->calc() . "\n"; $output = Utils::cmdout($params); $output .= $calc->infix() . " = " . $calc->calc(); Status::create()->data($output)->user_id($user->id)->channel($channel)->insert(); return true; }
function _lions($params) { $user = $params['user']; $channel = $params['channel']; $rmsg = $params['lions']; if (trim($rmsg) == '') { $rmsg = ''; } $rmsg = htmlspecialchars($rmsg); $rmsg = '<button onclick="play(\'/plugins/lions/lions.mp3\');">Play</button>' . $rmsg; $js = 'bareffect(function(){play("/plugins/lions/lions.mp3");});'; Status::create()->data($rmsg)->cssclass('lions')->channel($channel)->js($js)->insert(); return true; }
function _sound($params) { $file = $params['file']; $style = $params['style']; $channel = $params['channel']; $user = Auth::user(); $cssclass = array('sound'); if ($style != '') { $cssclass[] = $style; } if ($filerow = DB::get()->row('SELECT * FROM files WHERE filename = :file', array('file' => $file))) { Status::create()->data(Utils::cmdout($params))->user_id($user->id)->channel($channel)->cssclass(implode(' ', $cssclass))->js('bareffect(function(){play(' . json_encode($filerow->url) . ');});')->insert(); } else { Status::create()->data('Sorry, that file was not found in the file listing.')->user_id($user->id)->type('system')->cssclass('error')->user_to($user->id)->insert(); } return true; }
function _svn_create($params) { $reponame = $params['reponame']; $channel = $params['channel']; $user = Auth::user(); if (preg_match('%^\\w+$%', $reponame)) { $repodir = '/var/svn/repos/' . $reponame; $output = ''; $output .= "\n" . shell_exec('svnadmin create ' . $repodir); $output .= "\n" . shell_exec('chmod -R g+w ' . $repodir); $output .= "\n" . shell_exec('ln -s /var/svn/repos/barchat/hooks/post-commit ' . $repodir . '/hooks/post-commit'); $output .= "\n" . shell_exec('svn mkdir --username rrs --password 1dc6e78c12a7ec76a349bc63730b85aa -m "Initial directory creation" https://sol.rockriverstar.com/svn/' . $reponame . '/trunk https://sol.rockriverstar.com/svn/' . $reponame . '/tags https://sol.rockriverstar.com/svn/' . $reponame . '/branches 2>&1'); Status::create()->data(Utils::cmdout($params) . 'Created repo "' . $reponame . '" at https://sol.rockriverstar.com/svn/' . $reponame . '<br/><pre>' . str_replace("\n", '<br>', trim($output)) . '</pre>')->user_id($user->id)->channel($channel)->cssclass('svn')->insert(); } else { Status::create()->data('Sorry, repo names must not already exist and must not contain spaces.')->user_id($user->id)->type('system')->cssclass('error')->user_to($user->id)->insert(); } return true; }
function _spell($params) { $user = $params['user']; $channel = $params['channel']; $presence = DB::get()->row('SELECT status, data FROM presence WHERE user_id = :user_id AND data <> "" ORDER BY msgtime DESC LIMIT 1', array('user_id' => $user->id)); $data = $presence->data; $words = preg_split('%\\W+%', $data); $words = array_unique($words); $words = array_combine($words, $words); $pspell_link = pspell_new("en"); foreach ($words as $word) { if (!pspell_check($pspell_link, $word)) { $suggestions = pspell_suggest($pspell_link, $word); if (count($suggestions) > 0) { $presence->data = str_replace($word, reset($suggestions), $presence->data); } else { $presence->data = str_replace($word, '<s>' . $word . '</s>', $presence->data); } } } if ($presence->data == $data) { Immediate::ok('No spelling corrections.', $user); } else { include_once "Text/Diff.php"; include_once "Text/Diff/Renderer.php"; include_once "Text/Diff/Renderer/inline.php"; $diff =& new Text_Diff(explode("\n", $data), explode("\n", htmlspecialchars_decode($presence->data))); $renderer =& new Text_Diff_Renderer_inline(); $replacement = $renderer->render($diff); $replacement = addslashes($replacement); $replacement = str_replace("\n", '\\n', $replacement); $js = <<<REPLJS retcon({$presence->status}, '{$replacement}'); REPLJS; Status::create()->user_id($user->id)->js($js)->channel($channel)->cssclass('spell')->insert(); } return true; }
function _api($params) { $user = $params['user']; $name = $params['name']; $channel = $params['channel']; $output = Utils::cmdout($params); $searchurl = 'http://api.drupal.org/api/search/6/' . urlencode($name); $thtml = file_get_contents($searchurl); $content = SimpleHTML::str_get_html($thtml); $tbody = $content->find('table[class=sticky-enabled]', 0); if (!is_object($tbody)) { $code = $content->find('.active code', 0); $output .= '<code style="font-size: 1.5em;line-height: 2em"><a target="_blank" href="' . $searchurl . '">Reference</a>:' . $code->innertext . '</code>'; } else { $trs = $tbody->find('tr'); $modules = ''; $count = 0; array_shift($trs); foreach ($trs as $tr) { $tds = $tr->find('td'); $a = $tds[0]->find('a', 0); $modules .= '<li><a target="_blank" href="http://drupal.org/' . $a->href . '">' . $a->innertext . '</a>'; // $modules .= htmlspecialchars($tds[2]->innertext); $modules .= '</li>'; if (++$count > 9) { break; } } if ($modules != '') { $output .= '<ul style="margin-left:30px;">' . $modules . '</ul>'; } else { $output .= '<p>No results.</p>'; } } Status::create()->data($output)->user_id($user->id)->cssclass('drupal api')->channel($channel)->insert(); return true; }
function _contact($params) { $criteria = $params['criteria']; $user = $params['user']; $channel = $params['channel']; $api = $this->get_api(); if (is_numeric($criteria)) { $bycriteria = array('id' => $criteria); } else { $bycriteria = array('display_name' => $criteria); } $results = $api->requestArray('Contact/Get', $bycriteria); if (isset($results['Result'])) { $result = $results['Result']; if (isset($result['is_error'])) { if ($result['is_error']) { // Error message in $result['error_message'] $msg = $result['error_message']; } else { // No error, just no results. $msg = 'No contacts match that criteria.'; } Status::create()->data($msg)->type('system')->user_to($user->id)->cssclass('error')->channel($channel)->insert(); } elseif (isset($result['contact_id'])) { // Single result was sent back. $callnum = $this->get_call_num($result['phone']); $msg = Utils::cmdout($params); $msg .= '<span class="crm-name"> <a href="http://crm.rockriverstar.com/civicrm/contact/view?reset=1&cid=' . $result['contact_id'] . '" target="_blank">' . $result['display_name'] . '</a>' . '</span>'; $msg .= '<table class="crm-data">'; $msg .= '<tr><td>Primary Phone: ' . $this->get_call_num($result['phone']) . '</td>'; $msg .= '<td>Primary Email: ' . $result['email'] . '</td></tr>'; $msg .= '<tr>' . '<td>Title: ' . $result['job_title'] . '</td>' . '<td>Employer: ' . $result['current_employer'] . '</td>' . '</tr>'; $msg .= '</table>'; Status::create()->data($msg)->user_id($user->id)->cssclass('crm-contact')->channel($channel)->insert(); } else { // Multiple results. $msg = Utils::cmdout($params); $msg .= '<table><thead><tr><th>Name</th><th>Phone</th><th>Email</th></tr></thead>'; foreach ($result as $contact) { if (!$contact['is_deleted']) { $callnum = $this->get_call_num($contact['phone']); $msg .= '<tr>'; $msg .= '<td><a href="http://crm.rockriverstar.com/civicrm/contact/view?reset=1&cid=' . $contact['contact_id'] . '" target="_blank">' . $contact['display_name'] . '</a></td>'; $msg .= '<td>' . $this->get_call_num($contact['phone']) . '</td>'; $msg .= '<td><a href="mailto:' . $contact['email'] . '">' . $contact['email'] . '</a></td>'; $msg .= '</tr>'; } } $msg .= '</table>'; Status::create()->data($msg)->user_id($user->id)->cssclass('crm-contact')->channel($channel)->insert(); } } else { // Something has gone horribly wrong. Status::create()->data('Something has gone horribly wrong.')->type('system')->user_to($user->id)->cssclass('error')->channel($channel)->insert(); } return true; }
function _stats($params) { $nickname = $params['nickname']; $user = $params['user']; $channel = $params['channel']; $statsql = "\r\n\t\t\tselect\r\n\t\t\t\tnp.title as project,\r\n\t\t\t\tccs.csid as csid,\r\n\t\t\t\tccs.case_state_name as status,\r\n\t\t\t\tcount(*) as case_count,\r\n\t\t\t\tp.value as purl\r\n\t\t\tfrom\r\n\t\t\t\tpurl p,\r\n\t\t\t\tog_ancestry oa,\r\n\t\t\t\tnode n,\r\n\t\t\t\tnode_revisions r,\r\n\t\t\t\tusers u,\r\n\t\t\t\tcasetracker_case cc,\r\n\t\t\t\tcasetracker_case cc2,\r\n\t\t\t\tcasetracker_case cc3,\r\n\t\t\t\tcasetracker_case_states ccs,\r\n\t\t\t\tcasetracker_case_states ccs2,\r\n\t\t\t\tcasetracker_case_states ccs3,\r\n\t\t\t\tnode np\r\n\t\t\twhere\r\n\t\t\t\tp.id = oa.group_nid\r\n\t\t\t\tand oa.nid = n.nid\r\n\t\t\t\tand n.vid = r.vid\r\n\t\t\t\tand n.type = 'casetracker_basic_case'\r\n\t\t\t\tand u.uid = n.uid\r\n\t\t\t\tand cc.vid = n.vid\r\n\t\t\t\tand cc.case_status_id = ccs.csid\r\n\t\t\t\tand cc2.vid = n.vid\r\n\t\t\t\tand cc2.case_priority_id = ccs2.csid\r\n\t\t\t\tand cc3.vid = n.vid\r\n\t\t\t\tand cc3.case_type_id = ccs3.csid\r\n\t\t\t\tand ccs.case_state_name <> 'Closed'\r\n\t\t\t\tand ccs.case_state_name <> 'Duplicate'\r\n\t\t\t\tand p.id = np.nid\r\n\t\t"; $uid = false; if ($nickname == '*') { $statsql .= ' group by project, status order by project, status;'; $uid = -1; $sqlparams = array(); } elseif ($nickname != '') { $msg = 'The user "' . htmlspecialchars($params['nickname']) . '" does not exist.'; $target = PresenceController::_userstr($nickname); if ($target) { $msg = 'The user "' . htmlspecialchars($params['nickname']) . '" does not have a PD account associated in the options table.'; $sql = "SELECT value FROM options WHERE grouping = 'identity' AND name = 'pduid' AND user_id = :user_id;"; $uid = DB::get()->val($sql, array('user_id' => $target->id)); } $statsql .= ' and cc.assign_to = :uid group by project, status order by project, status;'; $sqlparams = array('uid' => $uid); } else { $msg = 'You do not have a PD account associated in the options table.'; $uid = Option::get('identity', 'pduid'); $statsql .= ' and cc.assign_to = :uid group by project, status order by project, status;'; $sqlparams = array('uid' => $uid); } if (!$uid || $uid == 0) { Status::create()->data(Utils::cmdout($params) . $msg)->type('system')->cssclass('error')->channel($channel)->insert(); return true; } if (!$this->pdb()) { Status::create()->data('Could not connect to the projects database.')->type('system')->user_to($user->id)->cssclass('error')->channel($channel)->insert(); return true; } $stats = $this->pdb()->results($statsql, $sqlparams); if (count($stats) == 0) { $msg = Utils::cmdout($params); Status::create()->data($msg . 'No open cases found.')->type('system')->cssclass('stats')->channel($channel)->insert(); } else { $msg = Utils::cmdout($params); foreach ($stats as $stat) { $statuses[$stat->csid] = $stat->status; $projects[$stat->purl] = $stat->project; $count[$stat->project][$stat->status] = $stat->case_count; } $msg .= '<table><thead><tr><th>Project Name</th>'; foreach ($statuses as $status) { $msg .= '<th>' . $status . '</th>'; } $msg .= '</tr></thead>'; foreach ($projects as $purl => $project) { $msg .= '<tr><th><a href="http://projects.rockriverstar.com/' . $purl . '/casetracker" target="_blank" onclick="send(\':' . $purl . '\');return false;">' . $project . '</a></th>'; foreach ($statuses as $csid => $status) { if (isset($count[$project][$status])) { $msg .= '<td><a href="http://projects.rockriverstar.com/' . $purl . '/casetracker/filter?keys='; if ($uid > 0) { $msg .= '&assign_to[]=' . $uid; } $msg .= '&pid=All&case_priority_id=All&case_status_id=' . $csid . '" target="_blank">' . $count[$project][$status] . '</a></td>'; } else { $msg .= '<td class="no_cases">—</td>'; } } $msg .= '</tr>'; } $msg .= '</table>'; Status::create()->data($msg)->user_id($user->id)->cssclass('stats')->channel($channel)->insert(); } return true; }
function bot_process_message() { $payload = $_POST['p']; try { $xml = new SimpleXMLElement($payload); if ($xml['silent'] == 'true') { return true; } foreach ($xml->result as $result) { $status = Status::create(); foreach ($result->attributes() as $k => $v) { switch ($k) { case 'append': break; case 'user': $remote_user = DB::get()->val("SELECT id FROM users WHERE username = ?", array($v)); if (!$remote_user) { $remote_user = min(-1, DB::get()->val("SELECT min(id) FROM users") - 1); DB::get()->query("INSERT INTO users (id, username) VALUES (?, ?)", array($remote_user, $v)); DB::get()->query("UPDATE users SET id = ? WHERE username = ?", array($remote_user, $v)); } $status->user_id = $remote_user; break; default: $status->{$k} = $v; break; } } $status->data((string) $result); $status->insert(); } } catch (Exception $e) { } }
function _morning($params) { $user = $params['user']; $channel = $params['channel']; $meanderfile = file_get_contents(dirname(__FILE__) . '/meander.txt'); $meanderlines = explode("\n", $meanderfile); $index = '%starts'; $meander = array(); foreach ($meanderlines as $line) { $line = trim($line); if (preg_match('#^%(%.+)$#', $line, $matches)) { $index = $matches[1]; } else { if ($line[0] == '#') { $meander[$index][] = str_rot13(substr($line, 1)); } else { $meander[$index][] = $line; } } } if (isset($params['target']) && isset($meander['%' . $params['target']])) { $starts = $meander['%' . $params['target']]; } else { if (isset($meander['%' . $user->username])) { $starts = $meander['%' . $user->username]; } else { $starts = $meander['%starts']; } } shuffle($starts); $morning = reset($starts); while (preg_match('#%\\w+#', $morning, $match)) { $replacements =& $meander[$match[0]]; shuffle($replacements); $morning = preg_replace('#%\\w+#', reset($replacements), $morning, 1); } Status::create()->data($morning)->user_id($user->id)->channel($channel)->cssclass('morning')->insert(); return true; }
function _response($channel) { $user = Auth::user(); $issearch = false; if (preg_match('%search:(?P<criteria>.+)%i', $channel, $searchmatches)) { $issearch = true; } preg_match('%(?P<roomtype>\\w+):(?P<criteria>.+)%i', $channel, $searchmatches); $searchmatches['roomtype'] = isset($searchmatches['roomtype']) ? $searchmatches['roomtype'] : ''; $searchmatches['criteria'] = isset($searchmatches['criteria']) ? $searchmatches['criteria'] : ''; if (DB::get()->val("SELECT count(*) FROM channels WHERE user_id = :user_id", array('user_id' => Auth::user_id())) == 0) { $join = 'bar'; //$user->username; $allowedchannels = DB::get()->col("SELECT room FROM options WHERE grouping = 'Permissions' AND name = 'allowedchannel' AND user_id = :user_id", array('user_id' => $user->id)); if ($allowedchannels) { $join = reset($allowedchannels); } DB::get()->query("INSERT INTO channels (name, user_id, active) VALUES (:join, :user_id, 1);", array('join' => $join, 'user_id' => Auth::user_id())); if (!($herald = DB::get()->val("SELECT value FROM options WHERE user_id = :user_id AND name = :name AND grouping = :grouping", array('user_id' => Auth::user_id(), 'name' => 'Herald', 'grouping' => 'Identity')))) { $herald = '{$nickname} has joined {$room}'; } $js = ''; $cssclass = ''; $packed = Plugin::call('herald', array('herald' => $herald, 'js' => $js, 'cssclass' => $cssclass)); extract($packed); $herald = str_replace('{$nickname}', $user->nickname, $herald); $herald = str_replace('{$room}', $this->_room_alias($join), $herald); $msg = htmlspecialchars($herald); Status::create()->data($msg)->type('join')->channel($join)->cssclass($cssclass)->js($js)->insert(); } DB::get()->query('UPDATE channels SET active = 0 WHERE user_id = :user_id', array('user_id' => Auth::user_id())); DB::get()->query('UPDATE channels SET active = 1, last = NOW() WHERE name = :channel AND user_id = :user_id', array('channel' => $channel, 'user_id' => Auth::user_id())); $laststatus = Immediate::get_status(); $obj = new StdClass(); $obj->comet_change = false; $obj->status = $laststatus; $obj->reported_status = 0; $obj->chanbar = $this->chanbar(); $obj->channels = DB::get()->col("SELECT name FROM channels WHERE user_id = :user_id ORDER BY name ASC", array('user_id' => Auth::user_id())); $obj->channel = DB::get()->val("SELECT name FROM channels WHERE user_id = :user_id and active = 1", array('user_id' => Auth::user_id())); $obj->jsdate = filemtime(dirname(__FILE__) . '/../../js/sp.js'); switch (strtolower($searchmatches['roomtype'])) { case 'search': $crit = DB::get()->val("SELECT value FROM options WHERE user_id = :user_id AND grouping = 'searches' AND name = :name", array('user_id' => $user->id, 'name' => $searchmatches['criteria'])); $obj->crit = $crit; $sql = ''; $params = array('user_id' => Auth::user_id(), 'crit' => $crit, 'searchchannel' => $obj->channel); $criteria = $this->_get_search_sql($sql, $params, $crit); $obj->updates = DB::get()->results($sql, $params, 'StdClass'); $insert = new stdClass(); $insert->status = 0; $insert->type = 'system'; $insert->channel = ''; $insert->data = 'Search Criteria: ' . $criteria; $insert->msgtime = 0; $insert->user_id = 0; $insert->cssclass = 'searchheader'; $insert->js = ''; $insert->user_to = ''; $insert->received = ''; $obj->updates[] = $insert; break; case 'office': $officeuser = $this->_userstr($searchmatches['criteria']); $qp = array('channel' => $obj->channel, 'user_id' => Auth::user_id()); if ($officeuser->id == $user->id) { $append = "((type = 'direct' AND user_to = :user_id AND presence.user_id <> :user_id) OR (user_to = :user_id) OR (user_to = 0)) AND (type <> 'notice')"; } else { $append = "((type = 'direct' AND user_to = :user_id and presence.user_id = :office_user) OR (user_to = 0)) AND (type <> 'notice')"; $qp['office_user'] = $officeuser->id; } $obj->updates = DB::get()->results("\nSELECT\n\tpresence.*,\n\tusers.username,\n\toptions.value as nickname,\n\tchannels.active as active\nFROM\n\tpresence\nLEFT JOIN\n\tusers\n\tON presence.user_id = users.id\nLEFT JOIN\n\toptions\n\tON options.user_id = users.id AND options.name = 'Nickname' AND options.grouping = 'Identity'\nLEFT JOIN\n\tchannels\n\tON channels.user_id = :user_id \n\tAND channels.name = presence.channel\nWHERE\n\t(channel = :channel OR channel = '')\n\tAND\n\t(\n\t\t{$append}\n\t)\nORDER BY\n\tstatus DESC\nLIMIT 100\n\t\t\t", $qp, 'StdClass'); break; default: $updates = Plugin::call('response', false, $searchmatches['roomtype'], $searchmatches['criteria']); if ($updates) { $obj->updates = $updates; } else { $obj->updates = DB::get()->results("\nSELECT\n\tpresence.*,\n\tusers.username,\n\toptions.value as nickname\nFROM\n\tpresence\nLEFT JOIN\n\tusers\n\tON presence.user_id = users.id\nLEFT JOIN\n\toptions\n\tON options.user_id = users.id AND options.name = 'Nickname' AND options.grouping = 'Identity'\nWHERE\n\t(channel = :channel OR channel = '')\n\tAND\n\t(\n\t\t(user_to = 0)\n\t\tOR\n\t\t(user_to = :user_id and isnull(received))\n\t)\nORDER BY\n\tstatus DESC\nLIMIT 100\n\t\t\t\t\t", array('channel' => $obj->channel, 'user_id' => Auth::user_id()), 'StdClass'); } break; } DB::get()->query('UPDATE presence SET received = msgtime, msgtime = NOW() WHERE isnull(received) AND user_to = :user_id', array('user_id' => Auth::user_id())); foreach ($obj->updates as $k => $v) { $obj->updates[$k]->msgtime = date('Y-m-d H:i:s', strtotime($obj->updates[$k]->msgtime) + intval((string) Option::get('Time', 'Zone Offset')) * 3600); } $obj->updates = array_reverse($obj->updates); $obj->names = DB::get()->results('select channels.name, users.id, username, pingtime, last, active, value as nickname from channels, sessions, users, options where channels.user_id = users.id AND users.id = sessions.user_id and pingtime > now() - 120000 and channels.name = :channel and options.user_id = users.id and options.grouping = "Identity" and options.name="Nickname";', array('channel' => $obj->channel), 'StdClass'); $obj->namebar = $this->namebar(); $obj->namebarmd5 = md5($obj->namebar); $obj->sups = DB::get()->val('SELECT count(*) as ct FROM presence, channels WHERE presence.channel = channels.name AND presence.msgtime > channels.last AND channels.active = 0 AND channels.user_id = :user_id AND presence.user_id <> :user_id AND presence.type <> "status"', array('user_id' => Auth::user_id())); $obj->drawers = DB::get()->results('SELECT * FROM drawers WHERE (channel = :channel OR isnull(channel) OR channel = "") AND user_id = :user_id ORDER BY added DESC;', array('channel' => $obj->channel, 'user_id' => Auth::user_id()), 'StdClass'); $obj->decor = DB::get()->assoc("SELECT name, value FROM options WHERE room = :channel AND grouping = 'decor';", array('channel' => $obj->channel)); $obj = Plugin::call('response_obj', $obj, $searchmatches['roomtype'], $searchmatches['criteria']); Immediate::set_status(); return json_encode($obj); }
public function run() { DB::table('statuses')->delete(); Status::create(array('status' => 'Published', 'slug' => 'published')); Status::create(array('status' => 'Draft', 'slug' => 'draft')); }
/** * Retrieve status label * * @param string $code * @return string */ public function getStatusLabel($code) { $code = $this->maskStatusForArea($this->state->getAreaCode(), $code); $status = $this->orderStatusFactory->create()->load($code); return $status->getStoreLabel(); }
function _cant_connect() { Status::create()->data(Utils::cmdout($params) . 'Couldn\'t connect to http_auth database.')->user_id($user->id)->channel($channel)->cssclass('httpauth')->insert(); return true; }
function _dig($params) { $user = $params['user']; $channel = $params['channel']; $domain = $params['domain']; $record = $params['record']; if (strpos($domain, '.') === false) { $domain .= '.rockriverstar.com'; } $output = Utils::cmdout($params); $records = array('a' => DNS_A, 'cname' => DNS_CNAME, 'hinfo' => DNS_HINFO, 'mx' => DNS_MX, 'ns' => DNS_NS, 'ptr' => DNS_PTR, 'soa' => DNS_SOA, 'txt' => DNS_TXT, 'aaaa' => DNS_AAAA, 'srv' => DNS_SRV, 'naptr' => DNS_NAPTR, 'a6' => DNS_A6, 'all' => DNS_ALL, 'and' => DNS_ANY); $record = $records[strtolower($record)]; $result = dns_get_record($domain, $record); if (count($result) > 0) { $cols = array_keys(reset($result)); $output .= '<table class="net"><tr>'; foreach ($cols as $col) { $output .= '<th>' . $col . '</th>'; } $output .= '</tr>'; foreach ($result as $res) { $output .= '<tr>'; foreach ($cols as $col) { $output .= '<td>' . $res[$col] . '</td>'; } $output .= '</tr>'; } $output .= '</table>'; } else { $output .= 'No results found.'; } //$output .= '<pre>' . print_r(,1) . '</pre>'; Status::create()->data($output)->user_id($user->id)->channel($channel)->type('message')->cssclass('net ip')->insert(); return true; }
/** * Tests Status::getDataPath */ public function testUncompressedDataPath() { $status = Status::create()->uncompressed()->dataPath('/foo'); $this->assertFalse($status->handledCompression()); $this->assertEquals('/foo', $status->getDataPath()); }
function _closequestion($params) { $user = $params['user']; $channel = $params['channel']; $qid = $params['qid']; $answer = $params['answer']; $users = DB::get()->col('SELECT user_id FROM drawers WHERE indexed = :qid', array('qid' => 'q' . $qid)); DB::get()->query('DELETE FROM drawers WHERE indexed = :qid', array('qid' => 'q' . $qid)); $q = DB::get()->row('SELECT * FROM drawers d inner join users u on d.user_id = u.id WHERE d.id = :qid', array('qid' => $qid)); DB::get()->query('DELETE FROM drawers WHERE id = :qid', array('qid' => $qid)); if (strpos($q->message, 'class="singleanswer"') === false) { $users[] = $user->id; foreach ($users as $user_id) { Status::create()->data(htmlspecialchars($q->username) . ' has withdrawn the question.')->cssclass('answers')->user_id($user->id)->user_to($user_id)->channel($channel)->js('bareffect(function(){refreshDrawers()});')->insert(); } } else { $message = $q->message; $message = preg_replace('%<button.+?</button>%i', '', $message); Status::create()->data($message)->cssclass('answers')->user_id($user->id)->channel($channel)->js('bareffect(function(){refreshDrawers()});')->insert(); } return true; }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { return view('shisan::tech_statuses.create', $this->status->create()); }
/** * Retrieve status label * * @param string $code * @return string */ public function getStatusLabel($code) { $status = $this->orderStatusFactory->create()->load($code); return $status->getStoreLabel(); }
function _ccall($params) { $user = $params['user']; $channel = $params['channel']; $target = $params['name']; $user_to = $params['presence']->_userstr($target); if (!$user_to) { Status::create()->data('That is not a valid username.')->type('system')->user_to($user->id)->cssclass('error')->insert(); } else { $drawer = DB::get()->val("SELECT id FROM drawers WHERE user_id = :user_id and indexed = :indexed;", array('user_id' => $user_to->id, 'indexed' => 'queue_call_' . $user->id)); if ($drawer) { Status::create()->data('Canceled queued call to ' . $user_to->username)->type('system')->user_to($user->id)->cssclass('ok')->insert(); Status::create()->data($user->username . ' has canceled their queued call request.')->type('system')->user_to($user_to->id)->cssclass('ok')->insert(); } else { Status::create()->data('You have no call queued to ' . $user_to->username)->type('system')->user_to($user->id)->cssclass('error')->insert(); } DB::get()->query("DELETE FROM drawers WHERE user_id = :user_id and indexed = :indexed;", array('user_id' => $user_to->id, 'indexed' => 'queue_call_' . $user->id)); } return true; }
function _karma($params) { $user = $params['user']; $channel = $params['channel']; $matches = $params['matches']; $word = trim(strtolower($matches['word']), '"'); $md5w = md5($word); $points = DB::get()->row('select sum(karma) as s, sum(abs(karma)) as b, sum(karma / abs(karma)) as v, std(karma) as d, var_pop(karma) as v from karma where word = ?', array($word)); $lastvote = DB::get()->row('SELECT time_to_sec(timediff(now(),lastvote)) as t, karma FROM karma WHERE word = ? and user_id = ?', array($word, $user->id)); if ($lastvote && $lastvote->t < 30) { Immediate::create()->laststatus()->js("\$('#mainscroller .karma_{$md5w} .inner.active .voters').html('You are voting too fast! Wait " . (30 - $lastvote->t) . " seconds.').effect('highlight', {}, 1500);"); return true; } if ($lastvote && abs($lastvote->karma) > $points->b - abs($lastvote->karma) && $points->v > 2) { Immediate::create()->laststatus()->js("\$('#mainscroller .karma_{$md5w} .inner.active .voters').html('You have voted more than everyone else <em>combined</em>. You win!').effect('highlight', {}, 1500);"); return true; } $kpoints = $points->s; if (DB::get()->val('SELECT count(word) FROM karma WHERE word = ? and user_id = ?', array($word, $user->id)) == 0) { switch ($matches['karma']) { case '++': $kpoints++; $bmsg = 'Added one karma point to "' . htmlspecialchars($matches['word']) . '", totaling ' . $kpoints . ' points.'; DB::get()->query('INSERT INTO karma (word, karma, user_id, direction) VALUES (?, ?, ?, 1)', array($word, 1, $user->id)); break; case '--': $kpoints--; $bmsg = 'Subtracted one karma point from "' . htmlspecialchars($matches['word']) . '", totaling ' . $kpoints . ' points.'; DB::get()->query('INSERT INTO karma (word, karma, user_id, direction) VALUES (?, ?, ?, -1)', array($word, -1, $user->id)); break; case '~~': $kpoints--; $bmsg = 'You didn\'t vote on "' . htmlspecialchars($matches['word']) . '" to begin with. The total is still ' . $kpoints . ' points.'; DB::get()->query('INSERT INTO karma (word, karma, user_id, direction) VALUES (?, ?, ?, 0)', array($word, -1, $user->id)); break; case '??': $bmsg = '"' . htmlspecialchars($matches['word']) . '" has ' . $kpoints . ' karma points -- you have not voted.'; if ($points->b == 0) { return false; } break; } } else { $oldkarma = DB::get()->val('SELECT karma FROM karma WHERE word = ? and user_id = ?', array($word, $user->id)); switch ($matches['karma']) { case '++': $kpoints++; $bmsg = 'Added one karma point to "' . htmlspecialchars($matches['word']) . '", totaling ' . $kpoints . ' points.'; DB::get()->query('UPDATE karma SET karma = karma + 1, lastvote = now(), direction = 1 WHERE word = ? and user_id = ?', array($word, $user->id)); break; case '--': $kpoints--; $bmsg = 'Subtracted one karma point from "' . htmlspecialchars($matches['word']) . '", totaling ' . $kpoints . ' points.'; DB::get()->query('UPDATE karma SET karma = karma - 1, lastvote = now(), direction = -1 WHERE word = ? and user_id = ?', array($word, $user->id)); break; case '~~': $kpoints -= $oldkarma; $bmsg = 'Removing your vote on "' . htmlspecialchars($matches['word']) . '", now totaling ' . $kpoints . ' points.'; DB::get()->query('DELETE FROM karma WHERE word = ? and user_id = ?', array($word, $user->id)); break; case '??': $bmsg = '"' . htmlspecialchars($matches['word']) . '" has ' . $kpoints . ' karma points -- you have already voted (' . $oldkarma . ').'; break; } } $points = DB::get()->row('select sum(karma) as s, sum(karma / abs(karma)) as v, std(karma) as d, var_pop(karma) as v from karma where word = ?', array($word)); $hword = htmlspecialchars($word); $bmsg = '<div class="word">' . $hword . '</div><button class="voteup" onclick="send(\'' . addslashes($hword) . '++\');">++</button><button class="votedown" onclick="send(\'' . addslashes($hword) . '--\');">--</button>'; $bmsg = '<div class="inner">loading</div>'; Status::create()->data($bmsg)->channel($channel)->type('notice')->cssclass('karma karma_' . md5($word))->js('apply_karma("' . $md5w . '", "' . $hword . '");')->insert(); return true; }