/** * Действие "поделиться ссылкой" через букмарклет: */ public function shareLinkAction(Application $application, Template $template) { $kvs = KVS::getInstance(); $validator = new ValidatorHelper($_GET); $validator->assertExists('title', ''); $validator->assertLength('title', 70, ''); $validator->assertExists('link', ''); $validator->assertRegexp('link', ValidatorHelper::URL_REGEXP, ''); $validator->assertLength('description', 128, ''); if ($validator->isValid()) { $key = md5(strtolower($_GET['link'])); $ip = md5($_SERVER['REMOTE_ADDR']); $counter = $kvs->get(__CLASS__, 'shared_links_ip', $ip); if (!$kvs->exists(__CLASS__, 'shared_links', $key) && !$kvs->exists(__CLASS__, 'shared_links_ban', $ip)) { if ($kvs->exists(__CLASS__, 'shared_links_ip', $ip)) { if ($counter > 5) { $kvs->set(__CLASS__, 'shared_links_ban', $ip, true); $kvs->expire(__CLASS__, 'shared_links_ban', $ip, 5 * 60); } else { $lifetime = $kvs->lifetime(__CLASS__, 'shared_links_ip', $ip); $kvs->set(__CLASS__, 'shared_links_ip', $ip, ++$counter); $kvs->expire(__CLASS__, 'shared_links_ip', $ip, $lifetime); } } else { $kvs->set(__CLASS__, 'shared_links_ip', $ip, 1); $kvs->expire(__CLASS__, 'shared_links_ip', $ip, 60); } JabberBot::send('-=% /me Отправлена ссылка: ' . $_GET['link'] . ' (' . $_GET['title'] . ')' . "\n" . (!empty($_GET['description']) ? 'С описанием: ' . $_GET['description'] : '')); $kvs->set(__CLASS__, 'shared_links', $key, true); $kvs->expire(__CLASS__, 'shared_links', $key, 60 * 60); $template->headerOk(); $template->headerContentTypeWOCharset('image/png'); readfile(WEB_DIR . '/ico/tick.png'); exit; } } $template->headerBadRequest(); exit; }
/** * Отправка сообщения в канал: */ public static function AddMessage($id, $message, $password = false) { $cache = KVS::getInstance(); $session = Session::getInstance(); $channel = self::GetChatChannel($id, $password); $message_id = $cache->incr(__CLASS__, $id, 'nextId'); $message = TexyHelper::markup($message, !$session->isAdminSession(), false); $date = time(); $cache->set(__CLASS__, $id, $message_id . ':ip', $_SERVER['REMOTE_ADDR']); $cache->expire(__CLASS__, $id, $message_id . ':ip', 60 * 5); EventModel::getInstance()->ClientBroadcast('chat_' . $channel, 'message', array('type' => 'normal', 'id' => $message_id, 'message' => $message, 'date' => date('H:i:s', $date))); /** * Отправка сообщения администратору: */ if ($id == '475266264b1e9696e0370039311f83ee4cee8d413c47c') { JabberBot::send('-=# ' . '>>' . $message_id . "\n" . strip_tags($message)); } self::LogMessage($channel, $message, $message_id, $date); return $message_id; }
public static function SetSpecialComment($id, $comment = '') { $dbh = PDOQuery::getInstance(); return $dbh->update('1chan_post', array('special_comment' => $comment), 'id = ' . $dbh->q($id)); } } /** * Обработчики событий класса: */ EventModel::getInstance()->AddEventListener('add_post', function ($data) { $session = Session::getInstance(); $session->persistenceSet('last_post_date', time()); $session->persistenceSet('last_post_text', $data['text_original']); $title = $data['category'] ? TemplateHelper::BlogCategory($data['category'], 'title') . ' — ' . $data['title'] : $data['title']; JabberBot::send('-=$ /me «' . $title . '» ( ' . 'http://' . TemplateHelper::getSiteUrl() . '/news/res/' . $data['id'] . '/ )'); Blog_BlogStatisticsModel::updateGlobalPosting(); EventModel::getInstance()->ClientBroadcast('posts', 'add_post')->ClientBroadcast('new_posts', 'add_post', array('id' => $data['id'], 'title' => $data['title'], 'category' => $data['category'] ? TemplateHelper::BlogCategory($data['category'], 'name') : 0, 'category_title' => $data['category'] ? TemplateHelper::BlogCategory($data['category'], 'title') : 0)); })->AddEventListener('rate_post', function ($data) { EventModel::getInstance()->ClientBroadcast('posts', 'rate_post', array('id' => $data[0], 'rate' => $data[1]))->ClientBroadcast('post_' . $data[0], 'rate_post', array('id' => $data[0], 'rate' => $data[1])); })->AddEventListener('info_post', function ($data) { EventModel::getInstance()->ClientBroadcast('post_' . $data[0], 'info_post', array('id' => $data[0], 'comment' => $data[1])); })->AddEventListener('rated_post', function ($data) { list($id, $rated) = $data; if ($rated) { $post = Blog_BlogPostsModel::GetPost($id); $title = $post['category'] ? TemplateHelper::BlogCategory($post['category'], 'title') . ' — ' . $post['title'] : $post['title']; JabberBot::send($title . "\n" . 'http://' . TemplateHelper::getSiteUrl() . '/news/res/' . $post['id'] . '/' . "\n" . str_repeat('—', 25) . "\n" . preg_replace('/\\t/', '', trim(strip_tags($post['text']))) . "\n" . str_repeat('—', 25)); //JabberBot::send('-=& /me «'. $title .'» ( '. 'http://'.TemplateHelper::getSiteUrl().'/news/res/'.$post['id'].'/ )'); EventModel::getInstance()->ClientBroadcast('posts', 'rated_post'); } });