Example #1
1
function do_minify($content)
{
    global $config;
    $c = File::open(__DIR__ . DS . 'states' . DS . 'config.txt')->unserialize();
    $url = $config->protocol . $config->host;
    // Minify HTML
    if (isset($c['html_minifier'])) {
        $config->html_minifier = true;
        Config::set('html_minifier', $config->html_minifier);
        $content = Converter::detractSkeleton($content);
    }
    // Minify URL
    if (isset($c['url_minifier']) && Text::check($content)->has('="' . $url)) {
        $content = str_replace(array('="' . $url . '"', '="' . $url . '/', '="' . $url . '?', '="' . $url . '#'), array('="/"', '="/', '="?', '="#'), $content);
    }
    // Minify Embedded CSS
    if (isset($c['css_minifier'])) {
        $content = preg_replace_callback('#<style(>| .*?>)([\\s\\S]*?)<\\/style>#i', function ($matches) use($config, $c, $url) {
            $css = Converter::detractShell($matches[2]);
            if (isset($c['url_minifier'])) {
                $css = preg_replace('#(?<=[\\s:])(src|url)\\(' . preg_quote($url, '/') . '#', '$1(', $css);
            }
            return '<style' . $matches[1] . $css . '</style>';
        }, $content);
    }
    // Minify Embedded JavaScript
    if (isset($c['js_minifier'])) {
        $content = preg_replace_callback('#<script(>| .*?>)([\\s\\S]*?)<\\/script>#i', function ($matches) {
            $js = Converter::detractSword($matches[2]);
            return '<script' . $matches[1] . $js . '</script>';
        }, $content);
    }
    return $content;
}
Example #2
0
 /**
  * Read a key from the cache
  *
  * @param string $key Identifier for the data
  * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
  * @access public
  */
 function read($key)
 {
     // Modifications by webligo
     $key .= '.php';
     // end modifications
     if ($this->__setKey($key) === false || !$this->__init || !$this->__File->exists()) {
         return false;
     }
     if ($this->settings['lock']) {
         $this->__File->lock = true;
     }
     // Modifications by webligo
     $this->__File->open('rb');
     fgets($this->__File->handle);
     // Strip off die
     $key .= '.php';
     // end modifications
     $time = time();
     $cachetime = intval($this->__File->read(11));
     if ($cachetime !== false && ($cachetime < $time || $time + $this->settings['duration'] < $cachetime)) {
         $this->__File->close();
         return false;
     }
     $data = $this->__File->read(true);
     if ($data !== '' && !empty($this->settings['serialize'])) {
         if ($this->settings['isWindows']) {
             $data = str_replace('\\\\\\\\', '\\', $data);
         }
         $data = unserialize((string) $data);
     }
     $this->__File->close();
     return $data;
 }
Example #3
0
 private function _rawParse($filename, $attributes)
 {
     App::import('Vendor', 'import.excelreader/excelreader');
     $buffer = array();
     if (file_exists($filename)) {
         if (isset($attributes['delimiter']) && (isset($attributes['excel_reader']) && $attributes['excel_reader'])) {
             $xl = new ExcelReader();
             $xl->read($filename);
             $tmp_array = $xl->toArray();
             for ($i = 0; $i < 10; $i++) {
                 if (isset($tmp_array[$i])) {
                     $buffer[] = implode("\t", $tmp_array[$i]);
                 }
             }
         } else {
             $file = new File($filename);
             if ($file->open('r', true)) {
                 for ($i = 0; $i < 10; $i++) {
                     if (isset($attributes['delimiter']) && $attributes['delimiter'] != "") {
                         if (isset($attributes['qualifier']) && $attributes['qualifier'] != "") {
                             $buffer[] = @fgetcsv($file->handle, null, $attributes['delimiter'], $attributes['qualifier']);
                         } else {
                             $buffer[] = @fgetcsv($file->handle, null, $attributes['delimiter']);
                         }
                     }
                 }
                 $file->close();
             } else {
                 // Error
             }
         }
     }
     return $buffer;
 }
 function _write()
 {
     // Load library
     App::uses('File', 'Utility');
     $translations = $this->Translation->find('all');
     $trunced = array();
     foreach ($translations as $t) {
         $t = $t['Translation'];
         if (empty($t['value'])) {
             continue;
         }
         $lang = $t['language'];
         $domain = $t['domain'];
         $filePath = APP . 'Locale' . DS . $lang . DS . 'LC_MESSAGES' . DS . $domain . '.po';
         $file = new File($filePath);
         if (!isset($trunced[$filePath])) {
             $file->open('w');
             $trunced[$filePath] = true;
             $file->close();
         }
         $append = 'msgid "' . str_replace('"', '\\"', $t['name']) . "\"\n";
         $append .= 'msgstr "' . str_replace('"', '\\"', $t['value']) . "\"\n\n";
         $file->write($append, 'a');
     }
 }
