Example #1
1
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $remoteFilename = 'http://get.insight.sensiolabs.com/insight.phar';
     $localFilename = $_SERVER['argv'][0];
     $tempFilename = basename($localFilename, '.phar') . '-temp.phar';
     try {
         copy($remoteFilename, $tempFilename);
         if (md5_file($localFilename) == md5_file($tempFilename)) {
             $output->writeln('<info>insight is already up to date.</info>');
             unlink($tempFilename);
             return;
         }
         chmod($tempFilename, 0777 & ~umask());
         // test the phar validity
         $phar = new \Phar($tempFilename);
         // free the variable to unlock the file
         unset($phar);
         rename($tempFilename, $localFilename);
         $output->writeln('<info>insight updated.</info>');
     } catch (\Exception $e) {
         if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
             throw $e;
         }
         unlink($tempFilename);
         $output->writeln('<error>The download is corrupt (' . $e->getMessage() . ').</error>');
         $output->writeln('<error>Please re-run the self-update command to try again.</error>');
     }
 }
Example #2
0
 public function generate($pages)
 {
     $out = $this->path;
     $path = APP_DIR . "/src/Data/themes/{$this->theme}";
     // The theme path
     if ($this->delete == 1) {
         $this->log("Emptying Output Directory");
         /**
          * Empty the Output Dir just in case
          */
         $this->recursiveRemoveDirectory($out);
         $this->log("Finished Emptying Output Directory");
     }
     if ($this->init) {
         /* Start copying the theme contents to output directory */
         $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($objects as $location => $object) {
             $name = str_replace("{$path}/", "", $location);
             // Make into relative path
             $outLoc = "{$out}/{$name}";
             if ($object->isFile() && $name != "layout.html" && $name != "thumbnail.png" && $name != "example.html") {
                 $this->log("Copying {$name} to Ouput Directory");
                 copy($location, $outLoc);
             } elseif ($object->isDir() && !file_exists($outLoc)) {
                 /* Make sub directories on output folder */
                 mkdir($outLoc);
             }
         }
         /* Start creating pages */
         $layout = "{$path}/layout.html";
         foreach ($pages as $page) {
             $this->page($page['slug'], array("{{page-title}}" => $page['title'], "{{page-content}}" => $page['body']));
         }
     }
 }
Example #3
0
 /**
  * Activate plugin action
  */
 function activate()
 {
     if (!$this->locked() && !@copy(W3TC_INSTALL_FILE_OBJECT_CACHE, W3TC_ADDIN_FILE_OBJECT_CACHE)) {
         w3_writable_error(W3TC_ADDIN_FILE_OBJECT_CACHE);
     }
     $this->schedule();
 }
Example #4
0
 /**
  *  fetch image from protected location and manipulate it and copy to public folder to show in front-end
  *  This function cache the fetched image with same width and height before
  * 
  * @author A.Jafaripur <*****@*****.**>
  * 
  * @param integer $id image id number to seprate the folder in public folder
  * @param string $path original image path
  * @param float $width width of image for resize
  * @param float $heigh height of image for resize
  * @param integer $quality quality of output image
  * @return string fetched image url
  */
 public function getImage($id, $path, $width, $heigh, $quality = 70)
 {
     $fileName = $this->getFileName(Yii::getAlias($path));
     $fileNameWithoutExt = $this->getFileNameWithoutExtension($fileName);
     $ext = $this->getFileExtension($fileName);
     if ($width == 0 && $heigh == 0) {
         $size = Image::getImagine()->open($path)->getSize();
         $width = $size->getWidth();
         $heigh = $size->getHeight();
     }
     $newFileName = $fileNameWithoutExt . 'x' . $width . 'w' . $heigh . 'h' . '.' . $ext;
     $upload_number = (int) ($id / 2000) + 1;
     $savePath = Yii::getAlias('@webroot/images/' . $upload_number);
     $baseImageUrl = Yii::$app->getRequest()->getBaseUrl() . '/images/' . $upload_number;
     FileHelper::createDirectory($savePath);
     $savePath .= DIRECTORY_SEPARATOR . $newFileName;
     if ($width == 0 && $heigh == 0) {
         copy($path, $savePath);
     } else {
         if (!file_exists($savePath)) {
             Image::thumbnail($path, $width, $heigh)->interlace(\Imagine\Image\ImageInterface::INTERLACE_PLANE)->save($savePath, ['quality' => $quality]);
         }
     }
     return $baseImageUrl . '/' . $newFileName;
 }
 /**
  * Creates an Image object from a file using a mock resource (in order to avoid a database resource pointer entry)
  * @param string $imagePathAndFilename
  * @return \TYPO3\Flow\Resource\Resource
  */
 protected function getMockResourceByImagePath($imagePathAndFilename)
 {
     $imagePathAndFilename = \TYPO3\Flow\Utility\Files::getUnixStylePath($imagePathAndFilename);
     $hash = sha1_file($imagePathAndFilename);
     copy($imagePathAndFilename, 'resource://' . $hash);
     return $mockResource = $this->createMockResourceAndPointerFromHash($hash);
 }
