예제 #1
0
/**
 * 获取附件文件URL
 * @param string $url
 * @param string $suffix
 * @param string $path
 */
function get_upfile_url($url, $suffix = '', $path = '')
{
    if (empty($url)) {
        return;
    }
    if (!empty($suffix)) {
        $info = pathInfo($url);
        $url = $info['dirname'] . '/' . $info['filename'] . '_' . $suffix . '.' . $info['extension'];
    }
    $tmpl = C('TMPL_PARSE_STRING');
    if (is_int($path)) {
        $path = $tmpl['__ALBUM' . $path . '__'];
    } elseif (empty($path)) {
        $search = array('__COMMON__', '__SD__', '__HD__', '__THEME__');
        $replace = array($tmpl['__COMMON__'], $tmpl['__SD__'], $tmpl['__HD__'], $tmpl['__THEME__']);
        foreach (C('ALBUM_TYPE') as $key => $v) {
            $search[] = 'album' . $key;
            $replace[] = 'album' . $tmpl[$key];
        }
        $url = str_replace($search, $replace, $url);
        if (substr($url, 0, 1) == '/' || substr($url, 0, 2) == './' || substr($url, 0, 3) == '../' || substr($url, 0, 7) == 'http://' || substr($url, 0, 8) == 'https://' || substr($url, 0, 6) == 'ftp://') {
            return $url;
        } else {
            $path = $tmpl['__UPFILE__'];
        }
    }
    if (substr($path, -1) != '/') {
        $path .= '/';
    }
    return $path . $url;
}
예제 #2
0
function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75)
{
    if (file_exists($src) && isset($dest)) {
        // path info
        $destInfo = pathInfo($dest);
        // image src size
        $srcSize = getImageSize($src);
        // image dest size $destSize[0] = width, $destSize[1] = height
        $srcRatio = $srcSize[0] / $srcSize[1];
        // width/height ratio
        $destRatio = $maxWidth / $maxHeight;
        if ($destRatio > $srcRatio) {
            $destSize[1] = $maxHeight;
            $destSize[0] = $maxHeight * $srcRatio;
        } else {
            $destSize[0] = $maxWidth;
            $destSize[1] = $maxWidth / $srcRatio;
        }
        // path rectification
        if ($destInfo['extension'] == "gif") {
            $dest = substr_replace($dest, 'jpg', -3);
        }
        // true color image, with anti-aliasing
        $destImage = imageCreateTrueColor($destSize[0], $destSize[1]);
        //       imageAntiAlias($destImage,true);
        // src image
        switch ($srcSize[2]) {
            case 1:
                //GIF
                $srcImage = imageCreateFromGif($src);
                break;
            case 2:
                //JPEG
                $srcImage = imageCreateFromJpeg($src);
                break;
            case 3:
                //PNG
                $srcImage = imageCreateFromPng($src);
                break;
            default:
                return false;
                break;
        }
        // resampling
        imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
        // generating image
        switch ($srcSize[2]) {
            case 1:
            case 2:
                imageJpeg($destImage, $dest, $quality);
                break;
            case 3:
                imagePng($destImage, $dest);
                break;
        }
        return true;
    } else {
        return 'No such File';
    }
}
 /**
  * 
  * get filename for thumbnail save / retrieve
  * TODO: do input validations - security measures
  */
 private function getThumbFilename()
 {
     $info = pathInfo($this->filename);
     //add dirname as postfix (if exists)
     $postfix = "";
     $dirname = UniteFunctionsRev::getVal($info, "dirname");
     if (!empty($dirname)) {
         $postfix = str_replace("/", "-", $dirname);
     }
     $ext = $info["extension"];
     $name = $info["filename"];
     $width = ceil($this->maxWidth);
     $height = ceil($this->maxHeight);
     $thumbFilename = $name . "_" . $width . "x" . $height;
     if (!empty($this->type)) {
         $thumbFilename .= "_" . $this->type;
     }
     if (!empty($this->effect)) {
         $thumbFilename .= "_e" . $this->effect;
         if (!empty($this->effect_arg1)) {
             $thumbFilename .= "x" . $this->effect_arg1;
         }
     }
     //add postfix
     if (!empty($postfix)) {
         $thumbFilename .= "_" . $postfix;
     }
     $thumbFilename .= "." . $ext;
     return $thumbFilename;
 }
예제 #4
0
파일: Image.php 프로젝트: karion/mydrinks
 /**
  * @param $name
  * @throws InvalidArgumentException
  */
 private function validateExtension($name)
 {
     $pathInfo = pathInfo($name);
     if (!array_key_exists('extension', $pathInfo)) {
         throw new InvalidArgumentException("Image extension can't be empty.");
     }
     if (!in_array($pathInfo['extension'], $this->availableExtensions)) {
         throw new InvalidArgumentException("Image needs to have jpeg extension.");
     }
 }
예제 #5
0
 /**
  * Zip a folder (including itself).
  * Usage:
  *   <code>HZip::zipDir('/path/to/sourceDir', '/path/to/out.zip');</code>
  *
  * @param string $sourcePath Path of directory to be zip.
  * @param string $outZipPath Path of output zip file.
  */
 public static function zipDir($sourcePath, $outZipPath)
 {
     $pathInfo = pathInfo($sourcePath);
     $parentPath = $pathInfo['dirname'];
     $dirName = $pathInfo['basename'];
     $z = new ZipArchive();
     $z->open($outZipPath, ZIPARCHIVE::CREATE);
     $z->addEmptyDir($dirName);
     self::folderToZip($sourcePath, $z, strlen($sourcePath) - strlen($dirName));
     $z->close();
 }
