protected function check_file_ext($file_name, $extensions) { if (defined('STRICT_TYPES') && CAMEL_CASE == '1') { return (bool) self::parameters(['file_name' => DT::STRING, 'extensions' => [DT::STRING, DT::TYPE_ARRAY]])->call(__FUNCTION__)->with($file_name, $extensions)->returning(DT::BOOL); } else { return (bool) check_file_ext($file_name, $extensions); } }
function get_theme_data($themename) { global $zbp; global $usersdir; $dir = $usersdir . 'theme/' . $themename . '/include/'; $return = array(); if (!is_dir($dir)) { mkdir($dir); } $dir_handle = opendir($dir); while (false !== ($filename = readdir($dir_handle))) { if (!is_file($dir . $filename) || $filename == 'index.html') { continue; } if (!$zbp->Config('tpluginmaker_' . $themename)->HasKey($filename)) { $zbp->Config('tpluginmaker_' . $themename)->{$filename} = ''; } $return[] = array("name" => TPLUGINMAKER_IS_WINDOWS ? iconv('GBK', 'UTF-8', $filename) : $filename, "value" => $zbp->Config('tpluginmaker_' . $themename)->{$filename}, "type" => check_file_ext($filename)); } $zbp->SaveConfig('tpluginmaker_' . $themename); return $return; }
function remove_file_obj($path = '', $rec = true) { /* Remove dir or folder $path - path to deleting folder with element $rec - recursive delete folder Return code true - Sucsess deleting Some string - Can`t delete this element -1 - File extension is not suported 0 - File is no deleted 1 - Not standart type (Dir or File) or dir not empty and recursive = false 2 - Write protect 3 - Bad names (empty name or "." or "..") 4 - Deleting not enabled in config 11 - non-exist file or directory */ global $CFG; if ($CFG->allowDelete === true) { $thumb_enabled = false; if (!empty($CFG->thumbDirName) && intval($CFG->thumbWidth) > 0 && intval($CFG->thumbHeight) > 0) { $thumb_enabled = true; } $path = realpath($CFG->imgUploadDir . $path); if (!file_exists($path)) { return 11; } if (is_subdir($CFG->imgUploadDir, $path) === false) { return 3; } $dst_type = is_file($path) ? 'file' : (is_dir($path) ? 'folder' : 'unknown'); $dst_path = substr(fix_path($path), 0, -1); $dst_path = $dst_type === 'file' ? dirname($dst_path) : $path; if ($thumb_enabled) { // Destination of thumbnail files $thumb_path = str_replace(dirname($path), dirname($path) . DIRECTORY_SEPARATOR . $CFG->thumbDirName, $path); } if (!empty($path) && $path !== '.' && $path !== '..') { // Check the premission if (is_writable($dst_path)) { if ($dst_type === 'folder' && ($rec || folder_is_empty($path))) { if (true === ($result = u_remove($path))) { if ($thumb_enabled && file_exists($thumb_path)) { // Remove thumbnail directory $result = u_remove($thumb_path); } if ($result === true) { return true; } } return $result; } else { if ($dst_type === 'file') { if (check_file_ext($path) === true && true === ($result = u_remove($path))) { if ($thumb_enabled && file_exists($thumb_path)) { // Remove thumbnail file $result = u_remove($thumb_path); } if ($result === true) { return true; } return $result; } else { if (check_file_ext($path) !== true) { return -1; } } return 0; } } return 1; } return 2; } return 3; } return 4; }