Example #1
0
 public function testThumbnail()
 {
     $image = new Image();
     $image->path = '/path/to/image.png';
     $thumbnail = $image->thumbnail('w:128;h:128');
     $this->assertInstanceOf('ICanBoogie\\Modules\\Thumbnailer\\Thumbnail', $thumbnail);
 }
Example #2
0
 /**
  * Constructor
  *
  * Parses arguments, looks for a command, and hands off command
  * options to another Relic library function.
  */
 public function __construct()
 {
     $this->_parseArgs();
     if (array_key_exists($this->command, $this->commands)) {
         $args = $this->_parseOpts($this->commands[$this->command]['options'], $this->commands[$this->command]['params']);
         switch ($this->command) {
             case 'thumb':
                 Image::thumbnail($args['params']['image'], $args['params']['dst'], $args['options']);
                 break;
             case 'split':
                 PDF::split($args);
                 break;
             case 'metadata':
                 $mime = Mime::mime($args['params']['file']);
                 if (in_array($mime, array('image/jpg', 'image/jpeg', 'image/tiff'))) {
                     $image = new Image($args['params']['file']);
                     $this->prettyPrint($image->exif());
                 } else {
                     if ($mime == 'application/pdf') {
                         $pdf = new PDF($args['params']['file']);
                         $this->prettyPrint($pdf->info);
                     }
                 }
                 break;
             case 'mime':
                 Mime::printMime($args['params']['file']);
                 break;
         }
     } else {
         $this->_usage(false, 'Unknown command.');
         exit(1);
     }
 }
Example #3
0
 public function make_thumb($width, $height = 0)
 {
     $img = $this->input->post('image');
     //die($img);
     if ($img == false) {
         die('FALSE');
     }
     $im = new Image($img);
     echo $im->thumbnail($width, $height)->url;
 }
Example #4
0
 /**
  * file agregator
  *
  * adds a file to an ad
  *
  * @param   mixed   $file
  * @param   mixed   $target     a blank parameter in which the
  *                              target file witll be written
  * @access  public
  * @return  Boolean
  */
 public function add($file, &$target)
 {
     $target = $this->_generateFilename($file);
     $up_pic = self::target($target);
     $up_thm = self::target($target, true);
     $stored = $this->uploaded_and_stored($file, $up_pic);
     // do not create thumbnails if file is not supported (pdf)
     if (Image::isValidType(Image::getType($up_pic))) {
         Image::thumbnail($up_pic, $up_thm, 333);
     }
     return !Image::isError() && $stored;
 }
Example #5
0
 /**
  * 用flash添加照片
  */
 function add_photo()
 {
     if ($_FILES) {
         global $php;
         $php->upload->thumb_width = 136;
         $php->upload->thumb_height = 136;
         $php->upload->max_width = 500;
         $php->upload->max_height = 500;
         $php->upload->thumb_qulitity = 100;
         if (class_exists('SaeStorage', false)) {
             $s = new SaeStorage();
             $file_id = uniqid('pic_', false) . mt_rand(1, 100);
             $tmp_file = SAE_TMP_PATH . '/thum_' . $file_id . '.jpg';
             Image::thumbnail($_FILES['Filedata']['tmp_name'], $tmp_file, $php->upload->thumb_width, $php->upload->thumb_height, $php->upload->thumb_qulitity, false);
             $pic = '/uploads/' . $file_id . ".jpg";
             $ret = $s->upload('static', $pic, $_FILES['Filedata']['tmp_name']);
             if ($ret) {
                 $data['picture'] = $s->getUrl('static', $pic);
             } else {
                 echo $s->errmsg() . ' : ' . $s->errno();
                 return;
             }
             $thum_pic = '/uploads/thum_' . $file_id . '.jpg';
             $ret = $s->upload('static', $thum_pic, $tmp_file);
             if ($ret) {
                 $data['imagep'] = $s->getUrl('static', $thum_pic);
             } else {
                 echo $s->errmsg() . ' : ' . $s->errno();
                 return;
             }
         } else {
             $php->upload->sub_dir = 'user_images';
             $up_pic = Swoole::$php->upload->save('Filedata');
             if (empty($up_pic)) {
                 return '上传失败,请重新上传! Error:' . $php->upload->error_msg;
             }
             $data['picture'] = $up_pic['name'];
             $data['imagep'] = $up_pic['thumb'];
         }
         $data['uid'] = $_POST['uid'];
         $up_pic['photo_id'] = $this->swoole->model->UserPhoto->put($data);
         /* if(isset($_POST['post']))
            {
            	Api::feed('photo', $data['uid'], 0, $up_pic['photo_id']);
            } */
         return json_encode($up_pic);
     } else {
         $this->swoole->tpl->display('myphoto_add_photo.html');
     }
 }
