Пример #1
4
 function command_dd()
 {
     $args = func_get_args();
     $options = $this->get_options();
     $dd = kernel::single('dev_docbuilder_dd');
     if (empty($args)) {
         $dd->export();
     } else {
         foreach ($args as $app_id) {
             $dd->export_tables($app_id);
         }
     }
     if ($filename = $options['result-file']) {
         ob_start();
         $dd->output();
         $out = ob_get_contents();
         ob_end_clean();
         if (!is_dir(dirname($filename))) {
             throw new Exception('cannot find the ' . dirname($filename) . 'directory');
         } elseif (is_dir($filename)) {
             throw new Exception('the result-file path is a directory.');
         }
         file_put_contents($options['result-file'], $out);
         echo 'data dictionary doc export success.';
     } else {
         $dd->output();
     }
 }
 /**
  * Save an uploaded file to a new location.
  *
  * @param   mixed    name of $_FILE input or array of upload data
  * @param   string   new filename
  * @param   string   new directory
  * @param   integer  chmod mask
  * @return  string   full path to new file
  */
 public static function save($file, $filename = NULL, $directory = NULL, $chmod = 0755)
 {
     // Load file data from FILES if not passed as array
     $file = is_array($file) ? $file : $_FILES[$file];
     if ($filename === NULL) {
         // Use the default filename, with a timestamp pre-pended
         $filename = time() . $file['name'];
     }
     // Remove spaces from the filename
     $filename = preg_replace('/\\s+/', '_', $filename);
     if ($directory === NULL) {
         // Use the pre-configured upload directory
         $directory = WWW_ROOT . 'files/';
     }
     // Make sure the directory ends with a slash
     $directory = rtrim($directory, '/') . '/';
     if (!is_dir($directory)) {
         // Create the upload directory
         mkdir($directory, 0777, TRUE);
     }
     //if ( ! is_writable($directory))
     //throw new exception;
     if (is_uploaded_file($file['tmp_name']) and move_uploaded_file($file['tmp_name'], $filename = $directory . $filename)) {
         if ($chmod !== FALSE) {
             // Set permissions on filename
             chmod($filename, $chmod);
         }
         //$all_file_name = array(FILE_INFO => $filename);
         // Return new file path
         return $filename;
     }
     return FALSE;
 }
Пример #3
1
 /**
  * Initializes this logger.
  *
  * Available options:
  *
  * - file:        The file path or a php wrapper to log messages
  *                You can use any support php wrapper. To write logs to the Apache error log, use php://stderr
  * - format:      The log line format (default to %time% %type% [%priority%] %message%%EOL%)
  * - time_format: The log time strftime format (default to %b %d %H:%M:%S)
  * - dir_mode:    The mode to use when creating a directory (default to 0777)
  * - file_mode:   The mode to use when creating a file (default to 0666)
  *
  * @param  sfEventDispatcher $dispatcher  A sfEventDispatcher instance
  * @param  array             $options     An array of options.
  *
  * @return Boolean      true, if initialization completes successfully, otherwise false.
  */
 public function initialize(sfEventDispatcher $dispatcher, $options = array())
 {
     if (!isset($options['file'])) {
         throw new sfConfigurationException('You must provide a "file" parameter for this logger.');
     }
     if (isset($options['format'])) {
         $this->format = $options['format'];
     }
     if (isset($options['time_format'])) {
         $this->timeFormat = $options['time_format'];
     }
     if (isset($options['type'])) {
         $this->type = $options['type'];
     }
     $dir = dirname($options['file']);
     if (!is_dir($dir)) {
         mkdir($dir, isset($options['dir_mode']) ? $options['dir_mode'] : 0777, true);
     }
     $fileExists = file_exists($options['file']);
     if (!is_writable($dir) || $fileExists && !is_writable($options['file'])) {
         throw new sfFileException(sprintf('Unable to open the log file "%s" for writing.', $options['file']));
     }
     $this->fp = fopen($options['file'], 'a');
     if (!$fileExists) {
         chmod($options['file'], isset($options['file_mode']) ? $options['file_mode'] : 0666);
     }
     return parent::initialize($dispatcher, $options);
 }
