public static function popStackQuery($string) { if (\Staq\Util::isStackQueryPopable($string)) { $string = \UString::substrBeforeLast($string, '\\'); } else { $string = NULL; } return $string; }
public function getBeginning($maximum = 300, $minimum = 200) { $seed = strip_tags($this->seed); $beginning = substr($seed, 0, $minimum); $margin = substr($seed, $minimum, $maximum); $part = trim(\UString::substrBeforeLast($margin, ['. ', '! ', '? '])); if (empty($part)) { $part = trim(\UString::substrBeforeLast($margin, [', ', '; ', ': '])); } if (strlen($seed) > strlen($beginning . $part)) { return $beginning . $part . '...'; } return $seed; }
public static function findTemplate($stack, $action = NULL) { $template = strtolower(\Staq\Util::getStackSubQuery($stack, '/')) . '.twig'; $template = str_replace('_', '/', $template); if (!empty($action)) { $template = $action . '/' . $template; } $folder = strtolower(\Staq\Util::getStackType($stack)); while (TRUE) { if (\Staq::App()->getFilePath('template/' . $folder . '/' . $template)) { break; } if (\UString::has($template, '/')) { $template = \UString::substrBeforeLast($template, '/') . '.twig'; } else { $template = 'index.twig'; break; } } return $folder . '/' . $template; }
protected function initializeNamespaces() { if (empty($this->namespaces)) { $vendorPath = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR; if (\UString::has(__DIR__, $vendorPath)) { $baseDir = \UString::substrBeforeLast(__DIR__, $vendorPath); } else { $baseDir = __DIR__ . '/../..'; } $psr0 = (require $baseDir . '/vendor/composer/autoload_namespaces.php'); foreach ($psr0 as $namespace => $pathList) { foreach ($pathList as $key => $path) { $psr0[$namespace][$key] = realpath($path . '/' . str_replace('\\', '/', $namespace)); } } $psr4 = (require $baseDir . '/vendor/composer/autoload_psr4.php'); foreach ($psr4 as $namespace => $pathList) { foreach ($pathList as $key => $path) { $psr0[$namespace][$key] = realpath($path); } } $this->namespaces = array_merge($psr0, $psr4); } }
public static function getNamespace($class) { \UObject::doConvertToClass($class); return \UString::substrBeforeLast($class, '\\'); }
public function test_substr_before_last__no_match() { $substr = \UString::substrBeforeLast('example.com', '/'); $this->assertEquals('', $substr); }
public static function doSubstrBeforeLast(&$haystack, $needles) { $substr = \UString::substrBeforeLast($haystack, $needles); $pop = substr($haystack, strlen($substr)); $haystack = $substr; return $pop; }
protected function initialize() { /* Id */ if (substr_count($this->id, '/') == 2) { $this->section = \UString::substrBefore($this->id, '/'); $this->subsection = \UString::substrBeforeLast(\UString::substrAfter($this->id, '/'), '/'); $this->shortTitle = \UString::substrAfterLast($this->id, '/'); } /* Retreat content */ if (trim($this->content)) { $doc = new \DOMDocument(); @$doc->loadHTML('<?xml encoding="UTF-8">' . $this->content); /* H1 */ $h1List = $doc->getElementsByTagName('h1'); if ($h1List->length) { $this->title = $h1List->item(0)->textContent; } foreach ($h1List as $h1) { $h1->parentNode->removeChild($h1); } /* H2 */ $h2List = $doc->getElementsByTagName('h2'); foreach ($h2List as $h2) { $title = $h2->textContent; if ($h2->hasAttribute('id')) { $id = $h2->getAttribute('id'); } else { $id = \UString::stripSpecialChar($title); $h2->setAttribute('id', $id); } $this->summary[$id] = $title; $h2->nodeValue = ''; $link = $doc->createElement('a'); $link->nodeValue = htmlentities($title); $link->setAttribute('href', '#' . $id); $h2->appendChild($link); } /* Image */ $imageList = $doc->getElementsByTagName('img'); if ($imageList->length) { $image = $imageList->item(0); if ($image->hasAttribute('src')) { $this->image = $image->getAttribute('src'); } } /* Intro */ $ps = $doc->getElementsByTagName('p'); if ($ps->length) { $firstP = $ps->item(0); $this->intro = $firstP->textContent; $this->introHTML = $doc->saveHTML($firstP); $firstP->parentNode->removeChild($firstP); } /* Content */ $stripHTML = ['/^\\<\\!DOCTYPE.*?<html><body>/si', '!</body></html>$!si']; $this->content = preg_replace($stripHTML, '', $doc->saveHTML()); } if (!$this->label) { $this->label = $this->title; } }
protected function getFileNames($fileName) { $fileNames = []; do { $fileNames[] = $fileName; $fileName = \UString::substrBeforeLast($fileName, '/'); } while (!empty($fileName)); return $fileNames; }