/** * Check if Single-User Mode is Enabled * * @access private * @internal * * @return 0/1 */ public static function check_single_user() { //-- $lock_file = (string) self::lock_file(); //-- $out = 0; //-- if (SmartFileSystem::file_or_link_exists($lock_file)) { //-- $lock_content = SmartFileSystem::read($lock_file); $chk_arr = explode("\n", trim($lock_content)); $tmp_time = Smart::format_number_dec(($chk_arr[1] - time()) / 60, 0, '.', ''); //-- if ($tmp_time <= 0) { $out = 1; // TOTAL LOCKED (if greater or equal than ZERO it only warns) ! } //end if //-- } //end if //-- return $out; //-- }
public function ftp_put($remotefile, $localfile, $mode = 1) { //-- if (!SmartFileSystem::file_or_link_exists($localfile)) { $this->error_msg = 'ERROR: PUT command failed // No such file or directory (or broken link): ' . $localfile; return false; } //end if //-- $fp = @fopen($localfile, "rb"); if (!$fp) { $this->error_msg = 'ERROR: PUT command failed // Cannot read file: ' . $localfile; return false; } //end if //-- if (!$this->_type($mode)) { $this->error_msg = 'ERROR: PUT command failed - TYPE: ' . $mode; @fclose($fp); return false; } //end if //-- if (!($string = $this->_pasv())) { $this->error_msg = 'ERROR: PUT command failed - PASSIVE'; @fclose($fp); return false; } //end if //-- $this->_putcmd("STOR", $remotefile); //-- $sock_data = $this->_open_data_connection($string); //-- if (!$sock_data) { $this->error_msg = 'ERROR: PUT // Cannot connect to remote host'; return false; } //end if //-- if (!$this->_ok()) { $this->error_msg = 'ERROR: PUT command failed (1)'; $this->_close_data_connection($sock_data); return false; } //end if //-- $this->_debug_print('OK: PUT // Connected to remote host' . "\n"); if ((string) $this->debug_level == 'full') { $this->_debug_print('Storing local file: ' . $localfile . ' to remote file: ' . $remotefile . "\n"); } //end if //-- while (!feof($fp)) { @fwrite($sock_data, @fread($fp, $this->_buf)); } //end while //-- @fclose($fp); //-- $this->_close_data_connection($sock_data); //-- $response = $this->_ok(); if (!$response) { $this->error_msg = 'ERROR: PUT command failed (2)'; return false; } //end if //-- return $response; //-- }
private function folder_iterator($recurring, $dir_name, $include_dot_files, $search_pattern = '', $search_prevent_file = '', $search_prevent_override = '') { //-- $recurring = (bool) $recurring; $dir_name = (string) $dir_name; $include_dot_files = (bool) $include_dot_files; $search_pattern = (string) $search_pattern; $search_prevent_file = (string) $search_prevent_file; $search_prevent_override = (string) $search_prevent_override; //-- if ((string) $dir_name == '') { Smart::log_warning('LibFileSys // ReadsFolderRecurring // Dir Name is Empty !'); return; // this function does not return anything, but just stop here in this case } //end if //-- fix invalid path (must end with /) $dir_name = SmartFileSysUtils::add_dir_last_slash($dir_name); //-- protection SmartFileSysUtils::raise_error_if_unsafe_path($dir_name); //-- @clearstatcache(); //-- $this->pattern_search_str = $search_pattern; $this->search_prevent_file = $search_prevent_file; $this->search_prevent_override = $search_prevent_override; //-- if (SmartFileSystem::file_or_link_exists($dir_name) and !is_file($dir_name)) { // can be dir or link //list //-- if ($handle = opendir($dir_name)) { //--------------------------------------- while (false !== ($file = readdir($handle))) { //-- if ((string) $file != '.' and (string) $file != '..') { //-- if ($include_dot_files or !$include_dot_files and substr($file, 0, 1) != '.') { //-- SmartFileSysUtils::raise_error_if_unsafe_path($dir_name . $file); //-- params to see if counted or added to pattern matches $tmp_allow_addition = 1; $tmp_add_pattern = 0; //-- this is for #private folders, will prevent searching in folders containing for example this file: .private-folder but can be overriden by the $search_prevent_override option exluding a particular path like folder/private/user1 if (strlen($search_prevent_file) > 0 and is_file($dir_name . $search_prevent_file)) { if (strlen($search_prevent_override) <= 0 or strlen($search_prevent_override) > 0 and !is_file($dir_name . $search_prevent_override)) { $tmp_allow_addition = 0; } //end if } //end if //-- this is a search pattern (search pattern does not apply to folders !!) ; if no empty will populate the pattern matches array with all files and folders matching ; to include all, use * or a particular search for the rest like myfile1 if ((string) $search_pattern == '' or is_dir($dir_name . $file)) { if ($tmp_allow_addition) { if ($this->list_files_and_dirs) { $tmp_add_pattern = 1; } //end if } //end if } else { if ($this->limit_search_files <= 0 or Smart::array_size($this->pattern_file_matches) < $this->limit_search_files) { if ((string) $search_pattern == '*' or (string) $search_pattern == '[image]' and (substr($file, -4, 4) == '.png' or substr($file, -4, 4) == '.gif' or substr($file, -4, 4) == '.jpg' or substr($file, -5, 5) == '.jpeg') or (string) $search_pattern != '*' and (string) $search_pattern != '[image]' and stripos($file, $search_pattern) !== false) { if ($tmp_allow_addition) { if ($this->list_files_and_dirs) { $tmp_add_pattern = 1; } //end if } //end if } else { $tmp_allow_addition = 0; } //end if else } //end if } //end if //-- if ($this->limit_search_files > 0) { // the dir should not be taken in count here if ($this->num_files + $this->num_links >= $this->limit_search_files) { break; } //end if } //end if //-- if (!is_link($dir_name . $file)) { //-- if (is_dir($dir_name . $file)) { //-- dir if ($tmp_allow_addition) { //-- $tmp_fsize = Smart::format_number_int(@filesize($dir_name . $file), '+'); //-- $this->num_dirs++; $this->num_size += $tmp_fsize; $this->num_dirs_size += $tmp_fsize; //-- $tmp_fsize = 0; //-- if ($tmp_add_pattern) { if ($recurring) { // if recurring, add the full path $this->pattern_dir_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_dir_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if //-- } //end if //-- if ($recurring) { //-- we go search inside even if this folder name may not match the search pattern, it is a folder, except if dissalow addition from above $this->folder_iterator($recurring, SmartFileSysUtils::add_dir_last_slash($dir_name . $file), $include_dot_files, $search_pattern, $search_prevent_file, $search_prevent_override); //-- } //end if //-- } else { //-- file if ($tmp_allow_addition) { //-- $tmp_fsize = Smart::format_number_int(@filesize($dir_name . $file), '+'); //-- $this->num_files++; $this->num_size += $tmp_fsize; $this->num_files_size += $tmp_fsize; //-- $tmp_fsize = 0; //-- if ($tmp_add_pattern) { if ($recurring) { // if recurring, add the full path $this->pattern_file_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_file_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if //-- } //end if //-- } //end else //-- } else { //-- link if ($tmp_allow_addition) { //-- $link_result = SmartFileSystem::link_get_origin($dir_name . $file); //-- if (empty($link_result) or (string) $link_result == '' or !SmartFileSystem::file_or_link_exists($link_result)) { //-- // case of readlink error ..., not includding broken links, they are useless //-- } else { //-- $tmp_size_arr = array(); $tmp_fsize = 0; //$tmp_size_arr = (array) @lstat($dir_name.$file); //$tmp_fsize = Smart::format_number_int($tmp_size_arr[7],'+'); // $tmp_size_arr[7] -> size, but may break compare if on a different file system or in distributed storage on various OS //-- $this->num_links++; //-- if (file_exists($dir_name . $file)) { // here file_exists must be tested because if broken link not stat on it (filemtime) to avoid log un-necessary errors //-- bugfix: not if broken link $this->num_size += $tmp_fsize; if ($tmp_add_pattern) { if (is_dir($dir_name . $file)) { $this->num_dirs++; $this->num_dirs_size += $tmp_fsize; if ($recurring) { // if recurring, add the full path $this->pattern_dir_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_dir_matches[$file] = @filemtime($dir_name . $file); } //end if else } else { $this->num_files++; $this->num_files_size += $tmp_fsize; if ($recurring) { // if recurring, add the full path $this->pattern_file_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_file_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if else } //end if //-- } //end if //-- $tmp_fsize = 0; $tmp_size_arr = array(); //-- } //end if else //-- } //end if //-- } //end if else //-- } //end if //-- } //end if(. ..) //-- } //end while //--------------------------------------- @closedir($handle); //--------------------------------------- } else { //--------------------------------------- $this->errors_arr[] = $dir_name; //--------------------------------------- } //end else //-- } else { //--------------------------------------- // nothing ... //--------------------------------------- } //end if else //-- }
public static function mov_pw_process($y_mov_file, $y_mov_img_preview, $y_quality, $y_width, $y_height, $y_watermark = '', $y_waterlocate = 'center', $y_mov_blank_img_preview = '') { //-- $y_mov_file = (string) trim((string) $y_mov_file); $y_mov_img_preview = (string) trim((string) $y_mov_img_preview); $y_mov_blank_img_preview = (string) trim((string) $y_mov_blank_img_preview); $y_watermark = (string) trim((string) $y_watermark); //-- //-- $blank_mov_pw = 'lib/core/plugins/img/mediagallery/video.jpg'; // this must be jpeg like the preview generated by ffmpeg //-- $watermark_mov_pw = 'lib/core/plugins/img/mediagallery/play.png'; //-- //-- if ((string) $y_mov_blank_img_preview == '') { $y_mov_blank_img_preview = $blank_mov_pw; } //end if //-- if (!SmartFileSysUtils::check_file_or_dir_name($y_mov_blank_img_preview)) { $y_mov_blank_img_preview = $blank_mov_pw; } //end if //-- if (!is_file($y_mov_blank_img_preview)) { Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // Invalid Blank Preview Path: BLANK-PREVIEW=' . $y_mov_blank_img_preview); return ''; } //end if //-- if ((string) $y_watermark == '') { $y_watermark = $watermark_mov_pw; } //end if //-- //-- if (!SmartFileSysUtils::check_file_or_dir_name($y_mov_file)) { Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // Unsafe Path: SRC=' . $y_mov_file); return ''; } //end if //-- if (!SmartFileSysUtils::check_file_or_dir_name($y_mov_img_preview)) { Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // Unsafe Path: DEST=' . $y_mov_img_preview); return ''; } //end if //-- if ((string) $y_mov_file == (string) $y_mov_img_preview) { Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // The Origin movie and Destination image are the same: SRC=' . $y_mov_file . ' ; DEST=' . $y_mov_img_preview); return ''; } //end if //-- if ((string) $y_watermark != '') { if (!SmartFileSysUtils::check_file_or_dir_name($y_watermark)) { $y_watermark = ''; Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // Unsafe Path: WATERMARK=' . $y_watermark); } //end if } //end if //-- //-- $y_quality = Smart::format_number_int($y_quality, '+'); if ($y_quality < 1) { $y_quality = 1; } //end if if ($y_quality > 100) { $y_quality = 100; } //end if //-- //-- $y_width = Smart::format_number_int($y_width, '+'); $y_height = Smart::format_number_int($y_height, '+'); //-- if ($y_width < 10) { $y_width = 10; } //end if if ($y_width > 240) { $y_width = 240; } //end if //-- if ($y_height < 10) { $y_height = 10; } //end if if ($y_height > 240) { $y_height = 240; } //end if //-- //-- {{{SYNC-GRAVITY}}} switch ((string) $y_waterlocate) { case 'northwest': $y_waterlocate = 'northwest'; break; case 'northeast': $y_waterlocate = 'northeast'; break; case 'southwest': $y_waterlocate = 'southwest'; break; case 'southeast': $y_waterlocate = 'southeast'; break; case 'center': default: $y_waterlocate = 'center'; } //end switch //-- //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { SmartFrameworkRegistry::setDebugMsg('extra', 'MEDIA-GALLERY', ['title' => '[INFO] :: MediaUTIL/Mov/Process-Preview', 'data' => "'" . SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER . "'" . ' :: ' . "'" . SMART_FRAMEWORK_MEDIAGALLERY_IMG_COMPOSITE . "'"]); } //end if //-- //-- $out = ''; //-- if (defined('SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER') and (string) SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER != '') { //-- $lock_file = $y_mov_img_preview . '.LOCK-MOV-MEDIAGALLERY'; $temporary_pw = $y_mov_img_preview . '.#tmp-preview#.jpg'; // {{{SYNC-MOV-TMP-PREVIEW}}} //-- $lock_time = Smart::format_number_int(SmartFileSystem::read($lock_file), '+'); //-- if ($lock_time > 0) { if ($lock_time + 45 < time()) { // allow max locktime of 45 seconds SmartFileSystem::delete($temporary_pw); // delete the old temporary if any SmartFileSystem::delete($lock_file); // release the lock file } //end if } //end if //-- if (is_file($y_mov_file) and !SmartFileSystem::file_or_link_exists($y_mov_img_preview) and !SmartFileSystem::file_or_link_exists($lock_file)) { //-- @chmod($y_mov_file, SMART_FRAMEWORK_CHMOD_FILES); //mark chmod //-- $out .= '<table width="550" bgcolor="#74B83F">'; $out .= '<tr><td>Processing Movie Preview:' . ' ' . "'" . Smart::escape_html(basename($y_mov_file)) . "'" . ' -> ' . "'" . Smart::escape_html(basename($y_mov_img_preview)) . "'" . '</td></tr>'; //-- create a lock file SmartFileSystem::write($lock_file, time()); //-- generate preview (jpeg) if (is_executable(SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER)) { // generate a max preview of 240x240 which will be later converted below $exec = SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER . ' -y -i ' . '"' . $y_mov_file . '"' . ' -s 240x240 -vframes 60 -f image2 -vcodec mjpeg -deinterlace ' . '"' . $temporary_pw . '"'; @exec($exec, $arr_result, $exitcode); } else { $arr_result = array('error' => 'IS NOT EXECUTABLE ...', 'movie-thumbnailer' => SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER); $exitcode = -1; } //end if //-- $is_ok_pw = 1; if (!is_file($temporary_pw)) { $is_ok_pw = 0; } elseif (@filesize($temporary_pw) <= 1444) { // detect if blank jpeg of 240x240 $is_ok_pw = 0; } //end if //-- if ($is_ok_pw != 1) { SmartFileSystem::delete($temporary_pw); SmartFileSystem::copy($y_mov_blank_img_preview, $temporary_pw); // in the case ffmpeg fails we avoid enter into a loop, or if ffmpeg is not found we use a blank preview } //end if //-- $out .= '<tr><td>[DONE]</td></tr>'; if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { SmartFrameworkRegistry::setDebugMsg('extra', 'MEDIA-GALLERY', ['title' => '[INFO] :: MediaUTIL/Mov/Process-Preview/FFMpeg', 'data' => 'Runtime Result: ' . "'" . $y_mov_file . "'" . ' -> ' . "'" . $y_mov_img_preview . "'" . ' = [' . $exitcode . '] @ ' . @print_r($arr_result, 1)]); } //end if //-- process and apply watermark if any if (is_file($temporary_pw)) { //-- @chmod($temporary_pw, SMART_FRAMEWORK_CHMOD_FILES); //mark chmod //-- self::img_process('preview', 'no', $temporary_pw, $y_mov_img_preview, $y_quality, $y_width, $y_height, $y_watermark, $y_waterlocate); //-- SmartFileSystem::delete($temporary_pw); //-- } //end if //-- release the lock file SmartFileSystem::delete($lock_file); //-- $out .= '</table>'; //-- } //end if //-- } //end if //-- //-- return $out; //-- }