예제 #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;
 }
예제 #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
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = \Faker\Factory::create();
     $blogMapper = new DataMapper('blogs');
     $categoryMapper = new DataMapper('categories');
     $authorMapper = new DataMapper('authors');
     $postMapper = new DataMapper('posts');
     $psMappingMapper = new DataMapper('category_post_maps');
     $content = file_get_contents(__DIR__ . '/fixtures/testcase.md');
     list($introtext, $fulltext) = explode('<!-- {READMORE} -->', $content);
     $metadesc = $faker->text();
     foreach ($blogMapper->findAll() as $blog) {
         $authors = iterator_to_array($authorMapper->find(['blog' => $blog->id]));
         $categories = iterator_to_array($categoryMapper->find(['blog' => $blog->id]));
         // Post
         foreach (range(1, 30) as $row) {
             $data = array();
             $data['blog'] = $blog->id;
             $data['type'] = 'post';
             $data['title'] = $faker->sentence(rand(3, 8));
             $data['alias'] = \Windwalker\Filter\OutputFilter::stringURLSafe($data['title']);
             $data['introtext'] = $introtext;
             $data['fulltext'] = $fulltext;
             $data['metadesc'] = $metadesc;
             $data['state'] = 1;
             $data['created'] = $faker->dateTime->format('Y-m-d H:i:s');
             $data['modified'] = $faker->dateTime->format('Y-m-d H:i:s');
             $data['publish_up'] = '';
             $data['publish_down'] = '';
             $data['author'] = $faker->randomElement($authors)->id;
             $data = $postMapper->createOne($data);
             // Categories
             foreach ($faker->randomElements($categories, rand(1, 3)) as $category) {
                 $map['category'] = $category->id;
                 $map['post'] = $data['id'];
                 $psMappingMapper->createOne($map);
             }
         }
         // Static
         foreach (range(1, 3) as $row) {
             $data = array();
             $data['blog'] = $blog->id;
             $data['type'] = 'static';
             $data['title'] = $faker->sentence(rand(3, 8));
             $data['alias'] = \Windwalker\Filter\OutputFilter::stringURLSafe($data['title']);
             $data['introtext'] = $introtext;
             $data['fulltext'] = $fulltext;
             $data['metadesc'] = $metadesc;
             $data['state'] = 1;
             $data['created'] = $faker->dateTime->format('Y-m-d H:i:s');
             $data['modified'] = $faker->dateTime->format('Y-m-d H:i:s');
             $data['publish_up'] = '';
             $data['publish_down'] = '';
             $data['author'] = $faker->randomElement($authors)->id;
             $data = $postMapper->createOne($data);
         }
     }
     $this->command->out('Post Seeder executed.')->out();
 }
예제 #5
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;
 }
예제 #6
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $languages = LanguageMapper::find(array('state' => 1))->code;
     $languages[] = '*';
     $categories = CategoryMapper::find(array('parent_id != 0', 'type' => 'article'));
     if (WarderHelper::tableExists('users')) {
         $userIds = UserMapper::findAll()->id;
     } else {
         $userIds = range(1, 50);
     }
     $tags = TagMapper::findAll()->dump();
     foreach ($categories as $category) {
         foreach (range(7, 15) as $i) {
             $data = new Data();
             $lang = $faker->randomElement($languages);
             $data['category_id'] = $category->id;
             $data['title'] = '(' . $lang . ') ' . $faker->sentence(mt_rand(3, 5));
             $data['alias'] = OutputFilter::stringURLSafe($data['title']);
             $data['introtext'] = '(' . $lang . ') ' . $faker->paragraph(5);
             $data['fulltext'] = $faker->paragraph(5);
             $data['image'] = UnsplashHelper::getImageUrl();
             $data['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
             $data['version'] = mt_rand(1, 50);
             $data['created'] = $faker->dateTime->format(DateTime::getSqlFormat());
             $data['created_by'] = $faker->randomElement($userIds);
             $data['modified'] = $faker->dateTime->format(DateTime::getSqlFormat());
             $data['modified_by'] = $faker->randomElement($userIds);
             $data['ordering'] = $i;
             $data['language'] = $lang;
             $data['params'] = '';
             ArticleMapper::createOne($data);
             foreach ($faker->randomElements($tags, mt_rand(5, 7)) as $tag) {
                 $map = new Data();
                 $map->tag_id = $tag->id;
                 $map->target_id = $data->id;
                 $map->type = 'article';
                 TagMapMapper::createOne($map);
             }
             $this->outCounting();
         }
     }
 }