Пример #4
1
 protected function createPath()
 {
     $fullPath = dirname($this->fullFilePath());
     if (!is_dir($fullPath)) {
         mkdir($fullPath, 0755, true);
     }
 }
Пример #5
1
 protected function bootstrap()
 {
     if (is_file('package.json')) {
         $this->comment(' -> Installing npm dependencies (with yarn)...');
         $this->executeCommand($this->input->getOption('sudo') ? 'sudo yarn' : 'yarn');
     }
     if (is_file('bower.json')) {
         $this->comment(' -> Installing bower dependencies...');
         $this->executeCommand('bower install');
     }
     if (is_file('composer.json')) {
         $this->comment(' -> Installing composer dependencies...');
         $this->executeCommand('composer install');
     }
     if (is_dir('storage')) {
         $this->comment(' -> Dando permissão de escrita no diretório storage...');
         $this->executeCommand('chmod -R 777 storage');
     }
     if (is_dir('app/storage')) {
         $this->comment(' -> Dando permissão de escrita no diretório storage...');
         $this->executeCommand('chmod -R 777 app/storage');
     }
     if (is_file('.env.example')) {
         $this->comment(' -> Criando o arquivo .env');
         $this->executeCommand('cp .env.example .env');
     }
 }
Пример #6
1
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getArgument('path');
     if (!file_exists($path)) {
         $output->writeln("{$path} is not a file or a path");
     }
     $filePaths = [];
     if (is_file($path)) {
         $filePaths = [realpath($path)];
     } elseif (is_dir($path)) {
         $filePaths = array_diff(scandir($path), array('..', '.'));
     } else {
         $output->writeln("{$path} is not known.");
     }
     $generator = new StopwordGenerator($filePaths);
     if ($input->getArgument('type') === 'json') {
         echo json_encode($this->toArray($generator->getStopwords()), JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE);
         echo json_last_error_msg();
         die;
         $output->write(json_encode($this->toArray($generator->getStopwords())));
     } else {
         $stopwords = $generator->getStopwords();
         $stdout = fopen('php://stdout', 'w');
         echo 'token,freq' . PHP_EOL;
         foreach ($stopwords as $token => $freq) {
             fputcsv($stdout, [utf8_encode($token), $freq]) . PHP_EOL;
         }
         fclose($stdout);
     }
 }
 public function __invoke($ctx)
 {
     if (isset($ctx['Directory']['path'])) {
         $path = $ctx['Directory']['path'];
     } else {
         $url = $ctx['env']['PATH_INFO'];
         if (strpos($url, '..') !== false) {
             return array(403, array('Content-Type', 'text/plain'), 'Forbidden');
         }
         $path = $this->path . $url;
     }
     // Sanity checks
     if (!file_exists($path)) {
         return array(404, array('Content-Type', 'text/plain'), 'File not found');
     }
     $path = realpath($path);
     if (false === $path) {
         // resolving failed. not enough rights for intermediate folder?
         return array(404, array('Content-Type', 'text/plain'), 'File not found');
     }
     if (strpos($path, $this->path) !== 0) {
         // gone out of "chroot"?
         return array(404, array('Content-Type', 'text/plain'), 'File not found');
     }
     if (!is_readable($path)) {
         return array(403, array('Content-Type', 'text/plain'), 'Forbidden');
     }
     // Only files are served
     if (is_dir($path)) {
         return array(403, array('Content-Type', 'text/plain'), 'Forbidden');
     }
     return $this->serve($path);
 }
