public function index() { $docId = $this->uri->segment(2); $docObj = new Document_Model($docId); $modules = $docObj->getModules(); if (!is_array($modules)) { $location = FCPATH . $this->config->item('dataDir') . $docObj->getLocation(); if (is_file($location)) { $data = array('id' => $docId, 'file' => $location); $this->load->view('editor/editor_view', $data); } else { $this->session->set_flashdata('error', 'There was an error trying to open this file for editing.'); redirect($_SERVER['HTTP_REFERER']); } } $mods = array(); foreach ($modules as $mod) { $modObj = new Module_Model($mod->id); $category = $modObj->getCategory(); $loc = $modObj->getLocation(); $location = FCPATH . $this->config->item('moduleDir') . $category . '/files/' . $loc; $mods[] = array('id' => $mod->id, 'category' => $category, 'location' => $location); } $data = array('id' => $docId, 'modules' => $mods); $this->load->view('editor/editor_view', $data); }
public function saveModuleChanges($data) { $this->load->helper('file'); $modData = new Module_Model($data['module']); $category = $modData->getCategory(); $location = $modData->getLocation(); $baseName = $modData->getBaseName(); if (!write_file($this->config->item('moduleDir') . $category . '/files/' . $location, $data['html'])) { $msg = array('status' => 'error', 'msg' => 'There was an error writing the update to the module to a file.'); echo json_encode($msg); exit; } else { $this->image->setBinary($this->config->item('image_binary')); $options = array('format' => 'jpg', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip'); $newImage = $this->config->item('moduleDir') . $category . '/files/thumbnails/' . $baseName . '.jpg'; $this->image->generateFromHtml($data['html'], $newImage, $options, true); $config['source_image'] = $newImage; $config['maintain_ratio'] = true; $config['height'] = 200; $this->load->library('image_lib', $config); $this->image_lib->resize(); $this->updateDocument($data['docId']); $msg = array('status' => 'success', 'msg' => 'We successfully created the new module, and inserted the data into the database.'); echo json_encode($msg); } }
public function getDraftModules() { $query = $this->db->select()->where('owner', $this->session->id)->where('publishable', 0)->get('modules'); $data = array(); foreach ($query->result() as $row) { $modData = new Module_Model($row->id); $loc = $modData->getLocation(); $file = $modData->getBaseName(); $category = $modData->getCategory(); $thumbnail = $this->checkThumbnail($category, $file); $data[] = array('id' => $row->id, 'owner' => $modData->getOwner(), 'fileLink' => $this->config->item('moduleDir') . $category . '/files/' . $loc, 'description' => $modData->getDescription(), 'thumbnail' => $thumbnail); } return json_encode($data); }