コード例 #1
0
 /**
  * Testet ob ein Widget im HTML aufgerufen wird und gibt dessen Parameter als objekt zurück
  * 
  * @return object
  */
 public function jqueryWidget($widgetName, $html)
 {
     $json = \Psc\Preg::qmatch($html, '/\\.' . $widgetName . '\\((.*?)\\)/s', 1);
     $this->testCase->assertNotEmpty($json, 'JSON Parameter für .' . $widgetName . ' konnte nicht aus dem HTML ausgelesen werden: ' . $html);
     $data = $this->json($json, FALSE);
     return $data;
 }
コード例 #2
0
 public function __construct(\PDOException $e = NULL)
 {
     if (isset($e)) {
         parent::__construct($e->errorInfo[2], $e->errorInfo[1]);
         $this->uniqueConstraint = \Psc\Preg::qmatch($e->errorInfo[2], "/key\\s+'(.*?)'/");
     }
 }
コード例 #3
0
ファイル: DebuggerTest.php プロジェクト: pscheit/psc-cms
 public function testConstruct()
 {
     $tag = new Tag('div');
     $this->debugger->container($tag);
     $this->assertNotEmpty($color = \Psc\Preg::qmatch($tag->htmlAttributes(), '/[0-9]+px solid (.*)/'));
     $this->debugger->container($tag);
     $this->assertNotEmpty($color2 = \Psc\Preg::qmatch($tag->htmlAttributes(), '/[0-9]+px solid (.*)/'));
     $this->assertNotEquals($color, $color2);
     $this->debugger->container($tag);
     $this->assertNotEmpty($color3 = \Psc\Preg::qmatch($tag->htmlAttributes(), '/[0-9]+px solid (.*)/'));
     $this->assertNotEquals($color2, $color3);
     // usw
 }
コード例 #4
0
ファイル: RequestMatcher.php プロジェクト: pscheit/psc-cms
 /**
  * @return string $match[$set]
  */
 public function qmatchiRX($rx, $set = 1)
 {
     if (($match = Preg::qmatch($this->part(), Preg::setModifier($rx, 'i'), $set, FALSE)) !== FALSE) {
         $ret = $this->success($match);
         if (is_array($ret)) {
             return array_map($ret, 'mb_strtolower');
         } elseif (is_string($ret)) {
             return mb_strtolower($ret);
         } else {
             return $ret;
         }
     }
     $this->fail('%s matched nicht: ' . $rx);
 }
コード例 #5
0
    public function run()
    {
        if (!isset($this->changes) || !is_array($this->changes)) {
            throw new \InvalidArgumentException('changes muss gesetzt sein');
        }
        if (!$this->changelog->exists()) {
            throw new \RuntimeException('changelogFile ' . $targetFile . ' muss existieren');
        }
        require $this->changelog;
        /* changeslist : 
           
           'bugfix: Im Sound Content stand nur "content" statt dem eigentlichen Soundtext',
           'geändert: Bei der Soundsuche wird bei sehr großen Results das Ergebnis auf 15 Einträge eingeschränkt'
           
           */
        /* version */
        //2.0.9-Beta
        $version = \Psc\Preg::qmatch($data[0]['version'], '/^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\-(Alpha|Beta|Gamma)$/i', array(1, 2, 3, 4));
        if (!is_array($version)) {
            throw new \RuntimeException('Fehler beim Version Parsing. Alte Version ' . $oldVersion);
        }
        if ($this->versionIncrement === 'minor') {
            $version[2]++;
        } else {
            throw new \InvalidArgumentException('Kann nichts anderes als minor für versionIncrement');
        }
        $newVersion = vsprintf('%d.%d.%d-%s', $version);
        $php = <<<'PHP'
$data[] = array(
  'version'=>'%version%',
  'time'=>'%time%',
  'changelog'=>array(
    %changesList%
  )
);

PHP;
        $php = \Psc\TPL\TPL::miniTemplate($php, array('version' => $newVersion, 'time' => date('H:i d.m.Y'), 'changesList' => \Webforge\Common\ArrayUtil::implode($this->changes, ",\n    ", function ($change) {
            return var_export($change, true);
        })));
        $contents = $this->changelog->getContents();
        $pos = mb_strpos($contents, $needle = '$data = array();' . "\n");
        if ($pos === FALSE) {
            throw new \RuntimeException('Cannot Modify File: ' . \Webforge\Common\String::cutAt($contents, 300) . ' enhält nicht ' . $needle);
        }
        $pos += mb_strlen($needle);
        $contents = mb_substr($contents, 0, $pos) . $php . "\n" . mb_substr($contents, $pos);
        $this->changelog->writeContents($contents);
    }
