PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý website tuyển dụng việc làm PHP/webcaoca/public_html/vlv/modules/mod_jabulletin2/helper.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 909 lines | 536 code | 314 blank | 59 comment | 33 complexity | 074e23d4633b4ebc81a928d382203403 MD5 | raw file
  1. <?php
  2. /*
  3. # ------------------------------------------------------------------------
  4. # JA Teline III Stable - Version 1.2 - Licence Owner JA115884
  5. # ------------------------------------------------------------------------
  6. # Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
  7. # @license - Copyrighted Commercial Software
  8. # Author: J.O.O.M Solutions Co., Ltd
  9. # Websites: http://www.joomlart.com - http://www.joomlancers.com
  10. # This file may not be redistributed in whole or significant part.
  11. # ------------------------------------------------------------------------
  12. */
  13. // no direct access
  14. defined ( '_JEXEC' ) or die ( 'Restricted access' );
  15. require_once (JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php');
  16. if (! class_exists ( 'modJABulletin2' )) {
  17. class modJABulletin2 {
  18. /*function getNotINArticle(&$params) {
  19. $db =JFactory::getDBO();
  20. $category = $params->get('category');
  21. $type = $params->get('type');
  22. if ($type == 'latest')
  23. $order = "DESC";
  24. else
  25. $order = "ASC";
  26. $qry = "select id from #__content where `catid` = $category and `state` = 1 order by id $order";
  27. $db->setQuery($qry);
  28. $results = $db->loadObjectList();
  29. return $results;
  30. }*/
  31. function getOtherArticle(&$params) {
  32. $db =JFactory::getDBO();
  33. $category = $params->get('category');
  34. $type = $params->get('type');
  35. $countother = $params->get('countother');
  36. //loc mau tin ko hien thi
  37. if ($type == 'latest')
  38. $order = "DESC";
  39. else
  40. $order = "ASC";
  41. $qry = "select id from #__content where `catid` = $category and `state` = 1 order by id $order";
  42. $db->setQuery($qry);
  43. $results = $db->loadObjectList();
  44. //$notResult = $this->getNotINArticle(&$params);
  45. //$where = " id NOT (".$notResult[0]->id.")";
  46. $qry = "select id,title,catid,sectionid from #__content where `catid` = $category and `state` = 1 and id NOT IN(".$results[0]->id.") order by id $order limit 0,$countother";
  47. $db->setQuery($qry);
  48. $resultOthers = $db->loadObjectList();
  49. //echo $qry;echo "<pre>";print_r($listOthers);exit("123");
  50. return $resultOthers;
  51. //latest mostread
  52. }
  53. function getMostRead(&$params) {
  54. global $mainframe;
  55. $db = & JFactory::getDBO ();
  56. $user = & JFactory::getUser ();
  57. $count = intval ( $params->get ( 'count', 1 ) );
  58. $catid = trim ( $params->get ( 'catid' ) );
  59. $secid = trim ( $params->get ( 'secid' ) );
  60. $show_front = $params->get ( 'show_front', 1 );
  61. $aid = $user->get ( 'aid', 0 );
  62. $contentConfig = &JComponentHelper::getParams ( 'com_content' );
  63. $access = ! $contentConfig->get ( 'shownoauth' );
  64. $nullDate = $db->getNullDate ();
  65. $date = & JFactory::getDate ();
  66. $now = $date->toMySQL ();
  67. $catid = $params->get ( 'category' );
  68. if (! is_array ( $catid ) && $catid != '') {
  69. $catid = split ( ',', $catid );
  70. }
  71. if ($catid) {
  72. $catCondition = ' AND cc.id IN ("' . implode ( '","', $catid ) . '")';
  73. }
  74. if ($secid) {
  75. $ids = explode( ',', $secid );
  76. JArrayHelper::toInteger( $ids );
  77. $secCondition = ' AND (s.id=' . implode( ' OR s.id=', $ids ) . ')';
  78. }
  79. //Content Items only
  80. $query = 'SELECT a.*,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,' . ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug' . ' FROM #__content AS a' . ' LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id' . ' INNER JOIN #__categories AS cc ON cc.id = a.catid' . ' INNER JOIN #__sections AS s ON s.id = a.sectionid' . ' WHERE ( a.state = 1 AND s.id > 0 )' . ' AND ( a.publish_up = ' . $db->Quote ( $nullDate ) . ' OR a.publish_up <= ' . $db->Quote ( $now ) . ' )' . ' AND ( a.publish_down = ' . $db->Quote ( $nullDate ) . ' OR a.publish_down >= ' . $db->Quote ( $now ) . ' )' . ($access ? ' AND a.access <= ' . ( int ) $aid . ' AND cc.access <= ' . ( int ) $aid . ' AND s.access <= ' . ( int ) $aid : '') . ($catid ? $catCondition : '') . ($secid ? $secCondition : '') . ($show_front == '0' ? ' AND f.content_id IS NULL' : '') . ' AND s.published = 1' . ' AND cc.published = 1' . ' ORDER BY a.hits DESC';
  81. $db->setQuery ( $query, 0, $count );
  82. $rows = $db->loadObjectList ();
  83. return $rows;
  84. }
  85. function getLatest(&$params) {
  86. global $mainframe;
  87. $db = & JFactory::getDBO ();
  88. $user = & JFactory::getUser ();
  89. $userId = ( int ) $user->get ( 'id' );
  90. $count = ( int ) $params->get ( 'count', 1 );
  91. $catid = $params->get ( 'category' );
  92. if (! is_array ( $catid ) && $catid != '') {
  93. $catid = split ( ',', $catid );
  94. }
  95. $secid = trim( $params->get('secid') );
  96. $show_front = $params->get ( 'show_front', 1 );
  97. $aid = $user->get ( 'aid', 0 );
  98. $contentConfig = &JComponentHelper::getParams ( 'com_content' );
  99. $access = ! $contentConfig->get ( 'shownoauth' );
  100. $nullDate = $db->getNullDate ();
  101. $date = & JFactory::getDate ();
  102. $now = $date->toMySQL ();
  103. $where = 'a.state = 1' . ' AND ( a.publish_up = ' . $db->Quote ( $nullDate ) . ' OR a.publish_up <= ' . $db->Quote ( $now ) . ' )' . ' AND ( a.publish_down = ' . $db->Quote ( $nullDate ) . ' OR a.publish_down >= ' . $db->Quote ( $now ) . ' )';
  104. // User Filter
  105. switch ($params->get ( 'user_id' )) {
  106. case 'by_me' :
  107. $where .= ' AND (created_by = ' . ( int ) $userId . ' OR modified_by = ' . ( int ) $userId . ')';
  108. break;
  109. case 'not_me' :
  110. $where .= ' AND (created_by <> ' . ( int ) $userId . ' AND modified_by <> ' . ( int ) $userId . ')';
  111. break;
  112. }
  113. // Ordering
  114. switch ($params->get ( 'ordering' )) {
  115. case 'm_dsc' :
  116. $ordering = 'a.modified DESC, a.created DESC';
  117. break;
  118. case 'c_dsc' :
  119. default :
  120. $ordering = 'a.created DESC';
  121. break;
  122. }
  123. if ($catid) {
  124. $catCondition = ' AND cc.id IN ("' . implode ( '","', $catid ) . '")';
  125. }
  126. if ($secid) {
  127. $ids = explode ( ',', $secid );
  128. JArrayHelper::toInteger ( $ids );
  129. $secCondition = ' AND (s.id=' . implode ( ' OR s.id=', $ids ) . ')';
  130. }
  131. // Content Items only
  132. $query = 'SELECT a.*, ' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,' . ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug' . ' FROM #__content AS a' . ($show_front == '0' ? ' LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id' : '') . ' INNER JOIN #__categories AS cc ON cc.id = a.catid' . ' INNER JOIN #__sections AS s ON s.id = a.sectionid' . ' WHERE ' . $where . ' AND s.id > 0' . ($access ? ' AND a.access <= ' . ( int ) $aid . ' AND cc.access <= ' . ( int ) $aid . ' AND s.access <= ' . ( int ) $aid : '') . ($catid ? $catCondition : '') . ($secid ? $secCondition : '') . ($show_front == '0' ? ' AND f.content_id IS NULL ' : '') . ' AND s.published = 1' . ' AND cc.published = 1' . ' ORDER BY ' . $ordering;
  133. $db->setQuery ( $query, 0, $count );
  134. $rows = $db->loadObjectList ();
  135. return $rows;
  136. }
  137. function parseList(&$rows, &$params) {
  138. $i = 0;
  139. $showimg = $params->get ( 'show_image', 1 );
  140. $w = ( int ) $params->get ( 'width');
  141. $h = ( int ) $params->get ( 'height');
  142. $showdate = $params->get ( 'show_date', 1 );
  143. $lists = array ();
  144. foreach ( $rows as $row ) {
  145. $lists [$i]->link = JRoute::_ ( ContentHelperRoute::getArticleRoute ( $row->slug, $row->catslug, $row->sectionid ) );
  146. $lists [$i]->text = htmlspecialchars ( $row->title );
  147. $lists [$i]->introtext = $row->introtext;
  148. if ($showdate) {
  149. $lists [$i]->date = strtotime ( $row->modified ) ? $row->created : $row->modified;
  150. }
  151. if ($showimg) {
  152. $imgsrc = JAImageTools::getImgUrlFromText ( $row->introtext . $row->fulltext );
  153. $imgsrc1 = JAImageTools::resizeImage ( $imgsrc, $w, $h );
  154. if ($imgsrc1) {
  155. if ($imgsrc1 == $imgsrc) {
  156. $width = $w ? "width=\"$w\"" : "";
  157. $height = $h ? "height=\"$h\"" : "";
  158. $lists [$i]->image = "<img src=\"$imgsrc1\" alt=\"{$lists[$i]->text}\" title=\"{$lists[$i]->text}\" $width $height class =\"ja-box-ct clearfix\" />";
  159. } else {
  160. $width = $w ? "width=\"$w\"" : "";
  161. $height = $h ? "height=\"$h\"" : "";
  162. //exit("123");
  163. $lists [$i]->image = "<img src=\"$imgsrc1\" alt=\"{$lists[$i]->text}\" title=\"{$lists[$i]->text}\" $width $height class =\"ja-box-ct clearfix\" />";
  164. }
  165. }
  166. }
  167. $i ++;
  168. }
  169. return $lists;
  170. }
  171. function getList(&$params) {
  172. $type = $params->get ( 'type', 'latest' );
  173. switch ($type) {
  174. case 'latest' :
  175. $rows = modJABulletin2::getLatest ( $params );
  176. break;
  177. case 'mostread' :
  178. $rows = modJABulletin2::getMostRead ( $params );
  179. break;
  180. }
  181. if (isset ( $rows ))
  182. return modJABulletin2::parseList ( $rows, $params );
  183. return null;
  184. }
  185. function addStyleFiles() {
  186. global $mainframe;
  187. $filename = 'ja.bulletin.css';
  188. $tplpath = DS . 'templates' . DS . $mainframe->getTemplate () . DS . 'css' . DS;
  189. $tplurl = '/templates/' . $mainframe->getTemplate () . '/css/';
  190. $modurl = '/modules/mod_jabulletin2/tmpl/';
  191. $cssurl = $tplurl;
  192. if (! file_exists ( JPATH_SITE . $tplpath . $filename )) {
  193. $cssurl = $modurl;
  194. }
  195. $cssurl = JURI::base () . $cssurl;
  196. ?>
  197. <script type="text/javascript">
  198. //<![CDATA[
  199. var links = document.getElementsByTagName ('link');
  200. var included = false;
  201. if (links.length) {
  202. for (var i=0;i<links.length;i++) {
  203. if (links[i].getAttribute('href').test('ja.bulletin.css')) {
  204. included = true;
  205. break;
  206. }
  207. }
  208. }
  209. if (!included) {
  210. var script = document.createElement('link');
  211. script.setAttribute('type', 'text/css');
  212. script.setAttribute('rel', 'stylesheet');
  213. script.setAttribute('href', '<?php
  214. echo $cssurl . $filename;
  215. ?>');
  216. document.getElementsByTagName("head")[0].appendChild(script);
  217. }
  218. //]]>
  219. </script>
  220. <?php
  221. }
  222. }
  223. }
  224. if (! class_exists ( 'JAImageTools' )) {
  225. class JAImageTools {
  226. function getImgUrlFromText($text) {
  227. $regex = "/\<img.+src\s*=\s*\"([^\"]*)\"[^\>]*\>/";
  228. preg_match ( $regex, $text, $matches );
  229. $images = (count ( $matches )) ? $matches : array ();
  230. $image = count ( $images ) > 1 ? $images [1] : '';
  231. return $image;
  232. }
  233. function resizeImage(&$img, $width, $height) {
  234. if (! $img)
  235. return '';
  236. if (! function_exists ( 'imagejpeg' ))
  237. return $img;
  238. $img = str_replace ( JURI::base (), '', $img );
  239. $img = rawurldecode ( $img );
  240. $imagesurl = (file_exists ( JPATH_SITE . '/' . $img )) ? JURI::base () . JAImageTools::jaResize ( $img, $width, $height ) : '';
  241. return $imagesurl;
  242. }
  243. function jaResize($image, $max_width, $max_height) {
  244. $path = JPATH_SITE;
  245. $sizeThumb = getimagesize ( JPATH_SITE . '/' . $image );
  246. $width = $sizeThumb [0];
  247. $height = $sizeThumb [1];
  248. if (! $max_width && ! $max_height) {
  249. $max_width = $width;
  250. $max_height = $height;
  251. } else {
  252. if (! $max_width)
  253. $max_width = 1000;
  254. if (! $max_height)
  255. $max_height = 1000;
  256. }
  257. $x_ratio = $max_width / $width;
  258. $y_ratio = $max_height / $height;
  259. if (($width <= $max_width) && ($height <= $max_height)) {
  260. $tn_width = $width;
  261. $tn_height = $height;
  262. } else if (($x_ratio * $height) < $max_height) {
  263. $tn_height = ceil ( $x_ratio * $height );
  264. $tn_width = $max_width;
  265. } else {
  266. $tn_width = ceil ( $y_ratio * $width );
  267. $tn_height = $max_height;
  268. }
  269. // read image
  270. $ext = strtolower ( substr ( strrchr ( $image, '.' ), 1 ) ); // get the file extension
  271. $rzname = strtolower ( substr ( $image, 0, strpos ( $image, '.' ) ) ) . "_{$tn_width}_{$tn_height}.{$ext}"; // get the file extension
  272. $resized = $path . '/images/resized/' . $rzname;
  273. if (file_exists ( $resized )) {
  274. $smallImg = getimagesize ( $resized );
  275. if (($smallImg [0] <= $tn_width && $smallImg [1] == $tn_height) || ($smallImg [1] <= $tn_height && $smallImg [0] == $tn_width)) {
  276. return "images/resized/" . $rzname;
  277. }
  278. }
  279. if (! file_exists ( $path . '/images/resized/' ) && ! mkdir ( $path . '/images/resized/', 0755 ))
  280. return '';
  281. $folders = explode ( '/', $image );
  282. $tmppath = $path . '/images/resized/';
  283. for($i = 0; $i < count ( $folders ) - 1; $i ++) {
  284. if (! file_exists ( $tmppath . $folders [$i] ) && ! mkdir ( $tmppath . $folders [$i], 0755 ))
  285. return '';
  286. $tmppath = $tmppath . $folders [$i] . '/';
  287. }
  288. switch ($ext) {
  289. case 'jpg' : // jpg
  290. $src = imagecreatefromjpeg ( JPATH_SITE . '/' . $image );
  291. break;
  292. case 'png' : // png
  293. $src = imagecreatefrompng ( JPATH_SITE . '/' . $image );
  294. break;
  295. case 'gif' : // gif
  296. $src = imagecreatefromgif ( JPATH_SITE . '/' . $image );
  297. break;
  298. default :
  299. }
  300. $dst = imagecreatetruecolor ( $tn_width, $tn_height );
  301. //imageantialias ($dst, true);
  302. if (function_exists ( 'imageantialias' ))
  303. imageantialias ( $dst, true );
  304. imagecopyresampled ( $dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height );
  305. imagejpeg ( $dst, $resized, 90 ); // write the thumbnail to cache as well...
  306. return "images/resized/" . $rzname;
  307. }
  308. }
  309. }