예제 #7
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = \Faker\Factory::create();
     $blogMapper = new DataMapper('blogs');
     $categoryMapper = new DataMapper('categories');
     foreach ($blogMapper->findAll() as $blog) {
         foreach (range(1, rand(3, 6)) as $row) {
             $data = array();
             $data['blog'] = $blog->id;
             $data['title'] = $faker->sentence(rand(3, 8));
             $data['alias'] = \Windwalker\Filter\OutputFilter::stringURLSafe($data['title']);
             $data['image'] = 'http://unsplash.it/300/200';
             $data['state'] = 1;
             $data['ordering'] = $row;
             $categoryMapper->createOne($data);
         }
     }
     $this->command->out('Category Seeder executed.')->out();
 }
예제 #8
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $users = (new UserMapper())->findColumn('id');
     CategoryRecord::resetFieldsCache();
     $record = new CategoryRecord();
     $ids = array();
     foreach (range(1, 30) as $i) {
         $record->reset();
         $data = new Data();
         $data['title'] = $faker->sentence(rand(1, 3));
         $data['alias'] = OutputFilter::stringURLSafe($data['title']);
         $data['type'] = 'topic';
         $data['description'] = $faker->sentence(5);
         $data['image'] = $faker->imageUrl();
         $data['version'] = rand(1, 50);
         $data['topics'] = rand(10, 100);
         $data['posts'] = rand(10, 100);
         $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['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
         // Color Image
         $params = array('bg_color' => $faker->randomElement($this->colors), 'image_icon' => $faker->randomElement($this->icons));
         $data['params'] = json_encode($params);
         $record->bind($data->dump());
         if ($i > 6) {
             $record->setLocation($faker->randomElement($ids), $record::LOCATION_LAST_CHILD);
         } else {
             $record->setLocation(1, $record::LOCATION_LAST_CHILD);
         }
         $record->store();
         $record->rebuildPath();
         $ids[] = $record->id;
         $this->command->out('.', false);
     }
     $this->command->out();
 }
예제 #9
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = \Faker\Factory::create();
     $blogMapper = new DataMapper('blogs');
     $users = (new DataMapper('users'))->findAll();
     foreach (range(1, 600) as $row) {
         $data['owner'] = $users[$faker->numberBetween(1, count($users) - 1)]->id;
         $data['title'] = $faker->sentence(4);
         $data['alias'] = \Windwalker\Filter\OutputFilter::stringURLSafe($data['title']);
         $data['sub_title'] = $faker->sentence(8);
         $data['description'] = $faker->text();
         $data['image'] = 'https://unsplash.it/200/300';
         $data['state'] = 1;
         $data['timezone'] = $faker->timezone;
         $data['disqus'] = 'asukademy';
         $data['webmaster'] = md5(1234);
         $data['analytics'] = 'UA-xxxx-xx-xx';
         $data['params'] = '';
         $blogMapper->createOne($data);
     }
     $this->command->out('Blog Seeder executed.')->out();
 }
예제 #10
0
 /**
  * Execute the controller.
  *
  * @throws \Exception
  * @return  mixed Return executed result.
  */
 public function execute()
 {
     $user = User::get($this->input->get('user_id'));
     $blog = $this->input->getVar('blog');
     $blog = new Data($blog);
     $blog->params = $this->input->getByPath('blog.params', array(), null);
     $isNew = !$blog->id;
     $blog->state = 1;
     $blog->alias = OutputFilter::stringURLSafe($blog->alias);
     if ($isNew) {
         $blog->params['css'] = $this->getDefaultCss();
     }
     if (!$this->validate($blog)) {
         return false;
     }
     $trans = Ioc::getDatabase()->getTransaction()->start();
     try {
         $blog->params = json_encode($blog->params);
         $this->blog = (new DataMapper('blogs'))->saveOne($blog, 'id');
         if ($isNew) {
             $author['user'] = $user->id;
             $author['blog'] = $this->blog->id;
             $author['owner'] = 1;
             $author['admin'] = 1;
             $this->author = (new DataMapper('authors'))->createOne($author);
         }
         $trans->commit();
     } catch (\Exception $e) {
         $trans->rollback();
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::buildHttp('admin:blog', ['id' => $blog->id ?: '']), 'Save fail', 'danger');
         return true;
     }
     $this->setRedirect(Router::buildHttp('admin:blogs'), 'Save Success', 'success');
     return true;
 }