예제 #6
0
파일: config.php 프로젝트: visor/nano
 /**
  * @param string[] $args
  * @return void
  */
 public function run(array $args)
 {
     if (0 == count($args)) {
         $this->stop('Please pass new configuration name and it\'s parent(s)', 1);
     }
     if (1 == count($args)) {
         $this->stop('Please pass new configuration parent(s) or string NONE if no parents', 1);
     }
     $name = $args[0];
     $parents = $args;
     $base = $this->getApplication()->rootDir . DIRECTORY_SEPARATOR . 'settings';
     $new = $base . DIRECTORY_SEPARATOR . $name;
     array_shift($parents);
     if (file_exists($new)) {
         echo 'Using setup directory', PHP_EOL, "\t", $new, PHP_EOL;
     } else {
         echo 'Creating new setup directory', PHP_EOL, "\t", $new, PHP_EOL;
         mkDir($new, 0755, true);
     }
     if (in_array('NONE', $parents)) {
         echo "\t\t", 'no parents', PHP_EOL;
         $parents = array();
     } else {
         file_put_contents($new . DIRECTORY_SEPARATOR . \Nano\Application\Config\Builder::PARENTS_FILE, '<?php return ' . var_export($parents, true) . ';');
         echo "\t\t", \Nano\Application\Config\Builder::PARENTS_FILE, PHP_EOL;
     }
     foreach ($parents as $parent) {
         $i = new \DirectoryIterator($base . DIRECTORY_SEPARATOR . $parent);
         foreach ($i as $file) {
             if ($file->isDir() || $file->isDir() || !$file->isReadable()) {
                 continue;
             }
             if (\Nano\Application\Config\Builder::PARENTS_FILE === $file->getBaseName()) {
                 continue;
             }
             if (\Nano\Application\Config\Builder::ROUTES_FILE === $file->getBaseName()) {
                 continue;
             }
             if ('php' !== pathInfo($file->getBaseName(), PATHINFO_EXTENSION)) {
                 continue;
             }
             $newFile = $new . DIRECTORY_SEPARATOR . $file->getBaseName();
             if (file_exists($newFile)) {
                 continue;
             }
             file_put_contents($newFile, '<?php return array(' . PHP_EOL . ');');
             echo "\t\t", $file->getBaseName(), PHP_EOL;
         }
     }
     echo "\t\t", \Nano\Application\Config\Builder::ROUTES_FILE, PHP_EOL;
     file_put_contents($new . DIRECTORY_SEPARATOR . \Nano\Application\Config\Builder::ROUTES_FILE, '<?php' . PHP_EOL . PHP_EOL);
     echo 'Done', PHP_EOL;
 }
예제 #7
0
 /**
  * @param $path
  * @param $subjects
  * @param $namespace
  */
 private function iterate($path, $subjects, $namespace)
 {
     foreach ($subjects as $subject) {
         $pathInfo = pathInfo($subject);
         if (is_dir($subject)) {
             $this->searchDir($path . '/' . $pathInfo['basename'], $namespace . '\\' . $pathInfo['basename']);
         } else {
             if ($pathInfo['extension'] === 'php' && $pathInfo['filename'] !== 'BaseRoute') {
                 $this->routes[] = $namespace . '\\' . $pathInfo['filename'];
             }
         }
     }
 }
예제 #8
0
 public static function zip($sourcePath, $outZipPath, $isDirectory = true)
 {
     $pathInfo = pathInfo($sourcePath);
     $parentPath = $pathInfo['dirname'];
     $dirName = $pathInfo['basename'];
     $z = new ZipArchive();
     $z->open($outZipPath, ZIPARCHIVE::CREATE);
     if ($isDirectory) {
         $z->addEmptyDir($dirName);
         self::folderToZip($sourcePath, $z, strlen("{$parentPath}/"));
     } else {
         $z->addFile($sourcePath, $dirName);
     }
     return $z->close();
 }
예제 #9
0
 /**
  * @access public
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param string $src
  * @param string $dest
  * @param string $includeDir
  */
 public static function compressFolder($src, $dest, $includeDir = false)
 {
     $pathInfo = pathInfo($src);
     $parentPath = $pathInfo['dirname'];
     $dirName = $pathInfo['basename'];
     $z = new ZipArchive();
     $z->open($dest, ZipArchive::OVERWRITE);
     $exclusiveLength = strlen("{$src}/");
     if ($includeDir) {
         $z->addEmptyDir($dirName);
         $exclusiveLength = strlen("{$parentPath}/");
     }
     self::folderToZip($src, $z, $exclusiveLength);
     $z->close();
 }
예제 #10
0
파일: test.php 프로젝트: 156248605/cishop
 public function ckeup()
 {
     $targetFolder = '/public/uploads';
     $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
     $targetFile = $targetPath . '/' . $_FILES['upload']['name'];
     $fileTypes = array('jpg', 'jpeg', 'gif', 'png');
     $uploadFilename = $_FILES['upload']['name'];
     $extensions = pathInfo($uploadFilename, PATHINFO_EXTENSION);
     if (in_array($extensions, $fileTypes)) {
         move_uploaded_file($_FILES['upload']['tmp_name'], $targetFile);
         $previewname = $targetFile;
         $callback = $_REQUEST["CKEditorFuncNum"];
         echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$callback},'" . $previewname . "','');</script>";
         // Array ( [upload] => Array ( [name] => 123.png [type] => image/png [tmp_name] => F:\uploads\php41FF.tmp [error] => 0 [size] => 11857 ) )
     }
 }
