Example #1
0
 protected function initialize()
 {
     parent::initialize();
     if (\UString::isStartWith($this->title, '(')) {
         \UString::doSubstrAfter($this->title, '(');
         $this->preTitle = \UString::substrBefore($this->title, ')');
         \UString::doSubstrAfter($this->title, ')');
     }
 }
Example #2
0
 public function initialize()
 {
     parent::initialize();
     $this->router = new \Stack\Router();
     if (isset($_SERVER['REQUEST_URI'])) {
         $uri = \UString::substrBefore($_SERVER['REQUEST_URI'], '?');
         $uri = rawurldecode($uri);
         \UString::doNotStartWith($uri, $this->baseUri);
         \UString::doStartWith($uri, '/');
         $this->router->setUri($uri);
     }
 }
Example #3
0
 public function byServer()
 {
     $return = new $this();
     if (isset($_SERVER['SERVER_NAME'])) {
         $return->host = $_SERVER['SERVER_NAME'];
     } else {
         $return->host = 'localhost';
     }
     if (isset($_SERVER['SERVER_PORT'])) {
         $return->port = intval($_SERVER['SERVER_PORT']);
     } else {
         $return->port = '80';
     }
     if (isset($_SERVER['REQUEST_URI'])) {
         $return->uri = \UString::substrBefore($_SERVER['REQUEST_URI'], '?');
     } else {
         $return->uri = '/';
     }
     return $return;
 }
Example #4
0
 public function test_substr_before__no_match()
 {
     $substr = \UString::substrBefore('example.com', '/');
     $this->assertEquals('example.com', $substr);
 }
Example #5
0
 public static function doSubstrBefore(&$haystack, $needles)
 {
     $substr = \UString::substrBefore($haystack, $needles);
     $pop = substr($haystack, strlen($substr));
     $haystack = $substr;
     return $pop;
 }
Example #6
0
 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;
     }
 }
Example #7
0
 public static function getParentStackQuery($stackable)
 {
     \UObject::doConvertToClass($stackable);
     $query = \Staq\Util::getStackableQuery($stackable);
     return \UString::substrBefore($query, '\\__Parent');
 }