Exemple #1
0
 /**
  * Test for Schwaen\Stdlib\StringUtils::endsWith
  */
 public function testEndsWith()
 {
     $this->assertEquals(false, StringUtils::endsWith('Hallo Welt', 'welt'));
     $this->assertEquals(true, StringUtils::endsWith('Hallo Welt', 'Welt'));
     $this->assertEquals(false, StringUtils::endsWith('Hallo Welt', 'Test'));
     $this->assertEquals(true, StringUtils::endsWith('Hallo Welt', ''));
 }
Exemple #2
0
 /**
  * Extract the domain from a url
  *
  * @param string $url
  *
  * @return string
  */
 public static function extractMainDomainFromUrl($url)
 {
     $matchesMainDomain = null;
     $hostString = self::urlToString($url);
     $pattern = '/[^.]+\\.[^.]+$/';
     foreach (self::$excludedTld as $extension) {
         if (StringUtils::endsWith($hostString, $extension)) {
             $pattern = sprintf('/.*\\.(.*%s)/', str_replace('.', '\\.', $extension));
             break;
         }
     }
     preg_match($pattern, $hostString, $matchesMainDomain);
     $mainDomain = array_pop($matchesMainDomain);
     return $mainDomain;
 }
 /**
  * Adds all the plugin's aspects
  *
  * @param Plugin $plugin The plugin to analyze
  * @param string &$log   A variable that will get logging detail appended
  *
  * @return void
  */
 public function processAspects(Plugin $plugin, &$log = '')
 {
     $anyChanged = false;
     $processedSlugs = array();
     $pluginPath = $plugin->Path;
     $aspectsPath = $pluginPath . '/aspects';
     if (file_exists($aspectsPath)) {
         $iter = new DirectoryIterator($aspectsPath);
         foreach ($iter as $aspectFile) {
             if ($aspectFile->isFile() && StringUtils::endsWith($aspectFile->getBasename(), '.xml')) {
                 $aspectSlug = $aspectFile->getBasename(".xml");
                 try {
                     $log .= "Processing aspect descriptor: {$aspectFile->getBasename()}\n";
                     $ts = $this->DateFactory->newLocalDate(filemtime($aspectFile->getPathname()));
                     $md5 = md5_file($aspectFile->getPathname());
                     if ($this->AspectService->slugExists($aspectSlug)) {
                         $aspect = $this->AspectService->getBySlug($aspectSlug);
                         if ($aspect->Md5 !== $md5) {
                             $aspectXML = $this->SimpleXMLParser->parseXMLFile($aspectFile->getPathname());
                             if ($aspectXML == false) {
                                 throw new Exception('Unable to load aspect XML [' . $aspectFile->getPathname() . ']');
                             }
                             $aspect = $this->SystemXMLConverter->xmlToAspect($aspect, $aspectXML);
                             if ($aspect->PluginID != $plugin->PluginID) {
                                 throw new Exception('Aspect installed by another plugin: ' . $aspect->Slug);
                             }
                             $aspect->ModifiedDate = $ts;
                             $aspect->Md5 = $md5;
                             $log .= "Aspect updated...\n";
                             $this->AspectService->edit($aspect);
                             $anyChanged = true;
                         }
                     } else {
                         $aspectXML = $this->SimpleXMLParser->parseXMLFile($aspectFile->getPathname());
                         if ($aspectXML == false) {
                             throw new Exception('Unable to load aspect XML [' . $aspectFile->getPathname() . ']');
                         }
                         $aspect = new Aspect();
                         $this->ModelMapper->defaultsOnModel($aspect);
                         $aspect = $this->SystemXMLConverter->xmlToAspect($aspect, $aspectXML);
                         $aspect->Slug = $aspectSlug;
                         $aspect->PluginID = $plugin->PluginID;
                         $aspect->ModifiedDate = $ts;
                         $aspect->Md5 = $md5;
                         $log .= "Aspect created...\n";
                         $this->AspectService->add($aspect);
                         $anyChanged = true;
                     }
                     // resolve schema
                     if ($aspect->getXMLSchema() != "") {
                         $schemaXML = "<?xml version='1.0'?><schema>";
                         $schemaXML .= preg_replace('/\\<\\?xml([^\\>\\/]*)\\>/', '', $aspect->getXMLSchema());
                         $schemaXML .= "</schema>";
                         try {
                             $this->NodeSchemaParser->parse($schemaXML);
                         } catch (Exception $e) {
                             throw new SchemaException("Unable to parse schema for aspect [{$aspect->Slug}]:\n " . $e->getMessage());
                         }
                     }
                     $this->AspectService->getBySlug($aspect->Slug);
                     $log .= "ID: {$aspect->AspectID}\n";
                     $log .= "Slug: {$aspect->Slug}\n";
                     $log .= "Name: {$aspect->Name}\n";
                     $log .= "Description: {$aspect->Description}\n";
                     $log .= "Md5: {$aspect->Md5}\n";
                     $log .= "\n";
                 } catch (ValidationException $ve) {
                     throw new Exception('Aspect [' . $aspectSlug . ']: ' . $ve->getMessage());
                 }
                 $processedSlugs[] = $aspectSlug;
             }
         }
     }
     if ($plugin->PluginID == '') {
         return $anyChanged;
     }
     $existing = $this->AspectService->findAll(new DTO(array('PluginID' => $plugin->PluginID)))->getResults();
     foreach ($existing as $e) {
         if (!in_array($e->Slug, $processedSlugs)) {
             $this->AspectService->delete($e->Slug);
         }
     }
     return $anyChanged;
 }
 protected function _importPhotosFromDir($dir)
 {
     $h = opendir($dir);
     while (($fname = readdir($h)) !== FALSE) {
         if (StringUtils::endsWith(strtolower($fname), '.jpg')) {
             try {
                 echo "importing {$fname}...";
                 $nodeRef = $this->NodeRefService->oneFromAspect('@images');
                 $nodeRef = $this->NodeRefService->generateNodeRef($nodeRef, $fname);
                 $node = $nodeRef->generateNode();
                 $node->Title = $fname;
                 $node->Status = "published";
                 $node->ActiveDate = $this->DateFactory->newStorageDate();
                 $node = $this->ImageService->storeMedia(rtrim($dir, '/') . '/' . $fname, $node);
                 $this->NodeService->add($node);
                 echo "done\n";
                 unset($nodeRef);
                 unset($node);
             } catch (Exception $e) {
                 echo "Exception: " . $e->getMessage() . "\n";
             }
         }
     }
     closedir($h);
 }