{"action":"created","comment":{"url":"https://api.github.com/repos/bolt/bolt/pulls/comments/52361724","id":52361724,"diff_hunk":"@@ -0,0 +1,201 @@\n+<?php\n+\n+namespace Bolt\\Helpers;\n+\n+class Excerpt\n+{\n+\n+    protected $body = null;\n+    protected $title = null;\n+\n+    public function __construct($body, $title = null)\n+    {\n+        $this->body = $body;\n+        $this->title = $title;\n+    }\n+\n+    /**\n+     * Get the excerpt of a given piece of text.\n+     *\n+     * @param int  $length\n+     * @param bool $includetitle\n+     * @param null $focus\n+     *\n+     * @return mixed|null|string\n+     */\n+    public function getExcerpt($length = 200, $includetitle = false, $focus = null)\n+    {\n+        if ($includetitle && !empty($this->title)) {\n+            $title = Html::trimText(strip_tags($this->title), $length);\n+            $length = $length - strlen($title);\n+        } else {\n+            $title = '';\n+        }\n+\n+        if (is_array($this->body)) {\n+            // Assume it's an array, strip some common fields that we don't need, implode the rest.\n+            $stripKeys = [\n+                'id',\n+                'slug',\n+                'datecreated',\n+                'datechanged',\n+                'username',\n+                'ownerid',\n+                'title',\n+                'contenttype',\n+                'status',\n+                'taxonomy',\n+            ];\n+\n+            foreach ($stripKeys as $key) {\n+                unset($this->body[$key]);\n+            }\n+            $excerpt = implode(' ', $this->body);\n+        } elseif (is_string($this->body)) {\n+            // otherwise we just use the string.\n+            $excerpt = $this->body;\n+        } else {\n+            // Nope, got nothing.\n+            $excerpt = '';\n+        }\n+\n+        $excerpt = str_replace('>', '> ', $excerpt);\n+\n+        if (empty($focus)) {\n+            $excerpt = Html::trimText(strip_tags($excerpt), $length);\n+        } else {\n+            $excerpt = $this->extractRelevant($focus, strip_tags($excerpt), $length);\n+        }\n+\n+        if (!empty($title)) {\n+            $excerpt = '<b>' . $title . '</b> ' . $excerpt;\n+        }\n+\n+        return $excerpt;\n+    }\n+\n+\n+    /**\n+     * Find the locations of each of the words.\n+     * Nothing exciting here. The array_unique is required, unless you decide\n+     * to make the words unique before passing in.\n+     *\n+     * @param $words\n+     * @param $fulltext\n+     * @return array\n+     */\n+    function _extractLocations($words, $fulltext)\n+    {\n+        $locations = array();\n+        foreach($words as $word) {\n+            $wordlen = strlen($word);\n+            $loc = stripos($fulltext, $word);\n+            while($loc !== FALSE) {\n+                $locations[] = $loc;\n+                $loc = stripos($fulltext, $word, $loc + $wordlen);\n+            }\n+        }\n+        $locations = array_unique($locations);\n+        sort($locations);\n+\n+        return $locations;\n+    }\n+\n+    /**\n+     * Work out which is the most relevant portion to display\n+     * This is done by looping over each match and finding the smallest distance between two found\n+     * strings. The idea being that the closer the terms are the better match the snippet would be.\n+     * When checking for matches we only change the location if there is a better match.\n+     * The only exception is where we have only two matches in which case we just take the\n+     * first as will be equally distant.\n+     *\n+     * @param $locations\n+     * @param $prevcount\n+     * @return int\n+     */\n+    function _determineSnipLocation($locations, $prevcount)\n+    {\n+        // If we only have 1 match we don't actually do the for loop so set to the first\n+        $startpos = $locations[0];\n+        $loccount = count($locations);\n+        $smallestdiff = PHP_INT_MAX;\n+\n+        // If we only have 2, skip as it's probably equally relevant\n+        if(count($locations) > 2) {\n+            // skip the first as we check 1 behind\n+            for($i=1; $i < $loccount; $i++) {\n+                if($i == $loccount-1) { // at the end","path":"src/Helpers/Excerpt.php","position":127,"original_position":127,"commit_id":"6a4cbd3d7fae0767191e6f08e73b283da06be740","original_commit_id":"6a4cbd3d7fae0767191e6f08e73b283da06be740","user":{"login":"Nitpick-CI","id":12626182,"avatar_url":"https://avatars.githubusercontent.com/u/12626182?v=3","gravatar_id":"","url":"https://api.github.com/users/Nitpick-CI","html_url":"https://github.com/Nitpick-CI","followers_url":"https://api.github.com/users/Nitpick-CI/followers","following_url":"https://api.github.com/users/Nitpick-CI/following{/other_user}","gists_url":"https://api.github.com/users/Nitpick-CI/gists{/gist_id}","starred_url":"https://api.github.com/users/Nitpick-CI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nitpick-CI/subscriptions","organizations_url":"https://api.github.com/users/Nitpick-CI/orgs","repos_url":"https://api.github.com/users/Nitpick-CI/repos","events_url":"https://api.github.com/users/Nitpick-CI/events{/privacy}","received_events_url":"https://api.github.com/users/Nitpick-CI/received_events","type":"User","site_admin":false},"body":"Expected 1 space after IF keyword; 0 found","created_at":"2016-02-09T19:38:23Z","updated_at":"2016-02-09T19:38:23Z","html_url":"https://github.com/bolt/bolt/pull/4825#discussion_r52361724","pull_request_url":"https://api.github.com/repos/bolt/bolt/pulls/4825","_links":{"self":{"href":"https://api.github.com/repos/bolt/bolt/pulls/comments/52361724"},"html":{"href":"https://github.com/bolt/bolt/pull/4825#discussion_r52361724"},"pull_request":{"href":"https://api.github.com/repos/bolt/bolt/pulls/4825"}}},"pull_request":{"url":"https://api.github.com/repos/bolt/bolt/pulls/4825","id":58797493,"html_url":"https://github.com/bolt/bolt/pull/4825","diff_url":"https://github.com/bolt/bolt/pull/4825.diff","patch_url":"https://github.com/bolt/bolt/pull/4825.patch","issue_url":"https://api.github.com/repos/bolt/bolt/issues/4825","number":4825,"state":"open","locked":false,"title":"Making better excerpts.","user":{"login":"bobdenotter","id":1833361,"avatar_url":"https://avatars.githubusercontent.com/u/1833361?v=3","gravatar_id":"","url":"https://api.github.com/users/bobdenotter","html_url":"https://github.com/bobdenotter","followers_url":"https://api.github.com/users/bobdenotter/followers","following_url":"https://api.github.com/users/bobdenotter/following{/other_user}","gists_url":"https://api.github.com/users/bobdenotter/gists{/gist_id}","starred_url":"https://api.github.com/users/bobdenotter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bobdenotter/subscriptions","organizations_url":"https://api.github.com/users/bobdenotter/orgs","repos_url":"https://api.github.com/users/bobdenotter/repos","events_url":"https://api.github.com/users/bobdenotter/events{/privacy}","received_events_url":"https://api.github.com/users/bobdenotter/received_events","type":"User","site_admin":false},"body":"This PR makes better excerpts of entries / arrays / strings: \n\n - Less duplicated code\n - Centers content around a search term, so the excerpt is more relevant\n - Highlights search terms\n","created_at":"2016-02-09T19:38:11Z","updated_at":"2016-02-09T19:38:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"159cb9e22fb1fb5526fc854d8c9516dad2acfe64","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bolt/bolt/pulls/4825/commits","review_comments_url":"https://api.github.com/repos/bolt/bolt/pulls/4825/comments","review_comment_url":"https://api.github.com/repos/bolt/bolt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bolt/bolt/issues/4825/comments","statuses_url":"https://api.github.com/repos/bolt/bolt/statuses/6a4cbd3d7fae0767191e6f08e73b283da06be740","head":{"label":"bolt:fix/better-excerpts","ref":"fix/better-excerpts","sha":"6a4cbd3d7fae0767191e6f08e73b283da06be740","user":{"login":"bolt","id":3869752,"avatar_url":"https://avatars.githubusercontent.com/u/3869752?v=3","gravatar_id":"","url":"https://api.github.com/users/bolt","html_url":"https://github.com/bolt","followers_url":"https://api.github.com/users/bolt/followers","following_url":"https://api.github.com/users/bolt/following{/other_user}","gists_url":"https://api.github.com/users/bolt/gists{/gist_id}","starred_url":"https://api.github.com/users/bolt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolt/subscriptions","organizations_url":"https://api.github.com/users/bolt/orgs","repos_url":"https://api.github.com/users/bolt/repos","events_url":"https://api.github.com/users/bolt/events{/privacy}","received_events_url":"https://api.github.com/users/bolt/received_events","type":"Organization","site_admin":false},"repo":{"id":4665416,"name":"bolt","full_name":"bolt/bolt","owner":{"login":"bolt","id":3869752,"avatar_url":"https://avatars.githubusercontent.com/u/3869752?v=3","gravatar_id":"","url":"https://api.github.com/users/bolt","html_url":"https://github.com/bolt","followers_url":"https://api.github.com/users/bolt/followers","following_url":"https://api.github.com/users/bolt/following{/other_user}","gists_url":"https://api.github.com/users/bolt/gists{/gist_id}","starred_url":"https://api.github.com/users/bolt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolt/subscriptions","organizations_url":"https://api.github.com/users/bolt/orgs","repos_url":"https://api.github.com/users/bolt/repos","events_url":"https://api.github.com/users/bolt/events{/privacy}","received_events_url":"https://api.github.com/users/bolt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bolt/bolt","description":"Bolt is a simple CMS written in PHP. It is based on Silex and Symfony components, uses Twig and either SQLite, MySQL or PostgreSQL.","fork":false,"url":"https://api.github.com/repos/bolt/bolt","forks_url":"https://api.github.com/repos/bolt/bolt/forks","keys_url":"https://api.github.com/repos/bolt/bolt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bolt/bolt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bolt/bolt/teams","hooks_url":"https://api.github.com/repos/bolt/bolt/hooks","issue_events_url":"https://api.github.com/repos/bolt/bolt/issues/events{/number}","events_url":"https://api.github.com/repos/bolt/bolt/events","assignees_url":"https://api.github.com/repos/bolt/bolt/assignees{/user}","branches_url":"https://api.github.com/repos/bolt/bolt/branches{/branch}","tags_url":"https://api.github.com/repos/bolt/bolt/tags","blobs_url":"https://api.github.com/repos/bolt/bolt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bolt/bolt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bolt/bolt/git/refs{/sha}","trees_url":"https://api.github.com/repos/bolt/bolt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bolt/bolt/statuses/{sha}","languages_url":"https://api.github.com/repos/bolt/bolt/languages","stargazers_url":"https://api.github.com/repos/bolt/bolt/stargazers","contributors_url":"https://api.github.com/repos/bolt/bolt/contributors","subscribers_url":"https://api.github.com/repos/bolt/bolt/subscribers","subscription_url":"https://api.github.com/repos/bolt/bolt/subscription","commits_url":"https://api.github.com/repos/bolt/bolt/commits{/sha}","git_commits_url":"https://api.github.com/repos/bolt/bolt/git/commits{/sha}","comments_url":"https://api.github.com/repos/bolt/bolt/comments{/number}","issue_comment_url":"https://api.github.com/repos/bolt/bolt/issues/comments{/number}","contents_url":"https://api.github.com/repos/bolt/bolt/contents/{+path}","compare_url":"https://api.github.com/repos/bolt/bolt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bolt/bolt/merges","archive_url":"https://api.github.com/repos/bolt/bolt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bolt/bolt/downloads","issues_url":"https://api.github.com/repos/bolt/bolt/issues{/number}","pulls_url":"https://api.github.com/repos/bolt/bolt/pulls{/number}","milestones_url":"https://api.github.com/repos/bolt/bolt/milestones{/number}","notifications_url":"https://api.github.com/repos/bolt/bolt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bolt/bolt/labels{/name}","releases_url":"https://api.github.com/repos/bolt/bolt/releases{/id}","deployments_url":"https://api.github.com/repos/bolt/bolt/deployments","created_at":"2012-06-14T16:07:54Z","updated_at":"2016-02-09T13:23:50Z","pushed_at":"2016-02-09T19:38:12Z","git_url":"git://github.com/bolt/bolt.git","ssh_url":"git@github.com:bolt/bolt.git","clone_url":"https://github.com/bolt/bolt.git","svn_url":"https://github.com/bolt/bolt","homepage":"","size":59562,"stargazers_count":2580,"watchers_count":2580,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":592,"mirror_url":null,"open_issues_count":131,"forks":592,"open_issues":131,"watchers":2580,"default_branch":"release/2.2"}},"base":{"label":"bolt:master","ref":"master","sha":"01a19f5337f2b877d24a9c09ea7666638d71d472","user":{"login":"bolt","id":3869752,"avatar_url":"https://avatars.githubusercontent.com/u/3869752?v=3","gravatar_id":"","url":"https://api.github.com/users/bolt","html_url":"https://github.com/bolt","followers_url":"https://api.github.com/users/bolt/followers","following_url":"https://api.github.com/users/bolt/following{/other_user}","gists_url":"https://api.github.com/users/bolt/gists{/gist_id}","starred_url":"https://api.github.com/users/bolt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolt/subscriptions","organizations_url":"https://api.github.com/users/bolt/orgs","repos_url":"https://api.github.com/users/bolt/repos","events_url":"https://api.github.com/users/bolt/events{/privacy}","received_events_url":"https://api.github.com/users/bolt/received_events","type":"Organization","site_admin":false},"repo":{"id":4665416,"name":"bolt","full_name":"bolt/bolt","owner":{"login":"bolt","id":3869752,"avatar_url":"https://avatars.githubusercontent.com/u/3869752?v=3","gravatar_id":"","url":"https://api.github.com/users/bolt","html_url":"https://github.com/bolt","followers_url":"https://api.github.com/users/bolt/followers","following_url":"https://api.github.com/users/bolt/following{/other_user}","gists_url":"https://api.github.com/users/bolt/gists{/gist_id}","starred_url":"https://api.github.com/users/bolt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bolt/subscriptions","organizations_url":"https://api.github.com/users/bolt/orgs","repos_url":"https://api.github.com/users/bolt/repos","events_url":"https://api.github.com/users/bolt/events{/privacy}","received_events_url":"https://api.github.com/users/bolt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bolt/bolt","description":"Bolt is a simple CMS written in PHP. It is based on Silex and Symfony components, uses Twig and either SQLite, MySQL or PostgreSQL.","fork":false,"url":"https://api.github.com/repos/bolt/bolt","forks_url":"https://api.github.com/repos/bolt/bolt/forks","keys_url":"https://api.github.com/repos/bolt/bolt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bolt/bolt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bolt/bolt/teams","hooks_url":"https://api.github.com/repos/bolt/bolt/hooks","issue_events_url":"https://api.github.com/repos/bolt/bolt/issues/events{/number}","events_url":"https://api.github.com/repos/bolt/bolt/events","assignees_url":"https://api.github.com/repos/bolt/bolt/assignees{/user}","branches_url":"https://api.github.com/repos/bolt/bolt/branches{/branch}","tags_url":"https://api.github.com/repos/bolt/bolt/tags","blobs_url":"https://api.github.com/repos/bolt/bolt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bolt/bolt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bolt/bolt/git/refs{/sha}","trees_url":"https://api.github.com/repos/bolt/bolt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bolt/bolt/statuses/{sha}","languages_url":"https://api.github.com/repos/bolt/bolt/languages","stargazers_url":"https://api.github.com/repos/bolt/bolt/stargazers","contributors_url":"https://api.github.com/repos/bolt/bolt/contributors","subscribers_url":"https://api.github.com/repos/bolt/bolt/subscribers","subscription_url":"https://api.github.com/repos/bolt/bolt/subscription","commits_url":"https://api.github.com/repos/bolt/bolt/commits{/sha}","git_commits_url":"https://api.github.com/repos/bolt/bolt/git/commits{/sha}","comments_url":"https://api.github.com/repos/bolt/bolt/comments{/number}","issue_comment_url":"https://api.github.com/repos/bolt/bolt/issues/comments{/number}","contents_url":"https://api.github.com/repos/bolt/bolt/contents/{+path}","compare_url":"https://api.github.com/repos/bolt/bolt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bolt/bolt/merges","archive_url":"https://api.github.com/repos/bolt/bolt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bolt/bolt/downloads","issues_url":"https://api.github.com/repos/bolt/bolt/issues{/number}","pulls_url":"https://api.github.com/repos/bolt/bolt/pulls{/number}","milestones_url":"https://api.github.com/repos/bolt/bolt/milestones{/number}","notifications_url":"https://api.github.com/repos/bolt/bolt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bolt/bolt/labels{/name}","releases_url":"https://api.github.com/repos/bolt/bolt/releases{/id}","deployments_url":"https://api.github.com/repos/bolt/bolt/deployments","created_at":"2012-06-14T16:07:54Z","updated_at":"2016-02-09T13:23:50Z","pushed_at":"2016-02-09T19:38:12Z","git_url":"git://github.com/bolt/bolt.git","ssh_url":"git@github.com:bolt/bolt.git","clone_url":"https://github.com/bolt/bolt.git","svn_url":"https://github.com/bolt/bolt","homepage":"","size":59562,"stargazers_count":2580,"watchers_count":2580,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":592,"mirror_url":null,"open_issues_count":131,"forks":592,"open_issues":131,"watchers":2580,"default_branch":"release/2.2"}},"_links":{"self":{"href":"https://api.github.com/repos/bolt/bolt/pulls/4825"},"html":{"href":"https://github.com/bolt/bolt/pull/4825"},"issue":{"href":"https://api.github.com/repos/bolt/bolt/issues/4825"},"comments":{"href":"https://api.github.com/repos/bolt/bolt/issues/4825/comments"},"review_comments":{"href":"https://api.github.com/repos/bolt/bolt/pulls/4825/comments"},"review_comment":{"href":"https://api.github.com/repos/bolt/bolt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bolt/bolt/pulls/4825/commits"},"statuses":{"href":"https://api.github.com/repos/bolt/bolt/statuses/6a4cbd3d7fae0767191e6f08e73b283da06be740"}}}}