PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/concreteOLD/helpers/html.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 250 lines | 149 code | 37 blank | 64 comment | 56 complexity | 57343d8b4d15ed74a4cf1103a2329742 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Helpers
  4. * @category Concrete
  5. * @author Andrew Embler <andrew@concrete5.org>
  6. * @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
  7. * @license http://www.concrete5.org/license/ MIT License
  8. */
  9. /**
  10. * Functions to help with using HTML. Does not include form elements - those have their own helper.
  11. * @package Helpers
  12. * @category Concrete
  13. * @author Andrew Embler <andrew@concrete5.org>
  14. * @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
  15. * @license http://www.concrete5.org/license/ MIT License
  16. */
  17. defined('C5_EXECUTE') or die("Access Denied.");
  18. class HtmlHelper {
  19. protected $legacyJavascript = array(
  20. 'ccm.dialog.js' => 'ccm.app.js',
  21. 'jquery.metadata.js' => 'ccm.app.js',
  22. 'ccm.themes.js' => 'ccm.app.js',
  23. 'ccm.filemanager.js' => 'ccm.app.js',
  24. /*'jquery.rating.js' => 'ccm.app.js',*/
  25. 'jquery.colorpicker.js' => 'ccm.app.js',
  26. 'jquery.liveupdate.js' => 'ccm.app.js',
  27. 'ccm.ui.js' => 'ccm.app.js',
  28. 'ccm.search.js' => 'ccm.app.js'
  29. );
  30. protected $legacyCSS = array(
  31. 'ccm.dialog.css' => 'ccm.app.css',
  32. 'ccm.ui.css' => 'ccm.app.css',
  33. 'ccm.forms.css' => 'ccm.app.css',
  34. 'ccm.menus.css' => 'ccm.app.css',
  35. 'ccm.search.css' => 'ccm.app.css',
  36. 'ccm.filemanager.css' => 'ccm.app.css',
  37. 'ccm.calendar.css' => 'ccm.app.css'
  38. );
  39. /**
  40. * Includes a CSS file. This function looks in several places.
  41. * First, if the item is either a path or a URL it just returns the link to that item (as XHTML-formatted style tag.)
  42. * Then it checks the currently active theme, then if a package is specified it checks there. Otherwise if nothing is found it
  43. * fires off a request to the relative directory CSS directory. If nothing is there, then it checks to the assets directories
  44. * @param $file
  45. * @return $str
  46. */
  47. public function css($file, $pkgHandle = null) {
  48. $css = new CSSOutputObject();
  49. // if the first character is a / then that means we just go right through, it's a direct path
  50. if (substr($file, 0, 1) == '/' || substr($file, 0, 4) == 'http' || strpos($file, DISPATCHER_FILENAME) > -1) {
  51. $css->compress = false;
  52. $css->file = $file;
  53. }
  54. $v = View::getInstance();
  55. // checking the theme directory for it. It's just in the root.
  56. if ($v->getThemeDirectory() != '' && file_exists($v->getThemeDirectory() . '/' . $file)) {
  57. $css->file = $v->getThemePath() . '/' . $file;
  58. } else if (file_exists(DIR_BASE . '/' . DIRNAME_CSS . '/' . $file)) {
  59. $css->file = DIR_REL . '/' . DIRNAME_CSS . '/' . $file;
  60. } else if ($pkgHandle != null) {
  61. if (file_exists(DIR_BASE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file)) {
  62. $css->file = DIR_REL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file;
  63. } else if (file_exists(DIR_BASE_CORE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file)) {
  64. $css->file = ASSETS_URL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file;
  65. }
  66. }
  67. if ($css->file == '') {
  68. if (isset($this->legacyCSS[$file])) {
  69. $file = $this->legacyCSS[$file];
  70. }
  71. $css->file = ASSETS_URL_CSS . '/' . $file;
  72. }
  73. $css->file .= (strpos($css->file, '?') > -1) ? '&amp;' : '?';
  74. $css->file .= 'v=' . md5(APP_VERSION . PASSWORD_SALT);
  75. // for the javascript addHeaderItem we need to have a full href available
  76. $css->href = $css->file;
  77. if (substr($css->file, 0, 4) != 'http') {
  78. $css->href = BASE_URL . $css->file;
  79. }
  80. return $css;
  81. }
  82. /**
  83. * Includes a JavaScript file. This function looks in several places.
  84. * First, if the item is either a path or a URL it just returns the link to that item (as XHTML-formatted script tag.)
  85. * If a package is specified it checks there. Otherwise if nothing is found it
  86. * fires off a request to the relative directory JavaScript directory.
  87. * @param $file
  88. * @return $str
  89. */
  90. public function javascript($file, $pkgHandle = null) {
  91. $js = new JavaScriptOutputObject();
  92. if (substr($file, 0, 1) == '/' || substr($file, 0, 4) == 'http' || strpos($file, DISPATCHER_FILENAME) > -1) {
  93. $js->compress = false;
  94. $js->file = $file;
  95. }
  96. if (file_exists(DIR_BASE . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
  97. $js->file = DIR_REL . '/' . DIRNAME_JAVASCRIPT . '/' . $file;
  98. } else if ($pkgHandle != null) {
  99. if (file_exists(DIR_BASE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
  100. $js->file = DIR_REL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file;
  101. } else if (file_exists(DIR_BASE_CORE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
  102. $js->file = ASSETS_URL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/'. $file;
  103. }
  104. }
  105. if ($js->file == '') {
  106. if (isset($this->legacyJavascript[$file])) {
  107. $file = $this->legacyJavascript[$file];
  108. }
  109. $js->file = ASSETS_URL_JAVASCRIPT . '/' . $file;
  110. }
  111. $js->file .= (strpos($js->file, '?') > -1) ? '&amp;' : '?';
  112. $js->file .= 'v=' . md5(APP_VERSION . PASSWORD_SALT);
  113. // for the javascript addHeaderItem we need to have a full href available
  114. $js->href = $js->file;
  115. return $js;
  116. }
  117. /**
  118. * Includes a JavaScript inline script.
  119. * @param string $script
  120. * @return string $str
  121. */
  122. public function script($script) {
  123. $js = new InlineScriptOutputObject();
  124. $js->script = $script;
  125. return $js;
  126. }
  127. /**
  128. * Includes an image file when given a src, width and height. Optional attribs array specifies style, other properties.
  129. * First checks the PATH off the root of the site
  130. * Then checks the PATH off the images directory at the root of the site.
  131. * @param string $src
  132. * @param int $width
  133. * @param int $height
  134. * @param array $attribs
  135. * @return string $html
  136. */
  137. public function image($src, $width = false, $height = false, $attribs = null) {
  138. $image = parse_url($src);
  139. $attribsStr = '';
  140. if (is_array($width) && $height == false) {
  141. $attribs = $width;
  142. $width = false;
  143. }
  144. if (is_array($attribs)) {
  145. foreach($attribs as $key => $at) {
  146. $attribsStr .= " {$key}=\"{$at}\" ";
  147. }
  148. }
  149. if ($width == false && $height == false && (!isset($image['scheme']))) {
  150. // if our file is not local we DON'T do getimagesize() on it. too slow
  151. $v = View::getInstance();
  152. if ($v->getThemeDirectory() != '' && file_exists($v->getThemeDirectory() . '/' . DIRNAME_IMAGES . '/' . $src)) {
  153. $s = getimagesize($v->getThemeDirectory() . '/' . DIRNAME_IMAGES . '/' . $src);
  154. $width = $s[0];
  155. $height = $s[1];
  156. $src = $v->getThemePath() . '/' . DIRNAME_IMAGES . '/' . $src;
  157. } else if (file_exists(DIR_BASE . '/' . $src)) {
  158. $s = getimagesize(DIR_BASE . '/' . $src);
  159. $width = $s[0];
  160. $height = $s[1];
  161. } else if (file_exists(DIR_BASE . '/' . DIRNAME_IMAGES . '/' . $src)) {
  162. $s = getimagesize(DIR_BASE . '/' . DIRNAME_IMAGES . '/' . $src);
  163. $width = $s[0];
  164. $height = $s[1];
  165. $src = DIR_REL . '/' . DIRNAME_IMAGES . '/' . $src;
  166. } else if (file_exists(DIR_BASE_CORE . '/' . DIRNAME_IMAGES . '/' . $src)) {
  167. $s = getimagesize(DIR_BASE_CORE . '/' . DIRNAME_IMAGES . '/' . $src);
  168. $width = $s[0];
  169. $height = $s[1];
  170. $src = ASSETS_URL_IMAGES . '/' . $src;
  171. }
  172. }
  173. if ($width > 0) {
  174. $str = '<img src="' . $src . '" width="' . $width . '" border="0" height="' . $height . '" ' . $attribsStr . ' />';
  175. } else {
  176. $str = '<img src="' . $src . '" border="0" ' . $attribsStr . ' />';
  177. }
  178. return $str;
  179. }
  180. }
  181. /**
  182. * @access private
  183. */
  184. class HeaderOutputObject {
  185. public $file = '';
  186. public $href = '';
  187. public $script = '';
  188. public $compress = true;
  189. }
  190. /**
  191. * @access private
  192. */
  193. class JavaScriptOutputObject extends HeaderOutputObject {
  194. public function __toString() {
  195. return '<script type="text/javascript" src="' . $this->file . '"></script>';
  196. }
  197. }
  198. /**
  199. * @access private
  200. */
  201. class InlineScriptOutputObject extends HeaderOutputObject {
  202. public function __toString() {
  203. return '<script type="text/javascript">/*<![CDATA[*/'. $this->script .'/*]]>*/</script>';
  204. }
  205. }
  206. /**
  207. * @access private
  208. */
  209. class CSSOutputObject extends HeaderOutputObject {
  210. public function __toString() {
  211. return '<link rel="stylesheet" type="text/css" href="' . $this->file . '" />';
  212. }
  213. }