1 | <?php |
||
15 | class CountryPrice_Page_Controller_Extension extends Extension |
||
|
|||
16 | { |
||
17 | |||
18 | /** |
||
19 | * replaces `Title` and `Content` with translated content |
||
20 | * where available. |
||
21 | * |
||
22 | * If the country code in the get parameter is not correct then |
||
23 | * @return [type] [description] |
||
24 | */ |
||
25 | public function onAfterInit() |
||
26 | { |
||
27 | $countryID = 0; |
||
28 | //provided by stealth ... |
||
29 | $countryObject = CountryPrice_EcommerceCountry::get_real_country(); |
||
30 | |||
31 | if ($countryObject) { |
||
32 | |||
33 | //check if a redirect is required ... |
||
34 | $this->checkForOffsiteRedirects($countryObject); |
||
35 | |||
36 | $countryID = $countryObject->ID; |
||
37 | //check that there is a translation |
||
38 | if ($this->owner->dataRecord->thisPageHasTranslation($countryID)) { |
||
39 | //if there is a translation but it is not showing in the URL then redirect |
||
40 | $newURL = $this->addCountryCodeToUrlIfRequired($countryObject->Code); |
||
41 | if ($newURL) { |
||
42 | $this->owner->redirect($newURL); |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 | |||
47 | $this->owner->dataRecord->loadTranslatedValues($countryID, null); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * returns the best fieldname for |
||
52 | * @param string $fieldName [description] |
||
53 | */ |
||
54 | public function CountryDistributorBestContentValue($fieldName) |
||
74 | |||
75 | /** |
||
76 | * caching variable |
||
77 | * |
||
78 | * @var integer |
||
79 | */ |
||
80 | private static $_redirection_count = 0; |
||
81 | |||
82 | /** |
||
83 | * returns a string for the new url if a locale parameter can be added |
||
84 | * |
||
85 | * @return string | null |
||
86 | */ |
||
87 | private function addCountryCodeToUrlIfRequired($countryCode = '') |
||
108 | |||
109 | |||
110 | /** |
||
111 | * |
||
112 | * |
||
113 | * @return ArrayList |
||
114 | */ |
||
115 | public function ChooseNewCountryList() |
||
143 | |||
144 | /** |
||
145 | * |
||
146 | * @return DataList |
||
147 | */ |
||
148 | public function AlternativeHrefLangLinksCachingKey() |
||
156 | |||
157 | /** |
||
158 | * |
||
159 | * @param string $link - passed by reference |
||
160 | */ |
||
161 | public function UpdateCanonicalLink(&$link) |
||
171 | |||
172 | /** |
||
173 | * redirects visitors to another website if they are listed as such in |
||
174 | * CountryPrices_ChangeCountryController.off_site_url_redirects |
||
175 | * |
||
176 | * @param EcommerceCountry $countryObject current country of visitor |
||
177 | * |
||
178 | * @return null|SS_HTTPResponse |
||
179 | */ |
||
180 | protected function checkForOffsiteRedirects($countryObject) |
||
188 | } |
||
189 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.