Example #6
0
 /**
  * add
  *
  * aggregates a image to the file system prefixing its name with
  * company id.
  *
  * @param string $type the type of image that is being uploaded,
  * a valid type can be a lowercassed model name to which images
  * are to be mapped
  * @param string $company_id company id to prefix the filename
  *
  * @access public
  * @return boolean
  */
 public function add($type, $company_id)
 {
     if (!$this->found()) {
         return false;
     }
     $name = $this->file['name'];
     $source = $this->file['tmp_name'];
     $img_dir = "img/uploads/{$type}";
     $tmb_dir = "img/uploads/{$type}/small";
     $file_format = WWW_ROOT . '%s/%s_%s';
     $target_file = sprintf($file_format, $img_dir, $company_id, $name);
     $thumbl_file = sprintf($file_format, $tmb_dir, $company_id, $name);
     $uploaded = is_uploaded_file($source);
     if ($uploaded && move_uploaded_file($source, $target_file)) {
         Image::thumbnail($target_file, $thumbl_file, 200);
     }
     return file_exists($target_file) && file_exists($thumbl_file);
 }
Example #7
0
 public function file($type, $src)
 {
     $types = Configure::read('thumbnail');
     if (!in_array($type, array_keys($types))) {
         $this->controller->_stop();
     }
     $dest = $this->getFileThumbnail($type, $src);
     if (!file_exists($dest) || filemtime($dest) < filemtime($src)) {
         App::import('vendor', 'inc/image');
         try {
             $img = new Image($src);
             $img->thumbnail($dest, $types[$type][0], $types[$type][1]);
         } catch (ImageNullException $e) {
             $this->controller->_stop();
         }
     }
     $this->controller->header('Content-Type: image/jpeg');
     echo file_get_contents($dest);
     $this->controller->_stop();
 }
Example #8
0
 public static function by_size($file_path, $width, $height, $force = false)
 {
     $width = empty($width) || !is_numeric($width) ? '96' : $width;
     $height = empty($height) || !is_numeric($height) ? '96' : $height;
     $thumb = self::normalize_thumb($file_path, $width, $height);
     if ($force) {
         $prefix = substr($file_path, 0, strrpos($file_path, '.'));
         $ext = substr($file_path, strrpos($file_path, '.') + 1);
         // remove all cached thumbnails so they get regenerated
         foreach (glob("{$prefix}*.*x*.{$ext}") as $file) {
             @unlink($file);
         }
     }
     $file = str_replace('//', '/', dirname($file_path) . "/" . basename($thumb));
     if (!file_exists($thumb)) {
         if (!Image::thumbnail($file_path, $width, $height)) {
             return false;
         }
     }
     return str_replace(PartuzaConfig::get('site_root'), '', $file);
 }
