function form_fields($values = array()) { $fields = parent::form_fields(); $CI =& get_instance(); $CI->load->module_model(BLOG_FOLDER, 'blog_users_model'); $CI->load->module_model(BLOG_FOLDER, 'blog_posts_model'); $post_title = ''; $post_options = $CI->blog_posts_model->options_list('id', 'title', array(), 'date_added desc'); if (empty($post_options)) { return lang('blog_error_no_posts_to_comment'); } $fields['post_id'] = array('type' => 'select', 'options' => $post_options, 'label' => 'Post'); if (!empty($values['id'])) { $post = $CI->blog_posts_model->find_by_key($values['post_id']); $post_title = $post->title; if (!$post->is_published()) { add_error(lang('blog_post_is_not_published')); } $fields['post_id'] = array('type' => 'hidden', 'value' => $post_title, 'displayonly' => TRUE); $fields['post_title'] = array('label' => 'Post', 'value' => $post_title, 'order' => 1); $fields['post_title']['displayonly'] = TRUE; $fields['post_published']['displayonly'] = TRUE; $fields['author_email']['displayonly'] = TRUE; $fields['author_name']['displayonly'] = TRUE; $fields['post_title']['displayonly'] = TRUE; $fields['author_website']['displayonly'] = TRUE; $fields['ip_host']['displayonly'] = TRUE; $fields['date_submitted'] = array('displayonly' => TRUE, 'value' => english_date($values['date_added'], TRUE)); $ip_host = !empty($values['author_ip']) ? gethostbyaddr($values['author_ip']) . ' (' . $values['author_ip'] . ')' : ''; $fields['ip_host'] = array('label' => 'IP/Host', 'value' => $ip_host, 'order' => 5, 'displayonly' => TRUE); $fields['Reply to this Comment'] = array('type' => 'section'); $replies = $this->find_all_array(array('parent_id' => $values['id'])); $reply_arr = array(); foreach ($replies as $r) { $reply_arr[] = $r['content']; } $fields['replies'] = array('label' => 'Replies', 'displayonly' => TRUE, 'value' => implode('<br /><br />', $reply_arr)); if ($values['author_id'] == $CI->fuel_auth->user_data('id') or $CI->fuel_auth->is_super_admin()) { $fields['reply'] = array('label' => 'Reply', 'type' => 'textarea'); $notify_options = array('Commentor' => lang('blog_comment_notify_option2'), 'All' => lang('blog_comment_notify_option1'), 'None' => lang('blog_comment_notify_option3')); $fields['reply_notify'] = array('label' => 'Notfiy', 'type' => 'enum', 'options' => $notify_options); } // hidden $fields['author_ip'] = array('type' => 'hidden'); } else { $fields['author_ip'] = array('type' => 'hidden', 'value' => $_SERVER['REMOTE_ADDR'], 'label' => 'Author IP Address'); $fields['is_spam'] = array('type' => 'hidden'); $fields['date_added']['type'] = 'hidden'; // so it will auto add $fields['last_modified']['type'] = 'hidden'; // so it will auto add } // set author to current fuel user if (empty($fields['author_id']) and $CI->fuel_auth->user_data('id')) { $fields['author_id'] = array('value' => $CI->fuel_auth->user_data('id')); } $fields['author_id'] = array('type' => 'hidden'); return $fields; }
function list_items($limit = null, $offset = 0, $col = 'name', $order = 'asc') { $CI =& get_instance(); $CI->load->helper('array'); $CI->load->helper('convert'); if (!isset($this->filters['group_id'])) { return array(); } $group_id = $this->filters['group_id']; // not encoded yet... then decode if (!$this->_encoded) { $this->filters['group_id'] = uri_safe_encode($group_id); // to pass the current folder $this->_encoded = TRUE; } else { $group_id = uri_safe_decode($group_id); } $asset_dir = $this->get_dir($group_id); $assets_path = $CI->asset->assets_server_path . $asset_dir . DIRECTORY_SEPARATOR; $tmpfiles = directory_to_array($assets_path, TRUE, $CI->config->item('assets_excluded_dirs', 'fuel'), FALSE); $files = get_dir_file_info($assets_path, TRUE); $cnt = count($tmpfiles); $return = array(); $asset_type_path = WEB_PATH . $CI->config->item('assets_path') . $asset_dir . '/'; //for ($i = $offset; $i < $cnt - 1; $i++) for ($i = 0; $i < $cnt; $i++) { if (!empty($tmpfiles[$i]) && !empty($files[$tmpfiles[$i]])) { $key = $tmpfiles[$i]; if (empty($this->filters['name']) || !empty($this->filters['name']) && (strpos($files[$key]['name'], $this->filters['name']) !== FALSE || strpos($key, $this->filters['name']) !== FALSE)) { $file['id'] = uri_safe_encode(assets_server_to_web_path($files[$tmpfiles[$i]]['server_path'], TRUE)); //$file['filename'] = $files[$key]['name']; $file['name'] = $key; $file['preview/kb'] = $files[$key]['size']; $file['link'] = NULL; $file['last_updated'] = english_date($files[$key]['date'], true); $return[] = $file; } } } $return = array_sorter($return, $col, $order, TRUE); // do a check for empty limit values to prevent issues found where an empty $limit value would return nothing in 5.16 $return = empty($limit) ? array_slice($return, $offset) : array_slice($return, $offset, $limit); // after sorting add the images foreach ($return as $key => $val) { if (is_image_file($return[$key]['name'])) { $return[$key]['preview/kb'] = $return[$key]['preview/kb'] . ' kb <div class="img_crop"><a href="' . $asset_type_path . $return[$key]['name'] . '" target="_blank"><img src="' . $asset_type_path . $return[$key]['name'] . '" border="0"></a></div>'; $return[$key]['link'] = '<a href="' . $asset_type_path . $return[$key]['name'] . '" target="_blank">' . $asset_dir . '/' . $return[$key]['name'] . '</a>'; } else { $return[$key]['preview/kb'] = $return[$key]['preview/kb']; $return[$key]['link'] = '<a href="' . $asset_type_path . $return[$key]['name'] . '" target="_blank">' . $asset_dir . '/' . $return[$key]['name'] . '</a>'; } } return $return; }
function list_items($limit = NULL, $offset = NULL, $col = 'date_added', $order = 'desc') { // set the filter again here just in case the table names are different $this->filters = array('title', 'content_filtered', $this->_tables['users'] . '.first_name', $this->_tables['users'] . '.last_name'); $this->db->select($this->_tables['blog_posts'] . '.id, title, CONCAT(' . $this->_tables['users'] . '.first_name, " ", ' . $this->_tables['users'] . '.last_name) AS author, ' . $this->_tables['blog_posts'] . '.date_added, ' . $this->_tables['blog_posts'] . '.published', FALSE); $this->db->join($this->_tables['users'], $this->_tables['users'] . '.id = ' . $this->_tables['blog_posts'] . '.author_id', 'left'); $data = parent::list_items($limit, $offset, $col, $order); foreach ($data as $key => $val) { $data[$key]['date_added'] = english_date($data[$key]['date_added'], TRUE); } return $data; }
function options_list($ref_id, $table_name, $include_current = false) { $CI =& get_instance(); $CI->load->helper('date'); $options = $this->find_all_array(array('ref_id' => $ref_id, 'table_name' => $table_name), 'version_timestamp desc'); $return = array(); $i = 0; foreach ($options as $val) { if ($i == 0 && $include_current) { $return[$val['version']] = 'Current Version'; } else { $return[$val['version']] = 'Version ' . $val['version'] . ' - ' . english_date($val['version_timestamp'], true); } $i++; } return $return; }
/** * Returns an option list of saved archives based on a record ID and table name * * @access public * @param string The record ID * @param string The table name * @param boolean Determines whether to include the currently active record in the archive list (optional) * @param boolean Order by for options list (optional) * @return array Key/value array with the key being the archive ID value */ public function options_list($ref_id = NULL, $table_name = NULL, $include_current = array(), $order_by = TRUE) { if ($order_by === TRUE) { $order_by = 'version_timestamp desc'; } $CI =& get_instance(); $CI->load->helper('date'); $options = $this->find_all_array(array('ref_id' => $ref_id, 'table_name' => $table_name), $order_by); $return = array(); $i = 0; foreach ($options as $val) { if ($i == 0 && !empty($include_current)) { $return[$val['version']] = 'Current Version'; } else { $return[$val['version']] = 'Version ' . $val['version'] . ' - ' . english_date($val['version_timestamp'], true); } $i++; } return $return; }
/** * Retrieves an archived value * * @access public * @param int The record ID associated with the archive * @param int The version of the archive to retrieve (optional) * @param boolean Determines whether to return all of the archives fields or just the data field value (optional) * @return array */ public function get_archive($ref_id, $version = NULL, $all_data = FALSE) { $CI =& get_instance(); $CI->load->module_model(FUEL_FOLDER, 'fuel_archives_model'); $CI->load->helper('date'); // best to use ref_id and version because it is more secure $where = array('table_name' => $this->table_name, 'ref_id' => $ref_id, 'version' => $version); $archive = $CI->fuel_archives_model->find_one_array($where); $return = $archive; $return['data'] = array(); if (!empty($archive)) { // check for serialization for backwards compatibility $data = is_serialized_str($archive['data']) ? @unserialize($archive['data']) : json_decode($archive['data'], TRUE); if (!empty($data) and is_array($data)) { foreach ($data as $key => $val) { // reformat dates if (is_date_format($val)) { $date_ts = strtotime($val); $return['data'][$key] = english_date($val); $return['data'][$key . '_hour'] = date('h', $date_ts); $return['data'][$key . '_min'] = date('i', $date_ts); $return['data'][$key . '_ampm'] = date('a', $date_ts); } else { $return['data'][$key] = $val; } } } } return $all_data ? $return : $return['data']; }
<pre class="brush: php"> is_english_format('01/01/2010'); // returns TRUE </pre> <h2>english_date('<var>date</var>', <var>[long]</var>, <var>[timezone]</var>, <var>[delimiter]</var>)</h2> <p>Returns a date in 'english' (mm/dd/yyy) format. The <dfn>long</dfn> parameter determines whether to include the time or not. The <dfn>timezone</dfn> parameter determines whether to include the time or not. The <dfn>delimiter</dfn> parameter determines whether to include the time or not. </p> <pre class="brush: php"> english_date(time()); // returns <?php echo english_date(time()); ?> </pre> <h2>english_date_verbose('<var>date</var>')</h2> <p>Returns date in 'verbose' ( Jan. 1, 2010) format.</p> <pre class="brush: php"> english_date_verbose(time()); // returns <?php echo english_date_verbose(time()); ?> </pre> <h2>time_verbose('<var>time</var>', <var>[include_seconds]</var>)</h2>
public function _form($id = NULL) { $this->load->library('form_builder'); $this->form_builder->load_custom_fields(APPPATH . 'config/custom_fields.php'); $this->fuel->load_model('fuel_navigation'); $this->load->helper('file'); $this->js_controller_params['method'] = 'add_edit'; // get saved data $saved = array(); if (!empty($id)) { $saved = $this->model->find_one_array(array($this->model->table_name() . '.id' => $id)); if (empty($saved)) { show_404(); } } if ($this->input->get('lang')) { $saved['language'] = $this->input->get('lang', TRUE); } //$this->model->add_required('location'); // create fields... start with the table info and go from there $fields = $this->model->form_fields($saved); $common_fields = $this->_common_fields($saved); $fields = array_merge($fields, $common_fields); if (!$this->fuel->auth->has_permission($this->permission, 'publish')) { unset($fields['published']); } // layout name tweaks if ($this->input->post('layout')) { $layout = $this->input->post('layout', TRUE); } else { if (!empty($saved['layout'])) { $layout = $saved['layout']; } else { $layout = $this->fuel->layouts->default_layout; } } // num uri params $fields['cache']['class'] = 'advanced'; $field_values = !empty($_POST) ? $_POST : $saved; $field_values['layout'] = $layout; // substitute data values into preview path $this->preview_path = $this->module_obj->url($field_values); $sort_arr = empty($fields['navigation_label']) ? array('location', 'layout', 'published', 'cache') : array('location', 'layout', 'navigation_label', 'published', 'cache'); // create page form fields $this->form_builder->set_validator($this->model->get_validation()); $this->form_builder->question_keys = array(); $this->form_builder->submit_value = NULL; $this->form_builder->use_form_tag = FALSE; $this->form_builder->set_field_order($sort_arr); $this->form_builder->display_errors = FALSE; $this->form_builder->show_required = FALSE; // set this one to FALSE because the layout selection will execute the js again $this->form_builder->auto_execute_js = FALSE; $this->form_builder->set_fields($fields); $this->form_builder->set_field_values($field_values); $vars['form'] = $this->form_builder->render(); // clear the values hear to prevent issues in subsequent calls $this->form_builder->clear(); $this->form_builder->submit_value = lang('btn_save'); $this->form_builder->cancel_value = lang('btn_cancel'); /***************************************************************************** // check for twin view file, controller and extra routing to generate warnings ******************************************************************************/ $view_twin = NULL; $import_view = FALSE; $routes = array(); $uses_controller = FALSE; if (!empty($field_values['location'])) { $view_twin = APPPATH . 'views/' . $field_values['location'] . EXT; $import_view = FALSE; if (file_exists($view_twin)) { $view_twin_info = get_file_info($view_twin); if (!empty($saved)) { $tz = date('T'); if ($view_twin_info['date'] > strtotime($saved['last_modified'] . ' ' . $tz) or $saved['last_modified'] == $saved['date_added']) { $import_view = TRUE; } } } // check if there is routing for this page and display warning require APPPATH . 'config/routes.php'; $page_vars = array(); foreach ($route as $key => $val) { // Convert wild-cards to RegEx $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); // Does the RegEx match? if (preg_match('#^' . $key . '$#', $field_values['location'])) { $routes[] = $key; } } // check if a controller and method already exists $segments = explode('/', $field_values['location']); if (file_exists(APPPATH . 'controllers/' . $segments[0] . EXT)) { require_once APPPATH . 'controllers/' . $segments[0] . EXT; $controller = $segments[0]; $method = !empty($segments[1]) ? $segments[1] : 'index'; $class_methods = get_class_methods($segments[0]); if (in_array($method, $class_methods)) { $uses_controller = TRUE; } } if (file_exists(APPPATH . 'controllers/' . $segments[0])) { // Is the controller in a sub-folder? if (is_dir(APPPATH . 'controllers/' . $segments[0])) { // Set the directory and remove it from the segment array if (count($segments) > 1) { // Does the requested controller exist in the sub-folder? if (file_exists(APPPATH . 'controllers/' . $segments[0] . '/' . $segments[1] . EXT)) { require_once APPPATH . 'controllers/' . $segments[0] . '/' . $segments[1] . EXT; $controller = $segments[1]; $method = !empty($segments[2]) ? $segments[2] : 'index'; $class_methods = get_class_methods($segments[1]); if (in_array($method, $class_methods)) { $uses_controller = TRUE; } } } else { if (file_exists(APPPATH . 'controllers/' . $segments[0] . $route['default_controller'] . EXT)) { require_once APPPATH . 'controllers/' . $segments[0] . $route['default_controller'] . EXT; $class_methods = get_class_methods($route['default_controller']); if (in_array('index', $class_methods)) { $uses_controller = TRUE; } } } } } } $page_vars = array(); if (!empty($_POST)) { $page_vars = array(); foreach ($_POST as $key => $val) { $key = end(explode('--', $key)); $page_vars[$key] = $val; } } if (!empty($id)) { $lang = $this->input->get('lang'); if (!$lang) { $lang = $this->fuel->language->default_option(); } $page_vars = array_merge($this->fuel_pagevariables_model->find_all_by_page_id($id, $lang), $page_vars); // the following will pre-populate fields of a different language to the default values if (empty($page_vars) and $this->fuel->language->has_multiple() and $lang != $this->fuel->language->default_option()) { $page_vars = $this->fuel_pagevariables_model->find_all_by_page_id($id, $this->fuel->language->default_option()); } } // page variables $layout = $this->fuel->layouts->get($layout); if (!empty($layout)) { $layout->set_field_values($page_vars); $fields = $layout->fields(); $import_field = $layout->import_field(); } if (!empty($import_field)) { $this->js_controller_params['import_field'] = $import_field; } // since the form builder is cleared above, we'll add in a script tag to make sure that the initialize code gets executed again $this->form_builder->add_js('<script></script>'); $this->form_builder->id = 'layout_fields'; $this->form_builder->name_prefix = 'vars'; $this->form_builder->set_fields($fields); $this->form_builder->set_field_values($page_vars); $conflict = $this->_has_conflict($fields); if (!empty($conflict)) { $vars['layout_fields'] = $conflict; } else { //$vars['layout_fields'] = ''; $vars['layout_fields'] = $this->form_builder->render(); } // other variables $vars['id'] = $id; $vars['data'] = $saved; $vars['action'] = !empty($saved['id']) ? 'edit' : 'create'; $action_uri = $vars['action'] . '/' . $id . '/'; $vars['form_action'] = $this->fuel->admin->is_inline() ? $this->module_uri . '/inline_' . $action_uri : $this->module_uri . '/' . $action_uri; $vars['versions'] = $this->fuel_archives_model->options_list($id, $this->model->table_name()); $vars['publish'] = !empty($saved['published']) && is_true_val($saved['published']) ? 'Unpublish' : 'Publish'; $vars['import_view'] = $import_view; $vars['view_twin'] = $view_twin; $vars['routes'] = $routes; $vars['uses_controller'] = $uses_controller; $vars['others'] = $this->model->get_others('location', $id); if (!empty($saved['location'])) { $related = $saved; $related['page_vars'] = $page_vars; $vars['related_items'] = $this->model->related_items($related); } $actions = $this->load->module_view(FUEL_FOLDER, '_blocks/module_create_edit_actions', $vars, TRUE); $vars['actions'] = $actions; $vars['error'] = $this->model->get_errors(); if (!empty($saved['last_modified'])) { $vars['last_updated'] = lang('pages_last_updated_by', english_date($vars['data']['last_modified'], true), $vars['data']['email']); } $notifications = $this->load->module_view(FUEL_FOLDER, '_blocks/notifications', $vars, TRUE); $vars['notifications'] = $notifications; if ($vars['action'] == 'edit') { $crumbs = array($this->module_uri => $this->module_name, '' => character_limiter(strip_tags($vars['data'][$this->display_field]), 50)); } else { $crumbs = array($this->module_uri => $this->module_name, '' => lang('action_create')); } $this->fuel->admin->set_titlebar($crumbs); // do this after rendering so it doesn't render current page' if (!empty($vars['data'][$this->display_field])) { $this->fuel->admin->add_recent_page($this->uri->uri_string(), $vars['data'][$this->display_field], $this->module); } return $vars; }
<?php echo $actions; ?> </div> <div id="notification" class="notification"> <?php echo $notifications; ?> <?php if (!empty($data['last_modified'])) { ?> <p class="ico ico_info last_updated"><?php echo lang('pages_last_updated_by', english_date($data['last_modified'], true), $data['email']); ?> </p> <?php } else { ?> <?php } ?> </div> <div id="main_content"> <?php if (!empty($page_navs)) { ?>
<?php if ($this->fuel_auth->has_permission('logs')) { if (!empty($latest_activity)) { ?> <div class="dashboard_pod" style="width: 450px;"> <h3>Latest Activity</h3> <ul class="nobullets"> <?php foreach ($latest_activity as $val) { ?> <li><strong><?php echo english_date($val['entry_date'], true); ?> :</strong> <?php echo $val['message']; ?> by <?php echo $val['name']; ?> </li> <?php } ?> </ul> <a href="<?php echo fuel_url('manage/activity'); ?> ">View all activity</a> </div>
<p>Returns a boolean value as to whether the date is in a valid 'english' (mm/dd/yyy) format.</p> <pre class="brush: php"> is_date_english_format('01/01/2010'); // returns TRUE </pre> <h2>english_date('<var>date</var>', <var>[long]</var>, <var>[timezone]</var>, <var>[delimiter]</var>)</h2> <p>Returns a date in 'english' (mm/dd/yyy) format. The <dfn>long</dfn> parameter determines whether to include the time or not. The <dfn>timezone</dfn> parameter determines whether to include the time or not. The <dfn>delimiter</dfn> parameter determines whether to include the time or not. </p> <pre class="brush: php"> english_date(time()); // returns <?=english_date(time())?> </pre> <h2>english_date_verbose('<var>date</var>')</h2> <p>Returns date in 'verbose' ( Jan. 1, 2010) format.</p> <pre class="brush: php"> english_date_verbose(time()); // returns <?=english_date_verbose(time())?> </pre> <h2>time_verbose('<var>time</var>', <var>[include_seconds]</var>)</h2> <p>Returns the time into a verbose format (e.g. 12hrs 10mins 10secs).</p> <pre class="brush: php"> time_verbose(time(), TRUE);
<?php echo $actions; ?> </div> <div id="notification" class="notification"> <?php echo $notifications; ?> <?php if (!empty($data['last_modified'])) { ?> <p class="ico ico_info last_updated"> Last updated <?php echo english_date($data['last_modified'], true); ?> by <?php echo $data['email']; ?> </p> <?php } else { ?> <?php } ?> </div> <div id="main_content">
/** * Retrieves an archived value * * @access public * @param string * @param int * @param boolean * @return array */ function get_archive($ref_id, $version = NULL, $all_data = FALSE) { $CI =& get_instance(); $CI->load->module_model(FUEL_FOLDER, 'archives_model'); $CI->load->helper('date'); // best to use ref_id and version because it is more secure $where = array('table_name' => $this->table_name, 'ref_id' => $ref_id, 'version' => $version); $archive = $CI->archives_model->find_one_array($where); $return = $archive; $return['data'] = array(); if (!empty($archive)) { $data = unserialize($archive['data']); foreach($data as $key => $val) { // reformat dates if (is_date_format($val)) { $date_ts = strtotime($val); $return['data'][$key] = english_date($val); $return['data'][$key.'_hour'] = date('h', $date_ts); $return['data'][$key.'_min'] = date('i', $date_ts); $return['data'][$key.'_ampm'] = date('a', $date_ts); } else { $return['data'][$key] = $val; } } } return ($all_data) ? $return : $return['data']; }