Example #5
0
 /**
  * Create a new file by copying the contents of an existing
  * file into this directory under the given name. Unlike the
  * link() method, this creates a separate file. Returns the
  * directory entry.
  *
  * @param File $source  source file to copy
  * @param string $name  destination file name
  *
  * @return DirectoryEntry  created DirectoryEntry object
  */
 public function copy(File $source, $name, $description = '')
 {
     // Copy single file?
     if ($source->storage_id != '') {
         $new_entry = $this->createFile($name, $description);
         $new_file = $new_entry->file;
         // copy contents
         $source_fp = $source->open('rb');
         $dest_fp = $new_file->open('wb');
         stream_copy_to_stream($source_fp, $dest_fp);
         fclose($dest_fp);
         fclose($source_fp);
         // copy attributes
         $new_file->filename = $source->filename;
         $new_file->restricted = $source->restricted;
         $new_file->mime_type = $source->mime_type;
         $new_file->size = $source->size;
         $new_file->update();
         return $new_entry;
     }
     //COPY directory
     $newFolder = $this->mkdir($name, $description);
     // Todo: This probably could be more sormy
     $folder = StudipDirectory::get($newFolder->file_id);
     $folder->filename = $newFolder->name;
     $folder->store();
     foreach ($source->listFiles() as $entry) {
         $folder->copy($entry->file, $entry->name, $entry->description);
     }
     return $folder;
 }
Example #6
0
 protected function _rawParse()
 {
     if (file_exists($this->filename)) {
         if (isset($this->options['delimiter']) && (isset($this->options['excel_reader']) && $this->options['excel_reader'])) {
             $xl = new ExcelReader();
             $xl->read($this->filename);
             $tmp_array = $xl->toArray();
             for ($i = 0; $i < 10; $i++) {
                 if (isset($tmp_array[$i])) {
                     $buffer[] = implode("\t", $tmp_array[$i]);
                 }
             }
         } else {
             $file = new File($this->filename);
             if ($file->open('r', true)) {
                 for ($i = 0; $i < 10; $i++) {
                     if (isset($this->options['delimiter']) && $this->options['delimiter'] != "") {
                         if (isset($this->options['qualifier']) && $this->options['qualifier'] != "") {
                             $buffer[] = @fgetcsv($file->handle, null, $this->options['delimiter'], $this->options['qualifier']);
                         } else {
                             $buffer[] = @fgetcsv($file->handle, null, $this->options['delimiter']);
                         }
                     }
                 }
                 $file->close();
             } else {
                 // Error
             }
         }
     }
     return $buffer;
 }
Example #7
0
 public static function open($file)
 {
     $content = parent::open($file);
     if ($content === false) {
         return false;
     }
     return json_decode($content, true);
 }
Example #8
0
 private function createFile()
 {
     //A valid test for file creation requires the absence of a file.
     $this->assertFalse(file_exists("test.csv"));
     $test = new File("test");
     $test->open();
     return $test;
 }
Example #9
0
 /**
  * Setup output source
  *
  * @param $datasource datasource name
  * @param $save path to save folder
  */
 function _setupOutput($datasource, $save)
 {
     if (empty($save)) {
         return false;
     }
     $now = time();
     $path = realpath($save) . DS . strftime($this->file_prefix, $now) . $datasource . strftime($this->file_suffix, $now);
     $this->File = new File($path, false, 0666);
     return $this->File->open('w');
 }
Example #10
0
/**
 * Cache Killer
 * ------------
 *
 * Add global cache killer for article(s) and page(s).
 *
 */
