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; }
/** * Simple return assets from Asset Manager * * @param $name - Collection's name * @param string $type - css/js * * @return void * * @author Kondratenko Alexander (Xander) */ private function simple_returner($name, $type = 'css') { // Simple returner $_type = 'am_' . $type; foreach ($this->{$_type}->get($name) as $f) { if ($type == 'css') { echo '<link rel="stylesheet" type="text/css" href="' . assets_server_to_web_path($f->getSourceRoot() . '/' . $f->getSourcePath()) . '" />' . "\n"; } else { echo '<script src="' . assets_server_to_web_path($f->getSourceRoot() . '/' . $f->getSourcePath()) . '"></script>' . "\n"; } } }
public function create($dir = NULL, $inline = FALSE) { $id = NULL; if (!empty($dir)) { $dir = uri_safe_decode($dir); } if ($inline !== FALSE) { $this->fuel->admin->set_inline(TRUE); } $inline = $this->fuel->admin->is_inline(); if (!empty($_POST)) { if (!empty($_FILES['userfile']) and $_FILES['userfile']['error'] != 4 or !empty($_FILES['userfile___0']) and $_FILES['userfile___0']['error'] != 4) { $this->model->on_before_post(); if ($this->input->post('asset_folder')) { $dir = $this->input->get_post('asset_folder', TRUE); if (!in_array($dir, array_keys($this->fuel->assets->dirs()))) { show_404(); } } $subfolder = $this->config->item('assets_allow_subfolder_creation', 'fuel') ? str_replace('..' . DIRECTORY_SEPARATOR, '', $this->input->get_post('subfolder', TRUE)) : ''; // remove any going down the folder structure for protections $upload_path = $this->config->item('assets_server_path') . $this->fuel->assets->dir($dir) . DIRECTORY_SEPARATOR . $subfolder; //assets_server_path is in assets config $posted['upload_path'] = $upload_path; $posted['overwrite'] = $this->input->get_post('overwrite') ? TRUE : FALSE; $posted['create_thumb'] = $this->input->get_post('create_thumb') ? TRUE : FALSE; $posted['resize_method'] = $this->input->get_post('resize_method') ? $this->input->get_post('resize_method', TRUE) : 'maintain_ratio'; $posted['resize_and_crop'] = $this->input->get_post('resize_and_crop', TRUE); $posted['width'] = $this->input->get_post('width', TRUE); $posted['height'] = $this->input->get_post('height', TRUE); $posted['master_dim'] = $this->input->get_post('master_dim', TRUE); $posted['file_name'] = $this->input->get_post('userfile_file_name', TRUE); $posted['unzip'] = $this->input->get_post('unzip') ? TRUE : FALSE; $posted['remove_subfolder'] = $this->input->get_post('remove_subfolder', TRUE); $redirect_to = uri_safe_decode($this->input->get_post('redirect_to')); $id = $posted['file_name']; // run before_create hook $this->_run_hook('before_create', $posted); // run before_save hook $this->_run_hook('before_save', $posted); if ($this->fuel->assets->upload($posted)) { foreach ($_FILES as $filename => $fileinfo) { $msg = lang('module_edited', $this->module_name, $fileinfo['name']); $this->fuel->logs->write($msg); } // explicitly set the flash values to save cookie space $flashdata['asset_folder'] = $this->input->post('asset_folder', TRUE); $flashdata['userfile_file_name'] = $this->input->post('userfile_file_name', TRUE); $flashdata['subfolder'] = $this->input->post('subfolder', TRUE); $flashdata['overwrite'] = $this->input->post('overwrite', TRUE); $flashdata['resize_method'] = $this->input->post('resize_method', TRUE); $flashdata['width'] = $this->input->post('width', TRUE); $flashdata['height'] = $this->input->post('height', TRUE); $flashdata['resize_method'] = $this->input->post('resize_method', TRUE); $flashdata['master_dim'] = $this->input->post('master_dim', TRUE); $flashdata['resize_method'] = $this->input->post('resize_method', TRUE); $uploaded_data = $this->fuel->assets->uploaded_data(); $first_file = current($uploaded_data); $uploaded_file_name_arr = array(); $uploaded_file_webpath_arr = array(); foreach ($uploaded_data as $ud) { $uploaded_path = assets_server_path() . $dir; if (is_true_val($posted['remove_subfolder'])) { $uploaded_path = $uploaded_path . '/' . $subfolder; } $uploaded_file_name_arr[] = trim(str_replace($uploaded_path, '', $ud['full_path']), '/'); $uploaded_file_webpath_arr[] = assets_server_to_web_path($ud['full_path']); } // set the uploaded file name to a concatenated string separated by commas $uploaded_file_name = implode(', ', $uploaded_file_name_arr); $flashdata['uploaded_file_name'] = $uploaded_file_name; $flashdata['uploaded_file_webpath'] = $uploaded_file_webpath_arr; $this->session->set_flashdata('uploaded_post', $flashdata); $this->fuel->admin->set_notification(lang('data_saved'), Fuel_admin::NOTIFICATION_SUCCESS); $this->model->on_after_post($posted); $inline = $this->fuel->admin->is_inline(); $query_str = query_str(array(), TRUE); if (!empty($redirect_to)) { $url = $redirect_to; } else { if ($inline === TRUE) { $url = fuel_uri($this->module . '/inline_create/' . uri_safe_encode($dir) . $query_str, FALSE); } else { $url = fuel_uri($this->module . '/create/' . uri_safe_encode($dir) . $query_str, FALSE); } } redirect($url); } else { add_errors($this->fuel->assets->errors()); } } else { add_errors(lang('error_upload')); } } $form_vars = $this->input->get(NULL, TRUE); if (!empty($dir)) { $form_vars['asset_folder'] = $dir; } $form_vars['asset_folder'] = !empty($form_vars['asset_folder']) ? trim($form_vars['asset_folder'], '/') : ''; $vars = $this->_form($form_vars, $inline); $vars['related_items'] = $this->model->related_items($vars); $list_view = $inline ? $this->module_uri . '/inline_items/' : $this->module_uri; $crumbs = array($list_view => $this->module_name, lang('assets_upload_action')); $this->fuel->admin->set_titlebar($crumbs); $this->fuel->admin->set_inline($inline === TRUE); if ($inline === TRUE) { $this->fuel->admin->set_display_mode(Fuel_admin::DISPLAY_COMPACT_TITLEBAR); } else { $vars['actions'] = $this->load->module_view(FUEL_FOLDER, '_blocks/module_create_edit_actions', $vars, TRUE); } $this->fuel->admin->render($this->views['create_edit'], $vars, '', FUEL_FOLDER); return $id; }
/** * Creates a file upload field but has the option to allow multiple fields * * @access public * @param array Fields parameters * @return string */ public function file($params) { $this->CI->load->helper('file'); $form_builder =& $params['instance']; $file_params = $params; if (!empty($params['multiple'])) { $file_params['class'] = 'multifile ' . $params['class']; } $file_params['name'] = str_replace(array('[', ']', '__'), array('_', '', '_'), $params['name']); $file_params['id'] = $params['name'] . '_upload'; $str = ''; $preview = ''; $asset_folder = ''; if (!isset($params['display_preview']) or $params['display_preview'] === TRUE) { // set the image preview containing class if (empty($params['img_container_styles'])) { $params['img_container_styles'] = 'overflow: auto; height: 200px; width: 400px; margin-top: 5px;'; } // set the styles specific to the image if (!isset($params['img_styles'])) { $params['img_styles'] = 'float: left; width: 100px;'; } if (empty($params['value'])) { $params['value'] = ''; } if (isset($params['folder']) or isset($params['upload_path'])) { if (isset($params['folder'])) { $asset_folder = trim($params['folder'], '/') . '/'; $asset_path = $asset_folder . $params['value']; $asset_path = assets_path($asset_path); } else { $asset_folder = assets_server_to_web_path($params['upload_path']) . '/'; $asset_path = $asset_folder . $params['value']; } if (!empty($params['replace_values'])) { foreach ($params['replace_values'] as $key => $val) { if (is_string($val)) { $asset_path = str_replace('{' . $key . '}', $val, $asset_path); $asset_folder = str_replace('{' . $key . '}', $val, $asset_folder); } } } } $preview = ''; if (!empty($asset_path) and !empty($params['value'])) { $preview .= ' '; $preview .= '<a href="' . $asset_path . '" target="_blank">'; if (isset($params['is_image']) or !isset($params['is_image']) and is_image_file($asset_path)) { $preview .= '<br><img src="' . $asset_path . '" style="' . $params['img_styles'] . '"/>'; } else { $preview .= $asset_path; } $preview .= '</a>'; } } $params['after_html'] = $preview; $str .= $form_builder->create_file($file_params); if (!empty($params['display_input'])) { $params['data'] = array('folder' => $asset_folder); $asset_class = ''; if (!isset($params['select']) or isset($params['select']) and $params['select'] !== FALSE) { $asset_class = 'asset_select'; } $params['class'] = !empty($params['class']) ? $params['class'] . ' ' . $asset_class : $asset_class; $params['type'] = ''; $str .= '<br><br>' . $form_builder->create_field($params); } else { $params['type'] = 'hidden'; $str .= $form_builder->create_field($params); } // add image altering hidden field values $img_params = array('create_thumb', 'thumb_marker', 'maintain_ratio', 'master_dim', 'width', 'height', 'resize_and_crop', 'resize_method'); foreach ($img_params as $img_p) { if (isset($params[$img_p])) { $str .= $this->CI->form->hidden($file_params['name'] . '_' . $img_p, $params[$img_p]); } } return $str; }