Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
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;
    }
}
Beispiel #3
0
 /**
  * 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();
 }
Beispiel #4
0
 /**
  * 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;
 }
Beispiel #5
0
 /**
  * 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();
 }
Beispiel #6
0
 /**
  * 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();
 }
Beispiel #7
0
 /**
  * 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();
     }
 }
Beispiel #8
0
 /**
  * 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;
 }
Beispiel #9
0
 /**
  * Make nice uri for file
  *
  * @param string $file
  * @param string
  */
 public static function pathToUri($file, $replace = ROOT)
 {
     return l(Url::toUri($file, $replace, FALSE));
 }
Beispiel #10
0
 /**
  * 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'));
 }
Beispiel #11
0
 /**
  * Load scripts
  */
 public function load()
 {
     $path = Url::toUri(dirname(__FILE__));
     js($path . '/editor/editor.js');
     css($path . '/editor/css/editor.css');
 }
Beispiel #12
0
 /**
  * Render favicon
  */
 public function renderFavicon()
 {
     echo '<link rel="shortcut icon" href="' . Url::toUri(UPLOADS) . cogear()->get('theme.favicon') . '" />' . "\n";
 }
Beispiel #13
0
 /**
  * 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');
 }
Beispiel #14
0
 /**
  * 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')));
     }
 }
Beispiel #15
0
 /**
  * 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'));
 }