예제 #11
0
 /**
  * 富文本的图片上传功能,基于ckedit
  * 配置路径在/public/packages/frozennode/administrator/js/ckedit/config.js
  */
 public function upload()
 {
     $extensions = array('jpg', 'bmp', 'gif', 'png');
     $uploadFilename = $_FILES['upload']['name'];
     $extension = pathInfo($uploadFilename, PATHINFO_EXTENSION);
     if (in_array($extension, $extensions)) {
         $uploadPath = public_path() . '/uploads/products/article/';
         $uuid = str_replace('.', '', uniqid("", TRUE)) . "." . $extension;
         $desname = $uploadPath . $uuid;
         $previewname = '/uploads/products/article/' . $uuid;
         $tag = move_uploaded_file($_FILES['upload']['tmp_name'], $desname);
         $callback = $_REQUEST["CKEditorFuncNum"];
         echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$callback},'" . $previewname . "','');</script>";
     } else {
         echo "<font color=\"red\"size=\"2\">*文件格式不正确(必须为.jpg/.gif/.bmp/.png文件)</font>";
     }
 }
예제 #12
0
파일: Dashboard.php 프로젝트: RCDawson/bhp
 public function init()
 {
     $Directory = new RecursiveDirectoryIterator(APPPATH . 'modules');
     $Iterator = new RecursiveIteratorIterator($Directory);
     $Models = new RegexIterator($Iterator, '/^.+\\_dashboard_model.php$/i', RecursiveRegexIterator::GET_MATCH);
     foreach ($Models as $k => $v) {
         $this->_modules[] = $k;
     }
     $this->_exceptions[] = '';
     // nothing at the moment...
     $this->_modules = array_diff($this->_modules, $this->_exceptions);
     foreach ($this->_modules as $k => $v) {
         $classname = pathInfo($v, PATHINFO_FILENAME);
         if (is_file($v)) {
             $this->CI->load->file($v);
         }
         $this->CI->load->file(FCPATH . APPPATH . '/modules/users/helpers/dashboard_helper.php');
         $class = new $classname();
     }
 }
예제 #13
0
파일: fix-spaces.php 프로젝트: visor/nano
 /**
  * @return void
  * @param string[] $args
  */
 public function run(array $args)
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getApplication()->rootDir), \RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $file) {
         /** @var \DirectoryIterator $file */
         if ($file->isDir()) {
             continue;
         }
         if ('php' != pathInfo($file->getBaseName(), PATHINFO_EXTENSION)) {
             continue;
         }
         $source = file_get_contents($file->getPathName());
         $result = $this->convertLineEnds($source);
         $result = $this->removeTrailingSpaces($result);
         $result = $this->convertIndentationSpaces($result);
         if ($source === $result) {
             continue;
         }
         file_put_contents($file->getPathName(), $result);
         echo $file->getPathName(), PHP_EOL;
     }
 }
예제 #14
0
 /**
  * Constructor
  * 
  * @param PHPRtfLite    $rtf
  * @param string        $imageFile image file incl. path
  * @param float         $width
  * @param flaot         $height
  */
 public function __construct(PHPRtfLite $rtf, $imageFile, PHPRtfLite_ParFormat $parFormat = null, $width = null, $height = null)
 {
     $this->_rtf = $rtf;
     $this->_parFormat = $parFormat;
     if (file_exists($imageFile)) {
         $this->_file = $imageFile;
         $pathInfo = pathInfo($imageFile);
         if (isset($pathInfo['extension'])) {
             $this->_extension = strtolower($pathInfo['extension']);
         }
         list($this->_defaultWidth, $this->_defaultHeight) = getimagesize($imageFile);
         if ($width !== null) {
             $this->setWidth($width);
         }
         if ($height !== null) {
             $this->setHeight($height);
         }
     } else {
         $this->_defaultWidth = 20;
         $this->_defaultHeight = 20;
         $this->_extension = 'png';
     }
 }
예제 #15
0
 /**
  * {@inheritDoc}
  */
 public function set($key, $value)
 {
     $pathInfo = pathInfo($this->cachedFile());
     $cacheDir = $pathInfo['dirname'];
     $fileName = $pathInfo['basename'];
     ErrorHandler::start();
     if (!is_dir($cacheDir)) {
         $umask = umask(0);
         mkdir($cacheDir, 0777, true);
         umask($umask);
         // @codeCoverageIgnoreStart
     }
     // @codeCoverageIgnoreEnd
     ErrorHandler::stop();
     if (!is_writable($cacheDir)) {
         throw new RuntimeException('Unable to write file ' . $this->cachedFile());
     }
     // Use "rename" to achieve atomic writes
     $tmpFilePath = $cacheDir . '/AssetManagerFilePathCache_' . $fileName;
     if (@file_put_contents($tmpFilePath, $value, LOCK_EX) === false) {
         throw new RuntimeException('Unable to write file ' . $this->cachedFile());
     }
     rename($tmpFilePath, $this->cachedFile());
 }