コード例 #6
0
ファイル: JSONObject.php プロジェクト: pscheit/psc-cms
 public function setJSONFields(stdClass $json)
 {
     foreach ($this->getJSONFields() as $field => $meta) {
         if ($meta === NULL) {
             $this->{$field} = $json->{$field};
         } elseif (mb_substr($meta, 0, 4) === 'JSON') {
             if ($json->{$field} === NULL) {
                 $this->{$field} = NULL;
             } elseif (($class = Preg::qmatch($meta, '/^JSON<(.*)>$/', 1)) !== NULL) {
                 $this->{$field} = $class::createFromJSON($json->{$field});
             }
         }
     }
     return $this;
 }
コード例 #7
0
 protected function getLocalSubtitle($episode, $lang)
 {
     $episodesDir = $this->getEpisodesDir($episode);
     $this->logger->writeln('Suche Sub(' . $lang . ') für: ' . $episode . ' ');
     // wir holen uns alle releases (in allen Formaten) aus dem Episoden Verzeichnis und suchen uns einen heißen Kandidaten
     $episodeDir = $episodesDir->sub($episode->getNum());
     // fastcheck
     if (!$episodeDir->exists()) {
         return NULL;
     }
     $subs = array();
     foreach ($episodeDir->getFiles(array('srt', 'rar', 'zip')) as $sub) {
         //$this->logger->writeln('   Kandidat: '.$sub);
         // nach language filtern und dabei das release holen
         if (($subRelease = Preg::qmatch($sub->getName(File::WITHOUT_EXTENSION), '/^(.*)\\.' . $lang . '$/i')) == NULL) {
             continue;
         }
         $subRelease = preg_replace('/-?proper-?/i', NULL, $subRelease);
         //$this->logger->writeln('  Sub-Release: '.$subRelease);
         // "IMMERSE" in "IMMERSE-x264 720p" oder so
         $this->logger->writeln($subRelease . ' in ' . $episode->getRelease());
         if (mb_stripos($episode->getRelease(), $subRelease) !== FALSE) {
             $subs[$sub->getExtension()] = $sub;
         }
     }
     if (count($subs) === 1) {
         $sub = current($subs);
         $this->logger->writeln('  Lokaler Subtitle: ' . $sub . ' gefunden');
         return $sub;
     } elseif (count($subs) === 0) {
         $this->logger->writeln('  Kein passenden Subtitle(' . $lang . ') im Episodenverzeichnis gefunden.');
     } else {
         if (isset($subs['srt'])) {
             return $subs['srt'];
         } else {
             $this->logger->writeln('  WARNING: Mehrere Subtitle im Episodenverzeichnis gefunden: ' . "\n" . implode("\n", $subs) . ' Nehme erstbesten, weil zu faul');
             return current($subs);
             // ach verdammt, mir jetzt grad egal! (eigentlich wäre hier .srt auswählen toll
         }
     }
 }
コード例 #8
0
ファイル: ClosureCompiler.php プロジェクト: pscheit/psc-cms
 /**
  * @return list($phpCode, $methodNames)
  */
 public function compile(GClass $gClass)
 {
     $this->methods = array();
     $gClass->elevateClass();
     $closures = array();
     $methodNames = array();
     foreach ($gClass->getAllMethods() as $method) {
         $closureName = $method->getName();
         if ($method->hasDocBlock()) {
             $docBlock = $method->getDocBlock();
             if (($ccAlias = \Psc\Preg::qmatch($docBlock->toString(), '/@cc-alias\\s+(.*?)([\\s]|$)/im', 1)) !== NULL) {
                 $closureName = $ccAlias;
             }
             if (\Psc\Preg::match($docBlock->toString(), '/@cc-ignore/i')) {
                 continue;
             }
         }
         $closures[$closureName] = $this->compileClosure($method, $closureName);
         $this->methods[$closureName] = $method;
         $methodNames[] = $closureName;
     }
     return array(\Webforge\Common\ArrayUtil::join($closures, "%s;\n\n"), $methodNames);
 }
