....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 195.3.193.33  /  Your IP : 216.73.216.125
Web Server : Apache
System : Linux server3 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User : web032 ( 1035)
PHP Version : 7.3.33
Disable Function : show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/web032/htdocs/cms/components/com_rialto/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/web032/htdocs/cms/components/com_rialto/classes/helper.php
<?php
/**
 *
 * Rialto - Classified Ads for Joomla!
 *
 * @Version       $Id: helper.php 2306 2016-06-13 13:24:56Z geoffc $
 * @Package       Rialto
 * @Subpackage    com_rialto
 * @Release       1.3.0
 * @Copyright     Copyright (C) 2015-2016 Macrotone Consulting Ltd. All rights reserved.
 * @License       GNU General Public License version 3 or later; see LICENSE.txt
 * @Contact       support@macrotoneconsulting.co.uk
 * @Lastrevision  $Date: 2016-06-13 14:24:56 +0100 (Mon, 13 Jun 2016) $
 *
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted Access');

if (! class_exists('RialtoHelperLog')) {
   require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_rialto'.DS.'classes'.DS.'log.php');
}

/**
 * Helper class
 *
 */
class RialtoFrontendHelper extends JObject
{

   /**
    * @param $cat_id
    * @return string
    */
   function getCategoryById( $cat_id) {
      return "";
   }

   /**
    * @return int
    */
   function updateRialtoStats() {
      return 0;
   }

   /**
    * @param $category_id
    * @return int
    */
   function updateCategoryStats( $category_id) {
      return 0;
   }

   /**
    * @param $cat_id
    * @return bool
    */
   function isCategoryModerated( $cat_id) {
      return false;
   }