function do_remove_cache()
{
    global $config;
    File::open(CACHE . DS . 'sitemap.cache')->delete();
    File::open(CACHE . DS . 'feed.cache')->delete();
    File::open(CACHE . DS . 'feeds.cache')->delete();
    foreach (glob(CACHE . DS . '{feed,feeds}.*.cache', GLOB_NOSORT | GLOB_BRACE) as $cache) {
        File::open($cache)->delete();
    }
}
Example #11
0
 public static function info($folder = null, $array = false)
 {
     $config = Config::get();
     $speak = Config::speak();
     // Check whether the localized "about" file is available
     if (!($info = File::exist(PLUGIN . DS . $folder . DS . 'about.' . $config->language . '.txt'))) {
         $info = PLUGIN . DS . $folder . DS . 'about.txt';
     }
     $default = 'Title' . S . ' ' . ucwords(Text::parse($folder, '->text')) . "\n" . 'Author' . S . ' ' . $speak->anon . "\n" . 'URL' . S . ' #' . "\n" . 'Version' . S . ' 0.0.0' . "\n" . "\n" . SEPARATOR . "\n" . "\n" . Config::speak('notify_not_available', $speak->description);
     $info = Text::toPage(File::open($info)->read($default), 'content', 'plugin:');
     return $array ? $info : Mecha::O($info);
 }
Example #12
0
 /**
  * @depends testFileWrite
  */
 public function testFileRead()
 {
     $file = File::open($this->path, 'r');
     $buffer = '';
     while (!$file->eof()) {
         $buffer .= $file->fgets();
     }
     $this->assertEquals('foobar', $buffer);
     // we are in read mode we cant write
     $bytes = $file->fwrite('something');
     $this->assertEquals(0, $bytes);
     unset($file);
 }
Example #13
0
/**
 * Cache Killer
 * ------------
 */
function do_remove_cache()
{
    global $config, $c_cache;
    foreach ($c_cache->path as $path => $expire) {
        $path = str_replace(array('(:any)', '(:num)', '(:all)', '(', ')', '|', '/', ':'), array('*', '[0-9]*', '*', '{', '}', ',', '.', '.'), $path) . '.cache';
        if ($cache = File::exist(CACHE . DS . $path)) {
            File::open($cache)->delete();
        } else {
            foreach (glob(CACHE . DS . $path, GLOB_NOSORT | GLOB_BRACE) as $cache) {
                File::open($cache)->delete();
            }
        }
    }
}
 private function generate_cache_file()
 {
     try {
         $cache_file = new File($this->cache_file_path);
         $cache_file->open(File::WRITE);
         $cache_file->lock();
         $cache_file->write($this->get_parsed_content());
         $cache_file->unlock();
         $cache_file->close();
         $cache_file->change_chmod(0666);
     } catch (IOException $ex) {
         throw new TemplateLoadingException('The template file cache couldn\'t been written due to this problem: ' . $ex->getMessage());
     }
 }
Example #15
0
	/**
	 * Recupera o Mime-type de um arquivo
	 * @param File $file
	 * @return string
	 */
	public function getMimeType( File $file ) {
		$ret = false;
		$iterator = $this->getIterator();
		$parser = new MagicParser( $file , $this );

		if (  !$file->isOpened() ) $file->open( 'r' );

		for ( $iterator->rewind() ; $iterator->valid() ; $iterator->next() ) {
			if ( ( $ret = $parser->parse( $iterator ) ) !== false ) {
				break;
			}
		}

		return $ret;
	}
