PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/system/helpers/fluid_helper.php

https://github.com/At-Team/Fluid_CI
PHP | 229 lines | 94 code | 45 blank | 90 comment | 17 complexity | 0d6b38e029f20a88e7a7b9ee8ad5f1ed MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * Fluid
  4. *
  5. *
  6. *
  7. * @package Fluid
  8. * @author Fluid creator
  9. * @copyright Copyright (c) 20013 , @Team.
  10. * @license
  11. * @link
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * Fluid System Helper
  18. *
  19. * @package Fluid
  20. * @subpackage Helpers
  21. * @category Helpers
  22. * @author Copyright
  23. * @link
  24. */
  25. // ------------------------------------------------------------------------
  26. /**
  27. * Creates a link to load the appropiate js
  28. *
  29. *
  30. *
  31. *
  32. * @access public
  33. * @param string
  34. * @return string
  35. */
  36. if ( ! function_exists('fluid_load_js'))
  37. {
  38. function fluid_load_js($filename = '',$self)
  39. {
  40. if ($filename == '') return '';
  41. $base_base = explode('/', BASEPATH ) ;
  42. //pop twice to get to base path
  43. array_pop($base_base);
  44. array_pop($base_base);
  45. $user_group_path = explode('/',$self->fluid->get_user_group());
  46. array_pop($user_group_path);
  47. $base = array_merge($base_base,$user_group_path);
  48. $file = false ;
  49. //search untill parent path untill the file is found..
  50. //concept of inheritence..
  51. //if an js or css library is not found in this group
  52. //search in parent to get hold of it..
  53. //if not found just print an error to usre saying
  54. //not found
  55. while(array_count_values($base) >= array_count_values($base_base) ){
  56. if (!file_exists( implode('/', $base) . '/' . $filename . '.js')){
  57. array_pop($base);
  58. array_pop($user_group_path);
  59. }else{
  60. $file = true ;
  61. break;
  62. }
  63. }//while
  64. //show_error(implode(' ** ', $_SERVER));
  65. if ($file){
  66. return '<script type="text/javascript" src="http://'. SITE_URL . implode('/', $user_group_path) . $filename . '.js"> </script>' ;
  67. }else{
  68. return '<!-- ' . $filename . '.js was not found in the group \'' . $self->fluid->get_user_group() . '\' nor in the inheritence tree. Please check its existence-->';
  69. }
  70. }
  71. }
  72. /**
  73. * Creates a link to load the appropiate css
  74. *
  75. *
  76. *
  77. *
  78. * @access public
  79. * @param string
  80. * @return string
  81. */
  82. if ( ! function_exists('fluid_load_css'))
  83. {
  84. function fluid_load_css($filename = '',$self,$media = 'screen')
  85. {
  86. if ($filename == '') return '';
  87. $base_base = explode('/', BASEPATH ) ;
  88. //pop twice to get to base path
  89. array_pop($base_base);
  90. array_pop($base_base);
  91. $user_group_path = explode('/',$self->fluid->get_user_group());
  92. array_pop($user_group_path);
  93. $base = array_merge($base_base,$user_group_path);
  94. $file = false ;
  95. //search untill parent path untill the file is found..
  96. //concept of inheritence..
  97. //if an js or css library is not found in this group
  98. //search in parent to get hold of it..
  99. //if not found just print an error to usre saying
  100. //not found
  101. while(array_count_values($base) >= array_count_values($base_base) ){
  102. if (!file_exists( implode('/', $base) . '/' . $filename . '.css')){
  103. array_pop($base);
  104. array_pop($user_group_path);
  105. }else{
  106. $file = true ;
  107. break;
  108. }
  109. }//while
  110. //show_error(implode(' ** ', $_SERVER));
  111. if ($file){
  112. return '<link href="http://'. SITE_URL . implode('/', $user_group_path) . $filename . '.css" media="'. $media .'" rel="stylesheet" type="text/css" />' ;
  113. }else{
  114. return '<!-- ' . $filename . '.css was not found in the group \'' . $self->fluid->get_user_group() . '\' nor in the inheritence tree. Please check its existence-->';
  115. }
  116. }
  117. }
  118. /**
  119. * Creates a link to load the appropiate css
  120. *
  121. *
  122. *
  123. *
  124. * @access public
  125. * @param string
  126. * @return string
  127. */
  128. if ( ! function_exists('fluid_load_image'))
  129. {
  130. function fluid_load_image($filename = '',$self,$htmlparams = "")
  131. {
  132. if ($filename == '') return '';
  133. $base_base = explode('/', BASEPATH ) ;
  134. //pop twice to get to base path
  135. array_pop($base_base);
  136. array_pop($base_base);
  137. $user_group_path = explode('/',$self->fluid->get_user_group());
  138. array_pop($user_group_path);
  139. $base = array_merge($base_base,$user_group_path);
  140. $file = false ;
  141. //search untill parent path untill the file is found..
  142. //concept of inheritence..
  143. //if an js or css library is not found in this group
  144. //search in parent to get hold of it..
  145. //if not found just print an error to usre saying
  146. //not found
  147. while(array_count_values($base) >= array_count_values($base_base) ){
  148. if (!file_exists( implode('/', $base) . '/' . $filename )){
  149. array_pop($base);
  150. array_pop($user_group_path);
  151. }else{
  152. $file = true ;
  153. break;
  154. }
  155. }//while
  156. //show_error(implode(' ** ', $_SERVER));
  157. if ($file){
  158. return '<img src="http://'. SITE_URL . implode('/', $user_group_path) . '/' . $filename . '"' . $htmlparams .'/>' ;
  159. }else{
  160. return '<!-- ' . $filename . ' was not found in the group \'' . $self->fluid->get_user_group() . '\' nor in the inheritence tree. Please check its existence-->';
  161. }
  162. }
  163. }
  164. // ------------------------------------------------------------------------
  165. /**
  166. * Base URL
  167. *
  168. * Create a local URL based on your basepath.
  169. * Segments can be passed in as a string or an array, same as site_url
  170. * or a URL to a file can be passed in, e.g. to an image file.
  171. *
  172. * @access public
  173. * @param string
  174. * @return string
  175. */
  176. if ( ! function_exists('base_url'))
  177. {
  178. function base_url($uri = '')
  179. {
  180. $CI =& get_instance();
  181. return $CI->config->base_url($uri);
  182. }
  183. }
  184. ?>