Example #6
0
 public static function copyr($source, $dest)
 {
     // recursive function to copy
     // all subdirectories and contents:
     if (is_dir($source)) {
         $dir_handle = opendir($source);
         $sourcefolder = basename($source);
         if (!is_dir($dest . "/" . $sourcefolder)) {
             mkdir($dest . "/" . $sourcefolder);
         }
         while ($file = readdir($dir_handle)) {
             if ($file != "." && $file != "..") {
                 if (is_dir($source . "/" . $file)) {
                     self::copyr($source . "/" . $file, $dest . "/" . $sourcefolder);
                 } else {
                     copy($source . "/" . $file, $dest . "/" . $file);
                 }
             }
         }
         closedir($dir_handle);
     } else {
         // can also handle simple copy commands
         copy($source, $dest);
     }
 }
Example #7
0
 /**
  * @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
  *
  * @param string $documentTemplate The fully qualified template filename.
  * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
  * @throws \PhpOffice\PhpWord\Exception\CopyFileException
  */
 public function __construct($documentTemplate)
 {
     // Temporary document filename initialization
     $this->temporaryDocumentFilename = tempnam(Settings::getTempDir(), 'PhpWord');
     if (false === $this->temporaryDocumentFilename) {
         throw new CreateTemporaryFileException();
     }
     // Template file cloning
     if (false === copy($documentTemplate, $this->temporaryDocumentFilename)) {
         throw new CopyFileException($documentTemplate, $this->temporaryDocumentFilename);
     }
     // Temporary document content extraction
     $this->zipClass = new ZipArchive();
     $this->zipClass->open($this->temporaryDocumentFilename);
     $index = 1;
     while ($this->zipClass->locateName($this->getHeaderName($index)) !== false) {
         $this->temporaryDocumentHeaders[$index] = $this->zipClass->getFromName($this->getHeaderName($index));
         $index++;
     }
     $index = 1;
     while ($this->zipClass->locateName($this->getFooterName($index)) !== false) {
         $this->temporaryDocumentFooters[$index] = $this->zipClass->getFromName($this->getFooterName($index));
         $index++;
     }
     $this->temporaryDocumentMainPart = $this->zipClass->getFromName('word/document.xml');
 }
 /**
  * Uploads and unpacks a file
  * @return boolean True on success, False on error
  */
 function upload($uploadfile)
 {
     if (substr(strtolower($this->_realname), -4) != ".xml") {
         if (!$this->extractArchive($uploadfile)) {
             $this->error = JText::_('AUP_EXTRACT_ERROR');
             JError::raiseWarning(0, $this->error);
             return false;
         }
     }
     if (!is_array($this->_uploadfile)) {
         if (!@copy($this->_uploadfile, $this->_plugindir . DS . $this->_realname)) {
             $this->errno = 2;
             $this->error = JText::_('AUP_FILEUPLOAD_ERROR');
             JError::raiseWarning(0, $this->error);
             return false;
         } else {
             $file = $this->_foldername . DS . $this->_realname;
         }
     } else {
         $file = array();
         $i = 0;
         foreach ($this->_uploadfile as $_file) {
             if (!@copy($this->_unpackdir . DS . $_file, $this->_plugindir . DS . $_file)) {
                 $this->errno = 2;
                 $this->error = JText::_('AUP_FILEUPLOAD_ERROR');
                 JError::raiseWarning(0, $this->error);
                 return false;
             }
             $file[$i] = $this->_foldername . DS . $_file;
             $i++;
         }
     }
     return $file;
 }