Example #16
0
 /**
  * @covers mychaelstyle\storage\File::rollback
  * @covers mychaelstyle\storage\Storage::rollback
  * @covers mychaelstyle\storage\File::initialize
  * @covers mychaelstyle\storage\File::clean
  * @covers mychaelstyle\storage\File::remove
  * @covers mychaelstyle\storage\File::isOpened
  * @covers mychaelstyle\storage\File::checkOpen
  */
 public function testRollback()
 {
     // remove first
     $this->object->remove();
     // create new storage without transaction
     $this->storage = new \mychaelstyle\Storage($this->dsn, $this->options, false);
     $this->object = $this->storage->createFile($this->uri, $this->options, false);
     // none transaxtion
     $expected = $this->test_string;
     $this->object->open('w');
     $this->object->write($expected);
     $this->object->close();
     $localPath = $this->getLocalPathUsingUri($this->dsn, $this->uri);
     $this->assertFalse(file_exists($localPath));
     $this->object->rollback();
     $this->assertFalse(file_exists($localPath));
 }
 function saveChanges()
 {
     $_POST->setType('filename', 'string');
     $_POST->setType('cropimgx', 'numeric');
     $_POST->setType('cropimgy', 'numeric');
     $_POST->setType('cropimgw', 'numeric');
     $_POST->setType('cropimgh', 'numeric');
     $_REQUEST->setType('mkcopy', 'string');
     if ($_REQUEST['filename']) {
         if ($_REQUEST['mkcopy']) {
             if ($_POST['filename'] != $this->basename && $_POST['filename']) {
                 if (!file_exists($this->dirname . '/' . $_POST['filename'])) {
                     $p = $this->dirname . '/' . $_POST['filename'];
                 } else {
                     Flash::queue(__('File exists. Please give another name or delete the conflicting file. Your changes were not saved.'), 'warning');
                     break;
                 }
             } else {
                 $nrofcopies = count(glob(substr($this->path, 0, -(strlen($this->extension) + 1)) . '_copy*'));
                 if ($nrofcopies == 0) {
                     $nrofcopies = '';
                 }
                 $p = substr($this->path, 0, -(strlen($this->extension) + 1)) . '_copy' . ($nrofcopies + 1) . substr($this->path, -(strlen($this->extension) + 1));
             }
             touch($p);
             $copy = File::open($p);
         } else {
             if ($_POST['filename'] != $this->basename) {
                 $this->rename($_POST['filename']);
             }
             $p = $this->path;
             $img = new Image($this->path);
             if ($_POST['cropimgw'] && $_POST['cropimgh']) {
                 $width = $img->width();
                 $s = $width / min($width, 400);
                 $img->crop(round($s * $_POST['cropimgx']), round($s * $_POST['cropimgy']), round($s * $_POST['cropimgw']), round($s * $_POST['cropimgh']));
             }
             if ($_REQUEST['imgrot']) {
                 $img->rotate($_REQUEST['imgrot']);
             }
             $img->save($p);
             Flash::queue(__('Your changes were saved'));
         }
     }
 }
function do_twitter_cards()
{
    $config = Config::get();
    $twitter_cards_config = File::open(__DIR__ . DS . 'states' . DS . 'config.txt')->unserialize();
    $T2 = str_repeat(TAB, 2);
    echo O_BEGIN . $T2 . '<!-- Start Twitter Cards -->' . NL;
    echo $T2 . '<meta name="twitter:card" content="' . (isset($config->{$config->page_type}->image) && $config->{$config->page_type}->image !== Image::placeholder() ? 'summary_large_image' : 'summary') . '"' . ES . NL;
    echo $T2 . '<meta name="twitter:site" content="@' . $twitter_cards_config['twitter_site'] . '"' . ES . NL;
    echo $T2 . '<meta name="twitter:creator" content="@' . $twitter_cards_config['twitter_creator'] . '"' . ES . NL;
    echo $T2 . '<meta name="twitter:title" content="' . Text::parse($config->page_title, '->text') . '"' . ES . NL;
    echo $T2 . '<meta name="twitter:url" content="' . Filter::colon('twitter:url', $config->url_current) . '"' . ES . NL;
    if (isset($config->{$config->page_type}->description)) {
        $config->description = $config->{$config->page_type}->description;
    }
    echo $T2 . '<meta name="twitter:description" content="' . Text::parse($config->description, '->text') . '"' . ES . NL;
    if ($config->page_type !== '404' && isset($config->{$config->page_type}->image)) {
        echo $T2 . '<meta name="twitter:image" content="' . $config->{$config->page_type}->image . '"' . ES . NL;
    } else {
        echo $T2 . '<meta name="twitter:image" content="' . $config->url . '/favicon.ico"' . ES . NL;
    }
    echo $T2 . '<!-- End Twitter Cards -->' . O_END;
}
 /**
  * testLastChange method
  *
  * @return void
  */
 public function testLastChange()
 {
     $someFile = new File(TMP . 'some_file.txt', false);
     $this->assertFalse($someFile->lastChange());
     $this->assertTrue($someFile->open('r+'));
     $this->assertWithinMargin($someFile->lastChange(), time(), 2);
     $someFile->write('something');
     $this->assertWithinMargin($someFile->lastChange(), time(), 2);
     $someFile->close();
     $someFile->delete();
 }
