PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Pagesetup/Pagesetup.php

https://gitlab.com/mrjkvcs/usnationalcommercial
PHP | 332 lines | 213 code | 33 blank | 86 comment | 35 complexity | af6a2acfe19d71278ca8e89cd9bc89a2 MD5 | raw file
  1. <?php
  2. class Pagesetup extends BaseModule {
  3. private $cssFiles = array();
  4. private $scriptFiles = array();
  5. private $scriptTags = array();
  6. private $rss = array();
  7. private $title = '';
  8. private $titleprefix = '';
  9. private $titlesuffix = '';
  10. private $titleSeparator = ' - ';
  11. private $description = '';
  12. private $keywords = '';
  13. private $author = '';
  14. private $robots = '';
  15. private $ga = '';
  16. private $imagetoolbar = true;
  17. private $favicon = '';
  18. private $extraheader = '';
  19. /**
  20. * Felvesz egy CSS fájlt a betöltendő stíluslapok közé
  21. * @param string $file a fájl neve
  22. * @param string $mediaType a kiválasztott média típus
  23. * @return pagesetup
  24. */
  25. public function addCss($file, $mediaType = 'all') {
  26. if ($file && !array_key_exists($file, $this->cssFiles)) {
  27. if (DEBUG_MODE) {
  28. UniAdmin::addDebugInfo('adding css ' . $file, 'page');
  29. }
  30. $this->cssFiles[$file] = $mediaType;
  31. }
  32. return $this;
  33. }
  34. /**
  35. * Felvesz egy JavaScript fájlt a betöltendő script fájlok közé
  36. * @param string $file a fájl neve
  37. * @return pagesetup
  38. */
  39. public function addScript($file) {
  40. if ($file && !in_array($file, $this->scriptFiles)) {
  41. if (DEBUG_MODE) {
  42. UniAdmin::addDebugInfo('adding javascript ' . $file, 'page');
  43. }
  44. $this->scriptFiles[] = $file;
  45. }
  46. return $this;
  47. }
  48. /**
  49. * Felvesz egy JavaScript kódrészletet a meghívandó scriptek közé
  50. * @param string $script a kódrészlet
  51. * @return pagesetup
  52. */
  53. public function addScriptTag($script) {
  54. if ($script) {
  55. if (DEBUG_MODE) {
  56. UniAdmin::addDebugInfo('adding javascript tag', 'page');
  57. }
  58. $this->scriptTags[] = $script;
  59. }
  60. return $this;
  61. }
  62. /**
  63. * Felvesz egy RSS fájlt az oldal feed-jei közé
  64. * @param string $file a fájl neve
  65. * @param string $title a feed címe
  66. * @return pagesetup|bool
  67. */
  68. public function addRSS($file, $title = '') {
  69. if ($file) {
  70. $this->rss[] = array('file' => $file, 'title' => $title);
  71. return $this;
  72. } else {
  73. return false;
  74. }
  75. }
  76. public function removeCss($file) {
  77. if (isset($this->cssFiles[$file])) {
  78. unset($this->cssFiles[$file]);
  79. }
  80. return $this;
  81. }
  82. public function removeAllCss() {
  83. $this->cssFiles = array();
  84. return $this;
  85. }
  86. public function removeScript($file) {
  87. $key = array_search($file, $this->scriptFiles);
  88. if ($key !== false) {
  89. unset($this->scriptFiles[$key]);
  90. }
  91. return $this;
  92. }
  93. public function removeAllScripts() {
  94. $this->scriptFiles = array();
  95. return $this;
  96. }
  97. public function removeRss($file) {
  98. $key = array_search($file, $this->rss);
  99. if ($key !== false) {
  100. unset($this->rss[$key]);
  101. }
  102. return $this;
  103. }
  104. /**
  105. * Beállítja a holnap címének előtagját
  106. * A rendszer a címeket három részre bontva kezeli: PREFIX | TITLE | SUFFIX
  107. * @param string $value
  108. * @return pagesetup
  109. */
  110. public function setTitlePrefix($value) {
  111. $this->titleprefix = $value;
  112. return $this;
  113. }
  114. /**
  115. * Beállítja a holnap címét
  116. * A rendszer a címeket három részre bontva kezeli: PREFIX | TITLE | SUFFIX
  117. * @param string $value
  118. * @return pagesetup
  119. */
  120. public function setTitle($value) {
  121. $this->title = $value;
  122. return $this;
  123. }
  124. /**
  125. * Beállítja a holnap címének utótagját
  126. * A rendszer a címeket három részre bontva kezeli: PREFIX | TITLE | SUFFIX
  127. * @param string $value
  128. * @param pagesetup
  129. */
  130. public function setTitleSuffix($value) {
  131. $this->titlesuffix = $value;
  132. return $this;
  133. }
  134. /**
  135. * Beállítja az oldal META DESCRIPTION fejlécét
  136. * @param string $value
  137. * @return pagesetup
  138. */
  139. public function setDescription($value) {
  140. $this->description = $value;
  141. return $this;
  142. }
  143. /**
  144. * Beállítja az oldal META KEYWORDS fejlécét
  145. * @param string $value
  146. * @return pagesetup
  147. */
  148. public function setKeywords($value) {
  149. $this->keywords = $value;
  150. return $this;
  151. }
  152. /**
  153. * Beállítja az oldal META AUTHOR fejlécét
  154. * @param string $value
  155. * @return pagesetup
  156. */
  157. public function setAuthor($value) {
  158. $this->author= $value;
  159. return $this;
  160. }
  161. /**
  162. * Beállítja az oldal META ROBOTS fejlécét
  163. * A fejléc az alábbi kifejezéseket tartalmazhatja:
  164. * index, follow, noindex, nofollow,all
  165. * @param string $value
  166. * @return pagesetup
  167. */
  168. public function setRobots($value) {
  169. $this->robots = $value;
  170. return $this;
  171. }
  172. /**
  173. * Beállítja a Google Analytics tracker azonosítóját, hogy ez alapján a
  174. * rendszer el tudja készíteni a követőkódot
  175. * @param string $value
  176. * @return pagesetup
  177. */
  178. public function setGATracker($value) {
  179. $this->ga = $value;
  180. return $this;
  181. }
  182. /**
  183. * Kikapcsolja az Internet Explorer 'Image Toolbar'-ját, ami az oldal képein jelenik meg
  184. * @param bool $state
  185. * @return pagesetup
  186. */
  187. public function setImageToolbar($state) {
  188. $this->imagetoolbar = $state;
  189. return $this;
  190. }
  191. /**
  192. * Beállítja a honlap FAVICON-ját, a böngészősávon megjelenő kis ikont
  193. * @param string $value alapértelmezetten a böngészők által keresett /favicon.ico
  194. * @@return pagesetup
  195. */
  196. public function setFavIcon($value = '/favicon.ico') {
  197. $this->favicon = $value;
  198. return $this;
  199. }
  200. /**
  201. * Csatol egy HTML kódot, ami a honlap fejlécébe a <HEAD> </HEAD> tagek közé fog kerülni
  202. * @param string $html
  203. * @return pagesetup
  204. */
  205. public function addExtraHeader($html) {
  206. $this->extraheader .= $html;
  207. return $this;
  208. }
  209. public function getCssFiles() {
  210. return $this->cssFiles;
  211. }
  212. public function getScriptFiles() {
  213. return $this->scriptFiles;
  214. }
  215. public function getTitlePrefix() {
  216. return $this->titleprefix;
  217. }
  218. public function getTitle() {
  219. return $this->title;
  220. }
  221. public function getTitleSuffix() {
  222. return $this->titlesuffix;
  223. }
  224. public function getFullTitle() {
  225. $elements = array();
  226. if ($this->titleprefix) {
  227. $elements[] = $this->titleprefix;
  228. }
  229. if ($this->title) {
  230. $elements[] = $this->title;
  231. }
  232. if ($this->titlesuffix) {
  233. $elements[] = $this->titlesuffix;
  234. }
  235. return implode($this->titleSeparator, $elements);
  236. }
  237. public function getContent() {
  238. return $this->content;
  239. }
  240. /**
  241. * Megjeleníti az oldal fejlécét a megadott beállításokkal
  242. */
  243. public function display() {
  244. if (UniAdmin::app()->isAjax()) {
  245. $page = false;
  246. UniAdmin::app()->config['layout'] = 'ajax';
  247. } else if (isset(UniAdmin::app()->config['page'])) {
  248. $page = UniAdmin::app()->config['page'];
  249. } else {
  250. $page = 'page';
  251. }
  252. if (!$this->description) {
  253. $this->description = WebsiteInfo::get('metaDescription');
  254. }
  255. if (!$this->keywords) {
  256. $this->keywords = WebsiteInfo::get('metaKeywords');
  257. }
  258. if (!$this->ga) {
  259. $this->ga = WebsiteInfo::get('gaTracker');
  260. }
  261. if (!$this->favicon) {
  262. $this->favicon = WebsiteInfo::get('favicon');
  263. }
  264. if ($page) {
  265. if (file_exists('views/' . $page . '.php')) {
  266. if (DEBUG_MODE) {
  267. UniAdmin::addDebugInfo('loading page file: ' . $page, 'page');
  268. }
  269. ob_start();
  270. include('views/' . $page . '.php');
  271. $this->content = ob_get_clean();
  272. } else {
  273. if (DEBUG_MODE) {
  274. UniAdmin::addDebugInfo('error loading page file: ' . $page, 'page', 3, __FILE__, __LINE__);
  275. }
  276. }
  277. } else {
  278. ob_start();
  279. UniAdmin::app()->render();
  280. $this->content = ob_get_clean();
  281. }
  282. UniAdmin::app()->dispatchEvent('application', 'afterRender');
  283. if (strpos(UniAdmin::app()->config['layout'], '.') !== false) {
  284. $path = str_replace('.', '/', UniAdmin::app()->config['layout']) . '.php';
  285. } else {
  286. $path = 'views/' . UniAdmin::app()->config['layout'] . '.php';
  287. }
  288. if (file_exists($path)) {
  289. $bufferContents = ob_get_clean();
  290. ob_start('ob_gzhandler');
  291. echo $bufferContents;
  292. include($path);
  293. } else {
  294. if (DEBUG_MODE) {
  295. UniAdmin::addDebugInfo('error loading layout ' . $path, 'page', 3, __FILE__, __LINE__);
  296. }
  297. }
  298. }
  299. }