Example #9
0
 private function convert_file($source, $dest)
 {
     // Узнаем какая кодировка у файла
     $teststring = file_get_contents($source, null, null, null, 1000000);
     // Кодировка - UTF8
     if (preg_match('//u', $teststring)) {
         // Просто копируем файл
         return copy($source, $dest);
     } else {
         // Конвертируем в UFT8
         if (!($src = fopen($source, "r"))) {
             return false;
         }
         if (!($dst = fopen($dest, "w"))) {
             return false;
         }
         while (($line = fgets($src, 4096)) !== false) {
             $line = $this->win_to_utf($line);
             fwrite($dst, $line);
         }
         fclose($src);
         fclose($dst);
         return true;
     }
 }
Example #10
0
/**
 * Generate a cached thumbnail for object lists (eg. carrier, order states...etc)
 *
 * @param string $image Real image filename
 * @param string $cacheImage Cached filename
 * @param integer $size Desired size
 */
function cacheImage($image, $cacheImage, $size, $imageType = 'jpg')
{
    if (file_exists($image)) {
        if (!file_exists(_PS_TMP_IMG_DIR_ . $cacheImage)) {
            $imageGd = $imageType == 'gif' ? imagecreatefromgif($image) : imagecreatefromjpeg($image);
            $x = imagesx($imageGd);
            $y = imagesy($imageGd);
            /* Size is already ok */
            if ($y < $size) {
                copy($image, _PS_TMP_IMG_DIR_ . $cacheImage);
            } else {
                $ratioX = $x / ($y / $size);
                $newImage = $imageType == 'gif' ? imagecreate($ratioX, $size) : imagecreatetruecolor($ratioX, $size);
                /* Allow to keep nice look even if resized */
                $white = imagecolorallocate($newImage, 255, 255, 255);
                imagefill($newImage, 0, 0, $white);
                imagecopyresampled($newImage, $imageGd, 0, 0, 0, 0, $ratioX, $size, $x, $y);
                imagecolortransparent($newImage, $white);
                /* Quality alteration and image creation */
                if ($imageType == 'gif') {
                    imagegif($newImage, _PS_TMP_IMG_DIR_ . $cacheImage);
                } else {
                    imagejpeg($newImage, _PS_TMP_IMG_DIR_ . $cacheImage, 86);
                }
            }
        }
        return '<img src="../img/tmp/' . $cacheImage . '" alt="" class="imgm" />';
    }
    return '';
}
Example #11
0
 function save_page($page)
 {
     $file_content = "";
     // set content
     foreach ($page as $key => $value) {
         if ($value) {
             if ($key == 'slug') {
                 $file_content .= "{: " . $key . " :} " . strtolower(url_title($value)) . "\n";
             } else {
                 $file_content .= "{: " . $key . " :} " . $value . "\n";
             }
         }
     }
     // if it is placed as subpage
     if (!empty($page['parent'])) {
         // if parent still as standalone file (not in folder)
         if (file_exists(PAGE_FOLDER . $page['parent'] . '.md')) {
             // create folder and move the parent inside
             mkdir(PAGE_FOLDER . $page['parent'], 0775);
             rename(PAGE_FOLDER . $page['parent'] . '.md', PAGE_FOLDER . $page['parent'] . '/index.md');
             // create index.html file
             copy(PAGE_FOLDER . 'index.html', PAGE_FOLDER . $page['parent'] . '/index.html');
         }
     }
     if (write_file(PAGE_FOLDER . $page['parent'] . '/' . $page['slug'] . '.md', $file_content)) {
         $this->pusaka->sync_page();
         return true;
     } else {
         return false;
     }
 }
