/** * Write content to file * @param string $path * @param string $content */ protected function writeFile($path, $content) { if (!in_array(SafeStream::PROTOCOL, stream_get_wrappers())) { SafeStream::register(); } file_put_contents("safe://" . $path, $content); }
/** * Returns array in format $filename => array($todos) * @uses SafeStream */ protected function generateTodo() { if (count($this->todoMask) === 0) { throw new InvalidStateException('No todo mask specified for TodoPanel.'); } $todoMask = '(?:' . implode('|', $this->todoMask) . ')'; @SafeStream::register(); //intentionally @ (prevents multiple registration warning) $items = array(); foreach ($this->scanDirs as $dir) { if (!is_string($dir)) { continue; } //only strings will be handled further $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); foreach ($iterator as $path => $match) { if (preg_match($this->ignorePCRE, $path)) { continue; } $phpBlock = FALSE; $latteBlock = FALSE; $htmlBlock = FALSE; foreach (file("safe://" . $path) as $n => $line) { $slashespos = strpos($line, '//'); $dashpos = strpos($line, '#'); if ($slashespos !== FALSE || $dashpos !== FALSE) { $lcpos = min($slashespos, $dashpos); //line comment starting position if ($lcpos === FALSE) { $lcpos = max($slashespos, $dashpos); } if (preg_match('~\\W' . $todoMask . '[\\s:;]+(?P<todo>.*)~i', substr($line, $lcpos), $found)) { $todo = trim($found['todo']); $items[$path][$n + 1] = !empty($todo) ? $todo : trim(substr($line, 0, $lcpos)); } continue; } if (!$phpBlock && strpos($line, '/*') !== FALSE) { $phpBlock = TRUE; } elseif (!$latteBlock && strpos($line, '{*') !== FALSE) { $latteBlock = TRUE; } elseif (!$htmlBlock && strpos($line, '<!--') !== FALSE) { $htmlBlock = TRUE; } if ($phpBlock || $latteBlock || $htmlBlock) { if (preg_match('~\\W' . $todoMask . '[\\s:;]+(?P<todo>.*?)(?:\\*/|\\*}|-->|\\r|\\n|$)~mixs', $line, $found)) { $items[$path][$n + 1] = trim($found['todo']); } if (strpos($line, '*/') !== FALSE) { $phpBlock = FALSE; } if (strpos($line, '*}') !== FALSE) { $latteBlock = FALSE; } if (strpos($line, '-->') !== FALSE) { $htmlBlock = FALSE; } } } } } return $items; }
/** * Load content and save file * @param array $files * @return string filename of generated file */ protected function generate($files) { $name = $this->getGeneratedFilename($files); $path = $this->tempPath . "/" . $name; if (!file_exists($path)) { if (!in_array(SafeStream::PROTOCOL, stream_get_wrappers())) { SafeStream::register(); } if (!file_exists(dirname($path))) { mkdir($path, 0775, true); } file_put_contents("safe://" . $path, $this->getContent($files)); } return $name; }
ini_set('date.timezone', $timezone); } } date_default_timezone_set(require Environment::expand('%timezoneFile%')); // debugging Debug::enable(NULL, BASE_DIR . '/error.log', Environment::expand('%adminEmail%')); // paths Environment::setVariable('themeDir', Environment::expand('%baseDir%/themes')); Environment::setVariable('templatesDir', Environment::expand('%themeDir%/%theme%')); Environment::setVariable('tempDir', Environment::expand('%baseDir%/tmp')); Environment::setVariable('themeBaseUri', Environment::expand('%baseUri%/themes/%theme%')); Environment::setVariable('mediaDir', Environment::expand('%baseDir%/media')); Environment::setVariable('mediaBaseUri', Environment::expand('%baseUri%/media')); set_include_path(LIB_DIR . PATH_SEPARATOR . get_include_path()); Html::$xhtml = FALSE; SafeStream::register(); setlocale(LC_ALL, require Environment::expand('%localeFile%')); Zend_Search_Lucene::setDefaultSearchField('description'); // configure locale require_once LIB_DIR . '/tr.php'; $available = array(); foreach (glob(APP_DIR . '/locale/' . '*.php') as $_) { $available[substr(substr($_, strlen(APP_DIR . '/locale/')), 0, 2)] = $_; } tr::$locale = Environment::getHttpRequest()->detectLanguage(array_keys($available)); if (tr::$locale) { list(tr::$plurals[tr::$locale], tr::$table[tr::$locale]) = (require $available[tr::$locale]); } // connect to DB dibi::connect(require Environment::expand('%dbFile%')); // get app