/** * Get all folders and files within a folder * * @param int $parent The id of this folder * @return array * **/ public static function folder_contents($parent = 0, $type = null) { // they can also pass a url hash such as #foo/bar/some-other-folder-slug if (!is_numeric($parent)) { $segment = explode('/', trim($parent, '/#')); $result = ci()->file_folders_m->get_by('slug', array_pop($segment)); $parent = $result ? $result->id : 0; } $folders = ci()->file_folders_m->where('parent_id', $parent)->where('hidden', 0)->order_by('sort')->get_all(); // $files = ci()->file_m->where(array('folder_id' => $parent)) // ->order_by('sort') // ->get_all(); $files = ci()->file_m->where(array('folder_id' => $parent, 'type' => $type))->order_by('sort')->get_all(); // let's be nice and add a date in that's formatted like the rest of the CMS if ($folders) { foreach ($folders as &$folder) { $folder->formatted_date = format_date($folder->date_added); $folder->file_count = ci()->file_m->count_by('folder_id', $folder->id); } } if ($files) { ci()->load->library('keywords/keywords'); foreach ($files as &$file) { $file->keywords_hash = $file->keywords; $file->keywords = ci()->keywords->get_string($file->keywords); $file->formatted_date = format_date($file->date_added); } } return Files::result(true, null, null, array('folder' => $folders, 'file' => $files, 'parent_id' => $parent)); }
/** * Edit the "alt" attribute of an image file */ public function save_alt() { if ($id = $this->input->post('file_id') and $alt_attribute = $this->input->post('alt_attribute')) { $this->file_m->update($id, array('alt_attribute' => $alt_attribute)); echo json_encode(Files::result(TRUE, lang('files:alt_saved'))); } }
/** * Edit description of a file */ public function save_description() { if ($id = $this->input->post('file_id') and $description = $this->input->post('description')) { $this->file_m->update($id, array('description' => $description)); echo json_encode(Files::result(TRUE, lang('files:description_saved'))); } }