/** * Upload image */ public function uploadImage() { $upload_path = Filesystem::makeDir(UPLOADS . DS . 'images' . DS . 'pages' . DS . date('Y/m/d/')); $filter = new Form_Filter_MachineName(); if (!empty($_POST['editor_file_link'])) { $file = $upload_path . DS . $filter->value(basename($_POST['editor_file_link'])); $info = Image::getInfo($file); copy($_POST['editor_file_link'], $file); } else { $image = new Upload_Image('file', array('path' => $upload_path)); if ($image->upload()) { $info = $image->getInfo(); $file = $image->file->path; //Ajax::json(array('succes'=>TRUE,'data'=>HTML::img(Url::toUri($image->file->path),$_POST['editor_file_alt'],array('width'=>$info->width,'height'=>$info->height)))); } //Ajax::json(array('success'=>FALSE,'data'=>implode("\n",$image->errors))); } if (isset($file)) { if ($max = config('pages.image.max', '600x600')) { $size = explode('x', $max); sizeof($size) == 1 && ($size[1] = $size[0]); if ($info->width > $size[0] or $info->height > $size[1]) { $image = new Image($file); $image->resize($max); $image->save(); } } exit(Url::toUri($file)); } exit; }
function image_preset($name, $path, $toUri = FALSE) { $preset = new Image_Preset($name); if ($preset->load()) { $image = $preset->image($path)->render(); return $toUri ? Url::toUri($image) : $image; } }
/** * Handle elFinder requests */ public function connector_action() { $path = $this->user->dir(); Filesystem::makeDir($path); $opts = array('root' => $path, 'URL' => Url::toUri($path), 'rootAlias' => 'Home', 'dotFiles' => false, 'dirSize' => true, 'fileMode' => 0666, 'dirMode' => 0777, 'mimeDetect' => 'internal', 'uploadAllow' => array('image/jpeg', 'image/png', 'image/gif', 'image/jpg'), 'imgLib' => 'gd', 'tmbDir' => '.thumbs', 'tmbAtOnce' => 5, 'tmbSize' => 48, 'fileURL' => true, 'dateFormat' => 'j M Y H:i'); $fm = new elFinder_Object($opts); $fm->run(); }
/** * Get icon uri * * @param string $name * @return string|boolean */ public function get($name) { $file = $this->path . DS . $name . '.' . $this->ext; if (file_exists($file)) { return Url::toUri($file); } return NULL; //return $this->icons->$name ? Url::toUri($this->icons->$name) : NULL; }
/** * Render */ public function render() { $this->getAttributes(); if ($this->value && ($this->value = Url::link(Url::toUri(UPLOADS . $this->value, ROOT, FALSE)))) { $tpl = new Template('Form.file'); $tpl->assign($this->attributes); $tpl->value = $this->value; $this->code = $tpl->render(); } return parent::render(); }
/** * Render */ public function render() { $this->getAttributes(); $this->attributes->type = 'file'; $this->attributes->class = 'ajaxed image'; $tpl = new Template('Upload_Ajax.image'); $tpl->assign($this->attributes); if ($this->value && ($this->value = Url::link(Url::toUri(UPLOADS . $this->value, ROOT, FALSE)))) { $tpl->value = $this->value; $tpl->image = $this->image; } $this->code = $tpl->render(); return Form_Element_Abstract::render(); }
/** * Set avatar from social account * * @param type $id */ public function avatar_action($id) { $loginza = new Db_ORM('users_loginza'); $loginza->id = $id; if ($loginza->find() && ($this->user->id == $id or access('loginza delete_all'))) { if ($loginza->photo) { $user = new User_Object(); $user->id = $this->user->id; $path = UPLOADS . DS . 'avatars' . DS . $this->user->id . DS . basename($loginza->photo); copy($loginza->photo, $path); $user->avatar = Url::toUri($path, UPLOADS); $user->save(); Ajax::json(array('action' => 'reload')); } } else { Ajax::denied(); } }
/** * Process upload * * @return string */ protected function processUpload() { if (file_exists($this->file->path) && !$this->options->overwrite) { $filename = pathinfo($this->file->name, PATHINFO_FILENAME); $this->file->path = str_replace($filename, $filename . '_' . time(), $this->file->path); } move_uploaded_file($this->file->tmp_name, $this->file->path); $this->uri = Url::toUri($this->file->path, UPLOADS, FALSE); return $this->uri; }
/** * Make nice uri for file * * @param string $file * @param string */ public static function pathToUri($file, $replace = ROOT) { return l(Url::toUri($file, $replace, FALSE)); }
/** * Render avatar * * @param string $file */ public function render($preset = 'avatar.small') { $file = UPLOADS . '/' . $this->file; return HTML::img(Url::toUri(image_preset($preset, $file)), $this->object->login, array('class' => 'avatar')); }
/** * Load scripts */ public function load() { $path = Url::toUri(dirname(__FILE__)); js($path . '/editor/editor.js'); css($path . '/editor/css/editor.css'); }
/** * Render favicon */ public function renderFavicon() { echo '<link rel="shortcut icon" href="' . Url::toUri(UPLOADS) . cogear()->get('theme.favicon') . '" />' . "\n"; }
/** * Load editor */ public function load() { $path = Url::toUri(dirname(__FILE__)) . '/elrte-1.3/'; css($path . 'css/elrte.full.css'); js($path . 'js/elrte.full.js'); }
/** * Render site logo */ public function renderLogo() { if ($logo = config('theme.logo')) { echo HTML::a(Url::link(), HTML::img(Url::toUri(UPLOADS . $logo), config('site.name'))); } }
/** * Render avatar * * @param string $file */ public function render($preset = 'avatar.small') { return HTML::img(Url::toUri(image_preset($preset, $this->getFile())), $this->object()->login, array('class' => 'avatar')); }