public function sendTemplate($keyword, $email, $tags = array(), $language = '') { loader::model('system/emailtemplates'); if (!$language) { $language = config::item('language_id', 'system'); } if (is_numeric($language)) { $language = config::item('languages', 'core', 'keywords', $language); } elseif (!in_array($language, config::item('languages', 'core', 'keywords'))) { return false; } if (!($template = config::item($keyword . '_' . $language, '_system_emails_cache'))) { if (!($template = $this->cache->item('core_email_template_' . $keyword . '_' . $language))) { $template = $this->emailtemplates_model->prepareTemplate($keyword, $language); if (count($template) == 3) { if ($template[$keyword]['active']) { $template = array('subject' => $template[$keyword]['subject'], 'message_html' => utf8::trim($template['header']['message_html'] . $template[$keyword]['message_html'] . $template['footer']['message_html']), 'message_text' => utf8::trim($template['header']['message_text'] . "\n\n" . $template[$keyword]['message_text'] . "\n\n" . $template['footer']['message_text'])); } else { $template = 'none'; } } else { error::show('Could not fetch email template from the database: ' . $keyword); } $this->cache->set('core_email_template_' . $keyword . '_' . $language, $template, 60 * 60 * 24 * 30); } config::set(array($keyword . '_' . $language => $template), '', '_system_emails_cache'); } $retval = true; if (is_array($template) && $template) { $retval = $this->sendEmail($email, $template['subject'], $template['message_text'], $template['message_html'], $tags); } return $retval; }
public function delete() { // Get URI vars $slugID = urldecode(utf8::trim(uri::segment(4))); // Do we have a slug ID? if ($slugID == '') { error::show404(); } // Get user if (!($user = $this->users_model->getUser($slugID)) || !$user['active'] || !$user['verified']) { error::show404(); } elseif ($user['user_id'] == session::item('user_id')) { router::redirect($user['slug']); } // Does user exist? if (!($blocked = $this->users_blocked_model->getUser($user['user_id'], true))) { view::setError(__('no_blocked_user', 'users_blocked')); router::redirect('users/blocked'); } // Delete blocked user $this->users_blocked_model->deleteBlockedUser(session::item('user_id'), $user['user_id']); // Success view::setInfo(__('user_unblocked', 'users_blocked')); router::redirect(input::get('page') ? 'users/blocked' : $user['slug']); }
public function send() { // Get URI vars $slugID = utf8::trim(urldecode(uri::segment(3))); // Do we have a slug ID? if ($slugID) { if (!($user = $this->users_model->getUser($slugID))) { view::setError(__('no_user', 'users')); router::redirect('messages/manage'); } // Does user have permission to send messages to this user group? if (!session::permission('messages_send', 'messages') || !in_array($user['group_id'], session::permission('messages_send', 'messages'))) { view::noAccess(); } elseif ($user['user_id'] == session::item('user_id')) { view::setError(__('message_recipients_self', 'messages')); router::redirect('messages/manage'); } elseif (config::item('credits_active', 'billing') && session::permission('messages_credits', 'messages') && session::permission('messages_credits', 'messages') > session::item('total_credits')) { view::setError(__('no_credits', 'system', array(), array('%' => html_helper::anchor('billing/credits', '\\1')))); router::redirect('messages/manage'); } } else { router::redirect('messages/manage'); } // Did user reach the max messages limit? if (session::permission('messages_limit', 'messages') && session::permission('messages_limit', 'messages') <= session::item('total_conversations')) { view::setError(__('message_limit_reached', 'messages', array('%limit%' => session::permission('messages_limit', 'messages')))); router::redirect('messages/manage'); } // Did we block this user or did they block us? if (config::item('blacklist_active', 'users') && ($blocked = $this->users_blocked_model->getUser($user['user_id']))) { if ($blocked['user_id'] == session::item('user_id')) { view::setError(__('user_blocked', 'users')); } else { view::setError(__('user_blocked_self', 'users')); } router::redirect($user['slug']); } // Get templates $templates = array(); if (session::permission('messages_templates', 'messages')) { loader::model('messages/templates', array(), 'messages_templates_model'); $templates = $this->messages_templates_model->getTemplates(true, true); } // Assign vars view::assign(array('user' => $slugID ? $user : array(), 'templates' => $templates)); // Process form values if (input::post('do_save_conversation')) { $this->_saveConversation($slugID ? $user : array()); } // Set title view::setTitle(__('message_send', 'messages')); // Load view view::load('messages/send'); }
protected function _saveLanguage($languageID) { // Check if demo mode is enabled if (input::demo()) { return false; } // Rules array $rules = array(); // Keyword and name fields $rules = array('name' => array('label' => __('name', 'system'), 'rules' => array('required', 'max_length' => 128)), 'keyword' => array('label' => __('keyword', 'system'), 'rules' => array('required', 'max_length' => 128, 'alpha_dash', 'strtolower', 'callback__is_unique_keyword' => $languageID))); // Assign rules validate::setRules($rules); // Validate fields if (!validate::run()) { return false; } // Get post data $name = utf8::trim(input::post('name')); $keyword = trim(input::post('keyword')); // Save language pack if (!$this->languages_model->saveLanguage($languageID, $name, $keyword)) { return false; } // Success view::setInfo(__('language_saved', 'system_languages')); router::redirect($languageID ? 'cp/system/languages/edit/' . $keyword : '/cp/system/languages'); }
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); } }
protected function parseCounters($params) { // Get fields $filters = $this->fields_model->getFields('pictures', 1, 'edit', 'in_search', true); // Set extra fields $filters[] = array('name' => __('search_keyword', 'system'), 'type' => 'text', 'keyword' => 'q'); $filters[] = array('name' => __('user', 'system'), 'type' => 'text', 'keyword' => 'user'); // Assign vars view::assign(array('filters' => $filters, 'values' => array())); // Did user submit the filter form? if (input::post_get('do_search')) { $values = array(); // Check extra keyword $keyword = utf8::trim(input::post_get('q')); if ($keyword) { $params['join_columns'][] = $this->search_model->prepareValue($keyword, 'a', array('data_title', 'data_description')); $values['q'] = $keyword; } // 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; } // Search albums $searchID = $this->search_model->searchData('picture_album', $filters, $params['join_columns'], $values); // 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')); $params['total'] = 0; return $params; } else { router::redirect('cp/plugins/pictures/albums?search_id=' . $searchID); } } // Do we have a search ID? if (!input::post_get('do_search') && input::get('search_id')) { // Get search if (!($search = $this->search_model->getSearch(input::get('search_id')))) { view::setError(__('search_expired', 'system')); router::redirect('cp/plugins/pictures/albums'); } // Combine results $params['join_columns'] = $search['conditions']['columns']; $params['join_items'] = $search['conditions']['items']; $params['values'] = $search['values']; $params['total'] = $search['results']; // Assign vars view::assign(array('values' => $search['values'])); } else { // Count albums if (!($params['total'] = $this->counters_model->countData('picture_album', 0, 0, $params['join_columns'], $params['join_items'], $params))) { view::setInfo(__('no_albums', 'pictures')); } } return $params; }
protected function parseCounters($params) { // Set filter fields $filters = array(array('name' => __('keyword', 'system'), 'type' => 'text', 'keyword' => 'q'), array('name' => __('reporter', 'reports'), 'type' => 'text', 'keyword' => 'user')); // Assign vars view::assign(array('filters' => $filters, 'values' => array())); // Did user submit the filter form? if (input::post_get('do_search')) { $values = array(); // Check extra keyword field $keyword = utf8::trim(input::post_get('q')); if ($keyword) { $params['join_columns'][] = $this->search_model->prepareValue($keyword, 'r', 'message'); $values['q'] = $keyword; } // 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; } // Search reports $searchID = $this->search_model->searchData('report', $filters, $params['join_columns'], $values); // 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')); $params['total'] = 0; return $params; } else { router::redirect('cp/content/reports?search_id=' . $searchID); } } // Do we have a search ID? if (!input::post_get('do_search') && input::get('search_id')) { // Get search if (!($search = $this->search_model->getSearch(input::get('search_id')))) { view::setError(__('search_expired', 'system')); router::redirect('cp/content/reports'); } // Combine results $params['join_columns'] = $search['conditions']['columns']; $params['values'] = $search['values']; $params['total'] = $search['results']; // Assign vars view::assign(array('values' => $search['values'])); } else { // Count reports if (!($params['total'] = $this->counters_model->countData('report', 0, 0, $params['join_columns'], array(), $params))) { view::setInfo(__('no_reports', 'reports')); } } return $params; }
protected function parseCounters($params, $typeID) { // Set filters $filters = array(array('name' => __('user', 'system'), 'type' => 'text', 'keyword' => 'user'), array('name' => __('user_group', 'users'), 'type' => 'select', 'keyword' => 'group', 'items' => config::item('usergroups', 'core')), array('name' => __('user_type', 'users'), 'type' => 'select', 'keyword' => 'type_id', 'items' => config::item('usertypes', 'core', 'names'))); foreach (config::item('usertypes', 'core', 'keywords') as $id => $type) { $filters['types'][$id] = $this->fields_model->getFields('users', $id, 'edit'); } $filters[] = array('name' => __('verified', 'users'), 'type' => 'boolean', 'keyword' => 'verified'); $filters[] = array('name' => __('active', 'system'), 'type' => 'boolean', 'keyword' => 'active'); // Assign vars view::assign(array('filters' => $filters, 'values' => array())); // Did user submit the filter form? if (input::post_get('do_search')) { $values = 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 $group = input::post_get('group'); if ($group != '' && config::item('usergroups', 'core', $group)) { $params['join_columns'][] = '`u`.`group_id`=' . $group; $values['group'] = $group; } // 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 = $this->search_model->searchData('profile', $filters, $params['join_columns'], $values, array('type_id' => $typeID)); // 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')); $params['total'] = 0; return $params; } else { router::redirect('cp/users?search_id=' . $searchID); } } // Do we have a search ID? if (!input::post_get('do_search') && input::get('search_id')) { // Get search if (!($search = $this->search_model->getSearch(input::get('search_id')))) { view::setError(__('search_expired', 'system')); router::redirect('cp/users'); } // Combine results $params['join_columns'] = $search['conditions']['columns']; $params['join_items'] = $search['conditions']['items']; $params['values'] = $search['values']; $params['total'] = $search['results']; // Assign vars view::assign(array('values' => $search['values'])); } else { // Count users if (!($params['total'] = $this->counters_model->countData('user', 0, 0, $params['join_columns'], $params['join_items'], $params))) { view::setInfo(__('no_users', 'users')); } } return $params; }
protected function parseCounters($params = array()) { // Assign vars view::assign(array('filters' => array(), 'values' => array())); // Do we have permission to search? if (session::permission('news_search', 'news')) { // Get fields $filters = $this->fields_model->getFields('news', 0, 'edit', 'in_search', true); // Set extra fields $filters[] = array('name' => __('search_keyword', 'system'), 'type' => 'text', 'keyword' => 'q'); // Assign vars view::assign(array('filters' => $filters)); // Did user submit the filter form? if (input::post_get('do_search') && session::permission('news_search', 'news')) { $values = array(); $params['total'] = $params['max'] = 0; // Check extra keyword $keyword = utf8::trim(input::post_get('q')); if ($keyword) { $params['join_columns'][] = $this->search_model->prepareValue($keyword, 'n', array('data_title_' . session::item('language'), 'data_body_' . session::item('language'))); $values['q'] = $keyword; } // Search news $searchID = $this->search_model->searchData('news', $filters, $params['join_columns'], $values, array('multilang' => true)); // 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')); return $params; } else { router::redirect('news?search_id=' . $searchID); } } // Do we have a search ID? if (!input::post_get('do_search') && input::get('search_id')) { // Get search if (!($search = $this->search_model->getSearch(input::get('search_id')))) { view::setError(__('search_expired', 'system')); router::redirect('news'); } // Set results $params['join_columns'] = $search['conditions']['columns']; $params['join_items'] = $search['conditions']['items']; $params['values'] = $search['values']; $params['total'] = $search['results']; $params['max'] = config::item('max_search_results', 'system') && config::item('max_search_results', 'system') < $params['total'] ? config::item('max_search_results', 'system') : $params['total']; // Assign vars view::assign(array('values' => $search['values'])); } } if (!input::get('search_id')) { // Count news if (!($params['total'] = $this->counters_model->countData('news', 0, 0, $params['join_columns'], $params['join_items'], $params))) { view::setInfo(__('no_entries', 'news')); } $params['max'] = $params['total']; } return $params; }
protected function parseCounters($params, $gateways) { // Set filter fields $filters = array(array('name' => __('receipt_id', 'billing_transactions'), 'type' => 'text', 'keyword' => 'receipt_id'), array('name' => __('product', 'billing'), 'type' => 'text', 'keyword' => 'product'), array('name' => __('payment_gateway', 'billing'), 'type' => 'select', 'items' => $gateways, 'keyword' => 'gateway_id'), array('name' => __('user', 'system'), 'type' => 'text', 'keyword' => 'user')); // Assign vars view::assign(array('filters' => $filters, 'values' => array())); // Did user submit the filter form? if (input::post_get('do_search')) { $values = array(); // Check extra product field $product = input::post_get('product'); if ($product != '') { $params['join_columns'][] = "`i`.`name` LIKE '" . trim($this->db->escape($product, true), "'") . "'"; $values['product'] = $product; } // Check extra receipt field $receipt_id = input::post_get('receipt_id'); if ($receipt_id != '') { $params['join_columns'][] = "`t`.`receipt_id`=" . $this->db->escape($receipt_id); $values['receipt_id'] = $receipt_id; } // Check extra gateway field $gateway_id = input::post_get('gateway_id'); if ($gateway_id && isset($gateways[$gateway_id])) { $params['join_columns'][] = "`t`.`gateway_id`=" . $gateway_id; $values['gateway_id'] = $gateway_id; } // 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; } // Search transactions $searchID = $this->search_model->searchData('billing_transaction', $filters, $params['join_columns'], $values); // 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')); $params['total'] = 0; return $params; } else { router::redirect('cp/billing/transactions?search_id=' . $searchID); } } // Do we have a search ID? if (!input::post_get('do_search') && input::get('search_id')) { // Get search if (!($search = $this->search_model->getSearch(input::get('search_id')))) { view::setError(__('search_expired', 'system')); router::redirect('cp/billing/transactions'); } // Combine results $params['join_columns'] = $search['conditions']['columns']; $params['values'] = $search['values']; $params['total'] = $search['results']; // Assign vars view::assign(array('values' => $search['values'])); } else { // Count transactions if (!($params['total'] = $this->counters_model->countData('billing_transaction', 0, 0, $params['join_columns'], array(), $params))) { view::setInfo(__('no_transactions', 'billing_transactions')); } } return $params; }
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)); } }
/** * Tests the utf8::trim() function. * @dataProvider trim_provider * @group core.helpers.utf8.trim * @test */ public function trim($str, $charlist, $expected_result) { $result = utf8::trim($str, $charlist); $this->assertEquals($expected_result, $result); }
protected function parseCounters($params = array(), $type = 'index') { // Assign vars view::assign(array('filters' => array(), 'values' => array())); // Do we have permission to search? if (session::permission('albums_search', 'pictures')) { // Get fields $filters = $this->fields_model->getFields('pictures', 1, 'edit', 'in_search', true); // Set extra fields $filters[] = array('name' => __('search_keyword', 'system'), 'type' => 'text', 'keyword' => 'q'); // Assign vars view::assign(array('filters' => $filters)); // Did user submit the filter form? if (input::post_get('do_search') && session::permission('albums_search', 'pictures')) { $values = array(); $params['total'] = $params['max'] = 0; // Check extra keyword $keyword = utf8::trim(input::post_get('q')); if ($keyword) { $params['join_columns'][] = $this->search_model->prepareValue($keyword, 'a', array('data_title', 'data_description')); $values['q'] = $keyword; } // Search albums $searchID = $this->search_model->searchData('picture_album', $filters, $params['join_columns'], $values); // 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')); return $params; } else { switch ($type) { case 'user': router::redirect('pictures/user/' . uri::segment(4) . '?search_id=' . $searchID); break; case 'manage': router::redirect('pictures/manage?search_id=' . $searchID); break; default: router::redirect('pictures?search_id=' . $searchID); break; } } } // Do we have a search ID? if (!input::post_get('do_search') && input::get('search_id')) { // Get search if (!($search = $this->search_model->getSearch(input::get('search_id')))) { view::setError(__('search_expired', 'system')); switch ($type) { case 'user': router::redirect('pictures/user/' . uri::segment(4)); break; case 'manage': router::redirect('pictures/manage'); break; default: router::redirect('pictures'); break; } } // Set results $params['join_columns'] = $search['conditions']['columns']; $params['join_items'] = $search['conditions']['items']; $params['values'] = $search['values']; $params['total'] = $search['results']; $params['max'] = config::item('max_search_results', 'system') && config::item('max_search_results', 'system') < $params['total'] ? config::item('max_search_results', 'system') : $params['total']; // Assign vars view::assign(array('values' => $search['values'])); } } if (!input::get('search_id')) { // Count albums if ($type == 'manage' && !$params['total'] || $type != 'manage' && !($params['total'] = $this->counters_model->countData('picture_album', 0, 0, $params['join_columns'], $params['join_items'], $params))) { if ($type == 'manage') { view::setInfo(__('no_albums_self', 'pictures')); } else { view::setInfo(__('no_albums', 'pictures')); } } $params['max'] = $params['total']; } return $params; }
protected function _saveField($plugin, $table, $categoryID, $fieldID, $fieldOld, $configs, $hidden) { // Check if demo mode is enabled if (input::demo()) { return false; } // Rules array $rules = array(); // Data array $inputData = array('keyword', 'type', 'style', 'class', 'required', 'system', 'multilang'); // Name foreach (config::item('languages', 'core', 'keywords') as $languageID => $lang) { $rules['name_' . $lang] = array('label' => __('name', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required', 'max_length' => 255)); $rules['vname_' . $lang] = array('label' => __('name_view', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255)); $rules['sname_' . $lang] = array('label' => __('name_search', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255)); $rules['validate_error_' . $lang] = array('label' => __('validate_error', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255)); $inputData[] = 'name_' . $lang; $inputData[] = 'vname_' . $lang; $inputData[] = 'sname_' . $lang; $inputData[] = 'validate_error_' . $lang; } // Keyword $rules['keyword'] = array('label' => __('keyword', 'system'), 'rules' => array('trim', 'required', 'alpha_dash', 'max_length' => 128, 'callback__is_unique_keyword' => array($plugin, $categoryID, $fieldID), 'callback__is_system_field' => array($fieldID ? $fieldOld['keyword'] : '', $fieldID ? $fieldOld['system'] : ''))); // Type $rules['type'] = array('label' => __('field_type', 'system_fields'), 'rules' => array('required', 'callback__is_system_field' => array($fieldID ? $fieldOld['type'] : '', $fieldID ? $fieldOld['system'] : ''))); // Style value $rules['style'] = array('label' => __('style', 'system_fields'), 'rules' => array('trim')); // Class value $rules['class'] = array('label' => __('class', 'system_fields'), 'rules' => array('trim')); // Required $rules['required'] = array('label' => __('required', 'system_fields'), 'rules' => array('intval')); // Regular expression $rules['validate'] = array('label' => __('validate', 'system_fields'), 'rules' => array('trim')); $inputData[] = 'validate'; // Configuration array $inputConfig = array(); foreach (array('custom', input::post('type')) as $conf) { if (isset($configs[$conf])) { foreach ($configs[$conf] as $option) { $rules['config_' . $conf . '_' . $option['keyword']] = array('label' => utf8::strtolower($option['label']), 'rules' => isset($option['rules']) ? $option['rules'] : array()); $inputConfig[$option['keyword']] = 'config_' . $conf . '_' . $option['keyword']; } } } // Add items rules $items = array(); $oldItems = $fieldID ? $fieldOld['items'] : array(); if ($this->fields_model->isMultiValue(input::post('type'))) { $itemsPost = input::post('items'); $sitemsPost = input::post('sitems'); foreach (config::item('languages', 'core', 'keywords') as $languageID => $lang) { $orderID = 1; if (isset($itemsPost[$lang]) && is_array($itemsPost[$lang])) { foreach ($itemsPost[$lang] as $itemID => $itemName) { // Trim name $itemName = utf8::trim($itemName); // Assign item data $items[$itemID]['order_id'] = $orderID; $items[$itemID]['name_' . $lang] = $itemName; $items[$itemID]['sname_' . $lang] = $sitemsPost[$lang][$itemID]; $orderID++; // Add rule $rules['items[' . $lang . '][' . $itemID . ']'] = array(); if ($itemName == '') { validate::setRule('items', '', ''); validate::setFieldError('items', __('empty_item', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : '')); } } } } if (!$items) { validate::setRule('items', '', ''); validate::setFieldError('items', __('no_items', 'system_fields')); } view::assign(array('field' => array('items' => $items))); } // Assign rules validate::setRules($rules); // Validate fields if (!validate::run()) { return false; } // Get post data $fieldData = input::post($inputData); // Default data $fieldData['system'] = isset($hidden['system']) ? $hidden['system'] : 0; $fieldData['multilang'] = isset($hidden['multilang']) ? $hidden['multilang'] : 0; // Get config data $fieldData['config'] = array(); foreach ($inputConfig as $key => $val) { $fieldData['config'][$key] = input::post($val); } // Set additional config data $fieldData['config']['html'] = input::post('html') ? 1 : 0; $fieldData['config']['in_search'] = input::post('in_search') ? 1 : 0; $fieldData['config']['in_search_advanced'] = input::post('in_search_advanced') ? 1 : 0; if ($fieldData['config']['in_search'] || $fieldData['config']['in_search_advanced']) { $fieldData['config']['search_options'] = input::post('search_options') ? input::post('search_options') : ''; } if (input::post('type') == 'checkbox' || input::post('search_options') == 'multiple') { $fieldData['config']['columns_number'] = input::post('columns_number') && input::post('columns_number') >= 1 && input::post('columns_number') <= 4 ? input::post('columns_number') : 1; } // Save field if (!($newFieldID = $this->fieldsdb_model->saveField($plugin, $table, $categoryID, $fieldID, $fieldData, $items))) { view::setError(__('db_no_alter', 'system_fields')); return false; } // Check if order of items have changed if ($fieldID && $this->fields_model->isMultiValue(input::post('type')) && $this->fields_model->isValueColumn(input::post('type'))) { // Get old and new item IDs $itemsOldIDs = $itemsNewIDs = array(); foreach ($oldItems as $itemID => $item) { $itemsOldIDs[$itemID] = $item['order_id']; } foreach ($items as $itemID => $item) { $itemsNewIDs[$itemID] = $item['order_id']; } // Do we have any differences? if (array_diff_assoc($itemsOldIDs, $itemsNewIDs)) { // Update items IDs $this->fieldsdb_model->updateItemsIDs($table, $fieldData['keyword'], $itemsOldIDs, $itemsNewIDs); } } // Adjust table column $this->fieldsdb_model->adjustColumn($table, $fieldData['keyword'], $newFieldID, $fieldData); // Success view::setInfo(__('field_saved', 'system_fields')); router::redirect('cp/system/fields/' . $plugin . '/edit/' . $categoryID . '/' . $newFieldID); }
/** * Execute SQL statement to upgrade the necessary tables. * * @param string - upgrade_sql - upgrade sql file */ private function _execute_upgrade_script($upgrade_sql) { $upgrade_schema = @file_get_contents($upgrade_sql); // If a table prefix is specified, add it to sql $db_config = Kohana::config('database.default'); $table_prefix = $db_config['table_prefix']; if ($table_prefix) { $find = array('CREATE TABLE IF NOT EXISTS `', 'INSERT INTO `', 'INSERT IGNORE INTO `', 'ALTER TABLE `', 'UPDATE `', 'FROM `', 'LOCK TABLES `', 'DROP TABLE IF EXISTS `', 'RENAME TABLE `', ' TO `', ' LIKE `'); $replace = array('CREATE TABLE IF NOT EXISTS `' . $table_prefix, 'INSERT INTO `' . $table_prefix, 'INSERT IGNORE INTO `' . $table_prefix, 'ALTER TABLE `' . $table_prefix, 'UPDATE `' . $table_prefix, 'FROM `' . $table_prefix, 'LOCK TABLES `' . $table_prefix, 'DROP TABLE IF EXISTS `' . $table_prefix, 'RENAME TABLE `' . $table_prefix, ' TO `' . $table_prefix, ' LIKE `' . $table_prefix); $upgrade_schema = str_replace($find, $replace, $upgrade_schema); } // Split by ; to get the sql statement for creating individual tables. $queries = explode(';', $upgrade_schema); // get the database object. foreach ($queries as $query) { // Trim whitespace and make sure we're not running an empty query (for example from the new line after the last query.) $query = utf8::trim($query); if (!empty($query)) { $result = $this->db->query($query); } } // Delete cache $cache = Cache::instance(); $cache->delete(Kohana::config('settings.subdomain') . '_settings'); }
public function delete() { // Is user loggedin ? if (!users_helper::isLoggedin()) { router::redirect('users/login'); } // Get URI vars $slugID = urldecode(utf8::trim(uri::segment(4))); // Do we have a slug ID? if ($slugID == '') { error::show404(); } // Get user if (!($user = $this->users_model->getUser($slugID)) || !$user['active'] || !$user['verified']) { error::show404(); } elseif ($user['user_id'] == session::item('user_id')) { router::redirect($user['slug']); } // Does friend exist? if (!($friend = $this->users_friends_model->getFriend($user['user_id'], false))) { view::setError(__('no_friend', 'users_friends')); router::redirect($user['slug']); } // Delete friend $this->users_friends_model->deleteFriend($friend['user_id'], $friend['friend_id'], $friend['active']); // Success view::setInfo(__($friend['active'] ? 'friend_deleted' : 'friend_canceled', 'users_friends')); router::redirect(input::get('page') ? 'users/friends/requests' : $user['slug']); }
function scrape($url, $infohash = "") { global $db; if (isset($url)) { $u = urldecode($url); $extannunce = str_replace("announce", "scrape", $u); $purl = parse_url($extannunce); $port = isset($purl["port"]) ? $purl["port"] : "80"; $path = isset($purl["path"]) ? $purl["path"] : "/scrape.php"; $an = ($purl["scheme"] != "http" ? $purl["scheme"] . "://" : "") . $purl["host"]; $fd = @fsockopen($an, $port, $errno, $errstr, 60); if ($fd) { if ($infohash != "") { $ihash = array(); $ihash = explode("','", $infohash); $info_hash = ""; foreach ($ihash as $myihash) { $info_hash .= "&info_hash=" . escapeURL($myihash); } $info_hash = substr($info_hash, 1); fputs($fd, "GET " . $path . "?" . $info_hash . " HTTP/1.0\r\nHost: somehost.net\r\n\r\n"); } else { fputs($fd, "GET " . $path . " HTTP/1.0\r\nHost: somehost.net\r\n\r\n"); } $stream = ""; while (!feof($fd)) { $stream .= fgets($fd, 4096); if (strlen($stream) > 100000) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (response too big)", ""); @fclose($fd); return; } } } else { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not connectable)", ""); return; } @fclose($fd); $stream = utf8::trim(stristr($stream, "d5:files")); if (strpos($stream, "d5:files") === false) { // if host answer but stream is not valid encoded file try old metod // will work only with standard http $ihash = array(); $ihash = explode("','", $infohash); $info_hash = ""; foreach ($ihash as $myihash) { $info_hash .= "&info_hash=" . escapeURL($myihash); } $info_hash = substr($info_hash, 1); $fd = fopen($extannunce . ($infohash != "" ? "?{$info_hash}" : ""), "rb"); if ($fd) { while (!feof($fd)) { $stream .= fread($fd, 4096); if (strlen($stream) > 100000) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (response too big)", ""); @fclose($fd); return; } } } else { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not connectable)", ""); return; } } $array = bencdec::decode($stream); if (!isset($array)) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not bencode data)", ""); return; } if ($array == false) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not bencode data)", ""); return; } if (!isset($array["files"])) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " torrent from " . $url . " tracker (not bencode data)", ""); return; } $files = $array["files"]; if (!is_array($files)) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (probably deleted torrent(s))", ""); return; } foreach ($files as $hash => $data) { $seeders = (int) $data["complete"]; $leechers = (int) $data["incomplete"]; if (isset($data["downloaded"])) { $completed = (int) $data["downloaded"]; } else { $completed = "0"; } $torrenthash = bin2hex(stripslashes($hash)); $ret = $db->query("UPDATE namemap SET lastupdate = NOW(), lastsuccess = NOW() WHERE announce_url = '" . $url . "'" . ($hash == "" ? "" : " AND namemap.info_hash = '" . $torrenthash . "'")); $ret = $db->query("UPDATE summary INNER JOIN namemap ON namemap.info_hash = summary.info_hash SET summary.seeds = " . $seeders . ", summary.leechers = " . $leechers . ", summary.finished = " . $completed . " WHERE summary.info_hash = '" . $torrenthash . "' AND namemap.announce_url = '" . $url . "'"); if ($db->affected_rows == 1) { write_log("SUCCESS update external torrent from " . $url . " tracker (infohash: " . $torrenthash . ")", ""); } } } }
public function view() { // Get URI vars $slugID = urldecode(utf8::trim(uri::segment(2))); // Do we have a slug ID? if ($slugID == '') { error::show404(); } // Is this our own account? if (strcasecmp($slugID, session::item('slug_id')) == 0) { $this->manage(); return; } // Get user if (!($user = $this->users_model->getUser($slugID))) { error::show404(); } elseif ($user['user_id'] != session::item('user_id') && (!$user['active'] || !$user['verified'] || $user['group_id'] == config::item('group_cancelled_id', 'users'))) { view::setError(__('user_not_active', 'users_signup')); router::redirect(users_helper::isLoggedin() ? users_helper::slug() : ''); } // Does user have permission to view this user group/type? if (!in_array($user['group_id'], session::permission('users_groups_view', 'users')) || !in_array($user['type_id'], session::permission('users_types_view', 'users'))) { view::noAccess(); } // Do we have cached user counters? if (!($counters = $this->counters_model->getCounters('user', session::item('user_id'), $user['user_id']))) { // Filter hook $counters = hook::filter('users/profile/view/counters', array(), $user); // Save counters for 24 hours $this->counters_model->saveCounters(false, 'user', session::item('user_id'), $user['user_id'], $counters, 60 * 24); } // Merge user and counters $user = array_merge($user, $counters); // Get fields $fields = $this->fields_model->getFields('users', $user['type_id'], 'view', 'in_view'); // Delete empty sections $this->fields_model->deleteEmptySections($fields, $user); // Assign vars view::assign(array('slugID' => $slugID, 'user' => $user, 'fields' => $fields)); // Set meta tags $this->metatags_model->set('users', 'users_view', array('user' => $user), ''); // Set trail view::setTrail($user['slug'], $user['name']); // Did we block this user or did they block us? if (users_helper::isLoggedin() && config::item('blacklist_active', 'users') && ($blocked = $this->users_blocked_model->getUser($user['user_id']))) { if ($blocked['user_id'] == session::item('user_id')) { view::setError(__('user_blocked', 'users')); } else { view::setError(__('user_blocked_self', 'users')); } // Load view view::load('users/profile/preview'); return; } // Set online/last visit status if (config::item('user_last_visit', 'users')) { if (!$user['invisible']) { if ($user['online']) { view::setTrail(false, '<span class="users online">' . __('status_online', 'users') . '</span>', array('side' => true)); } else { view::setTrail(false, '<span class="users date">' . __('status_visit_date', 'users', array('%span' => utf8::strtolower(date_helper::humanSpan($user['visit_date'])))) . '</span>', array('side' => true)); } } } // Validate profile privacy if (!$this->users_model->getPrivacyAccess($user['user_id'], isset($user['config']['privacy_profile']) ? $user['config']['privacy_profile'] : 1, false)) { view::setError(__('user_profile_limited', 'users')); // Load view view::load('users/profile/preview'); return; } // Do we have views enabled? if (config::item('user_views', 'users') && $user['user_id'] != session::item('user_id')) { // Update views counter $this->users_model->updateViews($user['user_id']); } // Do we have visitors enabled? if (users_helper::isLoggedin() && config::item('visitors_active', 'users') && $user['user_id'] != session::item('user_id') && !session::permission('users_visitors_anon', 'users')) { // Load visitors model loader::model('users/visitors', array(), 'users_visitors_model'); // Update views counter $this->users_visitors_model->addVisitor($user['user_id']); } // Load view view::load('users/profile/view'); }