/** * Сохранение нового комментария * @param $publication * @param $data * @throws Exception */ function newComment($publication, $data) { $page_obj =& Registry::get('TPage'); try { if (empty($data['comment'])) { throw new Exception('publications_comment_empty_text'); } $user_id = 0; /** * @var TAuth $auth */ $auth =& Registry::get('TAuth'); $user = $auth->getCurrentUser(); if ($page_obj->tpl->messages['publications_comment_only_users'] && !$user) { throw new Exception('publications_comment_no_user'); } if ($user) { $user_id = $user->getId(); } $data['comment'] = iconv('utf-8', 'windows-1251', $data['comment']); $data['name'] = iconv('utf-8', 'windows-1251', $data['name']); $_id = $publication->newComment($data['comment'], $user_id, $data['pid'], $data['name']); if (!is_int($_id)) { throw new Exception($_id); } $mail_data = array('site_name' => $_SERVER['HTTP_HOST'], 'href' => $data['dir'], 'text' => nl2br($data['comment'])); Notify("SEND_NEW_PUBLICATION_COMMENT", false, $mail_data); $success = true; $msg = 'publications_comment_success'; } catch (Exception $exc) { $msg = $exc->getMessage(); $success = false; } $message = isset($page_obj->tpl->messages[$msg]) ? $page_obj->tpl->get_config_vars($msg) : $page_obj->tpl->get_config_vars('msg_fail'); ob_clean(); header('Content-type: application/json; charset=utf-8'); echo json_encode(array('success' => $success, 'message' => iconv('windows-1251', 'utf-8', $message), 'visible' => $page_obj->tpl->messages['publications_comment_moderate'] ? 0 : 1)); die; }
$app->post('/:id', function ($id) use($app) { $report = new ValidationReport($id); $result = json_decode($app->request->getBody(), true); if (false != $result) { if (array_key_exists('name', $result)) { $index = $report->setName($result['name']); $app->render(200, array()); } } else { $app->render(400, array('error' => true, 'msg' => 'Not JSON')); } }); $app->delete('/:id', function ($id) use($app) { $report = new ValidationReport($id); $report->delete(); Notify(ADMIN_TOPIC, array('action' => 'delete', 'report' => $id)); $app->render(200, array()); }); $app->options('/:param+', function ($param) use($app) { $app->render(200, array()); }); }); $app->group('/drm', function () use($app) { $app->get('/', function () use($app) { $drm = new DRM(); $app->render(200, $drm->info()); })->name('drm'); $app->post('/', function () use($app) { $res = false; try { $drm = new DRM();
/** * Отправка уведомления со ссылкой для смены пароля * @param $login * @param string $tpl * @return true|string */ public function sendChangePassNotify($login, $tpl = 'SEND_HASH') { if ($user_id = $this->isUserExists($login)) { $hash = $this->createChPassHash($login); if (!$hash) { $this->getMessage('error_create_hash'); } $data = array('user_id' => $user_id, 'hash' => $hash, 'site_name' => $_SERVER["HTTP_HOST"]); $email = sql_getValue("SELECT {$this->_emailField} FROM {$this->_table} WHERE id={$user_id}"); $sent = Notify($tpl, $email, $data); if ($sent === true) { return true; } else { return implode("<br>", $sent); } } return $this->getMessage('no_user_with_login'); }