Example #1
0
 /**
  * save
  *
  * @param Data $data
  *
  * @return  mixed|Data
  */
 public function save(Data $data)
 {
     $data->title = trim($data->title);
     $data->alias = $data->alias ?: OutputFilter::stringURLUnicodeSlug($data->title);
     if (!$data->alias) {
         $data->alias = OutputFilter::stringURLSafe((new Date())->toISO8601());
     }
     $mapper = new DataMapper('posts');
     // Increment alias
     $conditions = ['alias' => $data->alias, 'blog' => $data->blog];
     $conditions[] = 'id != ' . ($data->id ?: -1);
     while ($mapper->findOne($conditions)->notNull()) {
         $conditions['alias'] = $data->alias = String::increment($data->alias, String::INCREMENT_STYLE_DASH);
     }
     $data = $mapper->saveOne($data);
     // Save Categories
     $categories = $data->category ?: [];
     $dataSet = [];
     foreach ($categories as $k => $cat) {
         $dataSet[$k]['category'] = $cat;
         $dataSet[$k]['post'] = $data->id;
     }
     (new DataMapper('category_post_maps'))->flush($dataSet, ['post' => $data->id]);
     return $data;
 }
 /**
  * doExecute
  *
  * @return  mixed
  */
 public function doExecute()
 {
     // Load SQL file.
     @($installFile = file_get_contents($this->config['dir.src'] . '/sql/install.sql'));
     @($uninstallFile = file_get_contents($this->config['dir.src'] . '/sql/uninstall.sql'));
     $installSql = String::parseVariable($installFile, $this->config['replace']);
     $uninstallSql = String::parseVariable($uninstallFile, $this->config['replace']);
     // Prevent import twice
     $table = '#__' . $this->config['name'] . '_' . $this->config['replace.controller.list.name.lower'];
     $db = Container::getInstance()->get('db');
     try {
         $db->getTableColumns($table);
     } catch (\RuntimeException $e) {
         // Import sql
         $this->controller->out('Importing SQL to table: ' . $table);
         $this->executeSql($installSql);
         $this->controller->out('Imported');
     }
     if (!strpos($installSql, $table)) {
         // Write SQL file to project.
         @($fp = fopen($this->config['dir.dest'] . '/sql/install.sql', 'a+'));
         @fputs($fp, "\n\n\n" . $installSql);
         @fclose($fp);
         @($fp = fopen($this->config['dir.dest'] . '/sql/uninstall.sql', 'a+'));
         @fputs($fp, "\n\n" . $uninstallSql);
         @fclose($fp);
     }
 }
Example #3
0
 /**
  * doRender
  *
  * @param string            $name
  * @param XulEngine         $engine
  * @param \SimpleXmlElement $element
  * @param mixed             $data
  *
  * @throws \LogicException
  * @return  mixed
  */
 protected static function doRender($name, XulEngine $engine, \SimpleXmlElement $element, $data)
 {
     $grid = $data->xulControl->grid;
     $cells = static::renderChildren($engine, $element, $data);
     $grid->addRow(XmlHelper::getAttributes($element));
     foreach ($cells as $key => $cell) {
         $content = String::parseVariable($cell, $data);
         $attribs = XmlHelper::getAttributes($element);
         $grid->setRowCell($key, $content, $attribs);
     }
     reset($element);
     return $cells;
 }
Example #4
0
 /**
  * copyFile
  *
  * @param string $src
  * @param string $dest
  * @param array  $replace
  *
  * @return  void
  */
 protected function copyFile($src, $dest, $replace = array())
 {
     // Replace dest file name.
     $dest = String::parseVariable($dest, $replace);
     if (is_file($dest)) {
         $this->io->out('File exists: ' . $dest);
     } else {
         $content = String::parseVariable(file_get_contents($src), $replace);
         if (File::write($dest, $content)) {
             $this->io->out('File created: ' . $dest);
         }
     }
 }