Пример #8
1
 /**
  *
  */
 public function checkSkinStyles($name, $values)
 {
     $config = Zend_Registry::get('config');
     $basePath = $config->design->pathToSkins;
     $xhtml = array();
     $this->view->name = $name;
     $this->view->selectedStyles = $values;
     //load the skin folders
     if (is_dir('./' . $basePath)) {
         $folders = Digitalus_Filesystem_Dir::getDirectories('./' . $basePath);
         if (count($folders) > 0) {
             foreach ($folders as $folder) {
                 $this->view->skin = $folder;
                 $styles = Digitalus_Filesystem_File::getFilesByType('./' . $basePath . '/' . $folder . '/styles', 'css');
                 if (is_array($styles)) {
                     foreach ($styles as $style) {
                         //add each style sheet to the hash
                         // key = path / value = filename
                         $hashStyles[$style] = $style;
                     }
                     $this->view->styles = $hashStyles;
                     $xhtml[] = $this->view->render($this->partialFile);
                     unset($hashStyles);
                 }
             }
         }
     } else {
         throw new Zend_Acl_Exception('Unable to locate skin folder');
     }
     return implode(null, $xhtml);
 }
Пример #9
1
Файл: Core.php Проект: z7/hydra
 function __construct(array $config = array())
 {
     $this->_config =& $config;
     // Try to locate app folder.
     if (!isset($config['app_dir'])) {
         $cwd = getcwd();
         while (!is_dir("{$cwd}/app")) {
             if ($cwd == dirname($cwd)) {
                 throw new \LogicException('/app folder not found.');
             }
             $cwd = dirname($cwd);
         }
         $config['app_dir'] = "{$cwd}/app";
     }
     $is_web_request = isset($_SERVER['SERVER_NAME']);
     $config += array('debug' => !$is_web_request || $_SERVER['SERVER_NAME'] == 'localhost', 'register_exception_handler' => $is_web_request, 'register_error_handler' => $is_web_request, 'core_dir' => __DIR__ . '/../..', 'data_dir' => "{$config['app_dir']}/../data");
     $this->exception_handler = new ExceptionHandler($this->debug);
     if ($this->register_exception_handler) {
         set_exception_handler(array($this->exception_handler, 'handle'));
     }
     if ($this->register_error_handler) {
         $this->errorHandler = \Symfony\Component\HttpKernel\Debug\ErrorHandler::register();
     }
     foreach (array($config['data_dir'], "{$config['data_dir']}/cache", "{$config['data_dir']}/logs") as $dir) {
         if (!is_dir($dir)) {
             mkdir($dir);
         }
     }
 }
Пример #10
1
 /**
  * @brief Get the points
  */
 function getPoint($member_srl, $from_db = false)
 {
     $member_srl = abs($member_srl);
     // Get from instance memory
     if (!$from_db && $this->pointList[$member_srl]) {
         return $this->pointList[$member_srl];
     }
     // Get from file cache
     $path = sprintf(_XE_PATH_ . 'files/member_extra_info/point/%s', getNumberingPath($member_srl));
     $cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl);
     if (!$from_db && file_exists($cache_filename)) {
         return $this->pointList[$member_srl] = trim(FileHandler::readFile($cache_filename));
     }
     // Get from the DB
     $args = new stdClass();
     $args->member_srl = $member_srl;
     $output = executeQuery('point.getPoint', $args);
     if (isset($output->data->member_srl)) {
         $point = (int) $output->data->point;
         $this->pointList[$member_srl] = $point;
         if (!is_dir($path)) {
             FileHandler::makeDir($path);
         }
         FileHandler::writeFile($cache_filename, $point);
         return $point;
     }
     return 0;
 }
Пример #11
1
 function __construct($name)
 {
     $this->folder = TEMP_FOLDER . '/' . $name;
     if (!is_dir($this->folder)) {
         mkdir($this->folder);
     }
 }
