示例#1
0
 /**
  * Register Edited image
  *
  * @access	private
  * @param   integer $id File ID (if 0 then is a new item)
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function saving($id_file, $_post)
 {
     $msg = null;
     // check permissions
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'files', $id_file, 2);
     if (is_null($msg)) {
         $ko = _MSG_ERROR;
         // check if set asnew
         $asnew = intval(isset($_post['asnew']));
         $mod = new File_model();
         $file = $mod->get_by_id($id_file);
         if ($file) {
             switch ($file->xtype) {
                 case 0:
                     // images
                     $path = APATH . 'files/filemanager/img/';
                     $rotation = intval($_post['rotate']);
                     $rotation = $rotation ? 360 - $rotation : 0;
                     if ($asnew) {
                         // save a new file
                         // set the new name
                         $final_name = X4Files_helper::get_final_name($path, $file->name);
                         $chk = X4Files_helper::create_cropped($path . $file->name, $path . $final_name, array($_post['width'], $_post['height']), array($_post['xcoord'], $_post['ycoord']), true);
                         if ($chk) {
                             $post = array();
                             $post[] = array('id_area' => $file->id_area, 'xtype' => $file->xtype, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1);
                             // insert
                             $result = $mod->insert_file($post);
                             // create permissions
                             if ($result[1]) {
                                 $id = $result[0];
                                 $perm = new Permission_model();
                                 // privs permissions
                                 $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                                 $res = $perm->pexec('files', $array, $file->id_area);
                                 if ($rotation) {
                                     sleep(1);
                                     $res = X4Files_helper::rotate($path . $final_name, $path . $final_name, $rotation);
                                 }
                             }
                         } else {
                             $result = array($_post['id'], intval($chk));
                         }
                     } else {
                         // replace old
                         $chk = X4Files_helper::create_cropped($path . $file->name, $path . $file->name, array($_post['width'], $_post['height']), array($_post['xcoord'], $_post['ycoord']), true);
                         if ($chk && $rotation) {
                             sleep(1);
                             $res = X4Files_helper::rotate($path . $file->name, $path . $file->name, $rotation);
                         }
                         $result = array($_post['id'], intval($chk));
                         $id = $file->id;
                     }
                     break;
                 case 1:
                     // generic text file
                     $path = APATH . 'files/filemanager/files/';
                     $txt = $_post['content'];
                     $res = file_put_contents($path . $file->name, $txt);
                     $id = $id_file;
                     $result = array($id, intval($res));
                     break;
                 case 2:
                     // video file
                     // get the command, if exists
                     $ffmpeg = str_replace(NL, '', $this->command_exist('ffmpeg'));
                     if (!empty($ffmpeg)) {
                         $file_name = $file->name;
                         $mimes = array('video/quicktime' => 'mov', 'video/mp4' => 'mp4', 'video/webm' => 'webm', 'video/ogg' => 'ogv', 'application/ogg' => 'ogv', 'video/x-flv' => 'flv', 'video/avi' => 'avi', 'application/vnd.adobe.flash.movie' => 'swf', 'application/x-shockwave-flash' => 'swf');
                         if (isset($_post['capture'])) {
                             // we have to extract a frame
                             $vpath = APATH . 'files/filemanager/media/';
                             $ipath = APATH . 'files/filemanager/img/';
                             $file_name = str_replace($mimes[$_post['old_format']], 'jpg', $file_name);
                             // set the new name
                             $final_name = X4Files_helper::get_final_name($ipath, $file_name);
                             //ffmpeg -i video_file -an -ss 27.888237 -vframes 1 -s 320x240 -f image2 image_file
                             $chk = shell_exec($ffmpeg . ' -i ' . $vpath . $file->name . ' -an -ss ' . $_post['sec'] . ' -vframes 1 -s ' . $_post['iwidth'] . 'x' . $_post['iheight'] . ' -f image2 ' . $ipath . $final_name . ' 2>&1');
                             if ($chk && file_exists($ipath . $final_name)) {
                                 chmod($ipath . $final_name, 0777);
                                 $post = array();
                                 $post[] = array('id_area' => $file->id_area, 'xtype' => 0, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1);
                                 // insert
                                 $result = $mod->insert_file($post);
                                 // create permissions
                                 if ($result[1]) {
                                     $id = $result[0];
                                     $perm = new Permission_model();
                                     // privs permissions
                                     $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                                     $res = $perm->pexec('files', $array, $file->id_area);
                                 }
                             }
                         } else {
                             // is a video conversion
                             $path = APATH . 'files/filemanager/media/';
                             $new_format = $new_size = 0;
                             if ($_post['old_width'] != $_post['width'] || $_post['old_height'] != $_post['height']) {
                                 $new_size = 1;
                             }
                             // if new format is a new file
                             if ($_post['old_format'] != $_post['format']) {
                                 $new_format = 1;
                                 $file_name = str_replace($mimes[$_post['old_format']], $mimes[$_post['format']], $file_name);
                             }
                             if ($asnew || $new_format) {
                                 // save a new file
                                 // set the new name
                                 $final_name = X4Files_helper::get_final_name($path, $file_name);
                                 if ($new_size) {
                                     $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' -vf scale=' . $_post['width'] . ':' . $_post['height'] . ' ' . $path . $final_name . ' 2>&1');
                                 } else {
                                     // -c:a copy
                                     $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' ' . $path . $final_name . ' 2>&1');
                                 }
                                 if ($chk) {
                                     chmod($path . $final_name, 0777);
                                     $post = array();
                                     $post[] = array('id_area' => $file->id_area, 'xtype' => $file->xtype, 'category' => $file->category, 'subcategory' => $file->subcategory, 'name' => $final_name, 'alt' => $file->alt, 'xon' => 1);
                                     // insert
                                     $result = $mod->insert_file($post);
                                     // create permissions
                                     if ($result[1]) {
                                         $id = $result[0];
                                         $perm = new Permission_model();
                                         // privs permissions
                                         $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                                         $res = $perm->pexec('files', $array, $file->id_area);
                                     }
                                 }
                             } else {
                                 // replace old
                                 if ($new_size) {
                                     $chk = shell_exec($ffmpeg . ' -i ' . $path . $file->name . ' -vf scale=' . $_post['width'] . ':' . $_post['height'] . ' ' . $path . $file->name . ' 2>&1');
                                 } else {
                                     $chk = 1;
                                 }
                                 $result = array($_post['id'], intval($chk));
                                 $id = $result[0];
                             }
                         }
                     } else {
                         // ffmpeg not available
                         $result = array(0, 0);
                         $ko = _FFMPEG_NOT_FOUND;
                     }
                     break;
                 case 3:
                     // template
                     $path = APATH . 'files/filemanager/template/';
                     if (extension_loaded('php5-tidy')) {
                         // clean the code
                         $tidy = tidy_parse_string($_post['content']);
                         $tidy->cleanRepair();
                         $html = $tidy->html();
                     } else {
                         $html = $_post['content'];
                     }
                     $res = file_put_contents($path . $file->name, $html);
                     $id = $id_file;
                     $result = array($id, intval($res));
                     break;
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result, _MSG_OK, $ko);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'files/editor/' . $id, 'title' => null);
             }
         } else {
             // file not found
             // set message
             $msg = AdmUtils_helper::set_msg(array(0, 0));
         }
     }
     $this->response($msg);
 }
示例#2
0
 /**
  * Duplicate modules for another language
  * This method have to be arranged foe each website
  *
  * @return  array(array_of_installed_modules, res)
  */
 public function duplicate_modules_lang($id_area, $old_lang, $new_lang)
 {
     // this list have to be adapted for each website
     $modules = array('x3_banner' => null, 'x3_contacts' => null, 'x3_forms' => null, 'x3_fields' => array('x3_forms' => 'id_form'), 'x3_menu' => null, 'x3_news' => null, 'x3_news_pictures' => array('x3_news' => 'id_news'), 'x3_projects' => null, 'x3_projects_picture' => array('x3_projects' => 'id_project'), 'x3_slideshow' => null, 'x3_slideshow_items' => array('x3_slideshow' => 'id_slideshow'), 'x3_social' => null, 'x3_pro' => null, 'x3_tree' => array('x3_tree' => 'id_from'), 'x3_xpro' => array('x3_tree' => 'id_tree', 'x3_pro' => 'id_pro'));
     $no_lang = array('x3_xpro', 'x3_slideshow_items', 'x3_news_pictures', 'x3_projects_picture');
     $images = array('x3_banner' => array('img'), 'x3_news_pictures' => array('img', 'thumb'), 'x3_pro' => array('thumb', 'img1', 'img2', 'img3', 'img4', 'img5', 'img6', 'img7', 'img8'), 'x3_projects' => array('img1', 'img2', 'img3', 'img4', 'img5', 'img6', 'img7'), 'x3_projects_pictures' => array('img', 'thumb'), 'x3_slideshow_pictures' => array('img', 'thumb'), 'x3_tree' => array('img'));
     // those table are empty 'x3_menu_page', 'x3_xtree'
     $tables = array();
     $path = APATH . 'files/filemanager/img/';
     foreach ($modules as $k => $v) {
         echo 'MODULE = ' . $k . BR;
         if (is_null($v)) {
             // simple case
             // get data
             $items = $this->db->query('SELECT * FROM ' . $k . ' WHERE id_area = ' . intval($id_area) . ' AND lang = ' . $this->db->escape($old_lang) . ' ORDER BY id ASC');
             if ($items) {
                 foreach ($items as $i) {
                     $post = (array) $i;
                     // remove useless fields
                     unset($post['id'], $post['updated']);
                     // update
                     $post['lang'] = $new_lang;
                     // imges?
                     if (isset($images[$k])) {
                         foreach ($images[$k] as $ii) {
                             $file = X4Files_helper::get_final_name($path, $i->{$ii});
                             $chk = @copy($path . $i->{$ii}, $path . $file);
                             if ($chk) {
                                 $post[$ii] = $file;
                             }
                         }
                     }
                     // insert
                     $res = $this->insert($post, $k);
                     if ($res[1]) {
                         $table[$k][$i->id] = $res[0];
                     }
                 }
             }
         } else {
             // dependency case
             // get data
             if (in_array($k, $no_lang)) {
                 $items = $this->db->query('SELECT * FROM ' . $k . ' WHERE id_area = ' . intval($id_area) . ' ORDER BY id ASC');
             } else {
                 $items = $this->db->query('SELECT * FROM ' . $k . ' WHERE id_area = ' . intval($id_area) . ' AND lang = ' . $this->db->escape($old_lang) . ' ORDER BY id ASC');
             }
             if ($items) {
                 foreach ($items as $i) {
                     $post = (array) $i;
                     // remove useless fields
                     unset($post['id'], $post['updated']);
                     // update
                     if (!in_array($k, $no_lang)) {
                         $post['lang'] = $new_lang;
                     }
                     // relations
                     foreach ($v as $t => $f) {
                         if ($k == 'x3_tree' && $i->id_from == 0) {
                         } else {
                             $post[$f] = $table[$t][$i->{$f}];
                         }
                     }
                     // imges?
                     if (isset($images[$k])) {
                         foreach ($images[$k] as $ii) {
                             $file = X4Files_helper::get_final_name($path, $i->{$ii});
                             $chk = @copy($path . $i->{$ii}, $path . $file);
                             if ($chk) {
                                 $post[$ii] = $file;
                             }
                         }
                     }
                     // insert
                     $res = $this->insert($post, $k);
                     if ($res[1]) {
                         $table[$k][$i->id] = $res[0];
                     }
                 }
             }
         }
     }
     return 1;
 }