コード例 #9
0
ファイル: DateValidatorRule.php プロジェクト: pscheit/psc-cms
 public function validate($data)
 {
     if ($data === NULL) {
         throw new EmptyDataException();
     }
     // date::parse schmeisst keine Exceptions für invalide Datum! Das ist kacke
     if ($this->format === 'd.m.') {
         /* Schaltjahrproblematik macht stress mit DateTime::parse */
         if (($match = \Psc\Preg::qmatch($data, '/^([0-9]+)\\.([0-9]+)\\.$/', array(1, 2))) !== NULL) {
             list($d, $m) = $match;
             if ($d == 29 && $m == 2) {
                 $date = new Date($d . '.' . $m . '.1972');
             } else {
                 $date = new Date($d . '.' . $m . '.1970');
             }
         } else {
             throw new \Psc\DateTime\ParsingException('Aus ' . $data . ' kann kein Datum extrahiert werden. Erwartetes Format: ' . $this->format);
         }
     } else {
         $date = new Date($data);
     }
     return $date;
 }
コード例 #10
0
 /**
  * 
  * Die Werte des Arrays sind relative links zum attachment
  * @return array schlüssel ebene eins ist sowas wie 1 2 ... für die Episoden ebene 2 sind die formate der Releases (ASAP, IMMERSE, etc...)
  */
 public function getSubs($threadLink)
 {
     $this->logger->writeln('Lade alle Subs aus ' . $threadLink);
     $this->req = new URLRequest($threadLink, $this->cookieJar);
     $html = $this->req->init()->process();
     $dom = xml::doc($html);
     $tables = xml::query($dom, 'div#main div.threadStarterPost div.messageContent div.messageBody div.baseSC table');
     if (count($tables) == 0) {
         $e = new SubcentralNoTablesException('Keine Tables: "div#main div.threadStarterPost div.messageContent div.messageBody div.baseSC table " gefunden in: ' . $this->req->getURL() . ' Wurde sich bedankt?');
         $this->logger->writeln($e->getMessage());
         $e->threadURL = $this->req->getURL();
         throw $e;
     }
     $defTable = xml::doc(xml::export(array_shift($tables)));
     $titles = xml::query($defTable, 'td a.sclink');
     $tabIds = array();
     /* die Titel der Tables stehen oben in der Box */
     foreach ($titles as $a) {
         $tabIds[Preg::qmatch($a->nodeValue, '/^\\s*(.*)\\*Klick\\*$/i')] = Preg::qmatch($a->getAttribute('id'), '/link(.*)/');
     }
     $subs = array();
     foreach ($tables as $table) {
         $subTable = xml::doc(xml::export($table));
         $lang = NULL;
         foreach (xml::query($subTable, 'tr') as $row) {
             $tds = xml::query(xml::doc(xml::export($row)), 'td');
             if (count($tds) > 0) {
                 $episode = (int) Preg::qmatch($tds[0]->nodeValue, '/^\\s*E([0-9]+)/');
                 foreach (xml::query(xml::doc(xml::export($row)), 'td a') as $attachment) {
                     $subs[$episode][$lang][$this->stringifyFormat($attachment->nodeValue)] = $attachment->getAttribute('href');
                 }
             } else {
                 // in der th-row die sprache auswählen
                 $usa = xml::query(xml::doc(xml::export($row)), 'th img[src*="flags/usa.png"]');
                 $de = xml::query(xml::doc(xml::export($row)), 'th img[src*="flags/de.png"]');
                 if (count($de) > 0) {
                     $lang = 'de';
                 } elseif (count($usa) > 0) {
                     $lang = 'en';
                 } else {
                     $lang = 'en';
                 }
             }
         }
     }
     $this->logger->writeln(count($subs) . ' Subs gefunden');
     return $subs;
 }