Example #12
0
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-7-11
 * Time: 上午10:40
 */
function copyDir($dirSrc, $dirTo)
{
    if (is_file($dirTo)) {
        //如果目标不是一个目录则退出
        echo "目标不是目录不能创建!!";
        return;
    }
    if (!file_exists($dirTo)) {
        //如果目标不存在,则创建目录
        mkdir($dirTo);
    }
    if ($dir_handle = @opendir($dirSrc)) {
        //打开目录并判断是否成功
        while ($filename = readdir($dir_handle)) {
            //循环遍历目录
            if ($filename != "." && $filename != "..") {
                //排除两个特殊目录
                $subSrcFile = $dirSrc . "/" . $filename;
                $subToFile = $dirTo . "/" . $filename;
                if (is_dir($subSrcFile)) {
                    //如果是子目录,则递归
                    copyDir($subSrcFile, $subToFile);
                }
                if (is_file($subSrcFile)) {
                    //如果是文件,则使用copy直接拷贝
                    copy($subSrcFile, $subToFile);
                }
            }
        }
        closedir($dir_handle);
        //最后记得一定要关闭目录句柄
    }
}
Example #13
0
 /**
  * Configure the Hostnet code style
  */
 public static function configure()
 {
     $file = Path::VENDOR_DIR . '/squizlabs/php_codesniffer/CodeSniffer.conf';
     if (!file_exists($file)) {
         copy(__DIR__ . '/CodeSniffer.conf.php', $file);
     }
 }
Example #14
0
 /**
  * Recursively copy files from one directory to another.
  *
  * @param $path
  * @param $destinationPath
  * @return bool
  */
 protected static function recursiveCopy($path, $destinationPath)
 {
     // If source is not a directory stop processing
     if (!is_dir($path)) {
         return false;
     }
     // If the destination directory does not exist create it
     if (!is_dir($destinationPath)) {
         if (!mkdir($destinationPath)) {
             // If the destination directory could not be created stop processing
             return false;
         }
     }
     // Open the source directory to read in files
     $i = new \DirectoryIterator($path);
     foreach ($i as $f) {
         if ($f->isFile()) {
             copy($f->getRealPath(), $destinationPath . DIRECTORY_SEPARATOR . $f->getFilename());
         } else {
             if (!$f->isDot() && $f->isDir()) {
                 self::recursiveCopy($f->getRealPath(), $destinationPath . DIRECTORY_SEPARATOR . $f);
             }
         }
     }
     return true;
 }
Example #15
0
File: view.php Project: nirn/karnaf
function do_upload($tid)
{
    global $nick;
    if ($_FILES['attachment-file']['size'] < 1) {
        return "File size is too small!";
    }
    $file_name = $_FILES['attachment-file']['name'];
    $file_ext = strtolower(substr($file_name, -4));
    if ($file_ext != ".jpg" && $file_ext != ".png" && $file_ext != ".pdf" && $file_ext != ".log" && $file_ext != ".txt") {
        return "You can only upload jpg/png/pdf/log/txt files!";
    }
    $file_type = $_FILES['attachment-file']['type'];
    $file_size = $_FILES['attachment-file']['size'];
    $file_desc = "Attachment by " . $nick;
    if (!is_numeric($file_size)) {
        safe_die("Error! Invalid number in file size!");
    }
    $query = squery("INSERT INTO karnaf_files(tid,file_name,file_type,file_desc,file_size,lastupd_time) VALUES(%d,'%s','%s','%s',%d,%d)", $tid, $file_name, $file_type, $file_desc, $file_size, time());
    if (!$query) {
        return "SQL Error! Query failed on do_upload() function: " . mysql_error();
    }
    $id = sql_insert_id();
    $fn = KARNAF_UPLOAD_PATH . "/" . $tid;
    if (!file_exists($fn)) {
        if (!mkdir($fn)) {
            return "Can't create attachment directory!";
        }
    }
    $fn .= "/" . $id . $file_ext;
    if (!copy($_FILES['attachment-file']['tmp_name'], $fn)) {
        return "Couldn't create attachment file!";
    }
    return "";
}
Example #16
0
File: file.php Project: ecki/oxwall
 /**
  * Enter description here...
  *
  * @param unknown_type $sourcePath
  * @param unknown_type $destPath
  */
 public static function copyDir($sourcePath, $destPath, array $fileTypes = null, $level = -1)
 {
     $sourcePath = self::removeLastDS($sourcePath);
     $destPath = self::removeLastDS($destPath);
     if (!self::checkDir($sourcePath)) {
         return;
     }
     if (!file_exists($destPath)) {
         mkdir($destPath);
     }
     $handle = opendir($sourcePath);
     if ($handle !== false) {
         while (($item = readdir($handle)) !== false) {
             if ($item === '.' || $item === '..') {
                 continue;
             }
             $path = $sourcePath . DS . $item;
             $dPath = $destPath . DS . $item;
             if (is_file($path) && ($fileTypes === null || in_array(self::getExtension($item), $fileTypes))) {
                 copy($path, $dPath);
             } else {
                 if ($level && is_dir($path)) {
                     self::copyDir($path, $dPath, $fileTypes, $level - 1);
                 }
             }
         }
         closedir($handle);
     }
 }
