/** * Sets template group ID. * * @access public * @param int $group_id The template group ID. * @return int */ public function set_group_id($group_id) { if (valid_int($group_id, 1)) { $this->_group_id = intval($group_id); } return $this->get_group_id(); }
/** * Determines whether the supplied argument is, or can be evaluated to, * a valid integer. * * @param mixed $value The value to check. * @param mixed $min The minimum permissible value. * @param mixed $max The maximum permissible value. * @return bool */ function valid_int($value, $min = NULL, $max = NULL) { $valid = (is_int($value) or is_numeric($value) && intval($value) == $value); // If no bounds have been set, we're done. if (!$valid or is_null($min) && is_null($max)) { return $valid; } $min = is_null($min) ? -INF : (valid_int($min) ? intval($min) : -INF); $max = is_null($max) ? INF : (valid_int($max) ? intval($max) : INF); $value = intval($value); $real_min = min($min, $max); $real_max = max($min, $max); return $valid && min(max($value, $real_min), $real_max) === $value; }
/** * Returns the log entries. By default, only the log entries for * the current site are returned. * * @access public * @param int|string $site_id Get the log entries for the specified site ID. * @param int $limit The maximum number of log entries to retrieve. * @return array */ public function get_log_entries($site_id = NULL, $limit = NULL) { if (!valid_int($site_id, 1)) { $site_id = $this->_ee->config->item('site_id'); } $db = $this->_ee->db; $db->select('addon_name, date, log_entry_id, message, notify_admin, type')->from('omnilog_entries')->where(array('site_id' => $site_id))->order_by('date', 'desc'); if (valid_int($limit, 1)) { $db->limit($limit); } $db_result = $db->get(); $entries = array(); foreach ($db_result->result_array() as $db_row) { $db_row['notify_admin'] = strtolower($db_row['notify_admin']) === 'y'; $entries[] = new Omnilog_entry($db_row); } return $entries; }
/** * Log. * * @access public * @return string */ public function log() { $this->EE->load->helper('form'); $log_count = $this->_model->get_log_entries_count(); $log_limit = $this->_model->get_default_log_limit(); /** * Retrieve the matching log entries: * - Filtered by entry type. * - Filtered by add-on. * - Paginated. */ $in = $this->EE->input; $post_addon = $in->post('filter_addon', TRUE); $post_type = $in->post('filter_type', TRUE); $addon_filter = $post_addon && $post_addon != 'null' ? urldecode($post_addon) : NULL; $type_filter = $post_type && $post_type != 'null' ? urldecode($post_type) : NULL; $log_start = ($addon_filter or $type_filter) ? 0 : (valid_int($in->get('start'), 0) ? (int) $in->get('start') : 0); $log_entries = $this->_model->get_log_entries(NULL, $log_limit, $log_start, $addon_filter, $type_filter); // Prepare the log pagination navigation. $next_url = $log_start + $log_limit < $log_count ? $this->_base_url . AMP . 'start=' . ($log_start + $log_limit) : ''; $previous_url = $log_start > 0 ? $this->_base_url . AMP . 'start=' . max($log_start - $log_limit, 0) : ''; // Prepare the log filter options. $addons = $this->_model->get_addons_with_an_omnilog_entry(); $types = $this->_model->get_types_with_an_omnilog_entry(); $view_addons = array('null' => $this->EE->lang->line('lbl_filter_by_addon')); foreach ($addons as $addon) { $view_addons[urlencode($addon)] = $addon; } $view_types = array('null' => $this->EE->lang->line('lbl_filter_by_type')); foreach ($types as $type) { $view_types[urlencode($type)] = $this->EE->lang->line('lbl_type_' . $type); } // Prepare the view variables. $vars = array('addon_filter' => $post_addon, 'cp_page_title' => $this->EE->lang->line('hd_log'), 'filter_addons' => $view_addons, 'filter_types' => $view_types, 'form_action' => $this->_base_qs, 'log_entries' => $log_entries, 'next_url' => $next_url, 'previous_url' => $previous_url, 'type_filter' => $post_type, 'webmaster_email' => $this->EE->config->item('webmaster_email')); // Language strings required by JS. $this->EE->load->library('javascript'); $this->EE->javascript->set_global('omnilog.lang', array('lblShow' => $this->EE->lang->line('lbl_show'), 'lblHide' => $this->EE->lang->line('lbl_hide'))); $this->EE->javascript->compile(); $this->EE->cp->add_to_foot('<script type="text/javascript" src="' . $this->_theme_url . 'common/js/cp.js"></script>'); return $this->EE->load->view('log', $vars, TRUE); }
/** * Sets template ID> * * @access public * @param int $template_id The template ID. * @return int */ public function set_template_id($template_id) { if (valid_int($template_id, 1)) { $this->_template_id = intval($template_id); } return $this->get_template_id(); }
/** * Retrieves all of the 'webpage' templates belonging to the specified * template group. * * @access public * @param int|string $group_id The template group ID. * @return array|FALSE */ public function get_templates_by_template_group($group_id) { if (!valid_int($group_id, 1)) { return FALSE; } $all_templates = $this->get_all_templates(); $group_templates = array(); foreach ($all_templates as $template) { if ($template->get_group_id() == $group_id) { $group_templates[] = $template; } } return $group_templates; }
/** * Returns an array of entry types with one or more entries in the OmniLog * table. * * @access public * @param int|string $site_id The site ID. Defaults to current site. * @return array */ public function get_types_with_an_omnilog_entry($site_id = NULL) { // Ensure we have a valid site ID. $site_id = valid_int($site_id, 1) ? (int) $site_id : $this->get_site_id(); $db_types = $this->EE->db->select('type')->group_by('type')->order_by('type', 'asc')->get_where('omnilog_entries', array('site_id' => $site_id)); $types = array(); foreach ($db_types->result() as $db_type) { $types[] = $db_type->type; } return $types; }
/** * Sets the category ID. * * @access public * @param int|string $cat_id The category ID. * @return int */ public function set_cat_id($cat_id) { if (valid_int($cat_id, 1)) { $this->_cat_id = intval($cat_id); } return $this->get_cat_id(); }
/** * Sets the log entry ID. * * @access public * @param int|string $log_entry_id The log entry ID. * @return int */ public function set_log_entry_id($log_entry_id) { if (valid_int($log_entry_id, 1)) { $this->_log_entry_id = $log_entry_id; } return $this->get_log_entry_id(); }