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

/administrator/components/com_acesef/extensions/com_contact.php

https://github.com/Shigaru/shigaru
PHP | 247 lines | 187 code | 49 blank | 11 comment | 49 complexity | 6042163efad7d66be02ba73cc57fef41 MD5 | raw file
  1. <?php
  2. /*
  3. * @package AceSEF
  4. * @subpackage Contact
  5. * @copyright 2009-2012 JoomAce LLC, www.joomace.net
  6. * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
  7. */
  8. // No Permission
  9. defined('_JEXEC') or die('Restricted access');
  10. class AceSEF_com_contact extends AcesefExtension {
  11. function beforeBuild(&$uri) {
  12. if (is_null($uri->getVar('view')) && (!is_null($uri->getVar('id')) || !is_null($uri->getVar('catid')))) {
  13. $uri->setVar('view', 'category');
  14. }
  15. /*if (!is_null($uri->getVar('view')) && $uri->getVar('view') == 'category' && !is_null($uri->getVar('id'))) {
  16. $uri->setVar('catid', $uri->getVar('id'));
  17. $uri->delVar('id');
  18. }*/
  19. }
  20. function catParam($vars, $real_url) {
  21. extract($vars);
  22. if (isset($view)) {
  23. switch($view) {
  24. case 'category':
  25. if (!empty($catid)) {
  26. parent::categoryParams($catid, 1, $real_url);
  27. }
  28. break;
  29. case 'contact':
  30. if (!empty($id)) {
  31. $catid = self::_getItemCatId(intval($id));
  32. if (!empty($catid)) {
  33. parent::categoryParams($catid, 0, $real_url);
  34. }
  35. }
  36. break;
  37. }
  38. }
  39. }
  40. function _getItemCatId($id) {
  41. static $cache = array();
  42. if (!isset($cache[$id])) {
  43. if ($this->AcesefConfig->cache_instant == 1) {
  44. $rows = AceDatabase::loadRowList("SELECT id, catid FROM #__contact_details");
  45. foreach ($rows as $row) {
  46. $cache[$row[0]] = $row[1];
  47. }
  48. } else {
  49. $cache[$id] = AceDatabase::loadResult("SELECT catid FROM #__contact_details WHERE id = {$id}");
  50. }
  51. }
  52. if (!isset($cache[$id])) {
  53. $cache[$id] = "";
  54. }
  55. return $cache[$id];
  56. }
  57. function build(&$vars, &$segments, &$do_sef, &$metadata, &$item_limitstart) {
  58. extract($vars);
  59. if (isset($view)) {
  60. switch($view) {
  61. case 'category':
  62. case 'categories':
  63. if (isset($catid)) {
  64. $segments = array_merge($segments, self::_getCategory(intval($catid)));
  65. unset($vars['catid']);
  66. }
  67. elseif (isset($id)) {
  68. $segments = array_merge($segments, self::_getCategory(intval($id)));
  69. unset($vars['id']);
  70. }
  71. break;
  72. case 'contact':
  73. if (isset($id)) {
  74. $segments = array_merge($segments, self::_getContact(intval($id)));
  75. unset($vars['id']);
  76. unset($vars['catid']);
  77. }
  78. break;
  79. default:
  80. $segments[] = $view;
  81. break;
  82. }
  83. unset($vars['view']);
  84. }
  85. $metadata = parent::getMetaData($vars, $item_limitstart);
  86. unset($vars['limit']);
  87. unset($vars['limitstart']);
  88. }
  89. function _getCategory($id) {
  90. if (self::_is16()) {
  91. return self::_getCategory16($id);
  92. }
  93. static $cache = array();
  94. if (!isset($cache[$id])) {
  95. $joomfish = $this->AcesefConfig->joomfish_trans_url ? ', id' : '';
  96. $row = AceDatabase::loadRow("SELECT title, alias, description{$joomfish} FROM #__categories WHERE id = ".$id);
  97. $name = (($this->params->get('categoryid_inc', '1') != '1') ? $id.' ' : '');
  98. if (parent::urlPart($this->params->get('category_part', 'global')) == 'title') {
  99. $name .= $row[0];
  100. } else {
  101. $name .= $row[1];
  102. }
  103. $cache[$id]['name'] = array($name);
  104. $cache[$id]['meta_title'] = $row[0];
  105. $cache[$id]['meta_desc'] = $row[2];
  106. }
  107. $this->meta_title[] = $cache[$id]['meta_title'];
  108. $this->meta_desc = $cache[$id]['meta_desc'];
  109. return $cache[$id]['name'];
  110. }
  111. function _getCategory16($id) {
  112. $cats = $this->params->get('category_inc', '1');
  113. if ($cats == '1') {
  114. return array();
  115. }
  116. static $cache = array();
  117. if (!isset($cache[$id])) {
  118. $joomfish = $this->AcesefConfig->joomfish_trans_url ? ', id' : '';
  119. $categories = array();
  120. $cat_title = array();
  121. $cat_desc = array();
  122. while ($id > 1 && $id != 4 && $id != 11) {
  123. $row = AceDatabase::loadObject("SELECT title, alias, parent_id, description{$joomfish} FROM #__categories WHERE id = '{$id}' AND extension = 'com_contact'");
  124. if (!is_object($row)) {
  125. break;
  126. }
  127. $name = (($this->params->get('categoryid_inc', '1') != '1') ? $id.' ' : '');
  128. if (parent::urlPart($this->params->get('category_part', 'global')) == 'title'){
  129. $name .= $row->title;
  130. } else {
  131. $name .= $row->alias;
  132. }
  133. array_unshift($categories, $name);
  134. $cat_title[] = $row->title;
  135. $cat_desc[] = $row->description;
  136. $id = $row->parent_id;
  137. if ($cats == '2'){
  138. break; // Only last cat
  139. }
  140. }
  141. $cache[$id]['name'] = $categories;
  142. $cache[$id]['meta_title'] = $cat_title;
  143. $cache[$id]['meta_desc'] = $cat_desc;
  144. }
  145. $this->meta_title = $cache[$id]['meta_title'];
  146. if (!empty($cache[$id]['meta_desc'])) {
  147. $this->meta_desc = $cache[$id]['meta_desc'][0];
  148. }
  149. return $cache[$id]['name'];
  150. }
  151. function _getContact($id) {
  152. static $cache = array();
  153. if (!isset($cache[$id])) {
  154. $joomfish = $this->AcesefConfig->joomfish_trans_url ? ', id' : '';
  155. $row = AceDatabase::loadRow("SELECT name, alias, catid{$joomfish} FROM #__contact_details WHERE id = ".$id);
  156. $name = (($this->params->get('contactid_inc', '1') != '1') ? $id.' ' : '');
  157. if (parent::urlPart($this->params->get('contact_part', 'global')) == 'title') {
  158. $name .= $row[0];
  159. } else {
  160. $name .= $row[1];
  161. }
  162. if ($this->params->get('category_inc', '1') == '1'){
  163. $cache[$id]['name'] = array($name);
  164. }
  165. else {
  166. $category = self::_getCategory($row[2]);
  167. array_push($category, $name);
  168. $cache[$id]['name'] = $category;
  169. }
  170. $cache[$id]['meta_title'] = $row[0];
  171. }
  172. array_unshift($this->meta_title, $cache[$id]['meta_title']);
  173. return $cache[$id]['name'];
  174. }
  175. function getCategoryList($query) {
  176. if (self::_is16()) {
  177. $field = 'extension';
  178. $value = 'com_contact';
  179. }
  180. else{
  181. $field = 'section';
  182. $value = 'com_contact_details';
  183. }
  184. $rows = AceDatabase::loadObjectList("SELECT id, title AS name FROM #__categories WHERE {$field} = '{$value}' ORDER BY title");
  185. return $rows;
  186. }
  187. function _is16() {
  188. static $status;
  189. if (!isset($status)) {
  190. if (version_compare(JVERSION,'1.6.0','ge')) {
  191. $status = true;
  192. } else {
  193. $status = false;
  194. }
  195. }
  196. return $status;
  197. }
  198. }