annamaria-daneswood-25102012 /components/com_jomcomment/functions.jomcomment.php

Language PHP Lines 730
MD5 Hash 0e07bba4beaa8f6c21c9f64de909f890 Estimated Cost $13,240 (why?)
Repository https://bitbucket.org/dgough/annamaria-daneswood-25102012.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
<?php
/**
 * Jom Comment 
 * @package JomComment
 * @copyright (C) 2006 by Azrul Rahim - All rights reserved!
 * @license Copyrighted Commercial Software
 **/
 
# Don't allow direct linking
(defined('_VALID_MOS') OR defined('_JEXEC')) or die('Direct Access to this location is not allowed.');

/** String utilities **/

/**
 * A more comprehansive nl2br replacement. Note that we need to put a space 
 * before the <br/> 
 */
function jcNl2BrStrict($text, $replac=" <br />") {
	return preg_replace("/\r\n|\n|\r/", $replac, $text);
}


// str_ireplace replacement for php4 compatibility
function jcStrIReplace($search,$replace,$subject) {
	if ( function_exists('str_ireplace') ) {
		return str_ireplace($search,$replace,$subject);		// php 5 only
	}
	$srchlen = strlen($search);    // lenght of searched string
	$result  = "";

	if(!empty($search)){
		while ($find = stristr($subject,$search)) {				// find $search text in $subject - case insensitiv
			$srchtxt = substr($find,0,$srchlen);    			// get new case-sensitively-correct search text
			$pos	 = strpos( $subject, $srchtxt );			// stripos is php5 only...
			$result	 .= substr( $subject, 0, $pos ) . $replace;	// replace found case insensitive search text with $replace
			$subject = substr( $subject, $pos + $srchlen );
		}
	}
	return $result . $subject;
}

function jcStrIPos( $search , $replace )
{
	// PHP5 has stripos, just use it
	if( function_exists('stripos') ){
		return stripos( $search , $replace );
	}

	// Convert them to lower case and do the search
	return strpos($search, stristr( $search, $replace ));
}

function jcValidEmail($email){
	return(preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $email ));
}

/**
 * jcCommentGetNum()
 * - Compatibility issues
 **/ 
function jcCommentGetNum($articleId, $option = 'com_content'){
	global $mainframe;
	
	if(!function_exists('jcCountComment'))
		include_once($mainframe->getCfg('absolute_path') . '/components/com_jomcomment/helper/minimal.helper.php');
	
	return jcCountComment($articleId, $option);
}

