function compose($o) { patchworkPath('zcache/', $o->zcacheDepth); $app = array(); foreach ($GLOBALS['patchwork_path'] as $k => $v) { pStudio::isAuthApp($v) && ($app[$k] = $v); } $o->apps = new loop_array($app, array($this, 'filterApp')); return $o; }
protected static function createConfiguration($dsn) { $conf = new \Doctrine\ORM\Configuration(); $cache = new $CONFIG['doctrine.cache'](); $conf->setQueryCacheImpl($cache); $conf->setMetadataCacheImpl($cache); $conf->setMetadataDriverImpl($conf->newDefaultAnnotationDriver(array(patchworkPath($CONFIG['doctrine.entities.dir'])))); $conf->setProxyDir(patchworkPath($CONFIG['doctrine.proxy.dir'])); $conf->setAutoGenerateProxyClasses($CONFIG['doctrine.proxy.generate']); $conf->setProxyNamespace($CONFIG['doctrine.proxy.namespace']); return $conf; }
function compose($o) { $db = patchworkPath('data/geodb.sqlite3'); $db = new PDO("sqlite:{$db}"); $sql = $this->get->q; $sql = '*' == $sql ? '' : lingua::getKeywords($sql); $sql = substr($db->quote($sql), 1, -1); switch ($a = substr($sql, 0, 3)) { case 'agi': case 'ayi': if ('os ' == substr($sql, 3, 3)) { $sql = substr($sql, 5); $sql = "search GLOB 'agios{$sql}*' OR search GLOB 'ayios{$sql}*'"; break; } case 'st ': $sql = 'saint ' . substr($sql, 3); default: $sql = '' === $sql ? 1 : "search GLOB '{$sql}*'"; } $sql = "SELECT city_id, city FROM city WHERE {$sql} ORDER BY rowid"; $o->cities = new loop_city_($db, $sql, 15); return $o; }
static function loadClass($req) { /**/ if (50300 <= PHP_VERSION_ID && PHP_VERSION_ID < 50303) { // Workaround http://bugs.php.net/50731 isset($req[0]) && '\\' === $req[0] && ($req = substr($req, 1)); } $lc_req = strtolower(strtr($req, '\\', '_')); $amark = $GLOBALS["a�"]; $GLOBALS["a�"] = false; $bmark = $GLOBALS["b�"]; // Step 1 - Get basic info $i = strrpos($req, '__'); $level = false !== $i ? substr($req, $i + 2) : false; $isTop = false === $level || '' !== trim($level, '0123456789'); if ($isTop) { // Top class $top = $req; $lc_top = $lc_req; $level = PATCHWORK_PATH_LEVEL; } else { // Preprocessor renammed class $top = substr($req, 0, $i); $lc_top = substr($lc_req, 0, $i); $level = min(PATCHWORK_PATH_LEVEL, '00' === $level ? -1 : (int) $level); } self::$preproc || (self::$preproc = 'patchwork_preprocessor' === $lc_top); // Step 2 - Get source file $src = ''; if (($customSrc =& self::$prefix) && ($a = strlen($lc_top))) { // Look for a registered prefix autoloader $i = 0; $cache = array(); do { $code = ord($lc_top[$i]); if (isset($customSrc[$code])) { $customSrc =& $customSrc[$code]; isset($customSrc[-1]) && ($cache[] = $customSrc[-1]); } else { break; } } while (++$i < $a); if ($cache) { do { $src = array_pop($cache); $src = $i < $a || !is_string($src) || function_exists($src) ? call_user_func($src, $top) : $src; } while (!$src && $cache); } } unset($customSrc); if ($customSrc = '' !== (string) $src) { } else { if ('_' !== substr($top, -1)) { $src = self::class2file($top); $src = trim($src, '/') === $src ? "class/{$src}.php" : ''; } } $src && ($src = patchworkPath($src, $a, $level, 0)); // Step 3 - Get parent class $src || ($a = -1); $isTop && ++$level; if ($level > $a) { do { $parent = $top . '__' . (0 <= --$level ? $level : '00'); } while (!($parent_exists = self::exists($parent, false)) && $level > $a); } else { $parent = 0 <= $level ? $top . '__' . (0 < $level ? $level - 1 : '00') : false; $parent_exists = false; } // Step 4 - Load class definition $cache = false; if ($src && !$parent_exists) { $cache = self::class2cache($top . '.php', $level); $current_pool = false; $parent_pool =& self::$pool; self::$pool =& $current_pool; if (!(file_exists($cache) && (self::$turbo || filemtime($cache) > filemtime($src)))) { if (self::$preproc) { file_exists($cache) && unlink($cache); copy($src, $cache); } else { Patchwork_Preprocessor::execute($src, $cache, $level, $top, $isTop, false); } } $current_pool = array(); try { // Force fatal errors to be always reported $src = error_reporting(error_reporting() | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR); patchwork_include($cache); error_reporting($src); } catch (Exception $cache) { error_reporting($src); throw $cache; } if ($parent && self::exists($req, false)) { $parent = false; } if (false !== $parent_pool) { $parent_pool[$parent ? $parent : $req] = $cache; } } // Step 5 - Finalize class loading $code = ''; if ($parent ? $code = self::exists($parent, true) : self::exists($req, false) && !isset($GLOBALS["c�"][$lc_req])) { if (false !== ($a = strrpos($req, '\\'))) { $ns = substr($req, 0, $a + 1); $req = substr($req, $a + 1); $parent = substr($parent, $a + 1); $lc_req = substr($lc_req, $a + 1); $lc_ns = strtolower(strtr($ns, '\\', '_')); } else { $ns = $lc_ns = ''; } if ($parent) { $code .= " {$req} extends {$parent}{}\$GLOBALS['c�']['{$lc_ns}{$lc_req}']=1;"; $parent = strtolower($parent); if ($ns && function_exists('class_alias')) { $code .= "\\class_alias('{$ns}{$req}','{$lc_ns}{$lc_req}');"; } if (isset(self::$abstracts[$lc_ns . $parent])) { $code = 'abstract ' . $code; self::$abstracts[$lc_ns . $lc_req] = 1; } } else { $parent = $lc_req; } if ($isTop && class_exists($ns . $parent, false)) { $a = "{$ns}{$parent}::i�"; if (defined($a) ? $lc_req === constant($a) : method_exists($ns . $parent, '__init')) { $code .= "{$parent}::__init();"; } $a = "{$ns}{$parent}::f�"; if (defined($a) ? $lc_req === constant($a) : method_exists($ns . $parent, '__free')) { $a = "\\Patchwork_ShutdownHandler::\$destructors[]='{$lc_ns}{$parent}';"; PHP_VERSION_ID < 50300 && ($a[0] = ' '); $code .= $a; } } if ($ns) { $req = $ns . $req; $parent = $lc_ns . $parent; $lc_req = $lc_ns . $lc_req; $ns = substr($ns, 0, -1); $ns = "namespace {$ns};"; } if ($code) { eval($ns . $code); } } if (!self::$turbo || self::$preproc) { self::$preproc && (self::$preproc = 'patchwork_preprocessor' !== $lc_top); return; } if (class_exists('Patchwork_Preprocessor', false) && Patchwork_Preprocessor::isRunning()) { return; } if ($code && isset($GLOBALS["c�"][$parent])) { // Include class declaration in its closest parent $src = self::parseMarker($GLOBALS["c�"][$parent], "\$GLOBALS['c�']['{$parent}']=%marker%;"); list($src, $marker, $a) = $src; if (false !== $a) { if (!$isTop) { $i = (string) mt_rand(1, mt_getrandmax()); $GLOBALS["c�"][$parent] = $src . '*' . $i; $code .= substr($marker, 0, strrpos($marker, '*') + 1) . $i . "';"; } $a = str_replace($marker, $code, $a); $cache === $src && $current_pool || self::write($a, $src); } } else { $a = false; } if ($cache) { if ($current_pool) { // Add an include directive of parent's code in the derivated class $code = '<?php ?' . '>'; $a || ($a = file_get_contents($cache)); if ('<?php ' != substr($a, 0, 6)) { $a = '<?php ?' . '>' . $a; } $a = explode("\n", $a, 2); isset($a[1]) || ($a[1] = ''); $i = '/^' . preg_replace('/__[0-9]+$/', '', $lc_req) . '__[0-9]+$/i'; foreach ($current_pool as $parent => $src) { if ($req instanceof $parent && false === strpos($a[0], $src)) { $code = substr($code, 0, -2) . (preg_match($i, $parent) ? 'include' : 'include_once') . " '{$src}';?" . ">"; } } if ('<?php ?' . '>' !== $code) { $a = substr($code, 0, -2) . substr($a[0], 6) . $a[1]; self::write($a, $cache); } } $cache = substr($cache, strlen(PATCHWORK_PROJECT_PATH) + 7, -11); if ($amark) { // Marker substitution list($src, $marker, $a) = self::parseMarker($amark, "\$a�=%marker%"); if (false !== $a) { if ($amark != $bmark) { $GLOBALS["a�"] = $bmark; $marker = "isset(\$c�['{$lc_req}'])||{$marker}"; $code = ".class_{$cache}.zcache.php"; $code = addslashes(PATCHWORK_PROJECT_PATH . $code); $ns = empty($ns) ? '' : '\\'; $code = "isset(\$c�['{$lc_req}'])||{$ns}patchwork_include('{$code}')||1"; } else { $marker = "\$e�=\$b�={$marker}"; $i = (string) mt_rand(1, mt_getrandmax()); $GLOBALS["a�"] = $GLOBALS["b�"] = $src . '*' . $i; $i = substr($marker, 0, strrpos($marker, '*') + 1) . $i . "'"; $marker = "({$marker})&&\$d�&&"; $code = $customSrc ? "'{$cache}'" : $level + count($GLOBALS['patchwork_path']) - PATCHWORK_PATH_LEVEL; $code = "\$c�['{$lc_req}']={$code}"; $code = "({$i})&&\$d�&&({$code})&&"; } $a = str_replace($marker, $code, $a); self::write($a, $src); } } } }
protected function getToken() { $token = patchworkPath($this->queueFolder) . $this->queueName . '.token'; //XXX user right problem? file_exists($token) || file_put_contents($token, p::strongId()); return trim(file_get_contents($token)); }
function getPdoConnection() { $db =& $this->getStatic('db'); if ($db) { return $db; } $q = $this->getQueueDefinition(); $file = patchworkPath($q->folder) . $q->name . '.sqlite3'; $sql = file_exists($file); $db = new PDO('sqlite:' . $file); if (!$sql) { foreach ($q->sql as $sql) { $db->exec($sql); } } $db->def = $q; return $db; }
static function getProcessedPath($file, $lazy = false) { /**/ if ('\\' === DIRECTORY_SEPARATOR) { false !== strpos($file, '\\') && ($file = strtr($file, '\\', '/')); } if (false !== strpos('.' . $file, './') || '\\' === DIRECTORY_SEPARATOR && ':' === substr($file, 1, 1)) { if ($f = realpath($file)) { $file = $f; } $p = $GLOBALS['patchwork_path']; for ($i = PATCHWORK_PATH_LEVEL + 1; $i < count($GLOBALS['patchwork_path']); ++$i) { if (0 === strncmp($file, $p[$i], strlen($p[$i]))) { $file = substr($file, strlen($p[$i])); break; } } if (count($GLOBALS['patchwork_path']) === $i) { return $f; } } $source = patchworkPath('class/' . $file, $level); if (false === $source) { return false; } $cache = self::file2cache($file, $level); if (file_exists($cache) && (self::$turbo || filemtime($cache) > filemtime($source))) { return $cache; } Preprocessor::execute($source, $cache, $level, false, true, $lazy); self::resetOpcodeCache(); return $cache; }
static function __init() { self::$db = new PDO('sqlite:' . patchworkPath('data/geodb.sqlite3')); }
static function readfile($file, $mime = true, $filename = true) { $h = patchworkPath($file); if (!$h || !file_exists($h) || is_dir($h)) { user_error(__METHOD__ . "(..): invalid file ({$file})"); return; } $file = $h; if (true === $mime) { $mime = strtolower(strrchr($file, '.')); $mime = isset(self::$contentType[$mime]) ? self::$contentType[$mime] : false; } $mime || ($mime = isset(p::$headers['content-type']) ? substr(p::$headers['content-type'], 14) : 'application/octet-stream'); $mime = strtolower($mime); $head = 'HEAD' == $_SERVER['REQUEST_METHOD']; $gzip = p::gzipAllowed($mime); $filter = $gzip || $head || !$CONFIG['xsendfile'] || in_array($mime, self::$ieSniffedTypes_edit) || in_array($mime, p::$ieSniffedTypes_download); header('Content-Type: ' . $mime); if ($filename) { $filename = basename(true === $filename ? $_SERVER['PATCHWORK_REQUEST'] : $filename); $size = false; if (!$filter) { // Force IE>=8 to respect attachment content disposition header('X-Download-Options: noopen'); } // It seems that IE assumes that filename is represented in its local system charset... // But we don't want to introduce "Vary: User-Agent" just because of this. if (('POST' === $_SERVER['REQUEST_METHOD'] || p::$private) && isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') && preg_match('/[\\x80-\\xFF]/', $filename)) { if (stripos(p::$headers['content-type'], 'octet-stream') && preg_match('#(.*)(\\.[- -,/-~]+)$#D', $filename, $size)) { // Don't search any rational here, it's IE... header('Content-Disposition: attachment; filename=' . rawurlencode($size[1]) . str_replace('"', "''", $size[2])); } else { $filename = Patchwork\Utf8::toAscii($filename); } } $size || header('Content-Disposition: attachment; filename="' . str_replace('"', "''", $filename) . '"'); // If only RFC 2231 were in use... See http://greenbytes.de/tech/tc2231/ //header('Content-Disposition: attachment; filename*=utf-8''" . rawurlencode($filename)); } else { if (false !== strpos($mime, 'html')) { header('P3P: CP="' . $CONFIG['P3P'] . '"'); header('X-XSS-Protection: 1; mode=block'); } } $size = filesize($file); p::$ETag = $size . '-' . p::$LastModified . '-' . fileinode($file); p::$LastModified = filemtime($file); p::$binaryMode = true; p::disable(); class_exists('SESSION', false) && s::close(); class_exists('adapter_DB', false) && \adapter_DB::__free(); $gzip || ob_start(); $filter && ob_start(array(__CLASS__, 'ob_filterOutput'), 32768); // Transform relative URLs to absolute ones if ($gzip) { if (0 === strncasecmp($mime, 'text/css', 8)) { self::$filterRx = "@([\\s:]url\\(\\s*[\"']?)(?![/\\\\#\"']|[^\\)\n\r:/\"']+?:)@i"; ob_start(array(__CLASS__, 'filter'), 32768); } else { if (0 === strncasecmp($mime, 'text/html', 9) || 0 === strncasecmp($mime, 'text/x-component', 16)) { self::$filterRx = "@(<[^<>]+?\\s(?:href|src)\\s*=\\s*[\"']?)(?![/\\\\#\"']|[^\n\r:/\"']+?:)@i"; ob_start(array(__CLASS__, 'filter'), 32768); } } } if ($filter) { $h = fopen($file, 'rb'); echo $starting_data = fread($h, 256); // For p::ob_filterOutput to fix IE if ($gzip) { if ($head) { ob_end_clean(); } $data = ''; $starting_data = false; } else { ob_end_flush(); $data = ob_get_clean(); $size += strlen($data) - strlen($starting_data); $starting_data = $data == $starting_data; } } else { $starting_data = true; } if (!$head) { if ($starting_data && $CONFIG['xsendfile']) { header(sprintf($CONFIG['xsendfile'], $file)); } else { if ($range = $starting_data && !$gzip) { header('Accept-Ranges: bytes'); $range = isset($_SERVER['HTTP_RANGE']) ? p\HttpRange::negociate($size, p::$ETag, p::$LastModified) : false; } else { header('Accept-Ranges: none'); } set_time_limit(0); ignore_user_abort(false); if ($range) { unset(p::$headers['content-type']); p\HttpRange::sendChunks($range, $h, $mime, $size); } else { $gzip || header('Content-Length: ' . $size); echo $data; feof($h) || fpassthru($h); } } } $filter && fclose($h); }
function compose($o) { $o->DATA = file_get_contents(patchworkPath('public/__/fckeditor/src/fckeditor.js')); return $o; }
protected function getSubpaths($dirpath, $low, $high) { $paths = array(); $depth = $high; $isTop = 1; do { if (!pStudio::isAuthApp($GLOBALS['patchwork_path'][PATCHWORK_PATH_LEVEL - $depth])) { --$depth; continue; } if ('' !== $dirpath) { $path = patchworkPath($dirpath, $depth, $depth, 0); } else { if ($depth < 0) { if (!pStudio::isAuthRead('class')) { break; } if (isset($paths['class'])) { ++$paths['class']['ancestorsNb']; } else { $paths['class'] = array('name' => 'class', 'isTop' => $isTop, 'isDir' => 1, 'ancestorsNb' => 0, 'depth' => $depth); } break; } else { $path = $GLOBALS['patchwork_path'][PATCHWORK_PATH_LEVEL - $depth]; } } if (!$path || $depth < $low) { break; } $h = @opendir($path); if (!$h) { break; } while (false !== ($file = readdir($h))) { if ('.' !== $file && '..' !== $file) { if (isset($paths[$file])) { ++$paths[$file]['ancestorsNb']; } else { $isDir = is_dir($path . $file) - 0; if (!pStudio::isAuthRead($dirpath . $file . ($isDir ? '/' : ''))) { continue; } $paths[$file] = array('name' => $file, 'isTop' => $isTop, 'isDir' => $isDir, 'path' => $path . $file, 'ancestorsNb' => 0, 'depth' => $depth, 'appname' => pStudio::getAppname($depth), 'isApp' => $isDir && file_exists($path . $file . '/config.patchwork.php')); } } } closedir($h); --$depth; $isTop = 0; } while ($depth >= $low); usort($paths, array($this, 'pathCmp')); return $paths; }
protected function setPath() { $this->path = patchworkPath('public/__/files/'); $this->path && ($this->watch[] = 'public/files'); }