예제 #16
0
 public function saveImage($savePath, $imageQuality = "100")
 {
     // *** Perform a check or two.
     if (!is_resource($this->imageResized)) {
         if ($this->debug) {
             throw new Exception('saveImage: This is not a resource.');
         } else {
             throw new Exception();
         }
     }
     $fileInfoArray = pathInfo($savePath);
     clearstatcache();
     if (!is_writable($fileInfoArray['dirname'])) {
         if ($this->debug) {
             throw new Exception('The path is not writable. Please check your permissions.');
         } else {
             throw new Exception();
         }
     }
     // *** Get extension
     $extension = strrchr($savePath, '.');
     $extension = fix_strtolower($extension);
     $error = '';
     switch ($extension) {
         case '.jpg':
         case '.jpeg':
             $this->checkInterlaceImage($this->isInterlace);
             if (imagetypes() & IMG_JPG) {
                 imagejpeg($this->imageResized, $savePath, $imageQuality);
             } else {
                 $error = 'jpg';
             }
             break;
         case '.gif':
             $this->checkInterlaceImage($this->isInterlace);
             if (imagetypes() & IMG_GIF) {
                 imagegif($this->imageResized, $savePath);
             } else {
                 $error = 'gif';
             }
             break;
         case '.png':
             // *** Scale quality from 0-100 to 0-9
             $scaleQuality = round($imageQuality / 100 * 9);
             // *** Invert qualit setting as 0 is best, not 9
             $invertScaleQuality = 9 - $scaleQuality;
             $this->checkInterlaceImage($this->isInterlace);
             if (imagetypes() & IMG_PNG) {
                 imagepng($this->imageResized, $savePath, $invertScaleQuality);
             } else {
                 $error = 'png';
             }
             break;
         case '.bmp':
             file_put_contents($savePath, $this->GD2BMPstring($this->imageResized));
             break;
             // ... etc
         // ... etc
         default:
             // *** No extension - No save.
             $this->errorArray[] = 'This file type (' . $extension . ') is not supported. File not saved.';
             break;
     }
     //imagedestroy($this->imageResized);
     // *** Display error if a file type is not supported.
     if ($error != '') {
         $this->errorArray[] = $error . ' support is NOT enabled. File not saved.';
     }
 }
예제 #17
0
 /**
  * Get media file if it exists
  *
  * @param \GeorgRinger\News\Domain\Model\News $news
  * @param string $mediaFile
  * @return Boolean|\GeorgRinger\News\Domain\Model\Media
  */
 protected function getMediaIfAlreadyExists(\GeorgRinger\News\Domain\Model\News $news, $mediaFile)
 {
     $result = FALSE;
     $mediaItems = $news->getMedia();
     if (isset($mediaItems) && $mediaItems->count() !== 0) {
         foreach ($mediaItems as $mediaItem) {
             $pathInfoItem = pathinfo($mediaItem->getImage());
             $pathInfoMediaFile = pathInfo($mediaFile);
             if (GeneralUtility::isFirstPartOfStr($pathInfoItem['filename'], $pathInfoMediaFile['filename']) && $this->filesAreEqual(PATH_site . $mediaFile, PATH_site . self::UPLOAD_PATH . $mediaItem->getImage())) {
                 $result = $mediaItem;
                 break;
             }
         }
     }
     return $result;
 }
예제 #18
0
파일: core.php 프로젝트: slact/webylene-php
 private function loadClassesWithEvents()
 {
     $dir = ROOT . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR;
     foreach ((array) cf('classes with events') as $filename) {
         $filename = $dir . $filename . ".php";
         $filePath = pathInfo($filename);
         //php4 incompatibility
         $className = $filePath['filename'];
         if ($filePath['filename'] != 'core' && ($filePath['extension'] = 'php')) {
             if (!(include_once $filename)) {
                 echo "Class w/event load failed: {$className} : file {$filename} not found.";
                 return false;
             }
             if (!class_exists($className)) {
                 echo "Class w/event load failed: {$className}.php doesn't actually have said class declared.";
                 return false;
             } else {
                 $this->events->registerClassEventListeners($className);
             }
         }
     }
 }
 /**
  * Returns the file extension used for this resource
  *
  * @return string The file extension used for this file
  * @api
  */
 public function getFileExtension()
 {
     $pathInfo = pathInfo($this->filename);
     return isset($pathInfo['extension']) ? $pathInfo['extension'] : '';
 }
예제 #20
0
function mime_type_identify($file)
{
    $ext = strtolower(pathInfo($file, PATHINFO_EXTENSION));
    return isset($GLOBALS['_mime_type_extensions'][$ext]) ? $GLOBALS['_mime_type_extensions'][$ext] : 'binary/octet-stream';
}
예제 #21
0
 public static function zipFiles($files_dir, $destination_file)
 {
     if (!file_exists($files_dir) || file_exists($destination_file)) {
         return false;
     }
     $pathInfo = pathInfo($files_dir);
     $parentPath = $pathInfo['dirname'];
     $dirName = $pathInfo['basename'];
     $zip = new ZipArchive();
     $zip->open($destination_file, ZIPARCHIVE::CREATE);
     $zip->addEmptyDir($dirName);
     self::folderToZip($files_dir, $zip, strlen("{$parentPath}/"));
     if ($zip->close()) {
         return true;
     } else {
         return false;
     }
 }
 private function uploadImageLogo()
 {
     if (is_uploaded_file($this->request->data['UnifiedStore']['image_logo']['tmp_name'])) {
         $ext = pathInfo($this->request->data['UnifiedStore']['image_logo']['name'], PATHINFO_EXTENSION);
         $fileName = md5(time()) . "." . $ext;
         move_uploaded_file($this->request->data['UnifiedStore']['image_logo']['tmp_name'], TMP . "upload/" . $fileName);
         ImgServer::instance()->upload_unified_logo($fileName, TMP . "upload/" . $fileName);
         unlink(TMP . "upload/" . $fileName);
         $this->request->data['UnifiedStore']['image_logo'] = $fileName;
     }
 }