示例#3
0
 /**
  * Extract a frame from a remote video
  *
  * @param string	$video	the video
  * @param string	$image	the frame
  * @param array		$sizes	width and height to scale	
  * @return mixed
  */
 public static function remote_video_frame($video, $image, $sizes = array())
 {
     $frame = '';
     $image_url = parse_url($video);
     if ($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com') {
         $array = explode("&", $image_url['query']);
         $frame = 'http://img.youtube.com/vi/' . substr($array[0], 2) . '/0.jpg';
     } elseif ($image_url['host'] == 'youtu.be') {
         $path = explode('/', $image_url['path']);
         $frame = 'http://i.ytimg.com/vi/' . $path[1] . '/0.jpg';
     } elseif ($image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com') {
         $hash = unserialize(file_get_contents('http://vimeo.com/api/v2/video/' . substr($image_url['path'], 1) . '.php'));
         $frame = $hash[0]['thumbnail_large'];
     }
     if (!empty($frame)) {
         // we can extract a frame
         $ipath = APATH . 'files/filemanager/img/';
         // set the new name
         $final_name = self::get_final_name($ipath, $image);
         // copy remote file
         $chk = copy($frame, $ipath . $final_name);
         if ($chk && file_exists($ipath . $final_name)) {
             chmod($ipath . $final_name, 0777);
             $check = X4Files_helper::create_fit($ipath . $final_name, $ipath . $final_name, $sizes, true);
             return $final_name;
         }
         return '';
     }
 }