// Transforme the utf-8 text into htmlentities compatible string
function jcTransformDbText ($source) {
	// if default ISO is already utf-8, just return the string
	if(defined('_ISO')){
		if(strpos(_ISO, 'UTF-8')){
			return $str;
		}
	}
	 
    // array used to figure what number to decrement from character order value
    // according to number of characters used to map unicode to ascii by utf-8
    $decrement[4] = 240;
    $decrement[3] = 224;
    $decrement[2] = 192;
    $decrement[1] = 0;
    
    // the number of bits to shift each charNum by
    $shift[1][0] = 0;
    $shift[2][0] = 6;
    $shift[2][1] = 0;
    $shift[3][0] = 12;
    $shift[3][1] = 6;
    $shift[3][2] = 0;
    $shift[4][0] = 18;
    $shift[4][1] = 12;
    $shift[4][2] = 6;
    $shift[4][3] = 0;
    
    $pos = 0;
    $len = strlen ($source);
    $encodedString = '';
    while ($pos < $len) {
        $asciiPos = ord (substr ($source, $pos, 1));
        
        // we must skip standard ascii cahracter from being unicode encoded!
        if($asciiPos > 31 && $asciiPos <= 127){
            $encodedString .= substr ($source, $pos, 1);
            $pos++;
        } 
        else 
        {
        
       
       if (($asciiPos >= 240) && ($asciiPos <= 255)) {
           // 4 chars representing one unicode character
           $thisLetter = substr ($source, $pos, 4);
           $pos += 4;
       }
       else if (($asciiPos >= 224) && ($asciiPos <= 239)) {
           // 3 chars representing one unicode character
           $thisLetter = substr ($source, $pos, 3);
           $pos += 3;
       }
       else if (($asciiPos >= 192) && ($asciiPos <= 223)) {
           // 2 chars representing one unicode character
           $thisLetter = substr ($source, $pos, 2);
           $pos += 2;
       }
       else {
           // 1 char (lower ascii)
           $thisLetter = substr ($source, $pos, 1);
           $pos += 1;
       }
    
       // process the string representing the letter to a unicode entity
       $thisLen = strlen ($thisLetter);
       $thisPos = 0;
       $decimalCode = 0;
       while ($thisPos < $thisLen) {
           $thisCharOrd = ord (substr ($thisLetter, $thisPos, 1));
           if ($thisPos == 0) {
               $charNum = intval ($thisCharOrd - $decrement[$thisLen]);
               $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
           }
           else {
               $charNum = intval ($thisCharOrd - 128);
               $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
           }
    
           $thisPos++;
       }
    
       if ($thisLen == 1)
           $encodedLetter = "&#". str_pad($decimalCode, 3, "0", STR_PAD_LEFT) . ';';
       else
           $encodedLetter = "&#". str_pad($decimalCode, 5, "0", STR_PAD_LEFT) . ';';
    
       $encodedString .= $encodedLetter;      
       
       }
    }
    return $encodedString;
}

/**
 * trim the given variable
 */
function jcTrim(& $val) {
	$val = trim($val);
	return $val;
}

// Wrap the given text
function jcTextwrap($text, $width = 75) {
	if ($text)
		return preg_replace("/([^\n\r ?&\.\/<>\"\\-]{" . $width . "})/i", " \\1\n", $text);
}


/** Comments **/

/**
 * Return valid Itemid for my blog links
 * If 'option' are currently on myblog, then use current ItemId 
 */  
function jcGetMyBlogItemid(){
	static $jcItemid = -1;
	
	if($jcItemid == -1){
		
		global $Itemid;
		$db = &cmsInstance('CMSDb');
		$jcItemid = $Itemid;
		$db->query("select id from #__menu where link LIKE '%option=com_myblog%' and published='1' AND `id`='$jcItemid'");
		if(!$db->get_value()){
			// The current itemId is not myblog related, ignore it, and find a valid one
			// Menu type is 'component' for Joomla 1.0 and 'components' for Jooma 1.5
			$db->query("select id from #__menu where (type='component' or type='components') and link='index.php?option=com_myblog' and published='1'");
			$jcItemid = $db->get_value();
		}
	}

	return $jcItemid;
}


# Post request to remote server
function jcHttpPost($host, $query, $others = '') {
	if(function_exists('curl_init')){
		$ch = curl_init();
		curl_setopt ($ch, CURLOPT_URL, "http://" .$host . "?". $query);
		curl_setopt ($ch, CURLOPT_HEADER, 0);
		ob_start();
		curl_exec ($ch);
		curl_close ($ch);
		$string = ob_get_contents();
		ob_end_clean();
		return $string;
	}

//				
// 	if(ini_get('allow_url_fopen') == 1){
// 		$dh = @fopen("http://". $host . "?". $query,'r');
// 		if($dh === FALSE){
// 			# fopen failed, Do nothing
// 		} else {
// 			$result = fread($dh,8192);                                                                                                                   
// 			return $result;
// 		}
// 	}
	
	$path = explode('/', $host);
	$host = $path[0];
	$r = "";
	unset ($path[0]);
	$path = '/' . (implode('/', $path));
	$post = "POST $path HTTP/1.0\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\n${others}User-Agent: Mozilla 4.0\r\nContent-length: " . strlen($query) . "\r\nConnection: close\r\n\r\n$query";
	$h = @fsockopen($host, 80, $errno, $errstr, 7);
	if ($h) {
		fwrite($h, $post);
		for ($a = 0, $r = ''; !$a;) {
			$b = fread($h, 8192);
			$r .= $b;
			$a = (($b == '') ? 1 : 0);
		}
		fclose($h);
	}
	return $r;
}