예제 #23
0
 private function _init()
 {
     // setting default skin
     if (!isset($this->skin) || $this->skin == "") {
         $this->skin = $this->skinDefault;
     }
     // deprecated submenu type ""green-submenu"" now is mapped to "submenu"
     if ($this->skin == "green-submenu") {
         $this->skin = "submenu";
     }
     if (!in_array(strtolower($this->skin), $this->skinVariants)) {
         $this->forceTemplateCompile = true;
         //Only save in session the main SKIN
         if (isset($_SESSION['currentSkin']) && $_SESSION['currentSkin'] != $this->skin) {
             $this->forceTemplateCompile = true;
         }
         $_SESSION['currentSkin'] = SYS_SKIN;
     } else {
         $_SESSION['currentSkin'] = SYS_SKIN;
         $_SESSION['currentSkinVariant'] = $this->skin;
     }
     // setting default skin
     if (!isset($_SESSION['currentSkin'])) {
         $_SESSION['currentSkin'] = $this->skinDefault;
     }
     $this->mainSkin = $_SESSION['currentSkin'];
     $skinObject = null;
     //Set defaults "classic"
     $configurationFile = $this->skinsBasePath . 'base' . PATH_SEP . 'config.xml';
     $layoutFile = $this->skinsBasePath . 'base' . PATH_SEP . 'layout.html';
     $layoutFileBlank = $this->skinsBasePath . 'base' . PATH_SEP . 'layout-blank.html';
     $layoutFileExtjs = $this->skinsBasePath . 'base' . PATH_SEP . 'layout-extjs.html';
     $layoutFileRaw = $this->skinsBasePath . 'base' . PATH_SEP . 'layout-raw.html';
     $layoutFileTracker = $this->skinsBasePath . 'base' . PATH_SEP . 'layout-tracker.html';
     $layoutFileSubmenu = $this->skinsBasePath . 'base' . PATH_SEP . 'layout-submenu.html';
     //Based on requested Skin look if there is any registered with that name
     if (strtolower($this->mainSkin) != "classic") {
         if (defined('PATH_CUSTOM_SKINS') && is_dir(PATH_CUSTOM_SKINS . $this->mainSkin)) {
             // check this skin on user skins path
             $skinObject = PATH_CUSTOM_SKINS . $this->mainSkin;
         } else {
             if (is_dir($this->skinsBasePath . $this->mainSkin)) {
                 // check this skin on core skins path
                 $skinObject = $this->skinsBasePath . $this->mainSkin;
             } else {
                 //Skin doesn't exist
                 $this->mainSkin = $this->skinDefault;
                 if (defined('PATH_CUSTOM_SKINS') && is_dir(PATH_CUSTOM_SKINS . $this->mainSkin)) {
                     // check this skin on user skins path
                     $skinObject = PATH_CUSTOM_SKINS . $this->mainSkin;
                 } else {
                     if (is_dir($this->skinsBasePath . $this->mainSkin)) {
                         // check this skin on core skins path
                         $skinObject = $this->skinsBasePath . $this->mainSkin;
                     }
                 }
             }
         }
     }
     //This should have an XML definition and a layout html
     if ($skinObject && file_exists($skinObject . PATH_SEP . 'config.xml') && file_exists($skinObject . PATH_SEP . 'layout.html')) {
         $configurationFile = $skinObject . PATH_SEP . 'config.xml';
         $layoutFile = $skinObject . PATH_SEP . 'layout.html';
         if (file_exists($skinObject . PATH_SEP . 'layout-blank.html')) {
             $layoutFileBlank = $skinObject . PATH_SEP . 'layout-blank.html';
         }
         if (file_exists($skinObject . PATH_SEP . 'layout-extjs.html')) {
             $layoutFileExtjs = $skinObject . PATH_SEP . 'layout-extjs.html';
         }
         if (file_exists($skinObject . PATH_SEP . 'layout-raw.html')) {
             $layoutFileRaw = $skinObject . PATH_SEP . 'layout-raw.html';
         }
         if (file_exists($skinObject . PATH_SEP . 'layout-tracker.html')) {
             $layoutFileTracker = $skinObject . PATH_SEP . 'layout-tracker.html';
         }
         if (file_exists($skinObject . PATH_SEP . 'layout-submenu.html')) {
             $layoutFileSubmenu = $skinObject . PATH_SEP . 'layout-submenu.html';
         }
     }
     $this->layoutFile = pathInfo($layoutFile);
     $this->layoutFileBlank = pathInfo($layoutFileBlank);
     $this->layoutFileExtjs = pathInfo($layoutFileExtjs);
     $this->layoutFileTracker = pathInfo($layoutFileTracker);
     $this->layoutFileRaw = pathInfo($layoutFileRaw);
     $this->layoutFileSubmenu = pathInfo($layoutFileSubmenu);
     $this->cssFileName = $this->mainSkin;
     if ($this->skin != $this->mainSkin && in_array(strtolower($this->skin), $this->skinVariants)) {
         $this->cssFileName .= "-" . $this->skin;
     }
 }
예제 #24
0
파일: Helper.php 프로젝트: frdl/webfan
 /**
  * Zip a folder (include itself).
  * Usage:
  *   MultipartCompress::zipDir('/path/to/sourceDir', '/path/to/out.zip');
  *
  * @param string $sourcePath Path of directory to be zip.
  * @param string $outZipPath Path of output zip file.
  */
 public static function zipDir($sourcePath, $outZipPath, $del = false, $delDir = false)
 {
     $pathInfo = pathInfo($sourcePath);
     $parentPath = $pathInfo['dirname'];
     $dirName = $pathInfo['basename'];
     $z = new \ZipArchive();
     $z->open($outZipPath, \ZipArchive::CREATE);
     $z->addEmptyDir($dirName);
     self::folderToZip($sourcePath, $z, strlen("{$parentPath}/"), $del);
     if (true === $delDir) {
         rmdir($sourcePath);
     }
     $z->close();
 }