예제 #11
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $record = new CategoryRecord();
     $languages = LanguageMapper::find(array('state' => 1))->code;
     $languages[] = '*';
     if (WarderHelper::tableExists('users')) {
         $userIds = UserMapper::findAll()->id;
     } else {
         $userIds = range(1, 50);
     }
     $existsRecordIds = array();
     foreach ($this->types as $type) {
         $existsRecordIds[$type] = array(1);
     }
     foreach (range(1, 30) as $i) {
         $record->reset();
         $lang = $faker->randomElement($languages);
         $record['title'] = $faker->sentence(mt_rand(1, 3)) . ' - [' . $lang . ']';
         $record['alias'] = OutputFilter::stringURLSafe($record['title']);
         $record['type'] = $faker->randomElement($this->types);
         $record['description'] = $faker->paragraph(5);
         $record['image'] = UnsplashHelper::getImageUrl();
         $record['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
         $record['version'] = mt_rand(1, 50);
         $record['created'] = $faker->dateTime->format(DateTime::getSqlFormat());
         $record['created_by'] = $faker->randomElement($userIds);
         $record['modified'] = $faker->dateTime->format(DateTime::getSqlFormat());
         $record['modified_by'] = $faker->randomElement($userIds);
         $record['language'] = $lang;
         $record['params'] = '';
         $record->setLocation($faker->randomElement($existsRecordIds[$record['type']]), $record::LOCATION_LAST_CHILD);
         $record->store();
         $record->rebuildPath();
         $existsRecordIds[$record['type']][] = $record->id;
         $this->outCounting();
     }
 }
예제 #12
0
 /**
  * prepareRecord
  *
  * @param NestedRecord|Record $record
  *
  * @return  void
  */
 protected function prepareRecord(Record $record)
 {
     $user = User::get();
     $date = DateTime::create();
     if (!$record->alias) {
         $record->alias = $record->title;
     }
     $record->alias = OutputFilter::stringURLUnicodeSlug($record->alias);
     if (!$record->alias) {
         $record->alias = OutputFilter::stringURLSafe($date->format('Y-m-d-H-i-s'));
     }
     // Created date
     if (!$record->created) {
         $record->created = $date->toSql();
     }
     // Modified date
     if ($record->id) {
         $record->modified = $date->toSql();
     }
     // Created user
     if (!$record->created_by) {
         $record->created_by = $user->id;
     }
     // Modified user
     if ($record->id) {
         $record->modified_by = $user->id;
     }
     // Set Ordering or Nested ordering
     if (!$record->id) {
         $record->setLocation($record->parent_id, $record::LOCATION_LAST_CHILD);
     }
     if (!$record->id) {
         $record->state = 1;
         $record->access = 1;
         $record->topics = 0;
         $record->posts = 0;
     }
 }
예제 #13
0
 protected function doExecute()
 {
     $data = $this->input->getVar('category');
     $data = new Data($data);
     $data['title'] = trim($data['title']);
     if (!$data['title']) {
         $this->setRedirect(Router::build('admin:categories'), 'Title should not be empty', 'danger');
         return false;
     }
     if (!$data['blog']) {
         $data['blog'] = Blog::get()->id;
     }
     $data['alias'] = OutputFilter::stringURLSafe(trim($data['title']));
     $data['alias'] = $data['alias'] ?: OutputFilter::stringURLSafe((string) new Date());
     $data['state'] = 1;
     if (!$data['ordering']) {
         $max = $this->getMaxOrder($data['blog']);
         $data['ordering'] = $max + 1;
     }
     try {
         $category = new Record('categories');
         if ($data['id']) {
             $category->load($data['id']);
         }
         $category->bind($data);
         $category->check();
         $category->store(true);
     } catch (\Exception $e) {
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::build('admin:categories'), 'Save Error', 'danger');
         return false;
     }
     $this->setRedirect(Router::build('admin:categories'), 'Create success', 'success');
     return true;
 }
예제 #14
0
 /**
  * createBlogAlias
  *
  * @param string $username
  *
  * @return  string
  */
 protected function createBlogAlias($username)
 {
     $username = strtolower($username);
     $alias = OutputFilter::stringURLSafe($username);
     $blogMapper = new DataMapper('blogs');
     if ($blogMapper->findOne(['alias' => $alias])->notNull()) {
         $alias = $alias . '-blog';
     }
     while ($blogMapper->findOne(['alias' => $alias])->notNull()) {
         $alias = 'u' . rand(100000, 9999999999.0);
     }
     return $alias;
 }
예제 #15
0
 /**
  * handleAlias
  *
  * @param   string  $alias
  *
  * @return  string
  */
 public function handleAlias($alias)
 {
     return OutputFilter::stringURLSafe($alias);
 }