示例#1
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);
     }
 }
示例#2
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;
 }
示例#3
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();
 }
示例#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');
 }
示例#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);
 }
示例#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;
 }
 /**
  * Translate a long text by Google, if it too long, will separate it..
  *
  * @param   string  $text      String to translate.
  * @param   string  $SourceLan Translate from this language, eg: 'zh-TW'. Empty will auto detect.
  * @param   string  $ResultLan Translate to this language, eg: 'en'. Empty will auto detect.
  * @param   integer $separate  Separate text by a number of words, batch translate them and recombine to return.
  *
  * @return  string    Translated text.
  */
 public static function translate($text, $SourceLan = null, $ResultLan = null, $separate = 0)
 {
     // If text too big, separate it.
     if ($separate) {
         if (Utf8String::strlen($text) > $separate) {
             $text = Utf8String::str_split($text, $separate);
         } else {
             $text = array($text);
         }
     } else {
         $text = array($text);
     }
     $result = '';
     // Do translate by google translate API.
     foreach ($text as $txt) {
         $result .= self::gTranslate($txt, $SourceLan, $ResultLan);
     }
     return $result;
 }
 /**
  * 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)));
 }
示例#9
0
 /**
  * Utility function to sort an array of objects on a given field
  *
  * @param   array  $a              An array of objects
  * @param   mixed  $k              The key (string) or a array of key to sort on
  * @param   mixed  $direction      Direction (integer) or an array of direction to sort in [1 = Ascending] [-1 = Descending]
  * @param   mixed  $caseSensitive  Boolean or array of booleans to let sort occur case sensitive or insensitive
  * @param   mixed  $locale         Boolean or array of booleans to let sort occur using the locale language or not
  *
  * @return  array  The sorted array of objects
  *
  * @since   2.0
  */
 public static function sortObjects(array $a, $k, $direction = 1, $caseSensitive = true, $locale = false)
 {
     if (!is_array($locale) || !is_array($locale[0])) {
         $locale = array($locale);
     }
     $sortCase = (array) $caseSensitive;
     $sortDirection = (array) $direction;
     $key = (array) $k;
     $sortLocale = $locale;
     usort($a, function ($a, $b) use($sortCase, $sortDirection, $key, $sortLocale) {
         for ($i = 0, $count = count($key); $i < $count; $i++) {
             if (isset($sortDirection[$i])) {
                 $direction = $sortDirection[$i];
             }
             if (isset($sortCase[$i])) {
                 $caseSensitive = $sortCase[$i];
             }
             if (isset($sortLocale[$i])) {
                 $locale = $sortLocale[$i];
             }
             $va = $a->{$key}[$i];
             $vb = $b->{$key}[$i];
             if ((is_bool($va) || is_numeric($va)) && (is_bool($vb) || is_numeric($vb))) {
                 $cmp = $va - $vb;
             } elseif ($caseSensitive) {
                 $cmp = Utf8String::strcmp($va, $vb, $locale);
             } else {
                 $cmp = Utf8String::strcasecmp($va, $vb, $locale);
             }
             if ($cmp > 0) {
                 return $direction;
             }
             if ($cmp < 0) {
                 return -$direction;
             }
         }
         return 0;
     });
     return $a;
 }
示例#10
0
 /**
  * Test...
  *
  * @param   string  $string  @todo
  * @param   string  $expect  @todo
  *
  * @return  array
  *
  * @covers        Windwalker\String\Utf8String::compliant
  * @dataProvider  seedTestValid
  * @since         1.0
  */
 public function testCompliant($string, $expect)
 {
     $actual = Utf8String::compliant($string);
     $this->assertEquals($expect, $actual);
 }
示例#11
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;
 }
示例#12
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;
 }
示例#13
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;
 }
示例#14
0
 /**
  * validate
  *
  * @param Data $data
  *
  * @return  void
  *
  * @throws ValidFailException
  */
 protected function validate($data)
 {
     if (!$data->tos) {
         // throw new ValidFailException('You must agree terms and policy');
     }
     if (!$data->username) {
         throw new ValidFailException('Username empty');
     }
     if (!(new EmailValidator())->validate($data->email)) {
         throw new ValidFailException('Email not valid.');
     }
     if (!$data->password) {
         throw new ValidFailException('Password empty');
     }
     if (Utf8String::strlen($data->password) < 4) {
         throw new ValidFailException('Password should longer than 4 characters.');
     }
     if ($data->password != $data->password2) {
         throw new ValidFailException('Password not match.');
     }
 }