/**
  * Retourne les informations des fichiers d'un article
  *
  * @return array
  */
 public function getFilesInfo()
 {
     $files = array();
     if (!$this->okt->diary->config->files['enable']) {
         return $files;
     }
     $files_array = array_filter((array) unserialize($this->files));
     $j = 1;
     for ($i = 1; $i <= $this->okt->diary->config->files['number']; $i++) {
         if (!isset($files_array[$i]) || empty($files_array[$i]['filename']) || !file_exists($this->okt->diary->upload_dir . 'files/' . $files_array[$i]['filename'])) {
             continue;
         }
         $mime_type = files::getMimeType($this->okt->diary->upload_dir . 'files/' . $files_array[$i]['filename']);
         $files[$j] = array_merge(stat($this->okt->diary->upload_dir . 'files/' . $files_array[$i]['filename']), array('url' => $this->okt->diary->upload_url . 'files/' . $files_array[$i]['filename'], 'filename' => $files_array[$i]['filename'], 'title' => $files_array[$i]['title'], 'mime' => $mime_type, 'type' => util::getMediaType($mime_type), 'ext' => pathinfo($this->okt->diary->upload_dir . 'files/' . $files_array[$i]['filename'], PATHINFO_EXTENSION)));
         $j++;
     }
     return $files;
 }
 /**
  * Retourne les informations des fichiers d'une question
  *
  * @param string $imageslist
  * @return 	array
  */
 function getFilesInfo()
 {
     $files_infos = array();
     $files = unserialize($this->files);
     foreach ($files as $locale => $files) {
         $files_infos[$locale] = array();
         $i = 0;
         foreach ($files as $file) {
             $path = $this->okt->faq->upload_dir . $file;
             $url = $this->okt->faq->upload_url . $file;
             if (!file_exists($path)) {
                 continue;
             }
             $mime_type = files::getMimeType($path);
             $files_infos[$locale][$i] = array_merge(stat($path), array('filename' => $file, 'path' => $path, 'url' => $url, 'mime' => $mime_type, 'type' => util::getMediaType($mime_type), 'ext' => pathinfo($path, PATHINFO_EXTENSION)));
             $i++;
         }
     }
     return $files_infos;
 }
Beispiel #3
0
 private function newMediaObject($blog_id, $user, $pwd, $file)
 {
     if (empty($file['name'])) {
         throw new Exception('No file name');
     }
     if (empty($file['bits'])) {
         throw new Exception('No file content');
     }
     $file_name = $file['name'];
     $file_bits = base64_decode($file['bits']);
     $this->setUser($user, $pwd);
     $this->setBlog();
     $media = new dcMedia($this->core);
     $dir_name = path::clean(dirname($file_name));
     $file_name = basename($file_name);
     $dir_name = preg_replace('!^/!', '', $dir_name);
     if ($dir_name != '') {
         $dir = explode('/', $dir_name);
         $cwd = './';
         foreach ($dir as $v) {
             $v = files::tidyFileName($v);
             $cwd .= $v . '/';
             $media->makeDir($v);
             $media->chdir($cwd);
         }
     }
     $media_id = $media->uploadBits($file_name, $file_bits);
     $f = $media->getFile($media_id);
     return array('file' => $file_name, 'url' => $f->file_url, 'type' => files::getMimeType($file_name));
 }
Beispiel #4
0
 /**
  * Constructor
  *
  * Creates an instance of fileItem object.
  *
  * @param string	$file		Absolute file or directory path
  * @param string	$root		File root path
  * @param string	$root_url		File root URL
  */
 public function __construct($file, $root, $root_url = '')
 {
     $file = path::real($file);
     $stat = stat($file);
     $path = path::info($file);
     $rel = preg_replace('/^' . preg_quote($root, '/') . '\\/?/', '', $file);
     $this->file = $file;
     $this->basename = $path['basename'];
     $this->dir = $path['dirname'];
     $this->relname = $rel;
     $this->file_url = str_replace('%2F', '/', rawurlencode($rel));
     $this->file_url = $root_url . $this->file_url;
     $this->dir_url = dirname($this->file_url);
     $this->extension = $path['extension'];
     $this->mtime = $stat[9];
     $this->size = $stat[7];
     $this->mode = $stat[2];
     $this->uid = $stat[4];
     $this->gid = $stat[5];
     $this->w = is_writable($file);
     $this->d = is_dir($file);
     $this->f = is_file($file);
     $this->x = file_exists($file . '/.');
     $this->del = files::isDeletable($file);
     $this->type = $this->d ? null : files::getMimeType($file);
     $this->type_prefix = preg_replace('/^(.+?)\\/.+$/', '$1', $this->type);
 }
