コード例 #1
0
 public function doValidate($validator, $values)
 {
     preg_match(ForgeValidatorGitHubUrl::PATTERN, $values['url'], $parts);
     $url = sprintf('http://github.com/%s/%s/', $parts[3], $parts[4]);
     if (!ForgeToolkit::isUrlAccessible($url)) {
         throw new sfValidatorError($validator, sprintf('Could not access <a href="%s">GitHub URL</a> (404)', $url));
     }
     $this->gitHubUser = $parts[3];
     $this->gitHubRepository = $parts[4];
     return $values;
 }
コード例 #2
0
 public function storeScreenshot()
 {
     $path = sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_screenshots_path') . '/' . $this->getPluginId() . '/' . $this->getId();
     ForgeToolkit::createRecursiveDirectory($path . '/thumbs/');
     $filename = $this->getFilename();
     try {
         $tmp = tempnam(sys_get_temp_dir(), uniqid($this->getUrl() . time()));
         @copy($this->getUrl(), $tmp);
         if (@file_get_contents($tmp)) {
             $image = new sfImage($tmp);
             $image->saveAs($path . '/' . $filename);
             $image->thumbnail(sfConfig::get('app_screenshots_' . ($this->isPrimary() ? 'primary' : '') . 'width'), sfConfig::get('app_screenshots_' . ($this->isPrimary() ? 'primary' : '') . 'height'), 'center');
             $image->saveAs($path . '/thumbs/' . $filename, 'image/png');
         }
     } catch (sfImageTransformException $e) {
         $this->delete();
     }
 }
 protected function doClean($values)
 {
     if (is_null($values)) {
         $values = array();
     }
     if (!is_array($values)) {
         throw new InvalidArgumentException('You must pass an array parameter to the clean() method');
     }
     $errors = array();
     $deps = isset($values[$this->getOption('dependencies_field')]) ? $values[$this->getOption('dependencies_field')] : array();
     if (!empty($deps)) {
         foreach ($deps as $i => $dep) {
             if (!isset($dep['package']) || !$dep['package']) {
                 $errors[] = new sfValidatorError($this, 'no_package');
             } else {
                 if (!ForgeToolkit::isUrl($dep['package'])) {
                     if (!isset($dep['version']) || !$dep['version']) {
                         $errors[] = new sfValidatorError($this, 'missing_tag', array('value' => $results[3]));
                     }
                     $plugin = PluginPeer::retrieveBySlug($results[3]);
                     if ($plugin) {
                         if ($tag = $plugin->getGitTagByName($dep['tag'])) {
                             $values[$i]['plugin_tag_id'] = $tag->getId();
                             $errors[] = new sfValidatorError($this, 'tag_not_found', array('plugin' => $results[3], 'value' => $dep['tag']));
                         }
                     } else {
                         $errors[] = new sfValidatorError($this, 'plugin_not_found', array('value' => $dep['package']));
                     }
                 } else {
                     $values[$i]['external'] = true;
                     $values[$i]['url'] = $dep['package'];
                     $values[$i]['title'] = ForgeToolkit::retrieveTitleFromURL($dep['package']);
                 }
             }
         }
     }
     if (!empty($errors)) {
         throw new sfValidatorErrorSchema($this, $errors);
     }
     return $values;
 }
コード例 #4
0
ファイル: Plugin.php プロジェクト: nageshwar545/PluginsKit
 public function setArbitrarySections($sections, $deletePrior = true)
 {
     if ($deletePrior) {
         $c = new Criteria();
         $c->add(PluginSectionPeer::PLUGIN_ID, $this->getId());
         PluginSectionPeer::doDelete($c);
     }
     foreach ($sections as $slug => $content) {
         $s = new PluginSection();
         $s->setTitle(ForgeToolkit::fromSlug($slug));
         $s->setContent($content);
         $s->setPlugin($this);
         $s->save();
     }
 }