Пример #12
1
 public static function createSymbolicLink($rootDir = null)
 {
     IS_MULTI_MODULES || exit('please set is_multi_modules => true');
     $deper = Request::isCli() ? PHP_EOL : '<br />';
     echo "{$deper}**************************create link start!*********************{$deper}";
     echo '|' . str_pad('', 64, ' ', STR_PAD_BOTH) . '|';
     is_null($rootDir) && ($rootDir = ROOT_PATH . DIRECTORY_SEPARATOR . 'web');
     is_dir($rootDir) || mkdir($rootDir, true, 0700);
     //modules_static_path_name
     // 递归遍历目录
     $dirIterator = new \DirectoryIterator(APP_MODULES_PATH);
     foreach ($dirIterator as $file) {
         if (!$file->isDot() && $file->isDir()) {
             $resourceDir = $file->getPathName() . DIRECTORY_SEPARATOR . Config::get('modules_static_path_name');
             if (is_dir($resourceDir)) {
                 $distDir = ROOT_PATH . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . $file->getFilename();
                 $cmd = Request::operatingSystem() ? "mklink /d {$distDir} {$resourceDir}" : "ln -s {$resourceDir} {$distDir}";
                 exec($cmd, $result);
                 $tip = "create link Application [{$file->getFilename()}] result : [" . (is_dir($distDir) ? 'true' : 'false') . "]";
                 $tip = str_pad($tip, 64, ' ', STR_PAD_BOTH);
                 print_r($deper . '|' . $tip . '|');
             }
         }
     }
     echo $deper . '|' . str_pad('', 64, ' ', STR_PAD_BOTH) . '|';
     echo "{$deper}****************************create link end!**********************{$deper}";
 }
Пример #13
1
 public function getAllClassNames()
 {
     if (null === $this->classCache) {
         $this->initialize();
     }
     $classes = array();
     if ($this->paths) {
         foreach ((array) $this->paths as $path) {
             if (!is_dir($path)) {
                 throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
             }
             $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::LEAVES_ONLY);
             foreach ($iterator as $file) {
                 $fileName = $file->getBasename($this->fileExtension);
                 if ($fileName == $file->getBasename() || $fileName == $this->globalBasename) {
                     continue;
                 }
                 // NOTE: All files found here means classes are not transient!
                 if (isset($this->prefixes[$path])) {
                     $classes[] = $this->prefixes[$path] . '\\' . str_replace('.', '\\', $fileName);
                 } else {
                     $classes[] = str_replace('.', '\\', $fileName);
                 }
             }
         }
     }
     return array_merge($classes, array_keys($this->classCache));
 }
 public function submitInfo()
 {
     $this->load->model("settings_model");
     // Gather the values
     $values = array('nickname' => htmlspecialchars($this->input->post("nickname")), 'location' => htmlspecialchars($this->input->post("location")));
     // Change language
     if ($this->config->item('show_language_chooser')) {
         $values['language'] = $this->input->post("language");
         if (!is_dir("application/language/" . $values['language'])) {
             die("3");
         } else {
             $this->user->setLanguage($values['language']);
             $this->plugins->onSetLanguage($this->user->getId(), $values['language']);
         }
     }
     // Remove the nickname field if it wasn't changed
     if ($values['nickname'] == $this->user->getNickname()) {
         $values = array('location' => $this->input->post("location"));
     } elseif (strlen($values['nickname']) < 4 || strlen($values['nickname']) > 14 || !preg_match("/[A-Za-z0-9]*/", $values['nickname'])) {
         die(lang("nickname_error", "ucp"));
     } elseif ($this->internal_user_model->nicknameExists($values['nickname'])) {
         die("2");
     }
     if (strlen($values['location']) > 32 && !ctype_alpha($values['location'])) {
         die(lang("location_error", "ucp"));
     }
     $this->settings_model->saveSettings($values);
     $this->plugins->onSaveSettings($this->user->getId(), $values);
     die("1");
 }
 /**
  * Run paths migrations
  *
  * @return void
  */
 protected function runPathsMigration()
 {
     $_fileService = new Filesystem();
     $_tmpPath = app_path('storage') . DIRECTORY_SEPARATOR . 'migrations';
     if (!is_dir($_tmpPath) && !$_fileService->exists($_tmpPath)) {
         $_fileService->mkdir($_tmpPath);
     }
     $this->info("Gathering migration files to {$_tmpPath}");
     // Copy all files to storage/migrations
     foreach ($this->migrationList as $migration) {
         $_fileService->mirror($migration['path'], $_tmpPath);
     }
     //call migrate command on temporary path
     $this->info("Migrating...");
     $opts = array('--path' => ltrim(str_replace(base_path(), '', $_tmpPath), '/'));
     if ($this->input->getOption('force')) {
         $opts['--force'] = true;
     }
     if ($this->input->getOption('database')) {
         $opts['--database'] = $this->input->getOption('database');
     }
     $this->call('migrate', $opts);
     // Delete all temp migration files
     $this->info("Cleaning temporary files");
     $_fileService->remove($_tmpPath);
     // Done
     $this->info("DONE!");
 }