Example #9
0
 public function process_template($newdomitem, $i, $page)
 {
     $single = $this->_IU->input->get('read');
     $logged_in = !empty($this->_IU->user);
     //set title, and link it if it's <a> tag
     $titlefield = $newdomitem->find('.iu-item-title');
     foreach ($titlefield as $field) {
         $field->innertext = $i->title;
         if (strtolower(trim($field->tag)) == 'a') {
             if (!empty($single)) {
                 $field->href = 'javascript:;';
             } else {
                 $format = empty($field->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $field->{'data-format'};
                 $seo_title = $i->id . '-' . cyr_url_title($i->title);
                 $url = str_replace('%page_url%', site_url($page->uri), $format);
                 $url = str_replace('%read_slug%', $this->read_slug, $url);
                 $url = str_replace('%seo_title%', $seo_title, $url);
                 $url = str_replace('%base_url%', base_url(), $url);
                 $url = str_replace('%site_url%', site_url(), $url);
                 $field->href = $url;
             }
         }
     }
     //set link for <a> element; usable for "read more" links
     $itemlnks = $newdomitem->find('.iu-item-url');
     foreach ($itemlnks as $lnk) {
         if (strtolower(trim($lnk->tag)) != 'a') {
             continue;
         }
         $format = empty($lnk->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $lnk->{'data-format'};
         $seo_title = $i->id . '-' . cyr_url_title($i->title);
         $url = str_replace('%page_url%', site_url($page->uri), $format);
         $url = str_replace('%read_slug%', $this->read_slug, $url);
         $url = str_replace('%seo_title%', $seo_title, $url);
         $url = str_replace('%base_url%', base_url(), $url);
         $url = str_replace('%site_url%', site_url(), $url);
         $lnk->href = $url;
     }
     //fill out author name
     $authorfield = $newdomitem->find('.iu-item-author');
     foreach ($authorfield as $field) {
         $field->innertext = $i->user->get()->name;
     }
     //fill out text field
     $textfield = $newdomitem->find('.iu-item-text');
     foreach ($textfield as $field) {
         $limit = empty($field->{'data-limit'}) ? 0 : (int) $field->{'data-limit'};
         //never show excerpt to a logged in user
         if ($logged_in) {
             $shortened = false;
         } else {
             $shortened = $single == false && $limit > 0;
         }
         if ($shortened) {
             $format = empty($field->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $field->{'data-format'};
             $readmore = empty($field->{'data-readmore'}) ? 'read more &raquo;' : (string) $field->{'data-readmore'};
             $seo_title = $i->id . '-' . cyr_url_title($i->title);
             $url = str_replace('%page_url%', site_url($page->uri), $format);
             $url = str_replace('%read_slug%', $this->read_slug, $url);
             $url = str_replace('%seo_title%', $seo_title, $url);
             $url = str_replace('%base_url%', base_url(), $url);
             $url = str_replace('%site_url%', site_url(), $url);
             $field->href = $url;
             $field->innertext = character_limiter($i->text, $limit);
             $field->innertext .= ' <a href="' . $url . '" class="iu-read-more">' . $readmore . '</a>';
         } else {
             $field->innertext = $i->text;
         }
     }
     //set images (and resize them)
     $images = $newdomitem->find('.iu-item-image');
     foreach ($images as $img) {
         if (strtolower(trim($img->tag)) != 'img') {
             continue;
         }
         $width = preg_replace('/[^0-9]+/', '', $img->width);
         if (empty($width)) {
             $width = 300;
         }
         $height = preg_replace('/[^0-9]+/', '', $img->height);
         if (empty($height)) {
             $height = 0;
         }
         $im = new Image($i->image);
         $img->src = $im->thumbnail($width, $height)->url;
         $img->setAttribute('data-fullimg', $im->uri);
         $img->alt = $img->title = $i->title;
         if (!empty($single)) {
             $img->onclick = 'return iu_popup_image(this, \'' . $i->title . '\');';
         }
     }
     //set image links for <a> elements
     $imagelnks = $newdomitem->find('.iu-item-image-url');
     foreach ($imagelnks as $lnk) {
         if (strtolower(trim($lnk->tag)) != 'a') {
             continue;
         }
         if (!empty($i->image)) {
             $im = new Image($i->image);
             $lnk->href = $im->url;
         }
     }
     //set date
     $datefield = $newdomitem->find('.iu-item-date');
     foreach ($datefield as $field) {
         $format = empty($field->{'data-format'}) ? Setting::value('datetime_format', 'F j, Y @ H:i') : $field->{'data-format'};
         $field->innertext = date($format, $i->timestamp);
     }
     //add id
     $idfield = $newdomitem->find('.iu-item-id', 0);
     if (!empty($idfield)) {
         $idfield->value = $i->id;
     } else {
         $newdomitem->innertext .= '<input type="hidden" class="iu-item-id" value="' . $i->id . '" />';
     }
     //add comments on single pages
     $comments = Setting::value('comments_enabled', 'no');
     if ($single !== false && $comments != 'no') {
         $comments_engine = Setting::value('comments_engine_id', 'no');
         if ($comments == 'Disqus') {
             $html = '<div id="disqus_thread"></div>';
         } else {
             $html = '<div style="text-align: center;" id="facebook_thread" class="fb-comments" data-href="' . site_url($page->uri) . '?read=' . $i->id . '-' . cyr_url_title($i->title) . '" data-num-posts="2"></div>';
         }
         $newdomitem->innertext .= $html;
     }
     //add new item to placeholder
     return $newdomitem->outertext . "\n\n";
 }
Example #10
0
 function save($name, $filename = null, $allow = null)
 {
     //检查请求中是否存在上传的文件
     if (empty($_FILES[$name]['type'])) {
         $this->error_msg = "No upload file '{$name}'!";
         $this->error_code = 0;
         return false;
     }
     //最终相对目录
     $base_dir = empty($this->sub_dir) ? $this->sub_dir : $this->base_dir . "/" . $this->sub_dir;
     //切分目录
     if ($this->shard_type == 'randomkey') {
         if (empty($this->shard_argv)) {
             $this->shard_argv = 8;
         }
         $up_dir = $base_dir . "/" . RandomKey::randmd5($this->shard_argv);
     } elseif ($this->shard_type == 'user') {
         $up_dir = $base_dir . "/" . $this->shard_argv;
     } else {
         if (empty($this->shard_argv)) {
             $this->shard_argv = 'Ym/d';
         }
         $up_dir = $base_dir . "/" . date($this->shard_argv);
     }
     //上传的最终绝对路径,如果不存在则创建目录
     $path = WEBPATH . $up_dir;
     if (!is_dir($path)) {
         if (mkdir($path, 0777, true) === false) {
             $this->error_msg = "mkdir path={$path} fail.";
             return false;
         }
     }
     //MIME格式
     $mime = $_FILES[$name]['type'];
     $filetype = $this->mime_type($mime);
     if ($filetype === 'bin') {
         $filetype = self::file_ext($_FILES[$name]['name']);
     }
     if ($filetype === false) {
         $this->error_msg = "File mime '{$mime}' unknown!";
         $this->error_code = 1;
         return false;
     } elseif (!in_array($filetype, $this->allow)) {
         $this->error_msg = "File Type '{$filetype}' not allow upload!";
         $this->error_code = 2;
         return false;
     }
     //生成文件名
     if ($filename === null) {
         $filename = RandomKey::randtime();
         //如果已存在此文件,不断随机直到产生一个不存在的文件名
         while ($this->exist_check and is_file($path . '/' . $filename . '.' . $filetype)) {
             $filename = RandomKey::randtime();
         }
     } elseif ($this->overwrite === false and is_file($path . '/' . $filename . '.' . $filetype)) {
         $this->error_msg = "File '{$path}/{$filename}.{$filetype}' existed!";
         $this->error_code = 3;
         return false;
     }
     if ($this->shard_type != 'user') {
         $filename .= '.' . $filetype;
     }
     //检查文件大小
     $filesize = filesize($_FILES[$name]['tmp_name']);
     if ($this->max_size > 0 and $filesize > $this->max_size) {
         $this->error_msg = "File size go beyond the max_size!";
         $this->error_code = 4;
         return false;
     }
     $save_filename = $path . "/" . $filename;
     //写入文件
     if (self::moveUploadFile($_FILES[$name]['tmp_name'], $save_filename)) {
         //产生缩略图
         if ($this->thumb_width and in_array($filetype, array('gif', 'jpg', 'jpeg', 'bmp', 'png'))) {
             if (empty($this->thumb_dir)) {
                 $this->thumb_dir = $up_dir;
             }
             $thumb_file = $this->thumb_dir . '/' . $this->thumb_prefix . $filename;
             Image::thumbnail($save_filename, WEBPATH . $thumb_file, $this->thumb_width, $this->thumb_height, $this->thumb_qulitity);
             $return['thumb'] = $thumb_file;
         }
         //压缩图片
         if ($this->max_width and in_array($filetype, array('gif', 'jpg', 'jpeg', 'bmp', 'png'))) {
             Image::thumbnail($save_filename, $save_filename, $this->max_width, $this->max_height, $this->max_qulitity);
         }
         $return['name'] = "{$up_dir}/{$filename}";
         $return['size'] = $filesize;
         $return['type'] = $filetype;
         return $return;
     } else {
         $this->error_msg = "move upload file fail. tmp_name={$_FILES[$name]['tmp_name']}|dest_name={$save_filename}";
         $this->error_code = 2;
         return false;
     }
 }
Example #11
0
 /**
  * Handles adding a media item from an external source, such as YouTube.
  *
  * @param array $fd
  * @return array
  */
 protected function handleExternal(array $fd)
 {
     try {
         parse_str(parse_url($fd['external']['youtube_url'], PHP_URL_QUERY), $queryArgs);
         if (empty($queryArgs['v'])) {
             throw new Media_Exception(t('Please provide a valid YouTube URL'));
         }
         $serviceId = $queryArgs['v'];
         $externalMedia = Externalmedia::factory($fd['external']['service'], $serviceId);
     } catch (ExternalMediaDriver_InvalidID $e) {
         throw new Media_Exception(t('Please provide a valid YouTube URL'));
     } catch (Externalmedia_Exception $e) {
         throw new Media_Exception($e->getMessage());
     }
     // Generate a random directory as the uploader would, to store thumbnail
     $uploadDir = $this->_zula->getDir('uploads') . '/media/' . $fd['cid'] . '/external';
     if ($dirname = zula_make_unique_dir($uploadDir)) {
         $uploadDir .= '/' . $dirname;
         $thumbname = $dirname . '_thumb.png';
         if (copy($externalMedia->thumbUrl, $uploadDir . '/' . $thumbname)) {
             // Resize the thumbnail image
             try {
                 $thumbnailWH = $this->_config->get('media/thumb_dimension');
                 $thumbnail = new Image($uploadDir . '/' . $thumbname);
                 $thumbnail->mime = 'image/png';
                 $thumbnail->thumbnail($thumbnailWH, $thumbnailWH);
                 $thumbnail->save();
             } catch (Image_Exception $e) {
                 $this->_event->error(t('Oops, an error occurred while processing an image'));
                 $this->_log->message($e->getMessage(), Log::L_WARNING);
             }
         } else {
             $this->_event->error(t('Unable to save thumbnail image'));
             $thumbname = null;
         }
         return array(array('title' => empty($fd['title']) ? $externalMedia->title : $fd['title'], 'desc' => empty($fd['desc']) ? $externalMedia->description : $fd['desc'], 'type' => 'external', 'file' => '', 'thumbnail' => isset($thumbname) ? $dirname . '/' . $thumbname : '', 'external' => array('service' => $fd['external']['service'], 'id' => $serviceId)));
     } else {
         throw new Media_Exception(t('Unable to create directory'));
     }
 }
Example #12
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->file && $model->validate()) {
             //TODO: Посмотреть, может возможно изменять размер картинки до загрузки на сервер
             $image_name = 'user_' . $id . '.' . $model->file->extension;
             $image_full_name = Yii::$app->params['user']['image']['path'] . $image_name;
             $model->file->saveAs($image_full_name);
             Image::thumbnail($image_full_name, Yii::$app->params['user']['image']['width'], Yii::$app->params['user']['image']['height'])->save(Yii::getAlias($image_full_name), ['quality' => 100]);
             $model->image = $image_name;
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Example #13
0
 /**
  * page for upload face in iframe
  * override the js array
  */
 public function ajax_face()
 {
     if (!$this->RequestHandler->isPost()) {
         $this->error(ECode::$SYS_REQUESTERROR);
     }
     $this->requestLogin();
     $u = User::getInstance();
     $face = Configure::read("user.face");
     //init upload file
     if (isset($this->params['url']['name'])) {
         //html5 mode
         $tmp_name = tempnam(CACHE, "upload_");
         file_put_contents($tmp_name, file_get_contents('php://input'));
         $file = array('tmp_name' => $tmp_name, 'name' => nforum_iconv('utf-8', $this->encoding, $this->params['url']['name']), 'size' => filesize($tmp_name), 'error' => 0);
     } else {
         if (isset($this->params['form']['file']) && is_array($this->params['form']['file'])) {
             //flash mode
             $file = $this->params['form']['file'];
             $file['name'] = nforum_iconv('utf-8', $this->encoding, $file['name']);
         } else {
             $this->error(ECode::$ATT_NONE);
         }
     }
     $errno = isset($file['error']) ? $file['error'] : UPLOAD_ERR_NO_FILE;
     switch ($errno) {
         case UPLOAD_ERR_OK:
             $tmpFile = $file['tmp_name'];
             $tmpName = $file['name'];
             if (!isset($tmp_name) && !is_uploaded_file($tmpFile)) {
                 $msg = "上传错误";
                 break;
             }
             $ext = strrchr($tmpName, '.');
             if (!in_array(strtolower($ext), $face['ext'])) {
                 $msg = "上传文件扩展名有误";
                 break;
             }
             if (filesize($tmpFile) > $face['size']) {
                 $msg = "文件大小超过上限" . $face['size'] / 1024 . "K";
                 break;
             }
             mt_srand();
             $faceDir = $face['dir'] . DS . strtoupper(substr($u->userid, 0, 1));
             $facePath = $faceDir . DS . $u->userid . "." . mt_rand(0, 10000) . $ext;
             $faceFullDir = WWW_ROOT . $faceDir;
             $faceFullPath = WWW_ROOT . $facePath;
             if (!is_dir($faceFullDir)) {
                 @mkdir($faceFullDir);
             }
             if (is_file($faceFullPath)) {
                 $msg = "我觉得您今天可以买彩票了";
                 break;
             }
             if (isset($tmp_name)) {
                 if (!rename($tmp_name, $faceFullPath)) {
                     $msg = "上传错误";
                     break;
                 }
             } else {
                 if (!move_uploaded_file($tmpFile, $faceFullPath)) {
                     $msg = "上传错误";
                     break;
                 }
             }
             App::import('vendor', "inc/image");
             try {
                 $img = new Image($faceFullPath);
                 $format = $img->getFormat();
                 if (!in_array($format, range(1, 3))) {
                     $msg = "上传的文件貌似不是图像文件";
                     break;
                 }
                 //gif do not thumbnail
                 if ($format != 1) {
                     $facePath = preg_replace("/\\.[^.]+\$/", '.jpg', $facePath);
                     $faceFullPath = WWW_ROOT . $facePath;
                     $img->thumbnail($faceFullPath, 120, 120);
                 }
             } catch (ImageNullException $e) {
                 $msg = "上传的文件貌似不是图像文件";
                 break;
             }
             $this->set("no_html_data", array("img" => $facePath, "width" => $img->getWidth(), "height" => $img->getHeight(), "ajax_st" => 1, "ajax_code" => ECode::$SYS_AJAXOK, "ajax_msg" => "文件上传成功"));
             return;
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $msg = "文件大小超过系统上限";
             break;
         case UPLOAD_ERR_PARTIAL:
             $msg = "文件传输出错!";
             break;
         case UPLOAD_ERR_NO_FILE:
             $msg = "没有文件上传!";
             break;
         default:
             $msg = "未知错误";
     }
     if (isset($tmp_name)) {
         @unlink($tmp_name);
     }
     $this->set("no_html_data", array("ajax_st" => 0, "ajax_code" => ECode::$SYS_AJAXERROR, "ajax_msg" => $msg));
 }
Example #14
0
 public function testThumbnailofWideImage()
 {
     $src = dirname(__FILE__) . '/assets/D.jpg';
     $expected_dst = dirname(__FILE__) . '/assets/D.expected_thumb.jpg';
     $actual_dst = dirname(__FILE__) . '/assets/D.actual_thumb.jpg';
     if (file_exists($actual_dst)) {
         unlink($actual_dst);
     }
     $result = Image::thumbnail($src, $actual_dst, 200, 200);
     // Test height and width
     $info = getimagesize($result);
     $this->assertFalse(empty($info));
     $this->assertEquals($info[0], 200);
     $this->assertEquals($info[1], 200);
     // Test signature
     $actual_sig = md5_file($actual_dst);
     $expected_sig = md5_file($expected_dst);
     $this->assertEquals($actual_sig, $expected_sig);
     if (file_exists($actual_dst)) {
         unlink($actual_dst);
     }
 }
Example #15
0
 public function process_template($newdomitem, $i, $page, $content)
 {
     //$single = $this->_IU->input->get('read');
     $logged_in = !empty($this->_IU->user);
     //set title, and link it if it's <a> tag
     $titlefield = $newdomitem->find('.iu-gallery-title');
     foreach ($titlefield as $field) {
         $field->innertext = $i->title;
         if (strtolower(trim($field->tag)) == 'a') {
             $format = empty($field->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $field->{'data-format'};
             $seo_title = $i->id . '-' . cyr_url_title($i->title);
             $url = str_replace('%page_url%', site_url($page->uri), $format);
             $url = str_replace('%read_slug%', $this->read_slug, $url);
             $url = str_replace('%seo_title%', $seo_title, $url);
             $url = str_replace('%base_url%', base_url(), $url);
             $url = str_replace('%site_url%', site_url(), $url);
             $field->href = $url;
         }
     }
     //set link for <a> element; usable for "read more" links
     $itemlnks = $newdomitem->find('.iu-gallery-url');
     foreach ($itemlnks as $lnk) {
         if (strtolower(trim($lnk->tag)) != 'a') {
             continue;
         }
         $format = empty($lnk->{'data-format'}) ? '%page_url%?%read_slug%=%seo_title%' : (string) $lnk->{'data-format'};
         $seo_title = $i->id . '-' . cyr_url_title($i->title);
         $url = str_replace('%page_url%', site_url($page->uri), $format);
         $url = str_replace('%read_slug%', $this->read_slug, $url);
         $url = str_replace('%seo_title%', $seo_title, $url);
         $url = str_replace('%base_url%', base_url(), $url);
         $url = str_replace('%site_url%', site_url(), $url);
         $lnk->href = $url;
     }
     //fill out author name
     $authorfield = $newdomitem->find('.iu-gallery-author');
     foreach ($authorfield as $field) {
         $field->innertext = $i->user->get()->name;
     }
     //fill out text field
     $textfield = $newdomitem->find('.iu-gallery-text');
     foreach ($textfield as $field) {
         $limit = empty($field->{'data-limit'}) ? 0 : (int) $field->{'data-limit'};
         $field->innertext = $i->text;
     }
     //set images (and resize them)
     $images = $newdomitem->find('.iu-gallery-image');
     foreach ($images as $img) {
         if (strtolower(trim($img->tag)) != 'img') {
             continue;
         }
         $width = preg_replace('/[^0-9]+/', '', $img->width);
         if (empty($width)) {
             $width = 300;
         }
         $height = preg_replace('/[^0-9]+/', '', $img->height);
         if (empty($height)) {
             $height = 0;
         }
         $jackbox = empty($newdomitem->{'data-no-lightbox'}) ? true : false;
         $im = new Image($i->image);
         $img->src = $im->thumbnail($width, $height)->url;
         $img->setAttribute('data-fullimg', $im->uri);
         $img->alt = $img->title = $i->title;
         if ($jackbox) {
             $img->onclick = 'return iu_popup_gallery_image($(this));';
         }
         $img->id = 'iu_image_' . $i->id;
         $img->setAttribute('data-group', $content->div);
         $img->setAttribute('data-title', $i->title);
         $img->setAttribute('data-href', $i->image);
         $img->setAttribute('data-description', '#iu_gallery_desc_' . $i->id);
         /*$classesarr = empty($img->class) ? array() : explode(' ', $img->class);
         		$classesarr[] = 'iu-gallery-member';
         		$img->class = implode(' ', $classesarr); //*/
     }
     //set image links for <a> elements
     $imagelnks = $newdomitem->find('.iu-gallery-image-url');
     foreach ($imagelnks as $lnk) {
         if (strtolower(trim($lnk->tag)) != 'a') {
             continue;
         }
         if (!empty($i->image)) {
             $im = new Image($i->image);
             $lnk->href = $im->url;
         }
     }
     //set date
     $datefield = $newdomitem->find('.iu-gallery-date');
     foreach ($datefield as $field) {
         $format = empty($field->{'data-format'}) ? Setting::value('datetime_format', 'F j, Y @ H:i') : $field->{'data-format'};
         $field->innertext = date($format, $i->timestamp);
     }
     /*//add id
     		$idfield = $newdomitem->find('.iu-gallery-item-id', 0);
     		if (!empty($idfield))
     			$idfield->value = $i->id;
     		else
     			$newdomitem->innertext .= '<input type="hidden" class="iu-gallery-item-id" value="'.$i->id.'" />';
     
     		//add comments on single pages
     		/*$comments = Setting::value('comments_enabled', 'no');
     		if (($single !== false) && ($comments != 'no'))
     		{
     			$comments_engine = Setting::value('comments_engine_id', 'no');
     			if ($comments == 'Disqus')
     			{
     				$html = '<div id="disqus_thread"></div>';
     			}
     			else
     			{
     				$html = '<div style="text-align: center;" id="facebook_thread" class="fb-comments" data-href="'.site_url($page->uri).'?read='.$i->id.'-'.cyr_url_title($i->title).'" data-num-posts="2"></div>';
     			}
     
     			$newdomitem->innertext .= $html;
     		}//*/
     //add new item to placeholder
     return $newdomitem->outertext . "\n\n";
 }
Example #16
0
 /**
  * Updates settings for the media module
  *
  * @return string
  */
 public function settingsSection()
 {
     $this->setTitle(t('Media Settings'));
     $this->setOutputType(self::_OT_CONFIG);
     if (!$this->_acl->check('media_manage_settings')) {
         throw new Module_NoPermission();
     }
     // Prepare the form of settings
     $mediaConf = $this->_config->get('media');
     $form = new View_form('config/settings.html', 'media');
     $form->addElement('media/per_page', $mediaConf['per_page'], t('Per page'), new Validator_Int())->addElement('media/use_lightbox', $mediaConf['use_lightbox'], t('Use lightbox'), new Validator_Bool())->addElement('media/max_fs', $mediaConf['max_fs'], t('Maximum file size'), new Validator_Int())->addElement('media/thumb_dimension', $mediaConf['thumb_dimension'], t('Thumbnail width/height'), new Validator_Between(20, 200))->addElement('media/max_image_width', $mediaConf['max_image_width'], t('Maximum image width'), new Validator_Between(200, 90000))->addElement('media/wm_position', $mediaConf['wm_position'], t('Watermark position'), new Validator_InArray(array('t', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl')), false);
     if ($form->hasInput() && $form->isValid()) {
         $purgeTmpImages = false;
         foreach ($form->getValues('media') as $key => $val) {
             if ($key == 'max_image_width' && $mediaConf['max_image_width'] != $val || $key == 'wm_position' && $mediaConf['wm_position'] != $val) {
                 $purgeTmpImages = true;
             } else {
                 if ($key == 'max_fs') {
                     $val = zula_byte_value($val . $this->_input->post('media/max_fs_unit'));
                 }
             }
             $this->_config_sql->update('media/' . $key, $val);
         }
         // Upload the watermark
         if ($this->_input->has('post', 'media_wm_delete')) {
             unlink($this->_zula->getDir('uploads') . '/media/wm.png');
             unlink($this->_zula->getDir('uploads') . '/media/wm_thumb.png');
             $purgeTmpImages = true;
         }
         try {
             $uploader = new Uploader('media_wm', $this->_zula->getDir('uploads') . '/media');
             $uploader->subDirectories(false)->allowImages();
             $file = $uploader->getFile();
             if ($file->upload() !== false) {
                 $image = new Image($file->path);
                 $image->mime = 'image/png';
                 $image->save($file->dirname . '/wm.png', false);
                 $image->thumbnail(80, 80)->save($file->dirname . '/wm_thumb.png');
                 $purgeTmpImages = true;
             }
         } catch (Uploader_NotEnabled $e) {
             $this->_event->error(t('Sorry, it appears file uploads are disabled within your PHP configuration'));
         } catch (Uploader_MaxFileSize $e) {
             $msg = sprintf(t('Selected file exceeds the maximum allowed file size of %s'), zula_human_readable($e->getMessage()));
             $this->_event->error($msg);
         } catch (Uploader_InvalidMime $e) {
             $this->_event->error(t('Sorry, the uploaded file is of the wrong file type'));
         } catch (Uploader_Exception $e) {
             $this->_log->message($e->getMessage(), Log::L_WARNING);
             $this->_event->error(t('Oops, an error occurred while uploading your files'));
         } catch (Image_Exception $e) {
             $this->_log->message($e->getMessage(), Log::L_WARNING);
             $this->_event->error(t('Oops, an error occurred while processing an image'));
         }
         // Purge tmp images if needed and redirect
         if ($purgeTmpImages) {
             $files = (array) glob($this->_zula->getDir('tmp') . '/media/max*-*');
             foreach (array_filter($files) as $tmpFile) {
                 unlink($tmpFile);
             }
         }
         $this->_event->success(t('Updated media settings'));
         return zula_redirect($this->_router->makeUrl('media', 'config', 'settings'));
     }
     if (is_file($this->_zula->getDir('uploads') . '/media/wm_thumb.png')) {
         $wmThumbPath = $this->_zula->getDir('uploads', true) . '/media/wm_thumb.png';
     } else {
         $wmThumbPath = null;
     }
     $form->assign(array('WM_THUMB_PATH' => $wmThumbPath));
     return $form->getOutput();
 }