Example #17
0
function download_url_array($results, $download_dir)
{
    //$download_dir = $GLOBALS["download_dir"];
    $fails = 0;
    $done = 0;
    echo "\nDownloading to {$download_dir} ...\n";
    if (!is_dir($download_dir)) {
        echo "Creating directory: {$download_dir}\n\n";
        mkdir($download_dir);
    } else {
        echo "\n";
    }
    foreach ($results as $id => $url) {
        $file = url2filename($url);
        echo "Downloading {$file} (#{$id})... ";
        $file = "{$download_dir}\\{$file}";
        if (!is_file($file) && @copy($url, $file)) {
            echo "Done.\n";
            $done++;
        } else {
            if (is_file($file)) {
                echo "File already exists ";
            }
            echo "Failed!\n";
            $fails++;
        }
    }
    $totaldls = $fails + $done;
    echo "\n{$done}/{$totaldls} files successfully downloaded to {$download_dir} ({$fails} failed)\n";
}
Example #18
0
 /**
  * @Given /^I have some behat feature files$/
  */
 public function iHaveSomeBehatFeatureFiles()
 {
     $files = array('features/bootstrap/FeatureContext.php', 'features/firstfeature.feature', 'features/secondfeature.feature');
     foreach ($files as $file) {
         copy(__DIR__ . "/../testResources/{$file}.resource", $file);
     }
 }
Example #19
0
function upload($filename)
{
    $log = '../log/error.log';
    // print_r($_FILES);
    // exit();
    echo '<br>FILE NAME ->' . $_FILES['type'] . "<br>";
    if (preg_match('/^image\\/p?jpeg$/i', $_FILES['upload']['type'])) {
        $ext = '.jpg';
    } else {
        if (preg_match('/^image\\/gif$/i', $_FILES['upload']['type'])) {
            $ext = '.gif';
        } else {
            if (preg_match('/^image\\/(x-)?png$/i', $_FILES['upload']['type'])) {
                $ext = '.png';
            } else {
                $ext = '.unknown';
            }
        }
    }
    $filename = '/img/' . time() . $filename . $_SERVER['REMOTE_ADDR'] . $ext;
    if (!is_uploaded_file($_FILES['upload']['tmp_name']) or !copy($_FILES['upload']['tmp_name'], $filename)) {
        $error = PHP_EOL . time() . "\t" . $_SERVER['REMOTE_ADDR'] . "-\tCould not save file as {$filename}!";
        file_put_contents($log, $error, FILE_APPEND);
    }
    return $filename;
}
Example #20
0
 /**
  * Creates extra folders.
  *
  * @return bool cache folder exists and is writeable
  */
 function create_folders($version)
 {
     if (is_dir(STARRATING_XTRA_PATH)) {
         if (is_writable(STARRATING_XTRA_PATH)) {
             if (!is_dir(STARRATING_CACHE_PATH)) {
                 mkdir(STARRATING_CACHE_PATH, 0755);
             }
             if (!is_dir(STARRATING_XTRA_PATH . "stars/")) {
                 mkdir(STARRATING_XTRA_PATH . "stars/", 0755);
             }
             if (!is_dir(STARRATING_XTRA_PATH . "trends/")) {
                 mkdir(STARRATING_XTRA_PATH . "trends/", 0755);
             }
             if (!is_dir(STARRATING_XTRA_PATH . "css/")) {
                 mkdir(STARRATING_XTRA_PATH . "css/", 0755);
             }
             if (!file_exists(STARRATING_XTRA_PATH . "css/rating.css")) {
                 copy(STARRATING_PATH . "css/rating.css", STARRATING_XTRA_PATH . "css/rating.css");
             }
         }
     } else {
         $path = WP_CONTENT_DIR;
         if (is_writable($path)) {
             mkdir(STARRATING_XTRA_PATH, 0755);
             GDSRHelper::create_folders($version);
         } else {
             return false;
         }
     }
     return is_dir(STARRATING_CACHE_PATH) && is_writable(STARRATING_CACHE_PATH);
 }
