protected function clean_image_id($value) { if (!ImageBrowser::check_file($value)) { throw new SValidationError(__('Select an image')); } return $value; }
/** * all_json action : return the list of all images useable to generate achievements in the pix folder * @access public * @return void */ public function all_json() { $this->layout = ''; $all = array(); foreach (ImageBrowser::all() as $image) { $all[] = array('image_id' => $image->filename, 'title' => $image->title, 'url' => $this->url_for($image->path)); } $this->render_json(array('message' => 'ok', 'count' => count($all), 'elements' => $all)); }
/** * Return the image from the image_id * @access public * @return Image */ public function read_image() { if (empty($this->_image)) { $this->_image = ImageBrowser::get($this->image_id); } return $this->_image; }
{ $path = $this->normalize($path); $this->ensureAccess($path); $name = basename($file['name']); $target = $path . $name; move_uploaded_file($file['tmp_name'], $target); header('Content-Type: application/json'); $result = new ImageBrowserEntry(); $result->size = filesize($target); $result->name = $name; echo json_encode($result); } } // serve response parse_str($_SERVER['QUERY_STRING'], $parameters); $imageBrowser = new ImageBrowser(); $action = $parameters['action']; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $path = $imageBrowser->basePath() . (isset($_POST['path']) ? $_POST['path'] : ''); $name = isset($_POST['name']) ? $_POST['name'] : ''; if ($action == 'read') { $imageBrowser->getList($path); } elseif ($action == 'create') { $imageBrowser->create($path, $name); } elseif ($action == 'destroy') { $imageBrowser->destroy($path, $name); } elseif ($action == 'upload') { if (isset($_FILES['file'])) { $imageBrowser->saveFile($_FILES['file'], $path); } }
$changebrowsetab = param_integer('imgbrowserconf_artefactid_changeowner', 0); // Folder value is 0 when returning to Home folder $changefolder = param_exists('imgbrowserconf_artefactid_changefolder') ? true : false; $uploadimg = param_integer('imgbrowserconf_artefactid_upload', 0); $formsubmit = param_exists('action_submitimage') ? true : false; $formcancel = param_exists('cancel_action_submitimage') ? true : false; if ($forumpostid && !$groupid) { $sql = "SELECT g.id\n FROM {group} g\n INNER JOIN {interaction_instance} ii ON ii.group = g.id\n INNER JOIN {interaction_forum_topic} ift ON ift.forum = ii.id\n INNER JOIN {interaction_forum_post} ifp ON ifp.topic = ift.id\n WHERE ifp.id = ?\n AND ifp.deleted = 0"; $groupid = get_field_sql($sql, array($forumpostid)); } if ($blogid) { safe_require('artefact', 'blog'); $blogobj = new ArtefactTypeBlog($blogid); $institution = $blogobj->get('institution'); } // Create new image browser if ($change) { $ib = new ImageBrowser(array('view' => $viewid, 'post' => $forumpostid, 'group' => $groupid, 'institution' => $institution)); try { $returndata = $ib->render_image_browser(); json_reply(false, array('data' => $returndata)); } catch (Exception $e) { json_reply(true, $e->getMessage()); } } // If an image browser was already created and updated somehow, rebuild or submit the form now // TODO why are other values true when submitting form? if ($changebrowsetab || $changefolder || $uploadimg || $formsubmit || $formcancel) { $ib = new ImageBrowser(array('view' => $viewid, 'post' => $forumpostid, 'group' => $groupid, 'institution' => $institution)); $ib->render_image_browser(); }
/** * Check file exists, has a valid extension and is readable * @param string $filename the image filename * @access public * @return string */ public static function check_file($filename) { $path = ImageBrowser::build_path($filename); $info = pathinfo($path); return file_exists($path) && ImageBrowser::is_valid_extension($info['extension']) && is_readable($path) && !is_dir($path . '/'); }