Exemplo n.º 1
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $users = (new UserMapper())->findColumn('id');
     $mapper = new ArticleMapper();
     foreach (range(1, 5) as $i) {
         $data = new Data();
         $data['title'] = $faker->sentence(rand(3, 5));
         $data['alias'] = OutputFilter::stringURLSafe($data['title']);
         $data['short_title'] = trim(\Windwalker\String\Utf8String::substr($data['title'], 0, rand(5, 7)));
         $data['icon'] = $faker->randomElement($this->icons);
         $data['url'] = rand(0, 2) ? 'http://windwalker.io' : null;
         $data['body'] = $faker->paragraph(5);
         $data['images'] = $faker->imageUrl();
         $data['version'] = rand(1, 50);
         $data['created'] = $faker->dateTime->format(DateTime::FORMAT_SQL);
         $data['created_by'] = $faker->randomElement($users);
         $data['modified'] = $faker->dateTime->format(DateTime::FORMAT_SQL);
         $data['modified_by'] = $faker->randomElement($users);
         $data['ordering'] = $i;
         $data['state'] = 1;
         //$faker->randomElement(array(1, 1, 1, 1, 0, 0));
         $data['params'] = '';
         $mapper->createOne($data);
         $this->command->out('.', false);
     }
     $this->command->out();
 }
Exemplo n.º 2
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $paths = $data->currentCategory->path;
     $data->breadcrumbs = BreadcrumbHelper::getBreadcrumbs($paths);
     if ($data->currentCategory->id != 1) {
         $this->setTitle($data->currentCategory->title);
     }
     // Prepare format
     foreach ($data->categories as $category) {
         $category->last_post->user_params = new Registry($category->last_post->user_params);
     }
     foreach ($data->topics as $topic) {
         $topic->last_user_params = new Registry($topic->last_user_params);
     }
     $user = User::get();
     $data->isWatch = Notification::getNotification('category', $data->currentCategory->id, $user->id)->notNull();
     if ($data->currentCategory->id != 1) {
         $desc = $data->currentCategory->description;
         $desc = Utf8String::substr(strip_tags($desc), 0, 150);
         HtmlHeader::addMetadata('description', $desc, true);
         HtmlHeader::addOpenGraph('og:title', HtmlHeader::getPageTitle(), true);
         HtmlHeader::addOpenGraph('og:description', $desc, true);
         HtmlHeader::addOpenGraph('og:image', $data->currentCategory->image, true);
     }
 }
Exemplo n.º 3
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $markdown = new MarkdownExtra();
     foreach ($data['posts'] as $post) {
         $post->link = Router::buildHtml('front:post_default', ['id' => $post->id, 'alias' => $post->alias]);
         $post->introtext = $markdown->defaultTransform($post->introtext);
         $post->author = Author::getPostAuthor($post->author);
         $post->created = new Date($post->created);
         $post->created = $post->created->format('F j, Y');
     }
     foreach ($data['statics'] as $post) {
         $post->link = Router::buildHtml('front:static_default', ['id' => $post->id, 'alias' => $post->alias]);
     }
     // Title
     if ($data->type == 'home') {
         $title = $data->blog->title;
         $suffix = '';
         $data->bodyClass = 'home posts page-' . $data->page;
     } else {
         $title = '';
         $suffix = $data->blog->title;
         $data->bodyClass = 'home posts page-' . $data->page;
     }
     $data->pageTitle = $title;
     $data->pageTitle .= $data->page > 1 ? ' - Page ' . $data->page : '';
     $data->pageTitle .= $suffix ? '|' . $suffix : '';
     // Meta
     $desc = $data->blog->description;
     $desc = OutputFilter::cleanText($desc);
     $desc = Utf8String::substr($desc, 0, 200);
     $data->meta->desc = $desc;
 }
Exemplo n.º 4
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     if ($this->layout == 'default') {
         $paths = $this['topic']->category->path;
         $data->breadcrumbs = BreadcrumbHelper::getBreadcrumbs($paths);
         foreach ($data->posts as $post) {
             $post->raw_body = $post->body;
             $post->body = Markdown::render($post->body);
         }
         $user = User::get();
         $data->isWatch = Notification::getNotification('topic', $this['topic']->id, $user->id)->notNull();
         $this->setTitle($data->topic->title);
     } else {
         $this->setTitle('New Topic');
     }
     $desc = $data->topic->title;
     if ($data->posts[0]) {
         $desc = $data->posts[0]->body;
         $desc = Utf8String::substr(strip_tags($desc), 0, 150);
     }
     HtmlHeader::addMetadata('description', $desc, true);
     HtmlHeader::addOpenGraph('og:title', HtmlHeader::getPageTitle(), true);
     HtmlHeader::addOpenGraph('og:description', $desc, true);
     HtmlHeader::getMetadata()->removeOpenGraph('og:image');
 }