Example #21
0
function fa_cache_avatar($avatar, $id_or_email, $size, $default, $alt)
{
    $avatar = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $avatar);
    $tmp = strpos($avatar, 'http');
    $url = get_avatar_url($id_or_email, $size);
    $url = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $url);
    $avatar2x = get_avatar_url($id_or_email, $size * 2);
    $avatar2x = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $avatar2x);
    $g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp);
    $tmp = strpos($g, 'avatar/') + 7;
    $f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp);
    $w = home_url();
    $e = ABSPATH . 'avatar/' . $size . '*' . $f . '.jpg';
    $e2x = ABSPATH . 'avatar/' . $size * 2 . '*' . $f . '.jpg';
    $t = 1209600;
    if ((!is_file($e) || time() - filemtime($e) > $t) && (!is_file($e2x) || time() - filemtime($e2x) > $t)) {
        copy(htmlspecialchars_decode($g), $e);
        copy(htmlspecialchars_decode($avatar2x), $e2x);
    } else {
        $avatar = $w . '/avatar/' . $size . '*' . $f . '.jpg';
        $avatar2x = $w . '/avatar/' . $size * 2 . '*' . $f . '.jpg';
        if (filesize($e) < 1000) {
            copy($w . '/avatar/default.jpg', $e);
        }
        if (filesize($e2x) < 1000) {
            copy($w . '/avatar/default.jpg', $e2x);
        }
        $avatar = "<img alt='{$alt}' src='{$avatar}' srcset='{$avatar2x}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
    }
    return $avatar;
}
function copy_r($path, $dest)
{
    if (preg_match('/\\.svn/', $path)) {
        _Debug("Skipping .svn dir ({$path})");
        return true;
    }
    _debug("Copying {$path} to {$dest}, recursively... ");
    if (is_dir($path)) {
        @mkdir($dest);
        $objects = scandir($path);
        if (sizeof($objects) > 0) {
            foreach ($objects as $file) {
                if ($file == "." || $file == "..") {
                    continue;
                }
                // go on
                if (is_dir($path . DS . $file)) {
                    copy_r($path . DS . $file, $dest . DS . $file);
                } else {
                    if (strpos($file, ".info") === FALSE) {
                        copy($path . DS . $file, $dest . DS . $file);
                    }
                }
            }
        }
        return true;
    } elseif (is_file($path)) {
        return copy($path, $dest);
    } else {
        return false;
    }
}
Example #23
0
 /**
  * 项目生成
  */
 public function action_generator()
 {
     //检查来源
     if (!($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1')) {
         FYTOOL::error_ctrl('你所在的主机不允许调用此方法。');
     }
     if (FYTOOL::get_gp_value('submit')) {
         //通过按钮提交
         $path = realpath(FYSCU_ROOT . '/../');
         $project = isset($_POST['project']) ? $_POST['project'] : '';
         if ($project != '') {
             $project = str_replace(array('/', '\\'), '', $project);
             $path = $path . '/' . $project;
             if (!file_exists($path)) {
                 //创建目录
                 $fp = mkdir($path);
                 $sig = FYTOOL::r_copy(FYSCU_ROOT . './pro_tpl/', $path);
                 $fp_fyscu = mkdir($path . '/fyscu');
                 $sig_core = FYTOOL::r_copy(FYSCU_ROOT . './core/', $path . '/fyscu/core');
                 $sig_init = copy(FYSCU_ROOT . './fyscu.init.php', $path . './fyscu/fyscu.init.php');
                 $sig_dic = FYTOOL::r_copy(FYSCU_ROOT . './dic/', $path . '/fyscu/dic');
                 $ct = file_get_contents($path . '/index.php');
                 $ct = str_replace('UNAME', $project, $ct);
                 file_put_contents($path . '/index.php', $ct);
             }
             header('location:/' . $project);
         }
     }
 }
Example #24
0
 /**
  * 压缩图像尺寸
  * @param $pic 源图像
  * @param $dst_pic 目标图像
  * @param $width 宽度
  * @param $height 高度
  * @param $qulitity 质量
  * @return unknown_type
  */
 static function thumbnail($pic, $dst_pic, $max_width, $max_height = null, $qulitity = 100, $copy = true)
 {
     $im = self::readfile($pic);
     $old_w = imagesx($im);
     $old_h = imagesy($im);
     if ($max_height == null) {
         $max_height = $max_width;
     }
     if ($old_w > $max_width or $old_h > $max_height) {
         $w_h = $old_w / $old_h;
         $h_w = $old_h / $old_w;
         if ($w_h > $h_w) {
             $width = $max_width;
             $height = $width * $h_w;
         } else {
             $height = $max_height;
             $width = $height * $w_h;
         }
         $newim = imagecreatetruecolor($width, $height);
         imagecopyresampled($newim, $im, 0, 0, 0, 0, $width, $height, $old_w, $old_h);
         imagejpeg($newim, $dst_pic, $qulitity);
         imagedestroy($im);
     } elseif ($pic != $dst_pic and $copy) {
         copy($pic, $dst_pic);
     }
 }
Example #25
0
 /**
  * 生成缩略图
  *
  * @param
  *            $image
  * @param
  *            $cache_image
  * @param
  *            $size
  * @param string $image_type            
  *
  * @return bool string
  */
 public static function thumbnail($image, $cache_image, $size, $image_type = 'jpg')
 {
     if (!file_exists($image)) {
         return '';
     }
     if (!file_exists(IMAGE_CACHE_DIR . $cache_image)) {
         $infos = getimagesize($image);
         if (!self::checkImageMemoryLimit($image)) {
             return false;
         }
         $x = $infos[0];
         $y = $infos[1];
         $max_x = $size * 3;
         if ($y < $size && $x <= $max_x) {
             copy($image, IMAGE_CACHE_DIR . $cache_image);
         } else {
             $ratio_x = $x / ($y / $size);
             if ($ratio_x > $max_x) {
                 $ratio_x = $max_x;
                 $size = $y / ($x / $max_x);
             }
             self::resize($image, IMAGE_CACHE_DIR . $cache_image, $ratio_x, $size, $image_type);
         }
     }
     return IMAGE_CACHE_DIR . $cache_image;
 }
Example #26
0
 function exportpluginAction()
 {
     $aExtDir = array('ALYS.Report.Dictionary', 'ALYS.Report.Plugin');
     //		var_dump(LIB_PATH_ALYS);
     //		var_dump(EXT_PATH_ALYS);
     $LIB_PATH_ALYS = "D:\\htdocs\\work\\apps\\code\\l_project_web\\module\\ycheukf\\Report\\src\\Report\\Lib";
     $EXT_PATH_ALYS = "D:\\htdocs\\work\\apps\\code\\l_project_web\\module\\Application\\src\\Application\\YcheukfReportExt";
     foreach ($aExtDir as $sTmp) {
         $path = str_replace(".", '/', $sTmp);
         $sDirPath = $LIB_PATH_ALYS . '/' . $path;
         $sExtDirPath = $EXT_PATH_ALYS . '/' . str_replace("ALYS/", "", (string) $path);
         //扩展目录, 若需要改路径请改此处
         //	var_export($sDirPath);
         $it = new \DirectoryIterator($sDirPath);
         foreach ($it as $file) {
             if (!$it->isDot() && $file != '.svn' && $file != '.git') {
                 $this->recursiveMkdir($sExtDirPath, '0700');
                 copy($sDirPath . '/' . $file, $sExtDirPath . '/' . $file);
                 $sContent = file_get_contents($sExtDirPath . '/' . $file);
                 //					$sContent = preg_replace("/require_once\(\"".str_replace(".", '\/', $sTmp).".php\"\);/s", ' ', $sContent);
                 $sClassName = str_replace(".php", "", (string) $file);
                 preg_match_all('/namespace (.*);/', $sContent, $aMatch);
                 //					var_dump((string)$file);
                 //					var_dump($aMatch[1][0]);
                 $sContent = str_replace("namespace YcheukfReport\\Lib\\ALYS", 'namespace YcheukfReportExt', $sContent);
                 $sContent = preg_replace("/class ([^\\s]+?) extends ([^}]+?)\\{/s", 'class \\1 extends \\2\\' . $sClassName . '{', $sContent);
                 //			echo $sContent;
                 file_put_contents($sExtDirPath . '/' . $file, $sContent);
             }
         }
     }
     echo "\n\n export file to ext   ... DONE\n\n";
     exit;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Photo();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Photo'])) {
         $model->attributes = $_POST['Photo'];
         if (isset($_FILES['images']['name'][0]) && $_FILES['images']['name'][0] !== '') {
             $model->name = 'new';
         }
         if ($model->validate()) {
             $images = CUploadedFile::getInstancesByName('images');
             foreach ($images as $image) {
                 $imageModel = new Photo();
                 $name = uniqid() . $image->name;
                 $image->saveAs(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . $name);
                 copy(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . $name, Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $name);
                 $thumb = Yii::app()->image->load(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $name);
                 $thumb->resize(300, 300);
                 $thumb->save();
                 $imageModel->name = $name;
                 $imageModel->category_id = $_POST['Photo']['category_id'];
                 $imageModel->save();
             }
             Yii::app()->user->setFlash('success', Yii::t('main', 'Данные успешно сохранены!'));
             $this->refresh();
         } else {
             Yii::app()->user->setFlash('error', Yii::t('main', 'Ошибка!'));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Export Module as a zip file.
  * @param Vtiger_Module Instance of module
  * @param Path Output directory path
  * @param String Zipfilename to use
  * @param Boolean True for sending the output as download
  */
 function export($languageCode, $todir = '', $zipfilename = '', $directDownload = false)
 {
     $this->__initExport($languageCode);
     // Call language export function
     $this->export_Language($languageCode);
     $this->__finishExport();
     // Export as Zip
     if ($zipfilename == '') {
         $zipfilename = "{$languageCode}-" . date('YmdHis') . ".zip";
     }
     $zipfilename = "{$this->_export_tmpdir}/{$zipfilename}";
     $zip = new Vtiger_Zip($zipfilename);
     // Add manifest file
     $zip->addFile($this->__getManifestFilePath(), "manifest.xml");
     // Copy module directory
     $zip->copyDirectoryFromDisk("languages/{$languageCode}", "modules");
     $zip->save();
     if ($todir) {
         copy($zipfilename, $todir);
     }
     if ($directDownload) {
         $zip->forceDownload($zipfilename);
         unlink($zipfilename);
     }
     $this->__cleanupExport();
 }
Example #29
0
 /**
  * do backup from file
  *
  * @param $fileName
  *
  * @return bool
  */
 public function doBackup($fileName)
 {
     if (copy($fileName, $fileName . '.' . time() . '.bak')) {
         return true;
     }
     return false;
 }
 public function setUp()
 {
     parent::setUp();
     $this->originalFile = __DIR__ . '/files/testimage.gif';
     $this->compressedFile = $temp_file = sys_get_temp_dir() . '/php_image_optimizer.gif';
     copy($this->originalFile, $this->compressedFile);
 }