PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/joomla/meta/customization/rt_quasar_j15/lib/gantry/core/gantrytemplatedetails.class.php

http://sewebar-cms.googlecode.com/
PHP | 197 lines | 156 code | 20 blank | 21 comment | 35 complexity | 2ef4abe6ce17253b98e4a6b1f6337dc7 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * @package gantry
  4. * @subpackage core
  5. * @version 2.0.12 February 12, 2010
  6. * @author RocketTheme http://www.rockettheme.com
  7. * @copyright Copyright (C) 2007 - 2010 RocketTheme, LLC
  8. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  9. *
  10. * Gantry uses the Joomla Framework (http://www.joomla.org), a GNU/GPLv2 content management system
  11. *
  12. */
  13. defined('JPATH_BASE') or die();
  14. jimport('joomla.error.profiler');
  15. /**
  16. * Populates the parameters and template configuration form the templateDetails.xml and params.ini
  17. *
  18. * @package gantry
  19. * @subpackage core
  20. */
  21. class GantryTemplateDetails {
  22. var $xml;
  23. var $positions = array ();
  24. var $params = array ();
  25. var $_pramas_ini;
  26. function GantryTemplateDetails() {
  27. }
  28. function init(&$gantry) {
  29. if (array_key_exists('gantry_profile', $_GET)){
  30. $profile = JProfiler::getInstance('GantryTemplateDetails->init()');
  31. $profile->mark('Start');
  32. }
  33. $this->xml = new JSimpleXML;
  34. if (array_key_exists('gantry_profile', $_GET)){
  35. $profile->mark('LoadFile Start');
  36. }
  37. $this->xml->loadFile($gantry->templatePath . '/templateDetails.xml');
  38. if (array_key_exists('gantry_profile', $_GET)){
  39. $profile->mark('LoadFile Stop');
  40. }
  41. $this->positions = & $this->_getPositions();
  42. $this->params = $this->_getParams($gantry);
  43. if (array_key_exists('gantry_profile', $_GET)){
  44. $profile->mark('Stop');
  45. var_dump($profile->getBuffer());
  46. }
  47. }
  48. function & _getPositions() {
  49. if (array_key_exists('gantry_profile', $_GET)){
  50. $profile = JProfiler::getInstance('GantryTemplateDetails->_getPositions()');
  51. $profile->mark('Start');
  52. }
  53. // positions
  54. $data = array ();
  55. $positions = $this->xml->document->positions[0]->children();
  56. foreach ($positions as $position) {
  57. array_push($data, $position->data());
  58. }
  59. if (array_key_exists('gantry_profile', $_GET)){
  60. $profile->mark('Stop');
  61. var_dump($profile->getBuffer());
  62. }
  63. return $data;
  64. }
  65. function &_getUniquePositions() {
  66. if (array_key_exists('gantry_profile', $_GET)){
  67. $profile = JProfiler::getInstance('GantryTemplateDetails->_getUniquePositions()');
  68. $profile->mark('Start');
  69. }
  70. // positions
  71. $data = array ();
  72. $positions = $this->xml->document->positions[0]->children();
  73. foreach ($positions as $position) {
  74. $name = $position->data();
  75. $name = preg_replace("/(\-a|\-b|\-c|\-d|\-e|\-f)$/i", "", $name);
  76. if (!in_array($name, $data)) array_push($data, $name);
  77. }
  78. if (array_key_exists('gantry_profile', $_GET)){
  79. $profile->mark('Stop');
  80. var_dump($profile->getBuffer());
  81. }
  82. return $data;
  83. }
  84. function parsePosition($position, $pattern) {
  85. if (null == $pattern) {
  86. $pattern = "(-)?";
  87. }
  88. $filtered_positions = array ();
  89. if (count($this->positions) > 0) {
  90. $regpat = "/^" . $position . $pattern . "/";
  91. foreach ($this->positions as $key => $value) {
  92. if (preg_match($regpat, $value) == 1) {
  93. $filtered_positions[] = $value;
  94. }
  95. }
  96. }
  97. return $filtered_positions;
  98. }
  99. function _getParams(&$gantry) {
  100. if (array_key_exists('gantry_profile', $_GET)){
  101. $profile = JProfiler::getInstance('GantryTemplateDetails->_getParams()');
  102. $profile->mark('Start');
  103. }
  104. $params_file = $gantry->templatePath.DS.'params.ini';
  105. $content="";
  106. $ingorables = array('spacer','gspacer','gantry');
  107. if (is_readable( $params_file ) )
  108. {
  109. $content = file_get_contents($params_file);
  110. $gantry->_base_params_checksum = md5($content);
  111. }
  112. $this->_pramas_ini = new JParameter($content);
  113. $data = array ();
  114. $params = $this->xml->document->params[0]->children();
  115. foreach ($params as $param) {
  116. //skip for unsupported types
  117. if (in_array($param->attributes('type'), $ingorables))
  118. continue;
  119. $this->_getParamInfo($gantry, $param, $data);
  120. }
  121. $this->params = $data;
  122. if (array_key_exists('gantry_profile', $_GET)){
  123. $profile->mark('Stop');
  124. var_dump($profile->getBuffer());
  125. }
  126. return $data;
  127. }
  128. function _getParamInfo(&$gantry, &$param, &$data, $prefix = ""){
  129. switch($param->attributes('type')){
  130. case 'groupedselection':
  131. $this->_decodeParamInfo($gantry, $param, $data, $prefix);
  132. // this should fall through and process children like chain and group
  133. case 'chain':
  134. case 'group':
  135. $prename = $prefix.$param->attributes('name')."-";
  136. foreach($param->children() as $subparam){
  137. $this->_getParamInfo($gantry, $subparam, $data, $prename);
  138. }
  139. break;
  140. default:
  141. $this->_decodeParamInfo($gantry, $param, $data, $prefix);
  142. break;
  143. }
  144. }
  145. function _decodeParamInfo(&$gantry, &$param, &$data, $prefix = ""){
  146. $attributes = $param->attributes();
  147. $data[$prefix.$attributes['name']] = array (
  148. 'name' => $prefix.$attributes['name'],
  149. 'type' => $attributes['type'],
  150. 'default' => (array_key_exists('default',$attributes))?$attributes['default']:false,
  151. 'value' => $this->_pramas_ini->get($prefix.$attributes['name'],(array_key_exists('default',$attributes))?$attributes['default']:false),
  152. 'sitebase' => $this->_pramas_ini->get($prefix.$attributes['name'],(array_key_exists('default',$attributes))?$attributes['default']:false),
  153. 'setbyurl' => (array_key_exists('setbyurl',$attributes))?($attributes['setbyurl'] == 'true')?true:false :false,
  154. 'setbycookie' => (array_key_exists('setbycookie',$attributes))?($attributes['setbycookie'] == 'true')?true:false :false,
  155. 'setbysession' => (array_key_exists('setbysession',$attributes))?($attributes['setbysession'] == 'true')?true:false :false,
  156. 'setincookie' => (array_key_exists('setbycookie',$attributes))?($attributes['setbycookie'] == 'true')?true:false :false,
  157. 'setinsession' => (array_key_exists('setinsession',$attributes))?($attributes['setinsession'] == 'true')?true:false :false,
  158. 'setinmenuitem' => (array_key_exists('setinmenuitem',$attributes))?($attributes['setinmenuitem'] == 'true')?true:false :true,
  159. 'setbymenuitem' => (array_key_exists('setbymenuitem',$attributes))?($attributes['setbymenuitem'] == 'true')?true:false :true,
  160. 'isbodyclass' => (array_key_exists('isbodyclass',$attributes))?($attributes['isbodyclass'] == 'true')?true:false :false,
  161. 'setby' => 'default'
  162. );
  163. if ($data[$prefix.$attributes['name']]['setbyurl']) $gantry->_setbyurl[] = $prefix.$attributes['name'];
  164. if ($data[$prefix.$attributes['name']]['setbysession']) $gantry->_setbysession[] = $prefix.$attributes['name'];
  165. if ($data[$prefix.$attributes['name']]['setbycookie']) $gantry->_setbycookie[] = $prefix.$attributes['name'];
  166. if ($data[$prefix.$attributes['name']]['setinsession']) $gantry->_setinsession[] = $prefix.$attributes['name'];
  167. if ($data[$prefix.$attributes['name']]['setincookie']) $gantry->_setincookie[] = $prefix.$attributes['name'];
  168. if ($data[$prefix.$attributes['name']]['setinmenuitem']) {
  169. $gantry->_setinmenuitem[] = $prefix.$attributes['name'];
  170. }
  171. else {
  172. $gantry->dontsetinmenuitem[] = $prefix.$attributes['name'];
  173. }
  174. if ($data[$prefix.$attributes['name']]['setbymenuitem']) $gantry->_setbymenuitem[] = $prefix.$attributes['name'];
  175. if ($data[$prefix.$attributes['name']]['isbodyclass']) $gantry->_bodyclasses[] = $prefix.$attributes['name'];
  176. }
  177. }