Пример #16
0
function chmod_R($path, $filemode)
{
    if (!is_dir($path)) {
        return chmod($path, $filemode);
    }
    $dh = opendir($path);
    while ($file = readdir($dh)) {
        if ($file != '.' && $file != '..') {
            $fullpath = $path . '/' . $file;
            if (!is_dir($fullpath)) {
                if (!chmod($fullpath, $filemode)) {
                    return FALSE;
                }
            } else {
                if (!chmod_R($fullpath, $filemode)) {
                    return FALSE;
                }
            }
        }
    }
    closedir($dh);
    if (chmod($path, $filemode)) {
        return true;
    } else {
        return false;
    }
}
Пример #17
0
/**
 * Returns an array of found directories
 *
 * This function checks every found directory if they match either $uid or $gid, if they do
 * the found directory is valid. It uses recursive function calls to find subdirectories. Due
 * to the recursive behauviour this function may consume much memory.
 *
 * @param  string   path       The path to start searching in
 * @param  integer  uid        The uid which must match the found directories
 * @param  integer  gid        The gid which must match the found direcotries
 * @param  array    _fileList  recursive transport array !for internal use only!
 * @return array    Array of found valid pathes
 *
 * @author Martin Burchert  <*****@*****.**>
 * @author Manuel Bernhardt <*****@*****.**>
 */
function findDirs($path, $uid, $gid)
{
    $list = array($path);
    $_fileList = array();
    while (sizeof($list) > 0) {
        $path = array_pop($list);
        $path = makeCorrectDir($path);
        $dh = opendir($path);
        if ($dh === false) {
            standard_error('cannotreaddir', $path);
            return null;
        } else {
            while (false !== ($file = @readdir($dh))) {
                if ($file == '.' && (fileowner($path . '/' . $file) == $uid || filegroup($path . '/' . $file) == $gid)) {
                    $_fileList[] = makeCorrectDir($path);
                }
                if (is_dir($path . '/' . $file) && $file != '..' && $file != '.') {
                    array_push($list, $path . '/' . $file);
                }
            }
            @closedir($dh);
        }
    }
    return $_fileList;
}
 /**
  * @param  EntityMapping $modelMapping
  * @param  string        $namespace
  * @param  string        $path
  * @param  bool          $override
  * @return void
  */
 public function generate(EntityMapping $modelMapping, $namespace, $path, $override = false)
 {
     $abstractNamespace = $namespace . '\\Base';
     if (!is_dir($path)) {
         mkdir($path, 0777, true);
     }
     $abstractPath = $path . DIRECTORY_SEPARATOR . 'Base';
     if (!is_dir($abstractPath)) {
         mkdir($abstractPath, 0777, true);
     }
     $abstracClassName = 'Abstract' . $modelMapping->getName();
     $classPath = $path . DIRECTORY_SEPARATOR . $modelMapping->getName() . '.php';
     $abstractClassPath = $abstractPath . DIRECTORY_SEPARATOR . $abstracClassName . '.php';
     $nodes = array();
     $nodes = array_merge($nodes, $this->generatePropertyNodes($modelMapping));
     $nodes = array_merge($nodes, $this->generateConstructNodes($modelMapping));
     $nodes = array_merge($nodes, $this->generateMethodNodes($modelMapping));
     $nodes = array_merge($nodes, $this->generateMetadataNodes($modelMapping));
     $nodes = array(new Node\Stmt\Namespace_(new Name($abstractNamespace), array(new Class_('Abstract' . $modelMapping->getName(), array('type' => 16, 'stmts' => $nodes)))));
     $abstractClassCode = $this->phpGenerator->prettyPrint($nodes);
     file_put_contents($abstractClassPath, '<?php' . PHP_EOL . PHP_EOL . $abstractClassCode);
     if (file_exists($classPath) && !$override) {
         return;
     }
     $nodes = array(new Node\Stmt\Namespace_(new Name($namespace), array(new Class_($modelMapping->getName(), array('extends' => new FullyQualified($abstractNamespace . '\\' . $abstracClassName))))));
     $classCode = $this->phpGenerator->prettyPrint($nodes);
     file_put_contents($classPath, '<?php' . PHP_EOL . PHP_EOL . $classCode);
 }