Example #20
0
 /**
  * Reads out a file, and echos the content to the client.
  *
  * @param File $file File object
  * @return boolean True is whole file is echoed successfully or false if client connection is lost in between
  */
 protected function _sendFile($file)
 {
     $compress = $this->outputCompressed();
     $file->open('rb');
     while (!feof($file->handle)) {
         if (!$this->_isActive()) {
             $file->close();
             return false;
         }
         set_time_limit(0);
         echo fread($file->handle, 8192);
         if (!$compress) {
             $this->_flushBuffer();
         }
     }
     $file->close();
     return true;
 }
Example #21
0
/**
 * Shield Attacher
 * ---------------
 */
Route::accept($config->manager->slug . '/shield/(attach|eject)/id:(:any)', function ($path = "", $slug = "") use($config, $speak) {
    $new_config = Get::state_config();
    $new_config['shield'] = $path === 'attach' ? $slug : 'normal';
    File::serialize($new_config)->saveTo(STATE . DS . 'config.txt', 0600);
    $G = array('data' => array('id' => $slug, 'action' => $path));
    $mode = $path === 'eject' ? 'eject' : 'mount';
    Notify::success(Config::speak('notify_success_updated', $speak->shield));
    Weapon::fire('on_shield_update', array($G, $G));
    Weapon::fire('on_shield_' . $mode, array($G, $G));
    Weapon::fire('on_shield_' . md5($slug) . '_update', array($G, $G));
    Weapon::fire('on_shield_' . md5($slug) . '_' . $mode, array($G, $G));
    foreach (glob(SYSTEM . DS . 'log' . DS . 'asset.*.log', GLOB_NOSORT) as $asset_cache) {
        File::open($asset_cache)->delete();
    }
    Guardian::kick($config->manager->slug . '/shield/' . $slug);
});
/**
 * Shield Backup
 * -------------
 */
Route::accept($config->manager->slug . '/shield/backup/id:(:any)', function ($folder = "") use($config, $speak) {
    $name = $folder . '.zip';
    Package::take(SHIELD . DS . $folder)->pack(ROOT . DS . $name, true);
    $G = array('data' => array('path' => ROOT . DS . $name, 'file' => ROOT . DS . $name));
    Weapon::fire('on_backup_construct', array($G, $G));
    Guardian::kick($config->manager->slug . '/backup/send:' . $name);
});
Example #22
0
 /**
  * Tests a file's contents against magic items
  *
  * @param string $file Absolute path to a file
  * @param array $items
  * @return mixed A string containing the MIME type of the file or false if no pattern matched
  * @access private
  */
 function __test($file, $items)
 {
     $File = new File($file);
     if (!$File->readable()) {
         return false;
     }
     $File->open('rb');
     foreach ($items as $item) {
         if ($result = $this->__testRecursive($File, $item)) {
             return $result;
         }
     }
     return false;
 }
