Esempio n. 1
0
    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $data = ['title' => 'Hello world!', 'meta_keywords' => 'magento 2 blog', 'meta_description' => 'Magento 2 blog default post.', 'identifier' => 'hello-world', 'content_heading' => 'Hello world!', 'content' => '<p>Welcome to <a title="Magefan - solutions for Magento 2" href="http://magefan.com/" target="_blank">Magefan</a> blog extension for Magento&reg; 2. This is your first post. Edit or delete it, then start blogging!</p>
<p><!-- pagebreak --></p>
<p>Please also read&nbsp;<a title="Magento 2 Blog online documentation" href="http://magefan.com/docs/magento-2-blog/" target="_blank">Online documentation</a>&nbsp;and&nbsp;<a href="http://magefan.com/blog/add-read-more-tag-to-blog-post-content/" target="_blank">How to add "read more" tag to post content</a></p>
<p>Follow Magefan on:</p>
<p><a title="Blog Extension for Magento 2 code" href="https://github.com/magefan/module-blog" target="_blank">GitHub</a>&nbsp;|&nbsp;<a href="https://twitter.com/magento2fan" target="_blank">Twitter</a>&nbsp;|&nbsp;<a href="https://www.facebook.com/magefan/" target="_blank">Facebook</a>&nbsp;|&nbsp;<a href="https://plus.google.com/+Magefan_Magento_2/posts/" target="_blank">Google +</a></p>', 'store_ids' => [0]];
        $this->_postFactory->create()->setData($data)->save();
    }