Пример #19
0
 /**
  * Returns if the file can be rendered.
  *
  * @return bool
  */
 public function canRender()
 {
     if (!is_dir($this->getTemplateDir() . $this->getTemplateFile())) {
         return false;
     }
     return is_file($this->getTemplateDir() . $this->getTemplateFile() . DIRECTORY_SEPARATOR . self::FILE_HTML) || is_file($this->getTemplateDir() . $this->getTemplateFile() . DIRECTORY_SEPARATOR . self::FILE_PHTML);
 }
Пример #20
0
Файл: lib.php Проект: LeonB/site
function findFilesHelper($additional, &$files, $term = '', $extensions = array())
{
    $basefolder = __DIR__ . '/../../files/';
    $currentfolder = realpath($basefolder . '/' . $additional);
    $dir = dir($currentfolder);
    $ignored = array('.', '..', '.DS_Store', '.gitignore', '.htaccess');
    while (false !== ($entry = $dir->read())) {
        if (in_array($entry, $ignored) || substr($entry, 0, 2) == '._') {
            continue;
        }
        if (is_file($currentfolder . '/' . $entry) && is_readable($currentfolder . '/' . $entry)) {
            // Check for 'term'..
            if (!empty($term) && strpos(strtolower($currentfolder . '/' . $entry), $term) === false) {
                continue;
                // skip this one..
            }
            // Check for correct extensions..
            if (!empty($extensions) && !in_array(getExtension($entry), $extensions)) {
                continue;
                // Skip files without correct extension..
            }
            if (!empty($additional)) {
                $filename = $additional . '/' . $entry;
            } else {
                $filename = $entry;
            }
            $files[] = $filename;
        }
        if (is_dir($currentfolder . '/' . $entry)) {
            findFilesHelper($additional . '/' . $entry, $files, $term, $extensions);
        }
    }
    $dir->close();
}
 public function getLang()
 {
     $browser_language = $this->http_language();
     $languages = $browser_language[0];
     if (is_dir(DIR_LANGUAGE . $languages[0])) {
         $this->lang = $languages[0];
     } elseif (isset($browser_language[2])) {
         $languages2 = explode(';', $browser_language[2][0]);
         if (is_dir(DIR_LANGUAGE . $languages2[0]) && $languages2[0] != $this->default) {
             $this->lang = $languages2[0];
         } else {
             $this->lang = $this->default;
         }
     } elseif (isset($browser_language[1])) {
         $languages3 = explode(';', $browser_language[1][0]);
         if (is_dir(DIR_LANGUAGE . $languages3[0]) && $languages3[0] != $this->default) {
             $this->lang = $languages3[0];
         } else {
             $this->lang = $this->default;
         }
     } else {
         $this->lang = $this->default;
     }
     return $this->lang;
 }
Пример #22
0
 public function testWebsiteService()
 {
     $website = $this->config->getService('website');
     $this->assertEquals(true, is_dir($website->htdocs()));
     $this->assertEquals('www.example.com', $website->name());
     $this->assertEquals('nginx', $website->webserver());
 }
