PageRenderTime 56ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/autotheme/EAutoTheme.php

http://phundament.googlecode.com/
PHP | 101 lines | 65 code | 11 blank | 25 comment | 12 complexity | 97e06f66c466166c994d55fa8a8bfc55 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Class File
  4. *
  5. * @author Tobias Munk <schmunk@usrbin.de>
  6. * @link http://www.phundament.com/
  7. * @copyright Copyright &copy; 2005-2010 diemeisterei GmbH
  8. * @license http://www.phundament.com/license/
  9. */
  10. /**
  11. * Widget, includes css and js files from theme directories
  12. *
  13. * Detailed info
  14. * <pre>
  15. * $var = code_example();
  16. * </pre>
  17. * {@link DefaultController}
  18. *
  19. * @author Tobias Munk <schmunk@usrbin.de>
  20. * @version $Id: EAutoTheme.php 508 2010-03-24 00:35:21Z schmunk $
  21. * @package extensions.autotheme
  22. * @since 2.0
  23. */
  24. class EAutoTheme extends CWidget
  25. {
  26. private $_themePath = null;
  27. private $_themeUrl = null;
  28. private $_themeCssDir = "css";
  29. private $_themeJsDir = "js";
  30. private $_themeImagesDir = "images";
  31. public function init()
  32. {
  33. if (isset($this->CssDir)) {
  34. $this->_themeCssDir = $this->CssDir;
  35. }
  36. if (isset($this->JsDir)) {
  37. $this->_themeJsDir = $this->JsDir;
  38. }
  39. if (Yii::app()->theme !== null){
  40. $this->_themePath = Yii::app()->themeManager->basePath.DS.Yii::app()->theme->name;
  41. $this->_themeUrl = Yii::app()->themeManager->baseUrl.'/'.Yii::app()->theme->name;
  42. }
  43. }
  44. public function run()
  45. {
  46. $cs = Yii::app()->getClientScript();
  47. $cssPath = $this->_themePath.DS.$this->_themeCssDir;
  48. Yii::trace("Scanning css and js folder in theme directory ".$this->_themePath." ...", "extensions.autotheme");
  49. if(is_dir($cssPath)){
  50. foreach (scandir($cssPath) AS $file){
  51. if ((substr($file,-3,3) == "css" && !is_file($cssPath.DS.$file.'.php')) || (substr($file,-7,7) == "css.php")){
  52. $cssLocation = $this->_themeUrl.'/'.$this->_themeCssDir.'/'.$file;
  53. $cs->registerCssFile($cssLocation);
  54. }
  55. }
  56. }
  57. $jsPath = $this->_themePath.DS.$this->_themeJsDir;
  58. if(is_dir($jsPath)){
  59. foreach (scandir($jsPath) AS $file){
  60. if (substr($file,-2,2) == "js"){
  61. $jsLocation = $this->_themeUrl.'/'.$this->_themeJsDir.'/'.$file;
  62. switch(strrchr(str_replace('.js','',$file),'.')) {
  63. case '.head':
  64. $cs->registerScriptFile($jsLocation, CClientScript::POS_HEAD);
  65. break;
  66. case '.load':
  67. $cs->registerScriptFile($jsLocation, CClientScript::POS_LOAD);
  68. break;
  69. case '.begin':
  70. $cs->registerScriptFile($jsLocation, CClientScript::POS_BEGIN);
  71. break;
  72. case '.ready':
  73. $cs->registerScriptFile($jsLocation, CClientScript::POS_READY);
  74. break;
  75. case '.end':
  76. $cs->registerScriptFile($jsLocation, CClientScript::POS_END);
  77. break;
  78. default:
  79. $cs->registerScriptFile($jsLocation);
  80. break;
  81. }
  82. }
  83. }
  84. }
  85. /*if(is_file($this->_themePath.DS.$this->_themeImagesDir).DS.'favicon.ico') {
  86. $cs->registerLinkTag('shortcut icon', 'image/x-icon', $this->_themeUrl.'/'.$this->_themeImagesDir.'/favicon.ico');
  87. }*/
  88. }
  89. }
  90. ?>