Example #23
0
     $menus[$speak->config] = array('icon' => 'cogs', 'url' => $config->manager->slug . '/config', 'stack' => 9);
     $menus[$speak->comment] = array('icon' => 'comments', 'url' => $config->manager->slug . '/comment', 'count' => $total, 'stack' => 9.029999999999999);
     $menus[$speak->menu] = array('icon' => 'bars', 'url' => $config->manager->slug . '/menu', 'stack' => 9.050000000000001);
     $menus[$speak->field] = array('icon' => 'th-list', 'url' => $config->manager->slug . '/field', 'stack' => 9.07);
     $menus[$speak->shortcode] = array('icon' => 'coffee', 'url' => $config->manager->slug . '/shortcode', 'stack' => 9.08);
     $menus[$speak->shield] = array('icon' => 'shield', 'url' => $config->manager->slug . '/shield', 'stack' => 9.09);
     $menus[$speak->plugin] = array('icon' => 'plug', 'url' => $config->manager->slug . '/plugin', 'stack' => 9.1);
     $menus[$speak->cache] = array('icon' => 'clock-o', 'url' => $config->manager->slug . '/cache', 'stack' => 9.109999999999999);
     $bars[$speak->config] = array('icon' => 'cog', 'url' => $config->manager->slug . '/config', 'stack' => 9.01);
     if ($errors = File::exist(ini_get('error_log'))) {
         $total = 0;
         if (filesize($errors) > MAX_ERROR_FILE_SIZE) {
             File::open($errors)->delete();
             $total = '&infin;';
         }
         foreach (explode("\n", File::open($errors)->read()) as $message) {
             if (trim($message) !== "") {
                 $total++;
             }
         }
         $menus[$speak->error] = array('icon' => 'exclamation-triangle', 'url' => $config->manager->slug . '/error', 'count' => $total, 'stack' => 9.130000000000001);
     }
 }
 if ($config->page_type !== '404' && $config->is->post) {
     $type = $config->page_type;
     $id = $config->{$type}->id;
     $text = Config::speak($type);
     $text_repair = Config::speak('manager._this_', array($speak->edit, $text));
     $text_kill = Config::speak('manager._this_', array($speak->delete, $text));
     $bars[$text] = array('icon' => 'plus', 'url' => $config->manager->slug . '/' . $type . '/ignite', 'description' => Config::speak('manager.title_new_', $text), 'stack' => 9.029999999999999);
     $bars[$speak->edit] = array('icon' => 'pencil', 'url' => $config->manager->slug . '/' . $type . '/repair/id:' . $id, 'description' => $text_repair, 'stack' => 9.039999999999999);
Example #24
0
 /**
  * Reads out a file, and echos the content to the client.
  *
  * @param File $file File object
  * @param array $range The range to read out of the file.
  * @return bool True is whole file is echoed successfully or false if client connection is lost in between
  */
 protected function _sendFile($file, $range)
 {
     $compress = $this->outputCompressed();
     $file->open('rb');
     $end = $start = false;
     if ($range) {
         list($start, $end) = $range;
     }
     if ($start !== false) {
         $file->offset($start);
     }
     $bufferSize = 8192;
     set_time_limit(0);
     session_write_close();
     while (!feof($file->handle)) {
         if (!$this->_isActive()) {
             $file->close();
             return false;
         }
         $offset = $file->offset();
         if ($end && $offset >= $end) {
             break;
         }
         if ($end && $offset + $bufferSize >= $end) {
             $bufferSize = $end - $offset + 1;
         }
         echo fread($file->handle, $bufferSize);
         if (!$compress) {
             $this->_flushBuffer();
         }
     }
     $file->close();
     return true;
 }
Example #25
0
<?php

/**
 * Error Log
 * ---------
 */
Route::accept($config->manager->slug . '/error', function () use($config, $speak) {
    Config::set(array('page_title' => $speak->errors . $config->title_separator . $config->manager->title, 'cargo' => 'cargo.error.php'));
    Shield::lot(array('segment' => 'error', 'content' => File::open(ini_get('error_log'))->read(false)))->attach('manager');
});
/**
 * Error Log Killer
 * ----------------
 */
Route::accept($config->manager->slug . '/error/kill', function () use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    $errors = LOG . DS . 'errors.log';
    $G = array('data' => array('content' => File::open($errors)->read()));
    File::open($errors)->delete();
    Weapon::fire('on_error_destruct', array($G, $G));
    Notify::success(Config::speak('notify_success_deleted', $speak->file));
    Guardian::kick(File::D($config->url_current));
});
 /**
  * .htaccess にスマートURLの設定を書きこむ
  *
  * @param	string	$path
  * @param	array	$rewriteSettings
  * @return	boolean
  * @access	protected
  */
 function _writeSmartUrlToHtaccess($path, $smartUrl, $type, $rewriteBase = '/')
 {
     //======================================================================
     // WindowsのXAMPP環境では、何故か .htaccess を書き込みモード「w」で開けなかったの
     // で、追記モード「a」で開くことにした。そのため、実際の書き込み時は、 ftruncate で、
     // 内容をリセットし、ファイルポインタを先頭に戻している。
     //======================================================================
     $rewritePatterns = array("/\n[^\n#]*RewriteEngine.+/i", "/\n[^\n#]*RewriteBase.+/i", "/\n[^\n#]*RewriteCond.+/i", "/\n[^\n#]*RewriteRule.+/i");
     switch ($type) {
         case 'root':
             $rewriteSettings = array('RewriteEngine on', 'RewriteBase ' . $this->getRewriteBase($rewriteBase), 'RewriteRule ^$ ' . APP_DIR . '/webroot/ [L]', 'RewriteRule (.*) ' . APP_DIR . '/webroot/$1 [L]');
             break;
         case 'webroot':
             $rewriteSettings = array('RewriteEngine on', 'RewriteBase ' . $this->getRewriteBase($rewriteBase), 'RewriteCond %{REQUEST_FILENAME} !-d', 'RewriteCond %{REQUEST_FILENAME} !-f', 'RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]');
             break;
     }
     $file = new File($path);
     $file->open('a+');
     $data = $file->read();
     foreach ($rewritePatterns as $rewritePattern) {
         $data = preg_replace($rewritePattern, '', $data);
     }
     if ($smartUrl) {
         $data .= "\n" . implode("\n", $rewriteSettings);
     }
     ftruncate($file->handle, 0);
     if (!$file->write($data)) {
         $file->close();
         return false;
     }
     $file->close();
 }
 private static function generatorAssemblyFile($classes, $outFile, $code, $cacheKey)
 {
     /*{{{*/
     $assemblyfile = new File($outFile);
     $assemblyfile->open("w+");
     $arrayCode = "";
     foreach ($classes as $key => $value) {
         $arrayCode .= "\t\t\t\"{$key}\" => \t\t\t\"{$value}\",\n";
     }
     $cacheKey = $cacheKey . ":" . time();
     $code = str_replace("___DATA___", $arrayCode, $code);
     $code = str_replace("___CACHEKEY___", $cacheKey, $code);
     $assemblyfile->write($code);
 }