/**
 * Basically, we need to add the HTTPS support if required.
 */ 
function jcFixLiveSiteUrl($content){

	//global
	$cms =& cmsInstance('CMSCore'); 
	$live_site = $cms->get_path('live');
	
	$reqURI   = $live_site;

	# if host have wwww, but mosConfig doesn't
	if((substr_count($_SERVER['HTTP_HOST'], "www.") != 0) && (substr_count($reqURI, "www.") == 0)) {
		$reqURI = str_replace("://", "://www.", $reqURI);
			
	} else if((substr_count($_SERVER['HTTP_HOST'], "www.") == 0) && (substr_count($reqURI, "www.") != 0)) {
		// host do not have 'www' but mosConfig does
		$reqURI = str_replace("www.", "", $reqURI);
	}

	/* Check for HTTPS */
	if(isset($_SERVER)){
		if(isset($_SERVER['HTTPS'])){
			if(strtolower($_SERVER['HTTPS']) == "on" ){
				$reqURI = str_replace("http://", "https://", $reqURI);
			}
		}
	} else if(isset($_SERVER['REQUEST_URI'])) {
		// use REQUEST_URI method
		if(strpos($_SERVER['REQUEST_URI'], 'https://') === FALSE){
			// not a https
		} else {
			$reqURI = str_replace("http://", "https://", $reqURI);
		}
	}

	return str_replace($live_site, $reqURI, $content);

}

function jcGetTemplatePath($file){
	global $_JC_CONFIG;
	
	$path		= JC_COM_PATH . '/templates/_default/' . $file;
	
	
	// Template overriding.
	if($_JC_CONFIG->get('overrideTemplate')){
		$customPath			= JC_CUSTOM_TPL . '/' . $file;

		if(file_exists($customPath))
			$path	= $customPath;
		
	} else {
		$template	= JC_COM_PATH . '/templates/' . $_JC_CONFIG->get('template');
		
		if(file_exists($template . '/' . $file))
			$path	= $template . '/' . $file;
	}
	return $path;
}

function jcCreatePagingLink($baseUrl, $total, $limit, $limitStart){
	$html = array();
	return $html;
}


