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

/administrator/components/com_virtuemart/classes/ps_main.php

http://vanphongphamdm.googlecode.com/
PHP | 1342 lines | 873 code | 127 blank | 342 comment | 215 complexity | 477bc306eb7b42bbb97450b1d8f59f10 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, Apache-2.0
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. * This is no class! This file only provides core virtuemart functions.
  5. *
  6. * @version $Id: ps_main.php 2659 2010-11-21 11:25:33Z zanardi $
  7. * @package VirtueMart
  8. * @subpackage classes
  9. * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
  10. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  11. * VirtueMart is free software. This version may have been modified pursuant
  12. * to the GNU General Public License, and as distributed it includes or
  13. * is derivative of works licensed under the GNU General Public License or
  14. * other free or open source software licenses.
  15. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  16. *
  17. * http://virtuemart.net
  18. */
  19. /**
  20. * This function validates a given date and creates a timestamp
  21. * @deprecated
  22. *
  23. * @param array $d
  24. * @param string $field The name of the field
  25. * @param string $type
  26. * @return boolean
  27. */
  28. if(function_exists('date_default_timezone_set')){
  29. date_default_timezone_set('GMT0');
  30. }else{
  31. putenv("TZ=GMT");
  32. }
  33. function process_date_time(&$d,$field,$type="") {
  34. $month = $d["$field" . "_month"];
  35. $day = $d["$field" . "_day"];
  36. $year = $d["$field" . "_year"];
  37. $hour = $d["$field" . "_hour"];
  38. $minute = $d["$field" . "_minute"];
  39. $use = $d["$field" . "_use"];
  40. $valid = true;
  41. /* If user unchecked "Use date and time" then time = 0 */
  42. if (!$use) {
  43. $d[$field] = 0;
  44. return true;
  45. }
  46. if (!checkdate($month,$day,$year)) {
  47. $d["error"] .= "ERROR: $type date is invalid.";
  48. $valid = false;
  49. }
  50. if (!$hour and !$minute) {
  51. $hour = 0;
  52. $minute = 0;
  53. } elseif ($hour < 0 or $hour > 23 or $minute < 0 or $minute > 59) {
  54. $d["error"] .= "ERROR: $type time is invalid.";
  55. $valid = false;
  56. }
  57. if ($valid) {
  58. $d[$field] = mktime($hour,$minute,0,$month,$day,$year);
  59. }
  60. return $valid;
  61. }
  62. /**
  63. * Validates an email address by using regular expressions
  64. * Does not resolve the domain name!
  65. *
  66. * @param string $email
  67. * @return boolean The result of the validation
  68. */
  69. function vmValidateEmail( $email ) {
  70. $valid = preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $email );
  71. return $valid;
  72. }
  73. /**
  74. * Checks if a given string is a valid (from-)name or subject for an email
  75. *
  76. * @since 1.0.7
  77. * @param string $string String to check for validity
  78. * @return boolean
  79. */
  80. function vmValidateName( $string ) {
  81. /*
  82. * The following regular expression blocks all strings containing any low control characters:
  83. * 0x00-0x1F, 0x7F
  84. * These should be control characters in almost all used charsets.
  85. * The high control chars in ISO-8859-n (0x80-0x9F) are unused (e.g. http://en.wikipedia.org/wiki/ISO_8859-1)
  86. * Since they are valid UTF-8 bytes (e.g. used as the second byte of a two byte char),
  87. * they must not be filtered.
  88. */
  89. $invalid = preg_match( '/[\x00-\x1F\x7F]/', $string );
  90. if ($invalid) {
  91. return false;
  92. } else {
  93. return true;
  94. }
  95. }
  96. /**
  97. * Validates an EU-vat number
  98. * @author Steve Endredy
  99. * @param string $euvat EU-vat number to validate
  100. * @return boolean The result of the validation
  101. */
  102. function vmValidateEUVat( $euvat ){
  103. require_once( CLASSPATH . 'nusoap/nusoap.php' );
  104. require_once( CLASSPATH . 'euvatcheck.class.php' );
  105. $GLOBALS['vmLogger']->debug( 'Checking for valid EU VAT ID' );
  106. $vatcheck = new VmEUVatCheck($euvat);
  107. return $vatcheck->validvatid;
  108. }
  109. /**
  110. * Returns the current time in microseconds
  111. *
  112. * @return float current time in microseconds
  113. */
  114. function utime()
  115. {
  116. list($usec, $sec) = explode(" ", microtime());
  117. return ((float)$usec + (float)$sec);
  118. }
  119. /**
  120. * Checks if $item is in $list
  121. *
  122. * @param array $list
  123. * @param string $item
  124. * @return mixed An integer representing the postion of $item in $list, false when not in list
  125. */
  126. function in_list($list, $item) {
  127. for ($i=0;$i<$list["cnt"];$i++) {
  128. if (!strcmp($list[$i]["name"],$item)) {
  129. return $i;
  130. }
  131. }
  132. return False;
  133. }
  134. /**
  135. * reads a file and returns its content as a string
  136. *
  137. * @param string $file The path to the file that shall be read
  138. * @param string $defaultfile The path to the file to is read when $file doesn't exist
  139. * @return string The file contents
  140. */
  141. function read_file( $file, $defaultfile='' ) {
  142. // open the HTML file and read it into $html
  143. if (file_exists( $file )) {
  144. $html_file = fopen( $file, "r" );
  145. }
  146. elseif( !empty( $defaultfile ) && file_exists( $defaultfile ) ) {
  147. $html_file = fopen( $defaultfile, "r" );
  148. }
  149. else {
  150. return;
  151. }
  152. if( $html_file === false ) {
  153. $GLOBALS['vmLogger']->err( 'Could not open '.basename( $file ).'.' );
  154. return;
  155. }
  156. $html = "";
  157. while (!feof($html_file)) {
  158. $buffer = fgets($html_file, 1024);
  159. $html .= $buffer;
  160. }
  161. fclose ($html_file);
  162. return( $html );
  163. }
  164. /**
  165. * Includes all needed classes for a core module and create + populate the objects
  166. *
  167. * @param string $module The name of the virtuemart core module
  168. */
  169. function include_class($module) {
  170. // globalize the vars so that they can be used outside of this function
  171. global $VM_LANG, $ps_vendor, $ps_affiliate, $ps_manufacturer, $ps_manufacturer_category,
  172. $ps_user, $ps_vendor_category, $ps_checkout, $ps_intershipper, $ps_shipping, $ps_order, $ps_order_status,
  173. $ps_product,$ps_product_category , $ps_product_attribute,
  174. $ps_product_type, // Changed Product Type
  175. $ps_product_type_parameter, // Changed Product Type
  176. $ps_product_product_type, // Changed Product Type
  177. $ps_product_price, $nh_report, $ps_payment_method, $ps_shopper, $ps_shopper_group,
  178. $ps_cart, $ps_zone,$ps_tax, $zw_waiting_list;
  179. $VM_LANG->load($module);
  180. switch ( $module ) {
  181. case "account":
  182. break;
  183. case "admin" :
  184. // Load class files
  185. require_once(CLASSPATH. 'ps_html.php' );
  186. require_once(CLASSPATH. 'ps_function.php' );
  187. require_once(CLASSPATH. 'ps_module.php' );
  188. require_once(CLASSPATH. 'ps_perm.php' );
  189. require_once(CLASSPATH. 'ps_user.php' );
  190. require_once(CLASSPATH. 'ps_user_address.php' );
  191. //Instantiate Classes
  192. $ps_html = new ps_html;
  193. $ps_function = new ps_function;
  194. $ps_module= new ps_module;
  195. $ps_perm= new ps_perm;
  196. $ps_user= new ps_user;
  197. $ps_user_address = new ps_user_address;
  198. break;
  199. case "checkout" :
  200. // Load class file
  201. require_once(CLASSPATH. 'ps_checkout.php' );
  202. //Instantiate Class
  203. //$ps_checkout = new ps_checkout;
  204. break;
  205. case "order" :
  206. // Load classes
  207. require_once(CLASSPATH.'ps_order.php' );
  208. require_once(CLASSPATH.'ps_order_status.php' );
  209. // Instantiate Classes
  210. $ps_order = new ps_order;
  211. $ps_order_status = new ps_order_status;
  212. break;
  213. case "product" :
  214. // Load Classes
  215. require_once(CLASSPATH.'ps_product.php' );
  216. require_once(CLASSPATH.'ps_product_category.php' );
  217. require_once(CLASSPATH.'ps_product_attribute.php' );
  218. require_once(CLASSPATH.'ps_product_type.php' ); // Changed Product Type
  219. require_once(CLASSPATH.'ps_product_type_parameter.php' ); // Changed Product Type
  220. require_once(CLASSPATH.'ps_product_product_type.php' ); // Changed Product Type
  221. require_once(CLASSPATH.'ps_product_price.php' );
  222. // Instantiate Classes
  223. $ps_product = new ps_product;
  224. $ps_product_category = new ps_product_category;
  225. $ps_product_attribute = new ps_product_attribute;
  226. $ps_product_type = new ps_product_type; // Changed Product Type
  227. $ps_product_type_parameter = new ps_product_type_parameter; // Changed Product Type
  228. $ps_product_product_type = new ps_product_product_type; // Changed Product Type
  229. $ps_product_price = new ps_product_price;
  230. break;
  231. case "reportbasic" :
  232. // Load Classes
  233. require_once( CLASSPATH . 'ps_reportbasic.php');
  234. $nh_report = new nh_report;
  235. break;
  236. case "shipping" :
  237. // Load Class
  238. require_once( CLASSPATH . 'ps_shipping.php');
  239. // Instantiate Class
  240. $ps_shipping = new ps_shipping;
  241. break;
  242. case "shop" :
  243. // Load Classes
  244. require_once( CLASSPATH. 'ps_cart.php' );
  245. require_once( CLASSPATH. 'zw_waiting_list.php');
  246. // Instantiate Classes
  247. $ps_cart = new ps_cart;
  248. $zw_waiting_list = new zw_waiting_list;
  249. break;
  250. case "shopper" :
  251. // Load Classes
  252. require_once( CLASSPATH . 'ps_shopper.php' );
  253. require_once( CLASSPATH . 'ps_shopper_group.php' );
  254. // Instantiate Classes
  255. $ps_shopper = new ps_shopper;
  256. $ps_shopper_group = new ps_shopper_group;
  257. break;
  258. case "store" :
  259. // Load Classes
  260. require_once( CLASSPATH . 'ps_payment_method.php' );
  261. // Instantiate Classes
  262. $ps_payment_method = new ps_payment_method;
  263. break;
  264. case "tax" :
  265. // Load Classes
  266. require_once ( CLASSPATH . 'ps_tax.php' );
  267. // Instantiate Classes
  268. $ps_tax = new ps_tax;
  269. break;
  270. case "vendor" :
  271. // Load Classes
  272. require_once (CLASSPATH . 'ps_vendor.php' );
  273. require_once (CLASSPATH . 'ps_vendor_category.php' );
  274. // Instantiate Classes
  275. $ps_vendor = new ps_vendor;
  276. $ps_vendor_category = new ps_vendor_category;
  277. break;
  278. case "zone" :
  279. // Load Class
  280. require_once (CLASSPATH . 'ps_zone.php');
  281. // Instantiate Class
  282. $ps_zone = new ps_zone;
  283. break;
  284. case "manufacturer" :
  285. require_once (CLASSPATH . 'ps_manufacturer.php');
  286. require_once (CLASSPATH . 'ps_manufacturer_category.php');
  287. $ps_manufacturer = new ps_manufacturer;
  288. $ps_manufacturer_category = new ps_manufacturer_category;
  289. break;
  290. }
  291. }
  292. /**
  293. * Login validation function
  294. *
  295. * Username and encoded password is compared to db entries in the mos_users
  296. * table. A successful validation returns true, otherwise false
  297. */
  298. function vmCheckPass() {
  299. global $database, $perm, $my, $mainframe;
  300. // only allow access to admins or storeadmins
  301. if( $perm->check("admin,storeadmin")) {
  302. $username = $my->username;
  303. $passwd_plain = $passwd = trim( vmGet( $_POST, 'passwd', '' ) );
  304. if( empty( $passwd_plain )) {
  305. $GLOBALS['vmLogger']->err( 'Password empty!');
  306. return false;
  307. }
  308. $passwd = md5( $passwd );
  309. $bypost = 1;
  310. if (!$username || !$passwd || $_REQUEST['option'] != "com_virtuemart") {
  311. return false;
  312. } elseif( vmIsJoomla('1.5') ) {
  313. $credentials = array();
  314. $credentials['username'] = $username;
  315. $credentials['password'] = $passwd_plain;
  316. $options = array();
  317. jimport( 'joomla.user.authentication');
  318. $authenticate = & JAuthentication::getInstance();
  319. $response = $authenticate->authenticate($credentials, $options);
  320. if ($response->status === JAUTHENTICATE_STATUS_SUCCESS) {
  321. return true;
  322. } else {
  323. return false;
  324. }
  325. } else {
  326. if( vmIsJoomla('1.0.12', '<=', false )) {
  327. $database->setQuery( "SELECT id, gid, block, usertype"
  328. . "\nFROM #__users"
  329. . "\nWHERE username='$username' AND password='$passwd'"
  330. );
  331. $row = null;
  332. $res = $database->loadObject( $row );
  333. } else {
  334. $query = "SELECT id, name, username, password, usertype, block, gid"
  335. . "\n FROM #__users"
  336. . "\n WHERE username = ". $database->Quote( $username );
  337. $database->setQuery( $query );
  338. $row = null;
  339. $database->loadObject( $row );
  340. list($hash, $salt) = explode(':', $row->password);
  341. $cryptpass = md5($passwd_plain.$salt);
  342. $res = $hash == $cryptpass;
  343. }
  344. if ($res) {
  345. return true;
  346. }
  347. else {
  348. $GLOBALS['vmLogger']->err( 'The Password you\'ve entered is not correct for your User Account');
  349. return false;
  350. }
  351. }
  352. }
  353. return false;
  354. }
  355. /**
  356. * Formerly used to print a search header for lists
  357. * use class listFactory instead
  358. * @deprecated
  359. *
  360. */
  361. function search_header() {
  362. echo "### THIS FUNCTION IS DEPRECATED. Use the class listFactory instead. ###";
  363. }
  364. /**
  365. * Formerly used to print a search header for lists
  366. * use class listFactory instead
  367. * @deprecated
  368. *
  369. */
  370. function search_footer() {
  371. echo "### THIS FUNCTION IS DEPRECATED. Use the class listFactory instead. ###";
  372. }
  373. /**
  374. * Used by the frontend adminsitration to save editor field contents
  375. *
  376. * @param string $editor1 the name of the editor field no. 1
  377. * @param string $editor2 the name of the editor field no. 2
  378. */
  379. function editorScript($editor1='', $editor2='') {
  380. ?>
  381. <script type="text/javascript">
  382. function submitbutton(pressbutton) {
  383. var form = document.adminForm;
  384. if (pressbutton == 'cancel') {
  385. submitform( pressbutton );
  386. return;
  387. }
  388. <?php
  389. if ($editor1 != '') {
  390. if( vmIsJoomla(1.5) ) {
  391. jimport('joomla.html.editor');
  392. $editor = JEditor::getInstance($GLOBALS['mainframe']->getCfg('editor'));
  393. echo $editor->getContent('editor1');
  394. } else {
  395. getEditorContents( 'editor1', $editor1 );
  396. }
  397. }
  398. if ($editor2 != '') {
  399. if( vmIsJoomla(1.5) ) {
  400. jimport('joomla.html.editor');
  401. $editor = JEditor::getInstance($GLOBALS['mainframe']->getCfg('editor'));
  402. echo $editor->getContent('editor2');
  403. } else {
  404. getEditorContents( 'editor2', $editor2 );
  405. }
  406. } ?>
  407. submitform( pressbutton );
  408. }
  409. </script><?php
  410. }
  411. /**
  412. * Function to create an email object for further use (uses phpMailer)
  413. * @param string From e-mail address
  414. * @param string From name
  415. * @param string E-mail subject
  416. * @param string Message body
  417. * @return phpMailer Mail object
  418. */
  419. function vmCreateMail( $from='', $fromname='', $subject='', $body='' ) {
  420. global $mosConfig_absolute_path, $mosConfig_sendmail;
  421. global $mosConfig_smtpauth, $mosConfig_smtpuser;
  422. global $mosConfig_smtppass, $mosConfig_smtphost;
  423. global $mosConfig_smtpport, $mosConfig_smtpsecure;
  424. global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_mailer;
  425. $phpmailer_classname='phpmailer';
  426. if( file_exists( $mosConfig_absolute_path . '/libraries/phpmailer/phpmailer.php') ) {
  427. $phpmailer_path = $mosConfig_absolute_path . '/libraries/phpmailer/phpmailer.php';
  428. }elseif( file_exists( $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php')) {
  429. $phpmailer_path = $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php';
  430. $phpmailer_classname = 'mosphpmailer';
  431. }
  432. require_once( $phpmailer_path );
  433. if( class_exists( $phpmailer_classname )) {
  434. $mail = new $phpmailer_classname();
  435. }
  436. $phpmailer_path = dirname( $phpmailer_path );
  437. $mail->PluginDir = $phpmailer_path .'/';
  438. $mail->SetLanguage( 'en', $phpmailer_path . '/language/' );
  439. $mail->CharSet = vmGetCharset();
  440. $mail->IsMail();
  441. $mail->From = $from ? $from : $mosConfig_mailfrom;
  442. $mail->FromName = $fromname ? $fromname : $mosConfig_fromname;
  443. $mail->Sender = $from ? $from : $mosConfig_mailfrom;
  444. $mail->Mailer = $mosConfig_mailer;
  445. // Add smtp values if needed
  446. if ( $mosConfig_mailer == 'smtp' ) {
  447. $mail->SMTPAuth = $mosConfig_smtpauth;
  448. $mail->Username = $mosConfig_smtpuser;
  449. $mail->Password = $mosConfig_smtppass;
  450. $mail->Host = $mosConfig_smtphost;
  451. $mail->Port = $mosConfig_smtpport;
  452. if ( $mosConfig_smtpsecure != "none" ) $mail->SMTPSecure = $mosConfig_smtpsecure;
  453. } else
  454. // Set sendmail path
  455. if ( $mosConfig_mailer == 'sendmail' ) {
  456. if (isset($mosConfig_sendmail))
  457. $mail->Sendmail = $mosConfig_sendmail;
  458. } // if
  459. if( $subject ) {
  460. $mail->Subject = vmAbstractLanguage::safe_utf8_encode( $subject, $mail->CharSet );
  461. }
  462. if( $body) {
  463. $mail->Body = $body;
  464. }
  465. // Patch to get correct Line Endings
  466. switch( substr( strtoupper( PHP_OS ), 0, 3 ) ) {
  467. case "WIN":
  468. $mail->LE = "\r\n";
  469. break;
  470. case "MAC": // Mac OS9
  471. $mail->LE = "\r";
  472. break;
  473. case "DAR": // Mac OSX
  474. default: // change nothing
  475. break;
  476. }
  477. return $mail;
  478. }
  479. /**
  480. * Mail function (uses phpMailer)
  481. * @param string From e-mail address
  482. * @param string From name
  483. * @param string/array Recipient e-mail address(es)
  484. * @param string E-mail subject
  485. * @param string Message body
  486. * @param boolean false = plain text, true = HTML
  487. * @param string/array CC e-mail address(es)
  488. * @param string/array BCC e-mail address(es)
  489. * @param array Images path,cid,name,filename,encoding,mimetype
  490. * @param string/array Attachment file name(s)
  491. * @return boolean Mail send success
  492. */
  493. function vmMail($from, $fromname, $recipient, $subject, $body, $Altbody='', $mode=false, $cc=NULL, $bcc=NULL, $images=null, $attachment=null, $replyto=null ) {
  494. global $mosConfig_debug;
  495. // Filter from, fromname and subject
  496. if (!vmValidateEmail( $from ) || !vmValidateName( $fromname ) || !vmValidateName( $subject )) {
  497. return false;
  498. }
  499. $mail = vmCreateMail( $from, $fromname, $subject, $body );
  500. if( $Altbody != "" ) {
  501. // In this section we take care for utf-8 encoded mails
  502. $mail->AltBody = vmAbstractLanguage::safe_utf8_encode( $Altbody, $mail->CharSet );
  503. }
  504. // activate HTML formatted emails
  505. if ( $mode ) {
  506. $mail->IsHTML(true);
  507. }
  508. if( $mail->ContentType == "text/plain" ) {
  509. $mail->Body = vmAbstractLanguage::safe_utf8_encode( $mail->Body, $mail->CharSet );
  510. }
  511. if( is_array($recipient) ) {
  512. foreach ($recipient as $to) {
  513. if( vmValidateEmail( $to )) {
  514. $mail->AddAddress($to);
  515. }
  516. }
  517. } else {
  518. if( vmValidateEmail( $recipient )) {
  519. $mail->AddAddress($recipient);
  520. }
  521. }
  522. if (isset($cc)) {
  523. if( is_array($cc) )
  524. foreach ($cc as $to) {
  525. if( vmValidateEmail( $to )) {
  526. $mail->AddCC($to);
  527. }
  528. }
  529. else {
  530. if( vmValidateEmail( $cc )) {
  531. $mail->AddCC($cc);
  532. }
  533. }
  534. }
  535. if (isset($bcc)) {
  536. if( is_array($bcc) )
  537. foreach ($bcc as $to) {
  538. if( vmValidateEmail( $to )) {
  539. $mail->AddBCC($to);
  540. }
  541. }
  542. else {
  543. if( vmValidateEmail( $bcc )) {
  544. $mail->AddBCC($bcc);
  545. }
  546. }
  547. }
  548. if( !empty($replyto) && vmValidateEmail( $replyto )) {
  549. $mail->AddReplyTo($replyto);
  550. }
  551. if( $images ) {
  552. foreach( $images as $image) {
  553. $mail->AddEmbeddedImage( $image['path'], $image['name'], $image['filename'], $image['encoding'], $image['mimetype']);
  554. }
  555. }
  556. if ($attachment) {
  557. if ( is_array($attachment) )
  558. foreach ($attachment as $fname) $mail->AddAttachment($fname);
  559. else
  560. $mail->AddAttachment($attachment);
  561. }
  562. $mailssend = $mail->Send();
  563. if( $mosConfig_debug ) {
  564. //$mosDebug->message( "Mails send: $mailssend");
  565. }
  566. if( $mail->error_count > 0 ) {
  567. //$mosDebug->message( "The mail message $fromname <$from> about $subject to $recipient <b>failed</b><br /><pre>$body</pre>", false );
  568. //$mosDebug->message( "Mailer Error: " . $mail->ErrorInfo . "" );
  569. }
  570. return $mailssend;
  571. }
  572. // $ Id: html_entity_decode.php,v 1.7 2005/01/26 04:55:13 aidan Exp $
  573. if (!defined('ENT_NOQUOTES')) {
  574. define('ENT_NOQUOTES', 0);
  575. }
  576. if (!defined('ENT_COMPAT')) {
  577. define('ENT_COMPAT', 2);
  578. }
  579. if (!defined('ENT_QUOTES')) {
  580. define('ENT_QUOTES', 3);
  581. }
  582. /**
  583. * Replace html_entity_decode()
  584. *
  585. * @category PHP
  586. * @package PHP_Compat
  587. * @link http://php.net/function.html_entity_decode
  588. * @author David Irvine <dave@codexweb.co.za>
  589. * @author Aidan Lister <aidan@php.net>
  590. * @since PHP 4.3.0
  591. * @internal Setting the charset will not do anything
  592. * @require PHP 4.0.0 (user_error)
  593. */
  594. function vmHtmlEntityDecode($string, $quote_style = ENT_COMPAT, $charset = null) {
  595. if( function_exists('html_entity_decode')) {
  596. return @html_entity_decode( $string, $quote_style, $charset );
  597. }
  598. if (!is_int($quote_style) && !is_null($quote_style)) {
  599. user_error(__FUNCTION__.'() expects parameter 2 to be long, ' .
  600. gettype($quote_style) . ' given', E_USER_WARNING);
  601. return;
  602. }
  603. $trans_tbl = get_html_translation_table(HTML_ENTITIES);
  604. $trans_tbl = array_flip($trans_tbl);
  605. // Add single quote to translation table;
  606. $trans_tbl['&#039;'] = '\'';
  607. // Not translating double quotes
  608. if ($quote_style & ENT_NOQUOTES) {
  609. // Remove double quote from translation table
  610. unset($trans_tbl['&quot;']);
  611. }
  612. return strtr($string, $trans_tbl);
  613. }
  614. /**
  615. * Unescapes REQUEST values if magic_quotes_gpc is set
  616. *
  617. * @param string $string The string to strip slashes from
  618. * @return string
  619. * @since 1.1.0
  620. */
  621. function vmGetUnEscaped( $string ) {
  622. if (get_magic_quotes_gpc()==1) {
  623. // if (ini_get('magic_quotes_sybase')) return str_replace("''","'",$string);
  624. return ( stripslashes( $string )); // this does not handle it correctly if magic_quotes_sybase is ON.
  625. } else {
  626. return ( $string );
  627. }
  628. }
  629. /**
  630. * Reads a file and sends them in chunks to the browser
  631. * This should overcome memory problems
  632. * http://www.php.net/manual/en/function.readfile.php#54295
  633. *
  634. * @since 1.0.3
  635. * @param string $filename
  636. * @param boolean $retbytes
  637. * @return mixed
  638. */
  639. function vmReadFileChunked($filename,$retbytes=true) {
  640. $chunksize = 1*(1024*1024); // how many bytes per chunk
  641. $buffer = '';
  642. $cnt =0;
  643. // $handle = fopen($filename, 'rb');
  644. $handle = fopen($filename, 'rb');
  645. if ($handle === false) {
  646. return false;
  647. }
  648. // Prevent time outs on big files
  649. @set_time_limit(0);
  650. // PHP on Windows has a useless "usleep" function until 5.0.0
  651. if( substr( strtoupper( PHP_OS ), 0, 3 ) == 'WIN' && version_compare( phpversion(), '5.0' ) < 0 ) {
  652. $sleepfunc = 'sleep';
  653. $time = 1; // sec.
  654. } else {
  655. $sleepfunc = 'usleep';
  656. $time = 100; // msec.
  657. }
  658. while (!feof($handle)) {
  659. $buffer = fread($handle, $chunksize);
  660. echo $buffer;
  661. $sleepfunc($time);
  662. @ob_flush();
  663. flush();
  664. if ($retbytes) {
  665. $cnt += strlen($buffer);
  666. }
  667. }
  668. $status = fclose($handle);
  669. if ($retbytes && $status) {
  670. return $cnt; // return num. bytes delivered like readfile() does.
  671. }
  672. return $status;
  673. }
  674. /**
  675. * Returns the charset string from the global _ISO constant
  676. *
  677. * @return string UTF-8 by default
  678. * @since 1.0.5
  679. */
  680. function vmGetCharset() {
  681. $iso = explode( '=', @constant('_ISO') );
  682. if( !empty( $iso[1] )) {
  683. return $iso[1];
  684. }
  685. else {
  686. return 'UTF-8';
  687. }
  688. }
  689. /**
  690. * Create a file system - safe file name
  691. *
  692. * @param string $filename
  693. * @since 1.1.0
  694. */
  695. function vmSafeFileName( $filename ) {
  696. $filename = preg_replace('/[^a-zA-Z0-9\.]/', '_', $filename );
  697. return $filename;
  698. }
  699. function vmIsAdminMode() {
  700. global $page;
  701. return ( (defined( '_VM_IS_BACKEND' )
  702. || @$_REQUEST['pshop_mode'] == 'admin'
  703. || strstr($page,'_list')
  704. || strstr($page,'_print')
  705. || strstr($page,'_cfg')
  706. || strstr($page,'_form'))
  707. && ( strncmp('account.',$page, 8) !== 0
  708. && strncmp('checkout.',$page, 9) !== 0
  709. && strncmp('shop.',$page, 5) !== 0
  710. )
  711. );
  712. }
  713. function vmCreateHash( $seed='virtuemart' ) {
  714. return md5( ENCODE_KEY . md5( $seed ) );
  715. }
  716. /**
  717. * Generate a random password
  718. *
  719. * @static
  720. * @param int $length Length of the password to generate
  721. * @return string Random Password
  722. * @since 1.1
  723. */
  724. function vmGenRandomPassword($length = 8)
  725. {
  726. $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  727. $len = strlen($salt);
  728. $makepass = '';
  729. mt_srand(10000000 * (double) microtime());
  730. for ($i = 0; $i < $length; $i ++) {
  731. $makepass .= $salt[mt_rand(0, $len -1)];
  732. }
  733. return $makepass;
  734. }
  735. /**
  736. * Equivalent to Joomla's josSpoofCheck function
  737. * @author Joomla core team
  738. *
  739. * @param boolean $header
  740. * @param unknown_type $alt
  741. */
  742. function vmSpoofCheck( $header=NULL, $alt=NULL ) {
  743. global $vm_mainframe;
  744. if( !empty( $_GET['vmtoken']) || !empty( $_POST['vmtoken'])) {
  745. $validate_hash = vmGet( $_REQUEST, 'vmtoken', null );
  746. $validate = vmSpoofValue($alt) == $validate_hash;
  747. } else {
  748. $validate = vmGet( $_REQUEST, vmSpoofValue($alt), 0 );
  749. }
  750. // probably a spoofing attack
  751. if (!$validate) {
  752. header( 'HTTP/1.0 403 Forbidden' );
  753. $vm_mainframe->errorAlert( 'Sorry, but we could not verify your Security Token.\nGo back and try again please.' );
  754. return false;
  755. }
  756. // First, make sure the form was posted from a browser.
  757. // For basic web-forms, we don't care about anything
  758. // other than requests from a browser:
  759. if (!isset( $_SERVER['HTTP_USER_AGENT'] )) {
  760. header( 'HTTP/1.0 403 Forbidden' );
  761. $vm_mainframe->errorAlert( 'Sorry, but we could not identify your web browser.\nBut this is necessary for using this web page.' );
  762. return false;
  763. }
  764. /* //NOTE: this is not really necessary, because GET request should also be allowed.
  765. // Make sure the request was done using "POST"
  766. if (!$_SERVER['REQUEST_METHOD'] == 'POST' ) {
  767. header( 'HTTP/1.0 403 Forbidden' );
  768. $vm_mainframe->errorAlert( $VM_LANG->_('NOT_AUTH') );
  769. return false;
  770. }
  771. */
  772. if ($header) {
  773. // Attempt to defend against header injections:
  774. $badStrings = array(
  775. 'Content-Type:',
  776. 'MIME-Version:',
  777. 'Content-Transfer-Encoding:',
  778. 'bcc:',
  779. 'cc:'
  780. );
  781. // Loop through each POST'ed value and test if it contains
  782. // one of the $badStrings:
  783. foreach ($_POST as $k => $v){
  784. foreach ($badStrings as $v2) {
  785. if (strpos( $v, $v2 ) !== false) {
  786. header( "HTTP/1.0 403 Forbidden" );
  787. $vm_mainframe->errorAlert( 'We are sorry, but using E-Mail Headers in Fields is not allowed.' );
  788. return false;
  789. }
  790. }
  791. }
  792. // Made it past spammer test, free up some memory
  793. // and continue rest of script:
  794. unset($k, $v, $v2, $badStrings);
  795. }
  796. return true;
  797. }
  798. /**
  799. * Equivalent to Joomla's josSpoofValue function
  800. *
  801. * @param boolean $alt
  802. * @return string Validation Hash
  803. */
  804. function vmSpoofValue($alt=NULL) {
  805. global $auth, $mainframe, $_VERSION;
  806. if ($alt) {
  807. if ( $alt == 1 ) {
  808. $random = date( 'Ymd' );
  809. } else {
  810. $random = $alt . date( 'Ymd' );
  811. }
  812. } else {
  813. $random = date( 'dmY' );
  814. }
  815. $validate = vmCreateHash( $mainframe->getCfg( 'db' ) . $random . $auth['user_id']);
  816. if( $_VERSION->DEV_LEVEL >= 11 ) {
  817. // Joomla 1.0.11 compatibility workaround
  818. // the prefix ensures that the hash is non-numeric
  819. // otherwise it will be intercepted by globals.php
  820. $validate = 'j' . $validate;
  821. }
  822. return $validate;
  823. }
  824. /**
  825. * This function creates the superglobal variable $product_currency
  826. * This variable is used for currency conversion
  827. *
  828. */
  829. function vmSetGlobalCurrency(){
  830. global $vendor_accepted_currencies, $vendor_currency, $vmLogger;
  831. if( !defined('_VM_IS_BACKEND') && empty( $_REQUEST['ajax_request']) && empty($_REQUEST['pshop_mode'])) {
  832. if( isset( $_REQUEST['product_currency']) ) {
  833. $GLOBALS['product_currency'] = $_SESSION['product_currency'] = vmGet($_REQUEST, 'product_currency' );
  834. }
  835. }
  836. $GLOBALS['product_currency'] = vmGet($_SESSION, 'product_currency', $vendor_currency);
  837. // Check if the selected currency is accepted! (the vendor currency is always accepted)
  838. if( $GLOBALS['product_currency'] != $vendor_currency ) {
  839. if( empty( $vendor_accepted_currencies )) {
  840. $vendor_accepted_currencies = $vendor_currency;
  841. }
  842. $page = vmGet($_REQUEST,'page');
  843. $acceptedCurrencies = explode(',', $vendor_accepted_currencies );
  844. if( !in_array( $GLOBALS['product_currency'], $acceptedCurrencies)
  845. && (stristr( $page, 'checkout.') || stristr( $page, 'account.') || stristr( $page, 'shop.cart')) ) {
  846. // Fallback to global vendor currency (as set in the store form)
  847. $vmLogger->warning( 'The Currency you had selected ('.$GLOBALS['product_currency'].') is not accepted for Checkout.');
  848. $GLOBALS['product_currency'] = $vendor_currency;
  849. }
  850. }
  851. }
  852. function vmIsJoomla( $version='', $operator='=', $compare_minor_versions=true) {
  853. global $_VERSION;
  854. $this_version = '';
  855. if( !empty($_VERSION) && is_object($_VERSION)) {
  856. $jversion =& $_VERSION;
  857. $this_version = $jversion->RELEASE;
  858. }
  859. elseif ( defined('JVERSION')) {
  860. $jversion = new JVersion();
  861. $this_version = $jversion->RELEASE;
  862. } else {
  863. include_once( $GLOBALS['mosConfig_absolute_path'].'/includes/version.php' );
  864. $jversion =& $_VERSION;
  865. $this_version = $jversion->RELEASE;
  866. }
  867. if( !$compare_minor_versions ) $this_version .= '.'. $jversion->DEV_LEVEL;
  868. if( empty( $version ) ) {
  869. return !empty($this_version) && strtolower($jversion->PRODUCT) == 'joomla!';
  870. }
  871. $allowed_operators = array( '<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne' );
  872. if( $compare_minor_versions ) {
  873. if( $jversion->RELEASE != $version ) {
  874. return false;
  875. }
  876. }
  877. if( in_array($operator, $allowed_operators )) {
  878. return version_compare( $this_version, $version, $operator );
  879. }
  880. return false;
  881. }
  882. function vmIsHttpsMode() {
  883. return ($_SERVER['SERVER_PORT'] == 443 || @$_SERVER['HTTPS'] == 'on');
  884. }
  885. /**
  886. * Checks if the Request is a XML HTTP Request (via Ajax)
  887. * @since 1.1.1
  888. * @return boolean
  889. */
  890. function vmIsXHR() {
  891. return strtolower(vmGet($_SERVER,'HTTP_X_REQUESTED_WITH')) == 'xmlhttprequest'
  892. || vmGet($_REQUEST,'ajax_request') == '1';
  893. }
  894. /**
  895. * Utility function redirect the browser location to another url
  896. *
  897. * Can optionally provide a message.
  898. * @param string The URL to redirect to
  899. * @param string A Message to display to the user
  900. */
  901. function vmRedirect( $url, $msg='' ) {
  902. if( function_exists('mosRedirect')) {
  903. mosRedirect($url, $msg );
  904. } elseif( vmIsJoomla( '1.5', '>=' ) ) {
  905. global $mainframe;
  906. $mainframe->redirect( $url, $msg );
  907. } else {
  908. global $mainframe;
  909. // specific filters
  910. $iFilter = vmInputFilter::getInstance();
  911. $url = $iFilter->process( $url );
  912. if (!empty($msg)) {
  913. $msg = $iFilter->process( $msg );
  914. }
  915. // Strip out any line breaks and throw away the rest
  916. $url = preg_split("/[\r\n]/", $url);
  917. $url = $url[0];
  918. if ($iFilter->badAttributeValue( array( 'href', $url ))) {
  919. $url = $GLOBALS['mosConfig_live_site'];
  920. }
  921. if (trim( $msg )) {
  922. if (strpos( $url, '?' )) {
  923. $url .= '&mosmsg=' . urlencode( $msg );
  924. } else {
  925. $url .= '?mosmsg=' . urlencode( $msg );
  926. }
  927. }
  928. if (headers_sent()) {
  929. echo '<script type="text/javascript">document.location.href=\''.$url.'\';</script>';
  930. } else {
  931. @ob_end_clean(); // clear output buffer
  932. header( 'HTTP/1.1 301 Moved Permanently' );
  933. header( "Location: ". $url );
  934. }
  935. $GLOBALS['vm_mainframe']->close(true);
  936. }
  937. }
  938. /**
  939. * Raise the memory limit when it is lower than the needed value
  940. *
  941. * @param string $setLimit Example: 16M
  942. */
  943. function vmRaiseMemoryLimit( $setLimit ) {
  944. $memLimit = @ini_get('memory_limit');
  945. if( stristr( $memLimit, 'k') ) {
  946. $memLimit = str_replace( 'k', '', str_replace( 'K', '', $memLimit )) * 1024;
  947. }
  948. elseif( stristr( $memLimit, 'm') ) {
  949. $memLimit = str_replace( 'm', '', str_replace( 'M', '', $memLimit )) * 1024 * 1024;
  950. }
  951. if( stristr( $setLimit, 'k') ) {
  952. $setLimitB = str_replace( 'k', '', str_replace( 'K', '', $setLimit )) * 1024;
  953. }
  954. elseif( stristr( $setLimit, 'm') ) {
  955. $setLimitB = str_replace( 'm', '', str_replace( 'M', '', $setLimit )) * 1024 * 1024;
  956. }
  957. if( $memLimit < $setLimitB ) {
  958. @ini_set('memory_limit', $setLimit );
  959. }
  960. }
  961. /**
  962. * Returns a formatted date
  963. *
  964. * @param int $time TimeStamp format
  965. * @param String $dateformat strftime Format String
  966. * @return String
  967. */
  968. function vmFormatDate( $time=0, $dateformat='' ) {
  969. global $vendor_date_format;
  970. if( empty($time)) $time = time();
  971. if( vmIsJoomla('1.5') ) {
  972. if( empty( $dateformat )) {
  973. return JHTML::_('date', $time, $vendor_date_format);
  974. } else {
  975. return JHTML::_('date', $time, $dateformat);
  976. }
  977. } else {
  978. if( empty( $dateformat )) {
  979. return strftime( $vendor_date_format, $time );
  980. } else {
  981. return strftime( $dateformat, $time );
  982. }
  983. }
  984. }
  985. /**
  986. * Function to strip additional / or \ in a path name
  987. * @param string The path
  988. * @param boolean Add trailing slash
  989. */
  990. function vmPathName($p_path,$p_addtrailingslash = true) {
  991. $retval = "";
  992. $isWin = (substr(PHP_OS, 0, 3) == 'WIN');
  993. if ($isWin) {
  994. $retval = str_replace( '/', '\\', $p_path );
  995. if ($p_addtrailingslash) {
  996. if (substr( $retval, -1 ) != '\\') {
  997. $retval .= '\\';
  998. }
  999. }
  1000. // Check if UNC path
  1001. $unc = substr($retval,0,2) == '\\\\' ? 1 : 0;
  1002. // Remove double \\
  1003. $retval = str_replace( '\\\\', '\\', $retval );
  1004. // If UNC path, we have to add one \ in front or everything breaks!
  1005. if ( $unc == 1 ) {
  1006. $retval = '\\'.$retval;
  1007. }
  1008. } else {
  1009. $retval = str_replace( '\\', '/', $p_path );
  1010. if ($p_addtrailingslash) {
  1011. if (substr( $retval, -1 ) != '/') {
  1012. $retval .= '/';
  1013. }
  1014. }
  1015. // Check if UNC path
  1016. $unc = substr($retval,0,2) == '//' ? 1 : 0;
  1017. // Remove double //
  1018. $retval = str_replace('//','/',$retval);
  1019. // If UNC path, we have to add one / in front or everything breaks!
  1020. if ( $unc == 1 ) {
  1021. $retval = '/'.$retval;
  1022. }
  1023. }
  1024. return $retval;
  1025. }
  1026. /**
  1027. * Utility function to read the files in a directory
  1028. * @param string The file system path
  1029. * @param string A filter for the names
  1030. * @param boolean Recurse search into sub-directories
  1031. * @param boolean True if to prepend the full path to the file name
  1032. */
  1033. function vmReadDirectory( $path, $filter='.', $recurse=false, $fullpath=false ) {
  1034. $arr = array();
  1035. if (!@is_dir( $path )) {
  1036. return $arr;
  1037. }
  1038. $handle = opendir( $path );
  1039. while ($file = readdir($handle)) {
  1040. $dir = vmPathName( $path.'/'.$file, false );
  1041. $isDir = is_dir( $dir );
  1042. if (($file != ".") && ($file != "..")) {
  1043. if (preg_match( "/$filter/", $file )) {
  1044. if ($fullpath) {
  1045. $arr[] = trim( vmPathName( $path.'/'.$file, false ) );
  1046. } else {
  1047. $arr[] = trim( $file );
  1048. }
  1049. }
  1050. if ($recurse && $isDir) {
  1051. $arr2 = vmReadDirectory( $dir, $filter, $recurse, $fullpath );
  1052. $arr = array_merge( $arr, $arr2 );
  1053. }
  1054. }
  1055. }
  1056. closedir($handle);
  1057. asort($arr);
  1058. return $arr;
  1059. }
  1060. /**
  1061. * Helper Function to completely remove a subdirectory
  1062. *
  1063. * @param string $dirname
  1064. * @return boolean
  1065. */
  1066. function vmRemoveDirectoryR( $dirname ) {
  1067. if ($dirHandle = opendir($dirname)){
  1068. $old_cwd = getcwd();
  1069. chdir($dirname);
  1070. while ($file = readdir($dirHandle)){
  1071. if ($file == '.' || $file == '..') continue;
  1072. if (is_dir($file)){
  1073. if (!vmRemoveDirectoryR($file)) return false;
  1074. }else{
  1075. if (!@unlink($file)) return false;
  1076. }
  1077. }
  1078. closedir($dirHandle);
  1079. chdir($old_cwd);
  1080. if (!@rmdir($dirname)) return false;
  1081. return true;
  1082. }else{
  1083. return false;
  1084. }
  1085. }
  1086. /**
  1087. * Utility function to return a value from a named array or a specified default
  1088. *
  1089. * @static
  1090. * @param array $array A named array
  1091. * @param string $name The key to search for
  1092. * @param mixed $default The default value to give if no key found
  1093. * @param string $type Return type for the variable (INT, FLOAT, STRING, WORD, BOOLEAN, ARRAY)
  1094. * @return mixed The value from the source array
  1095. * @since 1.1
  1096. */
  1097. function vmGetArrayValue(&$array, $name, $default=null, $type='') {
  1098. // Initialize variables
  1099. $result = null;
  1100. if (isset ($array[$name])) {
  1101. $result = $array[$name];
  1102. }
  1103. // Handle the default case
  1104. if ((is_null($result))) {
  1105. $result = $default;
  1106. }
  1107. // Handle the type constraint
  1108. switch (strtoupper($type)) {
  1109. case 'INT' :
  1110. case 'INTEGER' :
  1111. // Only use the first integer value
  1112. @ preg_match('/-?[0-9]+/', $result, $matches);
  1113. $result = @ (int) $matches[0];
  1114. break;
  1115. case 'FLOAT' :
  1116. case 'DOUBLE' :
  1117. // Only use the first floating point value
  1118. @ preg_match('/-?[0-9]+(\.[0-9]+)?/', $result, $matches);
  1119. $result = @ (float) $matches[0];
  1120. break;
  1121. case 'BOOL' :
  1122. case 'BOOLEAN' :
  1123. $result = (bool) $result;
  1124. break;
  1125. case 'ARRAY' :
  1126. if (!is_array($result)) {
  1127. $result = array ($result);
  1128. }
  1129. break;
  1130. case 'STRING' :
  1131. $result = (string) $result;
  1132. break;
  1133. case 'WORD' :
  1134. $result = (string) preg_replace( '#\W#', '', $result );
  1135. break;
  1136. case 'NONE' :
  1137. default :
  1138. // No casting necessary
  1139. break;
  1140. }
  1141. return $result;
  1142. }
  1143. function vmGetCleanArrayFromKeyword( $keyword ) {
  1144. global $database;
  1145. $keywordArr = array();
  1146. if( empty( $keyword )) return $keywordArr;
  1147. $keywords = explode( " ", $keyword, 10 );
  1148. foreach( $keywords as $searchstring ) {
  1149. $searchstring = trim( stripslashes($searchstring) );
  1150. $strlen = strlen($searchstring);
  1151. if( $strlen > 2 ) {
  1152. /*if( $searchstring[0] == "\"" || $searchstring[0]=="'" ) {
  1153. $searchstring[0] = " ";
  1154. }
  1155. if( $searchstring[strlen($searchstring)-1] == "\"" || $searchstring[strlen($searchstring)-1]=="'" ) {
  1156. $searchstring[strlen($searchstring)-1] = " ";
  1157. }*/
  1158. $searchstring = $database->getEscaped( $searchstring );
  1159. $searchstring = str_replace('\"', '"', $searchstring );
  1160. $keywordArr[] = $searchstring;
  1161. }
  1162. }
  1163. return $keywordArr;
  1164. }
  1165. /**
  1166. * Replaces &amp; with & for xhtml compliance
  1167. *
  1168. * Needed to handle unicode conflicts due to unicode conflicts
  1169. */
  1170. function vmAmpReplace( $text ) {
  1171. $text = str_replace( '&&', '*--*', $text );
  1172. $text = str_replace( '&#', '*-*', $text );
  1173. $text = str_replace( '&amp;', '&', $text );
  1174. $text = preg_replace( '|&(?![\w]+;)|', '&amp;', $text );
  1175. $text = str_replace( '*-*', '&#', $text );
  1176. $text = str_replace( '*--*', '&&', $text );
  1177. return $text;
  1178. }
  1179. /**
  1180. * Converts array to integer values
  1181. *
  1182. * @param array
  1183. * @param int A default value to assign if $array is not an array
  1184. * @return array
  1185. */
  1186. function vmArrayToInts( &$array, $default=null ) {
  1187. if (is_array( $array )) {
  1188. foreach( $array as $key => $value ) {
  1189. $array[$key] = (int) $value;
  1190. }
  1191. } else {
  1192. if (is_null( $default )) {
  1193. $array = array();
  1194. return array(); // Kept for backwards compatibility
  1195. } else {
  1196. $array = array( (int) $default );
  1197. return array( $default ); // Kept for backwards compatibility
  1198. }
  1199. }
  1200. }
  1201. function vmRoute( $nonSefUrl) {
  1202. // solve an issue with "?" and "&" in the wrong place in the URL
  1203. if(!strpos('option=com_virtuemart',$nonSefUrl)) {
  1204. $nonSefUrl = str_replace( '&amp;', '&', $nonSefUrl);
  1205. $nonSefUrl = str_replace( '?', '&', $nonSefUrl);
  1206. if(strpos($nonSefUrl,'&')) $nonSefUrl=preg_replace('/&/', '?', $nonSefUrl, 1);
  1207. return $nonSefUrl;
  1208. }
  1209. $nonSefUrl = str_replace( '&amp;', '&', $nonSefUrl);
  1210. $nonSefUrl = str_replace( JURI::base(), '', $nonSefUrl); // you are adding &amp; and mosConfig_live_site to urls, but it is actually the role of the sef function to do this. So we have to remove them, otherwise Joomla router will not accept to sef-y the url
  1211. $url = JRoute::_( $nonSefUrl);
  1212. return $url;
  1213. }
  1214. ?>