@@ -16,138 +16,138 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class CwpSearchEngine |
| 18 | 18 | { |
| 19 | - use Configurable; |
|
| 20 | - use Extensible; |
|
| 21 | - use Injectable; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Default search options |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - * @config |
|
| 28 | - */ |
|
| 29 | - private static $search_options = [ |
|
| 30 | - 'hl' => 'true', |
|
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Additional search options to send to search when spellcheck |
|
| 35 | - * is included |
|
| 36 | - * |
|
| 37 | - * @var array |
|
| 38 | - * @config |
|
| 39 | - */ |
|
| 40 | - private static $spellcheck_options = [ |
|
| 41 | - 'spellcheck' => 'true', |
|
| 42 | - 'spellcheck.collate' => 'true', |
|
| 43 | - // spellcheck.dictionary can also be configured to use '_spellcheck' |
|
| 44 | - // dictionary when indexing fields under the _spellcheckText column |
|
| 45 | - 'spellcheck.dictionary' => 'default', |
|
| 46 | - ]; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Build a SearchQuery for a new search |
|
| 50 | - * |
|
| 51 | - * @param string $keywords |
|
| 52 | - * @param array $classes |
|
| 53 | - * @return SearchQuery |
|
| 54 | - */ |
|
| 55 | - protected function getSearchQuery($keywords, $classes) |
|
| 56 | - { |
|
| 57 | - $query = new SearchQuery(); |
|
| 58 | - $query->classes = $classes; |
|
| 59 | - $query->search($keywords); |
|
| 60 | - $query->exclude('SiteTree_ShowInSearch', 0); |
|
| 61 | - $query->exclude('File_ShowInSearch', 0); |
|
| 62 | - |
|
| 63 | - // Artificially lower the amount of results to prevent too high resource usage. |
|
| 64 | - // on subsequent canView check loop. |
|
| 65 | - $query->limit(100); |
|
| 66 | - return $query; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get solr search options for this query |
|
| 71 | - * |
|
| 72 | - * @param bool $spellcheck True if we should include spellcheck support |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - protected function getSearchOptions($spellcheck) |
|
| 76 | - { |
|
| 77 | - $options = $this->config()->search_options; |
|
| 78 | - if ($spellcheck) { |
|
| 79 | - $options = array_merge($options, $this->config()->spellcheck_options); |
|
| 80 | - } |
|
| 81 | - return $options; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Get results for a search term |
|
| 86 | - * |
|
| 87 | - * @param string $keywords |
|
| 88 | - * @param array $classes |
|
| 89 | - * @param SolrIndex $searchIndex |
|
| 90 | - * @param int $limit Max number of results for this page |
|
| 91 | - * @param int $start Skip this number of records |
|
| 92 | - * @param bool $spellcheck True to enable spellcheck |
|
| 93 | - * @return CwpSearchResult |
|
| 94 | - */ |
|
| 95 | - protected function getResult($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $spellcheck = false) |
|
| 96 | - { |
|
| 97 | - // Prepare options |
|
| 98 | - $query = $this->getSearchQuery($keywords, $classes); |
|
| 99 | - $options = $this->getSearchOptions($spellcheck); |
|
| 100 | - |
|
| 101 | - // Get results |
|
| 102 | - $solrResult = $searchIndex->search( |
|
| 103 | - $query, |
|
| 104 | - $start, |
|
| 105 | - $limit, |
|
| 106 | - $options |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - return CwpSearchResult::create($keywords, $solrResult); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Get a CwpSearchResult for a given criterea |
|
| 114 | - * |
|
| 115 | - * @param string $keywords |
|
| 116 | - * @param array $classes |
|
| 117 | - * @param SolrIndex $searchIndex |
|
| 118 | - * @param int $limit Max number of results for this page |
|
| 119 | - * @param int $start Skip this number of records |
|
| 120 | - * @param bool $followSuggestions True to enable suggested searches to be returned immediately |
|
| 121 | - * @return CwpSearchResult|null |
|
| 122 | - */ |
|
| 123 | - public function search($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $followSuggestions = false) |
|
| 124 | - { |
|
| 125 | - if (empty($keywords)) { |
|
| 126 | - return null; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - try { |
|
| 130 | - // Begin search |
|
| 131 | - $result = $this->getResult($keywords, $classes, $searchIndex, $limit, $start, true); |
|
| 132 | - |
|
| 133 | - // Return results if we don't need to refine this any further |
|
| 134 | - if (!$followSuggestions || $result->hasResults() || !$result->getSuggestion()) { |
|
| 135 | - return $result; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // Perform new search with the suggested terms |
|
| 139 | - $suggested = $result->getSuggestion(); |
|
| 140 | - $newResult = $this->getResult($suggested, $classes, $searchIndex, $limit, $start, false); |
|
| 141 | - $newResult->setOriginal($keywords); |
|
| 142 | - |
|
| 143 | - // Compare new results to the original query |
|
| 144 | - if ($newResult->hasResults()) { |
|
| 145 | - return $newResult; |
|
| 146 | - } else { |
|
| 147 | - return $result; |
|
| 148 | - } |
|
| 149 | - } catch (Exception $e) { |
|
| 150 | - Injector::inst()->get(LoggerInterface::class)->warning($e); |
|
| 151 | - } |
|
| 152 | - } |
|
| 19 | + use Configurable; |
|
| 20 | + use Extensible; |
|
| 21 | + use Injectable; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Default search options |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + * @config |
|
| 28 | + */ |
|
| 29 | + private static $search_options = [ |
|
| 30 | + 'hl' => 'true', |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Additional search options to send to search when spellcheck |
|
| 35 | + * is included |
|
| 36 | + * |
|
| 37 | + * @var array |
|
| 38 | + * @config |
|
| 39 | + */ |
|
| 40 | + private static $spellcheck_options = [ |
|
| 41 | + 'spellcheck' => 'true', |
|
| 42 | + 'spellcheck.collate' => 'true', |
|
| 43 | + // spellcheck.dictionary can also be configured to use '_spellcheck' |
|
| 44 | + // dictionary when indexing fields under the _spellcheckText column |
|
| 45 | + 'spellcheck.dictionary' => 'default', |
|
| 46 | + ]; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Build a SearchQuery for a new search |
|
| 50 | + * |
|
| 51 | + * @param string $keywords |
|
| 52 | + * @param array $classes |
|
| 53 | + * @return SearchQuery |
|
| 54 | + */ |
|
| 55 | + protected function getSearchQuery($keywords, $classes) |
|
| 56 | + { |
|
| 57 | + $query = new SearchQuery(); |
|
| 58 | + $query->classes = $classes; |
|
| 59 | + $query->search($keywords); |
|
| 60 | + $query->exclude('SiteTree_ShowInSearch', 0); |
|
| 61 | + $query->exclude('File_ShowInSearch', 0); |
|
| 62 | + |
|
| 63 | + // Artificially lower the amount of results to prevent too high resource usage. |
|
| 64 | + // on subsequent canView check loop. |
|
| 65 | + $query->limit(100); |
|
| 66 | + return $query; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get solr search options for this query |
|
| 71 | + * |
|
| 72 | + * @param bool $spellcheck True if we should include spellcheck support |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + protected function getSearchOptions($spellcheck) |
|
| 76 | + { |
|
| 77 | + $options = $this->config()->search_options; |
|
| 78 | + if ($spellcheck) { |
|
| 79 | + $options = array_merge($options, $this->config()->spellcheck_options); |
|
| 80 | + } |
|
| 81 | + return $options; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Get results for a search term |
|
| 86 | + * |
|
| 87 | + * @param string $keywords |
|
| 88 | + * @param array $classes |
|
| 89 | + * @param SolrIndex $searchIndex |
|
| 90 | + * @param int $limit Max number of results for this page |
|
| 91 | + * @param int $start Skip this number of records |
|
| 92 | + * @param bool $spellcheck True to enable spellcheck |
|
| 93 | + * @return CwpSearchResult |
|
| 94 | + */ |
|
| 95 | + protected function getResult($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $spellcheck = false) |
|
| 96 | + { |
|
| 97 | + // Prepare options |
|
| 98 | + $query = $this->getSearchQuery($keywords, $classes); |
|
| 99 | + $options = $this->getSearchOptions($spellcheck); |
|
| 100 | + |
|
| 101 | + // Get results |
|
| 102 | + $solrResult = $searchIndex->search( |
|
| 103 | + $query, |
|
| 104 | + $start, |
|
| 105 | + $limit, |
|
| 106 | + $options |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + return CwpSearchResult::create($keywords, $solrResult); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Get a CwpSearchResult for a given criterea |
|
| 114 | + * |
|
| 115 | + * @param string $keywords |
|
| 116 | + * @param array $classes |
|
| 117 | + * @param SolrIndex $searchIndex |
|
| 118 | + * @param int $limit Max number of results for this page |
|
| 119 | + * @param int $start Skip this number of records |
|
| 120 | + * @param bool $followSuggestions True to enable suggested searches to be returned immediately |
|
| 121 | + * @return CwpSearchResult|null |
|
| 122 | + */ |
|
| 123 | + public function search($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $followSuggestions = false) |
|
| 124 | + { |
|
| 125 | + if (empty($keywords)) { |
|
| 126 | + return null; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + try { |
|
| 130 | + // Begin search |
|
| 131 | + $result = $this->getResult($keywords, $classes, $searchIndex, $limit, $start, true); |
|
| 132 | + |
|
| 133 | + // Return results if we don't need to refine this any further |
|
| 134 | + if (!$followSuggestions || $result->hasResults() || !$result->getSuggestion()) { |
|
| 135 | + return $result; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // Perform new search with the suggested terms |
|
| 139 | + $suggested = $result->getSuggestion(); |
|
| 140 | + $newResult = $this->getResult($suggested, $classes, $searchIndex, $limit, $start, false); |
|
| 141 | + $newResult->setOriginal($keywords); |
|
| 142 | + |
|
| 143 | + // Compare new results to the original query |
|
| 144 | + if ($newResult->hasResults()) { |
|
| 145 | + return $newResult; |
|
| 146 | + } else { |
|
| 147 | + return $result; |
|
| 148 | + } |
|
| 149 | + } catch (Exception $e) { |
|
| 150 | + Injector::inst()->get(LoggerInterface::class)->warning($e); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -11,204 +11,204 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class CwpSearchResult extends ViewableData |
| 13 | 13 | { |
| 14 | - private static $casting = [ |
|
| 15 | - 'Original' => 'Text', |
|
| 16 | - 'OriginalLink' => 'Text', |
|
| 17 | - 'Suggestion' => 'Text', |
|
| 18 | - 'SuggestionLink' => 'Text', |
|
| 19 | - 'Query' => 'Text', |
|
| 20 | - 'SearchLink' => 'Text', |
|
| 21 | - 'RSSLink' => 'Text', |
|
| 22 | - 'AtomLink' => 'Text', |
|
| 23 | - ]; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * List of results |
|
| 27 | - * |
|
| 28 | - * @var PaginatedList |
|
| 29 | - */ |
|
| 30 | - protected $matches; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Search terms for these results |
|
| 34 | - * |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - protected $query; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Suggested search keywords |
|
| 41 | - * Used when this search has suggested terms, but following suggestions isn't enabled |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $suggestion; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Original terms superceded by these result. |
|
| 49 | - * Used when a prior search had suggested terms, and follow suggestions is enabled. |
|
| 50 | - * |
|
| 51 | - * @var PaginatedList |
|
| 52 | - */ |
|
| 53 | - protected $original; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Create a new CwpSearchResult |
|
| 57 | - * |
|
| 58 | - * @param string $terms |
|
| 59 | - * @param ArrayData $results Result from SolrIndex |
|
| 60 | - */ |
|
| 61 | - public function __construct($terms = '', ArrayData $results = null) |
|
| 62 | - { |
|
| 63 | - $this->query = $terms; |
|
| 64 | - if ($results) { |
|
| 65 | - // Clean up the results. |
|
| 66 | - $matches = $results->Matches; |
|
| 67 | - foreach ($matches as $result) { |
|
| 68 | - if (!$result->canView()) { |
|
| 69 | - $matches->remove($result); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $this->matches = $matches; |
|
| 74 | - $this->suggestion = $results->SuggestionNice; |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Get search results |
|
| 80 | - * |
|
| 81 | - * @return PaginatedList |
|
| 82 | - */ |
|
| 83 | - public function getResults() |
|
| 84 | - { |
|
| 85 | - return $this->matches; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Check if there are found results |
|
| 90 | - * |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - public function hasResults() |
|
| 94 | - { |
|
| 95 | - return $this->matches && $this->matches->exists(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Get search keywords matching these results |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function getQuery() |
|
| 104 | - { |
|
| 105 | - return $this->query; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get suggested search keywords |
|
| 110 | - * |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - public function getSuggestion() |
|
| 114 | - { |
|
| 115 | - return $this->suggestion; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Get original search keywords superceded by these results |
|
| 120 | - * |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function getOriginal() |
|
| 124 | - { |
|
| 125 | - return $this->original; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Set original keywords |
|
| 130 | - * |
|
| 131 | - * @param string $original |
|
| 132 | - */ |
|
| 133 | - public function setOriginal($original) |
|
| 134 | - { |
|
| 135 | - $this->original = $original; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Get the link to the suggested search |
|
| 140 | - * |
|
| 141 | - * @param string $format Optional output format |
|
| 142 | - * @return string |
|
| 143 | - */ |
|
| 144 | - public function getSuggestionLink($format = null) |
|
| 145 | - { |
|
| 146 | - return $this->getLink($this->suggestion, $format); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Gets the link to the given search |
|
| 151 | - * |
|
| 152 | - * @param string $format Optional output format |
|
| 153 | - * @return string |
|
| 154 | - */ |
|
| 155 | - public function getSearchLink($format = null) |
|
| 156 | - { |
|
| 157 | - return $this->getLink($this->query, $format); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Gets the link to the original search, with suggestions disabled |
|
| 162 | - * |
|
| 163 | - * @param string $format Optional output format |
|
| 164 | - * @return string |
|
| 165 | - */ |
|
| 166 | - public function getOriginalLink($format = null) |
|
| 167 | - { |
|
| 168 | - return $this->getLink($this->original, $format) . "&suggestions=0"; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Get link to these results in RSS format |
|
| 173 | - * |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - public function getRSSLink() |
|
| 177 | - { |
|
| 178 | - return $this->getLink($this->query, 'rss'); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get link to these results in atom format |
|
| 183 | - * |
|
| 184 | - * @return string |
|
| 185 | - */ |
|
| 186 | - public function getAtomLink() |
|
| 187 | - { |
|
| 188 | - return $this->getLink($this->query, 'atom'); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Get a search link for given terms |
|
| 193 | - * |
|
| 194 | - * @param string $terms |
|
| 195 | - * @return string|null |
|
| 196 | - */ |
|
| 197 | - protected function getLink($terms, $format = null) |
|
| 198 | - { |
|
| 199 | - if (!$terms) { |
|
| 200 | - return null; |
|
| 201 | - } |
|
| 202 | - $link = 'search/SearchForm?Search='.rawurlencode($terms); |
|
| 203 | - if ($format) { |
|
| 204 | - $link .= '&format='.rawurlencode($format); |
|
| 205 | - } |
|
| 206 | - return $link; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - public function hasField($field) |
|
| 210 | - { |
|
| 211 | - // Fix customise not detecting custom field getters |
|
| 212 | - return array_key_exists($field, $this->config()->casting); |
|
| 213 | - } |
|
| 14 | + private static $casting = [ |
|
| 15 | + 'Original' => 'Text', |
|
| 16 | + 'OriginalLink' => 'Text', |
|
| 17 | + 'Suggestion' => 'Text', |
|
| 18 | + 'SuggestionLink' => 'Text', |
|
| 19 | + 'Query' => 'Text', |
|
| 20 | + 'SearchLink' => 'Text', |
|
| 21 | + 'RSSLink' => 'Text', |
|
| 22 | + 'AtomLink' => 'Text', |
|
| 23 | + ]; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * List of results |
|
| 27 | + * |
|
| 28 | + * @var PaginatedList |
|
| 29 | + */ |
|
| 30 | + protected $matches; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Search terms for these results |
|
| 34 | + * |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + protected $query; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Suggested search keywords |
|
| 41 | + * Used when this search has suggested terms, but following suggestions isn't enabled |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $suggestion; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Original terms superceded by these result. |
|
| 49 | + * Used when a prior search had suggested terms, and follow suggestions is enabled. |
|
| 50 | + * |
|
| 51 | + * @var PaginatedList |
|
| 52 | + */ |
|
| 53 | + protected $original; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Create a new CwpSearchResult |
|
| 57 | + * |
|
| 58 | + * @param string $terms |
|
| 59 | + * @param ArrayData $results Result from SolrIndex |
|
| 60 | + */ |
|
| 61 | + public function __construct($terms = '', ArrayData $results = null) |
|
| 62 | + { |
|
| 63 | + $this->query = $terms; |
|
| 64 | + if ($results) { |
|
| 65 | + // Clean up the results. |
|
| 66 | + $matches = $results->Matches; |
|
| 67 | + foreach ($matches as $result) { |
|
| 68 | + if (!$result->canView()) { |
|
| 69 | + $matches->remove($result); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $this->matches = $matches; |
|
| 74 | + $this->suggestion = $results->SuggestionNice; |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Get search results |
|
| 80 | + * |
|
| 81 | + * @return PaginatedList |
|
| 82 | + */ |
|
| 83 | + public function getResults() |
|
| 84 | + { |
|
| 85 | + return $this->matches; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Check if there are found results |
|
| 90 | + * |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + public function hasResults() |
|
| 94 | + { |
|
| 95 | + return $this->matches && $this->matches->exists(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Get search keywords matching these results |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function getQuery() |
|
| 104 | + { |
|
| 105 | + return $this->query; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get suggested search keywords |
|
| 110 | + * |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + public function getSuggestion() |
|
| 114 | + { |
|
| 115 | + return $this->suggestion; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Get original search keywords superceded by these results |
|
| 120 | + * |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function getOriginal() |
|
| 124 | + { |
|
| 125 | + return $this->original; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Set original keywords |
|
| 130 | + * |
|
| 131 | + * @param string $original |
|
| 132 | + */ |
|
| 133 | + public function setOriginal($original) |
|
| 134 | + { |
|
| 135 | + $this->original = $original; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Get the link to the suggested search |
|
| 140 | + * |
|
| 141 | + * @param string $format Optional output format |
|
| 142 | + * @return string |
|
| 143 | + */ |
|
| 144 | + public function getSuggestionLink($format = null) |
|
| 145 | + { |
|
| 146 | + return $this->getLink($this->suggestion, $format); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Gets the link to the given search |
|
| 151 | + * |
|
| 152 | + * @param string $format Optional output format |
|
| 153 | + * @return string |
|
| 154 | + */ |
|
| 155 | + public function getSearchLink($format = null) |
|
| 156 | + { |
|
| 157 | + return $this->getLink($this->query, $format); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Gets the link to the original search, with suggestions disabled |
|
| 162 | + * |
|
| 163 | + * @param string $format Optional output format |
|
| 164 | + * @return string |
|
| 165 | + */ |
|
| 166 | + public function getOriginalLink($format = null) |
|
| 167 | + { |
|
| 168 | + return $this->getLink($this->original, $format) . "&suggestions=0"; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Get link to these results in RSS format |
|
| 173 | + * |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + public function getRSSLink() |
|
| 177 | + { |
|
| 178 | + return $this->getLink($this->query, 'rss'); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get link to these results in atom format |
|
| 183 | + * |
|
| 184 | + * @return string |
|
| 185 | + */ |
|
| 186 | + public function getAtomLink() |
|
| 187 | + { |
|
| 188 | + return $this->getLink($this->query, 'atom'); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Get a search link for given terms |
|
| 193 | + * |
|
| 194 | + * @param string $terms |
|
| 195 | + * @return string|null |
|
| 196 | + */ |
|
| 197 | + protected function getLink($terms, $format = null) |
|
| 198 | + { |
|
| 199 | + if (!$terms) { |
|
| 200 | + return null; |
|
| 201 | + } |
|
| 202 | + $link = 'search/SearchForm?Search='.rawurlencode($terms); |
|
| 203 | + if ($format) { |
|
| 204 | + $link .= '&format='.rawurlencode($format); |
|
| 205 | + } |
|
| 206 | + return $link; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + public function hasField($field) |
|
| 210 | + { |
|
| 211 | + // Fix customise not detecting custom field getters |
|
| 212 | + return array_key_exists($field, $this->config()->casting); |
|
| 213 | + } |
|
| 214 | 214 | } |
@@ -199,9 +199,9 @@ |
||
| 199 | 199 | if (!$terms) { |
| 200 | 200 | return null; |
| 201 | 201 | } |
| 202 | - $link = 'search/SearchForm?Search='.rawurlencode($terms); |
|
| 202 | + $link = 'search/SearchForm?Search=' . rawurlencode($terms); |
|
| 203 | 203 | if ($format) { |
| 204 | - $link .= '&format='.rawurlencode($format); |
|
| 204 | + $link .= '&format=' . rawurlencode($format); |
|
| 205 | 205 | } |
| 206 | 206 | return $link; |
| 207 | 207 | } |
@@ -11,14 +11,14 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class CwpSearchPage extends Page |
| 13 | 13 | { |
| 14 | - private static $hide_ancestor = CwpSearchPage::class; |
|
| 14 | + private static $hide_ancestor = CwpSearchPage::class; |
|
| 15 | 15 | |
| 16 | - public function canViewStage($stage = Versioned::LIVE, $member = null) |
|
| 17 | - { |
|
| 18 | - if (Permission::checkMember($member, 'VIEW_DRAFT_CONTENT')) { |
|
| 19 | - return true; |
|
| 20 | - } |
|
| 16 | + public function canViewStage($stage = Versioned::LIVE, $member = null) |
|
| 17 | + { |
|
| 18 | + if (Permission::checkMember($member, 'VIEW_DRAFT_CONTENT')) { |
|
| 19 | + return true; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - return parent::canViewStage($stage, $member); |
|
| 23 | - } |
|
| 22 | + return parent::canViewStage($stage, $member); |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -16,52 +16,52 @@ |
||
| 16 | 16 | class SynonymsSiteConfig extends DataExtension |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - private static $db = array( |
|
| 20 | - 'SearchSynonyms' => 'Text', // fulltextsearch synonyms.txt content |
|
| 21 | - ); |
|
| 19 | + private static $db = array( |
|
| 20 | + 'SearchSynonyms' => 'Text', // fulltextsearch synonyms.txt content |
|
| 21 | + ); |
|
| 22 | 22 | |
| 23 | - public function updateCMSFields(FieldList $fields) |
|
| 24 | - { |
|
| 25 | - // Don't show this field if you're not an admin |
|
| 26 | - if (!Permission::check('ADMIN')) { |
|
| 27 | - return; |
|
| 28 | - } |
|
| 23 | + public function updateCMSFields(FieldList $fields) |
|
| 24 | + { |
|
| 25 | + // Don't show this field if you're not an admin |
|
| 26 | + if (!Permission::check('ADMIN')) { |
|
| 27 | + return; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - // Search synonyms |
|
| 31 | - $fields->addFieldToTab( |
|
| 32 | - 'Root.FulltextSearch', |
|
| 33 | - TextareaField::create('SearchSynonyms', _t('CwpConfig.SearchSynonyms', 'Search Synonyms')) |
|
| 34 | - ->setDescription(_t( |
|
| 35 | - 'CwpConfig.SearchSynonyms_Description', |
|
| 36 | - 'Enter as many comma separated synonyms as you wish, where '. |
|
| 37 | - 'each line represents a group of synonyms.<br /> ' . |
|
| 38 | - 'You will need to run <a rel="external" target="_blank" href="dev/tasks/Solr_Configure">' |
|
| 39 | - . 'Solr_Configure</a> if you make any changes' |
|
| 40 | - )) |
|
| 41 | - ); |
|
| 42 | - } |
|
| 30 | + // Search synonyms |
|
| 31 | + $fields->addFieldToTab( |
|
| 32 | + 'Root.FulltextSearch', |
|
| 33 | + TextareaField::create('SearchSynonyms', _t('CwpConfig.SearchSynonyms', 'Search Synonyms')) |
|
| 34 | + ->setDescription(_t( |
|
| 35 | + 'CwpConfig.SearchSynonyms_Description', |
|
| 36 | + 'Enter as many comma separated synonyms as you wish, where '. |
|
| 37 | + 'each line represents a group of synonyms.<br /> ' . |
|
| 38 | + 'You will need to run <a rel="external" target="_blank" href="dev/tasks/Solr_Configure">' |
|
| 39 | + . 'Solr_Configure</a> if you make any changes' |
|
| 40 | + )) |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @inheritdoc |
|
| 46 | - * |
|
| 47 | - * @param ValidationResult $validationResult |
|
| 48 | - */ |
|
| 49 | - public function validate(ValidationResult $validationResult) |
|
| 50 | - { |
|
| 51 | - $validator = new SynonymValidator(array( |
|
| 52 | - 'SearchSynonyms', |
|
| 53 | - )); |
|
| 44 | + /** |
|
| 45 | + * @inheritdoc |
|
| 46 | + * |
|
| 47 | + * @param ValidationResult $validationResult |
|
| 48 | + */ |
|
| 49 | + public function validate(ValidationResult $validationResult) |
|
| 50 | + { |
|
| 51 | + $validator = new SynonymValidator(array( |
|
| 52 | + 'SearchSynonyms', |
|
| 53 | + )); |
|
| 54 | 54 | |
| 55 | - $validator->php(array( |
|
| 56 | - 'SearchSynonyms' => $this->owner->SearchSynonyms |
|
| 57 | - )); |
|
| 55 | + $validator->php(array( |
|
| 56 | + 'SearchSynonyms' => $this->owner->SearchSynonyms |
|
| 57 | + )); |
|
| 58 | 58 | |
| 59 | - $errors = $validator->getErrors(); |
|
| 59 | + $errors = $validator->getErrors(); |
|
| 60 | 60 | |
| 61 | - if (is_array($errors) || $errors instanceof Traversable) { |
|
| 62 | - foreach ($errors as $error) { |
|
| 63 | - $validationResult->error($error['message']); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 61 | + if (is_array($errors) || $errors instanceof Traversable) { |
|
| 62 | + foreach ($errors as $error) { |
|
| 63 | + $validationResult->error($error['message']); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | TextareaField::create('SearchSynonyms', _t('CwpConfig.SearchSynonyms', 'Search Synonyms')) |
| 34 | 34 | ->setDescription(_t( |
| 35 | 35 | 'CwpConfig.SearchSynonyms_Description', |
| 36 | - 'Enter as many comma separated synonyms as you wish, where '. |
|
| 36 | + 'Enter as many comma separated synonyms as you wish, where ' . |
|
| 37 | 37 | 'each line represents a group of synonyms.<br /> ' . |
| 38 | 38 | 'You will need to run <a rel="external" target="_blank" href="dev/tasks/Solr_Configure">' |
| 39 | 39 | . 'Solr_Configure</a> if you make any changes' |
@@ -11,50 +11,50 @@ |
||
| 11 | 11 | class CwpSiteTreeFileExtension extends DataExtension |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - public function updateCMSFields(FieldList $fields) |
|
| 15 | - { |
|
| 16 | - Requirements::css('cwp/css/fieldDescriptionToggle.css'); |
|
| 17 | - Requirements::javascript('cwp/javascript/fieldDescriptionToggle.js'); |
|
| 18 | - |
|
| 19 | - $fields->insertAfter( |
|
| 20 | - ReadonlyField::create( |
|
| 21 | - 'BackLinkCount', |
|
| 22 | - _t('AssetTableField.BACKLINKCOUNT', 'Used on:'), |
|
| 23 | - $this->owner->BackLinkTracking()->Count() . ' ' . _t('AssetTableField.PAGES', 'page(s)') |
|
| 24 | - ) |
|
| 25 | - ->addExtraClass('cms-description-toggle') |
|
| 26 | - ->setDescription($this->BackLinkHTMLList()), |
|
| 27 | - 'LastEdited' |
|
| 28 | - ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Generate an HTML list which provides links to where a file is used. |
|
| 33 | - * |
|
| 34 | - * @return String |
|
| 35 | - */ |
|
| 36 | - public function BackLinkHTMLList() |
|
| 37 | - { |
|
| 38 | - $html = '<em>' . _t( |
|
| 39 | - 'SiteTreeFileExtension.BACKLINK_LIST_DESCRIPTION', |
|
| 40 | - 'This list shows all pages where the file has been added through a WYSIWYG editor.' |
|
| 41 | - ) . '</em>'; |
|
| 42 | - $html .= '<ul>'; |
|
| 43 | - |
|
| 44 | - foreach ($this->owner->BackLinkTracking() as $backLink) { |
|
| 45 | - $listItem = '<li>'; |
|
| 46 | - |
|
| 47 | - // Add the page link |
|
| 48 | - $listItem .= '<a href="' . $backLink->Link() . '" target="_blank">' |
|
| 49 | - . Convert::raw2xml($backLink->MenuTitle) . '</a> – '; |
|
| 50 | - |
|
| 51 | - // Add the CMS link |
|
| 52 | - $listItem .= '<a href="' . $backLink->CMSEditLink() . '">' |
|
| 53 | - . _t('SiteTreeFileExtension.EDIT', 'Edit') . '</a>'; |
|
| 54 | - |
|
| 55 | - $html .= $listItem . '</li>'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - return $html .= '</ul>'; |
|
| 59 | - } |
|
| 14 | + public function updateCMSFields(FieldList $fields) |
|
| 15 | + { |
|
| 16 | + Requirements::css('cwp/css/fieldDescriptionToggle.css'); |
|
| 17 | + Requirements::javascript('cwp/javascript/fieldDescriptionToggle.js'); |
|
| 18 | + |
|
| 19 | + $fields->insertAfter( |
|
| 20 | + ReadonlyField::create( |
|
| 21 | + 'BackLinkCount', |
|
| 22 | + _t('AssetTableField.BACKLINKCOUNT', 'Used on:'), |
|
| 23 | + $this->owner->BackLinkTracking()->Count() . ' ' . _t('AssetTableField.PAGES', 'page(s)') |
|
| 24 | + ) |
|
| 25 | + ->addExtraClass('cms-description-toggle') |
|
| 26 | + ->setDescription($this->BackLinkHTMLList()), |
|
| 27 | + 'LastEdited' |
|
| 28 | + ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Generate an HTML list which provides links to where a file is used. |
|
| 33 | + * |
|
| 34 | + * @return String |
|
| 35 | + */ |
|
| 36 | + public function BackLinkHTMLList() |
|
| 37 | + { |
|
| 38 | + $html = '<em>' . _t( |
|
| 39 | + 'SiteTreeFileExtension.BACKLINK_LIST_DESCRIPTION', |
|
| 40 | + 'This list shows all pages where the file has been added through a WYSIWYG editor.' |
|
| 41 | + ) . '</em>'; |
|
| 42 | + $html .= '<ul>'; |
|
| 43 | + |
|
| 44 | + foreach ($this->owner->BackLinkTracking() as $backLink) { |
|
| 45 | + $listItem = '<li>'; |
|
| 46 | + |
|
| 47 | + // Add the page link |
|
| 48 | + $listItem .= '<a href="' . $backLink->Link() . '" target="_blank">' |
|
| 49 | + . Convert::raw2xml($backLink->MenuTitle) . '</a> – '; |
|
| 50 | + |
|
| 51 | + // Add the CMS link |
|
| 52 | + $listItem .= '<a href="' . $backLink->CMSEditLink() . '">' |
|
| 53 | + . _t('SiteTreeFileExtension.EDIT', 'Edit') . '</a>'; |
|
| 54 | + |
|
| 55 | + $html .= $listItem . '</li>'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + return $html .= '</ul>'; |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -12,45 +12,45 @@ |
||
| 12 | 12 | class CwpSearchBoostExtension extends DataExtension |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Quality to boost the 'SearchBoost' field by. |
|
| 17 | - * Default boost is 2x |
|
| 18 | - * |
|
| 19 | - * @var config |
|
| 20 | - * @string |
|
| 21 | - */ |
|
| 22 | - private static $search_boost = '2'; |
|
| 23 | - |
|
| 24 | - private static $db = array( |
|
| 25 | - 'SearchBoost' => 'Text' |
|
| 26 | - ); |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Adds boost fields to this page |
|
| 30 | - * |
|
| 31 | - * @param FieldList $fields |
|
| 32 | - */ |
|
| 33 | - public function updateCMSFields(FieldList $fields) |
|
| 34 | - { |
|
| 35 | - parent::updateCMSFields($fields); |
|
| 36 | - |
|
| 37 | - // Rename metafield |
|
| 38 | - $meta = $fields->fieldByName('Root.Main.Metadata'); |
|
| 39 | - $meta->setTitle(_t('CwpSearchBoostExtension.PAGEINFO', 'Page info and SEO')); |
|
| 40 | - |
|
| 41 | - $boostTitle = _t('CwpSiteTreeSearchBoost.SearchBoost', 'Boost Keywords'); |
|
| 42 | - $boostNote = _t( |
|
| 43 | - 'CwpSiteTreeSearchBoost.SearchBoostNote', |
|
| 44 | - '(Only applies to the search results on this site e.g. not on Google search)' |
|
| 45 | - ); |
|
| 46 | - $boostDescription = _t( |
|
| 47 | - 'CwpSiteTreeSearchBoost.SearchBoostDescription', |
|
| 48 | - 'Enter keywords separated by comma ( , ) for which to boost the ranking of this page ' |
|
| 49 | - . 'within the search results on this site.' |
|
| 50 | - ); |
|
| 51 | - $boostField = TextareaField::create('SearchBoost', $boostTitle) |
|
| 52 | - ->setRightTitle($boostNote) |
|
| 53 | - ->setDescription($boostDescription); |
|
| 54 | - $fields->insertBefore($boostField, 'MetaDescription'); |
|
| 55 | - } |
|
| 15 | + /** |
|
| 16 | + * Quality to boost the 'SearchBoost' field by. |
|
| 17 | + * Default boost is 2x |
|
| 18 | + * |
|
| 19 | + * @var config |
|
| 20 | + * @string |
|
| 21 | + */ |
|
| 22 | + private static $search_boost = '2'; |
|
| 23 | + |
|
| 24 | + private static $db = array( |
|
| 25 | + 'SearchBoost' => 'Text' |
|
| 26 | + ); |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Adds boost fields to this page |
|
| 30 | + * |
|
| 31 | + * @param FieldList $fields |
|
| 32 | + */ |
|
| 33 | + public function updateCMSFields(FieldList $fields) |
|
| 34 | + { |
|
| 35 | + parent::updateCMSFields($fields); |
|
| 36 | + |
|
| 37 | + // Rename metafield |
|
| 38 | + $meta = $fields->fieldByName('Root.Main.Metadata'); |
|
| 39 | + $meta->setTitle(_t('CwpSearchBoostExtension.PAGEINFO', 'Page info and SEO')); |
|
| 40 | + |
|
| 41 | + $boostTitle = _t('CwpSiteTreeSearchBoost.SearchBoost', 'Boost Keywords'); |
|
| 42 | + $boostNote = _t( |
|
| 43 | + 'CwpSiteTreeSearchBoost.SearchBoostNote', |
|
| 44 | + '(Only applies to the search results on this site e.g. not on Google search)' |
|
| 45 | + ); |
|
| 46 | + $boostDescription = _t( |
|
| 47 | + 'CwpSiteTreeSearchBoost.SearchBoostDescription', |
|
| 48 | + 'Enter keywords separated by comma ( , ) for which to boost the ranking of this page ' |
|
| 49 | + . 'within the search results on this site.' |
|
| 50 | + ); |
|
| 51 | + $boostField = TextareaField::create('SearchBoost', $boostTitle) |
|
| 52 | + ->setRightTitle($boostNote) |
|
| 53 | + ->setDescription($boostDescription); |
|
| 54 | + $fields->insertBefore($boostField, 'MetaDescription'); |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -12,37 +12,37 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class CwpWorkflowDefinitionExtension extends DataExtension |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Create the default 'Two-step Workflow' when this extension is loaded |
|
| 17 | - * |
|
| 18 | - * @config |
|
| 19 | - * @var boolean |
|
| 20 | - */ |
|
| 21 | - private static $create_default_workflow = true; |
|
| 15 | + /** |
|
| 16 | + * Create the default 'Two-step Workflow' when this extension is loaded |
|
| 17 | + * |
|
| 18 | + * @config |
|
| 19 | + * @var boolean |
|
| 20 | + */ |
|
| 21 | + private static $create_default_workflow = true; |
|
| 22 | 22 | |
| 23 | - public function requireDefaultRecords() |
|
| 24 | - { |
|
| 25 | - if (Config::inst()->get(CwpWorkflowDefinitionExtension::class, 'create_default_workflow')) { |
|
| 26 | - // Only proceed if a definition using this template has not been created yet |
|
| 27 | - $definition = WorkflowDefinition::get()->filter("Template", "Review and Approve")->First(); |
|
| 28 | - if ($definition && $definition->exists()) { |
|
| 29 | - return; |
|
| 30 | - } |
|
| 23 | + public function requireDefaultRecords() |
|
| 24 | + { |
|
| 25 | + if (Config::inst()->get(CwpWorkflowDefinitionExtension::class, 'create_default_workflow')) { |
|
| 26 | + // Only proceed if a definition using this template has not been created yet |
|
| 27 | + $definition = WorkflowDefinition::get()->filter("Template", "Review and Approve")->First(); |
|
| 28 | + if ($definition && $definition->exists()) { |
|
| 29 | + return; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - //generate from the template, which happens after we write the definition |
|
| 33 | - $definition = WorkflowDefinition::create(); |
|
| 34 | - $definition->Template = "Review and Approve"; |
|
| 35 | - $definition->write(); |
|
| 32 | + //generate from the template, which happens after we write the definition |
|
| 33 | + $definition = WorkflowDefinition::create(); |
|
| 34 | + $definition->Template = "Review and Approve"; |
|
| 35 | + $definition->write(); |
|
| 36 | 36 | |
| 37 | - //change the title, description, and reminder days |
|
| 38 | - $definition->update(array( |
|
| 39 | - 'Title' => "Two-step Workflow", |
|
| 40 | - 'Description' => "Content Authors can write content and Content Publishers can approve/reject.", |
|
| 41 | - 'RemindDays' => 3, |
|
| 42 | - )); |
|
| 43 | - $definition->write(); |
|
| 37 | + //change the title, description, and reminder days |
|
| 38 | + $definition->update(array( |
|
| 39 | + 'Title' => "Two-step Workflow", |
|
| 40 | + 'Description' => "Content Authors can write content and Content Publishers can approve/reject.", |
|
| 41 | + 'RemindDays' => 3, |
|
| 42 | + )); |
|
| 43 | + $definition->write(); |
|
| 44 | 44 | |
| 45 | - DB::alteration_message("Added default workflow definition to WorkflowDefinition table", "created"); |
|
| 46 | - } |
|
| 47 | - } |
|
| 45 | + DB::alteration_message("Added default workflow definition to WorkflowDefinition table", "created"); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -11,55 +11,55 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class CustomSiteConfig extends DataExtension |
| 13 | 13 | { |
| 14 | - private static $db = array( |
|
| 15 | - 'GACode' => 'Varchar(16)', |
|
| 16 | - 'FacebookURL' => 'Varchar(256)', // multitude of ways to link to Facebook accounts, best to leave it open. |
|
| 17 | - 'TwitterUsername' => 'Varchar(16)', // max length of Twitter username 15 |
|
| 18 | - ); |
|
| 14 | + private static $db = array( |
|
| 15 | + 'GACode' => 'Varchar(16)', |
|
| 16 | + 'FacebookURL' => 'Varchar(256)', // multitude of ways to link to Facebook accounts, best to leave it open. |
|
| 17 | + 'TwitterUsername' => 'Varchar(16)', // max length of Twitter username 15 |
|
| 18 | + ); |
|
| 19 | 19 | |
| 20 | - public function updateCMSFields(FieldList $fields) |
|
| 21 | - { |
|
| 22 | - $fields->addFieldToTab( |
|
| 23 | - 'Root.Main', |
|
| 24 | - $gaCode = TextField::create( |
|
| 25 | - 'GACode', |
|
| 26 | - _t('CwpConfig.GaField', 'Google Analytics account') |
|
| 27 | - ) |
|
| 28 | - ); |
|
| 20 | + public function updateCMSFields(FieldList $fields) |
|
| 21 | + { |
|
| 22 | + $fields->addFieldToTab( |
|
| 23 | + 'Root.Main', |
|
| 24 | + $gaCode = TextField::create( |
|
| 25 | + 'GACode', |
|
| 26 | + _t('CwpConfig.GaField', 'Google Analytics account') |
|
| 27 | + ) |
|
| 28 | + ); |
|
| 29 | 29 | |
| 30 | - $gaCode->setRightTitle( |
|
| 31 | - _t( |
|
| 32 | - 'CwpConfig.GaFieldDesc', |
|
| 33 | - 'Account number to be used all across the site (in the format <strong>UA-XXXXX-X</strong>)' |
|
| 34 | - ) |
|
| 35 | - ); |
|
| 30 | + $gaCode->setRightTitle( |
|
| 31 | + _t( |
|
| 32 | + 'CwpConfig.GaFieldDesc', |
|
| 33 | + 'Account number to be used all across the site (in the format <strong>UA-XXXXX-X</strong>)' |
|
| 34 | + ) |
|
| 35 | + ); |
|
| 36 | 36 | |
| 37 | - $fields->findOrMakeTab('Root.SocialMedia', _t('CustomSiteConfig.SocialMediaTab', 'Social Media')); |
|
| 37 | + $fields->findOrMakeTab('Root.SocialMedia', _t('CustomSiteConfig.SocialMediaTab', 'Social Media')); |
|
| 38 | 38 | |
| 39 | - $fields->addFieldToTab( |
|
| 40 | - 'Root.SocialMedia', |
|
| 41 | - $facebookURL = TextField::create( |
|
| 42 | - 'FacebookURL', |
|
| 43 | - _t('CwpConfig.FbField', 'Facebook UID or username') |
|
| 44 | - ) |
|
| 45 | - ); |
|
| 46 | - $facebookURL->setRightTitle( |
|
| 47 | - _t( |
|
| 48 | - 'CwpConfig.FbFieldDesc', |
|
| 49 | - 'Facebook link (everything after the "http://facebook.com/", eg http://facebook.com/' |
|
| 50 | - . '<strong>username</strong> or http://facebook.com/<strong>pages/108510539573</strong>)' |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 39 | + $fields->addFieldToTab( |
|
| 40 | + 'Root.SocialMedia', |
|
| 41 | + $facebookURL = TextField::create( |
|
| 42 | + 'FacebookURL', |
|
| 43 | + _t('CwpConfig.FbField', 'Facebook UID or username') |
|
| 44 | + ) |
|
| 45 | + ); |
|
| 46 | + $facebookURL->setRightTitle( |
|
| 47 | + _t( |
|
| 48 | + 'CwpConfig.FbFieldDesc', |
|
| 49 | + 'Facebook link (everything after the "http://facebook.com/", eg http://facebook.com/' |
|
| 50 | + . '<strong>username</strong> or http://facebook.com/<strong>pages/108510539573</strong>)' |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | - $fields->addFieldToTab( |
|
| 55 | - 'Root.SocialMedia', |
|
| 56 | - $twitterUsername = TextField::create( |
|
| 57 | - 'TwitterUsername', |
|
| 58 | - _t('CwpConfig.TwitterField', 'Twitter username') |
|
| 59 | - ) |
|
| 60 | - ); |
|
| 61 | - $twitterUsername->setRightTitle( |
|
| 62 | - _t('CwpConfig.TwitterFieldDesc', 'Twitter username (eg, http://twitter.com/<strong>username</strong>)') |
|
| 63 | - ); |
|
| 64 | - } |
|
| 54 | + $fields->addFieldToTab( |
|
| 55 | + 'Root.SocialMedia', |
|
| 56 | + $twitterUsername = TextField::create( |
|
| 57 | + 'TwitterUsername', |
|
| 58 | + _t('CwpConfig.TwitterField', 'Twitter username') |
|
| 59 | + ) |
|
| 60 | + ); |
|
| 61 | + $twitterUsername->setRightTitle( |
|
| 62 | + _t('CwpConfig.TwitterFieldDesc', 'Twitter username (eg, http://twitter.com/<strong>username</strong>)') |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -8,42 +8,42 @@ |
||
| 8 | 8 | |
| 9 | 9 | class BasePageTest extends SapphireTest |
| 10 | 10 | { |
| 11 | - protected static $fixture_file = 'BasePageTest.yml'; |
|
| 12 | - |
|
| 13 | - protected function setUp() |
|
| 14 | - { |
|
| 15 | - parent::setUp(); |
|
| 16 | - |
|
| 17 | - Config::modify()->set(BasePage::class, 'pdf_export', true); |
|
| 18 | - Config::modify()->set(BasePage::class, 'generated_pdf_path', 'assets/_generated_pdfs'); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function testPdfFilename() |
|
| 22 | - { |
|
| 23 | - $page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
| 24 | - $this->assertContains( |
|
| 25 | - 'assets/_generated_pdfs/test-page-one-1.pdf', |
|
| 26 | - $page->getPdfFilename(), |
|
| 27 | - 'Generated filename for PDF' |
|
| 28 | - ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function testPdfLink() |
|
| 32 | - { |
|
| 33 | - $page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
| 34 | - $this->assertContains('test-page-one/downloadpdf', $page->PdfLink(), 'Link to download PDF'); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function testHomePagePdfLink() |
|
| 38 | - { |
|
| 39 | - $page = $this->objFromFixture(BasePage::class, 'home-page'); |
|
| 40 | - $this->assertContains('home/downloadpdf', $page->PdfLink(), 'Link to download PDF'); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function testPdfLinkDisabled() |
|
| 44 | - { |
|
| 45 | - Config::modify()->set(BasePage::class, 'pdf_export', false); |
|
| 46 | - $page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
| 47 | - $this->assertFalse($page->PdfLink(), 'No PDF link as the functionality is disabled'); |
|
| 48 | - } |
|
| 11 | + protected static $fixture_file = 'BasePageTest.yml'; |
|
| 12 | + |
|
| 13 | + protected function setUp() |
|
| 14 | + { |
|
| 15 | + parent::setUp(); |
|
| 16 | + |
|
| 17 | + Config::modify()->set(BasePage::class, 'pdf_export', true); |
|
| 18 | + Config::modify()->set(BasePage::class, 'generated_pdf_path', 'assets/_generated_pdfs'); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function testPdfFilename() |
|
| 22 | + { |
|
| 23 | + $page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
| 24 | + $this->assertContains( |
|
| 25 | + 'assets/_generated_pdfs/test-page-one-1.pdf', |
|
| 26 | + $page->getPdfFilename(), |
|
| 27 | + 'Generated filename for PDF' |
|
| 28 | + ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function testPdfLink() |
|
| 32 | + { |
|
| 33 | + $page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
| 34 | + $this->assertContains('test-page-one/downloadpdf', $page->PdfLink(), 'Link to download PDF'); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function testHomePagePdfLink() |
|
| 38 | + { |
|
| 39 | + $page = $this->objFromFixture(BasePage::class, 'home-page'); |
|
| 40 | + $this->assertContains('home/downloadpdf', $page->PdfLink(), 'Link to download PDF'); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function testPdfLinkDisabled() |
|
| 44 | + { |
|
| 45 | + Config::modify()->set(BasePage::class, 'pdf_export', false); |
|
| 46 | + $page = $this->objFromFixture(BasePage::class, 'test-page-one'); |
|
| 47 | + $this->assertFalse($page->PdfLink(), 'No PDF link as the functionality is disabled'); |
|
| 48 | + } |
|
| 49 | 49 | } |