PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_jacc/views/jacc/view.text.php

https://gitlab.com/hscomp2002/edmansport
PHP | 321 lines | 185 code | 77 blank | 59 comment | 27 complexity | 2dd2bd64687d7bd5614d315c4e770747 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: view.text.php 168 2013-11-12 16:14:31Z michel $
  4. * @package Jacc
  5. * @subpackage Views
  6. * @copyright Copyright (C) 2010, mliebler. All rights reserved.
  7. * @license #http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  8. */
  9. //--No direct access
  10. defined('_JEXEC') or die('=;)');
  11. jimport( 'joomla.application.component.view');
  12. class JaccViewJacc extends JViewLegacy
  13. {
  14. private $uses_categories = false;
  15. private $hasOrdering = false;
  16. private $hasCheckin = false;
  17. private $defaultOrderField = false;
  18. private $publishedField = false;
  19. private $hasAliasField = false;
  20. private $fieldlist = array();
  21. private $listfieldlist = array();
  22. private $parsedFields = array();
  23. private $searchableFields = array();
  24. private $hident = null;
  25. private $curtable = null;
  26. private $category_field = null;
  27. /**
  28. * componenthelp view display method
  29. *
  30. * @return void
  31. **/
  32. public function display($tpl = null)
  33. {
  34. $this->addTemplatePath(JPATH_COMPONENT.'/templates/mvctriple');
  35. $db = JFactory::getDBO();
  36. $config = JFactory::getConfig();
  37. $dbprefix = version_compare(JVERSION,'3.0','lt') ? $config->getValue('config.dbprefix') : $config->get('dbprefix');
  38. $model= $this->getModel();
  39. //get the Component to create
  40. $item= $this->get('Item');
  41. //Get Table and Template
  42. $mvcTable = $this->get('MvcTable');
  43. if($this->curtable != $mvcTable) {
  44. $this->hasOrdering;
  45. $this->category_field = "";
  46. $this->uses_categories = false;
  47. $this->hasCheckin = false;
  48. $this->defaultOrderField = false;
  49. $this->publishedField = false;
  50. $this->hasAliasField = false;
  51. $this->fieldlist = array();
  52. $this->listfieldlist = array();
  53. $this->parsedFields = array();
  54. $this->searchableFields = array();
  55. $this->hident = null;
  56. $this->curtable = $mvcTable;
  57. }
  58. $this->category_field = $model->TableHas($this->curtable,'category');
  59. $this->uses_categories = ($this->category_field && $item->params->get('uses_categories'));
  60. $mvcTemplate = $this->get('MvcTemplate');
  61. $mvcType = $this->get('MvcElementtype');
  62. //init the strings that replaces the fields and fieldslist pattern
  63. $freplace = "\n";
  64. $fdetailsreplace = "\n";
  65. $fparamsreplace = "\n";
  66. $fdescreplace = "\n";
  67. $fsubdescreplace = "\n";
  68. $flistreplace = "\n";
  69. $time = $item->created;
  70. $tableFields = $model->getTableFields($mvcTable);
  71. $this->parsedFields = array();
  72. $allfields = $tableFields->get('all');
  73. if(!count($this->fieldlist)) {
  74. $fieldlist = $allfields;
  75. foreach($fieldlist as $field) {
  76. $this->fieldlist[] = $field->get('key');
  77. }
  78. $listfieldlist = $tableFields->get('list');
  79. foreach($listfieldlist as $field) {
  80. $this->listfieldlist[] = $field->get('key');
  81. }
  82. $this->listfieldlist = array_unique($this->listfieldlist);
  83. }
  84. $hidentField = $allfields['hident'];
  85. $this->hident = $hidentField->get('key');
  86. $primaryField = $allfields['primary'];
  87. $this->primary = $primaryField->get('key');
  88. $this->parsedFields = $tableFields->get('all');
  89. $this->searchableFields = $tableFields->get('searchable');
  90. switch($mvcType) {
  91. case 'table':
  92. $this->parsedFields = $tableFields->get('all');
  93. break;
  94. case 'tmplfrontend':
  95. $this->parsedFields = $tableFields->get('list');
  96. break;
  97. case 'adminform' :
  98. $this->formfield = $tableFields->get('groups');
  99. break;
  100. case 'xmlmodel' :
  101. $this->formfield = $tableFields->get('all');
  102. break;
  103. case 'templ' :
  104. $this->parsedFields = $tableFields->get('list');
  105. break;
  106. default:
  107. $freplace .='';
  108. }
  109. foreach ($this->parsedFields as $field) {
  110. $this->field = $field;
  111. if ($field->get('key') == 'ordering') {
  112. $this->hasOrdering = true;
  113. $this->defaultOrderField = 'ordering';
  114. }
  115. if (($field->get('key') == 'created' || $field->get('key') == 'created_time' ) && empty($this->defaultOrderField)) {
  116. $this->defaultOrderField = $field->get('key');
  117. }
  118. if ($field->get('key') == 'checked_out') {
  119. $this->hasCheckin = true;
  120. }
  121. if ($field->get('key') == 'alias') {
  122. $this->hasAliasField = true;
  123. }
  124. if ($field->get('key') == 'published' || $field->get('key') == 'state') {
  125. $this->publishedField = $field->get('key');
  126. }
  127. /**
  128. switch($mvcTemplate) {
  129. case 'table':
  130. if (!$field->get('additional')) {
  131. $prim = $field->get('prim', false) ? '- Primary Key' : '';
  132. $default = $field->get('default') ? '"'.$field->get('default').'"' : 'null' ;
  133. }
  134. break;
  135. case 'tmplfrontend' :
  136. $freplace .= $this->replace_field($field, 'tmplfrontendrow');
  137. break;
  138. case 'templ' :
  139. $freplace .= $this->replace_field($field, 'templhead');
  140. if ($field->get('key') == 'ordering') {
  141. $flistreplace.= $this->loadTemplate('templordering');
  142. } elseif ($field->get('key') == $this->hident) {
  143. $flistreplace .= $this->replace_field($field, 'templlist_hident');
  144. } else {
  145. $flistreplace .= $this->replace_field($field, 'templlist');
  146. }
  147. break;
  148. default:$freplace .='';
  149. }
  150. **/
  151. }
  152. if(empty($this->defaultOrderField)) {
  153. $this->defaultOrderField = $this->hident;
  154. }
  155. $com_component = $item->name;
  156. $date = JFactory::getDate();
  157. //Component Name as first part of camel case class names
  158. $ComponentName = ucfirst(strtolower(str_replace('com_', '', $com_component)));
  159. //Replace the patterns
  160. $file = $this->loadTemplate($mvcTemplate);
  161. $file = str_replace("##Component##", $ComponentName, $file);
  162. $file = str_replace("##COMPONENT##", strtoupper($ComponentName), $file);
  163. $file = str_replace("##date##", $date->format('Y-m-d H:i:s'), $file);
  164. $file = str_replace("##com_component##", $com_component, $file);
  165. $file = str_replace("##title##", $this->hident, $file);
  166. $file = str_replace("##Name##", ucfirst($this->get('ItemSingular')), $file);
  167. $file = str_replace("##name##", strtolower($this->get('ItemSingular')), $file);
  168. $file = str_replace("##Plural##", ucfirst( $this->get('ItemPlural')), $file);
  169. $file = str_replace("##plural##", strtolower($this->get('ItemPlural')), $file);
  170. $file = str_replace("##primary##", $this->primary, $file);
  171. $file = str_replace("##time##", $time, $file);
  172. $file = str_replace("##codestart##", '<?php', $file);
  173. $file = str_replace("##codeend##", '?>', $file);
  174. $file = str_replace("##table##", $mvcTable, $file);
  175. //remove unneeded code parts
  176. $deleteList = $tableFields->get('delete');
  177. foreach ($deleteList as $field) {
  178. $pattern = '/##ifdefField'.$field.'Start##.*##ifdefField'.$field.'End##/isU';
  179. $file = preg_replace($pattern, '', $file);
  180. }
  181. $pattern = '/##ifnotdefField'.$field.'Start##.*##ifnotdefField'.$field.'End##/isU';
  182. $allFields = $tableFields->get('all');
  183. foreach ($allFields as $field) {
  184. $pattern = '/##ifnotdefField'.$field->get('key').'Start##.*##ifnotdefField'.$field->get('key').'End##/isU';
  185. $file = preg_replace($pattern, '', $file);
  186. }
  187. $pattern = '/\s+##ifdefField.*[Start|End]##+?/isU';
  188. $file = preg_replace($pattern, '', $file);
  189. $pattern = '/\s+##ifnotdefField.*[Start|End]##+?/isU';
  190. $file = preg_replace($pattern, '', $file);
  191. $file = str_replace("\n\r", "\n", $file);
  192. if (JRequest::getVar('mode') == 'return') {
  193. return $file;
  194. }
  195. while (@ob_end_clean());
  196. //Begin writing headers
  197. header("Cache-Control: max-age=60");
  198. header("Cache-Control: private");
  199. header("Content-Description: File Transfer");
  200. //Use the switch-generated Content-Type
  201. header("Content-Type: text/plain");
  202. //Force the download
  203. header("Content-Disposition: attachment; filename=\"".strtolower(JRequest::getVar('name')).".php\"");
  204. header("Content-Transfer-Encoding: binary");
  205. print $file;
  206. }
  207. /**
  208. * costum loadTempate method
  209. */
  210. public function loadTemplate($tpl) {
  211. $path = JPATH_COMPONENT_ADMINISTRATOR.'/templates/'.$tpl;
  212. $altpath = JPATH_COMPONENT_ADMINISTRATOR.'/usertemplates/'.$tpl;
  213. $this->_template = JFile::exists($altpath) ? $altpath : $path;
  214. if (!JFile::exists($this->_template)) $this->_template = false;
  215. if ($this->_template != false)
  216. {
  217. // Never allow a 'this' property
  218. if (isset($this->this))
  219. {
  220. unset($this->this);
  221. }
  222. // Start capturing output into a buffer
  223. ob_start();
  224. // Include the requested template filename in the local scope
  225. // (this will execute the view logic).
  226. include $this->_template;
  227. // Done with the requested template; get the buffer and
  228. // clear it.
  229. $this->_output = ob_get_contents();
  230. ob_end_clean();
  231. return $this->_output;
  232. }
  233. else
  234. {
  235. echo $path."<br />";
  236. echo JText::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $tpl); exit;
  237. throw new Exception(JText::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $tpl), 500);
  238. }
  239. }
  240. }// class