public function browse() { // Get user and last notice ID $lastID = (int) input::post_get('last_id', 0); // Get notices $notices = $this->timeline_notices_model->getNotices(session::item('user_id'), $lastID, config::item('notices_per_page', 'timeline')); // Set title view::setTitle(__('my_timeline_notifications', 'system_navigation')); // Dow we have new notifications? if (session::item('total_notices_new')) { // Reset new notifications counter $this->timeline_notices_model->resetCounter(); } // Load view if (input::isAjaxRequest()) { $output = view::load('timeline/notices/items', array('notices' => $notices), true); view::ajaxResponse($output); } else { view::load('timeline/notices/index', array('notices' => $notices)); } }
protected function parseQuerystring($max = 0) { $qstring = array(); // Set max page $maxpage = $max ? ceil($max / config::item('visitors_per_page', 'users')) : 0; // Get current page $qstring['page'] = (int) input::get('page', 1); $qstring['page'] = $qstring['page'] > 0 ? !$maxpage || $qstring['page'] <= $maxpage ? $qstring['page'] : $maxpage : 1; // Get search id $qstring['search_id'] = input::get('search_id'); // Get order field and direction $qstring['orderby'] = input::post_get('o') && in_array(input::post_get('o'), array('post_date')) ? input::post_get('o') : 'post_date'; $qstring['orderdir'] = input::post_get('d') && in_array(input::post_get('d'), array('asc', 'desc')) ? input::post_get('d') : 'desc'; $qstring['order'] = $qstring['orderby'] ? array($qstring['orderby'] => $qstring['orderdir']) : array(); // Create url string $qstring['url'] = ($qstring['search_id'] ? 'search_id=' . $qstring['search_id'] . '&' : '') . ($qstring['orderby'] ? 'o=' . $qstring['orderby'] . '&' : '') . ($qstring['orderby'] && $qstring['orderdir'] ? 'd=' . $qstring['orderdir'] . '&' : ''); // Set limit $from = ($qstring['page'] - 1) * config::item('visitors_per_page', 'users'); $qstring['limit'] = (!$max || $from <= $max ? $from : $max) . ', ' . (!$max || config::item('visitors_per_page', 'users') < $max ? config::item('visitors_per_page', 'users') : $max); // Assign vars view::assign(array('qstring' => $qstring)); return $qstring; }
protected function parseQuerystring($max = 0) { $qstring = array(); // Set max page $maxpage = $max ? ceil($max / $this->usersPerPage) : 0; // Get current page $qstring['page'] = (int) input::get('page', 1); $qstring['page'] = $qstring['page'] > 0 ? !$maxpage || $qstring['page'] <= $maxpage ? $qstring['page'] : $maxpage : 1; // Get search id $qstring['search_id'] = input::get('search_id'); // Get order field and direction $qstring['orderby'] = input::post_get('o') && in_array(input::post_get('o'), array('name1', 'join_date', 'total_views', 'total_rating', 'total_likes', 'total_comments')) ? input::post_get('o') : 'join_date'; $qstring['orderdir'] = input::post_get('d') && in_array(input::post_get('d'), array('asc', 'desc')) ? input::post_get('d') : 'desc'; $qstring['order'] = $qstring['orderby'] ? array($qstring['orderby'] => $qstring['orderdir']) : array(); // Create url string $qstring['url'] = ($qstring['search_id'] ? 'search_id=' . $qstring['search_id'] . '&' : '') . ($qstring['orderby'] ? 'o=' . $qstring['orderby'] . '&' : '') . ($qstring['orderby'] && $qstring['orderdir'] ? 'd=' . $qstring['orderdir'] . '&' : ''); // Set limit $from = ($qstring['page'] - 1) * $this->usersPerPage; $qstring['limit'] = (!$max || $from <= $max ? $from : $max) . ', ' . $this->usersPerPage; // Assign vars view::assign(array('qstring' => $qstring)); return $qstring; }
protected function parseQuerystring() { $qstring = array(); // Get order field and direction $qstring['orderby'] = input::post_get('o') && in_array(input::post_get('o'), array('data_title_' . session::item('language'), 'total_views', 'total_rating', 'total_votes', 'total_likes', 'total_comments', 'order_id')) ? input::post_get('o') : ''; $qstring['orderdir'] = input::post_get('d') && in_array(input::post_get('d'), array('asc', 'desc')) ? input::post_get('d') : 'desc'; $qstring['order'] = $qstring['orderby'] ? array($qstring['orderby'] => $qstring['orderdir']) : array(); // Create url string $qstring['url'] = ($qstring['orderby'] ? 'o=' . $qstring['orderby'] . '&' : '') . ($qstring['orderby'] && $qstring['orderdir'] ? 'd=' . $qstring['orderdir'] : ''); // Assign vars view::assign(array('qstring' => $qstring)); return $qstring; }
protected function _saveRecipients($newsletterID, $filters) { // Check if demo mode is enabled if (input::demo()) { return false; } $values = $params['join_columns'] = array(); // Check extra user field $user = utf8::trim(input::post_get('user')); if ($user) { $params['join_columns'][] = $this->search_model->prepareValue($user, 'u', 'user'); $values['user'] = $user; } // Check extra verified field $verified = input::post_get('verified'); if ($verified != '') { $params['join_columns'][] = '`u`.`verified`=' . (int) $verified; $values['verified'] = $verified; } // Check extra status field $status = input::post_get('active'); if ($status != '') { $params['join_columns'][] = '`u`.`active`=' . (int) $status; $values['active'] = $status; } // Check extra group field $groups = input::post_get('groups'); if ($groups) { foreach ($groups as $index => $group) { if (config::item('usergroups', 'core', $group)) { $groups[$index] = (int) $group; } else { unset($groups[$index]); } } if ($groups) { $params['join_columns'][] = '`u`.`group_id` IN (' . implode(',', $groups) . ')'; $values['groups'] = $groups; } } // Check extra type field $typeID = input::post_get('type_id'); if ($typeID != '' && config::item('usertypes', 'core', 'keywords', $typeID)) { $params['join_columns'][] = '`u`.`type_id`=' . $typeID; $values['type_id'] = $typeID; } // Search users $searchID = $values ? $this->search_model->searchData('profile', $filters, $params['join_columns'], $values, array('type_id' => $typeID)) : 'no_terms'; // Do we have any search terms? if ($searchID == 'no_terms') { view::setError(__('search_no_terms', 'system')); } elseif ($searchID == 'no_results') { view::setError(__('search_no_results', 'system')); } else { // Get search if (!($search = $this->search_model->getSearch($searchID))) { view::setError(__('save_error', 'system')); } $newsletter = array('params' => array('conditions' => $search['conditions'], 'values' => $search['values']), 'total_users' => $search['results'], 'total_sent' => 0); // Save recipients if (!$this->newsletters_model->saveNewsletter($newsletterID, $newsletter)) { view::setError(__('save_error', 'system')); return false; } router::redirect('cp/content/newsletters/review/' . $newsletterID); } }
public function vote() { // Is user logged in? if (!users_helper::isLoggedin()) { view::ajaxError(__('no_login', 'system_info'), 403); } // Get vars $resource = input::post_get('resource'); $itemID = (int) input::post_get('item_id'); $score = (int) input::post_get('score'); // Get resource ID $resourceID = config::item('resources', 'core', $resource, 'resource_id'); if (!$resourceID || !$itemID || $score < 1 || $score > 5) { return false; } // Load votes model loader::model('comments/votes'); // Get resource item and vote if exists $item = $this->votes_model->getResourceVote($resource, $itemID); // Do resource or vote exist? if (!$item || $item['post_date']) { return false; } // Save vote if (!$this->votes_model->saveVote($resource, isset($item['user_id']) ? $item['user_id'] : 0, $itemID, $score)) { if (!validate::getTotalErrors()) { view::setError(__('save_error', 'system')); } return false; } $rating = number_format(($item['total_score'] + $score) / ($item['total_votes'] + 1), 2); $params = array('resource' => $resource, 'itemID' => $itemID, 'votes' => $item['total_votes'] + 1, 'score' => $item['total_score'], 'rating' => $rating, 'voted' => $score, 'date' => date_helper::now()); $output = view::load('comments/rating', $params, true); view::ajaxResponse($output); }
protected function parseQuerystring() { $qstring = array(); // Get order field and direction $qstring['orderby'] = input::post_get('o') && in_array(input::post_get('o'), array('name', 'total_views', 'total_clicks')) ? input::post_get('o') : 'name'; $qstring['orderdir'] = input::post_get('d') && in_array(input::post_get('d'), array('asc', 'desc')) ? input::post_get('d') : 'asc'; $qstring['order'] = $qstring['orderby'] ? array($qstring['orderby'] => $qstring['orderdir']) : array(); // Create url string $qstring['url'] = ($qstring['orderby'] ? 'o=' . $qstring['orderby'] . '&' : '') . ($qstring['orderby'] && $qstring['orderdir'] ? 'd=' . $qstring['orderdir'] . '&' : ''); // Assign vars view::assign(array('qstring' => $qstring)); return $qstring; }
public function parseSearch($resource, $fields, $params = array()) { // Get resource $resource = config::item('resources', 'core', $resource); $columns = $items = $values = array(); if (isset($fields['types']) && isset($params['type_id']) && $params['type_id']) { foreach ($fields['types'] as $typeField => $type) { if ($typeField == $params['type_id']) { list($typeColumns, $typeItems, $typeValues) = $this->parseSearch($resource['keyword'], $type, $params); $columns = $columns + $typeColumns; $items = $items + $typeItems; $values = $values + $typeValues; } } } else { // Loop through fields foreach ($fields as $index => $field) { // Is this a data field? if (isset($field['system'])) { // Get post/get value $keyword = 'data_' . $field['keyword'] . (isset($field['category_id']) && $field['category_id'] ? '_' . $field['category_id'] : ''); $value = input::post_get($keyword); // Is this a checkbox? if ($this->getValueFormat($field['type']) == 'multiple') { // Do we have an array? if (!is_array($value)) { $value = array($value); } // Make sure only existing item IDs are present $value = array_intersect($value, array_keys($field['items'])); // Do we have any IDs? if ($value) { $values[$keyword] = array_map('intval', $value); $items[$field['field_id']] = array_map('intval', $value); } } else { // Is this a multi-value type of field? if ($this->isMultiValue($field['type'])) { // Do we have a ranged search option if (isset($field['config']['search_options']) && $field['config']['search_options'] == 'range') { // Set new values $from = input::post_get($keyword . '__from'); $to = input::post_get($keyword . '__to'); // Make sure only existing item IDs are present if ($from && $to && isset($field['items'][$from]) && isset($field['items'][$to])) { // Switch values if $from is larger than $to if ($from > $to) { $temp = $from; $from = $to; $to = $temp; } $values[$keyword . '__from'] = $from; $values[$keyword . '__to'] = $to; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . "` BETWEEN " . $from . " AND " . $to; } elseif ($from && isset($field['items'][$from])) { $values[$keyword . '__from'] = $from; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . "`>=" . $from; } elseif ($to && isset($field['items'][$to])) { $values[$keyword . '__to'] = $to; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . "`<=" . $to; } } else { // Do we have an array? if (!is_array($value)) { $value = array($value); } // Make sure only existing item IDs are present $value = array_intersect($value, array_keys($field['items'])); // Do we have any IDs? if ($value) { // Do we have a single ID? if (count($value) == 1) { $values[$keyword] = isset($field['config']['search_options']) && $field['config']['search_options'] == 'multiple' ? $value : current($value); $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . '`=' . current($value); } else { $values[$keyword] = $value; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . '` IN (' . implode(',', $value) . ')'; } } } } elseif ($this->getValueFormat($field['type']) == 'birthday') { // Set new values $from = (int) input::post_get($keyword . '__from'); $to = (int) input::post_get($keyword . '__to'); // Make sure only existing item IDs are present if ($from > 0 && $to > 0) { // Switch values if $from is bigger than $to if ($from > $to) { $temp = $from; $from = $to; $to = $temp; } $values[$keyword . '__from'] = $from; $values[$keyword . '__to'] = $to; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . '` BETWEEN ' . (date('Y') - $to - 1) . date('md') . ' AND ' . (date('Y') - $from) . date('md'); } elseif ($to > 0) { $values[$keyword . '__to'] = $to; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . '`>= ' . (date('Y') - $to - 1) . date('md'); } elseif ($from > 0) { $values[$keyword . '__from'] = $from; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . '`<=' . (date('Y') - $from) . date('md'); } } elseif ($this->getValueFormat($field['type']) == 'location') { // Set country, state and city values $location = input::post_get($keyword); foreach (array('country', 'state', 'city') as $key) { if (isset($location[$key]) && is_numeric($location[$key]) && $location[$key] > 0) { $values[$keyword][$key] = $location[$key]; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . ($key != 'country' ? '_' . $key : '') . '`=' . (int) $location[$key]; } } } else { // Do we have a ranged search option if (($this->getValueFormat($field['type']) == 'number' || $this->getValueFormat($field['type']) == 'double') && isset($field['config']['search_options']) && $field['config']['search_options'] == 'range') { // Set new values $from = input::post_get($keyword . '__from'); $to = input::post_get($keyword . '__to'); // Make sure only existing item IDs are present if ($from != '' && $to != '' && is_numeric($from) && is_numeric($to)) { // Switch values if $from is larger than $to if ($from > $to) { $temp = $from; $from = $to; $to = $temp; } $values[$keyword . '__from'] = $from; $values[$keyword . '__to'] = $to; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . "` BETWEEN " . $from . " AND " . $to; } elseif ($from != '' && is_numeric($from)) { $values[$keyword . '__from'] = $from; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . "`>=" . $from; } elseif ($to != '' && is_numeric($to)) { $values[$keyword . '__to'] = $to; $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . "`<=" . $to; } } else { // Trim value $value = utf8::trim($value); // Do we have a value? if ($value != '') { $values[$keyword] = $value; // Is this a numeric value? if (is_numeric($value)) { $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . (isset($params['multilang']) && $params['multilang'] && $field['multilang'] ? '_' . session::item('language') : '') . '`=' . $value; } else { $columns[] = "`" . $resource['prefix'] . "`.`data_" . $field['keyword'] . (isset($params['multilang']) && $params['multilang'] && $field['multilang'] ? '_' . session::item('language') : '') . "` LIKE '%" . trim($this->db->escapeLike($value), "'") . "%'"; } } } } } } } } return array($columns, $items, $values); }
public function user() { // Get user and last action ID $slugID = urldecode(utf8::trim(uri::segment(3))); $lastID = (int) input::post_get('last_id', 0); // Get user if (!($user = $this->users_model->getUser($slugID)) || !$user['active'] || !$user['verified']) { error::show404(); } // Does user have permission to view this user group/type? if (!in_array($user['group_id'], session::permission('users_groups_browse', 'users')) || !in_array($user['type_id'], session::permission('users_types_browse', 'users'))) { view::noAccess(); } elseif (!$this->users_model->getPrivacyAccess($user['user_id'], isset($user['config']['privacy_profile']) ? $user['config']['privacy_profile'] : 1)) { view::noAccess($user['slug']); } // Get actions $actions = $this->timeline_model->getActions($user['user_id'], 1, $lastID, config::item('actions_per_page', 'timeline')); $ratings = array(); // Do we have actions and are we logged in? if ($actions && users_helper::isLoggedin()) { foreach ($actions as $action) { if ($action['rating']) { $ratings[$action['relative_resource']][] = $action['item_id']; } else { $ratings['timeline'][] = $action['action_id']; } } // Load votes and like models loader::model('comments/votes'); loader::model('comments/likes'); // Get likes and votes $likes = $this->likes_model->getMultiLikes($ratings); $votes = $this->votes_model->getMultiVotes($ratings); $ratings = $likes + $votes; } // Can we post messages? $post = session::permission('messages_post', 'timeline') && $this->users_model->getPrivacyAccess($user['user_id'], isset($user['config']['privacy_timeline_messages']) ? $user['config']['privacy_timeline_messages'] : 1, false) ? true : false; // Update comments pagination config::set('comments_per_page', config::item('comments_per_page', 'timeline'), 'comments'); // Set meta tags $this->metatags_model->set('timeline', 'timeline_user', array('user' => $user)); // Set title view::setTitle(__('timeline_recent', 'system_navigation'), false); // Set trail view::setTrail($user['slug'], $user['name']); // Load view if (input::isAjaxRequest()) { $output = view::load('timeline/actions', array('actions' => $actions, 'user' => $user, 'post' => $post, 'ratings' => $ratings), true); view::ajaxResponse($output); } else { view::load('timeline/index', array('actions' => $actions, 'user' => $user, 'post' => $post, 'ratings' => $ratings)); } }