Esempio n. 1
2
 public function getRecommended()
 {
     static $phpOptions = array();
     if (empty($phpOptions)) {
         $phpOptions[] = array('label' => AText::_('MAIN_REC_SAFEMODE'), 'current' => (bool) ini_get('safe_mode'), 'recommended' => false);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_DISPERRORS'), 'current' => (bool) ini_get('display_errors'), 'recommended' => false);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_MCR'), 'current' => (bool) ini_get('magic_quotes_runtime'), 'recommended' => false);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_MCGPC'), 'current' => (bool) ini_get('magic_quotes_gpc'), 'recommended' => false);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_OUTBUF'), 'current' => (bool) ini_get('output_buffering'), 'recommended' => false);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_SESSIONAUTO'), 'current' => (bool) ini_get('session.auto_start'), 'recommended' => false);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_CURL'), 'current' => function_exists('curl_init'), 'recommended' => true);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_FTP'), 'current' => function_exists('ftp_connect'), 'recommended' => true);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_SSH2'), 'current' => extension_loaded('ssh2'), 'recommended' => true);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_FOPEN'), 'current' => ini_get('allow_url_fopen'), 'recommended' => true);
         if (function_exists('gzencode')) {
             $gz = @gzencode('dd') !== false;
         } else {
             $gz = false;
         }
         $phpOptions[] = array('label' => AText::_('MAIN_REC_GZ'), 'current' => $gz, 'recommended' => true);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_MCRYPT'), 'current' => function_exists('mcrypt_encrypt'), 'recommended' => true);
         $phpOptions[] = array('label' => AText::_('MAIN_REC_DOM'), 'current' => extension_loaded('Dom'), 'recommended' => true);
     }
     return $phpOptions;
 }
Esempio n. 2
1
 function postContent()
 {
     $this->adminGatekeeper();
     $request = $this->getInput('request');
     $key = $this->getInput('key');
     $username = $this->getInput('username');
     $json = $this->getInput('json');
     $follow_redirects = $this->getInput('follow_redirects');
     $method = $this->getInput('method', 'GET');
     $url = \Idno\Core\Idno::site()->config()->getURL();
     if (strripos($url, '/') == strlen($url) - 1) {
         $url = substr($url, 0, strlen($url) - 1);
     }
     $url .= $request;
     $client = new Webservice();
     if ($method == 'POST') {
         $result = $client->post($url, $json, array('X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', $request, $key, true))));
     } else {
         $result = $client->get($url, null, array('X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', $request, $key, true))));
     }
     $response = Webservice::getLastResponse();
     $sent_request = Webservice::getLastRequest() . $json;
     $api_request = array('request' => $request, 'key' => $key, 'username' => $username, 'json' => $json, 'sent_request' => $sent_request, 'response' => gzencode($response, 9), 'method' => $method);
     \Idno\Core\Idno::site()->session()->set('api_request', $api_request);
     $this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'admin/apitester/');
 }