예제 #25
0
 public function wrap($xsl,$xml)
 {/*{{{*/
     $fileInfo = pathInfo($xml);
     if('xml' == strtolower($fileInfo['extension']))
     {
         $this->xsl->load($xsl); 
         $this->processor ->importStyleSheet($this->xsl); 
         $this->xml->load($xml); 
         return  $this->processor->transformToXML($this->xml); 
     }
     return null;
 }/*}}}*/
function gs_ringtone_set($user, $src, $bellcore, $change_file = false, $file = null)
{
    if (!preg_match('/^[a-zA-Z\\d]+$/', $user)) {
        return new GsError('User must be alphanumeric.');
    }
    if (!in_array($src, array('internal', 'external'), true)) {
        return new GsError('Source must be internal|external.');
    }
    $bellcore = (int) $bellcore;
    if ($bellcore < 0 || $bellcore > 10) {
        return new GsError('Bellcore must be between 1 and 10 or 0 for silent.');
    }
    if (!$change_file) {
        $file = null;
    } else {
        if (!$file) {
            # to remove a custom ringer
            $file = null;
        } else {
            $file = @realPath($file);
            if (!@file_exists($file)) {
                $file = @realPath(@$_ENV['PWD'] . '/' . $file);
                if (!@file_exists($file)) {
                    return new GsError('File not found.');
                }
            }
            //if (strToLower(subStr($file,-4)) != '.mp3')
            //	return new GsError( 'File is not an mp3.' );
        }
    }
    # connect to db
    #
    $db = gs_db_master_connect();
    if (!$db) {
        return new GsError('Could not connect to database.');
    }
    # get user_id
    #
    $user_id = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\'');
    if (!$user_id) {
        return new GsError('Unknown user.');
    }
    # make sure there is an entry in the db and set the bellcore ringer
    #
    $num = (int) $db->executeGetOne('SELECT COUNT(*) `num` FROM `ringtones` WHERE `user_id`=' . $user_id . ' AND `src`=\'' . $src . '\'');
    if ($num < 1) {
        $ok = $db->execute('INSERT INTO `ringtones` (`user_id`, `src`, `bellcore`, `file`) VALUES (' . $user_id . ', \'' . $src . '\', ' . $bellcore . ', NULL)');
    } else {
        $ok = $db->execute('UPDATE `ringtones` SET `bellcore`=' . $bellcore . ' WHERE `user_id`=' . $user_id . ' AND `src`=\'' . $src . '\'');
    }
    if (!$ok) {
        return new GsError('DB error.');
    }
    if (!$change_file) {
        return true;
    }
    # are we the web server?
    #
    if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
        $our_host_ips = @gs_get_listen_to_ips();
        if (!is_array($our_host_ips)) {
            return new GsError('Failed to get our host IPs.');
        }
        $we_are_the_webserver = in_array(GS_PROV_HOST, $our_host_ips);
    } else {
        $we_are_the_webserver = true;
    }
    # remove old ringer from htdocs/prov/ringtones/ dir
    #
    if ($we_are_the_webserver) {
        # local
        @exec('sudo rm -rf ' . GS_DIR . 'htdocs/prov/ringtones/' . $user . '-' . subStr($src, 0, 3) . '-* 1>>/dev/null 2>>/dev/null');
    } else {
        # remotely
        $cmd = 'rm -rf /opt/gemeinschaft/htdocs/prov/ringtones/' . $user . '-' . subStr($src, 0, 3) . '-* 1>>/dev/null 2>>/dev/null &';
        @exec('sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa('root@' . GS_PROV_HOST) . ' ' . qsa($cmd) . ' 1>>/dev/null 2>>/dev/null');
    }
    # just remove custom ringer?
    #
    if (!$file) {
        $ok = $db->execute('UPDATE `ringtones` SET `file`=NULL WHERE `user_id`=' . $user_id . ' AND `src`=\'' . $src . '\'');
        if (!$ok) {
            return new GsError('DB error.');
        }
        return true;
    }
    # convert sound file to the formats needed for each phone type
    #
    $to_sox_format = array('alaw' => 'al', 'ulaw' => 'ul');
    $pinfo = pathInfo($file);
    //$base = $pinfo['basename'];
    $ext = strToLower(@$pinfo['extension']);
    if (array_key_exists($ext, $to_sox_format)) {
        $ext = $to_sox_format[$ext];
    }
    $rand = base_convert(rand(1296, 46655), 10, 36);
    # 100(36) - zzz(36)
    $tmpbase = '/tmp/gs-ring-' . $user . '-' . $rand;
    $infile = $tmpbase . '-in.' . $ext;
    $outbase = $tmpbase . '-out';
    $ok = @copy($file, $infile);
    @chmod($infile, 0666);
    if (!$ok) {
        return new GsError('Failed to copy file to "' . $infile . '".');
    }
    include_once GS_DIR . 'inc/phone-capability.php';
    $phone_types = glob(GS_DIR . 'htdocs/prov/*/capability.php');
    if (!is_array($phone_types)) {
        $phone_types = array();
    }
    for ($i = 0; $i < count($phone_types); ++$i) {
        $phone_types[$i] = baseName(dirName($phone_types[$i]));
    }
    gs_log(GS_LOG_DEBUG, 'Ringtone conversion: Found phone types: ' . implode(', ', $phone_types));
    $errors = array();
    $new_ringer_basename = $user . '-' . subStr($src, 0, 3) . '-' . $rand;
    foreach ($phone_types as $phone_type) {
        include_once GS_DIR . 'htdocs/prov/' . $phone_type . '/capability.php';
        $class = 'PhoneCapability_' . $phone_type;
        if (!class_exists($class)) {
            gs_log(GS_LOG_WARNING, $phone_type . ': Class broken.');
            $errors[] = $phone_type . ': Class broken.';
            continue;
        }
        $PhoneCapa = new $class();
        $outfile = $PhoneCapa->conv_ringtone($infile, $outbase);
        if (isGsError($outfile)) {
            gs_log(GS_LOG_WARNING, 'Ringtone conversion: ' . $phone_type . ': ' . $outfile->getMsg());
            $errors[] = $phone_type . ': ' . $outfile->getMsg();
        } elseif ($outfile === null) {
            gs_log(GS_LOG_DEBUG, 'Ringtone conversion: ' . $phone_type . ': Not implemented.');
            continue;
        } elseif (!$outfile) {
            gs_log(GS_LOG_WARNING, 'Ringtone conversion: ' . $phone_type . ': Failed to convert file.');
            $errors[] = $phone_type . ': ' . 'Failed to convert file.';
            continue;
        }
        if (!file_exists($outfile)) {
            gs_log(GS_LOG_WARNING, 'Ringtone conversion: ' . $phone_type . ': Failed to convert file.');
            $errors[] = $phone_type . ': ' . 'Failed to convert file.';
            continue;
        }
        gs_log(GS_LOG_DEBUG, 'Ringtone conversion: ' . $phone_type . ': Converted.');
        @chmod($outfile, 0666);
        $pinfo = pathInfo($outfile);
        $ext = strToLower(@$pinfo['extension']);
        $newbase = $new_ringer_basename . '-' . $phone_type . '.' . $ext;
        if ($phone_type === 'siemens' && !gs_get_conf('GS_SIEMENS_PROV_PREFER_HTTP')) {
            # if this is a Siemens phone, push the file on the FTP server
            @copy($infile, '/tmp/' . $newbase);
            //FIXME - why?
            $ok = $PhoneCapa->_upload_ringtone('/tmp/' . $newbase);
            if (!$ok) {
                gs_log(GS_LOG_WARNING, 'Failed to upload ringtone to FTP server.');
            }
            if (is_file('/tmp/' . $newbase)) {
                @unlink('/tmp/' . $newbase);
            }
        } else {
            if ($we_are_the_webserver) {
                # local
                //rename( $outfile, GS_DIR .'htdocs/prov/ringtones/'. $newbase );
                @exec('sudo mv ' . qsa($outfile) . ' ' . qsa(GS_DIR . 'htdocs/prov/ringtones/' . $newbase), $out, $err);
            } else {
                # remotely
                @exec('sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($outfile) . ' ' . qsa('root@' . GS_PROV_HOST . ':/opt/gemeinschaft/htdocs/prov/ringtones/' . $newbase) . ' >>/dev/null 2>>/dev/null', $out, $err);
                //@exec( 'sudo rm -f '. qsa($outfile) .' >>/dev/null 2>&1' );
                @unlink($outfile);
            }
            if ($err != 0) {
                gs_log(GS_LOG_WARNING, 'Failed to mv ringtone.');
            }
        }
    }
    if (is_file($infile)) {
        @unlink($infile);
    }
    @exec('rm -rf ' . $tmpbase . '-* 1>>/dev/null 2>>/dev/null &');
    if (count($errors) > 0) {
        return new GsError("Failed to convert ringtone for some or all phone types: " . implode(", ", $errors));
    }
    $ok = $db->execute('UPDATE `ringtones` SET `file`=\'' . $db->escape($new_ringer_basename) . '\' WHERE `user_id`=' . $user_id . ' AND `src`=\'' . $src . '\'');
    if (!$ok) {
        return new GsError('DB error.');
    }
    return true;
    // OLD STUFF:
    /*
    # remove old ringer
    #
    $files = @glob( GS_DIR .'htdocs/prov/ringtones/'. $user .'/'. $src .'-*' );
    if (is_array($files)) {
    	foreach ($files as $f) {
    		unlink();
    	}
    }
    die();
    
    
    shell_exec( 'rm -f /opt/ast/htdocs/prov/ringtones/'. $ext .'-*' );
    
    # get SIP name
    #
    $ext = $db->executeGetOne( 'SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`='. $user_id );
    if (! $ext)
    	return new GsError( 'DB error.' );
    
    
    if ($file) {
    	
    	$rand = rand(10000,99999).time();
    	
    	shell_exec( 'mpg123 -m -r 8000 -w - -n 500 -q \''. $file .'\' > \'/opt/gemeinschaft/htdocs/prov/ringtones/'. $rand .'.wav\'' );
    	shell_exec( 'sox \'/opt/gemeinschaft/htdocs/prov/ringtones/'. $rand .'.wav\' -r 8000 -c 1 -w \'/opt/gemeinschaft/htdocs/prov/ringtones/'. $ext .'-'. time() .'.wav\'' );
    	shell_exec( 'rm \'/opt/gemeinschaft/htdocs/prov/ringtones/'. $rand .'.wav\'' );
    	
    } else {
    	//shell_exec( 'rm -f /opt/gemeinschaft/htdocs/prov/ringtones/'. $ext .'-*' );
    }
    
    return true;
    */
}
예제 #27
0
 /**
  * Creates a magic image
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $imageFileObject: the original image file
  * @param array $fileConfiguration (width, height, maxW, maxH)
  * @param string $targetFolderCombinedIdentifier: target folder combined identifier
  * @return \TYPO3\CMS\Core\Resource\FileInterface
  */
 public function createMagicImage(\TYPO3\CMS\Core\Resource\FileInterface $imageFileObject, array $fileConfiguration, $targetFolderCombinedIdentifier)
 {
     $magicImage = NULL;
     // Get file for processing
     $imageFilePath = $imageFileObject->getForLocalProcessing(TRUE);
     // Process dimensions
     $maxWidth = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fileConfiguration['width'], 0, $fileConfiguration['maxW']);
     $maxHeight = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fileConfiguration['height'], 0, $fileConfiguration['maxH']);
     if (!$maxWidth) {
         $maxWidth = $fileConfiguration['maxW'];
     }
     if (!$maxHeight) {
         $maxHeight = $fileConfiguration['maxH'];
     }
     // Create the magic image
     $magicImageInfo = $this->getImageObject()->imageMagickConvert($imageFilePath, 'WEB', $maxWidth . 'm', $maxHeight . 'm');
     if ($magicImageInfo[3]) {
         $targetFileName = 'RTEmagicC_' . pathInfo($imageFileObject->getName(), PATHINFO_FILENAME) . '.' . pathinfo($magicImageInfo[3], PATHINFO_EXTENSION);
         $magicFolder = $this->getMagicFolder($targetFolderCombinedIdentifier);
         if ($magicFolder instanceof \TYPO3\CMS\Core\Resource\Folder) {
             $magicImage = $magicFolder->addFile($magicImageInfo[3], $targetFileName, 'changeName');
         }
     }
     return $magicImage;
 }