コード例 #11
0
ファイル: DocBlock.php プロジェクト: pscheit/psc-cms
 public function stripCommentAsteriks($body)
 {
     /* okay, also das Prinzip ist eigentlich: lösche alle Tokens am Anfang der Zeile (deshalb /m)
           bzw * / am Ende der Zeile 
           
           da aber bei leeren Zeilen im Docblock bzw. Zeilen ohne * das multi-line-pattern kaputt geht
           überprüfen wir im callback ob die zeile "leer" ist und fügen dann einen Umbruch ein.
           Wir behalten quasi die Umbrüche zwischendrin
        */
     //$body = preg_replace_callback('/(^\s*$|^\/\*\*($|\s*)|^\s*\*\/|^\s*\*($|\s*)|\*\/$)/mu', function ($m) {
     //  return (mb_strpos($m[0], '*') !== FALSE) ? NULL : "\n";
     //}, $body);
     $lines = array();
     $debug = "\n";
     foreach (explode("\n", ltrim($body)) as $line) {
         $tline = trim($line);
         $debug .= "'{$tline}'";
         $debug .= "\n  ";
         if ($tline === '*') {
             // nur ein sternchen bedeutet eine gewollte Leerzeile dazwischen
             $lines[] = NULL;
             // means zeilenumbruch
             $debug .= "newline";
         } elseif ($tline === '/**' || $tline === '/*' || $tline === '*/') {
             // top und bottom wollen wir nicht in unserem docBlock haben
             $debug .= "discard";
         } elseif (($content = Preg::qmatch($line, '/^\\s*\\/?\\*+\\s?(.*?)\\s*$/')) !== NULL) {
             // eine Zeile mit * am Anfang => wir nehmen den $content (Einrückungssafe)
             // eine Zeile mit /*+ am Anfang => wir nehmen den content (Einrückungssafe)
             $content = rtrim($content, ' /*');
             // read carefully
             $lines[] = $content;
             $debug .= "content: '" . $content . "'";
         } else {
             // dies kann jetzt nur noch eine Zeile ohne * sein (also ein kaputter Docblock). Den machen wir heile
             $lines[] = $line;
             // preservewhitespace davor?
             $debug .= "fix: '{$line}'";
         }
         $debug .= "\n";
     }
     $debug .= "ergebnis:\n";
     //$debug .= print_r($lines,true);
     $debug .= "\n\n";
     //print $debug;
     // mit rtrim die leerzeilen nach dem letzten Text entfernen
     return rtrim(implode("\n", $lines));
     // while array_peek(lines) === NULL : array_pop($lines)
 }
コード例 #12
0
 public function getRelease()
 {
     if (!isset($this->release) && !empty($this->info)) {
         /* wir holen uns das Release so:
              meist steht am Ende (xvid|h.264|web-ddl|..etc...)-$release
            */
         // @TODO mal in en Parser auslagern
         // das ist <Format>-<ReleaseGroup> am Ende des Strings
         // sowas wie AVC-TVS oder XviD-RSG
         $this->release = Preg::qmatch($this->info, '/([a-z0-9A-Z]+-[a-zA-Z0-9&]+)$/', 1);
         /* group darf auch leer sein, dann versuchen wir das release anders zu bekommen
          */
         if (!isset($this->release)) {
             if (($this->release = Preg::qmatch($this->info, '/S[0-9]+E[0-9]+\\.German\\.Dubbed\\.DL\\.(.*)$/', 1)) !== NULL) {
                 $this->release = str_replace('.', ' ', $this->release);
                 return $this->release;
             }
             try {
                 // normalize
                 $this->release = \Psc\Preg::matchArray(array('/(WEB.DL(.*)720p|720p(.*)WEB.DL)/i' => 'WEB-DL 720p', '/(WEB.DL(.*)1080|1080(.*)WEB.DL)/i' => 'WEB-DL 1080', '/720p.ITunesHD/' => 'ITunesHD 720p', '/WEB-DL/i' => 'WEB-DL', '/(dvdrip(.*)xvid|dvdrip(.*)xvid)/i' => 'XviD-DVDRip', '/dvdrip/i' => 'DVDRip'), $this->info);
             } catch (\Psc\NoMatchException $e) {
             }
         }
         /* jetzt suchen wir noch nach tags, die das Release besser kennzeichnen */
         try {
             $tags = \Psc\Preg::matchFullArray(array('/ITunesHD/i' => 'ITunes', '/WEB.DL/i' => 'WEB-DL', '/dvdrip/i' => 'DVDRip', '/720p/i' => '720p', '/1080p/i' => '1080p', '/1080i/i' => '1080i', '/dvdscr/i' => 'DVDScr', '/blue?ray/i' => 'Bluray', '/xvid/i' => 'XviD'), $this->info);
             // merge
             foreach ($tags as $tag) {
                 if (mb_stripos($this->release, $tag) === FALSE) {
                     $this->release .= ' ' . $tag;
                 }
             }
         } catch (\Psc\NoMatchException $e) {
         }
         $this->release = trim($this->release);
         if ($this->release === '') {
             $this->release = NULL;
         }
     }
     return $this->release;
 }