Пример #23
0
 /**
  * Sets data
  *
  * @param string $key
  * @param string $var
  * @param int $expire
  * @return boolean
  */
 function set($key, $var, $expire = 0)
 {
     $key = $this->get_item_key($key);
     $sub_path = $this->_get_path($key);
     $path = $this->_cache_dir . '/' . $sub_path;
     $sub_dir = dirname($sub_path);
     $dir = dirname($path);
     if (!@is_dir($dir)) {
         if (!w3_mkdir_from($dir, W3TC_CACHE_DIR)) {
             return false;
         }
     }
     $fp = @fopen($path, 'w');
     if (!$fp) {
         return false;
     }
     if ($this->_locking) {
         @flock($fp, LOCK_EX);
     }
     @fputs($fp, $var['content']);
     @fclose($fp);
     if ($this->_locking) {
         @flock($fp, LOCK_UN);
     }
     // some hostings create files with restrictive permissions
     // not allowing apache to read it later
     @chmod($path, 0644);
     $old_entry_path = $path . '.old';
     @unlink($old_entry_path);
     if (w3_is_apache() && isset($var['headers']) && isset($var['headers']['Content-Type']) && substr($var['headers']['Content-Type'], 0, 8) == 'text/xml') {
         file_put_contents(dirname($path) . '/.htaccess', "<IfModule mod_mime.c>\n" . "    RemoveType .html_gzip\n" . "    AddType text/xml .html_gzip\n" . "    RemoveType .html\n" . "    AddType text/xml .html\n" . "</IfModule>");
     }
     return true;
 }
Пример #24
0
 public static function instance()
 {
     if (!Kotwig::$instance) {
         Kotwig::$instance = new static();
         // Load Twig configuration
         Kotwig::$instance->config = Kohana::$config->load('kotwig');
         // Create the the loader
         $views = Kohana::include_paths();
         $look_in = array();
         foreach ($views as $key => $view) {
             $dir = $view . Kotwig::$instance->config->templates;
             if (is_dir($dir)) {
                 $look_in[] = $dir;
             }
         }
         $loader = new Twig_Loader_Filesystem($look_in);
         // Set up Twig
         Kotwig::$instance->twig = new Twig_Environment($loader, Kotwig::$instance->config->environment);
         foreach (Kotwig::$instance->config->extensions as $extension) {
             // Load extensions
             Kotwig::$instance->twig->addExtension(new $extension());
         }
         foreach (Kotwig::$instance->config->globals as $global => $object) {
             // Load globals
             Kotwig::$instance->twig->addGlobal($global, $object);
         }
         foreach (Kotwig::$instance->config->filters as $filter => $object) {
             // Load filters
             Kotwig::$instance->twig->addFilter($filter, $object);
         }
     }
     return Kotwig::$instance;
 }
Пример #25
0
 /**
  * Initialize the provider
  *
  * @return void
  */
 public function initialize()
 {
     $this->options = array_merge($this->defaultConfig, $this->options);
     date_default_timezone_set($this->options['log.timezone']);
     // Finally, create a formatter
     $formatter = new LineFormatter($this->options['log.outputformat'], $this->options['log.dateformat'], false);
     // Create a new directory
     $logPath = realpath($this->app->config('bono.base.path')) . '/' . $this->options['log.path'];
     if (!is_dir($logPath)) {
         mkdir($logPath, 0755);
     }
     // Create a handler
     $stream = new StreamHandler($logPath . '/' . date($this->options['log.fileformat']) . '.log');
     // Set our formatter
     $stream->setFormatter($formatter);
     // Create LogWriter
     $logger = new LogWriter(array('name' => $this->options['log.name'], 'handlers' => array($stream), 'processors' => array(new WebProcessor())));
     // Bind our logger to Bono Container
     $this->app->container->singleton('log', function ($c) {
         $log = new Log($c['logWriter']);
         $log->setEnabled($c['settings']['log.enabled']);
         $log->setLevel($c['settings']['log.level']);
         $env = $c['environment'];
         $env['slim.log'] = $log;
         return $log;
     });
     // Set the writer
     $this->app->config('log.writer', $logger);
 }
Пример #26
0
 protected function rmDir($dir)
 {
     if (is_dir($dir)) {
         chmod($dir, 0777);
         rmdir($dir);
     }
 }