예제 #28
0
 private function _doesntHasAlphaLayer($path)
 {
     if (file_exists($path)) {
         $pathInfo = pathInfo($path);
         if ($pathInfo['extension'] != 'png') {
             return false;
         }
         $firstChars = $this->_getFileSystem()->openFile($path)->read(26);
         $char = $firstChars[25];
         $pngType = ord($char);
     }
     if ($pngType == 6) {
         return false;
     } else {
         return true;
     }
 }
예제 #29
0
파일: s3.php 프로젝트: mariakhair/bootstrap
 /**
  * Get MIME type for file
  *
  * @internal Used to get mime types
  * @param string &$file File path
  * @return string
  */
 public static function __getMimeType(&$file)
 {
     $type = false;
     // Fileinfo documentation says fileinfo_open() will use the
     // MAGIC env var for the magic file
     if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) && ($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC'])) !== false) {
         if (($type = finfo_file($finfo, $file)) !== false) {
             // Remove the charset and grab the last content-type
             $type = explode(' ', str_replace('; charset=', ';charset=', $type));
             $type = array_pop($type);
             $type = explode(';', $type);
             $type = trim(array_shift($type));
         }
         finfo_close($finfo);
         // If anyone is still using mime_content_type()
     } elseif (function_exists('mime_content_type')) {
         $type = trim(mime_content_type($file));
     }
     if ($type !== false && strlen($type) > 0) {
         return $type;
     }
     // Otherwise do it the old fashioned way
     static $exts = array('jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon', 'swf' => 'application/x-shockwave-flash', 'pdf' => 'application/pdf', 'zip' => 'application/zip', 'gz' => 'application/x-gzip', 'tar' => 'application/x-tar', 'bz' => 'application/x-bzip', 'bz2' => 'application/x-bzip2', 'txt' => 'text/plain', 'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', 'css' => 'text/css', 'js' => 'text/javascript', 'xml' => 'text/xml', 'xsl' => 'application/xsl+xml', 'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', 'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php');
     $ext = strtolower(pathInfo($file, PATHINFO_EXTENSION));
     return isset($exts[$ext]) ? $exts[$ext] : 'application/octet-stream';
 }