Example #5
0
 /**
  * Create a html element.
  *
  * @param string $name    Element tag name.
  * @param mixed  $content Element content.
  * @param array  $attribs Element attributes.
  *
  * @return  string Created element string.
  */
 public static function create($name, $content = '', $attribs = array())
 {
     $name = trim($name);
     $unpaired = in_array(strtolower($name), static::$unpairedElements);
     $tag = '<' . $name;
     foreach ((array) $attribs as $key => $value) {
         if ($value !== null && $value !== false && $value !== '') {
             $tag .= ' ' . $key . '=' . String::quote($value, '""');
         }
     }
     if ($content) {
         if (!$content instanceof HtmlElement) {
             $content = implode(PHP_EOL, (array) $content);
         }
         $tag .= '>' . PHP_EOL . "\t" . $content . PHP_EOL . '</' . $name . '>';
     } else {
         $tag .= $unpaired ? ' />' : '></' . $name . '>';
     }
     return $tag;
 }
 /**
  * doRender
  *
  * @param string            $name
  * @param \SimpleXmlElement $element
  * @param mixed             $data
  *
  * @throws \UnexpectedValueException
  * @return  mixed
  */
 protected static function doRender($name, XulEngine $engine, \SimpleXmlElement $element, $data)
 {
     $formVar = XmlHelper::get($element, 'form', 'form');
     $fieldset = XmlHelper::get($element, 'name');
     if (!$fieldset) {
         throw new \UnexpectedValueException('Need "name" attribute in XUL <fieldset> element.');
     }
     $form = $data->{$formVar};
     if (!$form instanceof \JForm) {
         throw new \UnexpectedValueException(sprintf('No form data found in $data->%s.', $formVar));
     }
     $option = $data->view->option ?: 'LIB_WINDWALKER';
     $label = XmlHelper::get($element, 'label', $option . '_EDIT_FIELDSET_' . $fieldset);
     $label = String::parseVariable($label, $data);
     $html = '<legend>' . \JText::_(strtoupper($label)) . '</legend>';
     foreach ($form->getFieldset($fieldset) as $field) {
         $html .= $field->getControlGroup() . "\n\n";
     }
     $html = HtmlBuilder::create('fieldset', $html, XmlHelper::getAttributes($element));
     return $html;
 }
Example #7
0
 /**
  * convertPath
  *
  * @param string $path
  *
  * @return  string
  */
 protected function convertPath($path)
 {
     $user = Container::getInstance()->get('user');
     $date = DateHelper::getDate();
     $replace = array('username' => $user->username, 'name' => $user->name, 'session' => \JFactory::getSession()->getId(), 'year' => $date->year, 'month' => $date->month, 'day' => $date->day);
     return String::parseVariable($path, $replace);
 }
Example #8
0
 /**
  * getArguments
  *
  * @param \SimpleXmlElement $element
  * @param mixed             $data
  *
  * @return  array
  */
 protected static function getArguments($element, $data, $argumrntTag = 'argument')
 {
     $args = $element->xpath($argumrntTag);
     $return = array();
     foreach ($args as $arg) {
         if (isset($arg['data'])) {
             $return[] = ArrayHelper::getByPath($data, (string) $arg['data']);
         } else {
             if (strtolower($arg) == 'null') {
                 $arg = null;
             }
             if (strtolower($arg) == 'false') {
                 $arg = false;
             }
             $return[] = String::parseVariable((string) $arg, $data);
         }
     }
     return $return;
 }
 /**
  * replaceVariable
  *
  * @param $attributes
  * @param $data
  *
  * @return  mixed
  */
 protected static function replaceVariable($attributes, $data)
 {
     foreach ($attributes as &$attr) {
         $attr = String::parseVariable($attr, $data);
     }
     return $attributes;
 }
 /**
  * getSubsystemText
  *
  * @param \SplFileinfo $file
  *
  * @return  string
  */
 protected function getSubsystemText(\SplFileinfo $file)
 {
     $text = file_get_contents($file);
     $text = substr($text, strpos($text, '; {{controller.item.name.cap}}') - strlen($text));
     return String::parseVariable($text, $this->config['replace']);
 }