PageRenderTime 231ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/nonus/framework/createit/ctFrontendOptionsHandler.class.php

https://github.com/alniko009/magic
PHP | 109 lines | 62 code | 19 blank | 28 comment | 10 complexity | 94b9c457e6c59b5d40bd197fddd972fb MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Frontend options handler
  4. * @author alex
  5. */
  6. class ctFrontendOptionsHandler {
  7. /**
  8. * Creates admin handler
  9. */
  10. public function __construct() {
  11. }
  12. /**
  13. * Inits events
  14. */
  15. public function init() {
  16. add_action('wp_head', array($this, 'handleFaviconOption'));
  17. add_action('wp_head', array($this, 'handleAppleTouchOption'));
  18. add_action('wp_head', array($this, 'handleCustomCss'));
  19. add_action('wp_head', array($this, 'handleCustomJS'));
  20. add_action('wp_head', array($this, 'handleGoogleWebfonts'), 1);
  21. add_action('wp_head', array($this, 'handleGoogleAnalytics'));
  22. }
  23. /**
  24. * Adds google stylesheet
  25. */
  26. function handleGoogleWebfonts() {
  27. if ($f = ct_get_option('style_font_style')) {
  28. $font = explode(':', $f);
  29. if (isset($font[1])) {
  30. wp_enqueue_style('google.webfont', 'http://fonts.googleapis.com/css?subset=latin,latin-ext&family=' . str_replace(' ', '+', $font[0]));
  31. }
  32. }
  33. }
  34. /**
  35. * Generates favicon icon
  36. */
  37. function handleFaviconOption() {
  38. if ($f = ct_get_option('general_favicon')) {
  39. echo '<link rel="shortcut icon" href="' . esc_url($f) . '" />';
  40. }
  41. }
  42. /**
  43. * Generates apple touch icon
  44. */
  45. function handleAppleTouchOption() {
  46. if ($f = ct_get_option('general_apple_touch_icon')) {
  47. echo '<link rel="apple-touch-icon" href="' . esc_url($f) . '" />';
  48. }
  49. }
  50. /**
  51. * Includes user css + css from general settings
  52. */
  53. function handleCustomCss() {
  54. ctThemeLoader::getFilesLoader()->includeIt(CT_THEME_SETTINGS_MAIN_DIR . '/custom_style.php');
  55. }
  56. /**
  57. * Custom JS
  58. */
  59. function handleCustomJS() {
  60. if ($e = ct_get_option('code_custom_styles_js')) {
  61. $hasTag = stripos($e, '<script') !== false;
  62. if (!$hasTag) {
  63. echo '<script type="text/javascript">';
  64. }
  65. echo $e . "\n";
  66. if (!$hasTag) {
  67. echo '</script>';
  68. }
  69. }
  70. }
  71. /**
  72. * Adds Google Analytics
  73. */
  74. function handleGoogleAnalytics() {
  75. if ($num = ct_get_option('code_google_analytics_account')) {
  76. echo '<script type="text/javascript">';
  77. echo <<<EOF
  78. var _gaq = _gaq || [];
  79. _gaq.push(['_setAccount', '{$num}']);
  80. _gaq.push(['_trackPageview']);
  81. (function() {
  82. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  83. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  84. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  85. })();
  86. EOF;
  87. echo '</script>';
  88. }
  89. }
  90. }