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

/Quản lý website tuyển dụng việc làm PHP/webcaoca/public_html/vlv/administrator/components/com_sh404sef/lib/extplugins/acesef/utility.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 357 lines | 262 code | 74 blank | 21 comment | 52 complexity | 2234fd69029dce1e99d398139cd240ae MD5 | raw file
  1. <?php
  2. /**
  3. * @version 1.5.0
  4. * @package AceSEF Library
  5. * @subpackage Utility
  6. * @copyright 2009-2010 JoomAce LLC, www.joomace.net
  7. * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
  8. */
  9. // No Permission
  10. defined('_JEXEC') or die('Restricted Access');
  11. // Imports
  12. jimport('joomla.filesystem.file');
  13. // Utility class
  14. class AcesefUtility {
  15. static $props = array();
  16. function __construct() {
  17. // Get config object
  18. $this->AcesefConfig = AcesefFactory::getConfig();
  19. }
  20. function import($path) {
  21. require_once(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_acesef' . DS . str_replace('.', '/', $path).'.php');
  22. }
  23. function render($path) {
  24. ob_start();
  25. require_once($path);
  26. $contents = ob_get_contents();
  27. ob_end_clean();
  28. return $contents;
  29. }
  30. function get($name, $default = null) {
  31. if (!is_array(self::$props) || !isset(self::$props[$name])) {
  32. return $default;
  33. }
  34. return self::$props[$name];
  35. }
  36. function set($name, $value) {
  37. if (!is_array(self::$props)) {
  38. self::$props = array();
  39. }
  40. $previous = self::get($name);
  41. self::$props[$name] = $value;
  42. return $previous;
  43. }
  44. function getConfigState($params, $cfg_name, $prm = "") {
  45. if (!is_object($params)) {
  46. return false;
  47. }
  48. $prm_name = $cfg_name;
  49. if ($prm != "") {
  50. $prm_name = $prm;
  51. }
  52. $param = $params->get($prm_name, 'global');
  53. if (($param == 'no') || ($param == 'global' && $this->AcesefConfig->$cfg_name == '0')) {
  54. return false;
  55. }
  56. return true;
  57. }
  58. function &getMenu() {
  59. jimport('joomla.application.menu');
  60. $options = array();
  61. $menu =& JMenu::getInstance('site', $options);
  62. if (JError::isError($menu)) {
  63. $null = null;
  64. return $null;
  65. }
  66. return $menu;
  67. }
  68. function getComponents() {
  69. static $components;
  70. if(!isset($components)) {
  71. $filter = "'com_sef', 'com_sh404sef', 'com_joomfish', 'com_config', 'com_media', 'com_installer', 'com_templates', 'com_plugins', 'com_modules', 'com_cpanel', 'com_cache', 'com_messages', 'com_menus', 'com_massmail', 'com_languages', 'com_users'";
  72. $rows = AceDatabase::loadObjectList("SELECT `name`, `option` FROM `#__components` WHERE `parent` = '0' AND `option` != '' AND `option` NOT IN ({$filter}) ORDER BY `name`");
  73. foreach($rows as $row) {
  74. $components[] = JHTML::_('select.option', $row->option, $row->name);
  75. }
  76. }
  77. return $components;
  78. }
  79. function getExtensionFromRequest() {
  80. static $extension;
  81. if (!isset($extension)) {
  82. $cid = JRequest::getVar('cid', array(0), 'method', 'array');
  83. $extension = AceDatabase::loadResult("SELECT extension FROM #__acesef_extensions WHERE id = ".$cid[0]);
  84. }
  85. return $extension;
  86. }
  87. function getOptionFromRealURL($url) {
  88. $url = str_replace('&amp;', '&', $url);
  89. $url = str_replace('index.php?', '', $url);
  90. parse_str($url, $vars);
  91. if (isset($vars['option'])) {
  92. return $vars['option'];
  93. } else {
  94. return '';
  95. }
  96. }
  97. // Get the list of languages
  98. function getLanguages() {
  99. static $languages;
  100. if(!isset($languages)) {
  101. $db =& JFactory::getDBO();
  102. $tables = $db->getTableList();
  103. $prefix = $db->getPrefix();
  104. $langs = $prefix."languages";
  105. if (in_array($langs, $tables)){
  106. // Get installed languages and add them to list
  107. $langs = AceDatabase::loadObjectList("SELECT `id`, `shortcode`, `name` FROM `#__languages` WHERE `active` = '1' ORDER BY `ordering`");
  108. if( @count(@$langs) ) {
  109. foreach($langs as $lang) {
  110. $l = new stdClass();
  111. $l->code = $lang->shortcode;
  112. $l->name = $lang->name;
  113. // Load languages
  114. $languages[] = JHTML::_('select.option', $l->code, $l->name);
  115. }
  116. }
  117. }
  118. }
  119. return $languages;
  120. }
  121. function replaceLoop($search, $replace, $text) {
  122. $count = 0;
  123. if (!is_string($text)) {
  124. return $text;
  125. }
  126. while ((strpos($text, $search) !== false) && ($count < 10)) {
  127. $text = str_replace($search, $replace, $text);
  128. $count++;
  129. }
  130. return $text;
  131. }
  132. function getSefStatus() {
  133. static $status;
  134. if (!isset($status)) {
  135. $JoomlaConfig =& JFactory::getConfig();
  136. $status = array();
  137. $status['version_checker'] = (bool)$this->AcesefConfig->version_checker;
  138. $status['php'] = (bool)version_compare(PHP_VERSION, '5.2.0', '>');
  139. $status['s_mod_rewrite'] = '';
  140. if (function_exists('apache_get_modules')) {
  141. $modules = apache_get_modules();
  142. $status['s_mod_rewrite'] = (bool)in_array('mod_rewrite', $modules);
  143. }
  144. $status['sef'] = (bool)$JoomlaConfig->getValue('sef');
  145. $status['mod_rewrite'] = (bool)$JoomlaConfig->getValue('sef_rewrite');
  146. $status['htaccess'] = false;
  147. if (file_exists(JPATH_ROOT.DS.'.htaccess')) {
  148. $filesize = filesize(JPATH_ROOT.DS.'.htaccess');
  149. $status['htaccess'] = (bool)($filesize > 2060);
  150. }
  151. $status['live_site'] = $JoomlaConfig->getValue('live_site');
  152. if (AcesefUtility::JoomFishInstalled()) {
  153. $status['jfrouter'] = JPluginHelper::isEnabled('system', 'jfrouter');
  154. }
  155. $status['acesef'] = (bool)$this->AcesefConfig->mode;
  156. $status['plugin'] = JPluginHelper::isEnabled('system', 'acesef');
  157. $status['generate_sef'] = (bool)$this->AcesefConfig->generate_sef;
  158. }
  159. return $status;
  160. }
  161. function JoomFishInstalled() {
  162. static $installed;
  163. if (!isset($installed)) {
  164. $installed = JFile::exists(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php');
  165. }
  166. return $installed;
  167. }
  168. function getParam($text, $param) {
  169. $params = new JParameter($text);
  170. return $params->get($param);
  171. }
  172. function storeParams($table, $id, $db_field, $new_params) {
  173. $row = AcesefFactory::getTable($table);
  174. if (!$row->load($id)) {
  175. return false;
  176. }
  177. $params = new JParameter($row->$db_field);
  178. foreach ($new_params as $name => $value) {
  179. $params->set($name, $value);
  180. }
  181. $row->$db_field = $params->toString();
  182. if (!$row->check()) {
  183. return false;
  184. }
  185. if (!$row->store()) {
  186. return false;
  187. }
  188. }
  189. // Clear texts from unwanted chars
  190. function cleanText($text) {
  191. $text = strip_tags($text);
  192. $text = preg_replace(array('/&amp;quot;/', '/&amp;nbsp;/', '/&amp;lt;/', '/&amp;gt;/', '/&amp;copy;/', '/&amp;amp;/', '/&amp;euro;/', '/&amp;hellip;/'), ' ', $text);
  193. $text = preg_replace(array('/&quot;/', '/&nbsp;/', '/&lt;/', '/&gt;/', '/&copy;/', '/&amp;/', '/&euro;/', '/&hellip;/'), ' ', $text);
  194. $text = preg_replace("'<script[^>]*>.*?</script>'si", ' ', $text);
  195. $text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text);
  196. $text = preg_replace('/<!--.+?-->/', ' ', $text);
  197. $text = preg_replace('/{.+?}/', ' ', $text);
  198. $text = preg_replace('(\{.*?\})', ' ', $text);
  199. $text = preg_replace('/\s\s+/', ' ', $text);
  200. $text = preg_replace('/\n\n+/s', ' ', $text);
  201. $text = preg_replace('/<[^<|^>]*>/u', ' ', $text);
  202. $text = preg_replace('/{[^}]*}[\s\S]*{[^}]*}/u', ' ', $text);
  203. $text = preg_replace('/{[^}]*}/u', ' ', $text);
  204. $text = trim($text);
  205. $text = str_replace(array('\r\n', '\r', '\n', '\t', '\n\n', '<', '>', ':', '#', '`', '”', '“', '¿', '\0', '\x0B', '"', '&quot;', '&quot'), ' ', $text);
  206. $text = preg_replace('/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', ' ', $text);
  207. while(strpos($text, ' ')) {
  208. $text = str_replace(' ', ' ', $text);
  209. }
  210. // Space
  211. $text = preg_replace('/\s/u', ' ', $text);
  212. // Special chars
  213. $text = self::replaceSpecialChars($text);
  214. $text = rtrim($text, "'");
  215. $text = rtrim($text, "\\");
  216. return $text;
  217. }
  218. // Replace some special chars
  219. function replaceSpecialChars($text, $reverse = false) {
  220. if (is_string($text)) {
  221. if (!$reverse) {
  222. $text = str_replace("\'", "'", $text);
  223. $text = addslashes($text);
  224. } else {
  225. $text = stripslashes($text);
  226. }
  227. }
  228. return $text;
  229. }
  230. // Get text from XML
  231. function getXmlText($file, $variable) {
  232. // Try to find variable
  233. $value = null;
  234. if (JFile::exists($file)) {
  235. $xml =& JFactory::getXMLParser('Simple');
  236. if ($xml->loadFile($file)) {
  237. $root =& $xml->document;
  238. $element =& $root->getElementByPath($variable);
  239. $value = $element ? $element->data() : '';
  240. }
  241. }
  242. return $value;
  243. }
  244. // Get Menu title
  245. function getMenuTitle($Itemid, $start_level = 0, $length_level = 0) {
  246. if (empty($Itemid)) {
  247. return array();
  248. }
  249. static $menus = array();
  250. $id = $Itemid;
  251. if (!isset($menus[$id])) {
  252. $joomfish = $this->AcesefConfig->joomfish_trans_url ? ', id' : '';
  253. // Title or Alias
  254. $part = 'name';
  255. if ($this->AcesefConfig->menu_url_part == 'alias') {
  256. $part = 'alias';
  257. }
  258. $menus[$id] = array();
  259. while ($Itemid > 0) {
  260. $row = AceDatabase::loadObject("SELECT $part AS name, parent$joomfish FROM #__menu WHERE id = '$Itemid' AND published > 0");
  261. if (is_null($row)) {
  262. break;
  263. }
  264. array_unshift($menus[$id], $row->name);
  265. $Itemid = $row->parent;
  266. if ($this->AcesefConfig->parent_menus == '0') {
  267. break; // Only last one
  268. }
  269. }
  270. }
  271. if ($this->AcesefConfig->parent_menus == '1' && ($start_level != 0 || $length_level != 0) && !empty($menus[$id])) {
  272. if ($length_level != 0) {
  273. return array_slice($menus[$id], $start_level, $length_level);
  274. }
  275. else {
  276. return array_slice($menus[$id], $start_level);
  277. }
  278. }
  279. return $menus[$id];
  280. }
  281. }