Exemplo n.º 5
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     parent::prepareData($data);
     $desc = $data->item->body;
     $desc = Utf8String::substr(strip_tags($desc), 0, 150);
     HtmlHeader::addMetadata('description', $desc, true);
     HtmlHeader::addOpenGraph('og:title', HtmlHeader::getPageTitle(), true);
     HtmlHeader::addOpenGraph('og:description', $desc, true);
     HtmlHeader::addOpenGraph('og:image', $data->item->image, true);
 }
Exemplo n.º 6
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $markdown = new MarkdownExtra();
     $text = $data['post']->introtext . $data['post']->fulltext;
     $data['post']['text'] = $markdown->defaultTransform($text);
     $data['post']['link'] = Router::buildHttp('front:post_default', ['id' => $data['post']['id'], 'alias' => $data['post']['alias']]);
     $data['post']->created = new Date($data['post']->created);
     $data['post']->created = $data['post']->created->format('F j, Y');
     foreach ($data['statics'] as $post) {
         $post->link = Router::buildHtml('front:static_default', ['id' => $post->id, 'alias' => $post->alias]);
     }
     $data->bodyClass = $data['type'] ?: 'post';
     // Meta
     $text = $data['post']->text;
     $desc = trim($data['post']->metadesc);
     $desc = $desc ?: Utf8String::substr(OutputFilter::cleanText($text), 0, 200);
     $data->meta->desc = $desc;
 }
 /**
  * normalizeBacktrace
  *
  * @param   array  $trace
  *
  * @return  array
  */
 public static function normalizeBacktrace(array $trace)
 {
     $trace = new Data($trace);
     $args = [];
     foreach ($trace['args'] as $arg) {
         if (is_array($arg)) {
             $arg = 'Array';
         } elseif (is_object($arg)) {
             $arg = ReflectionHelper::getShortName($arg);
         } elseif (is_string($arg)) {
             if (Utf8String::strlen($arg) > 20) {
                 $arg = Utf8String::substr($arg, 0, 20) . '...';
             }
             $arg = StringHelper::quote($arg);
         } elseif (is_null($arg)) {
             $arg = 'NULL';
         } elseif (is_bool($arg)) {
             $arg = $arg ? 'TRUE' : 'FALSE';
         }
         $args[] = $arg;
     }
     return array('file' => $trace['file'] ? $trace['file'] . ' (' . $trace['line'] . ')' : null, 'function' => ($trace['class'] ? $trace['class'] . $trace['type'] : null) . $trace['function'] . sprintf('(%s)', implode(', ', $args)));
 }
Exemplo n.º 8
0
 /**
  * Test...
  *
  * @param   string    $expect  @todo
  * @param   string    $string  @todo
  * @param   string    $start   @todo
  * @param   bool|int  $length  @todo
  *
  * @return  array
  *
  * @covers        Windwalker\String\Utf8String::substr
  * @dataProvider  seedTestSubstr
  * @since         1.0
  */
 public function testSubstr($expect, $string, $start, $length = false)
 {
     $actual = Utf8String::substr($string, $start, $length);
     $this->assertEquals($expect, $actual);
 }
Exemplo n.º 9
0
 /**
  * Is home page?
  *
  * @return  boolean
  */
 public static function isHome()
 {
     $uri = \JUri::getInstance();
     $root = $uri::root(true);
     // Get site route
     $route = Utf8String::substr($uri->getPath(), Utf8String::strlen($root));
     // Remove index.php
     $route = str_replace('index.php', '', $route);
     if (!trim($route, '/') && !$uri->getVar('option')) {
         return true;
     }
     return false;
 }
Exemplo n.º 10
0
 /**
  * endsWith
  *
  * @param string  $string
  * @param string  $target
  * @param boolean $caseSensitive
  *
  * @return  boolean
  */
 public static function endsWith($string, $target, $caseSensitive = true)
 {
     $stringLength = Utf8String::strlen($string);
     $targetLength = Utf8String::strlen($target);
     if ($stringLength < $targetLength) {
         return false;
     }
     if (!$caseSensitive) {
         $string = strtolower($string);
         $target = strtolower($target);
     }
     $end = Utf8String::substr($string, -$targetLength);
     return $end === $target;
 }
Exemplo n.º 11
0
 /**
  * Pivot $origin['prefix_xxx'] to $target['prefix']['xxx'].
  *
  * @param   string $prefix A prefix text.
  * @param   array  $origin Origin array to pivot.
  * @param   array  $target A target array to store pivoted value.
  *
  * @return  array  Pivoted array.
  */
 public static function pivotFromPrefix($prefix, $origin, $target = null)
 {
     $target = is_object($target) ? (object) $target : (array) $target;
     foreach ((array) $origin as $key => $row) {
         if (strpos($key, $prefix) === 0) {
             $key2 = Utf8String::substr($key, Utf8String::strlen($prefix));
             self::setValue($target, $key2, $row);
         }
     }
     return $target;
 }