Example #28
0
 /**
  * Retrieves the next spool entry.
  *
  * @return  io.File spoolfile next spoolfile. Its opened in read/write mode.
  */
 public function getNextSpoolEntry()
 {
     if (false !== ($entry = $this->_hTodo->getEntry())) {
         $f = new File($this->_hTodo->getURI() . DIRECTORY_SEPARATOR . $entry);
         $f->open(File::READWRITE);
     }
     return $f;
 }
Example #29
0
        if (!File::exist(ASSET . DS . $name)) {
            Shield::abort();
            // File not found!
        } else {
            $deletes = array($name);
        }
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . (count($deletes) === 1 ? File::B($name) : $speak->assets) . $config->title_separator . $config->manager->title, 'files' => $deletes, 'cargo' => DECK . DS . 'workers' . DS . 'kill.asset.php'));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $info_path = array();
        $is_folder_or_file = count($deletes) === 1 && is_dir(ASSET . DS . $deletes[0]) ? 'folder' : 'file';
        foreach ($deletes as $file_to_delete) {
            $_path = ASSET . DS . $file_to_delete;
            $info_path[] = $_path;
            File::open($_path)->delete();
        }
        $P = array('data' => array('files' => $info_path));
        Notify::success(Config::speak('notify_' . $is_folder_or_file . '_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>'));
        Weapon::fire('on_asset_update', array($P, $P));
        Weapon::fire('on_asset_destruct', array($P, $P));
        Guardian::kick($config->manager->slug . '/asset/1' . $p);
    } else {
        Notify::warning(count($deletes) === 1 ? Config::speak('notify_confirm_delete_', '<code>' . File::path($name) . '</code>') : $speak->notify_confirm_delete);
    }
    Shield::lot('segment', 'asset')->attach('manager', false);
});
/**
 * Multiple Asset Killer
 * ---------------------
 */
Example #30
0
<?php

$custom_ = CUSTOM . DS . Date::format($task_connect_page->date->W3C, 'Y-m-d-H-i-s');
if (file_exists($custom_ . $extension_o)) {
    Weapon::fire('on_custom_update', array($G, $P));
    if (trim(File::open($custom_ . $extension_o)->read()) === "" || trim(File::open($custom_ . $extension_o)->read()) === SEPARATOR || empty($css) && empty($js) || $css === $task_connect_page_css && $js === $task_connect_page_js) {
        // Always delete empty custom CSS and JavaScript file(s) ...
        File::open($custom_ . $extension_o)->delete();
        Weapon::fire('on_custom_destruct', array($G, $P));
    } else {
        Page::content($css)->content($js)->saveTo($custom_ . $extension_o);
        File::open($custom_ . $extension_o)->renameTo(Date::format($date, 'Y-m-d-H-i-s') . $extension);
        Weapon::fire('on_custom_repair', array($G, $P));
    }
} else {
    if (!empty($css) && $css !== $task_connect_page_css || !empty($js) && $js !== $task_connect_page_js) {
        Page::content($css)->content($js)->saveTo(CUSTOM . DS . Date::format($date, 'Y-m-d-H-i-s') . $extension_o);
        Weapon::fire('on_custom_update', array($G, $P));
        Weapon::fire('on_custom_construct', array($G, $P));
    }
}