function jcIsValidtf8($Str) {	
		/*
		if(function_exists('mb_detect_encoding')){
			$enc = mb_detect_encoding($Str, "auto");		
			$iso = explode( '=', _ISO );
	
			return ($enc == $iso);
		} else
		*/ {
		for ($i = 0; $i < strlen($Str) / 5; $i++) {
			if (ord($Str[$i]) < 0x80)
				continue; # 0bbbbbbb
			elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n = 1; # 110bbbbb
			elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n = 2; # 1110bbbb
			elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n = 3; # 11110bbb
			elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n = 4; # 111110bb
			elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n = 5; # 1111110b
			else
				return false; # Does not match any model
			for ($j = 0; $j < $n; $j++) { # n bytes matching 10bbbbbb follow ?
				if ((++ $i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
					return false;
			}
		}
		return true;
	}
}

/**
 * Decode the BBCode
 */
function jcDecodeSmilies($comment) {
	$cms =& cmsInstance('CMSCore'); 
	$live_site = $cms->get_path('live');
	
	$img_path = $live_site;
	
	# fix smilies
	$smilies = array (
		":)" => "smilies/smiley.gif",
		";)" => "smilies/wink.gif",
		":D" => "smilies/cheesy.gif",
		";D" => "smilies/grin.gif",
		">:(" => "smilies/angry.gif",
		":(" => "smilies/sad.gif",
		":o" => "smilies/shocked.gif",
		"8)" => "smilies/cool.gif",
		"::)" => "smilies/rolleyes.gif",
		":P" => "smilies/tongue.gif",
		":-[" => "smilies/embarassed.gif",
		":-X" => "smilies/lipsrsealed.gif",
		":-*" => "smilies/kiss.gif",
		":'(" => "smilies/cry.gif"
	);
	
	$smiliesAlt  = array (
			":)"     => 'smile',
			";)"     => 'wink',
			":D"     => 'laugh',
			";D"     => 'grin',
			">:("    => 'angry',
			":("     => 'sad',
			":o"     => 'shocked',
			"8)"     => 'cool',
			"::)" 	 => "rolleyes",
			":P"     => 'tongue',
			":-[" 	 => "embarassed",
			":-X" 	 => "lips sealed",
			":-*"    => 'kiss',
			":'("   => 'cry'
		);

	foreach ($smilies as $key => $value) {
		$comment = str_replace($key, "<img src='$img_path/"."components/com_jomcomment/" . $value . "' title='{$smiliesAlt[$key]}' border='0' alt='$value' />", $comment);
	}
	
	return $comment;
}

/**
 * Return the content author's id
 */
function jcGetContentAuthor($cid) {
	$db = &cmsInstance('CMSDb');
	$db->query("SELECT created_by from #__content WHERE id=$cid");
	return $db->get_value();
}

function jcGetAuthorName($uid) {
	$db = &cmsInstance('CMSDb');
	$db->query("SELECT name from #__users WHERE id={$uid}");
	return $db->get_value();
}

function jcContentTitle($cid) {
	$db = &cmsInstance('CMSDb');
	$db->query("SELECT title from #__content WHERE id=$cid");
	$title = $db->get_value();
	if(!$title)
		$title = "n/a";
		
	return $title;
}

function jcContentPublished($cid){
	$db = &cmsInstance('CMSDb');
	$db->query("SELECT state from #__content WHERE id=$cid");
	return $db->get_value();
}


/**
 * $ip : ip to test
 * $ips: array of test condition 
 */ 
function jcCheckBlockedIp($ip, $ips) {
	# read in the ip address file
	$lines = $ips; //file("ipaddresses.txt");
	
	# set a variable as false
	$found = false;
	
	# convert ip address into a number
	$split_it = split("\.",$ip);
	$ip = "1" . sprintf("%03d",$split_it[0]) .
	sprintf("%03d",$split_it[1]) . sprintf("%03d",$split_it[2]) .
	sprintf("%03d",$split_it[3]);
	
	# loop through the ip address file
	foreach ($lines as $line) {
		# remove line feeds from the line
		$line = chop($line);
		# replace x with a *
		$line = str_replace("x","*",$line);
		# remove comments
		$line = preg_replace("|[A-Za-z#/]|","",$line);
		# set a maximum and minimum value
		$max = $line;
		$min = $line;
		# replace * with a 3 digit number
		if ( strpos($line,"*",0) <> "" ) {
			$max = str_replace("*","999",$line);
			$min = str_replace("*","000",$line);
		}
		# replace ? with a single digit
		if ( strpos($line,"?",0) <> "" ) {
			$max = str_replace("?","9",$line);
			$min = str_replace("?","0",$line);
		}
		# if the line is invalid go to the next line
		if ( $max == "" ) { continue; };
		# check for a range
		if ( strpos($max," - ",0) <> "" ) {
			$split_it = split(" - ",$max);
			# if the second part does not match an ip address
			if ( !preg_match("|\d{1,3}\.|",$split_it[1]) ) {
				$max = $split_it[0];
			}
			else { 
				$max = $split_it[1];
			};
		}
		if ( strpos($min," - ",0) <> "" ) {
			$split_it = split(" - ",$min);
			$min = $split_it[0];
		}
		# make $max into a number
		$split_it = split("\.",$max);
		for ( $i=0;$i<4;$i++ ) {
			if ( $i == 0 ) { $max = 1; };
			if ( strpos($split_it[$i],"-",0) <> "" ) {
				$another_split = split("-",$split_it[$i]);
				$split_it[$i] = $another_split[1];
			} 
		$max .= sprintf("%03d",$split_it[$i]);
		}
		# make $min into a number
		$split_it = split("\.",$min);
		for ( $i=0;$i<4;$i++ ) {
			if ( $i == 0 ) { $min = 1; };
			if ( strpos($split_it[$i],"-",0) <> "" ) {
				$another_split = split("-",$split_it[$i]);
				$split_it[$i] = $another_split[0];
			} 
		$min .= sprintf("%03d",$split_it[$i]);
		}
		# check for a match
		if ( ($ip <= $max) && ($ip >= $min) ) {
			$found = true;
			break;
		};
	}
	return $found;
}; # end function


function jcClearCache(){
	global $mainframe;

	$cms    =& cmsInstance('CMSCore');
	$cms->load('helper','directory');
	$cms->load('libraries', 'cache');
	$cms->cache->clear();

	$list   = cmsGetFiles(JC_CACHE_PATH, '');

	foreach($list as $file){
	    // Only remove files that contains the naming convention for cache_
	    if(strstr($file, 'cache_')){
	        @unlink(JC_CACHE_PATH . '/' . $file);
		}
	}
	
	// For Joomla 1.0 we would still need to clear the cached files
	// located in $mosConfig_cachepath
	if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
	    $list   = cmsGetFiles($mainframe->getCfg('cachepath'), '');
	    foreach($list as $file){
	        if(strstr($file, 'cache_'))
	            @unlink($mainframe->getCfg('cachepath') . '/' . $file);
		}
	}
	
	// For Joomla 1.5 we would also need to clear the cached files for JCache.
	if(cmsVersion() == _CMS_JOOMLA15){
		if($mainframe->getCfg('caching')){
			$cache =& JFactory::getCache();
			
			// Clear com_content's cache
			$cache->clean('com_content');
		}
	}
}

function jcGetCommentHtml($id, $extoption, $row){
	global $_JOMCOMMENT;
	return $_JOMCOMMENT->getHTML($id, $extoption, $row);
}

/**
* Similar to mosCreateMail, except that we need to change the email
* encoding to utf-8
*/
function jomCreateMail($from = '', $fromname = '', $subject, $body) {
	$cms =& cmsInstance('CMSCore');

	if(cmsVersion() == _CMS_JOOMLA15){
		$cms->load('libraries','cfg');
		jimport('joomla.mail.mail');

		$mail		=& JFactory::getMailer();
		$fromname	= $fromname ? $fromname : $cms->cfg->get('fromname');
		$from		= $from ? $from : $cms->cfg->get('mailfrom');

		$mail->setSender(array($from,$fromname));
		$mail->setSubject($subject);
		$mail->setBody($body);

	}else if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
		$mail = new mosPHPMailer();
		global $mainframe;

		$mail->PluginDir = $cms->get_path('root') . '/includes/phpmailer/';
		$mail->SetLanguage('en', $cms->get_path('root') . '/includes/phpmailer/language/');
		$mail->CharSet = 'UTF-8'; //substr_replace(_ISO, '', 0, 8);
		$mail->IsMail();
		$mail->From = $from ? $from : $mainframe->getCfg('mailfrom');
		$mail->FromName = $fromname ? $fromname : $mainframe->getCfg('fromname');
		$mail->Mailer = $mainframe->getCfg('mailer');

		// Add smtp values if needed
		if ($mainframe->getCfg('mailer') == 'smtp') {
			$mail->IsSMTP();
			$mail->SMTPAuth = $mainframe->getCfg('smtpauth');
			$mail->Username = $mainframe->getCfg('smtpuser');
			$mail->Password = $mainframe->getCfg('smtppass');

			$smtphost = $mainframe->getCfg('smtphost');
			$hostIp = split(":", $smtphost);
			if(count($hostIp)> 1){
				$mail->Host = $hostIp[0];
				$mail->Port = $hostIp[1];
			} else {
				$mail->Host = $mainframe->getCfg('smtphost');
			}
			
		} else{
			// Set sendmail path
			if ($mainframe->getCfg('mailer') == 'sendmail') {
				$sendmail = $mainframe->getCfg('sendmail');
				if (isset ($sendmail))
					$mail->Sendmail = $sendmail;
				} // if
		}
		$mail->Subject = $subject;
		$mail->Body = $body;
	}

	return $mail;
}