Beispiel #5
0
require dirname(__FILE__) . '/../inc/admin/prepend.php';
dcPage::check('admin');
# -- Loading themes --
$core->themes = new dcThemes($core);
$core->themes->loadModules($core->blog->themes_path, null);
# -- Page helper --
$list = new adminThemesList($core->themes, $core->blog->themes_path, $core->blog->settings->system->store_theme_url);
adminThemesList::$distributed_modules = explode(',', DC_DISTRIB_THEMES);
# -- Theme screenshot --
if (!empty($_GET['shot']) && $list->modules->moduleExists($_GET['shot'])) {
    $f = path::real(empty($_GET['src']) ? $core->blog->themes_path . '/' . $_GET['shot'] . '/screenshot.jpg' : $core->blog->themes_path . '/' . $_GET['shot'] . '/' . path::clean($_GET['src']));
    if (!file_exists($f)) {
        $f = dirname(__FILE__) . '/images/noscreenshot.png';
    }
    http::cache(array_merge(array($f), get_included_files()));
    header('Content-Type: ' . files::getMimeType($f));
    header('Content-Length: ' . filesize($f));
    readfile($f);
    exit;
}
# -- Display module configuration page --
if ($list->setConfiguration($core->blog->settings->system->theme)) {
    # Get content before page headers
    include $list->includeConfiguration();
    # Gather content
    $list->getConfiguration();
    # Display page
    dcPage::open(__('Blog appearance'), dcPage::jsPageTabs() . dcPage::jsColorPicker() . $core->callBehavior('themesToolsHeaders', $core, true), dcPage::breadcrumb(array(html::escapeHTML($core->blog->name) => '', __('Blog appearance') => $list->getURL('', false), '<span class="page-title">' . __('Theme configuration') . '</span>' => '')));
    # Display previously gathered content
    $list->displayConfiguration();
    dcPage::helpBlock('core_blog_theme_conf');
Beispiel #6
0
 /**
  * Upload an image in images folder
  *
  * @param  string $folder images folder
  * @param  string $f      selected image file (as $_FILES[<file input fieldname>])
  * @param  int    $width  check accurate width of uploaded image if <> 0
  *
  * @return string         full pathname of uploaded image
  */
 public static function uploadImage($folder, $f, $width = 0)
 {
     if (!self::canWriteImages($folder, true)) {
         throw new Exception(__('Unable to create images.'));
     }
     $name = $f['name'];
     $type = files::getMimeType($name);
     if ($type != 'image/jpeg' && $type != 'image/png') {
         throw new Exception(__('Invalid file type.'));
     }
     $dest = self::imagesPath($folder) . '/uploaded' . ($type == 'image/png' ? '.png' : '.jpg');
     if (@move_uploaded_file($f['tmp_name'], $dest) === false) {
         throw new Exception(__('An error occurred while writing the file.'));
     }
     if ($width) {
         $s = getimagesize($dest);
         if ($s[0] != $width) {
             throw new Exception(sprintf(__('Uploaded image is not %s pixels wide.'), $width));
         }
     }
     return $dest;
 }
Beispiel #7
0
 /**
 Removes a file.
 
 @param	f		<b>fileItem</b>	fileItem object
 */
 public function removeFile($f)
 {
     if (!$this->core->auth->check('media,media_admin', $this->core->blog->id)) {
         throw new Exception(__('Permission denied.'));
     }
     $media_file = $this->relpwd ? path::clean($this->relpwd . '/' . $f) : path::clean($f);
     $strReq = 'DELETE FROM ' . $this->table . ' ' . "WHERE media_path = '" . $this->con->escape($this->path) . "' " . "AND media_file = '" . $this->con->escape($media_file) . "' ";
     if (!$this->core->auth->check('media_admin', $this->core->blog->id)) {
         $strReq .= "AND user_id = '" . $this->con->escape($this->core->auth->userID()) . "'";
     }
     $this->con->execute($strReq);
     if ($this->con->changes() == 0) {
         throw new Exception(__('File does not exist in the database.'));
     }
     parent::removeFile($f);
     $this->callFileHandler(files::getMimeType($media_file), 'remove', $f);
 }
Beispiel #8
0
 /**
 Removes a file.
 
 @param	f		<b>fileItem</b>	fileItem object
 */
 public function removeFile($f)
 {
     if (!$this->okt->checkPerm('media') && !$this->okt->checkPerm('media_admin')) {
         throw new Exception(__('Permission denied.'));
     }
     $media_file = $this->relpwd ? path::clean($this->relpwd . '/' . $f) : path::clean($f);
     $strReq = 'DELETE FROM ' . $this->t_media . ' ' . "WHERE media_path = '" . $this->db->escapeStr($this->path) . "' " . "AND media_file = '" . $this->db->escapeStr($media_file) . "' ";
     if (!$this->okt->checkPerm('media_admin')) {
         $strReq .= 'AND user_id = ' . (int) $this->okt->user->id . ' ';
     }
     $this->db->execute($strReq);
     if ($this->db->affectedRows() == 0) {
         throw new Exception(__('File does not exist in the database.'));
     }
     parent::removeFile($f);
     $this->callFileHandler(files::getMimeType($media_file), 'remove', $f);
 }
 public static function createImages(&$config, $uploaded)
 {
     $body_color = $config['body_bg_c'];
     $prelude_color = $config['prelude_c'];
     $gradient = $config['body_bg_g'];
     $comment_color = $config['post_comment_bg_c'];
     $comment_color_my = $config['post_commentmy_bg_c'];
     $top_image = $config['top_image'];
     $config['top_height'] = null;
     if ($top_image != 'custom' && !isset(self::$top_images[$top_image])) {
         $top_image = 'default';
     }
     if ($uploaded && !is_file($uploaded)) {
         $uploaded = null;
     }
     if (!self::canWriteImages(true)) {
         throw new Exception(__('Unable to create images.'));
     }
     $body_fill = array('light' => dirname(__FILE__) . '/../alpha-img/gradient-l.png', 'medium' => dirname(__FILE__) . '/../alpha-img/gradient-m.png', 'dark' => dirname(__FILE__) . '/../alpha-img/gradient-d.png');
     $body_g = isset($body_fill[$gradient]) ? $body_fill[$gradient] : false;
     if ($top_image == 'custom' && $uploaded) {
         $page_t = $uploaded;
     } else {
         $page_t = dirname(__FILE__) . '/../alpha-img/page-t/' . $top_image . '.png';
     }
     $body_bg = dirname(__FILE__) . '/../alpha-img/body-bg.png';
     $page_t_mask = dirname(__FILE__) . '/../alpha-img/page-t/image-mask.png';
     $page_b = dirname(__FILE__) . '/../alpha-img/page-b.png';
     $comment_t = dirname(__FILE__) . '/../alpha-img/comment-t.png';
     $comment_b = dirname(__FILE__) . '/../alpha-img/comment-b.png';
     $default_bg = '#e0e0e0';
     $default_prelude = '#ededed';
     self::dropImage(basename($body_bg));
     self::dropImage('page-t.png');
     self::dropImage(basename($page_b));
     self::dropImage(basename($comment_t));
     self::dropImage(basename($comment_b));
     $body_color = self::adjustColor($body_color);
     $prelude_color = self::adjustColor($prelude_color);
     $comment_color = self::adjustColor($comment_color);
     if ($top_image || $body_color || $gradient != 'light' || $prelude_color || $uploaded) {
         if (!$body_color) {
             $body_color = $default_bg;
         }
         $body_color = sscanf($body_color, '#%2X%2X%2X');
         # Create body gradient with color
         $d_body_bg = imagecreatetruecolor(50, 180);
         $fill = imagecolorallocate($d_body_bg, $body_color[0], $body_color[1], $body_color[2]);
         imagefill($d_body_bg, 0, 0, $fill);
         # User choosed a gradient
         if ($body_g) {
             $s_body_bg = imagecreatefrompng($body_g);
             imagealphablending($s_body_bg, true);
             imagecopy($d_body_bg, $s_body_bg, 0, 0, 0, 0, 50, 180);
             imagedestroy($s_body_bg);
         }
         if (!$prelude_color) {
             $prelude_color = $default_prelude;
         }
         $prelude_color = sscanf($prelude_color, '#%2X%2X%2X');
         $s_prelude = imagecreatetruecolor(50, 30);
         $fill = imagecolorallocate($s_prelude, $prelude_color[0], $prelude_color[1], $prelude_color[2]);
         imagefill($s_prelude, 0, 0, $fill);
         imagecopy($d_body_bg, $s_prelude, 0, 0, 0, 0, 50, 30);
         imagepng($d_body_bg, self::imagesPath() . '/' . basename($body_bg));
     }
     if ($top_image || $body_color || $gradient != 'light') {
         # Create top image from uploaded image
         $size = getimagesize($page_t);
         $size = $size[1];
         $type = files::getMimeType($page_t);
         $d_page_t = imagecreatetruecolor(800, $size);
         if ($type == 'image/png') {
             $s_page_t = @imagecreatefrompng($page_t);
         } else {
             $s_page_t = @imagecreatefromjpeg($page_t);
         }
         if (!$s_page_t) {
             throw new exception(__('Unable to open image.'));
         }
         $fill = imagecolorallocate($d_page_t, $body_color[0], $body_color[1], $body_color[2]);
         imagefill($d_page_t, 0, 0, $fill);
         if ($type == 'image/png') {
             # PNG, we only add body gradient and image
             imagealphablending($s_page_t, true);
             imagecopyresized($d_page_t, $d_body_bg, 0, 0, 0, 50, 800, 130, 50, 130);
             imagecopy($d_page_t, $s_page_t, 0, 0, 0, 0, 800, $size);
         } else {
             # JPEG, we add image and a frame with rounded corners
             imagecopy($d_page_t, $s_page_t, 0, 0, 0, 0, 800, $size);
             imagecopy($d_page_t, $d_body_bg, 0, 0, 0, 50, 8, 4);
             imagecopy($d_page_t, $d_body_bg, 0, 4, 0, 54, 4, 4);
             imagecopy($d_page_t, $d_body_bg, 792, 0, 0, 50, 8, 4);
             imagecopy($d_page_t, $d_body_bg, 796, 4, 0, 54, 4, 4);
             $mask = imagecreatefrompng($page_t_mask);
             imagealphablending($mask, true);
             imagecopy($d_page_t, $mask, 0, 0, 0, 0, 800, 11);
             imagedestroy($mask);
             $fill = imagecolorallocate($d_page_t, 255, 255, 255);
             imagefilledrectangle($d_page_t, 0, 11, 3, $size - 1, $fill);
             imagefilledrectangle($d_page_t, 796, 11, 799, $size - 1, $fill);
             imagefilledrectangle($d_page_t, 0, $size - 9, 799, $size - 1, $fill);
         }
         $config['top_height'] = $size . 'px';
         imagepng($d_page_t, self::imagesPath() . '/page-t.png');
         imagedestroy($d_body_bg);
         imagedestroy($d_page_t);
         imagedestroy($s_page_t);
         # Create bottom image with color
         $d_page_b = imagecreatetruecolor(800, 8);
         $fill = imagecolorallocate($d_page_b, $body_color[0], $body_color[1], $body_color[2]);
         imagefill($d_page_b, 0, 0, $fill);
         $s_page_b = imagecreatefrompng($page_b);
         imagealphablending($s_page_b, true);
         imagecopy($d_page_b, $s_page_b, 0, 0, 0, 0, 800, 160);
         imagepng($d_page_b, self::imagesPath() . '/' . basename($page_b));
         imagedestroy($d_page_b);
         imagedestroy($s_page_b);
     }
     if ($comment_color) {
         self::commentImages($comment_color, $comment_t, $comment_b, basename($comment_t), basename($comment_b));
     }
     if ($comment_color_my) {
         self::commentImages($comment_color_my, $comment_t, $comment_b, 'commentmy-t.png', 'commentmy-b.png');
     }
 }
Beispiel #10
0
 /**
 Calls file handlers registered for recreate event
 
 @param	f	<b>fileItem</b>	fileItem object
 */
 public function mediaFireRecreateEvent($f)
 {
     $media_type = files::getMimeType($f->basename);
     $this->callFileHandler($media_type, 'recreate', null, $f->basename);
     // Args list to be completed as necessary (Franck)
 }