Esempio n. 3
0
function smarty_outputfilter_gzip($tpl_source, &$smarty)
{
    /*~ the compression level to use
    		default: 9
    		-------------------------------------
    		0		->	9
    		less compressed ->	better compressed
    		less CPU usage	->	more CPU usage
    		-------------------------------------
    	*/
    $compression_level = defined('GZIP') && GZIP ? 9 : 0;
    /*~ force compression, even if gzip is not sent in HTTP_ACCEPT_ENCODING,
    		for example Norton Internet Security filters this, but 95% percent of
    		the browsers do support output compression, including Phoenix and Opera.
    		default: yes
    	*/
    $force_compession = true;
    //~ message to append to the template source, if it is compressed
    $append_message = "\n<!-- zlib compression level " . $compression_level . " -->";
    if ($compression_level && !headers_sent() && extension_loaded("zlib") && !$smarty->caching && !$smarty->debugging && (strstr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") || $force_compession)) {
        //~ correct encoding is sent, or compression is forced
        $tpl_source = gzencode($tpl_source . $append_message, $compression_level);
        header("Content-Encoding: gzip");
        header("Vary: Accept-Encoding");
        header("Content-Length: " . strlen($tpl_source));
    }
    return $tpl_source;
}
Esempio n. 4
0
 /**
  * Creates a Services_Gnip_Payload object.
  * 
  * @param string $raw required string representation of the dataset
  * @param string $title optional
  * @param string $body optional
  * @param array  $mediaURL with optional atrributes. 2d array can be sent. optional
  * optional attributes for mediaURL are:
  * height
  * width
  * duration
  * mimeType
  * type
  */
 public function __construct($raw, $title = null, $body = null, $mediaURL = null)
 {
     $this->title = $title != null ? trim($title) : null;
     $this->body = $body != null ? trim($body) : null;
     $this->mediaURL = is_array($mediaURL) ? $mediaURL : null;
     $this->raw = base64_encode(gzencode($raw));
 }
Esempio n. 5
0
function template_outputfilter_gzip($tpl_source, &$template_object)
{
    static $_tpl_saved = '';
    $gzipped = 0;
    if ($template_object->enable_gzip) {
        if (extension_loaded("zlib") && !get_cfg_var('zlib.output_compression') && !$template_object->cache && (strstr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") || $template_object->force_compression)) {
            $_tpl_saved .= $tpl_source . "\n<!-- zlib compression level " . $template_object->compression_level . " -->\n\n";
            $tpl_source = "";
            if ($template_object->send_now == 1) {
                $gzipped = 1;
                $tpl_source = gzencode($_tpl_saved, $template_object->compression_level);
                $_tpl_saved = "";
            }
        }
    } else {
        if (!$template_object->caching && !get_cfg_var('zlib.output_compression')) {
            $_tpl_saved .= $tpl_source . "\n<!-- normal saved output -->\n\n";
            $tpl_source = "";
            if ($template_object->send_now == 1) {
                $tpl_source = $_tpl_saved;
                $_tpl_saved = "";
            }
        }
    }
    if ($template_object->send_now == 1 && $template_object->enable_gzip == 1) {
        if ($gzipped == 1) {
            header("Content-Encoding: gzip");
            header("Content-Length: " . strlen($tpl_source));
        }
    }
    return $tpl_source;
}
 private function setEncodingToUse($encodingUsed)
 {
     switch ($encodingUsed) {
         case 'identity':
             $this->compressFunction = function ($data) {
                 return $data;
             };
             $this->outputResponse->removeHeader('Content-Encoding');
             break;
         case 'x-gzip':
         case 'gzip':
             $this->compressFunction = function ($data) {
                 return gzencode($data);
             };
             $this->outputResponse->setHeader('Content-Encoding', 'gzip');
             break;
         case 'deflate':
             $this->compressFunction = function ($data) {
                 return zlib_encode($data, 15);
             };
             $this->outputResponse->setHeader('Content-Encoding', 'deflate');
             break;
         case 'bzip2':
             $this->compressFunction = function ($data) {
                 return bzcompress($data);
             };
             $this->outputResponse->setHeader('Content-Encoding', 'bzip2');
             break;
         default:
             throw new \LogicException('Unknown encoding');
     }
 }
 public function create($paths, $filename = FALSE)
 {
     $archive = new Archive('tar');
     foreach ($paths as $set) {
         $archive->add($set[0], $set[1]);
     }
     $gzfile = gzencode($archive->create());
     if ($filename == FALSE) {
         return $gzfile;
     }
     if (substr($filename, -7) !== '.tar.gz') {
         // Append tar extension
         $filename .= '.tar.gz';
     }
     // Create the file in binary write mode
     $file = fopen($filename, 'wb');
     // Lock the file
     flock($file, LOCK_EX);
     // Write the tar file
     $return = fwrite($file, $gzfile);
     // Unlock the file
     flock($file, LOCK_UN);
     // Close the file
     fclose($file);
     return (bool) $return;
 }
Esempio n. 8
0
function write_to_file($filename, $stream_id, $content)
{
    global $GLOBAL_CRON;
    $file_ext = substr($filename, strrpos($filename, '.') + 1);
    switch ($file_ext) {
        case 'gz':
            $string = gzencode($content, 9);
            break;
        case 'bz2':
            $string = bzcompress($content, 9);
            break;
        default:
            $string = $content;
            break;
    }
    flush();
    if (!$GLOBAL_CRON) {
        echo $string;
    } else {
        echo "file " . $filename . " " . strlen($string) . "\n";
    }
    if ($stream_id) {
        return fwrite($stream_id, $string);
    }
}
Esempio n. 9
0
function cssTemplate($cssFileName)
{
    global $developmode;
    $fName = substr($cssFileName, 0, strlen($cssFileName) - 4);
    $file = "cache/css/" . $fName . ".gcss";
    $dir = dirname($file);
    $cssfile = "css/{$fName}.css";
    if (!file_exists($dir)) {
        mkdir($dir, 0777, true);
    }
    if (!file_exists($file) || $developmode) {
        $fp = fopen($cssfile, 'r');
        $fz = filesize($cssfile);
        if ($fz) {
            $theData = fread($fp, $fz);
            $patterns = array("/\\/\\*[^*]*?\\*\\//", "/\n/", "/    /");
            $replacements = array("", "", "");
            $theData = preg_replace($patterns, $replacements, $theData);
        } else {
            $theData = "";
        }
        fclose($fp);
        writeToFile($file, gzencode($theData, 9));
        chmod($file, 0777);
    }
    echo "<link href=\"include/component/css.php?f={$fName}\" rel=\"stylesheet\" type=\"text/css\"/>";
}
Esempio n. 10
0
 protected function _generateContent($code)
 {
     $url = $this->getVersionUrl();
     $type = $this->has('type') ? $this->get('type') : 'echo';
     if ($this->has('gzip_static_dir')) {
         $zlevel = $this->has('gzip_level') ? $this->get('gzip_level') : 3;
         $file_source = lmbFs::normalizePath($this->get('gzip_static_dir'), lmbFs::UNIX) . '/' . str_replace('/', '-', lmbFs::normalizePath($this->getFileUrl(), lmbFs::UNIX));
         lmbFs::cp($this->getFilePath(), $this->getRootDir() . '/' . $file_source);
         $file_gz = $file_source . '.gz';
         lmbFs::safeWrite($this->getRootDir() . '/' . $file_gz, gzencode(file_get_contents($this->getFilePath()), $zlevel, FORCE_DEFLATE));
         $url = $this->addVersion($file_source);
     }
     switch ($type) {
         case 'echo':
             if ($this->has('to_var')) {
                 $code->writePhp($this->get('to_var') . ' = \'' . addslashes($url) . '\';');
             } else {
                 $code->writeHTML(htmlspecialchars($url, 3));
             }
             break;
         case 'js':
             $code->writeHTML('<script type="text/javascript" src="' . htmlspecialchars($url, 3) . '" ></script>');
             break;
         case 'css':
             $code->writeHTML('<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($url, 3) . '" />');
             break;
         default:
             throw new lmbMacroException('Unknown type ' . $type);
     }
 }
Esempio n. 11
0
 /**
  * @param $url
  * @param $data
  * @param $gzip
  * @param $action
  * @return mixed
  */
 private static function httpPost($url, $data, $gzip, $action)
 {
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
     curl_setopt($curl, CURLOPT_USERAGENT, 'GeTui PHP/1.0');
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, GTConfig::getHttpConnectionTimeOut());
     curl_setopt($curl, CURLOPT_TIMEOUT_MS, GTConfig::getHttpSoTimeOut());
     $header = array('Content-Type:text/html;charset=UTF-8');
     if ($gzip) {
         $data = gzencode($data, 9);
         $header[] = 'Accept-Encoding:gzip';
         $header[] = 'Content-Encoding:gzip';
         curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
     }
     if (null !== $action) {
         $header[] = 'Gt-Action:' . $action;
     }
     curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
     $curl_version = curl_version();
     if ($curl_version['version_number'] >= 462850) {
         curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 30000);
         curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
     }
     //通过代理访问接口需要在此处配置代理
     //curl_setopt($curl, CURLOPT_PROXY, '192.168.1.18:808');
     //请求失败有3次重试机会
     $result = HttpManager::exeBySetTimes(3, $curl);
     curl_close($curl);
     return $result;
 }
Esempio n. 12
0
 /**
  * Pack file by GZ compressor.
  *
  * @param string $source
  * @param string $destination
  * @return string
  */
 public function pack($source, $destination)
 {
     $data = $this->_readFile($source);
     $gzData = gzencode($data, 9);
     $this->_writeFile($destination, $gzData);
     return $destination;
 }
Esempio n. 13
0
 /**
  * {@inheritdoc}
  *
  * The file name for the CSS or JS cache file is generated from the hash of
  * the aggregated contents of the files in $data. This forces proxies and
  * browsers to download new CSS when the CSS changes.
  */
 public function dump($data, $file_extension)
 {
     // Prefix filename to prevent blocking by firewalls which reject files
     // starting with "ad*".
     $filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension;
     // Create the css/ or js/ path within the files folder.
     $path = 'public://' . $file_extension;
     $uri = $path . '/' . $filename;
     // Create the CSS or JS file.
     file_prepare_directory($path, FILE_CREATE_DIRECTORY);
     if (!file_exists($uri) && !file_unmanaged_save_data($data, $uri, FILE_EXISTS_REPLACE)) {
         return FALSE;
     }
     // If CSS/JS gzip compression is enabled and the zlib extension is available
     // then create a gzipped version of this file. This file is served
     // conditionally to browsers that accept gzip using .htaccess rules.
     // It's possible that the rewrite rules in .htaccess aren't working on this
     // server, but there's no harm (other than the time spent generating the
     // file) in generating the file anyway. Sites on servers where rewrite rules
     // aren't working can set css.gzip to FALSE in order to skip
     // generating a file that won't be used.
     if (extension_loaded('zlib') && \Drupal::config('system.performance')->get($file_extension . '.gzip')) {
         if (!file_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
             return FALSE;
         }
     }
     return $uri;
 }
Esempio n. 14
0
    /**
     * Return cache with given parameters
     * @param $content
     * @param $content_type
     * @param $charset
     * @return string
     */
    public function createCacheContent($content, $content_type, $charset)
    {
        $cacheContent = '<?php
header(\'Last-Modified: ' . gmdate("D, d M Y H:i:s", time()) . ' GMT\');
header(\'Cache-Control: public\');
if(isset($_SERVER[\'HTTP_IF_MODIFIED_SINCE\']) && ' . time() . ' <= strtotime($_SERVER[\'HTTP_IF_MODIFIED_SINCE\']))
{
header(\'HTTP/1.1 304 Not Modified\');
exit;
}
else
{
';
        if (function_exists('xgzencode')) {
            $cacheContent .= 'if(isset($_SERVER[\'HTTP_ACCEPT_ENCODING\']) && strpos($_SERVER[\'HTTP_ACCEPT_ENCODING\'], \'gzip\')!==false)
{
header(\'Content-Encoding: gzip\');
header(\'Content-Type: ' . $content_type . '; charset=' . $charset . '\'); ?' . '>' . gzencode($content, 9) . '<?php
}
else
{
header(\'Content-Type: ' . $content_type . '; charset=' . $charset . '\'); ?' . '>' . $content . '<?php
}';
        } else {
            $cacheContent .= 'header(\'Content-Type: ' . $content_type . '; charset=' . $charset . '\'); ?' . '>' . $content . '<?php
';
        }
        $cacheContent .= '}
?>';
        return $cacheContent;
    }
Esempio n. 15
0
 public static function compress(string $output)
 {
     $request = Request::createFromGlobals();
     // Check to see if we have data, if not, then return empty string
     if ($output === null) {
         return (string) '';
     }
     // Handle the supported compressions.
     $supported_enc = array();
     if ($request->headers->get('HTTP_ACCEPT_ENCODING')) {
         $supported_enc = explode(',', $request->headers->get('HTTP_ACCEPT_ENCODING'));
     }
     if (in_array('gzip', $supported_enc) === true) {
         header('Vary: Accept-Encoding');
         header('Content-Encoding: gzip');
         $encoded_output = gzencode($output, 9);
         return (string) $encoded_output;
     } elseif (in_array('deflate', $supported_enc) === true) {
         header('Vary: Accept-Encoding');
         header('Content-Encoding: deflate');
         $deflated_output = gzdeflate($output, 9);
         return (string) $deflated_output;
     } else {
         return (string) $output;
     }
 }
Esempio n. 16
0
 protected static function _writeMeta($tableData, $migrations)
 {
     //file_put_contents(static::_getTableDataFileName(), serialize([ $tableData, $migrations ]));
     /** @var Model\Settings $settings */
     $settings = DI::getDefault()['Settings'];
     $settings::set('_database_struct', gzencode(serialize([$tableData, $migrations]), 9));
 }
Esempio n. 17
0
 /**
  * @param object|string $string
  * @param string        $format
  * @param array         $context
  *
  * @return array|bool|float|int|null|string
  */
 public function normalize($string, $format = null, array $context = array())
 {
     $mime = isset($context[static::CONTEXT_MIME]) ? $context[static::CONTEXT_MIME] : 'application/octet-stream';
     $charset = isset($context[static::CONTEXT_CHARSET]) ? $context[static::CONTEXT_CHARSET] : null;
     $gzip = isset($context[static::CONTEXT_GZIP]) ? $context[static::CONTEXT_GZIP] : null;
     $base64 = isset($context[static::CONTEXT_BASE64]) ? $context[static::CONTEXT_BASE64] : null;
     $base64 = $base64 !== null ? $base64 : strpos($mime, '/octet-stream') !== false;
     $urlencode = isset($context[static::CONTEXT_URLENCODE]) ? $context[static::CONTEXT_URLENCODE] : null;
     $urlencode = $urlencode !== null ? $urlencode : strpos($mime, 'text/') !== false;
     if ($gzip) {
         $string = gzencode($string);
         $mime = 'application/x-gzip';
     }
     if ($urlencode and !$base64) {
         $string = urlencode($string);
     }
     if ($base64 or !$urlencode) {
         $string = base64_encode($string);
     }
     $options = $mime;
     if ($charset and $mime) {
         $options .= ';charset=' . $charset;
     }
     if ($base64) {
         $options .= ';base64';
     }
     return sprintf('data:%s,%s', $options, $string);
 }
Esempio n. 18
0
 private function request($url, $data, $apiKey = null, $operation = null)
 {
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     if ($this->certificationFile) {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
         curl_setopt($ch, CURLOPT_CAINFO, $this->certificationFile);
     } else {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     }
     if ($this->proxy) {
         curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
     }
     $headers = array("Content-Type: application/json+gzip", "User-Agent: QafooLabs Profiler Collector DevMode");
     if ($apiKey) {
         $headers[] = 'X-Profiler-Key: ' . $apiKey;
     }
     if ($operation) {
         $headers[] = 'X-Profiler-Op: ' . $operation;
     }
     curl_setopt($ch, CURLOPT_FAILONERROR, true);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_POSTFIELDS, gzencode(json_encode($data)));
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     if (curl_exec($ch) === false) {
         syslog(LOG_WARNING, "Qafoo Profiler DevMode cURL failed: " . curl_error($ch));
     }
 }
 public function write($content, $md5)
 {
     $flags = 0;
     if ($this->compression) {
         $flags = \StaticHtmlMemcachedResponse::MEMCACHED_GZIP_FLAG;
         $content = gzencode($content, 4);
     }
     if (!$this->memcached || !$this->memcached->set($this->cacheKey, $content, $flags)) {
         return false;
     }
     $this->props = new \stdClass();
     $this->props->mtime = time();
     $this->props->etag = md5($this->cacheKey . $this->props->size . $this->props->mtime);
     $this->props->type = "text/html; charset=" . LANG_CHARSET;
     $this->props->md5 = $md5;
     $this->props->gzip = $this->compression;
     if (function_exists("mb_strlen")) {
         $this->props->size = mb_strlen($content, "latin1");
         $this->props->size += mb_strlen(serialize($this->props), "latin1");
     } else {
         $this->props->size = strlen($content);
         $this->props->size += strlen(serialize($this->props));
     }
     $this->memcached->set("~" . $this->cacheKey, $this->props);
     return $this->props->size;
 }
Esempio n. 20
0
 public function testInflatesStreams()
 {
     $content = gzencode('test');
     $a = Psr7\stream_for($content);
     $b = new InflateStream($a);
     $this->assertEquals('test', (string) $b);
 }
Esempio n. 21
0
 /**
  * Compresses data and send it to the client
  *
  * @param String $data - The string to send.
  */
 public static function send($data = '')
 {
     if (!headers_sent()) {
         if (array_key_exists('HTTP_ACCEPT_ENCODING', $_SERVER)) {
             $HTTP_ACCEPT_ENCODING = $_SERVER['HTTP_ACCEPT_ENCODING'];
             if (headers_sent()) {
                 $encoding = false;
             } else {
                 if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) {
                     $encoding = 'x-gzip';
                 } else {
                     if (strpos($HTTP_ACCEPT_ENCODING, 'gzip') !== false) {
                         $encoding = 'gzip';
                     } else {
                         $encoding = false;
                     }
                 }
             }
             // no need to waste resources in compressing very little data
             if (strlen($data) > 2048 && $encoding && function_exists('gzencode')) {
                 $data = gzencode($data, 5);
                 header('Content-Encoding: ' . $encoding);
             }
         }
         header('Content-Length: ' . strlen($data));
     }
     echo $data;
 }
Esempio n. 22
0
 /**
  * Import products
  */
 public function actionImport()
 {
     $importer = new CsvImporter();
     $importer->deleteDownloadedImages = Yii::app()->request->getPost('remove_images');
     if (Yii::app()->request->isPostRequest && isset($_FILES['file'])) {
         $importer->file = $_FILES['file']['tmp_name'];
         if ($importer->validate() && !$importer->hasErrors()) {
             // Create db backup
             if (isset($_POST['create_dump']) && $_POST['create_dump']) {
                 Yii::import('application.components.SDatabaseDumper');
                 $dumper = new SDatabaseDumper();
                 $file = Yii::getPathOfAlias('webroot.protected.backups') . DIRECTORY_SEPARATOR . 'dump_' . date('Y-m-d_H_i_s') . '.sql';
                 if (is_writable(Yii::getPathOfAlias('webroot.protected.backups'))) {
                     if (function_exists('gzencode')) {
                         file_put_contents($file . '.gz', gzencode($dumper->getDump()));
                     } else {
                         file_put_contents($file, $dumper->getDump());
                     }
                 } else {
                     throw new CHttpException(503, Yii::t('CsvModule.admin', 'Ошибка. Директория для бэкапов недоступна для записи.'));
                 }
             }
             $importer->import();
         }
     }
     $this->render('import', array('importer' => $importer));
 }
Esempio n. 23
0
function steEncode($encodeType, $decodedString)
{
    switch (strtolower($encodeType)) {
        case 'base64':
            return base64_encode($decodedString);
        case 'gz':
            return gzencode($decodedString);
        case 'rawurl':
            return rawurlencode($decodedString);
        case 'url':
            return urlencode($decodedString);
        case 'utf8':
            return utf8_encode($decodedString);
        case 'html':
            return htmlentities($decodedString);
        case 'htmlnl':
            return nl2br(htmlentities($decodedString));
        case 'nl':
            return nl2br($decodedString);
        case 'email':
            return str_replace("@", " AT ", str_replace(".", " DOT ", str_replace("_", " UNDERLINE ", str_replace("-", " MINUS ", $decodedString))));
        default:
            return "Encoding does not support type {$encodeType}<br>";
    }
}
Esempio n. 24
0
 /**
  * Put file to storage
  *
  * @param  string $file   file path in storage
  * @param  array  $params uploaded data and options
  * @return array  file size and file name
  */
 public function put($file, $params)
 {
     if (empty($params['overwrite'])) {
         $file = $this->generateName($file);
         // check if name is unique and generate new if not
     }
     $file = $this->prefix($file);
     if (!empty($params['compress'])) {
         if (!empty($params['contents'])) {
             $params['contents'] = gzencode($params['contents']);
         }
     }
     if (!fn_mkdir(dirname($file))) {
         return false;
     }
     if (!empty($params['file'])) {
         fn_copy($params['file'], $file);
     } else {
         fn_put_contents($file, $params['contents']);
     }
     if (!file_exists($file)) {
         return false;
     }
     $filesize = filesize($file);
     if (!empty($params['file']) && empty($params['keep_origins'])) {
         fn_rm($params['file']);
     }
     return array($filesize, str_replace($this->prefix(), '', $file));
 }
Esempio n. 25
0
 public function index()
 {
     //$sitemap = new google_sitemap; //Create a new Sitemap Object
     $posts = $this->cf_blog_model->getRecentPosts('50');
     $item = $this->cf_sitemap_lib->google_sitemap_item(site_url(), date("Y-m-d", time()), 'daily', '1.0');
     //Create a new Item
     $this->cf_sitemap_lib->add_item($item);
     foreach ($posts->result_array() as $entry) {
         $link = get_page_url($entry);
         //Create a new Item
         $item = $this->cf_sitemap_lib->google_sitemap_item(site_url($link), date("Y-m-d", strtotime($entry['page_date'])), 'daily', '0.5');
         //Append the item to the sitemap object
         $this->cf_sitemap_lib->add_item($item);
     }
     $this->cf_sitemap_lib->build("sitemap.xml");
     //Build it...
     //Let's compress it to gz
     $data = implode("", file("sitemap.xml"));
     $gzdata = gzencode($data, 9);
     $fp = fopen("sitemap.xml.gz", "w");
     fwrite($fp, $gzdata);
     fclose($fp);
     //Let's Ping google
     $this->_pingGoogleSitemaps(base_url() . "/sitemap.xml.gz");
     echo site_url();
 }
 public function buildCss()
 {
     App::import('Vendor', 'AssetMinify.JSMinPlus');
     // Ouverture des fichiers de config
     $dir = new Folder(Configure::read('App.www_root') . 'css' . DS . 'minified');
     if ($dir->path !== null) {
         foreach ($dir->find('config_.*.ini') as $file) {
             preg_match('`^config_(.*)\\.ini$`', $file, $grep);
             $file = new File($dir->pwd() . DS . $file);
             $ini = parse_ini_file($file->path, true);
             $fileFull = new File($dir->path . DS . 'full_' . $grep[1] . '.css', true, 0644);
             $fileGz = new File($dir->path . DS . 'gz_' . $grep[1] . '.css', true, 0644);
             $contentFull = '';
             foreach ($ini as $data) {
                 // On a pas de version minifié
                 if (!($fileMin = $dir->find('file_' . md5($data['url'] . $data['md5']) . '.css'))) {
                     $fileMin = new File($dir->path . DS . 'file_' . md5($data['url'] . $data['md5']) . '.css', true, 0644);
                     $this->out("Compression de " . $data['file'] . ' ... ', 0);
                     $fileMin->write(MinifyUtils::compressCss(MinifyUtils::cssAbsoluteUrl($data['url'], file_get_contents($data['file']))));
                     $this->out('OK');
                 } else {
                     $fileMin = new File($dir->path . DS . 'file_' . md5($data['url'] . $data['md5']) . '.css');
                 }
                 $contentFull .= $fileMin->read() . PHP_EOL;
             }
             // version full
             $fileFull->write($contentFull);
             $fileFull->close();
             // compression
             $fileGz->write(gzencode($contentFull, 6));
         }
     }
 }
    /**
     * Notifies managing contact about updated metadata of entity
     *
     * @param   sspmod_janus_Entity $entity
     * @param   string $metadataXml
     * @return void
     */
    protected function _mailUpdatedMetaData(sspmod_janus_Entity $entity, $metadataXml)
    {
        $config = SimpleSAML_Configuration::getInstance();
        $time = date(DATE_RFC822);
        $entityName = $entity->getPrettyname();
        $entityId = $entity->getEntityId();
        $message = <<<MESSAGE
<h1>Metadata Change detected</h1>
<p>Cron ran at {$time}</p>
<p>Name: {$entityName}</p>
<p>EntityId: {$entityId}</p>
MESSAGE;
        $toAddress = $config->getString('managingcontact_email');
        if (empty($toAddress)) {
            SimpleSAML_Logger::error('Cron - Could not send email. [managingcontact_email] not set in config.');
        }
        $fromAddress = '*****@*****.**';
        $subject = "Metadata Change detected for entity " . $entity->getPrettyname() . " (" . $entity->getEntityId() . "])";
        $email = new SimpleSAML_XHTML_EMail($toAddress, $subject, $fromAddress);
        $email->setBody($message);
        // Add gzipped metadata
        $attachmentContent = gzencode($metadataXml);
        $attachmentFileName = 'metadata-' . $entityName . '.xml.gz';
        $email->addAttachment($attachmentContent, $attachmentFileName, 'application/zip');
        $email->send();
    }
Esempio n. 28
-1
 static function test_gz()
 {
     if (function_exists('gzencode')) {
         return !(@gzencode('dd') === false);
     }
     return false;
 }
 function afterLayout()
 {
     if (Configure::read('Cache.disable') || Configure::read('ViewMemcache.disable')) {
         return true;
     }
     try {
         if (!empty($this->_View->viewVars['enableViewMemcache'])) {
             if (isset($this->_View->viewVars['viewMemcacheDuration'])) {
                 // CakeLog::write('debug', "ViewMemCache: duration override: {$this->_View->viewVars['viewMemcacheDuration']}");
                 @Cache::set(array('duration' => $this->_View->viewVars['viewMemcacheDuration'], null, 'view_memcache'));
                 //'+30 days' or seconds
             }
             if (!isset($this->_View->viewVars['viewMemcacheNoFooter'])) {
                 //CakeLog::write('debug', "ViewMemCache: footer disabled");
                 $this->cacheFooter = "\n<!-- ViewCached";
                 if ($this->gzipContent) {
                     $this->cacheFooter .= ' gzipped';
                 }
                 $this->cacheFooter .= ' ' . date('r') . ' -->';
             }
             if ($this->gzipContent && empty($this->_View->viewVars['viewMemcacheDisableGzip'])) {
                 //CakeLog::write('debug', "ViewMemCache: gzipping ".$this->request->here."\n\n".var_export($this->request,true)."\n\n".var_export($_SERVER,true));
                 @Cache::write($this->request->here, gzencode($this->_View->output . $this->cacheFooter, $this->compressLevel), 'view_memcache');
             } else {
                 //CakeLog::write('debug', "ViewMemCache: NOT gzipping ");
                 @Cache::write($this->request->here, $this->_View->output . $this->cacheFooter, 'view_memcache');
             }
         }
     } catch (Exception $e) {
         //do nothing
     }
     return true;
 }
 /**
  * Saves data in the cache.
  *
  * @param string $entryIdentifier An identifier for this specific cache entry
  * @param string $data The data to be stored
  * @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
  * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
  *
  * @return void
  * @throws \TYPO3\CMS\Core\Cache\Exception if no cache frontend has been set.
  * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException if the data is not a string
  */
 public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
 {
     $databaseData = ['created' => $GLOBALS['EXEC_TIME'], 'expires' => $GLOBALS['EXEC_TIME'] + $this->getRealLifetime($lifetime)];
     if (in_array('explanation', $tags)) {
         $databaseData['explanation'] = $data;
         parent::set($entryIdentifier, serialize($databaseData), $tags, $lifetime);
         return;
     }
     // call set in front of the generation, because the set method
     // of the DB backend also call remove
     parent::set($entryIdentifier, serialize($databaseData), $tags, $lifetime);
     $fileName = $this->getCacheFilename($entryIdentifier);
     $cacheDir = PathUtility::pathinfo($fileName, PATHINFO_DIRNAME);
     if (!is_dir($cacheDir)) {
         GeneralUtility::mkdir_deep($cacheDir);
     }
     // normal
     GeneralUtility::writeFile($fileName, $data);
     // gz
     if ($this->configuration->get('enableStaticFileCompression')) {
         $contentGzip = gzencode($data, $this->getCompressionLevel());
         if ($contentGzip) {
             GeneralUtility::writeFile($fileName . '.gz', $contentGzip);
         }
     }
     // htaccess
     $this->writeHtAccessFile($fileName, $lifetime);
 }