/**
 * Sending out email. Very similar to mosMail, except that we uses jomCreateMail
 * instead of mosCreateMail to allow us to change the encoding. 
 */
function jomMail($from, $fromname, $recipient, $subject, $body, $mode = 0, $cc = NULL, $bcc = NULL, $attachment = NULL, $replyto = NULL, $replytoname = NULL) {

	$body = stripslashes($body);
	$mail = jomCreateMail($from, $fromname, $subject, $body);

	// activate HTML formatted emails
	if ($mode) {
		$mail->IsHTML(true);
	}

	// Check if mail address is valid.
	$regexp	= "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
	
	if (is_array($recipient)) {
		foreach ($recipient as $to) {
			if(!empty($to) && eregi($regexp, $to)){
				$mail->AddAddress($to);
			}
		}
	} else {
		if(!empty($recipient) && eregi($regexp, $recipient)){
			$mail->AddAddress($recipient);
		}
	}
	if (isset ($cc)) {
		if (is_array($cc)) {
			foreach ($cc as $to) {
				$mail->AddCC($to);
			}
		} else {
			$mail->AddCC($cc);
		}
	}
	if (isset ($bcc)) {
		if (is_array($bcc)) {
			foreach ($bcc as $to) {
				$mail->AddBCC($to);
			}
		} else {
			$mail->AddBCC($bcc);
		}
	}
	if ($attachment) {
		if (is_array($attachment)) {
			foreach ($attachment as $fname) {
				$mail->AddAttachment($fname);
			}
		} else {
			$mail->AddAttachment($attachment);
		}
	}
	
	if(cmsVersion() == _CMS_JOOMLA15){
		if($replyto){
			$mail->addReplyTo(array($replyto, $replytoname));
		}
	} else {
		//Important for being able to use mosMail without spoofing...
		if ($replyto) {
			if (is_array($replyto)) {
				reset($replytoname);
				foreach ($replyto as $to) {
					$toname = ((list ($key, $value) = each($replytoname)) ? $value : '');
					$mail->AddReplyTo($to, $toname);
				}
			} else {
				$mail->AddReplyTo($replyto, $replytoname);
			}
		}
	}

	$mailssend = $mail->Send();

	return $mailssend;
}


// return ItemID for jom comment link
function jcGetItemID(){
	$db = &cmsInstance('CMSDb');
	static $jcitemid   = '';
	
	if(empty($jcitemid)){
		# autodetect Itemid
		$query = "SELECT id FROM #__menu  WHERE type='components' "
		        ."AND link='index.php?option=com_jomcomment' "
		        ."AND published='1'";

		$db->query($query);

		$jcitemid = $db->get_value();
		if (!$jcitemid){
			if (isset ($_REQUEST['Itemid']) and $_REQUEST['Itemid'] != "" and $_REQUEST['Itemid'] != "0"){
				$jcitemid	= $_REQUEST['Itemid'];
			} else
            	$jcitemid = 1;
		}
	}
	return $jcitemid;
}

// Return the 'Powered by xxx' link
function jcGetPoweredByLink(){
	return '';
	return '<div style="text-align:center;font-size:95%"><a target="_blank" href="http://www.azrul.com">Powered by Azrul&#39;s Jom Comment for Joomla!</a></div>';
}
Back to Top