{"action":"created","comment":{"url":"https://api.github.com/repos/dienncrelipa/test/pulls/comments/221815168","pull_request_review_id":160554665,"id":221815168,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyMTgxNTE2OA==","diff_hunk":"@@ -0,0 +1,1890 @@\n+<?php\n+/**\n+ * Created by PhpStorm.\n+ * User: macintosh\n+ * Date: 6/8/16\n+ * Time: 4:41 PM\n+ */\n+\n+namespace App\\Http\\Controllers\\Webapp;\n+\n+\n+use App\\Exceptions\\TitleDuplicatedException;\n+use App\\Models\\Activity;\n+use App\\Models\\Backup;\n+use App\\Models\\Keywords;\n+use App\\Libs\\CdsApiDriver;\n+use App\\Libs\\MessagesContainer\\Message;\n+use App\\Libs\\MessagesContainer\\MessageSet;\n+use App\\Models\\Category;\n+use App\\Models\\Post;\n+use App\\Models\\PostHistory;\n+use App\\Models\\PostMeta;\n+use App\\Models\\Site;\n+use App\\Models\\User;\n+use Carbon\\Carbon;\n+use Illuminate\\Http\\Request;\n+use Illuminate\\Routing\\Route;\n+use Illuminate\\Support\\Facades\\DB;\n+use Nayjest\\Grids\\Components\\FiltersRow;\n+use Nayjest\\Grids\\Components\\RenderFunc;\n+use Nayjest\\Grids\\Components\\SelectFilter;\n+use Nayjest\\Grids\\EloquentDataProvider;\n+use Nayjest\\Grids\\FilterConfig;\n+use Nayjest\\Grids\\GridConfig;\n+use Nayjest\\Grids\\DbalDataProvider;\n+use Nayjest\\Grids\\FieldConfig;\n+use Nayjest\\Grids\\Grid;\n+use Nayjest\\Grids\\ObjectDataRow;\n+use Nayjest\\Grids\\Components\\THead;\n+use Nayjest\\Grids\\Components\\TFoot;\n+use Nayjest\\Grids\\Components\\RecordsPerPage;\n+use Nayjest\\Grids\\Components\\ShowingRecords;\n+use Nayjest\\Grids\\Components\\OneCellRow;\n+use Nayjest\\Grids\\Components\\ColumnHeadersRow;\n+use Nayjest\\Grids\\Components\\Base\\RenderableRegistry;\n+use Nayjest\\Grids\\Components\\HtmlTag;\n+use Nayjest\\Grids\\Components\\Laravel5\\Pager;\n+\n+use HTML;\n+use Nayjest\\Grids\\SelectFilterConfig;\n+use Psy\\Exception\\BreakException;\n+\n+class PostController extends NeedAuthController\n+{\n+    public function __construct(Route $route, Request $request) {\n+        parent::__construct();\n+\n+        $this->activityLog = new Activity();\n+        $this->activityLog->setSession($this->currentSession);\n+\n+        $actionName = explode(\"\\\\\", $route->getActionName());\n+        $actionName = $actionName[count($actionName)-1];\n+\n+        $this->activityLog->setAction($actionName);\n+        if(($postId = $request->get('post_id', false)) !== false) {\n+            $this->activityLog->setPostId($postId);\n+        }\n+    }\n+\n+    public function __destruct() {\n+        $exceptActions = [\n+            'PostController@getIndex',\n+            'PostController@postStashChange',\n+//            'PostController@postLock',\n+            'PostController@postAutoSave'\n+        ];\n+\n+        if(array_search($this->activityLog->action, $exceptActions) !== false) {\n+            return;\n+        }\n+\n+        $this->activityLog->save();\n+    }\n+\n+    public function getIndex(Request $request) {\n+        $query = DB::getDoctrineConnection()->createQueryBuilder();\n+        $query->select([\n+                'p.id',\n+                'title',\n+                'published_status',\n+                'target_post_id',\n+                'p.id_post_old',\n+                'site_url',\n+                'fullname',\n+                'name',\n+                'keyword',\n+                'p.word_count',\n+                'type',\n+                'p.user_id',\n+                'p.is_delete'\n+            ])\n+            ->from('posts', 'p')\n+            ->leftJoin('p', 'sites', 's', 'p.site_id=s.id AND s.status = 1')\n+            ->leftJoin('p', 'post_meta', 'pm', 'p.id = pm.post_id')\n+            ->leftJoin('pm', 'keywords', 'k', 'pm.keyword_id = k.id')\n+            ->innerJoin('p', 'users', 'u', 'p.user_id=u.id');\n+\n+        $userQueryWhere = '';\n+        if(!$this->currentUser->is(User::ADMIN)) {\n+            $userQueryWhere = ' AND is_delete = 0 ';\n+        }\n+        if($this->currentUser->is(User::EDITOR) || $this->currentUser->is(User::CONTRIBUTOR)) {\n+            $userQueryWhere .= ' AND p.user_id = '.$this->currentUser->id;\n+        }\n+        if($request->get('keyword')) {\n+            $_kw = urldecode($request->get('keyword'));\n+            $queryWhere = '((p.site_id > 0 AND s.id > 0) OR (p.site_id = 0 OR p.site_id IS NULL)) AND keyword=\\'' . mysqli_real_escape_string(new \\mysqli(env('DB_HOST'), env('DB_USERNAME'), env('DB_PASSWORD'), env('DB_DATABASE'), env('DB_PORT')), $_kw) . '\\' AND k.type = 1'.$userQueryWhere;\n+        } else if(empty($request->all())) {\n+            $queryWhere = '((p.site_id > 0 AND s.id > 0) OR (p.site_id = 0 OR p.site_id IS NULL)) ' . $userQueryWhere . ' GROUP BY p.id';\n+        } else {\n+            $filters = array_column($request->all(), 'filters');\n+\n+            if($filters && count($filters[0]) == 1 && isset($filters[0]['records_per_page'])) {\n+                $queryWhere = '((p.site_id > 0 AND s.id > 0) OR (p.site_id = 0 OR p.site_id IS NULL)) '.$userQueryWhere . ' GROUP BY p.id';\n+            } else if(count($filters) == 0) {\n+                $queryWhere = '((p.site_id > 0 AND s.id > 0) OR (p.site_id = 0 OR p.site_id IS NULL)) '.$userQueryWhere . ' GROUP BY p.id';\n+            } else {\n+                $queryWhere = '((p.site_id > 0 AND s.id > 0) OR (p.site_id = 0 OR p.site_id IS NULL)) '.$userQueryWhere;\n+            }\n+\n+        }\n+\n+        $query->where($queryWhere);\n+\n+        $cfg = (new GridConfig())\n+          ->setDataProvider(\n+            new DbalDataProvider($query)\n+          )\n+          ->setColumns([\n+            (new FieldConfig)\n+              ->setName('id')\n+              ->setLabel('ID')\n+              ->addFilter(\n+                (new SelectFilterConfig())\n+                  ->setOperator(FilterConfig::OPERATOR_EQ)\n+                  ->setDefaultValue(null)\n+                  ->setTemplate('webapp.components.nayjest_columns_filter')\n+                  ->setFilteringFunc(function($val, DbalDataProvider $dap) {\n+                    return $dap->getBuilder()->andWhere(\"p.id = $val\")->addGroupBy('p.id');\n+                })\n+              )\n+              ->setSortable(true)\n+              ->setSorting(Grid::SORT_DESC)\n+              ->setCallback(function($pid) {\n+                  return \"<input type='checkbox' name='selected_ids[]' value='$pid' style='display: none'/>\".$pid;\n+              }),\n+            (new FieldConfig)\n+              ->setName('title')\n+              ->setLabel('タイトル')\n+              ->setSortable(true)\n+              ->setSorting(Grid::SORT_ASC)\n+              ->setCallback(function ($val, ObjectDataRow $row) {\n+                  $post_id = $row->getCellValue('id');\n+                  return '<a href=\"' . action('Webapp\\PostController@getEdit', $post_id) . '\"</a>'.$val.'</td>';\n+              })\n+              ->addFilter(\n+                (new FilterConfig)\n+                  ->setOperator(FilterConfig::OPERATOR_LIKE)\n+                  ->setFilteringFunc(function($val, DbalDataProvider $dap) {\n+                      $val = mysqli_real_escape_string(new \\mysqli(env('DB_HOST'), env('DB_USERNAME'), env('DB_PASSWORD'), env('DB_DATABASE'), env('DB_PORT')), $val);\n+                      return $dap->getBuilder()->andWhere(\"title like '%$val%'\")->addGroupBy('p.id');\n+                  })\n+              ),\n+            (new FieldConfig)\n+              ->setName('fullname')\n+              ->setLabel('ライター名')\n+              ->setSortable(true)\n+              ->setSorting(Grid::SORT_ASC)\n+              ->addFilter(\n+                (new SelectFilterConfig())\n+                  ->setDefaultValue(null)\n+                  ->setOperator(FilterConfig::OPERATOR_EQ)\n+                  ->setTemplate('webapp.components.nayjest_columns_filter')\n+                  ->setFilteringFunc(function($val, DbalDataProvider $dap) {\n+                      return $dap->getBuilder()->andWhere(\"u.id = $val\")->addGroupBy('p.id');\n+                  })\n+              )\n+                ->setCallback(function($val, ObjectDataRow $obj) {\n+                    $user_id = $obj->getCellValue('user_id');\n+                    if($this->currentUser->is('admin')) {\n+                        return '<a href=\"' . action('Webapp\\UserController@getEdit', $user_id) . '\">' . $val . '</a>' ;\n+                    }\n+                    return $val;\n+                }),\n+            (new FieldConfig)\n+              ->setName('keyword')\n+              ->setLabel('キーワード')\n+              ->addFilter(\n+                (new SelectFilterConfig())\n+                  ->setDefaultValue(null)\n+                  ->setName('keyword_fil')\n+                  ->setTemplate('webapp.components.nayjest_columns_filter')\n+                  ->setOperator(FilterConfig::OPERATOR_EQ)\n+                  ->setFilteringFunc(function($val, DbalDataProvider $dap) {\n+                      return $dap->getBuilder()->andWhere(\"k.id = $val\")->addGroupBy('p.id');\n+                  })\n+              )\n+              ->setCallback(function($val, ObjectDataRow $obj) {\n+                  return $obj->getCellValue('type') == 1 ? '<a href=\"' . url('/webapp/post') . '?keyword=' . urlencode($val) . '\">' . $val . '</a>' : '';\n+              }),\n+            (new FieldConfig)\n+              ->setName('published_status')\n+              ->setLabel('ステータス')\n+              ->setSortable(true)\n+              ->setSorting(Grid::SORT_ASC)\n+              ->setCallback(function($val) {\n+                  return $val == 1 ? $val = '<span class=\"label label-success fa fa-check\"><span class=\"tooltip action-top\">公開済み</span></span>' : $val = '<span class=\"label label-default fa fa-minus-circle\"><span class=\"tooltip action-top\">下書き</span></span>';\n+              })\n+              ->addFilter(\n+                  (new SelectFilterConfig())\n+                      ->setFilteringFunc(function($val, DbalDataProvider $dap) {\n+                          return $dap->getBuilder()->andWhere(\"p.published_status = $val\")->addGroupBy('p.id');\n+                      })\n+                    ->setOptions(['1' => '公開済み', '0' => '下書き'])\n+              ),\n+            (new FieldConfig)\n+              ->setName('name')\n+              ->setLabel('記事リンク')\n+              ->addFilter(\n+                (new SelectFilterConfig)\n+                  ->setDefaultValue(null)\n+                  ->setName('site_id')\n+                  ->setOperator(FilterConfig::OPERATOR_EQ)\n+                  ->setTemplate('webapp.components.nayjest_columns_filter')\n+                  ->setFilteringFunc(function($val, DbalDataProvider $dap) {\n+                      $post= false;\n+                      $site = false;\n+                      if(strpos($val,'SITE-') !== false){\n+                          $site = str_replace('SITE-', '', $val);\n+                          return $dap->getBuilder()->andWhere(\"p.site_id = $site\")->addGroupBy('p.id');\n+                      } else{\n+                          return $dap->getBuilder()->andWhere(\"p.id = $val\")->addGroupBy('p.id');\n+                      }\n+                  })\n+              )\n+              ->setCallback(function($val, ObjectDataRow $row) {\n+                  $site_url = $row->getCellValue('site_url');\n+                  $target_post_id = $row->getCellValue('target_post_id');\n+                  $post_link = !empty($target_post_id) ? $site_url . \"?p=\".$target_post_id : \"\";\n+                  return '<a target=\"_blank\" href=\"' . $post_link . '\">' . $post_link . '</a>';\n+              }),\n+            (new FieldConfig)\n+               ->setName('word_count')\n+               ->setLabel('文字数')\n+               ->setCallback(function($val){\n+                   return $val === -1 ? '未更新' : $val;\n+               }),\n+              (new FieldConfig)\n+                  ->setName('id_post_old')\n+                  ->setLabel('元ID')\n+                  ->setCallback(function($val){\n+                      return $val === 0 ? '' : $val;\n+                  }),\n+            (new FieldConfig)\n+              ->setName('is_delete')\n+              ->setLabel('編集')\n+              ->setCallback(function($val, ObjectDataRow $row) {\n+                  $clonePost = new Post();\n+                  $clonePost->id = $row->getCellValue('id');\n+                  $clonePost->user_id = $row->getCellValue('user_id');\n+                  $clonePost->is_delete = $row->getCellValue('is_delete');\n+                  $clonePost->published_status = $row->getCellValue('published_status');\n+\n+                  $status = $row->getCellValue('published_status');\n+                  $post_id = $row->getCellValue('id');\n+                  $action_delete = $this->currentUser->is(User::ADMIN) ? 'Webapp\\PostController@getDelete' : 'Webapp\\PostController@getWriterDelete';\n+                  $is_delete = '';\n+                  if($val){\n+                      $is_delete = '<span class=\"is-delete\"></span>';\n+                  }\n+                  $url_pub_draft = '';\n+\n+                  $nextStatusButton = ($status == 1) ? 'Draft' : 'Publish';\n+\n+                  if($clonePost->{'can'.$nextStatusButton.'By'}($this->currentUser)) {\n+                      $url_pub_draft = '<a href=\"'. action(($status==0 ? 'Webapp\\PostController@getPublish' : 'Webapp\\PostController@getDraft' ), $post_id) . '?hasFilter\">'\n+                          . '<span class=\"label'. ($status==0 ? ' label-success fa fa-check' : ' label-default fa fa-minus-circle' ) .'\"><span class=\"tooltip action-top\">'. ($status==0 ? '公開' : '下書きに戻す' ) .'</span></span>'\n+                          . '</a> ';\n+                  }\n+\n+                  $editHtml = '<a href=\"' . action('Webapp\\PostController@getEdit', $post_id) . '\">'\n+                      . '<span class=\"label label-warning fa fa-edit\"><span class=\"action-top tooltip\">編集</span></span>'\n+                      . '</a> ';\n+\n+                  $copyHtml = ($clonePost->canCopyBy($this->currentUser)) ? '<a href=\"' . action('Webapp\\PostController@getCopyPost', $post_id) . '?hasFilter\">'\n+                      . '<span class=\"label label-primary fa fa-copy\"><span class=\"action-top tooltip\">コピー</span></span>'\n+                      . '</a> ' : '';\n+\n+                  $deleteHtml = $clonePost->canWriteDeleteBy($this->currentUser) ? '<a href=\"' . action($action_delete, $post_id) . '?hasFilter\" class=\"btn-delete-post\" data-title=\"ID' . $post_id . 'の記事を削除\">'\n+                      . '<span class=\"label label-danger fa fa-trash\"><span class=\"action-top tooltip\">削除</span></span>'\n+                      . '</a>' : '';\n+\n+                  return '<div class=\"btn-toolbar\" role=\"toolbar\" aria-label=\"Action button group toolbar\">'\n+                                            . '<div class=\"btn-group\" role=\"group\" aria-label=\"Action group button\">'\n+                                                . $url_pub_draft\n+                                                . $editHtml\n+                                                . $copyHtml\n+                                                . $deleteHtml\n+                                            . '</div>'\n+                                        . '</div>' . $is_delete;\n+              }),\n+          ])\n+          ->setComponents([\n+            (new THead())\n+              ->setComponents([\n+                (new ColumnHeadersRow),\n+                (new FiltersRow)\n+                  ->setComponents([\n+                    (new RenderFunc(function() {\n+                        return \"\";\n+                    }))\n+                    ->setRenderSection('filters_row_column_name')\n+                  ]),\n+                (new OneCellRow)\n+                  ->setRenderSection(RenderableRegistry::SECTION_END)\n+                  ->setComponents([\n+                    (new RecordsPerPage)\n+                      ->setVariants([25, 50, 100, 1000])\n+                      ->setTemplate('webapp/components/nayjest_records_per_page_template'),\n+                    (new HtmlTag)\n+                      ->setContent('フィルタ')\n+                      ->setTagName('button')\n+                      ->setRenderSection(RenderableRegistry::SECTION_END)\n+                      ->setAttributes([\n+                        'class' => 'btn btn-success btn-sm filter-post'\n+                      ])\n+                  ])\n+              ])\n+              ,\n+            (new TFoot)\n+              ->setComponents([\n+                (new OneCellRow)\n+                  ->setComponents([\n+                    (new Pager),\n+                    (new HtmlTag)\n+                      ->setAttributes(['class' => 'pull-right'])\n+                      ->addComponent((new ShowingRecords)->setTemplate('webapp/components/nayjest_showing_records_template')),\n+                  ])\n+              ])\n+              ,\n+          ]);\n+        $grid = new Grid($cfg);\n+        $grid = $grid->render();\n+        return view('webapp/posts/index', [\n+          'posts_grid' => $grid,\n+          'action_delete' => $this->currentUser->is(User::ADMIN) ? 'delete' : 'writerDelete',\n+          'is_filter' => count(array_column($request->all(), 'filters')) ? true : false\n+        ]);\n+    }\n+\n+    public function getCreate(Request $request) {\n+        $categoriesSet = [];\n+        $sites = Site::where('status', 1)->get();\n+\n+        if(count($sites) == 0) {\n+            $request->session()->flash('flashMessageSet',\n+              (new MessageSet())->setType('warning')->add(new Message('ターゲットサイトがありません。記事を新規作成する前にターゲットサイトを追加してください', 'warning'))\n+            );\n+\n+            return redirect()->to(action('Webapp\\\\PostController@getIndex'))->send();\n+        }\n+\n+        foreach(Category::all() as $category) {\n+            if(!isset($categoriesSet[$category->site_id])) {\n+                $categoriesSet[$category->site_id] = [];\n+            }\n+            $categoriesSet[$category->site_id][] = $category;\n+        }\n+\n+        return view('webapp/posts/create', [\n+          'sites' => $sites,\n+          'categoriesSet' => $categoriesSet\n+        ]);\n+    }\n+\n+    public function postCreate(Request $request) {\n+        $postTitle = $request->get('post_title');\n+        $postContent = $request->get('post_content');\n+        $postDescription = trim($request->get('post_description'));\n+        if($request->get('site_id') == ''){\n+            $this->_flashMessage($request, 'ターゲットサイトを選んでください', 'danger');\n+            return redirect()->to(action('Webapp\\\\PostController@getIndex'))->send();\n+        }\n+\n+        $post = new Post();\n+\n+        if(($postId = $request->get('post_id', 0)) != 0) {\n+            $post = (!empty($postTmp = Post::find($postId)) && $postTmp->user_id == $this->currentUser->id) ? $postTmp : $post;\n+        }\n+        $post->title = !empty($postTitle) ? $postTitle : 'タイトルなし';\n+        $post->content = !empty($postContent) ? $postContent : '&nbsp;';\n+        $post->user_id = $this->currentUser->id;\n+        $post->site_id = $request->get('site_id');\n+        $post->category = $request->get('category');\n+        $post->description = $postDescription;\n+        $post->feature_img = $request->get('feature_img_url');\n+        $post->priority = (int)$request->get('post_priority', 0);\n+        $post->word_count = (int)$request->get('word_count', 0);\n+\n+        $submitType = strpos($request->get('submit_type'), '公開') !== false ? 'publish' : 'draft';\n+\n+        $post->save();\n+\n+        $post->saveHistory();\n+\n+        try {\n+            if(!$this->currentUser->is(User::CONTRIBUTOR) && $post->site_id > 0) {\n+                $apiUrl = Site::find($post->site_id)->api_url;\n+                $returnData = (new CdsApiDriver($apiUrl, [\n+                    'content' => $post->content,\n+                    'title' => $postTitle,\n+                    'categories' => [$post->category],\n+                    'post_excerpt' => $postDescription,\n+                    'post_status' => $submitType,\n+                    'feature_img' => $post->feature_img,\n+                    'author_name' => !empty($author = User::find($post->user_id)) ? $author->username : '',\n+                    'cback_url' => action('Webapp\\\\PostController@getEdit', $post->id),\n+                    'priority' => $post->priority,\n+                ]))->send('publish')->getResult();\n+\n+                if($returnData->data->post_id == 0) {\n+                    throw new \\Exception();\n+                }\n+                $post->content = Post::replaceIDButtonLink($returnData->data->post_id, $post->content);\n+                $post->target_post_id = $returnData->data->post_id;\n+                $post->published_status = ($submitType == 'publish') ? 1 : 0;\n+            }\n+\n+            $this->_flashMessage($request, $submitType == 'publish' ? '公開しました' : '下書きに保存しました', 'success');\n+        } catch(\\Exception $e) {\n+            $post->published_status = 0;\n+            $this->_flashMessage($request, '更新に失敗しました。もう一度ご確認ください。', 'warning');\n+        }\n+\n+        $post->save();\n+\n+        // Save kw and match post_id and kw_id\n+        // Main keyword\n+        $main = explode(',', $request->get('mainkw'));\n+        $uniqueMainKeyword = trim($main[0]);\n+        $mainKeyword = Keywords::getKeyword($uniqueMainKeyword, 1);\n+\n+        if(empty($mainKeyword)) {//there is no keyword\n+            if(strlen($uniqueMainKeyword) > 0) {\n+                // Insert new main keyword\n+                $mainKeyword = new Keywords();\n+                $mainKeyword->keyword = $uniqueMainKeyword;\n+                $mainKeyword->type = 1;\n+                $mainKeyword->save();\n+            }\n+        }\n+\n+        $postMetaMkw = PostMeta::getPostMeta($post->id, isset($mainKeyword->id) ? $mainKeyword->id : 0);\n+        if(empty($postMetaMkw) && isset($mainKeyword->id)) {\n+            // Insert new post-keyword relationship if not exist\n+            $postMetaMkw = new PostMeta();\n+            $postMetaMkw->post_id = $post->id;\n+            $postMetaMkw->keyword_id = $mainKeyword->id;\n+            $postMetaMkw->save();\n+        }\n+\n+        // Sub keywords\n+        $subs = explode(',', $request->get('subkws'));\n+        foreach ($subs as $item) {\n+            $trimmedItem = trim($item);\n+            if(strlen($trimmedItem) == 0) {\n+                continue;\n+            }\n+\n+            $subKeyword = Keywords::getKeyword($trimmedItem, 2);\n+\n+            if(empty($subKeyword)) {\n+                // Insert new keyword\n+                $subKeyword = new Keywords();\n+                $subKeyword->keyword = $trimmedItem;\n+                $subKeyword->type = 2;\n+                $subKeyword->save();\n+\n+                // Save post-keyword relationship\n+            }\n+\n+            $postMetaSkw = PostMeta::getPostMeta($post->id, $subKeyword->id);\n+            if(empty($postMetaSkw)) {\n+                // Insert new post-keyword relationship if not exist\n+                $postMetaSkw = new PostMeta();\n+                $postMetaSkw->post_id = $post->id;\n+                $postMetaSkw->keyword_id = $subKeyword->id;\n+                $postMetaSkw->save();\n+            }\n+\n+\n+        }\n+\n+        if(strpos($request->get('submit_type'),'公開') !== false || strpos($request->get('submit_type'),'下書き') !== false){\n+            return redirect()->to(action('Webapp\\\\PostController@getEdit', $post->id))->send();\n+        }else if(strpos($request->get('submit_type'),'プレビュー') !== false){\n+            return redirect()->to(action('Webapp\\\\PostController@getPreviewIframe', $post->id))->send();\n+        }\n+\n+        return redirect()->to(action('Webapp\\\\PostController@getEdit', $post->id))->send();\n+    }\n+\n+    public function postCreateAjax(Request $request) {\n+        $post = new Post();\n+\n+        if(($postId = $request->get('post_id', 0)) != 0) {\n+            $post = (!empty($postTmp = Post::find($postId)) && $postTmp->user_id == $this->currentUser->id) ? $postTmp : $post;\n+        }\n+\n+        $postTitle = $request->get('post_title');\n+        $postContent = $request->get('post_content');\n+        $postChecksum = $request->get('checksum', 0);\n+        $postDescription = trim($request->get('post_description'));\n+\n+        if($post->isLock($this->currentSession)) {\n+            $this->activityLog->setInfo('Locked');\n+            return ['error' => [\n+                'message' => 'このコンテンツは現在ロックされています。編集できません'\n+            ]];\n+        }\n+\n+        if(empty($postChecksum) && empty($postContent)) {\n+            $this->activityLog->setInfo('Empty content');\n+            return ['error' => [\n+                'message' => '投稿内容は空です'\n+            ]];\n+        }\n+\n+        $calculatedChecksum = Post::calculateChecksum($postContent);\n+\n+        if($postChecksum != $calculatedChecksum) {\n+            $this->activityLog->setInfo('Checksum failed');\n+            return ['error' => [\n+                'message' => 'サーバへ送信する内容にエラーがあります'\n+            ]];\n+        }\n+\n+        $oldTitle = $post->title;\n+\n+        $post->title = !empty($postTitle) ? $postTitle : 'タイトルなし';\n+        $post->content = !empty($postContent) ? $postContent : '&nbsp;';\n+        $post->user_id = $this->currentUser->id;\n+        $post->site_id = $request->get('site_id');\n+        $post->category = $request->get('category');\n+        $post->description = $postDescription;\n+        $post->feature_img = $request->get('feature_img_url');\n+        $post->priority = (int)$request->get('post_priority', 0);\n+        $post->published_status = 0;\n+        $post->word_count = (int)$request->get('word_count', 0);\n+\n+        $submitType = strpos($request->get('submit_type'), '公開') !== false ? 'publish' : 'draft';\n+\n+        if($submitType == 'publish' && !$post->canPublishBy($this->currentUser)) {\n+            $submitType = 'draft';\n+        }\n+\n+        if($submitType == 'publish' && $this->currentUser->is(User::CONTRIBUTOR)){\n+            $this->activityLog->setInfo('Contributor can not publish');\n+            return '404 Not Found';\n+        }\n+\n+        $post->save();\n+\n+        $post->saveHistory();\n+\n+        $this->activityLog->setPostId($post->id);\n+        $this->activityLog->addMeta('SubmitType', $submitType);\n+\n+        if($submitType == 'publish'){\n+            try {\n+                if (!Post::isUniquePostByTitle($post)) {\n+                    throw new TitleDuplicatedException('このタイトルは存在しています。公開できないのでタイトルを変更してください。');\n+                }\n+\n+                if (!$this->currentUser->is(User::CONTRIBUTOR) && $post->site_id > 0) {\n+                    $apiUrl = Site::find($post->site_id)->api_url;\n+                    $returnData = (new CdsApiDriver($apiUrl, [\n+                        'content' => $post->content,\n+                        'title' => $postTitle,\n+                        'categories' => [$post->category],\n+                        'post_excerpt' => $postDescription,\n+                        'post_status' => $submitType,\n+                        'feature_img' => $post->feature_img,\n+                        'author_name' => !empty($author = User::find($post->user_id)) ? $author->username : '',\n+                        'cback_url' => action('Webapp\\\\PostController@getEdit', $post->id),\n+                        'priority' => $post->priority,\n+                    ]))->send('publish')->getResult();\n+\n+                    if ($returnData->data->post_id == 0) {\n+                        $this->activityLog->addMeta('PublishedStatus', 'failed');\n+                        throw new \\Exception();\n+                    }\n+                    $post->content = Post::replaceIDButtonLink($returnData->data->post_id, $post->content);\n+                    $post->target_post_id = $returnData->data->post_id;\n+                    $post->published_status = 1;\n+                    $this->activityLog->addMeta('PublishedStatus', 'success');\n+                    $this->activityLog->addMeta('TargetPostId', $post->target_post_id);\n+                }\n+\n+                $this->_flashMessage($request, '公開しました', 'success');\n+            } catch(TitleDuplicatedException $e) {\n+                $this->_flashMessage($request, $e->getMessage(), 'danger');\n+                $this->activityLog->addMeta('Error', 'Title duplicated: '.$post->title);\n+                $post->title = $oldTitle;\n+            } catch(\\Exception $e) {\n+                $post->published_status = 0;\n+                $this->activityLog->addMeta('PublishedStatus', 'failed');\n+                $this->_flashMessage($request, '更新に失敗しました。もう一度ご確認ください。', 'warning');\n+            }\n+\n+            $post->save();\n+        }else{\n+            $this->_flashMessage($request, '下書きに保存しました', 'success');\n+        }\n+\n+        $this->activityLog->addMeta('NewPublishedStatus', $post->published_status);\n+\n+        // Save kw and match post_id and kw_id\n+        // Main keyword\n+        $main = explode(',', $request->get('mainkw'));\n+        $uniqueMainKeyword = trim($main[0]);\n+        $mainKeyword = Keywords::getKeyword($uniqueMainKeyword, 1);\n+\n+        if(empty($mainKeyword)) {//there is no keyword\n+            if(strlen($uniqueMainKeyword) > 0) {\n+                // Insert new main keyword\n+                $mainKeyword = new Keywords();\n+                $mainKeyword->keyword = $uniqueMainKeyword;\n+                $mainKeyword->type = 1;\n+                $mainKeyword->save();\n+            }\n+        }\n+\n+        $postMetaMkw = PostMeta::getPostMeta($post->id, isset($mainKeyword->id) ? $mainKeyword->id : 0);\n+        if(empty($postMetaMkw) && isset($mainKeyword->id)) {\n+            // Insert new post-keyword relationship if not exist\n+            $postMetaMkw = new PostMeta();\n+            $postMetaMkw->post_id = $post->id;\n+            $postMetaMkw->keyword_id = $mainKeyword->id;\n+            $postMetaMkw->save();\n+        }\n+\n+        // Sub keywords\n+        $subs = explode(',', $request->get('subkws'));\n+        foreach ($subs as $item) {\n+            $trimmedItem = trim($item);\n+            if(strlen($trimmedItem) == 0) {\n+                continue;\n+            }\n+\n+            $subKeyword = Keywords::getKeyword($trimmedItem, 2);\n+\n+            if(empty($subKeyword)) {\n+                // Insert new keyword\n+                $subKeyword = new Keywords();\n+                $subKeyword->keyword = $trimmedItem;\n+                $subKeyword->type = 2;\n+                $subKeyword->save();\n+\n+                // Save post-keyword relationship\n+            }\n+\n+            $postMetaSkw = PostMeta::getPostMeta($post->id, $subKeyword->id);\n+            if(empty($postMetaSkw)) {\n+                // Insert new post-keyword relationship if not exist\n+                $postMetaSkw = new PostMeta();\n+                $postMetaSkw->post_id = $post->id;\n+                $postMetaSkw->keyword_id = $subKeyword->id;\n+                $postMetaSkw->save();\n+            }\n+\n+\n+        }\n+\n+        return [\n+            'data' => [\n+                'id' => $post->id,\n+                'checksum' => $calculatedChecksum\n+            ],\n+            'next' => action('Webapp\\\\PostController@getEdit', $post->id)\n+        ];\n+    }\n+\n+    public function getEdit(Request $request, $postId = 0) {\n+        $this->activityLog->setPostId($postId);\n+\n+        if(empty($post = Post::find($postId))\n+            || !$post->canViewBy($this->currentUser)\n+            || ($post->site_id > 0 && Site::find($post->site_id)->status != 1) ) {\n+            $this->activityLog->setInfo('Not found');\n+            return '404 Not Found';\n+        }\n+\n+        $readOnly = !$post->canEditBy($this->currentUser);\n+\n+        // Lock detect\n+        if(!($lockStatus = $post->isLock($this->currentSession)) && !$readOnly) {\n+            $post->lock($this->currentSession);\n+        }\n+\n+        $categoriesSet = [];\n+\n+        foreach(Category::all() as $category) {\n+            if(!isset($categoriesSet[$category->site_id])) {\n+                $categoriesSet[$category->site_id] = [];\n+            }\n+            $categoriesSet[$category->site_id][] = $category;\n+        }\n+\n+        $post->site = Site::find($post->site_id);\n+\n+        $pmt = new PostMeta();\n+        $pmt_data = $pmt->getPostMetaByPostId($post->id);\n+        $subkws = '';\n+        $mainkw = '';\n+        foreach ($pmt_data as $value) {\n+            if($value->type == 2) {\n+                $subkws .= $value->keyword . ',';\n+            } elseif ($value->type == 1) {\n+                $mainkw .= $value->keyword . ',';\n+            }\n+        }\n+        $action_delete = $this->currentUser->is(User::ADMIN) ? 'Webapp\\PostController@getDelete' : 'Webapp\\PostController@getWriterDelete';\n+\n+        $clientChecksum = $post->getLastClientChecksum();\n+        $recoverChecksum = null;\n+\n+        if(!empty($checksum) && $post->getChecksum() != $clientChecksum) {\n+            $this->_flashMessage($request,\n+                'Content failed integrity check, maybe error when saving or database was manipulated. '.\n+                'Editor will try to recover from backup. If error continue, please contact admin with message: Checksum failed('.$checksum.')'\n+                , 'danger');\n+            $recoverChecksum = $clientChecksum;\n+        }\n+\n+        $site = Site::find($post->site_id);\n+        $additionCss = (!empty($site)) ? $site->getAdditionCss() :null;\n+        $draftUnsaved = PostHistory::getFirstFrom($post, PostHistory::STATUS_DRAFT, $post->updated_at->toDateTimeString());\n+\n+        return view('webapp/posts/edit'.(($readOnly) ? '_readonly' : ''), [\n+            'post' => $post,\n+            'lockStatus' => $lockStatus,\n+            'sites' => Site::where('status', 1)->get(),\n+            'categoriesSet' => $categoriesSet,\n+            'subkws' => $subkws,\n+            'mainkw' => $mainkw,\n+            'action_delete' => $action_delete,\n+            'additionCss' => $additionCss,\n+            'postChecksum' => $clientChecksum,\n+            'recoverChecksum' => $recoverChecksum,\n+            'draftUnsaved' => $draftUnsaved,\n+            'readOnly' => $readOnly\n+        ]);\n+    }\n+\n+    public function postEdit(Request $request, $postId = 0) {\n+        if(empty($post = Post::find($postId)) || !$post->canEditBy($this->currentUser) ) {\n+            return '404 Not Found';\n+        }\n+\n+\n+        if($post->isLock($this->currentSession)) {\n+            $this->_flashMessage($request, 'このコンテンツは現在ロックされています。編集できません。', 'danger');\n+            return redirect()->to(action('Webapp\\\\PostController@getEdit', $postId))->send();\n+        }\n+        if($request->get('site_id') == ''){\n+            $this->_flashMessage($request, 'ターゲットサイトを選んでください', 'danger');\n+            return redirect()->to(action('Webapp\\\\PostController@getEdit', $postId))->send();\n+        }\n+\n+        $postTitle = $request->get('post_title');\n+        $postContent = $request->get('post_content');\n+        $postDescription = trim($request->get('post_description'));\n+\n+        $previousContent = $post->content;\n+        $post->title = !empty($postTitle) ? $postTitle : 'タイトルなし';\n+        $post->content = $postContent;\n+        $post->category = $request->get('category');\n+        $post->description = $postDescription;\n+        $post->feature_img = !empty($request->get('new_feature_img_url')) ? $request->get('new_feature_img_url') : $request->get('feature_img_url');\n+\n+        $post->priority = (int)$request->get('post_priority', 0);\n+        $post->word_count = (int)$request->get('word_count', 0);\n+\n+        $submitType = strpos($request->get('submit_type'),'下書き') !== false ? 'draft' : 'publish';\n+\n+        if($submitType == 'publish' && $this->currentUser->is(User::CONTRIBUTOR)){\n+            return '404 Not Found';\n+        }\n+\n+        $oldSiteId = $post->site_id;\n+        $oldTargetPostId = $post->target_post_id;\n+        $oldPostId = 0;\n+        if($post->site_id == 0 || $oldSiteId != $request->get('site_id')) {\n+            $post->site_id = $request->get('site_id');\n+        }\n+\n+        try {\n+//            $action = ($submitType == 'publish' && $post->published_status == 0 && $post->target_post_id == 0) ? 'publish' : 'edit';\n+            if( ($oldSiteId != $request->get('site_id')) || $oldSiteId == 0\n+                    || ($post->published_status == 0 && $post->target_post_id == 0) ) {\n+                $action = 'publish';\n+            } else {\n+                $action = 'edit';\n+            }\n+\n+            $post->published_status = ($submitType == 'publish' && $post->site_id > 0) ? 1 : 0;\n+\n+            if(!$this->currentUser->is(User::CONTRIBUTOR)\n+                && $post->site_id > 0) {\n+                $apiUrl = Site::find($post->site_id)->api_url;\n+\n+                  $returnData = (new CdsApiDriver($apiUrl, [\n+                    'content' => $postContent,\n+                    'title' => $postTitle,\n+                    'categories' => [$post->category],\n+                    'post_id' => $post->target_post_id,\n+                    'post_excerpt' => $postDescription,\n+                    'post_status' => $submitType,\n+                    'feature_img' => $post->feature_img,\n+                    'author_name' => !empty($author = User::find($post->user_id)) ? $author->username : '',\n+                    'cback_url' => action('Webapp\\\\PostController@getEdit', $post->id),\n+                    'old_post_id' => $oldPostId,\n+                    'priority' => $post->priority,\n+                  ]))->send($action)->getResult();\n+                  if($returnData->data->post_id == 0) {\n+                    throw new \\Exception();\n+                  }\n+                  $post->content = Post::replaceIDButtonLink($returnData->data->post_id, $postContent, $oldPostId);\n+                  $post->target_post_id = $returnData->data->post_id;\n+                  $apiUrlOldTarget = ($oldSiteId != 0) ? Site::find($oldSiteId)->api_url : null;\n+\n+                  if($post->target_post_id != 0 && $oldSiteId != $post->site_id && $oldSiteId != 0 && $oldTargetPostId != 0) {\n+                    $resData = (new CdsApiDriver($apiUrlOldTarget, ['post_id' => $oldTargetPostId]))->send('delete')->getResult();\n+                    if($resData->data->post == 'ERROR') {\n+                        throw new \\Exception();\n+                    }\n+                  }\n+            }\n+\n+            $this->_flashMessage($request, $submitType == 'publish' ? '公開しました' : '下書きに保存しました', 'success');\n+        } catch(\\Exception $e) {\n+            $post->content = Post::replaceIDButtonLink('__POSTID__', $postContent, $oldPostId);\n+            $post->target_post_id = 0;\n+            $this->_flashMessage($request, '更新に失敗しました。もう一度ご確認ください。' . $e->getMessage(), 'warning');\n+        }\n+\n+        $post->save();\n+        $post->saveHistory();\n+\n+        // Update Post meta and keywords\n+        // Main keyword\n+        PostMeta::deletePostMetaByPostId($post->id);\n+        $main = explode(',', $request->get('mainkw'));\n+\n+        $uniqueMainKeyword = trim($main[0]);\n+        $mainKeyword = Keywords::getKeyword($uniqueMainKeyword, 1);\n+\n+        if(empty($mainKeyword)) {//there is no keyword\n+            if(strlen($uniqueMainKeyword) > 0) {\n+                // Insert new main keyword\n+                $mainKeyword = new Keywords();\n+                $mainKeyword->keyword = $uniqueMainKeyword;\n+                $mainKeyword->type = 1;\n+                $mainKeyword->save();\n+            }\n+        }\n+\n+        $postMetaMkw = PostMeta::getPostMeta($post->id, isset($mainKeyword->id) ? $mainKeyword->id : 0);\n+        if(empty($postMetaMkw) && isset($mainKeyword->id)) {\n+            // Insert new post-keyword relationship if not exist\n+            $postMetaMkw = new PostMeta();\n+            $postMetaMkw->post_id = $post->id;\n+            $postMetaMkw->keyword_id = $mainKeyword->id;\n+            $postMetaMkw->save();\n+        }\n+\n+        // Sub keywords\n+        $subs = explode(',', $request->get('subkws'));\n+        foreach ($subs as $item) {\n+            $trimmedItem = trim($item);\n+            if(strlen($trimmedItem) == 0) {\n+                continue;\n+            }\n+\n+            $subKeyword = Keywords::getKeyword($trimmedItem, 2);\n+\n+            if(empty($subKeyword)) {\n+                // Insert new keyword\n+                $subKeyword = new Keywords();\n+                $subKeyword->keyword = $trimmedItem;\n+                $subKeyword->type = 2;\n+                $subKeyword->save();\n+\n+                // Save post-keyword relationship\n+            }\n+\n+            $postMetaSkw = PostMeta::getPostMeta($post->id, $subKeyword->id);\n+            if(empty($postMetaSkw)) {\n+                // Insert new post-keyword relationship if not exist\n+                $postMetaSkw = new PostMeta();\n+                $postMetaSkw->post_id = $post->id;\n+                $postMetaSkw->keyword_id = $subKeyword->id;\n+                $postMetaSkw->save();\n+            }\n+\n+\n+        }\n+\n+        if(strpos($request->get('submit_type'),'公開') !== false || strpos($request->get('submit_type'),'下書き') !== false){\n+            return redirect()->to(action('Webapp\\\\PostController@getEdit', $postId))->send();\n+        }else if(strpos($request->get('submit_type'),'プレビュー') !== false){\n+            return redirect()->to(action('Webapp\\\\PostController@getPreviewIframe', $postId))->send();\n+        }\n+\n+        return redirect()->to(action('Webapp\\\\PostController@getEdit', $postId))->send();\n+    }\n+\n+    public function postEditAjax(Request $request, $postId) {\n+        $this->activityLog->setPostId($postId);\n+\n+        if(empty($post = Post::find($postId)) || !$post->canEditBy($this->currentUser) ) {\n+            $this->activityLog->setInfo('Not found');\n+            return ['error' => [\n+                'message' => '記事が見つかりません'\n+            ]];\n+        }\n+\n+        if($post->isLock($this->currentSession)) {\n+            $this->activityLog->setInfo('Locked');\n+            return ['error' => [\n+                'message' => 'このコンテンツは現在ロックされています。編集できません。'\n+            ]];\n+        }\n+\n+        $postChecksum = $request->get('checksum', 0);\n+        $postContent = $request->get('post_content');\n+\n+        if(empty($postChecksum) && empty($postContent)) {\n+            PostHistory::saveFromSession($request->session(), $post);\n+            $this->activityLog->setInfo('Empty content');\n+            return ['error' => [\n+                'message' => '投稿内容は空です'\n+            ]];\n+        }\n+\n+        $calculatedChecksum = Post::calculateChecksum($postContent);\n+\n+        if($postChecksum != $calculatedChecksum) {\n+            PostHistory::saveFromSession($request->session(), $post);\n+            $this->activityLog->setInfo('Checksum failed');\n+            return ['error' => [\n+                'message' => 'サーバへ送信する内容にエラーがあります'\n+            ]];\n+        }\n+\n+        $postTitle = $request->get('post_title');\n+        $postDescription = trim($request->get('post_description'));\n+\n+        $oldTitle = $post->title;\n+        $post->title = !empty($postTitle) ? $postTitle : 'タイトルなし';\n+        $post->content = $postContent;\n+        $post->description = $postDescription;\n+        $post->feature_img = !empty($request->get('new_feature_img_url')) ? $request->get('new_feature_img_url') : $request->get('feature_img_url');\n+\n+        $post->priority = (int)$request->get('post_priority', 0);\n+        $post->word_count = (int)$request->get('word_count', 0);\n+\n+        $submitType = strpos($request->get('submit_type'),'下書き') !== false ? 'draft' : 'publish';\n+\n+        $postAction = 'can'.ucfirst($submitType).'By';\n+\n+        if($submitType == 'publish' && !$post->{$postAction}($this->currentUser)) {\n+            $this->_flashMessage($request, 'Action is not permitted', 'danger');\n+            $this->activityLog->setInfo(\"$submitType is not permitted\");\n+            return redirect()->to($request->url());\n+        }\n+\n+        $this->activityLog->addMeta('SubmitType', $submitType);\n+        $this->activityLog->addMeta('PreviousPublishedStatus', $post->published_status);\n+\n+        $oldStatus = $post->published_status;\n+\n+        $oldSiteId = $post->site_id;\n+        $this->activityLog->addMeta('PreviousSiteId', $oldSiteId);\n+\n+        $oldTargetPostId = $post->target_post_id;\n+        $oldPostId = 0;\n+\n+        $newCategory = $request->get('category');\n+        $newSiteId = $post->site_id;\n+\n+        if($post->site_id == 0 || $oldSiteId != $request->get('site_id')) {\n+            $newSiteId = $request->get('site_id');\n+        }\n+\n+        try {\n+            if($this->currentUser->is(User::CONTRIBUTOR)) {\n+                throw new BreakException();\n+            }\n+\n+            if ($submitType == 'publish' && !Post::isUniquePostByTitle($post, ['site_id' => $newSiteId])) {\n+                throw new TitleDuplicatedException('このタイトルは存在しています。公開できないのでタイトルを変更してください。');\n+            }\n+\n+            if ($oldSiteId != $newSiteId && $oldSiteId != 0 && $oldTargetPostId != 0) {\n+                $apiUrlOldTarget = ($oldSiteId != 0) ? Site::find($oldSiteId)->api_url : null;\n+                try {\n+                    (new CdsApiDriver($apiUrlOldTarget, ['post_id' => $oldTargetPostId]))->send('delete')->getResult();\n+                } catch (\\Exception $e) {\n+                    if ($e->getMessage() != 'DELETE_POST_NOT_FOUND') {\n+                        $this->activityLog->setInfo('Delete old post on target site failed');\n+                        $this->activityLog->addMeta('ChangeTargetSiteFailed', \"Delete old post on target site failed\");\n+                        throw $e;\n+                    }\n+                    $this->activityLog->addMeta('Warning', \"Target post id #{$oldTargetPostId} not found\");\n+                }\n+\n+                $post->target_post_id = 0;\n+            }\n+\n+            if (($submitType == 'publish' || ($oldStatus == 1 && $submitType == 'draft'))\n+                && (!$this->currentUser->is(User::CONTRIBUTOR) && $post->site_id > 0)) {\n+\n+                $action = ($oldSiteId != $newSiteId) || $oldSiteId == 0\n+                || ($post->published_status == 0 && $post->target_post_id == 0) ? 'publish' : 'edit';\n+\n+                $apiUrl = Site::find($newSiteId)->api_url;\n+\n+                $returnData = (new CdsApiDriver($apiUrl, [\n+                    'content' => $postContent,\n+                    'title' => $postTitle,\n+                    'categories' => [$newCategory],\n+                    'post_id' => $post->target_post_id,\n+                    'post_excerpt' => $postDescription,\n+                    'post_status' => $submitType,\n+                    'feature_img' => $post->feature_img,\n+                    'author_name' => !empty($author = User::find($post->user_id)) ? $author->username : '',\n+                    'cback_url' => action('Webapp\\\\PostController@getEdit', $post->id),\n+                    'old_post_id' => $oldPostId,\n+                    'priority' => $post->priority,\n+                ]))->send($action)->getResult();\n+                if ($returnData->data->post_id == 0) {\n+                    $this->activityLog->setInfo('Post to target site failed for unknown reason');\n+                    $this->activityLog->addMeta('FailedPostToTargetSite','unknown reason');\n+                    throw new \\Exception();\n+                }\n+                $post->content = Post::replaceIDButtonLink($returnData->data->post_id, $postContent, $oldPostId);\n+                $post->target_post_id = $returnData->data->post_id;\n+                $post->published_status = ($submitType == 'publish' && $post->site_id > 0) ? 1 : 0;\n+            }\n+\n+            $post->site_id = $newSiteId;\n+            $post->category = $newCategory;\n+            $this->_flashMessage($request, $submitType == 'publish' ? '公開しました' : '下書きに保存しました', 'success');\n+            $this->activityLog->addMeta('SiteId', $post->site_id);\n+            $this->activityLog->addMeta('TargetPostId', $post->target_post_id);\n+            $this->activityLog->addMeta('Category', $post->category);\n+\n+        } catch(BreakException $e) {\n+            $this->_flashMessage($request, $submitType == 'publish' ? '公開しました' : '下書きに保存しました', 'success');\n+        } catch(TitleDuplicatedException $e) {\n+            $this->_flashMessage($request, $e->getMessage(), 'danger');\n+            $this->activityLog->addMeta('Error', 'Title duplicated: '.$post->title);\n+            $post->title = $oldTitle;\n+            $post->site_id = $oldSiteId;\n+        } catch(\\Exception $e) {\n+            $post->content = Post::replaceIDButtonLink('__POSTID__', $postContent, $oldPostId);\n+            if($e->getMessage() == 'POST_NOT_FOUND') {\n+                $post->target_post_id = 0;\n+                $post->published_status = 0;\n+            }\n+            $this->_flashMessage($request, '更新に失敗しました。もう一度ご確認ください。' . $e->getMessage(), 'warning');\n+            $this->activityLog->setInfo('Post to target site failed. Error: '.$e->getMessage());\n+            $this->activityLog->addMeta('FailedPostToTargetSite', $e->getMessage());\n+        }\n+\n+        $post->save();\n+        $post->saveHistory();\n+\n+        $this->activityLog->addMeta('NewPublishedStatus', $post->published_status);\n+        $this->activityLog->addMeta('NewSiteId', $post->site_id);\n+\n+        // Update Post meta and keywords\n+        // Main keyword\n+        PostMeta::deletePostMetaByPostId($post->id);\n+        $main = explode(',', $request->get('mainkw'));\n+\n+        $uniqueMainKeyword = trim($main[0]);\n+        $mainKeyword = Keywords::getKeyword($uniqueMainKeyword, 1);\n+\n+        if(empty($mainKeyword)) {//there is no keyword\n+            if(strlen($uniqueMainKeyword) > 0) {\n+                // Insert new main keyword\n+                $mainKeyword = new Keywords();\n+                $mainKeyword->keyword = $uniqueMainKeyword;\n+                $mainKeyword->type = 1;\n+                $mainKeyword->save();\n+            }\n+        }\n+\n+        $postMetaMkw = PostMeta::getPostMeta($post->id, isset($mainKeyword->id) ? $mainKeyword->id : 0);\n+        if(empty($postMetaMkw) && isset($mainKeyword->id)) {\n+            // Insert new post-keyword relationship if not exist\n+            $postMetaMkw = new PostMeta();\n+            $postMetaMkw->post_id = $post->id;\n+            $postMetaMkw->keyword_id = $mainKeyword->id;\n+            $postMetaMkw->save();\n+        }\n+\n+        // Sub keywords\n+        $subs = explode(',', $request->get('subkws'));\n+        foreach ($subs as $item) {\n+            $trimmedItem = trim($item);\n+            if(strlen($trimmedItem) == 0) {\n+                continue;\n+            }\n+\n+            $subKeyword = Keywords::getKeyword($trimmedItem, 2);\n+\n+            if(empty($subKeyword)) {\n+                // Insert new keyword\n+                $subKeyword = new Keywords();\n+                $subKeyword->keyword = $trimmedItem;\n+                $subKeyword->type = 2;\n+                $subKeyword->save();\n+\n+                // Save post-keyword relationship\n+            }\n+\n+            $postMetaSkw = PostMeta::getPostMeta($post->id, $subKeyword->id);\n+            if(empty($postMetaSkw)) {\n+                // Insert new post-keyword relationship if not exist\n+                $postMetaSkw = new PostMeta();\n+                $postMetaSkw->post_id = $post->id;\n+                $postMetaSkw->keyword_id = $subKeyword->id;\n+                $postMetaSkw->save();\n+            }\n+        }\n+\n+        return [\n+            'data' => [\n+                'id' => $post->id,\n+                'checksum' => $calculatedChecksum\n+            ],\n+            'next' => action('Webapp\\\\PostController@getEdit', $post->id)\n+        ];\n+    }\n+\n+    public function getPublish(Request $request, $postId = 0) {\n+        $this->activityLog->setPostId($postId);\n+\n+        if(empty($post = Post::find($postId))\n+            || $this->currentUser->is(User::CONTRIBUTOR)) {\n+            $this->activityLog->setInfo('Not found');\n+            return '404 Not Found';\n+        }\n+\n+        $this->activityLog->addMeta('PreviousPublishedStatus', $post->published_status);\n+\n+        if(!$post->canPublishBy($this->currentUser)) {\n+            $this->_flashMessage($request, 'Publish is not permitted', 'danger');\n+            $this->activityLog->setInfo('Not permitted');\n+            return redirect()->to(action('Webapp\\\\PostController@getIndex'))->send();\n+        }\n+\n+        if($post->isLock($this->currentSession)) {\n+            $this->_flashMessage($request, 'このコンテンツは現在ロックされています。変更できません。', 'danger');\n+            $this->activityLog->setInfo('Locked');\n+            if(!$request->get('selected_ids'))\n+                return redirect()->to(action('Webapp\\\\PostController@getIndex'))->send();\n+            else\n+                return;\n+        }\n+\n+        if($post->published_status == 1) {\n+            $this->_flashMessage($request, '更新しました。', 'warning');\n+            $this->activityLog->setInfo('Already published');\n+            if(!$request->get('selected_ids'))\n+                return redirect()->to(action('Webapp\\\\PostController@getIndex'))->send();\n+            else\n+                return;\n+        }\n+\n+        $data = array(\n+            'site_id' => $post->site_id,\n+            'title' => $post->title,\n+            'desc' => $post->description,\n+            'thumb' => $post->feature_img,\n+            'mainKey' => empty(PostMeta::getMainKeywordByPostId($postId)) ? '' : $postId\n+        );\n+\n+        $mess_error = Post::checkPostDataRequireField($data, true);\n+\n+        if($mess_error != ''){\n+            $this->_flashMessage($request, $mess_error, 'danger');\n+            $this->activityLog->setInfo('Missing required field');\n+            return redirect()->to(action('Webapp\\\\PostController@getEdit', $postId))->send();\n+        }\n+\n+        if($post->site_id == 0) {\n+            $this->_flashMessage($request, 'ターゲットサイトを選んでください', 'warning');\n+            $this->activityLog->setInfo('Missing target site');\n+            if(!$request->get('selected_ids'))\n+                return redirect()->to(action('Webapp\\\\PostController@getEdit', $postId))->send();\n+            else\n+                return;\n+        }\n+\n+        if (!Post::isUniquePostByTitle($post)) {\n+            $this->_flashMessage($request, 'このタイトルは存在しています。公開できないのでタイトルを変更してください。', 'danger');\n+            $this->activityLog->addMeta('Error', 'Title duplicated: '.$post->title);\n+            if(!$request->get('selected_ids'))\n+                return redirect()->to(action('Webapp\\\\PostController@getIndex'))->send();\n+            else\n+                return;\n+        }\n+\n+        try {\n+            $apiUrl = Site::find($post->site_id)->api_url;\n+            $action = ($post->target_post_id == 0) ? 'publish' : 'edit';\n+            $returnData = (new CdsApiDriver($apiUrl, [\n+                'content' => $post->content,\n+                'title' => $post->title,\n+                'categories' => [$post->category],\n+                'post_id' => $post->target_post_id,\n+                'post_excerpt' => $post->description,\n+                'post_status' => 'publish',\n+                'feature_img' => $post->feature_img,\n+                'author_name' => $post->author_name,\n+                'cback_url' => action('Webapp\\\\PostController@getEdit', $post->id),\n+                'priority' => $post->priority,\n+            ]))->send($action)->getResult();\n+            $post->content = Post::replaceIDButtonLink($returnData->data->post_id, $post->content, $post->target_post_id);\n+            $post->target_post_id = $returnData->data->post_id;\n+            $post->published_status = 1;\n+            $this->_flashMessage($request, 'OK', 'success');\n+\n+            $this->activityLog->addMeta('TargetPostId', $post->target_post_id);\n+        } catch(\\Exception $e) {\n+            $post->content = Post::replaceIDButtonLink('__POSTID__', $post->content, $post->target_post_id);\n+            $this->activityLog->setInfo('Error when reaching to target site');\n+            $this->activityLog->addMeta('FailedPostToTargetSite', 'error when reaching to target site');\n+            $this->_flashMessage($request, '更新に失敗しました。もう一度ご確認ください。', 'warning');\n+        }\n+\n+        $post->save();\n+\n+        $this->activityLog->addMeta('NewPublishedStatus', $post->published_status);\n+\n+        $next = action('Webapp\\\\PostController@getIndex');\n+\n+        if(($from = $request->get('from', null) != null) && $from == 'preview') {\n+            $next = $post->getTargetSiteUrl();\n+            $this->_clearFlashMessage($request);\n+        }\n+\n+        if($request->get('hasFilter', false) !== false) {\n+            return redirect()->back()->send();\n+        }\n+\n+        if(!$request->get('selected_ids'))\n+        return redirect()->to($next)->send();\n+    }\n+\n+    public function getDraft(Request $request, $postId = 0) {\n+        $this->activityLog->setPostId($postId);\n+\n+        if(empty($post = Post::find($postId))) {\n+            $this->activityLog->setInfo('Not found');\n+            return '404 Not Found';\n+        }\n+\n+        if(!$post->canDraftBy($this->currentUser)) {\n+            $this->_flashMessage($request, 'Draft is not permitted', 'danger');\n+            $this->activityLog->setInfo('Not permitted');\n+            return redirect()->to(action('Webapp\\\\PostController@getIndex'))->send();\n+        }\n+\n+        if($post->isLock($this->currentSession)) {\n+            $this->_flashMessage($request, 'このコンテンツは現在ロックされています。下書きに保存できません。', 'danger');\n+            $this->activityLog->setInfo('Locked');\n+            if(!$request->get('selected_ids'))","path":"app/Http/Controllers/Webapp/PostController.php","position":1293,"original_position":1293,"commit_id":"a922de5d24ac07cf163098e5d53d9f791e01a251","original_commit_id":"a922de5d24ac07cf163098e5d53d9f791e01a251","user":{"login":"dienncrelipa","id":39975181,"node_id":"MDQ6VXNlcjM5OTc1MTgx","avatar_url":"https://avatars3.githubusercontent.com/u/39975181?v=4","gravatar_id":"","url":"https://api.github.com/users/dienncrelipa","html_url":"https://github.com/dienncrelipa","followers_url":"https://api.github.com/users/dienncrelipa/followers","following_url":"https://api.github.com/users/dienncrelipa/following{/other_user}","gists_url":"https://api.github.com/users/dienncrelipa/gists{/gist_id}","starred_url":"https://api.github.com/users/dienncrelipa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dienncrelipa/subscriptions","organizations_url":"https://api.github.com/users/dienncrelipa/orgs","repos_url":"https://api.github.com/users/dienncrelipa/repos","events_url":"https://api.github.com/users/dienncrelipa/events{/privacy}","received_events_url":"https://api.github.com/users/dienncrelipa/received_events","type":"User","site_admin":false},"body":"![CRITICAL](https://sonarsource.github.io/sonar-github/severity-critical.png 'Severity: CRITICAL') Add curly braces around the nested statement(s). [![rule](https://sonarsource.github.io/sonar-github/rule.png)](http://sonar.relipa.blog/coding_rules#rule_key=php%3AS121)\n","created_at":"2018-10-02T03:09:06Z","updated_at":"2018-10-02T03:09:06Z","html_url":"https://github.com/dienncrelipa/test/pull/8#discussion_r221815168","pull_request_url":"https://api.github.com/repos/dienncrelipa/test/pulls/8","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/dienncrelipa/test/pulls/comments/221815168"},"html":{"href":"https://github.com/dienncrelipa/test/pull/8#discussion_r221815168"},"pull_request":{"href":"https://api.github.com/repos/dienncrelipa/test/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/dienncrelipa/test/pulls/8","id":219573211,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE5NTczMjEx","html_url":"https://github.com/dienncrelipa/test/pull/8","diff_url":"https://github.com/dienncrelipa/test/pull/8.diff","patch_url":"https://github.com/dienncrelipa/test/pull/8.patch","issue_url":"https://api.github.com/repos/dienncrelipa/test/issues/8","number":8,"state":"open","locked":false,"title":"Drone","user":{"login":"dienncrelipa","id":39975181,"node_id":"MDQ6VXNlcjM5OTc1MTgx","avatar_url":"https://avatars3.githubusercontent.com/u/39975181?v=4","gravatar_id":"","url":"https://api.github.com/users/dienncrelipa","html_url":"https://github.com/dienncrelipa","followers_url":"https://api.github.com/users/dienncrelipa/followers","following_url":"https://api.github.com/users/dienncrelipa/following{/other_user}","gists_url":"https://api.github.com/users/dienncrelipa/gists{/gist_id}","starred_url":"https://api.github.com/users/dienncrelipa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dienncrelipa/subscriptions","organizations_url":"https://api.github.com/users/dienncrelipa/orgs","repos_url":"https://api.github.com/users/dienncrelipa/repos","events_url":"https://api.github.com/users/dienncrelipa/events{/privacy}","received_events_url":"https://api.github.com/users/dienncrelipa/received_events","type":"User","site_admin":false},"body":"Checklist cho PR. Ghi X vào trong ngoặc []. PM xác nhận pass hết các điều kiện dưới đây thì nhấn approve\r\n\r\n### [Developer]\r\n  - [ ] Đã tự review lại source code của mình trước khi nhờ người khác review theo [Coding Checklist](http://bit.ly/2H8kodH)\r\n  - [ ] Đã self-test và điền kết quả vào checklist\r\n  - [ ] Đã đặt title PR theo định dạng `Task #{ISSUE_NUMBER} {ISSUE_CONTENTS}`\r\n  - [ ] TẤT CẢ các commit message tuân theo định dạng `Task #{ISSUE_NUMBER} {ISSUE_CONTENTS}`\r\n    - Trong đó :\r\n      - `#{ISSUE_NUMBER}` là Redmine ID.\r\n      - `#{ISSUE_CONTENTS}` là nội dung ngắn gọn mô tả task\r\n    - V/d:\r\n      - `Task #1234 #DEV Gọt đầu ông Tuyển`\r\n      - `Task #1234 #HOTFIX Gọt đầu ông Tuyển`\r\n      - `Task #1234 #RELEASE Gọt đầu ông Tuyển`\r\n  - [ ] Đã viết đầy đủ thông tin trong Redmine. Mục nào không có thì ghi \"Không\"\r\n  - [ ] Đã viết Release Note. Đảm bảo release khi có lỗi xảy ra có thể rollback ngay lập tức\r\n  - [ ] Đã rebase lại branch khi tạo PR vào master. Đảm bảo 1 PR chỉ có 1 commit\r\n  - [ ]  Đã chuyển Redmine issue sang trạng thái Resolved\r\n\r\n### [Reviewer]\r\n  - [ ] Đã kiểm tra redmine chưa:\r\n    - Đã kiểm tra Redmine các mục: `PHƯƠNG HƯỚNG SỬA, PHẠM VI ẢNH HƯỞNG, RELEASE NOTE, PR LINK, TRẠNG THÁI ISSUE...`\r\n  - [ ] Đã review source code và xác nhận `KHÔNG CÓ LỖI VỀ MẶT CÚ PHÁP`\r\n  - [ ] Đã review source code và xác nhận `KHÔNG SAI LỆCH CHỨC NĂNG`\r\n  - [ ] Đã review source code và xác nhận `KHÔNG GÂY SAI LỆCH TỚI CHỨC NĂNG KHÁC`\r\n\r\n### [Tester] Checklist\r\n  - [ ] Đã đọc và kiểm tra kết quả self-test của Developer\r\n  - [ ] Đã test lại và xác nhận KHÔNG GÂY ẢNH HƯỞNG TỚI CHỨC NĂNG KHÁC\r\n  - [ ] Đã chuyển Redmine issue sang trạng thái Test done\r\n\r\n### [PM]\r\n  - [ ] Xác nhận khách hàng đã đồng ý release\r\n","created_at":"2018-10-02T03:08:00Z","updated_at":"2018-10-02T03:09:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f6e6dec6dfd73e8a3c9a069c1cbb5d1799c1db19","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/dienncrelipa/test/pulls/8/commits","review_comments_url":"https://api.github.com/repos/dienncrelipa/test/pulls/8/comments","review_comment_url":"https://api.github.com/repos/dienncrelipa/test/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dienncrelipa/test/issues/8/comments","statuses_url":"https://api.github.com/repos/dienncrelipa/test/statuses/a922de5d24ac07cf163098e5d53d9f791e01a251","head":{"label":"dienncrelipa:drone","ref":"drone","sha":"a922de5d24ac07cf163098e5d53d9f791e01a251","user":{"login":"dienncrelipa","id":39975181,"node_id":"MDQ6VXNlcjM5OTc1MTgx","avatar_url":"https://avatars3.githubusercontent.com/u/39975181?v=4","gravatar_id":"","url":"https://api.github.com/users/dienncrelipa","html_url":"https://github.com/dienncrelipa","followers_url":"https://api.github.com/users/dienncrelipa/followers","following_url":"https://api.github.com/users/dienncrelipa/following{/other_user}","gists_url":"https://api.github.com/users/dienncrelipa/gists{/gist_id}","starred_url":"https://api.github.com/users/dienncrelipa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dienncrelipa/subscriptions","organizations_url":"https://api.github.com/users/dienncrelipa/orgs","repos_url":"https://api.github.com/users/dienncrelipa/repos","events_url":"https://api.github.com/users/dienncrelipa/events{/privacy}","received_events_url":"https://api.github.com/users/dienncrelipa/received_events","type":"User","site_admin":false},"repo":{"id":147624759,"node_id":"MDEwOlJlcG9zaXRvcnkxNDc2MjQ3NTk=","name":"test","full_name":"dienncrelipa/test","private":false,"owner":{"login":"dienncrelipa","id":39975181,"node_id":"MDQ6VXNlcjM5OTc1MTgx","avatar_url":"https://avatars3.githubusercontent.com/u/39975181?v=4","gravatar_id":"","url":"https://api.github.com/users/dienncrelipa","html_url":"https://github.com/dienncrelipa","followers_url":"https://api.github.com/users/dienncrelipa/followers","following_url":"https://api.github.com/users/dienncrelipa/following{/other_user}","gists_url":"https://api.github.com/users/dienncrelipa/gists{/gist_id}","starred_url":"https://api.github.com/users/dienncrelipa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dienncrelipa/subscriptions","organizations_url":"https://api.github.com/users/dienncrelipa/orgs","repos_url":"https://api.github.com/users/dienncrelipa/repos","events_url":"https://api.github.com/users/dienncrelipa/events{/privacy}","received_events_url":"https://api.github.com/users/dienncrelipa/received_events","type":"User","site_admin":false},"html_url":"https://github.com/dienncrelipa/test","description":null,"fork":false,"url":"https://api.github.com/repos/dienncrelipa/test","forks_url":"https://api.github.com/repos/dienncrelipa/test/forks","keys_url":"https://api.github.com/repos/dienncrelipa/test/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dienncrelipa/test/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dienncrelipa/test/teams","hooks_url":"https://api.github.com/repos/dienncrelipa/test/hooks","issue_events_url":"https://api.github.com/repos/dienncrelipa/test/issues/events{/number}","events_url":"https://api.github.com/repos/dienncrelipa/test/events","assignees_url":"https://api.github.com/repos/dienncrelipa/test/assignees{/user}","branches_url":"https://api.github.com/repos/dienncrelipa/test/branches{/branch}","tags_url":"https://api.github.com/repos/dienncrelipa/test/tags","blobs_url":"https://api.github.com/repos/dienncrelipa/test/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dienncrelipa/test/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dienncrelipa/test/git/refs{/sha}","trees_url":"https://api.github.com/repos/dienncrelipa/test/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dienncrelipa/test/statuses/{sha}","languages_url":"https://api.github.com/repos/dienncrelipa/test/languages","stargazers_url":"https://api.github.com/repos/dienncrelipa/test/stargazers","contributors_url":"https://api.github.com/repos/dienncrelipa/test/contributors","subscribers_url":"https://api.github.com/repos/dienncrelipa/test/subscribers","subscription_url":"https://api.github.com/repos/dienncrelipa/test/subscription","commits_url":"https://api.github.com/repos/dienncrelipa/test/commits{/sha}","git_commits_url":"https://api.github.com/repos/dienncrelipa/test/git/commits{/sha}","comments_url":"https://api.github.com/repos/dienncrelipa/test/comments{/number}","issue_comment_url":"https://api.github.com/repos/dienncrelipa/test/issues/comments{/number}","contents_url":"https://api.github.com/repos/dienncrelipa/test/contents/{+path}","compare_url":"https://api.github.com/repos/dienncrelipa/test/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dienncrelipa/test/merges","archive_url":"https://api.github.com/repos/dienncrelipa/test/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dienncrelipa/test/downloads","issues_url":"https://api.github.com/repos/dienncrelipa/test/issues{/number}","pulls_url":"https://api.github.com/repos/dienncrelipa/test/pulls{/number}","milestones_url":"https://api.github.com/repos/dienncrelipa/test/milestones{/number}","notifications_url":"https://api.github.com/repos/dienncrelipa/test/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dienncrelipa/test/labels{/name}","releases_url":"https://api.github.com/repos/dienncrelipa/test/releases{/id}","deployments_url":"https://api.github.com/repos/dienncrelipa/test/deployments","created_at":"2018-09-06T05:57:19Z","updated_at":"2018-09-06T06:57:50Z","pushed_at":"2018-10-02T03:08:00Z","git_url":"git://github.com/dienncrelipa/test.git","ssh_url":"git@github.com:dienncrelipa/test.git","clone_url":"https://github.com/dienncrelipa/test.git","svn_url":"https://github.com/dienncrelipa/test","homepage":null,"size":8804,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"license":null,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"dienncrelipa:master","ref":"master","sha":"b6b5494dd5c551386e7588297f44ae0a158b610d","user":{"login":"dienncrelipa","id":39975181,"node_id":"MDQ6VXNlcjM5OTc1MTgx","avatar_url":"https://avatars3.githubusercontent.com/u/39975181?v=4","gravatar_id":"","url":"https://api.github.com/users/dienncrelipa","html_url":"https://github.com/dienncrelipa","followers_url":"https://api.github.com/users/dienncrelipa/followers","following_url":"https://api.github.com/users/dienncrelipa/following{/other_user}","gists_url":"https://api.github.com/users/dienncrelipa/gists{/gist_id}","starred_url":"https://api.github.com/users/dienncrelipa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dienncrelipa/subscriptions","organizations_url":"https://api.github.com/users/dienncrelipa/orgs","repos_url":"https://api.github.com/users/dienncrelipa/repos","events_url":"https://api.github.com/users/dienncrelipa/events{/privacy}","received_events_url":"https://api.github.com/users/dienncrelipa/received_events","type":"User","site_admin":false},"repo":{"id":147624759,"node_id":"MDEwOlJlcG9zaXRvcnkxNDc2MjQ3NTk=","name":"test","full_name":"dienncrelipa/test","private":false,"owner":{"login":"dienncrelipa","id":39975181,"node_id":"MDQ6VXNlcjM5OTc1MTgx","avatar_url":"https://avatars3.githubusercontent.com/u/39975181?v=4","gravatar_id":"","url":"https://api.github.com/users/dienncrelipa","html_url":"https://github.com/dienncrelipa","followers_url":"https://api.github.com/users/dienncrelipa/followers","following_url":"https://api.github.com/users/dienncrelipa/following{/other_user}","gists_url":"https://api.github.com/users/dienncrelipa/gists{/gist_id}","starred_url":"https://api.github.com/users/dienncrelipa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dienncrelipa/subscriptions","organizations_url":"https://api.github.com/users/dienncrelipa/orgs","repos_url":"https://api.github.com/users/dienncrelipa/repos","events_url":"https://api.github.com/users/dienncrelipa/events{/privacy}","received_events_url":"https://api.github.com/users/dienncrelipa/received_events","type":"User","site_admin":false},"html_url":"https://github.com/dienncrelipa/test","description":null,"fork":false,"url":"https://api.github.com/repos/dienncrelipa/test","forks_url":"https://api.github.com/repos/dienncrelipa/test/forks","keys_url":"https://api.github.com/repos/dienncrelipa/test/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dienncrelipa/test/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dienncrelipa/test/teams","hooks_url":"https://api.github.com/repos/dienncrelipa/test/hooks","issue_events_url":"https://api.github.com/repos/dienncrelipa/test/issues/events{/number}","events_url":"https://api.github.com/repos/dienncrelipa/test/events","assignees_url":"https://api.github.com/repos/dienncrelipa/test/assignees{/user}","branches_url":"https://api.github.com/repos/dienncrelipa/test/branches{/branch}","tags_url":"https://api.github.com/repos/dienncrelipa/test/tags","blobs_url":"https://api.github.com/repos/dienncrelipa/test/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dienncrelipa/test/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dienncrelipa/test/git/refs{/sha}","trees_url":"https://api.github.com/repos/dienncrelipa/test/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dienncrelipa/test/statuses/{sha}","languages_url":"https://api.github.com/repos/dienncrelipa/test/languages","stargazers_url":"https://api.github.com/repos/dienncrelipa/test/stargazers","contributors_url":"https://api.github.com/repos/dienncrelipa/test/contributors","subscribers_url":"https://api.github.com/repos/dienncrelipa/test/subscribers","subscription_url":"https://api.github.com/repos/dienncrelipa/test/subscription","commits_url":"https://api.github.com/repos/dienncrelipa/test/commits{/sha}","git_commits_url":"https://api.github.com/repos/dienncrelipa/test/git/commits{/sha}","comments_url":"https://api.github.com/repos/dienncrelipa/test/comments{/number}","issue_comment_url":"https://api.github.com/repos/dienncrelipa/test/issues/comments{/number}","contents_url":"https://api.github.com/repos/dienncrelipa/test/contents/{+path}","compare_url":"https://api.github.com/repos/dienncrelipa/test/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dienncrelipa/test/merges","archive_url":"https://api.github.com/repos/dienncrelipa/test/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dienncrelipa/test/downloads","issues_url":"https://api.github.com/repos/dienncrelipa/test/issues{/number}","pulls_url":"https://api.github.com/repos/dienncrelipa/test/pulls{/number}","milestones_url":"https://api.github.com/repos/dienncrelipa/test/milestones{/number}","notifications_url":"https://api.github.com/repos/dienncrelipa/test/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dienncrelipa/test/labels{/name}","releases_url":"https://api.github.com/repos/dienncrelipa/test/releases{/id}","deployments_url":"https://api.github.com/repos/dienncrelipa/test/deployments","created_at":"2018-09-06T05:57:19Z","updated_at":"2018-09-06T06:57:50Z","pushed_at":"2018-10-02T03:08:00Z","git_url":"git://github.com/dienncrelipa/test.git","ssh_url":"git@github.com:dienncrelipa/test.git","clone_url":"https://github.com/dienncrelipa/test.git","svn_url":"https://github.com/dienncrelipa/test","homepage":null,"size":8804,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"license":null,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dienncrelipa/test/pulls/8"},"html":{"href":"https://github.com/dienncrelipa/test/pull/8"},"issue":{"href":"https://api.github.com/repos/dienncrelipa/test/issues/8"},"comments":{"href":"https://api.github.com/repos/dienncrelipa/test/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/dienncrelipa/test/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/dienncrelipa/test/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dienncrelipa/test/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/dienncrelipa/test/statuses/a922de5d24ac07cf163098e5d53d9f791e01a251"}},"author_association":"OWNER"}}
{"actor":{"display_login":"dienncrelipa"}}