예제 #30
0
 /**
  * Get MIME type for file
  *
  * To override the putObject() Content-Type, add it to $requestHeaders
  *
  * To use fileinfo, ensure the MAGIC environment variable is set
  *
  * @internal Used to get mime types
  * @param string &$file File path
  * @return string
  */
 private static function __getMIMEType(&$file)
 {
     $type = false;
     // Fileinfo documentation says fileinfo_open() will use the
     // MAGIC env var for the magic file
     if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) && ($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC'])) !== false) {
         if (($type = finfo_file($finfo, $file)) !== false) {
             // Remove the charset and grab the last content-type
             $type = explode(' ', str_replace('; charset=', ';charset=', $type));
             $type = array_pop($type);
             $type = explode(';', $type);
             $type = trim(array_shift($type));
         }
         finfo_close($finfo);
         // If anyone is still using mime_content_type()
     } elseif (function_exists('mime_content_type')) {
         $type = trim(mime_content_type($file));
     }
     if ($type !== false && strlen($type) > 0) {
         return $type;
     }
     // Otherwise do it the old fashioned way
     global $mimes;
     $ext = strtolower(pathInfo($file, PATHINFO_EXTENSION));
     if ($ext == 'png') {
         return 'image/png';
     }
     $mime_type = isset($mimes[$ext]) ? $mimes[$ext] : 'application/octet-stream';
     if (is_array($mime_type)) {
         $mime_type = end($mime_type);
     }
     return $mime_type;
 }