public function index($module) { $output = ''; $Register = Register::getInstance(); $model = $Register['ModManager']->getModelInstance('Comments'); $where = !empty($_GET['premoder']) ? array('premoder' => 'nochecked') : array(); $where[] = "`module` = '" . $module . "'"; $total = $model->getTotal(array('cond' => $where)); list($pages, $page) = pagination($total, 20, '/admin/comments_list.php?m=' . $module . (!empty($_GET['order']) ? '&order=' . $_GET['order'] : '') . (!empty($_GET['asc']) ? '&asc=1' : '')); $model->bindModel('author'); $model->bindModel('parent_entity'); $materials = $model->getCollection($where, array('page' => $page, 'limit' => 20, 'order' => $model->getOrderParam())); if (empty($materials)) { $output = '<div class="setting-item"><div class="left"><b>' . __('Materials not found') . '</b></div><div class="clear"></div></div>'; return array($output, $pages); } foreach ($materials as $mat) { $output .= '<div class="setting-item"><div class="left">'; $output .= '<a style="font-weight:bold; margin-bottom:5px;" href="' . get_url('/admin/materials_list.php?m=' . $module . '&ac=edit&id=' . $mat->getParent_entity()->getId()) . '">' . h($mat->getParent_entity()->getTitle()) . '</a><br>'; $output .= __('Author') . ': '; if (is_object($mat->getAuthor())) { $output .= '<a style="font-weight:bold; margin-bottom:5px;" href="' . get_url('/admin/users_list.php?ac=ank&id=' . $mat->getAuthor()->getId()) . '">'; $output .= h($mat->getAuthor()->getName()); $output .= '</a>'; } else { $output .= __('Guest'); } $output .= '</div><div style="width:60%;" class="right">'; $output .= h(mb_substr($mat->getMessage(), 0, 120)); $output .= '<br /><span class="comment">' . AtmDateTime::getSimpleDate($mat->getDate()) . '</span>'; if (!empty($_GET['premoder'])) { $output .= '</div><div class="unbordered-buttons"> <a href="' . get_url('/admin/comments_list.php?m=' . $module . '&ac=premoder&status=confirmed&id=' . $mat->getId()) . '" class="on"></a> <a href="' . get_url('/admin/comments_list.php?m=' . $module . '&ac=premoder&status=rejected&id=' . $mat->getId()) . '" class="off"></a> </div><div class="clear"></div></div>'; } else { $output .= '</div><div class="unbordered-buttons"> <a href="' . get_url('/admin/comments_list.php?m=' . $module . '&ac=edit&id=' . $mat->getId()) . '" class="edit"></a> <a href="' . get_url('/admin/comments_list.php?m=' . $module . '&ac=delete&id=' . $mat->getId()) . '" class="delete"></a> </div><div class="clear"></div></div>'; } } return array($output, $pages); }
public static function get() { $functions = array(); /** * Get one or couple entities. * If get one entity of the UsersModel, we also get user statistic * * @param $modelName * @param array $id * @return array * @throws Exception */ $functions['fetch'] = function ($modelName, $id = array()) { $Register = Register::getInstance(); try { $model = $Register['ModManager']->getModelInstance($modelName); // get collection of entities if (is_array($id) && count($id)) { $id = array_map(function ($n) { $n = intval($n); if ($n < 1) { throw new Exception('Only integer value might send as ID.'); } return $n; }, $id); $ids = implode(", ", $id); $result = $model->getCollection(array("`id` IN ({$ids})")); // get one entity } else { if (is_numeric($id)) { $id = intval($id); if ($id < 1) { throw new Exception('Only integer value might send as ID.'); } $result = $model->getById($id); if ($result && strtolower($modelName) == 'users') { $stat = $model->getFullUserStatistic($id); $result->setStatistic($stat); } } } } catch (Exception $e) { throw new Exception($e->getMessage()); } return !empty($result) ? $result : array(); }; /** * Format date. * If date_format == 'atm-format', just call AtmGetSimpleDate. * * @param $date string * @param $format string * @return string */ $functions['AtmGetDate'] = function ($date, $format = false) { return AtmDateTime::getDate($date, $format); }; /** * Return date formatted as(example) - "3 seconds before" * * @param $date string * @return string */ $functions['AtmGetSimpleDate'] = function ($date) { return AtmDateTime::getSimpleDate($date); }; /** * Check access according with ACL rules. * * @param $params array * @return bool */ $functions['checkAccess'] = function ($params = array()) { if (isset($params) && is_array($params)) { $Register = Register::getInstance(); return $Register['ACL']->turn($params, false); } return false; }; $functions['get_url'] = function ($url, $notRoot = false, $useLang = true) { return get_url($url, $notRoot, $useLang); }; /** * Return URl to the user avatar * or default image if avatar image is not exists. * * @param null $id_user * @param null $email_user * @return string */ $functions['getAvatar'] = function ($id_user = null, $email_user = null) { $def = get_url('/template/' . getTemplateName() . '/img/noavatar.png', false, false); if (isset($id_user) && $id_user > 0) { if (is_file(ROOT . '/sys/avatars/' . $id_user . '.jpg')) { return get_url('/sys/avatars/' . $id_user . '.jpg', false, false); } else { $Register = Register::getInstance(); $Viewer = $Register['Viewer']; if (Config::read('use_gravatar', 'users') && $Viewer->customFunctionExists('getGravatar')) { if (!isset($email_user)) { $usersModel = $Register['ModManager']->getModelInstance('Users'); $user = $usersModel->getById($id_user); if ($user) { $email_user = $user->getEmail(); } else { return $def; } } return $Viewer->runCustomFunction('getGravatar', array($email_user)); } else { return $def; } } } else { return $def; } }; /** * Get either a Gravatar URL or complete image tag for a specified email address. * * @param string $email The email address * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] * @return String containing either just a URL or a complete image tag */ $functions['getGravatar'] = function ($email, $s = 120, $d = 'mm', $r = 'g') { $url = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . ".png?s={$s}&d={$d}&r={$r}"; return $url; }; $functions['getOrderLink'] = function ($params) { if (!$params || !is_array($params) || count($params) < 2) { return ''; } $order = !empty($_GET['order']) ? strtolower(trim($_GET['order'])) : ''; $new_order = strtolower($params[0]); $active = $order === $new_order; $asc = $active && isset($_GET['asc']); $url = $_SERVER['REQUEST_URI']; $url = preg_replace('#(order=[^&]*[&]?)|(asc=[^&]*[&]?)#i', '', $url); if (substr($url, -1) !== '&' && substr($url, -1) !== '?') { $url .= !strstr($url, '?') ? '?' : '&'; } return '<a href="' . $url . 'order=' . $new_order . ($asc ? '' : '&asc=1') . '">' . $params[1] . ($active ? ' ' . ($asc ? '↑' : '↓') : '') . '</a>'; }; /** * Checks is an user online or not. * * @param $user_id int */ $functions['CheckUserOnline'] = function ($user_id) { $users = getOnlineUsers(); return array_key_exists($user_id, $users); }; /** * Returns user rank img such as Stars or Progressbar * * @param $rating int */ $functions['getUserRatingImg'] = function ($rating) { $Register = Register::getInstance(); $settingsModel = $Register['ModManager']->getModelInstance('UsersSettings'); $rating_settings = $settingsModel->getCollection(array('type' => 'rating')); $rating_settings = count($rating_settings) > 0 ? $rating_settings[0]->getValues() : ''; $rank = getUserRating($rating, $rating_settings); return $rank['img']; }; $custom_functions = self::loadCustomTemplateFunctions(); if (is_array($custom_functions)) { $functions = array_merge($functions, $custom_functions); } return $functions; }
public function pm_view_update($pm_id = null) { $this->counter = false; $result = array('errors' => null, 'data' => array()); if (empty($pm_id)) { $this->showAjaxResponse($result); } if (empty($_SESSION['user'])) { $this->showAjaxResponse($result); } // don't use getById, because current user might not be message owner $messageModel = $this->Register['ModManager']->getModelInstance('messages'); $message = $messageModel->getCollection(array('id' => $pm_id, "(`to_user` = '" . $_SESSION['user']['id'] . "' OR `from_user` = '" . $_SESSION['user']['id'] . "')")); if (!$message[0]) { $result['errors'] = __('Message not found'); $this->showAjaxResponse($result); } $message = $message[0]; $last_date = $message->getSendtime(); $owner = $_SESSION['user']['id']; $collocutor = $owner == $message->getTo_user() ? $message->getFrom_user() : $message->getTo_user(); $newMessages = $this->Model->getDialog($owner, $collocutor, array("`sendtime` > '" . $last_date . "'")); if (is_array($newMessages) && count($newMessages)) { foreach ($newMessages as &$mes) { $message_text = $this->Textarier->parseBBCodes($mes->getMessage(), array('status' => $mes->getFromuser()->getStatus())); $mes_ = array('touser' => array('id' => $mes->getTouser()->getId(), 'name' => $mes->getTouser()->getName(), 'avatar' => $mes->getTouser()->getAvatar()), 'fromuser' => array('id' => $mes->getFromuser()->getId(), 'name' => $mes->getFromuser()->getName(), 'avatar' => $mes->getFromuser()->getAvatar())); $mes_['sender'] = $mes_['fromuser']; $mes = array_merge($mes->asArray(), $mes_); $mes['message'] = $message_text; $mes['sendtime'] = AtmDateTime::getSimpleDate($mes['sendtime']); } $result['data'] = $newMessages; $this->showAjaxResponse($result); } $this->showAjaxResponse($result); }