/Quản lý website tuyển dụng việc làm PHP/webcaoca/public_html/vlv/modules/mod_jabulletin4/helper.php
PHP | 909 lines | 549 code | 314 blank | 46 comment | 36 complexity | cc49a7009c9804ddbd201ded13598ad9 MD5 | raw file
- <?php
- /*
- # ------------------------------------------------------------------------
- # JA Teline III Stable - Version 1.2 - Licence Owner JA115884
- # ------------------------------------------------------------------------
- # Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
- # @license - Copyrighted Commercial Software
- # Author: J.O.O.M Solutions Co., Ltd
- # Websites: http://www.joomlart.com - http://www.joomlancers.com
- # This file may not be redistributed in whole or significant part.
- # ------------------------------------------------------------------------
- */
- // no direct access
- defined ( '_JEXEC' ) or die ( 'Restricted access' );
- require_once (JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php');
- if (! class_exists ( 'modJABulletin4' )) {
- class modJABulletin4 {
- function getNotINArticle(&$params) {
- $db =JFactory::getDBO();
- $category = $params->get('category');
- $type = $params->get('type');
- if ($type == 'latest')
- $order = "DESC";
- else
- $order = "ASC";
- $qry = "select id from #__content where `catid` = $category and `state` = 1 order by id $order";
- $db->setQuery($qry);
- $results = $db->loadObjectList();
- return $results;
- }
-
- function getOtherArticle(&$params) {
- $db =JFactory::getDBO();
- $category = $params->get('category');
- $type = $params->get('type');
- $countother = $params->get('countother');
- //loc mau tin ko hien thi
- if ($type == 'latest')
- $order = "DESC";
- else
- $order = "ASC";
-
- $qry = "select id from #__content where `catid` = $category and `state` = 1 order by id $order";
- $db->setQuery($qry);
- $results = $db->loadObjectList();
-
- //$notResult = $this->getNotINArticle(&$params);
- //$where = " id NOT (".$notResult[0]->id.")";
-
- $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";
- $db->setQuery($qry);
- $resultOthers = $db->loadObjectList();
- //echo $qry;echo "<pre>";print_r($listOthers);exit("123");
- return $resultOthers;
- //latest mostread
- }
-
- function getMostRead(&$params) {
- global $mainframe;
-
- $db = & JFactory::getDBO ();
- $user = & JFactory::getUser ();
-
- $count = intval ( $params->get ( 'count', 1 ) );
- $catid = trim ( $params->get ( 'catid' ) );
- $secid = trim ( $params->get ( 'secid' ) );
- $show_front = $params->get ( 'show_front', 1 );
- $aid = $user->get ( 'aid', 0 );
-
- $contentConfig = &JComponentHelper::getParams ( 'com_content' );
- $access = ! $contentConfig->get ( 'shownoauth' );
- $nullDate = $db->getNullDate ();
- $date = & JFactory::getDate ();
- $now = $date->toMySQL ();
- $catid = $params->get ( 'category' );
- if (! is_array ( $catid ) && $catid != '') {
- $catid = split ( ',', $catid );
- }
- if ($catid) {
- $catCondition = ' AND cc.id IN ("' . implode ( '","', $catid ) . '")';
- }
- if ($secid) {
- $ids = explode( ',', $secid );
- JArrayHelper::toInteger( $ids );
- $secCondition = ' AND (s.id=' . implode( ' OR s.id=', $ids ) . ')';
- }
- //Content Items only
- $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';
- $db->setQuery ( $query, 0, $count );
- $rows = $db->loadObjectList ();
- return $rows;
- }
- function getLatest(&$params) {
- global $mainframe;
- $db = & JFactory::getDBO ();
- $user = & JFactory::getUser ();
- $userId = ( int ) $user->get ( 'id' );
- $count = ( int ) $params->get ( 'count', 1 );
- $catid = $params->get ( 'category' );
- if (! is_array ( $catid ) && $catid != '') {
- $catid = split ( ',', $catid );
- }
- $secid = trim( $params->get('secid') );
- $show_front = $params->get ( 'show_front', 1 );
- $aid = $user->get ( 'aid', 0 );
- $contentConfig = &JComponentHelper::getParams ( 'com_content' );
- $access = ! $contentConfig->get ( 'shownoauth' );
- $nullDate = $db->getNullDate ();
- $date = & JFactory::getDate ();
- $now = $date->toMySQL ();
- $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 ) . ' )';
- // User Filter
- switch ($params->get ( 'user_id' )) {
- case 'by_me' :
- $where .= ' AND (created_by = ' . ( int ) $userId . ' OR modified_by = ' . ( int ) $userId . ')';
- break;
- case 'not_me' :
- $where .= ' AND (created_by <> ' . ( int ) $userId . ' AND modified_by <> ' . ( int ) $userId . ')';
- break;
- }
- // Ordering
- switch ($params->get ( 'ordering' )) {
- case 'm_dsc' :
- $ordering = 'a.modified DESC, a.created DESC';
- break;
- case 'c_dsc' :
- default :
- $ordering = 'a.created DESC';
- break;
- }
- if ($catid) {
- $catCondition = ' AND cc.id IN ("' . implode ( '","', $catid ) . '")';
- }
- if ($secid) {
- $ids = explode ( ',', $secid );
- JArrayHelper::toInteger ( $ids );
- $secCondition = ' AND (s.id=' . implode ( ' OR s.id=', $ids ) . ')';
- }
- // Content Items only
- $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;
- $db->setQuery ( $query, 0, $count );
- $rows = $db->loadObjectList ();
- return $rows;
- }
- function parseList(&$rows, &$params) {
- $i = 0;
- $showimg = $params->get ( 'show_image', 1 );
- $w = ( int ) $params->get ( 'width');
- $h = ( int ) $params->get ( 'height');
- $showdate = $params->get ( 'show_date', 1 );
- $lists = array ();
- foreach ( $rows as $row ) {
- $lists [$i]->link = JRoute::_ ( ContentHelperRoute::getArticleRoute ( $row->slug, $row->catslug, $row->sectionid ) );
- $lists [$i]->text = htmlspecialchars ( $row->title );
- $lists [$i]->introtext = $row->introtext;
- if ($showdate) {
- $lists [$i]->date = strtotime ( $row->modified ) ? $row->created : $row->modified;
- }
- if ($showimg) {
- $imgsrc = JAImageTools::getImgUrlFromText ( $row->introtext . $row->fulltext );
- $imgsrc1 = JAImageTools::resizeImage ( $imgsrc, $w, $h );
- if ($imgsrc1) {
- if ($imgsrc1 == $imgsrc) {
- $width = $w ? "width=\"$w\"" : "";
- $height = $h ? "height=\"$h\"" : "";
- $lists [$i]->image = "<img src=\"$imgsrc1\" alt=\"{$lists[$i]->text}\" title=\"{$lists[$i]->text}\" $width $height class =\"ja-box-ct clearfix\" />";
- } else {
- $width = $w ? "width=\"$w\"" : "";
- $height = $h ? "height=\"$h\"" : "";
- //exit("123");
- $lists [$i]->image = "<img src=\"$imgsrc1\" alt=\"{$lists[$i]->text}\" title=\"{$lists[$i]->text}\" $width $height class =\"ja-box-ct clearfix\" />";
- }
- }
- }
- $i ++;
- }
- return $lists;
- }
-
- function getList(&$params) {
- $type = $params->get ( 'type', 'latest' );
- switch ($type) {
- case 'latest' :
- $rows = modJABulletin4::getLatest ( $params );
- break;
- case 'mostread' :
- $rows = modJABulletin4::getMostRead ( $params );
- break;
- }
- if (isset ( $rows ))
- return modJABulletin4::parseList ( $rows, $params );
- return null;
- }
-
- function addStyleFiles() {
- global $mainframe;
- $filename = 'ja.bulletin.css';
- $tplpath = DS . 'templates' . DS . $mainframe->getTemplate () . DS . 'css' . DS;
- $tplurl = '/templates/' . $mainframe->getTemplate () . '/css/';
- $modurl = '/modules/mod_jabulletin2/tmpl/';
- $cssurl = $tplurl;
- if (! file_exists ( JPATH_SITE . $tplpath . $filename )) {
- $cssurl = $modurl;
- }
- $cssurl = JURI::base () . $cssurl;
- ?>
- <script type="text/javascript">
- //<![CDATA[
- var links = document.getElementsByTagName ('link');
- var included = false;
- if (links.length) {
- for (var i=0;i<links.length;i++) {
- if (links[i].getAttribute('href').test('ja.bulletin.css')) {
- included = true;
- break;
- }
- }
- }
- if (!included) {
- var script = document.createElement('link');
- script.setAttribute('type', 'text/css');
- script.setAttribute('rel', 'stylesheet');
- script.setAttribute('href', '<?php
- echo $cssurl . $filename;
- ?>');
- document.getElementsByTagName("head")[0].appendChild(script);
- }
- //]]>
- </script>
- <?php
- }
- }
- }
- if (! class_exists ( 'JAImageTools' )) {
- class JAImageTools {
- function getImgUrlFromText($text) {
- $regex = "/\<img.+src\s*=\s*\"([^\"]*)\"[^\>]*\>/";
- preg_match ( $regex, $text, $matches );
- $images = (count ( $matches )) ? $matches : array ();
- $image = count ( $images ) > 1 ? $images [1] : '';
- return $image;
- }
-
- function resizeImage(&$img, $width, $height) {
- if (! $img)
- return '';
- if (! function_exists ( 'imagejpeg' ))
- return $img;
- $img = str_replace ( JURI::base (), '', $img );
- $img = rawurldecode ( $img );
- $imagesurl = (file_exists ( JPATH_SITE . '/' . $img )) ? JURI::base () . JAImageTools::jaResize ( $img, $width, $height ) : '';
- return $imagesurl;
- }
-
- function jaResize($image, $max_width, $max_height) {
- $path = JPATH_SITE;
- $sizeThumb = getimagesize ( JPATH_SITE . '/' . $image );
- $width = $sizeThumb [0];
- $height = $sizeThumb [1];
- if (! $max_width && ! $max_height) {
- $max_width = $width;
- $max_height = $height;
- } else {
- if (! $max_width)
- $max_width = 1000;
- if (! $max_height)
- $max_height = 1000;
- }
- $x_ratio = $max_width / $width;
- $y_ratio = $max_height / $height;
- if (($width <= $max_width) && ($height <= $max_height)) {
- $tn_width = $width;
- $tn_height = $height;
- } else if (($x_ratio * $height) < $max_height) {
- $tn_height = ceil ( $x_ratio * $height );
- $tn_width = $max_width;
- } else {
- $tn_width = ceil ( $y_ratio * $width );
- $tn_height = $max_height;
- }
- // read image
- $ext = strtolower ( substr ( strrchr ( $image, '.' ), 1 ) ); // get the file extension
- $rzname = strtolower ( substr ( $image, 0, strpos ( $image, '.' ) ) ) . "_{$tn_width}_{$tn_height}.{$ext}"; // get the file extension
- $resized = $path . '/images/resized/' . $rzname;
- if (file_exists ( $resized )) {
- $smallImg = getimagesize ( $resized );
- if (($smallImg [0] <= $tn_width && $smallImg [1] == $tn_height) || ($smallImg [1] <= $tn_height && $smallImg [0] == $tn_width)) {
- return "images/resized/" . $rzname;
- }
- }
- if (! file_exists ( $path . '/images/resized/' ) && ! mkdir ( $path . '/images/resized/', 0755 ))
- return '';
- $folders = explode ( '/', $image );
- $tmppath = $path . '/images/resized/';
- for($i = 0; $i < count ( $folders ) - 1; $i ++) {
- if (! file_exists ( $tmppath . $folders [$i] ) && ! mkdir ( $tmppath . $folders [$i], 0755 ))
- return '';
- $tmppath = $tmppath . $folders [$i] . '/';
- }
- switch ($ext) {
- case 'jpg' : // jpg
- $src = imagecreatefromjpeg ( JPATH_SITE . '/' . $image );
- break;
- case 'png' : // png
- $src = imagecreatefrompng ( JPATH_SITE . '/' . $image );
- break;
- case 'gif' : // gif
- $src = imagecreatefromgif ( JPATH_SITE . '/' . $image );
- break;
- default :
- }
- $dst = imagecreatetruecolor ( $tn_width, $tn_height );
- //imageantialias ($dst, true);
- if (function_exists ( 'imageantialias' ))
- imageantialias ( $dst, true );
- imagecopyresampled ( $dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height );
- imagejpeg ( $dst, $resized, 90 ); // write the thumbnail to cache as well...
- return "images/resized/" . $rzname;
- }
-
- }
- }