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 _instant_time($params) { $user = $params['user']; $channel = $params['channel']; $task = $params['task']; $pcode = $this->_project_alias($params['pcode']); $time = $params['time']; $approx = $params['approx']; $notes = $params['notes']; $return = true; if (strpos($time, ':') === 0) { $hours = floatval(substr($time, 1)) / 60; } elseif (strpos($time, ':') > 0) { list($hours, $minutes) = split(':', $time); $hours = intval($hours) + $minutes / 60; } else { $hours = floatval($time); } if (strpos($approx, ':') === 0) { $est = floatval(substr($approx, 1)) / 60; } elseif (strpos($approx, ':') > 0) { $est = (strtotime($approx) - strtotime($time)) / 3600; } elseif (trim($approx) == '') { $est = null; } else { $est = floatval($approx); } extract(Plugin::call('task_filter', array('task' => $task, 'notes' => $notes))); $timerec = array('time' => $hours, 'ondate' => date('Y-m-d'), 'pcode' => $pcode, 'task' => $task, 'notes' => $notes, 'billable' => !(preg_match('%-\\$%', $task) || preg_match('%-\\$%', $notes))); $projects = $this->_get_projects(); if (in_array($timerec['pcode'], $projects)) { $this->_add_time($timerec); $msg = "<span class=\"time\">Added {$hours} hours</span> <span class=\"project\">{$pcode}</span> <span class=\"task\">{$task}</span>"; Immediate::ok($msg, 'ok time time_instant'); } else { Immediate::error('Specified project "' . $timerec['pcode'] . '" does not exist.'); } return $return; }