Esempio n. 2
0
 /**
  * Validate and Match Blog Pages and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $_identifier = trim($request->getPathInfo(), '/');
     if (strpos($_identifier, 'blog') !== 0) {
         return;
     }
     $identifier = str_replace(array('blog/', 'blog'), '', $_identifier);
     $condition = new \Magento\Framework\DataObject(['identifier' => $identifier, 'continue' => true]);
     $this->_eventManager->dispatch('magefan_blog_controller_router_match_before', ['router' => $this, 'condition' => $condition]);
     if ($condition->getRedirectUrl()) {
         $this->_response->setRedirect($condition->getRedirectUrl());
         $request->setDispatched(true);
         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]);
     }
     if (!$condition->getContinue()) {
         return null;
     }
     $identifier = $condition->getIdentifier();
     $success = false;
     $info = explode('/', $identifier);
     if (!$identifier) {
         $request->setModuleName('blog')->setControllerName('index')->setActionName('index');
         $success = true;
     } elseif (count($info) > 1) {
         $store = $this->_storeManager->getStore()->getId();
         switch ($info[0]) {
             case 'post':
                 $post = $this->_postFactory->create();
                 $postId = $post->checkIdentifier($info[1], $this->_storeManager->getStore()->getId());
                 if (!$postId) {
                     return null;
                 }
                 $request->setModuleName('blog')->setControllerName('post')->setActionName('view')->setParam('id', $postId);
                 $success = true;
                 break;
             case 'category':
                 $category = $this->_categoryFactory->create();
                 $categoryId = $category->checkIdentifier($info[1], $this->_storeManager->getStore()->getId());
                 if (!$categoryId) {
                     return null;
                 }
                 $request->setModuleName('blog')->setControllerName('category')->setActionName('view')->setParam('id', $categoryId);
                 $success = true;
                 break;
             case 'archive':
                 $request->setModuleName('blog')->setControllerName('archive')->setActionName('view')->setParam('date', $info[1]);
                 $success = true;
                 break;
             case 'search':
                 $request->setModuleName('blog')->setControllerName('search')->setActionName('index')->setParam('q', $info[1]);
                 $success = true;
                 break;
         }
     }
     if (!$success) {
         return null;
     }
     $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $_identifier);
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
 }
 /**
  * Retrieve post id by identifier
  * @param  string $identifier
  * @return int
  */
 protected function _getPostId($identifier)
 {
     if (is_null($this->_postId)) {
         $post = $this->_postFactory->create();
         $this->_postId = $post->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());
     }
     return $this->_postId;
 }
 public function generate(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->getData('identifier')) {
         return;
     }
     $identifier = trim($object->getData('title'));
     if (!$identifier) {
         return;
     }
     $from = ['Á', 'À', 'Â', 'Ä', 'Ă', 'Ā', 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С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', 'І', 'і', 'Ї', 'ї', 'Є', 'є', ' & ', '&'];
     $to = ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'G', 'G', 'G', 'G', 'G', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'g', 'g', 'g', 'g', 'g', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'IJ', 'J', 'K', 'L', 'L', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'CE', 'h', 'h', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'ij', 'j', 'k', 'l', 'l', 'n', 'n', 'n', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'W', 'Y', 'Y', 'Y', 'Z', 'Z', 'Z', 'r', 'r', 's', 's', 's', 's', 'B', 't', 't', 'b', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'w', 'y', 'y', 'y', 'z', 'z', 'z', 'A', 'B', 'V', 'H', 'D', 'e', 'Io', 'Z', 'Z', 'Y', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'Ch', 'C', 'Ch', 'Sh', 'Shtch', '', 'Y', '', 'E', 'Iu', 'Ia', 'a', 'b', 'v', 'h', 'd', 'e', 'io', 'z', 'z', 'y', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'ch', 'c', 'ch', 'sh', 'shtch', '', 'y', '', 'e', 'iu', 'ia', 'I', 'i', 'Ji', 'ji', 'Je', 'je', '-and-', '-and-'];
     $identifier = str_replace($from, $to, $identifier);
     $identifier = mb_strtolower($identifier);
     $identifier = preg_replace('/[^A-Za-z0-9-]+/', '-', $identifier);
     $identifier = preg_replace('/[--]+/', '-', $identifier);
     $identifier = trim($identifier, '-');
     $post = $this->_postFactory->create();
     $category = $this->_categoryFactory->create();
     $number = 1;
     while (true) {
         $finalIdentifier = $identifier . ($number > 1 ? '-' . $number : '');
         $postId = $post->checkIdentifier($finalIdentifier, $object->getStoreId());
         $categoryId = $category->checkIdentifier($finalIdentifier, $object->getStoreId());
         if (!$postId && !$categoryId) {
             break;
         } else {
             if ($postId && $postId == $object->getId() && $object instanceof \Magefan\Blog\Model\Post) {
                 break;
             }
             if ($categoryId && $categoryId == $object->getId() && $object instanceof \Magefan\Blog\Model\Category) {
                 break;
             }
         }
         $number++;
     }
     $object->setData('identifier', $finalIdentifier);
 }
 /**
  * {@inheritdoc}
  */
 public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
 {
     /* Create categories */
     $categoryData = ['title' => 'Category {n}', 'is_active' => 1, 'store_ids' => [0], 'path' => 0];
     $categoriesId = [];
     for ($i = 1; $i < 4; $i++) {
         $data = $categoryData;
         $data['title'] = str_replace('{n}', $i, $data['title']);
         $category = $this->_categoryFactory->create()->setData($data)->save();
         $categoriesId[] = $parentCategoryId = $category->getId();
         for ($j = 1; $j < 3; $j++) {
             $data = $categoryData;
             $data['title'] = str_replace('{n}', $i . '.' . $j, $data['title']);
             $data['path'] = $parentCategoryId;
             $category = $this->_categoryFactory->create()->setData($data)->save();
             $categoriesId[] = $parentCategoryId = $category->getId();
         }
     }
     /* Create Posts */
     $postData = ['title' => 'Article {n}', 'is_active' => 1, 'store_ids' => [0], 'categories' => [], 'relatedposts_links' => [], 'author_id' => 0];
     $postsId = [];
     $authorsId = $this->_authorFactory->create()->getCollection()->getAllIds();
     $time = time() - 86400 * 200;
     for ($i = 1; $i < 23; $i++) {
         $data = $postData;
         $data['title'] = str_replace('{n}', $i, $data['title']);
         $data['content'] = str_replace('{n}', $i, $this->_getPostContent());
         $data['publish_time'] = $time + 86400 * $i * 3;
         $data['creation_time'] = $data['publish_time'];
         $data['update_time'] = $data['publish_time'];
         if (count($categoriesId)) {
             for ($x = 0; $x < 2; $x++) {
                 $cid = $categoriesId[rand(0, count($categoriesId) - 1)];
                 $data['categories'][$cid] = $cid;
             }
         }
         if (count($postsId)) {
             for ($x = 0; $x < 5; $x++) {
                 $pid = $postsId[rand(0, count($postsId) - 1)];
                 $data['relatedposts_links'][$pid] = $pid;
             }
         }
         if (count($authorsId)) {
             $data['author_id'] = $authorsId[rand(0, count($authorsId) - 1)];
         }
         $post = $this->_postFactory->create()->setData($data)->save();
         $postsId[] = $post->getId();
     }
 }
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
 {
     $data = ['title' => 'Hello world!', 'meta_keywords' => 'magento 2 blog', 'meta_description' => 'Magento 2 blog default post.', 'identifier' => 'hello-world', 'content_heading' => 'Hello world!', 'content' => 'Welcome to <a target="_blank" href="http://magefan.com/" title="Magefan - solutions for Magento 2">Magefan</a> blog extension for Magento&reg; 2. This is your first post. Edit or delete it, then start blogging!', 'stores' => [0]];
     $this->_postFactory->create()->setData($data)->save();
 }