/** * Scannt ein Verzeichnis nach einem Dateipattern und * vergleicht dabei die Versionen um die aktuellste Version dieser Datei zurückgeben zu können * * Als Beispiel: * jquery-1.3.2.min.js * jquery-1.4.1.min.js * jquery-1.5.1.min.js * jquery-1.5.2.min.js * * gibt logischerweise jquery-1.5.2.min.js zurück * * @param string $directory das Verzeichnis (mit trailingsslash) welches durchsucht werden soll * @param string $search sollte der String am Anfang der Datei sein. Dies kann auch eine regexp sein (mit / umschlossen) * @param array $fileRegexps können zusätzliche reguläre Ausdrücke sein um aus einer Datei den Versionsstring herauszubekommen, diese werden benutzt, wenn das normale vorgehen (match ((?:[0-9]\.)+[0-9]) scheitert */ public static function getLatestFileVersion($directory, $search, array $fileRegexps = array()) { $standardRx = '/((?:[0-9]\\.)+[0-9])/'; $files = glob($directory . '*.*'); $maxFile = NULL; $maxVersion = 0; $searchRx = S::startsWith($search, '/') ? $search : '/^' . $search . '/'; foreach ($files as $file) { $fileName = basename($file); if (preg::match($fileName, $searchRx) > 0) { if (($version = preg::qmatch($fileName, $standardRx, 1)) == '') { foreach ($fileRegexps as $fileRx) { if (($version = preg::qmatch($fileName, $fileRegexps)) != '') { break; } } } if ($version == '') { throw new Exception('Für Datei: "' . $fileName . '" konnte keine Version extrahiert werden'); } if (version_compare($version, $maxVersion, '>')) { $maxVersion = $version; $maxFile = $file; } } } return array($maxFile, $maxVersion); }
/** * Erstellt eine neue Rule durch eine Spezifikation (was so quasi alles sein kann) * * Die Parameter dieser Funktion sind sehr Variabel * Möglicherweise ist es einfacher generate[A-Za-z+]Rule zu benutzen */ public static function generateRule($ruleSpecification) { $rs = $ruleSpecification; if (is_string($rs)) { if ($rs == 'nes') { return new NesValidatorRule(); } if ($rs == 'id') { return new IdValidatorRule(); } if ($rs == 'pi' || $rs == 'pint') { return new PositiveIntValidatorRule(); } if ($rs == 'array') { return new ArrayValidatorRule(); } if ($rs == 'pi0' || $rs == 'pint0') { $rule = new PositiveIntValidatorRule(); $rule->setZeroAllowed(TRUE); return $rule; } if (S::startsWith($rs, '/') && S::endsWith($rs, '/')) { return self::generateRegexpRule($rs); } $c = '\\' . __NAMESPACE__ . '\\' . ucfirst($rs) . 'ValidatorRule'; if (class_exists($c)) { return new $c(); } throw new \Psc\Exception('Unbekannte Parameter für generateRule ' . Code::varInfo($rs)); } if (is_array($rs)) { $num = count($rs); } throw new \Psc\Exception('Unbekannte Parameter für generateRule ' . Code::varInfo($rs)); }
public function testSaveImageThumbnailInOtherFormatThanpng() { $this->resetDatabaseOnNextTest(); $image = $this->manager->store($this->im('image2.jpg'), $title = 'my nice title'); $url = $image->getUrl('thumbnail', array(300, 200, 'outbound'), array('format' => 'jpg', 'quality' => 70)); // /dimg bla if (S::startsWith($url, '/dimg/')) { $url = mb_substr($url, 6); } $file = File::createFromURL($url, $this->cacheDir); $this->assertTrue($file->exists(), $file . ' does not exist'); $this->assertEquals('jpg', $file->getExtension()); $finfo = finfo_open(FILEINFO_MIME_TYPE); $mimeType = finfo_file($finfo, (string) $file); finfo_close($finfo); $this->assertEquals('image/jpeg', $mimeType); }
/** * return array */ public function getRequestPath() { $uri = $this->getRequestURI(); if (\Webforge\Common\String::startsWith($uri, '/index.php')) { $uri = mb_substr($uri, mb_strlen('index.php')); } if (empty($uri) || $uri == '/') { return array(); } $uri = ltrim($uri, '/'); $parts = explode('/', $uri); return array_filter($parts, function ($p) { return trim($p) != ''; }); }
public static function reformat($html, $withPFirst = TRUE) { /* compile regex */ $blockElements = array('h1', 'h2', 'h3', 'div', 'h3', 'table', 'tr', 'td', 'ol', 'li', 'ul', 'pre', 'p'); $blemRx = '(?:' . implode('|', $blockElements) . ')'; $blemStartRx = '<' . $blemRx . '[^>]*(?<!\\/)>'; // ignores self-closing $blemEndRx = '<\\/' . $blemRx . '[^>]*>'; $blemBothRx = '<\\/?' . $blemRx . '[^>]*>'; $debug = FALSE; $log = NULL; $log .= 'Starte mit Text: "' . $html . '"<br />' . "\n"; $level = 0; $pOpen = FALSE; $matching = NULL; $ret = NULL; $firstP = $withPFirst; $x = 0; while ($html != '' && $x <= 100000000) { $x++; $log .= "level: " . $level . ": "; /* $html abschneiden (schritt) */ if (isset($matching)) { $html = mb_substr($html, mb_strlen($matching)); $ret .= $matching; $matching = NULL; } /* normaler text */ $match = array(); if (Preg::match($html, '/^([^\\n<>]+)/', $match) > 0) { /* p öffnen, wenn es nicht offen ist */ if ($level == 0 && !$pOpen) { $pOpen = TRUE; $log .= "open p<br />\n"; if ($firstP && mb_strlen(trim($ret)) == 0) { $ret .= '<p class="first">'; $firstP = FALSE; } else { $ret .= '<p>'; } } $matching = $match[1]; $log .= "text(" . mb_strlen($matching) . "): " . str_replace(array("\n", "\r"), array("-n-\n", "-r-\r"), $matching) . "<br />\n"; continue; } /* absatz */ $match = array(); if (S::startsWith($html, "\n\n")) { $matching = "\n\n"; if ($level == 0 && $pOpen) { $log .= "Absatz (close p)<br />\n"; $pOpen = FALSE; $ret .= '</p>'; //$ret .= "\n"; // da matching hinzugefügt wird } continue; } /* zeilenumbruch */ if (S::startsWith($html, "\n")) { $matching = "\n"; $log .= "\\n gefunden<br />\n"; /* wir machen ein <br /> aus dem \n, wenn wir im p modus sind */ if ($pOpen) { $ret .= '<br />'; $log .= "in br umwandeln<br />\n"; } continue; } /* prüfen auf html tags (block start, block end, inline tag */ $match = array(); if (Preg::match($html, '/^<(\\/)?([^\\s>]+)((?>[^>])*)>/', $match) > 0) { list($full, $op, $tagName, $rest) = $match; if (in_array($tagName, $blockElements)) { $matching = $full; if ($op != '/') { /* block element start */ if ($pOpen) { $ret .= '</p>'; $log .= "close p<br />\n"; $pOpen = FALSE; } $log .= "block level(" . $level . ") start : '" . $matching . "'<br />\n"; $level++; } else { /* block element end */ $log .= "block level(" . $level . ") end: '" . $matching . "'<br />\n"; $level--; } } else { /* html tag (kein block element) */ $matching = $full; /* p öffnen, wenn es nicht offen ist */ if ($level == 0 && !$pOpen) { $pOpen = TRUE; $log .= "open p<br />\n"; if ($firstP && mb_strlen(trim($ret)) == 0) { $ret .= '<p class="first">'; $firstP = FALSE; } else { $ret .= '<p>'; } } $log .= "inline-tag: '" . $matching . "'<br />\n"; } continue; } /* kein fall hat gegriffen, wir verkürzen um 1 Zeichen */ $matching = HTML::esc(mb_substr($html, 0, 1)); $log .= "zeichen: " . $matching . "<br />\n"; } /* letztes <p> schließen */ if ($pOpen) { $ret .= '</p>' . "\n"; } if ($debug) { print $log; } return $ret; }
public function guid($set = NULL) { if (func_num_args() == 1) { $guid = $this->guid; if ($set != NULL) { if (!S::startsWith($set, 'psc-guid-')) { $set = 'psc-guid-' . $set; } $set = HTML::string2id($set); } $this->guid = $set; if ($this->guid != $guid && $this->hasClass($guid)) { $this->removeClass($guid); //unpublish $this->publishGUID(); } return $this; } if (!isset($this->guid)) { $this->generateGUID(); } return $this->guid; }
public static function expand($label, $name = NULL, $id = NULL) { if ($name == NULL) { $name = self::convertToName($label); } if ($id == NULL) { //$id = self::convertToId($name); // wenn wir das müssen wird eine id automatisch erzeugt, dies hier ist zu uneindeutig } if (isset(self::$uniquePrefix) && !S::startsWith($id, self::$uniquePrefix)) { $id = self::$uniquePrefix . $id; } return array($label, $name, $id); }
public function filterjqxWidgetsFromRequestData(FormData $requestData) { $filteredData = $requestData; foreach ($requestData as $key => $value) { if (S::startsWith($key, 'jqxWidget')) { unset($filteredData->{$key}); } } return $filteredData; }