   /**
    * @param $cat_id
    * @param int|Switch $sw Switch to control whether entry categories are displayed.
    *
    * Called from category display.
    * @return string
    */
   function getQuickJumpSelectBox( $cat_id, $sw = 0)
   {
      // $user = JFactory::getUser();
      $db   = JFactory::getDBO();

      // create array for slugs
      $slugs = array();

      // set slug counter to 0
      $iSlug = 0;

      $html = "<select class='quickselectbox' name='quickselectbox' onchange='callURL( this)'>";

      // get all published categories above Root.
      /*
       $sql_categories = "SELECT id, title, level, " .
          " CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END as slug" .
          " FROM ".$db->quoteName( '#__rialto_categories') .
          " WHERE id > 1 AND state='1'" .
          " ORDER BY lft ASC";

      $db->setQuery( $sql_categories);
      */

      $sql = "SELECT c.id, c.title, c.level, ";
      $sql .= " CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(':', c.id, c.alias) ELSE c.id END as slug ";
      $sql .= " FROM ".$db->quoteName('#__rialto_categories')." c ";

      if ( JLanguageMultilang::isEnabled() ) {
         if (JLanguageAssociations::isEnabled()) {
            // We sum up the individual bits to get the total entry count.
            // First these are the unassociated entries in the current category.
            $sql .=" LEFT JOIN (select category_id as id, count(*) as nrecs from ".$db->quoteName('#__rialto_entries')." AS e
                                WHERE e.state = '1'
                             AND e.id NOT IN ( SELECT id FROM ".$db->quoteName('#__associations')." WHERE context ='com_rialto.entry' )
                             group by e.category_id) c1 ON c1.id = c.id";

            // Then we have the associated entries within this category and all associated categories.
            $sql .= " LEFT JOIN (SELECT c.id, COUNT( DISTINCT r.`key`) AS nrecs
                                    FROM ".$db->quoteName('#__rialto_categories') ." AS c,
                                    (SELECT e.category_id, ae.`key`
                                               FROM ".$db->quoteName('#__associations') ." AS ae,
                                                    ".$db->quoteName('#__rialto_entries') ." AS e
                                               WHERE e.id  = ae.id
                                               AND context = 'com_rialto.entry'
                                               AND e.state = 1) AS r
                                    WHERE r.category_id IN (SELECT id FROM ".$db->quoteName('#__associations') ."
                                                            WHERE `key` = ( SELECT `key` FROM ".$db->quoteName('#__associations') ."
                                                                            WHERE context='com_rialto.category'
                                                                            AND id = c.id
                                                                          )
                                                           )
                                    GROUP BY c.id ) c2 ON c2.id = c.id";

            // Finally we have the unassociated entries in the other associated categories.
            /* This does not work with more than two associations.
            $sql .= " LEFT JOIN (select distinct id as id,
                              (SELECT COUNT(*) AS nrecs FROM ".$db->quoteName('#__rialto_entries') ." AS e
                               WHERE e.category_id IN ( SELECT id FROM ".$db->quoteName('#__associations').
                               " WHERE `key` = ( SELECT `key` FROM ".$db->quoteName('#__associations') . "
                                                WHERE context='com_rialto.category' AND id = f.id )
                               AND id != f.id )
                               AND e.id NOT IN ( SELECT id FROM ".$db->quoteName('#__associations') ."
                               WHERE context ='com_rialto.entry' )
                               AND e.state = '1'
                               group by e.category_id ) AS nrecs
                               FROM ".$db->quoteName('#__rialto_categories')." f) c3 ON c3.id = c.id";
            */
            $sql .= " LEFT JOIN (SELECT rc.id, sum(z.rows) AS nrecs
                         FROM ".$db->quoteName('#__rialto_categories') ." AS rc,
                           (SELECT rf.id, sum(g.recs) as rows
                            FROM ".$db->quoteName('#__rialto_categories') ." AS rf
                         LEFT JOIN ( SELECT category_id, count(*) as recs
                            FROM ".$db->quoteName('#__rialto_entries') ."
                            WHERE id NOT IN (select id from ".$db->quoteName('#__associations'). " WHERE context='com_rialto.entry')
                            GROUP BY category_id) AS g
                            ON rf.id = g.category_id
                         GROUP BY rf.id) as z
                         WHERE z.id IN (
                            SELECT id FROM ".$db->quoteName('#__associations') ."
                            WHERE `key` = (
                               SELECT `key` FROM ".$db->quoteName('#__associations') ."
                               WHERE context='com_rialto.category' AND id = rc.id )
                            AND id != rc.id )
                         GROUP BY rc.id) c3 ON c3.id = c.id";
         } else {
            $sql .= "LEFT JOIN (select category_id, count(*) AS nrecs from " . $db->quoteName('#__rialto_entries') . " e
                        WHERE e.state = '1' group by e.category_id ) AS g ON g.category_id= c.id";
         }

         // Get current language plus 'all'.  Also allow for undefined language.
         $sql .= " WHERE c.language in (" . $db->quote(JFactory::getLanguage()->getTag()) . "," . $db->quote('*') . ",'')";
         $sql .= " AND c.state='1' ";

      } else {
         $sql .= "LEFT JOIN (select category_id, count(*) AS nrecs from " . $db->quoteName('#__rialto_entries') . " e
                    WHERE e.state = '1' group by e.category_id ) AS g ON g.category_id= c.id";

         $sql .= " WHERE c.state='1' ";
      }

      if ( $sw == 0) {
         if ( JLanguageMultilang::isEnabled() ) {
            if (JLanguageAssociations::isEnabled()) {
               $sql.= " AND (IFNULL(c1.nrecs,0)+IFNULL(c2.nrecs,0)+IFNULL(c3.nrecs,0) ) > 0 ";
            } else {
               $sql .= " AND g.nrecs > 0 ";
            }
         } else {
            $sql .= " AND g.nrecs > 0 ";
         }
      }

      $sql .= " ORDER by c.lft ASC";

      $db->setQuery($sql);

      /*
      $query = $db->getQuery(true);
      $query->select('id, title, level')
         ->select("CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END as slug")
         ->from('#__rialto_categories')
         ->where('id > 1 AND state=1');

      // Add language criteria.
      if ( JLanguageMultilang::isEnabled() )
         $query->where('language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
      $query->order('lft ASC');

      $db->setQuery($query);
      */

      $_category_list = $db->loadAssocList();
      reset( $_category_list);
      while (list($key, $val) = each( $_category_list)) {
         $category_id    = $_category_list[$key]['id'];
         $category_name  = $_category_list[$key]['title'];
         $category_slug  = $_category_list[$key]['slug'];
         $cat_level      = $_category_list[$key]['level'];

         if ( $category_id == $cat_id) { // this category is the current active
            $html .= "<option value='".$category_id."' selected='selected'>" . str_repeat('<span class="gi">|&mdash;</span>', $cat_level-1). $category_name;
         } else {
            $html .= "<option value='".$category_id."'>" . str_repeat('<span class="gi">|&mdash;</span>', $cat_level-1). $category_name;
         }

         $category_urlTMP = "index.php?option=com_rialto&view=category&catid=".$category_slug;
         $category_url = JRoute::_( $category_urlTMP);

         $slugs[$iSlug][0] = utf8_encode( $category_id);
         $slugs[$iSlug][1] = utf8_encode( $category_url);
         $iSlug++;
      }
      $html .= "</select>";

      print "<script type='text/javascript'> var slugsarray = ".json_encode($slugs)."; </script>";
      return $html;
   }

   /**
    * @param $cat_id
    * @return string
    *
    * Called from entry display.
    *
    */
   function getCategorySelectBox( $cat_id)
   {
      // $user = JFactory::getUser();
      $db   = JFactory::getDBO();

      /*
      $html = "<select class='quickselectbox' name='categoryselectbox'>";
      // get all published category groups
      $sql_groups = "SELECT id, title FROM ".$db->quoteName( '#__rialto_categories') .
            " WHERE parent_id='0' AND state='1'" .
            " ORDER BY lft ASC";

      $db->setQuery( $sql_groups);

      $_group_list = $db->loadAssocList();

      reset( $_group_list);
      while (list($key, $val) = each( $_group_list)) {
         $group_id   = $_group_list[$key]['id'];
         $group_name = $_group_list[$key]['title'];

         $html .= "<optgroup label='".$group_name."'>";

         // get categories from this group
         // get all published categories in this group
         $sql_categories = "SELECT id, title, " .
               " CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END as slug" .
               " FROM ".$db->quoteName( '#__rialto_categories') .
               " WHERE parent_id='".$group_id."' AND state='1'" .
               " ORDER BY lft ASC";

         $db->setQuery( $sql_categories);

         $_category_list = $db->loadAssocList();

         reset( $_category_list);
         while (list($key, $val) = each( $_category_list)) {
            $category_id    = $_category_list[$key]['id'];
            $category_name   = $_category_list[$key]['title'];
            $category_slug   = $_category_list[$key]['slug'];

            if ( $category_id == $cat_id) { // this category is the current active
               $html .= "<option value='".$category_id."' selected='selected'>" . $category_name;
            } else {
               $html .= "<option value='".$category_id."'>" . $category_name;
            }

            $category_urlTMP = "index.php?option=com_rialto&view=category&catid=".$category_slug;
            $category_url = JRoute::_( $category_urlTMP);

         }
         // get categories from this group

         $html .= "</optgroup>";
      }
      */

      $html = "<select class='quickselectbox' name='categoryselectbox'>";

      // get all published categories above Root.
      /*
      $sql_categories = "SELECT id, title, level, " .
          " CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END as slug" .
          " FROM ".$db->quoteName( '#__rialto_categories') .
          " WHERE id > 1 AND state='1'" .
          " ORDER BY lft ASC";

      $db->setQuery( $sql_categories);
      */
      $query = $db->getQuery(true);
      $query->select('id, title, level')
         ->select("CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END as slug")
         ->from('#__rialto_categories')
         ->where('id > 1 AND state=1');
      // Add language criteria.
      if ( JLanguageMultilang::isEnabled() )
         $query->where('language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
      $query->order('lft ASC');

      $db->setQuery($query);

      $_category_list = $db->loadAssocList();
      reset( $_category_list);
      while (list($key, $val) = each( $_category_list)) {
         $category_id    = $_category_list[$key]['id'];
         $category_name   = $_category_list[$key]['title'];
         // $category_slug   = $_category_list[$key]['slug'];
         $cat_level = $_category_list[$key]['level'];

         if ( $category_id == $cat_id) { // this category is the current active
            $html .= "<option value='".$category_id."' selected='selected'>" . str_repeat('<span class="gi">|&mdash;</span>', $cat_level-1).$category_name;
         } else {
            $html .= "<option value='".$category_id."'>" . str_repeat('<span class="gi">|&mdash;</span>', $cat_level-1). $category_name;
         }

//         $category_urlTMP = "index.php?option=com_rialto&view=category&catid=".$category_slug;
//         $category_url = JRoute::_( $category_urlTMP);

//         $slugs[$iSlug][0] = utf8_encode( $category_id);
//         $slugs[$iSlug][1] = utf8_encode( $category_url);
//         $iSlug++;
      }
      $html .= "</select>";

//      print "<script type='text/javascript'> var slugsarray = ".json_encode($slugs)."; </script>";
      return $html;
   }

   /**
    * @param $lang_id
    * @return string
    */
   function getLanguageSelectBox($lang_id)
   {
      $html = "<select name=\"filter_language\" class=\"inputbox\" onchange=\"callCat( this)\">";
//      $html = "<select name=\"filter_language\" class=\"inputbox\" onchange=\"this.form.submit()\">";
      $html .= "<option value=\"\">".JText::_('JOPTION_SELECT_LANGUAGE')."</option>";
      $html .= JHtml::_('select.options', JHtml::_('contentlanguage.existing', true, true), 'value', 'text', $lang_id);
      $html .= "</select>";
      return $html;
   }

   /**
    * @param $cat_id
    * @param $lang_id
    * @return string
    *
    * Given a category id return the associated category for the requested langauge code.
    */
   function updateCategoryID($cat_id, $lang_id)
   {
      $db   = JFactory::getDBO();
      $query = "SELECT id
                FROM ".$db->QuoteName('#__rialto_categories')."
                WHERE language = ".$db->Quote($lang_id) . "
                AND id IN (SELECT id FROM ".$db->quoteName('#__associations') ."
                WHERE `key` = (
                  SELECT `key` FROM ".$db->quoteName('#__associations') ."
                  WHERE context='com_rialto.category' AND id = ".$cat_id." )
                ) ";
      $db->setQuery($query);
      $category_id = $db->loadResult();

      if ( empty($category_id) )
         $category_id = $cat_id;

      return $category_id;
   }


   /**
    * @param $cat_id
    * @return mixed|string
    */
   function getCategorySlugById( $cat_id)
   {
      $db   = JFactory::getDBO();
      $sql = "SELECT CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END as slug" .
            " FROM " . $db->quoteName('#__rialto_categories') . " WHERE id='". $cat_id . "'";

      $db->setQuery( $sql);
      $slug = $db->loadResult();

      if ( !$slug) {
         return "";
      } else {
         return $slug;
      }
   }


   /**
    * @param $lab_id
    * @param string $lang
    * @return string
    */
   function getLabelSelectBox($lab_id, $lang = '')
   {
      // $user = JFactory::getUser();
      $db   = JFactory::getDBO();

      $html = "<select class='labelselectbox' name='labelselectbox'>";

      // get all published labels
      /*
      $sql = "SELECT id, name " .
            " FROM ".$db->quoteName( '#__rialto_labels') .
            " WHERE state='1'" .
            " ORDER BY ordering ASC";
      $db->setQuery( $sql);
      */

      $query = $db->getQuery(true);
      $query->select('id, name')
            ->from('#__rialto_labels')
            ->where('state=1');
      // Add language criteria.
      if ( JLanguageMultilang::isEnabled() ) {
         if ( $lang == '') {
            $query->where('language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
         } else {
            $query->where('language in (' . $db->quote($lang) . ',' . $db->quote('*') . ')');
         }
      }
      $query->order('ordering ASC');

      $db->setQuery($query);

      $_label_list = $db->loadAssocList();

      reset( $_label_list);
      while (list($key, $val) = each( $_label_list)) {
         $label_id     = $_label_list[$key]['id'];
         $label_name   = $_label_list[$key]['name'];

         if ( $label_id == $lab_id) { // this label is the current active
            $html .= "<option value='".$label_id."' selected='selected'>" . $label_name;
         } else {
            $html .= "<option value='".$label_id."'>" . $label_name;
         }
      }

      $html .= "</select>";
      return $html;
   }


   /**
    * @param $id
    * @return mixed|string
    */
   function getUsernameById( $id)
   {
      $db   = JFactory::getDBO();
      $sql = "SELECT username FROM ".$db->quoteName('#__users')." WHERE id='". $id . "'";
      $db->setQuery( $sql);
      $username = $db->loadResult();

      if ( !$username) {
         return "-";
      } else {
         return $username;
      }
   }


   /**
    * @param $id
    * @return mixed|string
    */
   function getLabelnameById( $id)
   {
      $db   = JFactory::getDBO();
      // What language are we displaying?
      $input = JFactory::getApplication()->input;
      $_lang = $input->get('language');

      $sql  = "SELECT name FROM ".$db->quoteName('#__rialto_labels');

      if ( JLanguageMultilang::isEnabled() ) {
         // Should display page defined language string value.
         if (JLanguageAssociations::isEnabled()) {
            $sql .=  " WHERE id IN ( SELECT id FROM ".$db->quoteName('#__associations'). "
                      WHERE `key` = ( SELECT `key` FROM ".$db->quoteName('#__associations'). "
                                      WHERE context='com_rialto.label' AND id = ". $db->Quote($id) . " ) UNION SELECT id ) ";
            $sql .= " AND language IN ( ". $db->quote($_lang). ",'*')";
         } else {
             $sql .=  " WHERE id=" . $db->Quote($id);
         }
      } else {
         $sql .=  " WHERE id=" . $db->Quote($id);
      }

      $db->setQuery( $sql);
      $labelname = $db->loadResult();

      if ( !$labelname) {
         return "-";
      } else {
         return $labelname;
      }
   }


   /**
    * @param $duration
    * @param $mode
    * @param $cleanup
    * @param $cleanupduration
    */
   function expireEntries( $duration, $mode, $cleanup, $cleanupduration)
   {
      $db   = JFactory::getDBO();
      $db->setQuery( "SELECT CURRENT_DATE()");
      $date_current = $db->loadResult();

       // are there expired entries?
      $sql  = "SELECT COUNT(*) FROM #__rialto_entries ";
      $sql .= " WHERE date_created < DATE_SUB( '" . $date_current . "', INTERVAL " . $duration . " DAY)";
      $db->setQuery( $sql);
      $count_expired = $db->loadResult();

      if ( $count_expired > 0) { // found expired entries
         switch ( $mode) {
            case 1: { // unpublish
               $sql  = "UPDATE #__rialto_entries SET state='0', expired='1' ";
               $sql .= " WHERE date_created < DATE_SUB( '" . $date_current . "', INTERVAL " . $duration . " DAY)";
               $db->setQuery( $sql);
               $db->execute();
               break;
            }
            case 2: { // delete
               // select loop over expired entries
               $sql = "SELECT id FROM #__rialto_entries ";
               $sql .= " WHERE date_created < DATE_SUB( '" . $date_current . "', INTERVAL " . $duration . " DAY)";
               $db->setQuery( $sql);
               $rows = $db->loadObjectList();
               foreach ( $rows as $row ) {
                  $this->rm_imagefolder( $row->id);
               }

               // delete the entries from database
               $sql = "DELETE FROM #__rialto_entries ";
               $sql .= " WHERE date_created < DATE_SUB( '" . $date_current . "', INTERVAL " . $duration . " DAY)";
               $db->setQuery( $sql);
               $db->execute();
               break;
            }
            default: { // do nothing
               break;
            }
         }
      } // if count_expired > 0

       // are there entries to cleanup?
      $sql = "SELECT COUNT(*) FROM #__rialto_entries ";
      $sql .= " WHERE date_created < DATE_SUB( '" . $date_current . "', INTERVAL " . $cleanupduration . " DAY)";
      $db->setQuery( $sql);
      $count_cleanup = $db->loadResult();

      if ( $count_cleanup > 0) { // found entries to cleanup
         if ( $cleanup == 1)  { // cleanup (delete) unpublished entries
            // select loop over cleanup entries
            $sql = "SELECT id FROM #__rialto_entries ";
            $sql .= " WHERE date_created < DATE_SUB( '" . $date_current . "', INTERVAL " . $cleanupduration . " DAY)";
            $db->setQuery( $sql);
            $rows = $db->loadObjectList();

            foreach ( $rows as $row ) {
               $this->rm_imagefolder( $row->id);
            }

            // delete the entries from database
            $sql = "DELETE FROM #__rialto_entries ";
            $sql .= " WHERE date_created < DATE_SUB( '" . $date_current . "', INTERVAL " . $cleanupduration . " DAY)";
            $db->setQuery( $sql);
            $db->execute();
         }
      } // if count_cleanup > 0

   }


   /**
    * @param $component
    * @return int|mixed
    */
   function getItemidByComponentName( $component)
   {
      $db   = JFactory::getDBO();
      $sql = "SELECT extension_id FROM " . $db->quoteName('#__extensions');
      $sql .= " WHERE " . $db->quoteName('element') . "=" . $db->Quote($component);
      $db->setQuery( $sql);
      $componentid = $db->loadResult();

      if ( !$componentid) {
         return 0;
      } else {
         $sql = "SELECT id FROM " . $db->quoteName('#__menu') ;
         $sql .= " WHERE " . $db->quoteName('component_id') . "=" . $db->Quote($componentid);
         $sql .= " AND level='1' AND published='1' ";

         $db->setQuery( $sql);
         $itemid = $db->loadResult();

         if ( !$itemid) {
            return 0;
         } else {
            return $itemid;
         }
      }
   }


   /**
    * Get the version number of the componnnt.
    * Change to get it fromthe manifest rather tha n the meta table.
    *
    * @return mixed|string
    */
   function getVersion()
   {
      $db   = JFactory::getDBO();
      $db->setQuery("SELECT manifest_cache FROM #__extensions WHERE element = 'com_rialto' AND type='component' ");
      $manifest = json_decode( $db->loadResult(), true );
      $version = $manifest[ 'version' ];
/*
      $sql = "SELECT version FROM " . $db->quoteName( '#__rialto_meta')." WHERE id='1'";
      $db->setQuery( $sql);
      $version = $db->loadResult();
*/
      if ( !$version) {
         return "0";
      } else {
         return $version;
      }
   }


   /**
    * @param $id
    * @return int
    */
   function getCategoryUseFirstnameById( $id)
   {
      if ( $id == 0 || $id == "") return 2;

      $db   = JFactory::getDBO();
      $sql = "SELECT use_firstname FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseLastnameById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_lastname FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }


   /**
    * @param $id
    * @return int
    */
   function getCategoryUseCompanyById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_company FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }


   /**
    * @param $id
    * @return int
    */
   function getCategoryUseStreetById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_street FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseZipById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_zip FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseCityById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_city FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseStateById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_state FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseCountryById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_country FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUsePhoneById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_phone FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseMobileById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_mobile FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseEmailById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_email FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseWebById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_web FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUseConditionById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_condition FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * @param $id
    * @return int
    */
   function getCategoryUsePriceById( $id)
   {
      if ( $id == 0 || $id == "") return 2;
      $db   = JFactory::getDBO();
      $sql = "SELECT use_price FROM " . $db->quoteName( '#__rialto_categories') . " WHERE id='" . $id . "'";
      $db->setQuery( $sql);
      $use = $db->loadResult();

      switch ( $use) {
         case 0: {
            return 0; // No
            break;
         }
         case 1: {
            return 1; // Yes
            break;
         }
         default: {
            return 2; // global
            break;
         }
      }
   }

   /**
    * Method to add an image to an entry.
    *
    * Formally part of the model, but moved into a helper since we wish to make teh back end teh same as the
    * front end in a later version.
    *
    * This differs from teh back end in that the image parameter is a text string in the front end but is an
    * array in the back end.
    *
    * @access public
    * @param $entry_id
    * @param $image
    * @param $absolute_path
    * @param $db
    * @param $imagenumber
    * @return String
    */
   public static function add_image( $entry_id, $image, $absolute_path, $db, $imagenumber)
   {
      // get max_imagesize from parameters
      $params = JComponentHelper::getParams('com_rialto');
      $max_image_size = $params->get('maxImageSize', '209715200');

      $max_big_image_x = $params->get('maxBigImageX', '800');
      $max_big_image_y = $params->get('maxBigImageY', '600');

      $max_small_image_x = $params->get('maxSmallImageX', '128');
      $max_small_image_y = $params->get('maxSmallImageY', '96');

      $rialto_folder = $absolute_path."/images/rialto/";
      if ( !is_dir( $rialto_folder)) {
         mkdir( $rialto_folder);
      }

      $image_folder = $absolute_path."/images/rialto/entries/";
      if ( !is_dir( $image_folder)) {
         mkdir( $image_folder);
      }

      $image_too_big = 0;
      if (isset( $_FILES[$image])) {
         if ( $_FILES[$image]['size'] > $max_image_size) {
            $image_too_big = 1;
         }
      }

      if ( $image_too_big == 1) {
         echo '<span style="color: #CC0000">';
         echo JText::_( 'COM_RIALTO_IMAGE_TOO_BIG' );
         echo "</span>";
         echo "<br>";
         echo "<br>";
      } else {
         $af_size = GetImageSize ($_FILES[$image]['tmp_name']);
         switch ($af_size[2]) {
            case 1 : {
               $thispicext = 'gif';
               break;
            }
            case 2 : {
               $thispicext = 'jpg';
               break;
            }
            case 3 : {
               $thispicext = 'png';
               break;
            }
         }

         // if ( $af_size[2] >= 1 && $af_size[2] <= 3) { // 1=GIF, 2=JPG or 3=PNG
         if ( $af_size[2] >= 2 && $af_size[2] <= 3) { // 2=JPG or 3=PNG
            $pic_jpg = $absolute_path."/images/rialto/entries/" . $entry_id . "_" .$imagenumber . ".jpg";
            if ( file_exists( $pic_jpg)) {
               unlink( $pic_jpg);
            }

            $pic_png = $absolute_path."/images/rialto/entries/" . $entry_id . "_" .$imagenumber . ".png";
            if ( file_exists( $pic_png)) {
               unlink( $pic_png);
            }

            $pic_gif = $absolute_path."/images/rialto/entries/" . $entry_id . "_" .$imagenumber . ".gif";
            if ( file_exists( $pic_gif)) {
               unlink( $pic_gif);
            }

            chmod ( $_FILES[$image]['tmp_name'], 0644);

            // 1. if directory ./entries/ENTRYID does not exist, create it
            // 2. create the subdirs for ORIGINAL, LARGE and SMALL
            if ( !is_dir( $image_folder.$entry_id)) {
               mkdir($image_folder.$entry_id);
               mkdir($image_folder.$entry_id."/original"); // ORIGINAL
               mkdir($image_folder.$entry_id."/large"); // LARGE
               mkdir($image_folder.$entry_id."/small"); // SMALL
            }

            $original_image = $image_folder.$entry_id."/original/".$entry_id . "_" . $imagenumber . "." . $thispicext;
            $large_image = $image_folder.$entry_id."/large/".$entry_id . "_" . $imagenumber . "." . $thispicext;
            $small_image = $image_folder.$entry_id."/small/".$entry_id . "_" . $imagenumber . "." . $thispicext;

            // copy original image to folder "original"
            move_uploaded_file ( $_FILES[$image]['tmp_name'], $original_image);

            // create "large" image
            switch ($af_size[2]) {
               case 1 : $src = ImageCreateFromGif(  $original_image); break;
               case 2 : $src = ImageCreateFromJpeg( $original_image); break;
               case 3 : $src = ImageCreateFromPng(  $original_image); break;
            }

            $width_before  = ImageSx( $src);
            $height_before = ImageSy( $src);

            if ( $width_before  >= $height_before) {
               $width_new = min( $max_big_image_x, $width_before);
               $scale = $width_before / $height_before;
               $height_new = round( $width_new / $scale);
            } else {
               $height_new = min( $max_big_image_y, $height_before);
               $scale = $height_before / $width_before;
               $width_new = round( $height_new / $scale);
            }

            $dst = ImageCreateTrueColor( $width_new, $height_new);

            // GD Lib 2
            ImageCopyResampled( $dst, $src, 0, 0, 0, 0, $width_new, $height_new, $width_before, $height_before);

            switch ($af_size[2]) {
               case 1 : ImageGIF(  $dst, $large_image); break;
               case 2 : ImageJPEG( $dst, $large_image); break;
               case 3 : ImagePNG(  $dst, $large_image); break;
            }

            imagedestroy( $dst);
            imagedestroy( $src);

            // create "small" image
            switch ($af_size[2]) {
               case 1 : $src = ImageCreateFromGif(  $original_image); break;
               case 2 : $src = ImageCreateFromJpeg( $original_image); break;
               case 3 : $src = ImageCreateFromPng(  $original_image); break;
            }

            $width_before  = ImageSx( $src);
            $height_before = ImageSy( $src);

            if ( $width_before  >= $height_before) {
               $width_new = min( $max_small_image_x, $width_before);
               $scale = $width_before / $height_before;
               $height_new = round( $width_new / $scale);
            } else {
               $height_new = min( $max_small_image_y, $height_before);
               $scale = $height_before / $width_before;
               $width_new = round( $height_new / $scale);
            }

            $dst = ImageCreateTrueColor( $width_new, $height_new);

            // GD Lib 2
            ImageCopyResampled( $dst, $src, 0, 0, 0, 0, $width_new, $height_new, $width_before, $height_before);

            switch ($af_size[2]) {
               case 1 : ImageGIF(  $dst, $small_image); break;
               case 2 : ImageJPEG( $dst, $small_image); break;
               case 3 : ImagePNG(  $dst, $small_image); break;
            }

            imagedestroy( $dst);
            imagedestroy( $src);

            // DB update
            $sql = "UPDATE #__rialto_entries ";
            $sql .= " SET ". $image . "='".$entry_id . "_" . $imagenumber . "." .$thispicext ."' WHERE id=" . $db->Quote($entry_id);

            $db->setQuery($sql);
            if ($db->getErrorNum()) {
               echo $db->stderr();
            } else {
               $db->execute();
            }
         }
      }
   }


   /**
    * @param $entry_id
    * @param $image
    * @param $absolute_path
    * @param $db
    * @param $imagenumber
    */
   public static function del_image( $entry_id, $image, $absolute_path, $db, $imagenumber)
   {
      $image_folder = $absolute_path."/images/rialto/entries/";

      // get image name
      $sql = "SELECT " . $image . " FROM #__rialto_entries WHERE id=".$entry_id;
      $db->setQuery( $sql);
      $imagename = $db->loadResult();

      if ( $imagename != "") {
         $original_image = $image_folder.$entry_id."/original/" . $imagename;
         $large_image = $image_folder.$entry_id."/large/" . $imagename;
         $small_image = $image_folder.$entry_id."/small/" . $imagename;

         if ( file_exists( $original_image)) {
            unlink( $original_image);
         }
         if ( file_exists( $large_image)) {
            unlink( $large_image);
         }
         if ( file_exists( $small_image)) {
            unlink( $small_image);
         }

         // DB update
         $sql = "UPDATE #__rialto_entries SET ". $image . "='' WHERE id=".$entry_id;
         $db->setQuery( $sql);

         if ($db->getErrorNum()) {
            echo $db->stderr();
         } else {
            $db->execute();
         }
      }
   }


   /**
    * @param $entry_id
    */
   public static function rm_imagefolder( $entry_id )
   {
      $db = JFactory::getDBO();
      // get folder name
      $rootDir = JPATH_ROOT;
      $folder = $rootDir . "/images/rialto/entries/" . $entry_id;

      // 1. delete all existing images for this entry
      // get image names
      $sql = "SELECT image1, image2, image3, image4, image5, image6, image7, image8, image9, image10 ";
      $sql .= " FROM #__rialto_entries WHERE id=".$entry_id;
      $db->setQuery( $sql);
      $rows = $db->loadObjectList();

      foreach ( $rows as $row ) {
         if ( $row->image1 != "") {
            self::del_image( $entry_id, "image1", $rootDir, $db, 1);
         }
         if ( $row->image2 != "") {
            self::del_image( $entry_id, "image2", $rootDir, $db, 2);
         }
         if ( $row->image3 != "") {
            self::del_image( $entry_id, "image3", $rootDir, $db, 3);
         }
         if ( $row->image4 != "") {
            self::del_image( $entry_id, "image4", $rootDir, $db, 4);
         }
         if ( $row->image5 != "") {
            self::del_image( $entry_id, "image5", $rootDir, $db, 5);
         }
         if ( $row->image6 != "") {
            self::del_image( $entry_id, "image6", $rootDir, $db, 6);
         }
         if ( $row->image7 != "") {
            self::del_image( $entry_id, "image7", $rootDir, $db, 7);
         }
         if ( $row->image8 != "") {
            self::del_image( $entry_id, "image8", $rootDir, $db, 8);
         }
         if ( $row->image9 != "") {
            self::del_image( $entry_id, "image9", $rootDir, $db, 9);
         }
         if ( $row->image10 != "") {
            self::del_image( $entry_id, "image10", $rootDir, $db, 10);
         }
      }

      // 2. remove all existing folders for this entry
      if (is_dir( $folder. "/original/")) {
         rmdir( $folder. "/original/");
      }
      if (is_dir( $folder. "/large/")) {
         rmdir( $folder. "/large/");
      }
      if (is_dir( $folder. "/small/")) {
         rmdir( $folder. "/small/");
      }
      if (is_dir( $folder)) {
         rmdir( $folder );
      }
   }

   /**
    * @param $vtype
    * @return string
    */
   function getVideotype($vtype)
   {
      $options = array(
         JHTML::_('select.option', '1', JText::_('COM_RIALTO_VTYPE_UTUBE') ),
         JHTML::_('select.option', '2', JText::_('COM_RIALTO_VTYPE_VIMEO') ),
      );

      return JHTML::_('select.genericlist', $options, 'vtype', null, 'value', 'text', '1');
   }

   /**
    * Checks if a remote file exists.
    * Mainly intended to check that remote video files exist in our usage.
    * @param     $ref
    * @param int $vtype
    * @param int $eid
    * @return bool
    */
   public static function checkRemoteFile($ref, $vtype = 1, $eid = 0 )
   {
      $params  = JComponentHelper::getParams('com_rialto');
      $logging = $params->get('enablelogging', '0');

      if ( $vtype == 1 ) {
         // UTube
         $url = "http://www.youtube.com/watch?v=".$ref;
         $youtube = "http://www.youtube.com/oembed?url=".$url."&format=json";

         $curl = curl_init($youtube);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         $rdata = curl_exec($curl);
         curl_close($curl);

         // We are not really interested in the video details just want to know it exists.
         //  return json_decode($return, true);
         // $vdata = json_decode($rdata);
         // echo "<pre>";var_dump($vdata);echo "</pre>";
         // print("Rdata: $rdata<p>");
         // There is no obvious consistency between Utube and Vimeo.
         //  If video does not exist then Utube returns 'Not found' Vimeo returns '404 Not Found'
         if ( strpos('404', $rdata) || empty($rdata)  || ($rdata == 'Not Found')  ) {
            if ( $logging) {
               if ( $eid != 0 ) {
                  RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG',$url), JLog::INFO);  // Log an error.
               } else {
                  RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG3',$url, $eid), JLog::INFO);  // Log an error.
               }
            }
            return false;
         } else {
            return true;
         }
      } elseif ( $vtype == 2) {
         // Vimeo
         $url = "http://www.vimeo.com/video/".$ref;
         $turl = 'http://www.vimeo.com/api/oembed.json?url=' . rawurlencode($url);
         // print("Test url: $turl<p>");
         $curl = curl_init($turl);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_TIMEOUT, 30);
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
         $rdata = curl_exec($curl);
         curl_close($curl);
         $vdata = json_decode($rdata);
         // echo "<pre>";var_dump($vdata);echo "</pre>";
         //print("Rdata: $rdata<p>");
         if ( strpos('404', $rdata) || empty($vdata) ) {
            if ( $logging ) {
               if ( $eid != 0 ) {
                  RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG',$url), JLog::INFO);  // Log an error.
               } else {
                  RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG3',$url, $eid), JLog::INFO);  // Log an error.
               }
            }
            return false;
         } else {
            return true;
         }
      }
      return false;
   }

   /**
    * Method to get the id of this category given the alias.
    *
    * @access public
    * @param null $name
    * @return int
    */
   public static function getCategoryId($name)
   {
      $db   = JFactory::getDBO();
      $categoryNameQuery = "SELECT id FROM ".$db->quoteName( '#__rialto_categories')." WHERE alias=" . $db->Quote($name);
      $db->setQuery( $categoryNameQuery);
      $cid = $db->loadResult();
      return $cid;
   }

   /**
    * Method to get the name of this category
    *
    * @access public
    * @param null $id
    * @return String
    */
   public static function getCategoryName($id )
   {
      $db   = JFactory::getDBO();
      $categoryNameQuery = "SELECT title FROM ".$db->quoteName( '#__rialto_categories')." WHERE id=" . $db->Quote($id);
      $db->setQuery( $categoryNameQuery);
      $catName = $db->loadResult();
      return $catName;
   }


   /**
    * Method to get the Slug of this category
    *
    * @access public
    * @param $id
    * @return String
    */
   public static function getCategorySlug($id)
   {
      $db   = JFactory::getDBO();
      $query = "SELECT ";
      $query .= 'CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(\':\', id, alias) ELSE id END ';
      $query .= " FROM ".$db->quoteName( '#__rialto_categories')." WHERE id=" . $db->Quote($id);
      $db->setQuery( $query);
      $catSlug = $db->loadResult();
      return $catSlug;
   }

   /**
    * Method to get the menu item for a component.
    *
    * @param   string    $comp      The specific component string we want.
    *
    * @return  string    The path to the itemid or one derived from input parameter.
    *
    */
   public static function getmenuitemId($comp = 'index.php?option=com_rialto&view=index')
   {
      // look if there is a menu item set for rialto. if yes, we use that one to redirect
      $db  = JFactory::getDBO();
      $query   = $db->getQuery(true);
      $query->select('id')
            ->from('#__menu')
            ->where('link LIKE '. $db->Quote($comp))
            ->setLimit('1');

      // Get current entries for the displayed language and 'all'.
      if ( JLanguageMultilang::isEnabled() )
         $query->where('language IN (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');

      $db->setQuery($query);
      $itemId = ($db->getErrorNum())? 0 : intval($db->loadResult());
      if($itemId) {
         $rpath = JRoute::_('index.php?Itemid='.$itemId);
      } else {
         $rpath = JRoute::_($comp);
      }
      return $rpath;
   }

   /**
    * Method to check if logged in user is a Rialto user.
    *
    * @param string $uid
    * @return bool True or false.
    *
    * @internal param int $id The unique idebntifier of the user.
    */
   public static function checkRialtoUser($uid = '0')
   {
      // look if there is a menu item set for rialto. if yes, we use that one to redirect
      $db  = JFactory::getDBO();
      $query   = $db->getQuery(true);
      $query->select('id')
            ->from('#__rialto_users')
            ->where('id = '. $db->Quote($uid));

      $db->setQuery($query);
      $res = intval($db->loadResult());
      if($res) {
         return true;
      }
      return false;
   }


   /**
    * Method to send a message to the subscribers when a new entry is created.
    *
    * @access public
    * @param $data
    * @param $pk
    * @return String
    */
   static function sendsubsmessage($data, $pk)
   {
      $app = JFactory::getApplication();
      $input = $app->input;

      // get parameters
      $params = JComponentHelper::getParams('com_rialto');
      $logging = $params->get('enablelogging', '0');

      $subopts = $params->get('subs_opts',0);

      if ( $logging )
         RialtoHelperLog::dblog('In helper method sendsubsmessage', JLog::INFO);

      $id = $data['id'];
      $cat_id = $data['category_id'];

      if ( $subopts == 0 || ( $subopts == 1 && $id > 0 ) ||
           ( $subopts == 2 && $id == 0 ) ) return true;

      // Get a db connection.
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);

      // Select all users who are subscribed to the category, order it by the username.
      $query
         ->select(array('u.email', 'u.username'))
         ->from($db->quoteName('#__rialto_users', 'u'))
         ->join('LEFT', $db->quoteName('#__rialto_cat_users', 'c') . ' ON (' . $db->quoteName('u.id') . ' = ' . $db->quoteName('c.user_id') . ')')
         ->where($db->quoteName('c.cat_id') . ' = '.$cat_id)
         ->order($db->quoteName('u.username') . ' DESC');

      // print("Query: $query<p>");

      // Reset the query using our newly populated query object.
      $db->setQuery($query);

      // Load the results as a list of stdClass objects.
      $results = $db->loadObjectList();

      // echo "<pre>";var_dump($results); echo "</pre>";

      if ( empty($results) ) {
         // die("Nothing to send. No subscribers.<p>");
         return true;
      } else {
         $msg = strip_tags($data['description']);
         if ( empty($msg) ) {
            if ($logging)
               RialtoHelperLog::dblog(JText::_('COM_RIALTO_EMPTY_MESSAGE_MSG'), JLog::WARNING);
            // $app->enqueueMessage( JText::_('COM_RIALTO_NO_MESSAGE_BODY_PROVIDED_MSG'), 'error');
            return false;
         }

         $mailto = '';
         // Build up mailto list. Will modify this based upon whether we are using BB or BCC.
         foreach ( $results AS $res ) {
            $mailto .= $res->email.',';
         }
         $mailto = rtrim($mailto,',');
         if (empty($mailto)) {
            if ($logging)
               RialtoHelperLog::dblog(JText::_('COM_RIALTO_NO_RECIPIENT_EMAIL_ADDRESS_PROVIDED_MSG'), JLog::ERROR);
            return false;
         }

         // Which one do we want?
         $mopt = $params->get('mail_opts',0);
         if ( $mopt == 1 ) {
            $mailcc = $mailto;
            $mailto = '';
         } elseif ( $mopt== 2 ) {
            $mailbcc = $mailto;
            $mailto = '';
         }

         $replyto       = $params->get('emailFrom');
         if (empty($replyto)) {
            if ($logging)
               RialtoHelperLog::dblog(JText::_('COM_RIALTO_NO_SENDER_EMAIL_ADDRESS_PROVIDED_MSG'), JLog::ERROR);
            return false;
         }
         if (!JMailHelper::isEmailAddress($replyto)) {
            if ($logging)
               RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_INVALID_FROM_ADDR_MSG', $replyto), JLog::ERROR);
            return false;
         }

         $replytoname   = $params->get( 'emailSender', '');
         if (empty($replytoname)) {
            if ($logging)
               RialtoHelperLog::dblog(JText::_('COM_RIALTO_NO_SENDER_CONTACT_NAME_PROVIDED_MSG'), JLog::ERROR);
            return false;
         }
         if ($logging)
            RialtoHelperLog::dblog('Sender name: '.$replytoname, JLog::INFO);

         $msgprefix  = $params->get('emailMSGMessagePrefixSubs', '');
         $msgpostfix = $params->get('emailMSGMessagePostfixSubs', '');
         $msgsubjectprefix = $params->get('emailMSGSubjectSubs', '');

         // determine url for new entry.
         if ( empty ($data['id'] ) ) {
            $url = JRoute::_(JURI::base().'index.php?option=com_rialto&view=entry&catid=' . $data['category_id'] . '&entry=' . $pk );
         } else {
           $url = JRoute::_(JURI::base().'index.php?option=com_rialto&view=entry&catid=' . $data['category_id'] . '&entry=' . $data['id'] );
         }

         if (!empty($msgprefix) ) {
            $message = $msgprefix;
         } else {
            $message = "";
         }

         $subs_hdr = JText::_('COM_RIALTO_MESSAGE_SUBS_HDR_TXT');
         if ( !empty($subs_hdr) ) $message .= $subs_hdr;

         $message .= JText::sprintf('COM_RIALTO_SUBS_TITLE_MSG', $data['title']);
         $message .= "<br /><br />".JText::_('COM_RIALTO_LINK_TITLE').' <a href="'.$url.'">'.JText::_('COM_RIALTO_ENTRY').' ';
         if ( empty ($data['id'] ) ) {
            $message .= $pk.'</a><br /><br />';
         } else {
            $message .= $data['id'].'</a><br /><br />';
         }
         $message .= JText::sprintf('COM_RIALTO_SUBS_DESC_MSG', $data['description']);

         if (!empty($msgpostfix) )
            $message .= $msgpostfix;

         $subs_ftr = JText::_('COM_RIALTO_MESSAGE_SUBS_FTR_TXT');
         if ( !empty($subs_ftr) ) $message .= $subs_ftr;

         if ($logging)
            RialtoHelperLog::dblog('Subscription message: '.$msg, JLog::INFO);

         // Clean the email data
         if ( $id == 0 ) {
            $subject = JText::_('COM_RIALTO_SUBS_NEW_ENTRY_MSG');
         } else {
            $subject = JText::sprintf('COM_RIALTO_SUBS_UPD_ENTRY_MSG', $id);
         }

         if (! empty($msgsubjectprefix) )
            $subject = $msgsubjectprefix . ' '.$subject;
         $body    = JMailHelper::cleanBody($message);
         $fromadr = JMailHelper::cleanAddress($replyto);
         $sender = "Rialto";

         //setup the mailer & create message
         $mail = JFactory::getMailer();
         $mail->isHTML(true);
         $mail->Encoding = 'base64';
         if ( ! empty($mailto) )
            $mail->addRecipient($mailto);
         if ( ! empty($mailbcc) )
            $mail->addBcc($mailbcc);
         if ( ! empty($mailcc) )
            $mail->addCc($mailcc);
         $mail->setSender($fromadr, $sender);
         if (!empty($replyto)) $mail->addReplyTo($replyto, $replytoname);
         $mail->setSubject($subject);
         $mail->setBody($body);

         try {
            $mail->Send();
            if ($logging)
               RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_SUBS_MESSAGES_SENT', $mailto), JLog::INFO);
         }
         catch (Exception $e) {
            RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_MESSAGE_SENDING_PROBLEM', $mailto), JLog::ERROR);
            RialtoHelperLog::dblog(__METHOD__.' -> '.$e->getTrace()[1]['function'].': '.$e->getMessage(), JLog::ERROR);
            return false;
         }
         unset($mail);

         return true;
      }
   }

}

Youez - 2016 - github.com/yon3zu
LinuXploit