Пример #27
0
function doAction($action)
{
    $id = $_POST['id'];
    $mapFile = "map/" . $id . ".map";
    $offlineFile = "map/offline/" . $id . ".js";
    switch ($action) {
        case "save":
            if (!is_dir("map")) {
                mkdir("map");
                mkdir("map/offline");
            }
            file_put_contents($mapFile, $_POST['data']);
            file_put_contents($offlineFile, "Map.level[" . $id . "]  = " . $_POST['data']);
            return $_POST['data'];
            break;
        case "load":
            if (!empty($_POST['offlineMode'])) {
                return file_get_contents($offlineFile);
            }
            if (file_exists($mapFile)) {
                return file_get_contents($mapFile);
            }
            echo "Echo file not found: " . $mapFile;
            ThrowNotFound();
            break;
    }
}
Пример #28
0
function getElementsData() {
	$elements_dirname = ADMIN_BASE_PATH.'/components/elements';
	if ($elements_dir = opendir($elements_dirname)) {
		$tmpArray = array();
		while (false !== ($dir = readdir($elements_dir))) {
			if (substr($dir,0,1) != "." && is_dir($elements_dirname . '/' . $dir)) {
				$tmpKey = strtolower($dir);
				if (@file_exists($elements_dirname . '/' . $dir . '/metadata.json')) {
					$tmpValue = json_decode(@file_get_contents($elements_dirname . '/' . $dir . '/metadata.json'));
					if ($tmpValue) {
						$tmpArray["$tmpKey"] = $tmpValue;
					}
				}
			}
		}
		closedir($elements_dir);
		if (count($tmpArray)) {
			return $tmpArray;
		} else {
			return false;
		}
	} else {
		echo 'not dir';
		return false;
	}
}
Пример #29
0
 /**
  * Create a new BrowserInfo object for the given user agent string.
  *
  * Instances may not be created directly, use the static newFromUA method instead
  * @param $userAgent string
  */
 protected function parseUserAgent($userAgent)
 {
     $browscapCacheDir = $this->context->getConf()->storage->cacheDir . '/phpbrowscap';
     if (!is_dir($browscapCacheDir)) {
         if (!mkdir($browscapCacheDir, 755)) {
             throw new SwarmException("Cache directory must be writable.");
         }
     }
     /**
      * A Browscap object looks like this (simplified version of the actual object)
      * @source https://github.com/GaretJax/phpbrowscap/wiki/QuickStart
      *
      * stdClass Object (
      *     [Platform] => MacOSX
      *     [Browser] => Safari
      *     [Version] => 3.1
      *     [MajorVer] => 3
      *     [MinorVer] => 1
      * )
      */
     $browscapInstance = new Browscap($browscapCacheDir);
     // Default cache is 5 days...
     $browscapInstance->updateInterval = 3600;
     // 1 hour
     $browscapData = $browscapInstance->getBrowser($userAgent);
     $this->rawUserAgent = $userAgent;
     $this->browscapData = $browscapData;
     return $this;
 }
Пример #30
0
 /**
  * Chmods files and directories recursively to given permissions.
  *
  * @param   string  $path        Root path to begin changing mode [without trailing slash].
  * @param   string  $filemode    Octal representation of the value to change file mode to [null = no change].
  * @param   string  $foldermode  Octal representation of the value to change folder mode to [null = no change].
  *
  * @return  boolean  True if successful [one fail means the whole operation failed].
  *
  * @since   11.1
  */
 public static function setPermissions($path, $filemode = '0644', $foldermode = '0755')
 {
     // Initialise return value
     $ret = true;
     if (is_dir($path)) {
         $dh = opendir($path);
         while ($file = readdir($dh)) {
             if ($file != '.' && $file != '..') {
                 $fullpath = $path . '/' . $file;
                 if (is_dir($fullpath)) {
                     if (!JPath::setPermissions($fullpath, $filemode, $foldermode)) {
                         $ret = false;
                     }
                 } else {
                     if (isset($filemode)) {
                         if (!@chmod($fullpath, octdec($filemode))) {
                             $ret = false;
                         }
                     }
                 }
             }
         }
         closedir($dh);
         if (isset($foldermode)) {
             if (!@chmod($path, octdec($foldermode))) {
                 $ret = false;
             }
         }
     } else {
         if (isset($filemode)) {
             $ret = @chmod($path, octdec($filemode));
         }
     }
     return $ret;
 }