-2

i am problem with line 3462 ?! :@

<?php
function trigger_db_error($obj)
	{
		global $CFG;

		$error_arr = debug_backtrace();

		$subject = 'Report bug - Sql error - {site_url}';
		$content = '<u><b>Url :</b></u>
		{current_url}

		<u><b>Error File :</b></u>
		{file}

		<u><b>Error Line No :</b></u>
		{line}

		<u><b>Error Description:</b></u>
		{error}';

		$frmobj = new FormHandler();
		if(isset($CFG['site']['current_url']))
			$frmobj->setEmailTemplateValue('current_url', $CFG['site']['current_url']);
		$frmobj->setEmailTemplateValue('file', $error_arr[0]['file']);
		$frmobj->setEmailTemplateValue('line', $error_arr[0]['line']);

		$frmobj->setEmailTemplateValue('error', $error_arr[0]['args'][0]->debug_output);
		$frmobj->buildEmailTemplate($subject, $content, false, true);

		sendBugEmail($frmobj);
		trigger_error('Error at '.$error_arr[0]['file'].' on line '.$error_arr[0]['line']."<br>".$obj->ErrorNo().' '.$obj->ErrorMsg(), E_USER_ERROR);
	}

function sendBugEmail($frmobj)
	{
		global $CFG;
		$EasySwift = new EasySwift($frmobj->getSwiftConnection());
		$EasySwift->flush();
		$EasySwift->addPart($frmobj->getEmailContent(), "text/html");
		$from_email = $CFG['site']['noreply_email'];
		$EasySwift->send($CFG['site']['dev_bug_email'], $from_email, $frmobj->getEmailSubject());
	}

function getCurrentMemberUrl()
	{
		global $CFG;
		return str_replace($CFG['site']['url'],$CFG['site']['url'].'members/',$CFG['site']['current_url']);
	}

function postForm($url, $post_value)
	{
		$ch = curl_init();

		// set the target url
		curl_setopt($ch, CURLOPT_URL,$url);

		// howmany parameter to post
		curl_setopt($ch, CURLOPT_POST, 1);

		// the parameter 'username' with its value 'johndoe'
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_value);

		$result= curl_exec ($ch);
		curl_close ($ch);
	}

/**
 * Check the site is under maintenance
 *
 * @access	public
 * @return	boolean
 */
function chkIsSiteUnderMaintenance()
	{
		global $CFG;

		if(!isAdmin())
			{
				$currentPage = strtolower($CFG['html']['current_script_name']);
				if($CFG['admin']['module']['site_maintenance'] AND $currentPage != 'maintenance')
					{
						// Unset all of the session variables.
						$_SESSION = array();
						// If it's desired to kill the session, also delete the session cookie.
						// Note: This will destroy the session, and not just the session data!
						if (isset($_COOKIE[session_name()]))
							{
							   setcookie(session_name(), '', time()-42000, '/');
							}
						// Finally, destroy the session.
						session_destroy();
						session_write_close();
						setcookie($CFG['cookie']['starting_text'].'_bba', '', time()-42000, '/');
						$murl = getUrl($CFG['redirect']['maintenance_module_url']['file_name'], $CFG['redirect']['maintenance_module_url']['normal'], $CFG['redirect']['maintenance_module_url']['htaccess'], 'root');
						$CFG['site']['current_url'];
						if($CFG['site']['current_url']!=$murl)
							{
								Redirect2Url($murl);
								exit;
							}

					}
			}
		else
			{
				$value_array = explode('/', $CFG['site']['relative_url']);
				if(!in_array('admin', $value_array) and $CFG['admin']['module']['site_maintenance'])
					{
						$admin_url = $CFG['site']['url'].'admin/index.php';
						Redirect2URL($admin_url);
					}
			}
	}

/**
 * Check the allowed country user
 *
 * @access	public
 * @return	boolean
 */
function chkIsAllowedCountry()
	{
		global $CFG;
		$country_code = apache_note("GEOIP_COUNTRY_CODE");
		if(in_array($country_code, $CFG['admin']['geo_country']))
			return false;
		return true;
	}

/**
 * Return the matched pattern list from given string
 *
 * @access	public
 * @param	string	pattern to search
 * @param	string	content
 * @param	integer	to return the particular array value
 * @return	array
 */
function MatchPattern($PATTERN = '', $CONTENT = '', $KEY = '')
	{
		if ($PATTERN && $CONTENT)
			{
				preg_match_all ($PATTERN, $CONTENT, $Match);
			}
		if ($KEY != '')
			{
				return $Match[$KEY];
			}
		return $Match;
	}
/**
$varrfile = '<filename class="class1">test<filename class="class2">dsfsd fsd<filename class="class3">';
$pattern2 ='~<filename class="([^"]+)">~i';
$lang_value = MatchPattern($pattern2, $varrfile);
echo '<pre>';print_r($lang_value);echo '</pre>';
*/

/**
 * used to get the image with and height
 *
 * @access	public
 * @param	integer required width
 * @param	integer required height
 * @param	integer	image original width
 * @param	integer	image original height
 * @return	string
 */
function DISP_IMAGE($cfg_width = 0, $cfg_height = 0, $img_width = 0, $img_height = 0)
	{
	   	 $relative_height='';
	   	 $relative_width='';
		if ($cfg_width > 0 AND $cfg_height > 0 AND ($cfg_width < $img_width) AND ($cfg_height < $img_height))
			$attr = ($img_width > $img_height)? " width=\"".$cfg_width."\"" : " height=\"".$cfg_height."\"";
			else if ($cfg_width > 0 AND $cfg_width < $img_width)
			{
			   	$ratio = $img_height / $img_width;
			    $relative_height=$cfg_width*$ratio;
				$attr = " width=\"".$cfg_width."\" height=\"".$relative_height."\"";
			 }
				else if ($cfg_height > 0 AND $cfg_height < $img_height)
				{
				   	$ratio = $img_width / $img_height;
			        $relative_width=$cfg_height*$ratio;
					$attr = " width=\"".$relative_width."\" height=\"".$cfg_height."\"";
				}
					else
						$attr = "";
			return $attr;
	}

/**
 * Word Limiter
 *
 * Limits a string to X number of words.
 *
 * @access	public
 * @param	string
 * @param	integer
 * @param	string	the end character. Usually an ellipsis
 * @return	string
 */
function word_limiter($str, $limit = 100, $end_char = '…')
	{
		if (trim($str) == '')
			{
				return $str;
			}
		preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches);
		if (strlen($str) == strlen($matches[0]))
			{
				$end_char = '';
			}
		return rtrim($matches[0]).$end_char;
	}

/**
 * Character Limiter
 *
 * Limits the string based on the character count.  Preserves complete words
 * so the character count may not be exactly as specified.
 *
 * @access	public
 * @param	string
 * @param	integer
 * @param	string	the end character. Usually an ellipsis
 * @return	string
 */
function character_limiter($str, $n = 500, $end_char = '…')
	{
		if (strlen($str) < $n)
			{
				return $str;
			}
		$str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str));
		if (strlen($str) <= $n)
			{
				return $str;
			}
		$out = "";
		foreach (explode(' ', trim($str)) as $val)
			{
				$out .= $val.' ';
				if (strlen($out) >= $n)
					{
						return trim($out).$end_char;
					}
			}
	}

/**
 * Word Censoring Function
 *
 * Supply a string and an array of disallowed words and any
 * matched words will be converted to #### or to the replacement
 * word you've submitted.
 *
 * @access	public
 * @param	string	the text string
 * @param	string	the array of censoered words
 * @param	string	the optional replacement value
 * @return	string
 */
function word_censor($str, $censored, $replacement = '')
	{
		if ( ! is_array($censored))
			{
				return $str;
			}
		$str = ' '.$str.' ';
		foreach ($censored as $badword)
			{
				if ($replacement != '')
					{
						$str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str);
					}
				else
					{
						$str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str);
					}
			}
		return trim($str);
	}

/**
 * Code Highlighter
 *
 * Colorizes code strings
 *
 * @access	public
 * @param	string	the text string
 * @return	string
 */
function highlight_code($str)
	{
		// The highlight string function encodes and highlights
		// brackets so we need them to start raw
		$str = str_replace(array('&lt;', '&gt;'), array('<', '>'), $str);

		// Replace any existing PHP tags to temporary markers so they don't accidentally
		// break the string out of PHP, and thus, thwart the highlighting.

		$str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'),
							array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str);

		// The highlight_string function requires that the text be surrounded
		// by PHP tags.  Since we don't know if A) the submitted text has PHP tags,
		// or B) whether the PHP tags enclose the entire string, we will add our
		// own PHP tags around the string along with some markers to make replacement easier later

		$str = '<?php tempstart'."\n".$str.'tempend ?>';

		// All the magic happens here, baby!
		$str = highlight_string($str, TRUE);

		// Prior to PHP 5, the highlight function used icky font tags
		// so we'll replace them with span tags.
		if (abs(phpversion()) < 5)
			{
				$str = str_replace(array('<font ', ',',',',',',',','</font>'), array('<span ', ',',',',',',',','</span>'), $str);
				$str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
			}

		// Remove our artificially added PHP
		$str = preg_replace("#\<code\>.+?tempstart\<br />(?:\</span\>)?#is", "<code>\n", $str);
		$str = preg_replace("#tempend.+#is", "</span>\n</code>", $str);

		// Replace our markers back to PHP tags.
		$str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
							array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $str);

		return $str;
	}

/**
 * Phrase Highlighter
 *
 * Highlights a phrase within a text string
 *
 * @access	public
 * @param	string	the text string
 * @param	string	the phrase you'd like to highlight
 * @param	string	the openging tag to precede the phrase with
 * @param	string	the closing tag to end the phrase with
 * @return	string
 */
 function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
	{
		if ($str == '')
			{
				return '';
			}
		if ($phrase != '')
			{
				return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str);
			}
		return $str;
	}

/**
 * Word Wrap
 *
 * Wraps text at the specified character.  Maintains the integrity of words.
 * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
 * will URLs.
 *
 * @access	public
 * @param	string	the text string
 * @param	integer	the number of characters to wrap at
 * @return	string
 */
function word_wrap($str, $charlim = '76')
	{
		// Se the character limit
		if ( ! is_numeric($charlim))
			$charlim = 76;

		// Reduce multiple spaces
		$str = preg_replace("| +|", " ", $str);

		// Standardize newlines
		$str = preg_replace("/\r\n|\r/", "\n", $str);

		// If the current word is surrounded by {unwrap} tags we'll
		// strip the entire chunk and replace it with a marker.
		$unwrap = array();
		if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
			{
				for ($i = 0; $i < count($matches['0']); $i++)
					{
						$unwrap[] = $matches['1'][$i];
						$str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
					}
			}

		// Use PHP's native function to do the initial wordwrap.
		// We set the cut flag to FALSE so that any individual words that are
		// too long get left alone.  In the next step we'll deal with them.
		$str = wordwrap($str, $charlim, "\n", FALSE);

		// Split the string into individual lines of text and cycle through them
		$output = "";
		foreach (explode("\n", $str) as $line)
			{
				// Is the line within the allowed character count?
				// If so we'll join it to the output and continue
				if (strlen($line) <= $charlim)
					{
						$output .= $line."\n";
						continue;
					}

				$temp = '';
				while((strlen($line)) > $charlim)
					{
						// If the over-length word is a URL we won't wrap it
						if (preg_match("!\[url.+\]|://|wwww.!", $line))
							{
								break;
							}

						// Trim the word down
						$temp .= substr($line, 0, $charlim-1);
						$line = substr($line, $charlim-1);
					}

				// If $temp contains data it means we had to split up an over-length
				// word into smaller chunks so we'll add it back to our current line
				if ($temp != '')
					{
						$output .= $temp . "\n" . $line;
					}
				else
					{
						$output .= $line;
					}

				$output .= "\n";
			}

		// Put our markers back
		if (count($unwrap) > 0)
			{
				foreach ($unwrap as $key => $val)
					{
						$output = str_replace("{{unwrapped".$key."}}", $val, $output);
					}
			}

		// Remove the unwrap tags
		$output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output);

		return $output;
	}

/**
 * Create a Directory Map
 *
 * Reads the specified directory and builds an array
 * representation of it.  Sub-folders contained with the
 * directory will be mapped as well.
 *
 * @access	public
 * @param	string	path to source
 * @param	bool	whether to limit the result to the top level only
 * @return	array
 */
function directory_map($source_dir, $top_level_only = FALSE)
	{
		if ($fp = @opendir($source_dir))
		{
			$filedata = array();
			while (FALSE !== ($file = readdir($fp)))
			{
				if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)
				{
					$temp_array = array();

					$temp_array = directory_map($source_dir.$file."/");

					$filedata[$file] = $temp_array;
				}
				elseif (substr($file, 0, 1) != ".")
				{
					$filedata[] = $file;
				}
			}
			return $filedata;
		}
	}

/**
 * Read File
 *
 * Opens the file specfied in the path and returns it as a string.
 *
 * @access	public
 * @param	string	path to file
 * @return	string
 */
 function read_file($file)
	{
		if ( ! file_exists($file))
			{
				return FALSE;
			}

		if (function_exists('file_get_contents'))
			{
				return file_get_contents($file);
			}

		if ( ! $fp = @fopen($file, 'rb'))
			{
				return FALSE;
			}

		flock($fp, LOCK_SH);

		$data = '';
		if (filesize($file) > 0)
			{
				$data =& fread($fp, filesize($file));
			}

		flock($fp, LOCK_UN);
		fclose($fp);

		return $data;
	}

/**
 * Write File
 *
 * Writes data to the file specified in the path.
 * Creates a new file if non-existent.
 *
 * @access	public
 * @param	string	path to file
 * @param	string	file data
 * @return	bool
 */
 function write_file($path, $data, $mode = 'w+')
	{
		if ( ! $fp = @fopen($path, $mode))
			{
				return FALSE;
			}
		flock($fp, LOCK_EX);
		fwrite($fp, $data);
		@chmod($path, 0777);
		flock($fp, LOCK_UN);
		fclose($fp);
		return TRUE;
	}

/**
 * read Directory
 *
 * read to the file specified in the path.
 *
 * @access	public
 * @param	string	$dir_path to file
 * @param	string	return (dir, file, both)
 * @return	bool
 */
function readDirectory($dir_path, $return = 'both')
	{
		$return_arr = array();
		if ($handle = opendir($dir_path))
			{
    			while (false !== ($file = readdir($handle)))
					{
				        if ($file != "." && $file != ".." && $file != ".svn")
							{
				            	if((is_file($dir_path.$file) and $return=='file') or (is_dir($dir_path.$file) and $return=='dir') or ($return=='both'))
									{
										$return_arr[] = $file;
									}
        					}
    				}
    			closedir($handle);
			}
		return $return_arr;
	}

/**
 * Force Download
 *
 * Generates headers that force a download to happen
 *
 * @access	public
 * @param	string	filename
 * @param	mixed	the data to be downloaded
 * @return	void
 */
function force_download($filename = '', $data = '')
	{
		global $CFG;
		if ($filename == '' OR $data == '')
			{
				return FALSE;
			}

		// Try to determine if the filename includes a file extension.
		// We need it in order to set the MIME type
		if (FALSE === strpos($filename, '.'))
			{
				return FALSE;
			}

		// Grab the file extension
		$x = explode('.', $filename);
		$extension = end($x);

		// Load the mime types
		@include($CFG['site']['project_path'].'common/configs/config_mimes.inc..php');

		// Set a default mime if we can't find it
		if ( ! isset($mimes[$extension]))
			{
				$mime = 'application/octet-stream';
			}
		else
			{
				$mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
			}

		// Generate the server headers
		if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
			{
				header('Content-Type: "'.$mime.'"');
				header('Content-Disposition: attachment; filename="'.$filename.'"');
				header('Expires: 0');
				header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
				header("Content-Transfer-Encoding: binary");
				header('Pragma: public');
				header("Content-Length: ".strlen($data));
			}
		else
			{
				header('Content-Type: "'.$mime.'"');
				header('Content-Disposition: attachment; filename="'.$filename.'"');
				header("Content-Transfer-Encoding: binary");
				header('Expires: 0');
				header('Pragma: no-cache');
				header("Content-Length: ".strlen($data));
			}
		echo $data;
	}

/**
 * Strip Slashes
 *
 * Removes slashes contained in a string or in an array
 *
 * @access	public
 * @param	mixed	string or array
 * @return	mixed	string or array
 */
function strip_slashes($str)
	{
		if (is_array($str))
			{
				foreach ($str as $key => $val)
					{
						$str[$key] = strip_slashes($val);
					}
			}
		else
			{
				$str = stripslashes($str);
			}
		return $str;
	}

/**
 * check particular cron file running status
 *
 * @access	public
 * @param	string	script name to check
 * @return	boolean
 */
function isCronRunning($script_name = '')
	{
		global $CFG;
		if(strstr($CFG['site']['url'], '/localhost/'))
			{
				return false;
			}
		$max_cron_allowed = 1;
		$cronRunning = false;
		if ($script_name)
			{
				$command = ' ps -eaf | grep '.$script_name;
				$result  = @shell_exec($command);
				$scriptCount = intval(@substr_count($result, $script_name));
				$max_cron_allowed = ($max_cron_allowed + 3);// 1 for ps, 1 for grep, 1 for the current /usr/bin/php cron.php
				$cronRunning = ($scriptCount >= $max_cron_allowed);
			}
		return $cronRunning;
	}

/**
 * to control the cron file running
 *
 * @access	public
 * @return	static
 */
function callMultipleCronCheck()
	{
		global $CFG;
		$cronUrl = $CFG['site']['current_url'];
		$time = date('d-m-y H:i:s');
		print "\n CRON:\t$cronUrl:\nTIME:$time\n";
		if (isCronRunning($cronUrl))
			{
				print "CRON : $cronUrl\nTIME:$cronUrl\nConcurrent Process Detected\nSo Skipping ".$cronUrl." CRON at ".date('d-M-y H:i:s')."\n\n";
				die();
			}
	}

/**
 * get the md5 text with number of characters
 *
 * @access	public
 * @param	string
 * @param	integer
 * @return	boolean
 */
function getMD5Text($text, $count = 15)
	{
		$text = md5($text);
		return substr($text, 0, $count-1);
	}

/**
 * to encode purpose, we can change it as per requirement
 *
 * @access	public
 * @param	string
 * @param	integer
 * @return	boolean
 */
function doEncode($text, $size=0)
	{
		$text = str_pad($text, $size, '0', STR_PAD_LEFT);
		$text = base64_encode($text);
		$text = urlencode($text);
		return $text;
	}

/**
 * to decode purpose, we can change it as per requirement
 *
 * @access	public
 * @param	string
 * @return	boolean
 */
function doDecode($text)
	{
		$text = urldecode($text);
		$text = base64_decode($text);
		return $text;
	}

/**
 * to get the seconds difference b/w current time and given time
 *
 * @access	public
 * @param	integer
 * @return	integer
 */
function getTimeDiffInSeconds($date)
	{
		global $CFG;
		global $db;

		$sql = 'SELECT TIMEDIFF(NOW(), \''.$date.'\') AS date_added';

		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt);
		    if (!$rs)
				trigger_db_error($db);

		$row = $rs->FetchRow();
		return $row['date_added'];
	}

/**
 * to get the time difference b/w current time and given time
 *
 * @access	public
 * @param	integer
 * @return	string
 */
function getTimeDiffernce($time)
	{
		global $LANG;
		$date_added_pc = array();

		$date_added_pc = explode(':', $time);

		if(sizeof($date_added_pc)!=3)
			return '0 '.$LANG['timediff_seconds_ago'];

		$date_added_pc[0] = intval($date_added_pc[0]);
		$date_added_pc[1] = intval($date_added_pc[1]);
		$date_added_pc[2] = intval($date_added_pc[2]);

		if($date_added_pc[0])
			{
				$day = floor($date_added_pc[0]/24);
				if($day>365)
					{
						$year = floor($day/365);
						if($year>1)
							$time = $year.' '.$LANG['timediff_years_ago'];
						else
							$time = $year.' '.$LANG['timediff_year_ago'];
					}
				else if($day>30)
					{
						$month = floor($day/30);
						if($month>1)
							$time = $month.' '.$LANG['timediff_months_ago'];
						else
							$time = $month.' '.$LANG['timediff_month_ago'];
					}
				else if($day)
					{
						if($day>1)
							$time = $day.' '.$LANG['timediff_days_ago'];
						else
							$time = $day.' '.$LANG['timediff_day_ago'];
					}
				else
					{
						if($date_added_pc[0]>1)
							$time = $date_added_pc[0].' '.$LANG['timediff_hours_ago'];
						else
							$time = $date_added_pc[0].' '.$LANG['timediff_hour_ago'];
					}
			}
		else if($date_added_pc[1])
			{
				if($date_added_pc[1]>1)
					$time = $date_added_pc[1].' '.$LANG['timediff_minutes_ago'];
				else
					$time = $date_added_pc[1].' '.$LANG['timediff_minute_ago'];
			}
		else
			{
				if($date_added_pc[2]>1)
					$time = $date_added_pc[2].' '.$LANG['timediff_seconds_ago'];
				else
					$time = $date_added_pc[2].' '.$LANG['timediff_second_ago'];
			}

		return $time;
	}

	function getDateTimeDiff($date,$today)
		{
			list($year, $month, $day, $hrs, $min, $sec) = split('[ \:-]', $date);

			list($year1, $month1, $day1, $hrs1, $min1, $sec1) = split('[ \:-]', $today);

			$secs = mktime($hrs1, $min1, $sec1, $month1, $day1, $year1)-mktime($hrs, $min, $sec, $month, $day, $year);
			$mins = floor($secs/60);
			$hrs  = floor($mins/60);
			$secs = $secs % 60;
			$mins = $mins % 60;
			return $row['date_added'] = $hrs.':'.$mins.':'.$secs;
		}

/**
 * Looks for the first occurence of $needle in $haystack and replaces it with $replace.
 *
 * @access	public
 * @param	string	search string
 * @param	string	replace string
 * @param	string	given string
 * @return	string
 */
function str_replace_once($needle, $replace, $haystack)
	{
	    $pos = strpos($haystack, $needle);
	    if ($pos === false)
			{
		        return $haystack;
		    }
	    return substr_replace($haystack, $replace, $pos, strlen($needle));
	}

/**
 * get full text format of given string
 *
 * @access	public
 * @param	string	given string
 * @return	string
 */
function getFullTextSearchString($tags)
	{
		$tags= rawurlencode($tags);
		return $tags = '[[:<:]]'.preg_replace('/\s+/', '|', addslashes($tags)).'[[:>:]]';

		$tags = trim($tags);
		while(strpos($tags, '  '))
			{
				$tags = str_replace('  ', ' ', $tags);
			}
		$tags = addslashes($tags);
		$tags_arr = explode(' ', $tags);
		$tags = '[[:<:]]'.implode('[[:>:]]|[[:<:]]', $tags_arr).'[[:>:]]';
		return $tags;
	}

/**
 * to get search qurey like full text search query.
 *
 * @access	public
 * @param	string	tags to search
 * @param	string	search field
 * @param	string	additional string to add (AND, OR)
 * @return	string
 */
function getSearchRegularExpressionQueryForums($tags, $field_name, $extra = '')
	{
		global $CFG;
		$not_allowed_search_array = $CFG['admin']['not_allowed_chars'];
		$tags = replaceCharacter($not_allowed_search_array, '-', $tags);
		$tags = addslashes($tags);
		$additional_query = ' ('.$field_name.' REGEXP \''.formatSearchString($tags).'\') '.$extra.' ';
		return $additional_query;
	}

function replaceCharacter($search_value, $replace, $text)
	{
		if(is_array($search_value))
			{
				foreach($search_value as $key=>$value)
					$text = str_replace ($value, $replace, $text);
				return $text;
			}
		return str_replace ($char, $replace, $text);
	}
function formatSearchString($tags)
	{
		return $tags = '[[:<:]]'.preg_replace('/\s+/', '|', $tags).'[[:>:]]';

		$tags = trim($tags);
		while(strpos($tags, '  '))
			{
				$tags = str_replace('  ', ' ', $tags);
			}
		$tags = addslashes($tags);
		$tags_arr = explode(' ', $tags);
		$tags = '[[:<:]]'.implode('[[:>:]]|[[:<:]]', $tags_arr).'[[:>:]]';
		return $tags;
	}


/**
 * to get search qurey like full text search query.
 *
 * @access	public
 * @param	string	tags to search
 * @param	string	search field
 * @param	string	additional string to add (AND, OR)
 * @return	string
 */
function getSearchRegularExpressionQuery($tags, $field_name, $extra = '')
	{
		global $CFG;
		$tags = addslashes($tags);
		if($CFG['admin']['search']['regular_expression'])
			{
				$additional_query = ' ('.$field_name.' REGEXP \''.getFullTextSearchString($tags).'\') '.$extra.' ';
			}
		else
			{
				$additional_query = ' MATCH('.$field_name.') AGAINST (\''.$tags.'\' IN BOOLEAN MODE) '.$extra.' ';
			}
		return $additional_query;
	}

/**
 * to create the multi level folder.
 *
 * @access	public
 * @param	string	folder name to create (root/sub/test/)
 * @return	static
 */
function createMultiLevelFolder($folderName)
	{
		$folder_arr = explode('/', $folderName);
		$folderName = '';
		foreach($folder_arr as $key=>$value)
			{
				$folderName .= $value.'/';
				if($value == '..' or $value == '.')
					continue;
				if (!is_dir($folderName))
					{
						mkdir($folderName);
						@chmod($folderName, 0777);
					}
			}
	}

/**
 * to remove the directory, if sub folders or file is in given directory,
 * this function will remove all the files
 *
 * @access	public
 * @param	string	directory name to delete
 * @return	boolean
 */
function removeDirectory($dirname)
	{
		if (is_dir($dirname))
	   		{
		       	$result = array();
		   		if (substr($dirname,-1) != '/')
					{
						$dirname.='/';
					}
			  	$handle = opendir($dirname);
			    while (false !== ($file = readdir($handle)))
				   {
			   			if ($file != '.' && $file != '..')
					   		{    //Ignore . and ..
				               $path = $dirname.$file;
				               	if (is_dir($path))
							   		{    //Recurse if subdir, Delete if file
				                   		$result=array_merge($result, $this->removeDirectory($path));
				            		}
								else
									{
						            	unlink($path);
						                $result[].=$path;
			               			}
		           			}
	       			}
			     closedir($handle);
			     rmdir($dirname);
			     $result[].=$dirname;
			     return $result;
	   		}
		else
			{
		       return false;
		   	}
	}

/**
 * used to top of the ajax pages
 *
 * @access	public
 * @param
 * @return	static
 */
function setHeaderStart($check_login=false)
	{
		global $CFG;
		ob_start();
		header("Pragma: no-cache");
		header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
		header("Expires: 0"); // Date in the past
		header("Content-type: text/xml; charset=\"".$CFG['site']['charset']."\"");
		if($check_login)
			echo 'check|||||||||valid|||||||||login';
	}

/**
 * used to bottom of the ajax pages
 *
 * @access	public
 * @param
 * @return	static
 */
function setHeaderEnd()
	{
		ob_end_flush();
	}

/**
 * to check given url valid or not with using curl
 *
 * @access	public
 * @param	string
 * @return	boolean
 */
function chkIsValidUrlUsingCurl($url)
	{
		if(!strstr($url, '://'))
			$url = 'http://'.$url;

		if (function_exists('curl_init'))
			{
				$ch = @curl_init();
				if ($ch)
				    {
						curl_setopt($ch, CURLOPT_URL, $url);
						curl_setopt($ch, CURLOPT_HEADER, 0);
						curl_setopt($ch, CURLOPT_NOBODY, 1);
						curl_setopt($ch, CURLOPT_RANGE, "0-1");
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
						curl_setopt($ch, CURLOPT_TIMEOUT, 10);
						$result = curl_exec($ch);
						$errno = curl_errno($ch);
						curl_close($ch);
						if ($errno!=0)
							{
								return false;
							}
				    }
			}
		return true;
	}

function getContents($url)
	{
		$result = '';

		if(!strstr($url, '://'))
			$url = 'http://'.$url;

		if (function_exists('curl_init'))
			{
				$ch = curl_init($url);
				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
			    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');
			    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			    $result = curl_exec($ch);
			    if (!curl_errno($ch))
			        curl_close($ch);
			     else
			        $result = false;
			}
		else
			{
				set_time_limit(180);
				$result = file_get_contents($url) ;
			}
		return $result;
	}

/**
 * used to get the font size of based on count(like search count)
 *
 * @access	public
 * @param	array
 * @return	array
 */
function setFontSizeForTagCloud($tag_array=array())
	{
		$formattedArray = $tag_array;
		$max_qty = max(array_values($formattedArray));
		$min_qty = min(array_values($formattedArray));
		$max_font_size = 28;
		$min_font_size = 12;
		$spread = $max_qty - $min_qty;
		if (0 == $spread) { // Divide by zero
			$spread = 1;
		}
		$step = ($max_font_size - $min_font_size)/($spread);
			foreach ($tag_array as $catname => $count)
			{
				$size = $min_font_size + ($count - $min_qty) * $step;
				$formattedArray[$catname] = ceil($size);
			}
		return $formattedArray;
	}

/**
 * intialize the template folder
 *
 * @access	public
 * @param	string	value may be ('', 'members/', 'admin/')
 * @return	static
 */
function setTemplateFolder($template_for = '',$module='')
	{
		global $smartyObj, $CFG;


		if($module)
			{

				if($template_for == 'admin/')
					{
						$smartyObj->template_dir 	= $CFG['site']['project_path'].'/design/templates/'.$CFG['html']['template']['default'].'/'.$template_for.$module.'/';
						$smartyObj->compile_dir  	= $CFG['site']['project_path'].'/design/templates/'.$CFG['html']['template']['default'].'/'.getTplFolder().$module.'/templates_c/';
						$smartyObj->css_path  		= $CFG['site']['url'].'/design/templates/'.$CFG['html']['template']['default'].'/'.$template_for.$module.'/css/'.$CFG['html']['stylesheet']['screen']['default'].'/';
					}
				else
					{
						if(isAdmin())
							{
								$smartyObj->template_dir 	= $CFG['site']['project_path'].$module.'/design/templates/'.$CFG['html']['template']['default'].'/'.$template_for;
								$smartyObj->compile_dir  	= $CFG['site']['project_path'].$module.'/design/templates/'.$CFG['html']['template']['default'].'/members/templates_c/';
								$smartyObj->css_path  		= $CFG['site']['url'].$module.'/design/templates/'.$CFG['html']['template']['default'].'/'.$template_for.'css/'.$CFG['html']['stylesheet']['screen']['default'].'/';
							}
						else
							{
								$smartyObj->template_dir 	= $CFG['site']['project_path'].$module.'/design/templates/'.$CFG['html']['template']['default'].'/'.$template_for;
								$smartyObj->compile_dir  	= $CFG['site']['project_path'].$module.'/design/templates/'.$CFG['html']['template']['default'].'/'.getTplFolder().'templates_c/';
								$smartyObj->css_path  		= $CFG['site']['url'].$module.'/design/templates/'.$CFG['html']['template']['default'].'/'.$template_for.'css/'.$CFG['html']['stylesheet']['screen']['default'].'/';
							}
						//Check whether template is available for current module, if not available change template to available template
						if(!is_dir($smartyObj->template_dir))
							{
								foreach($CFG['html']['template']['allowed'] as $available_template)
									{
										$available_template_dir = $CFG['site']['project_path'].$module.'/design/templates/'.$available_template.'/'.$template_for;
										if(is_dir($available_template_dir))
											{
												foreach($CFG['html']['stylesheet'][$available_template]['allowed'] as $available_css)
													{
														$available_css_path  = $CFG['site']['project_path'].$module.'/design/templates/'.$available_template.'/root/css/'.$available_css.'/';
														if(is_dir($available_css_path))
															{
																$smartyObj->template_dir 	= $available_template_dir;
																$smartyObj->compile_dir  	= $CFG['site']['project_path'].$module.'/design/templates/'.$available_template.'/'.getTplFolder().'templates_c/';
																$smartyObj->css_path  		= $CFG['site']['url'].$module.'/design/templates/'.$available_template.'/'.$template_for.'css/'.$available_css.'/';
																break;
															}

													}
											}
									}
							}
					}


			}
		else
			{
				$smartyObj->template_dir = $CFG['site']['project_path'].'design/templates/'.$CFG['html']['template']['default'].'/'.$template_for;
				$smartyObj->compile_dir  = $CFG['site']['project_path'].'design/templates/'.$CFG['html']['template']['default'].'/'.getTplFolder().'templates_c/';
				$smartyObj->css_path  = $CFG['site']['url'].'design/templates/'.$CFG['html']['template']['default'].'/'.$template_for.'css/'.$CFG['html']['stylesheet']['screen']['default'].'/';
				//Check whether template is available for current module, if not available change template to available template
				if(!empty($CFG['site']['is_module_page']))
					{
						//check whether directory exists or not for the current module & current template
						$template_dir_module = $CFG['site']['project_path'].$CFG['site']['is_module_page'].'/design/templates/'.$CFG['html']['template']['default'].'/'.$template_for;
						if(!is_dir($template_dir_module))
							{
								foreach($CFG['html']['template']['allowed'] as $available_template)
									{
										$available_template_dir = $CFG['site']['project_path'].$CFG['site']['is_module_page'].'/design/templates/'.$available_template.'/'.$template_for;
										if(is_dir($available_template_dir))
											{
												$CFG['html']['template']['default'] = $available_template;
												foreach($CFG['html']['stylesheet'][$available_template]['allowed'] as $available_css)
													{
														$available_css_path  = $CFG['site']['project_path'].$CFG['site']['is_module_page'].'/design/templates/'.$available_template.'/root/css/'.$available_css.'/';
														if(is_dir($available_css_path))
															{
																$CFG['html']['stylesheet']['screen']['default'] = $available_css;
																$smartyObj->template_dir 	= $CFG['site']['project_path'].'design/templates/'.$available_template.'/'.$template_for;;
																$smartyObj->compile_dir  	= $CFG['site']['project_path'].'design/templates/'.$available_template.'/'.getTplFolder().'templates_c/';
																$smartyObj->css_path  		= $CFG['site']['url'].'design/templates/'.$available_template.'/'.$template_for.'css/'.$available_css.'/';
																break;
															}

													}
											}
									}
							}
					}
			}
		$smartyObj->cache_dir  = $CFG['site']['project_path'].'design/templates/'.$CFG['html']['template']['default'].'/'.getTplFolder().'cache/';
		$image_path = $CFG['site']['url'].'design/templates/'.$CFG['html']['template']['default'].'/root/images/'.$CFG['html']['stylesheet']['screen']['default'].'/';
		$smartyObj->assign('html_stylesheet', $smartyObj->css_path.$CFG['html']['stylesheet']['screen']['default_file'].'.css');
		$smartyObj->css_defalut_path=$smartyObj->css_path.$CFG['html']['stylesheet']['screen']['default_file'].'.css';

		$smartyObj->assign('images_path', $image_path);
		$smartyObj->assign('html_stylesheet_path', $smartyObj->css_path);
	}

/**
 * return the url
 *
 * @access	public
 * @param	string
 * @return	string
 */
function URL($url)
	{
		return $url;
	}

/**
 * check the current page is ajax request
 *
 * @access	public
 * @param
 * @return	boolean
 */
function isAjaxPage()
	{
		return isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
		    $_SERVER ['HTTP_X_REQUESTED_WITH']  == 'XMLHttpRequest';
	}

/**
 * used to show the help tip
 *
 * @access	public
 * @param	string	key in help file
 * @param	string	name for smarty
 * @return	static
 */
function ShowHelpTip($tip_key, $tipfor = '')
	{
		global $LANG, $CFG;
		$tipfor = $tipfor?$tipfor:$tip_key;
		$tip = str_replace("\n", '
', $LANG['help'][$tip_key]);
?>
<div class="clsHelpText" id="<?php echo $tipfor;?>_Help" style="visibility:hidden"><?php echo $tip;?></div>
<?php
	}

/**
 * check the current page is ajax request
 *
 * @access	public
 * @param
 * @return	boolean
 */
function isAjax()
		{
			return (isset($_REQUEST['ajax_page']) and $_REQUEST['ajax_page']==true) or (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
		    $_SERVER ['HTTP_X_REQUESTED_WITH']  == 'XMLHttpRequest');
		}

/**
 * used to change the format of date
 *
 * @access	public
 * @param	string
 * @return	string
 */
function FMT_DATE($date)
	{
		return $date;
	}

/**
 * used to change the format of amount
 *
 * @access	public
 * @param	string
 * @return	string
 */
function FMT_AMOUNT($amount)
	{
		global $CFG;
		$exponent = pow(10, $CFG['framework']['no_of_decimals']);
		return (floor($amount * $exponent) / $exponent);
	}

/**
 * to display the exposed query
 *
 * @access	public
 * @param	string	error message
 * @param	string	new line character (currently we don't use the argument)
 * @return	static
 */
function ExposeQuery($msg, $newline = '')
	{
		GLOBAL $SQL_QUERIES;
		$SQL_QUERIES .= "\n".$msg."\n";
   	}

/**
 * to display debugging list
 *
 * @access	public
 * @param	string	error name
 * @param	string	error description
 * @return	static
 */
function DEBUG($var_name, $var_desc='')
	{
	    global $CFG, $DEBUG_TRACE;
	    if ($CFG['debug']['is_debug_mode'])
			{
        		$DEBUG_TRACE .= "\n".$var_desc.':';
        		if (!is_array($var_name))
					$var_name = htmlspecialchars($var_name);
        		$DEBUG_TRACE .= print_r($var_name, true);
        		if (is_array($var_name))
					reset($var_name);
        		$DEBUG_TRACE .= "\n";
    		}
	}

/**
 * to redirection
 *
 * @access	public
 * @param	string
 * @return	static
 */
function Redirect2URL($url)
	{
		global $CFG;
		if(isAjaxpage() or $CFG['admin']['session_redirect_light_window_page'])
			{
				if(!isMember())
					{
						unset($_SESSION['url']);
						$param = '';
						if(isAjaxpage() and $CFG['html']['current_script_name'] != 'shareVideo')
							$param = '?ajax_page=true';
						$url = $CFG['auth']['ajax_url'].$param;
					}
			}

		if (!headers_sent())
		    {
			   header('Location: '.URL($url));
			   //if IIS, then send Refresh header too (as a safe solution)...Location header doesn't seems to work in IIS
			   if (stristr($_SERVER['SERVER_SIGNATURE'], 'IIS'))
			   		header('Refresh: 0;url='.$url);
		    }
		else
			{
				trigger_error('Headers already sent', E_USER_NOTICE);
				echo '<meta http-equiv="refresh" content="0; URL='.URL($url).'" />'."\n";
				echo '<p>Please click this <a href="'.URL($url).'">link</a> to continue...</p>'."\n";
			}
		exit(0);
	}

/**
 * to get the advertisement
 *
 * @access	public
 * @param	string	block name
 * @return	string
 */
$______ADVERTISEMENT_ID = array();
function getAdvertisement($block,$not_allowed_page_name=array())
	{
		global $CFG;
		global $db;
		global $______ADVERTISEMENT_ID;
		$block_condition='';
		if(!chkAllowedModule(array('banner')))
			return;
		 $cur_page_name=strtolower(basename($_SERVER['SCRIPT_NAME'], ".php")); /* supposing filetype .php*/

		  if(sizeof($not_allowed_page_name)>0 && in_array($cur_page_name,$not_allowed_page_name))
	 	    {
	 		 return false;
	 		}

	  	$sql = 'SELECT add_id, source FROM '.$CFG['db']['tbl']['advertisement'].' WHERE'.
			' post_from=\'Admin\'AND block=\''.$block.'\''.
			' AND status=\'activate\'';

		if($CFG['admin']['banner']['impressions_date'])
			{
				$sql .= ' AND NOW()>=start_date AND (((allowed_impressions!=\'\' AND allowed_impressions!=0) AND'.
						' (completed_impressions < allowed_impressions)) OR ((allowed_impressions=\'\''.
						' OR allowed_impressions=0) AND (end_date!=\'0000-00-00 00:00:00\''.
						' AND end_date > NOW())))';
			}
		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt, array());
		    if (!$rs)
			    trigger_db_error($db);

		$total_count = $rs->PO_RecordCount();

   		if(!$total_count)
         {
		 $sql = 'SELECT add_id, source FROM '.$CFG['db']['tbl']['advertisement'].' WHERE'.
				' post_from=\'Admin\' AND block LIKE \'%'.$block.'\''.
				' AND status=\'activate\'';

		if($CFG['admin']['banner']['impressions_date'])
			{
				$sql .= ' AND NOW()>=start_date AND (((allowed_impressions!=\'\' AND allowed_impressions!=0) AND'.
						' (completed_impressions < allowed_impressions)) OR ((allowed_impressions=\'\''.
						' OR allowed_impressions=0) AND (end_date!=\'0000-00-00 00:00:00\''.
						' AND end_date > NOW())))';
			}

		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt);
		    if (!$rs)
			    trigger_db_error($db);

		$total_count = $rs->PO_RecordCount();
		}

   		if(!$total_count)
   			return false;

		$add_array = array();

		$need = rand(1, $total_count);
		$i = 1;
		while($row = $rs->FetchRow())
			{
				if($need==$i)
					{
						echo htmlentitydecode($row['source']);
						$______ADVERTISEMENT_ID[$row['add_id']] = $row['add_id'];
						break;
					}

				 $i++;
			}
	}

function htmlentitydecode($text)
	{
		global $CFG;

		$default_charset = strtolower($CFG['site']['charset']);
		$allwable_charsets = array('iso-8859-1', 'iso-8859-15', 'utf-8', 'cp866', 'cp1251',
									'cp1252', 'koi8-r', 'big5', 'gb2312', 'big5-hkscs', 'shift_jis',
									'euc-jp', 'iso8859-1', 'iso8859-15', 'ibm866', '866', 'windows-1251',
									'win-1251', '1251', 'windows-1252', '1252', 'koi8-ru', 'koi8r', '950',
									'936', 'sjis', '932', 'eucjp');

		if(in_array($default_charset, $allwable_charsets))
			{
				$charset = $CFG['site']['charset'];
			}
		else
			{
				$charset = 'ISO-8859-1';
			}

		return @html_entity_decode($text, ENT_QUOTES, $charset);
	}

/**
 * to update the advertisement view count
 *
 * @access	public
 * @param
 * @return	static
 */
function updateAdvertisementCount()
	{
		global $______ADVERTISEMENT_ID;
		global $CFG;
		global $db;

		if(!$CFG['admin']['banner']['impressions_date'])
			return;

		if(sizeof($______ADVERTISEMENT_ID))
			{
				$sql = 'UPDATE '.$CFG['db']['tbl']['advertisement'].' SET'.
						' completed_impressions=completed_impressions+1'.
						' WHERE add_id IN('.implode(',', $______ADVERTISEMENT_ID).')';

				$stmt = $db->Prepare($sql);
				$rs = $db->Execute($stmt);
				    if (!$rs)
					    trigger_db_error($db);

				$______ADVERTISEMENT_ID = array();
			}
	}

function getCleanUrl($url)
	{
		global $CFG;
		if($CFG['feature']['rewrite_mode']=='clean')
			{
				$url = str_replace('&amp;', '/', $url);
				$url = str_replace('?', '/', $url);
				$url = str_replace('&', '/', $url);
				$url = str_replace('=', '/', $url);
			}
		return $url;
	}

function populateGETValue()
	{
		global $CFG;
		if($CFG['feature']['rewrite_mode']=='clean')
			{
				if($CFG['site']['query_string'])
					{
						$query_string = getCleanUrl($CFG['site']['query_string']);
						/*while(strpos($query_string, '//'))
							{
								$query_string = str_replace('//', '/', $query_string);
							}*/
						if(strpos($query_string, '/')===0)
							$query_string = substr($query_string, 1);
						if(strrpos($query_string, '/')==strlen($query_string)-1)
							$query_string = substr($query_string, 0, strlen($query_string)-1);

						$query_string_arr = explode('/', $query_string);
						for($i=0;$i<sizeof($query_string_arr);$i = $i+2)
							{
								$_REQUEST[$query_string_arr[$i]] = $_GET[$query_string_arr[$i]] = isset($query_string_arr[$i+1])?urldecode(str_replace('%25', '%', $query_string_arr[$i+1])):'';
							}
					}
			}
	}
populateGETValue();

/**
 * to get the url based on htaccess setting
 *
 * @access	public
 * @param	string	file_name url
 * @param	string	normal url
 * @param	string	htaccess url
 * @param	boolean	check url need to change or not(it may be current, root, members, nothing)
 * @return	string
 */
function getUrl($file_name, $normal = '', $htaccess = '', $change = '',$module='')
	{
		global $CFG;
		global $folder_names_arr;
		$relativeUrl='';
		if(!$change)
		{
			$change='current';
		}
		$normal = $CFG['page_url'][$file_name]['normal'].$normal;
		$htaccess = $CFG['page_url'][$file_name]['htaccess'].$htaccess;

		if($CFG['feature']['rewrite_mode']=='clean')
			{
				$restricted_pages = array('addbookmark');
				if(!in_array($file_name, $restricted_pages))
					{
						$normal = getCleanUrl($normal);
					}
			}
		if($CFG['feature']['rewrite_mode']=='htaccess')
			{
				if(strrpos($htaccess, '/')==strlen($htaccess)-1 and ($htaccess!=$CFG['site']['url']) and ($htaccess!=$CFG['site']['url'].'/members/') and ($htaccess!=$CFG['site']['url'].'/admin/'))
					{
						$htaccess = substr($htaccess, 0, strrpos($htaccess, '/')).$CFG['feature']['rewrite_mode_endwith'];
					}
				$htaccess = str_replace('/?', '.html?', $htaccess);
				$htaccess = str_replace('/&', '.html&', $htaccess);
			}

		if($module)
		{
			if($CFG['site']['relative_url']==$CFG['site']['url'])
			{
				$relativeUrl=$CFG['site']['url'].$module.'/';

			}
			foreach($folder_names_arr as $folder)
			{
				if($CFG['site']['relative_url']==$CFG['site']['url'].$folder)
				{
					$relativeUrl=$CFG['site']['url'].$module.'/'.$folder;
					break;
				}
			}
			foreach($CFG['site']['modules_arr'] as $mod)
			{

				if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/')
				{
					$relativeUrl=$CFG['site']['url'].$module.'/';
					break;
				}
				if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/members/')
				{
					$relativeUrl=$CFG['site']['url'].$module.'/members/';
					break;
				}
				if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/rss/')
				{
					$relativeUrl=$CFG['site']['url'].$module.'/rss/';
					break;
				}
				if($CFG['site']['relative_url']==$CFG['site']['url'].'admin/'.$mod.'/')
				{
					$relativeUrl=$CFG['site']['url'].'admin/'.$module.'/';
					break;
				}

			}
		$siteUrl=$CFG['site']['url'].$module.'/';

		}
		else
		{
			foreach($CFG['site']['modules_arr'] as $mod)
			{
				if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/')
				{
					$CFG['site']['relative_url']=$CFG['site']['url'];
				}
				if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/members/')
				{
					$relativeUrl=$CFG['site']['url'].'members/';
					break;
				}
				if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/rss/')
				{
					$relativeUrl=$CFG['site']['url'].'rss/';
					break;
				}
				if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/admin/')
				{
					$relativeUrl=$CFG['site']['url'].'admin/';
					break;
				}

			}
		$siteUrl=$CFG['site']['url'];
		}
		if(!$relativeUrl)
		{
			$relativeUrl=$CFG['site']['relative_url'];
			$siteUrl=$CFG['site']['url'];
		}
		switch($change)
			{
				case 'current':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $relativeUrl.$htaccess;
						else
							return $relativeUrl.$normal;
					break;

				case 'root':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $siteUrl.$htaccess;
						else
							return $siteUrl.$normal;
					break;

				case 'members':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $siteUrl.'members/'.$htaccess;
						else
							return $siteUrl.'members/'.$normal;
					break;

				case 'admin':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $siteUrl.'admin/'.$htaccess;
						else
							return $siteUrl.'admin/'.$normal;
					break;

				case 'nothing':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $htaccess;
						else
							return $normal;
					break;
			}
	}

function getCurrentUrl($with_query_string = false)
	{
		global $CFG;
		$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		if(!$with_query_string)
			{
				if(strpos($url, '?'))
					$url = substr($url, 0, strpos($url, '?'));
				if(strpos($url, '.php'))
					$url = substr($url, 0, strpos($url, '.php')+4);
				//$url = $CFG['site']['relative_url'].$CFG['site']['script_name'];
			}
		return $url;
	}

function getQueryString($url)
	{
		if(strpos($url, '?'))
			$url = substr($url, strpos($url, '?'));
		if(strpos($url, '.php'))
			$url = substr($url, strpos($url, '.php')+4);

		return $url;
	}

/**
 * to control the module
 *
 * @access	public
 * @param	array	module list
 * @return	boolean
 */
function chkAllowedModule($module_arr = array())
	{
		global $CFG;
		foreach($module_arr as $key=>$value)
			{
				if(!isset($CFG['admin']['module'][$value]) or
					!$CFG['admin']['module'][$value])
					return false;
			}
		return true;
	}

/**
 * to check member logged in or not
 *
 * @access	public
 * @param
 * @return	boolean
 */
function isMember()
	{
		if(isset($_SESSION['user']['user_id']) and $_SESSION['user']['user_id'])
			return true;
		return false;
	}

function ispaidmember(){
	if(isset($_SESSION['user']['is_paid_member']) and $_SESSION['user']['is_paid_member']=='Yes')
			return true;
		return false;
}

function chkAndUpdatePaidMember(){
	global $db;
	global $CFG;
	$sql = 'SELECT is_paid_member FROM '.$CFG['db']['tbl']['users'].' WHERE user_id ='.$db->Param('user_id');
	$stmt = $db->Prepare($sql);
	$rs = $db->Execute($stmt, array($CFG['user']['user_id']));
	if (!$rs)
		trigger_db_error($db);

	if($row = $rs->FetchRow())
	{
		$_SESSION['user']['is_paid_member']=$row['is_paid_member'];
	}
}

/**
 * to check admin logged in or not
 *
 * @access	public
 * @param
 * @return	boolean
 */
function isAdmin()
	{
		if((isset($_SESSION['user']['user_id']) and $_SESSION['user']['user_id']) and (isset($_SESSION['admin']['is_logged_in']) and $_SESSION['admin']['is_logged_in']))
			return true;
		return false;
	}

/**
 * to check display the block for particular pages
 *
 * @access	public
 * @param	array	pages list
 * @param	boolean	make functionality to reverse
 * @return	boolean
 */
function displayBlock($allowed_pages = array(), $reverse = false)
	{
		global $CFG;
		if($allowed_pages and in_array('index.php', $allowed_pages) and !$reverse)
			$allowed_pages=array_merge($CFG['site']['side_menu_showing_pages'],$allowed_pages);

		$REQUEST_UNAME = (isset($_REQUEST['uname']))?($_REQUEST['uname']):(isset($CFG['user']['user_name'])?$CFG['user']['user_name']:'');
		$script_name = substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/')+1);

		if(!$reverse)
			{
				if(in_array($script_name, $allowed_pages))
					return true;
				return false;
			}
		else
			{
				if(!in_array($script_name, $allowed_pages))
					return true;
				return false;
			}
	}

/**
 * to change the url and email to clickable from given text
 *
 * @access	public
 * @param	string
 * @return	string
 */
function makeClickableLinks($text)
	{
		$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
		$ret = ' ' . $text;
		$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
		$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
		$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
		$ret = substr($ret, 1);
		return $ret;
	}

/**
 * to connect the db
 *
 * @access	public
 * @param
 * @return	static
 */
function dbConnect()
	{
		global $db;
		global $CFG;
		$db->Connect($CFG['db']['hostname'], $CFG['db']['username'], $CFG['db']['password'], $CFG['db']['name']);
		if (!$db)
				trigger_error('DB Connection Error', E_USER_ERROR);
	}
/**
 * to disconnect the db
 *
 * @access	public
 * @param
 * @return	static
 */
function dbDisconnect()
	{
		global $db;
		global $CFG;
		$db->Disconnect();
	}

function getUserDisplayName($user_fields_arr)
	{
		global $CFG;
		$user_fields_arr['user_name'] = isset($user_fields_arr['user_name'])?$user_fields_arr['user_name']:'';
		$user_fields_arr['first_name'] = isset($user_fields_arr['first_name'])?$user_fields_arr['first_name']:'';
		$user_fields_arr['middle_name'] = isset($user_fields_arr['middle_name'])?$user_fields_arr['middle_name']:'';
		$user_fields_arr['last_name'] = isset($user_fields_arr['last_name'])?$user_fields_arr['last_name']:'';

		$display_name = $CFG['username']['display_format'];
		$display_name = str_replace('{first_name}', $user_fields_arr['first_name'], $display_name);
		$display_name = str_replace('{middle_name}', $user_fields_arr['middle_name'], $display_name);
		$display_name = str_replace('{last_name}', $user_fields_arr['last_name'], $display_name);
		$display_name = str_replace('{user_name}', $user_fields_arr['user_name'], $display_name);
		return trim($display_name);
	}

function populateRichTextEdit($field_name='', $value='', $useHtmlSpChars = true)
		{
			global $CFG;
			global $LANG;
			$param = 'framework_page';
			$_SESSION[$param] = urlencode($value);
?>
	<script language="JavaScript" type="text/javascript" src="<?php echo $CFG['site']['url'];?>js/lib/richtext/richtext.js"></script>
	<script language="JavaScript" type="text/javascript">
		var palette_url = '<?php echo $CFG['site']['url'].'js/lib/richtext/palette.htm';?>';
		var field_name = '<?php echo $field_name;?>';
		var filenameNew = "<?php echo $CFG['site']['url'];?>richText.php?htmSpChar=<?php echo $useHtmlSpChars?1:0;?>&source=<?php echo $param;?>";
		function submitForm() {
			updateRTE('rte1');
			alert("rte1 = " + document.RTEDemo.rte1.value);
			return false;
		}
		initRTE("<?php echo $CFG['site']['url'];?>js/lib/richtext/icons/", "<?php echo $CFG['site']['url'];?>js/lib/richtext/", "");
	</script>
	<noscript><p><b><?php echo $LANG['javascript_enabled'];?></b></p></noscript>
	<script language="JavaScript" type="text/javascript">
		if(!b.isFirefox())
			{
				writeRichText('rte1', '', 400, 200, true, false);
			}
	</script>
	<?php
		if ($useHtmlSpChars)
		    {
		        $value = htmlspecialchars($value);
		    }
	?>
	<input type="hidden" id="<?php echo $field_name;?>" name="<?php echo $field_name;?>" value="<?php echo ($value);?>" />
	<script language="JavaScript" type="text/javascript">
		if(b.isFirefox())
			{
				writeRichText('rte1', '', 400, 200, true, false);
			}
	</script>
<?php
		}

	function populateWYSIWYGeditor($field_name)
		{
			global $CFG;
			global $LANG;
			if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'opera'))
				return;
?>
	 <script language="JavaScript" type="text/javascript" src="<?php echo $CFG['site']['url'];?>js/lib/wysiwyg/wysiwyg.js"></script>
	  <script language="javascript" type="text/javascript">
	  	generate_wysiwyg('<?php echo $field_name;?>');
	  </script>
<?php
		}


	function populateTinyMceEditor($field_name='', $value='')
		{
				global $CFG;
				global $LANG;
	?>

		<script type="text/javascript" src="<?php echo $CFG['site']['url'];?>js/lib/tinymce/tiny_mce.js"></script>
		<script type="text/javascript">

		tinyMCE.init({
			// General options
			mode : "exact",
			elements: "<?php echo $field_name; ?>",
			theme : "advanced",//"advanced", "simple"
			plugins : "safari,spellchecker,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

			// Theme options
			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,ltr,rtl",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,|,visualchars,nonbreaking,blockquote,|,forecolor,backcolor,|,print,|,fullscreen",

			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "none",
			width: "100%",
			height : "370",
			theme_advanced_resizing_min_height : 370,
			theme_advanced_resizing_max_height : 500,
			use_native_selects : true,
			convert_urls : false,
   			remove_script_host : false,
			//relative_urls : false,
			//theme_advanced_resizing : true,
			spellchecker_languages : "+English=en",
			tab_focus : ':prev,:next',
			//auto_resize: true
			cleanup_on_startup : true

			// Replace values for the template plugin
			/*template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}*/
		});
		</script>
		<div id="desc_textarea"><textarea name="<?php echo $field_name; ?>"><?php echo $value; ?></textarea></div>
		<noscript><p><b><?php echo $LANG['javascript_enabled'];?></b></p></noscript>

	<?php
		}

	function populateSimpleTinyMceEditor($field_name='', $value='')
		{
				global $CFG;
				global $LANG;
	?>

		<script type="text/javascript" src="<?php echo $CFG['site']['url'];?>js/lib/tinymce/tiny_mce.js"></script>
		<script type="text/javascript">

		tinyMCE.init({
			// General options
			mode : "exact",
			elements: "<?php echo $field_name; ?>",
			theme : "advanced",//"advanced", "simple"
			plugins : "safari,advlink,emotions,inlinepopups,noneditable,xhtmlxtras",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,cleanup,|,styleselect,formatselect,fontselect,fontsizeselect,",
			theme_advanced_buttons2 : "bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,|,link,unlink,|,forecolor,|,code",
			theme_advanced_buttons3 : false,
			theme_advanced_buttons4 : false,

			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "none",
			width: "100%",
			height : "370",
			theme_advanced_resizing_min_height : 370,
			theme_advanced_resizing_max_height : 500,
			use_native_selects : true,
			convert_urls : false,
   			remove_script_host : false,
			//relative_urls : false,
			//theme_advanced_resizing : true,
			//auto_resize: true
			cleanup_on_startup : true

			// Replace values for the template plugin
			/*template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}*/
		});
		</script>
		<div id="desc_textarea"><textarea name="<?php echo $field_name; ?>"><?php echo $value; ?></textarea></div>
		<noscript><p><b><?php echo $LANG['javascript_enabled'];?></b></p></noscript>

	<?php
		}


	function writeLog($file_name, $data)
		{
			global $CFG;
			if($CFG['feature']['log'])
				{
					chkAndCreateFolder($CFG['site']['project_path'].'files/logs/');
					$path = $CFG['site']['project_path'].'files/logs/'.$file_name;
					$seperator = "\n--------------------------------------------------------------------\n\n";
					$data = date('Y-m-d H:i:s')."\n.....................\n".$data.$seperator;
					write_file($path, $data, 'a+');
				}
		}

	function isMemberShipValid($date)
		{
			global $db, $CFG;

			if(!$CFG['feature']['signup_payment'])
				return true;

			$sql = 'SELECT NOW()<\''.$date.'\' AS date_diff';

			$stmt = $db->Prepare($sql);
			$rs = $db->Execute($stmt);
			    if (!$rs)
				    trigger_db_error($db);

			$row = $rs->FetchRow();
			return $row['date_diff'];
		}

	function to7bit($text)
		{
			global $CFG;

			$text = mb_convert_encoding($text,'HTML-ENTITIES',$CFG['site']['charset']);
			$text = preg_replace( array('/&szlig;/','/&(..)lig;/', '/&([aouAOU])uml;/','/&(.)[^;]*;/'), array('ss',"$1","$1".'e',"$1"), $text);
			return $text;
		}

	function getUrlTitle($text)
		{
			$text = to7bit($text);
			$text = ereg_replace ('[^a-zA-Z0-9]', '_', $text);
			return $text;
		}

	function setMetaKeywords($keywords)
		{
			global $LANG,$CFG;

			$currentPage = strtolower($CFG['html']['current_script_name']);

			if(isset($LANG['header_meta_'.$currentPage.'_keywords']))
				{
					$LANG['header_meta_'.$currentPage.'_keywords'] .= ', '.$keywords ;
					return;
				}
			$LANG['header_meta_'.$currentPage.'_keywords'] = $keywords ;
			return;
		}

	function setMetaDescription($description)
		{
			global $LANG,$CFG;

			$currentPage = strtolower($CFG['html']['current_script_name']);

			if(isset($LANG['header_meta_'.$currentPage.'_description']))
				{
					$LANG['header_meta_'.$currentPage.'_description'] .= ' '.$description ;
					return;
				}
			$LANG['header_meta_'.$currentPage.'_description'] = $description ;
			return;
		}

	function setPageTitle($title)
		{
			global $LANG,$CFG;

			$currentPage = strtolower($CFG['html']['current_script_name']);

			if(isset($LANG['header_meta_'.$currentPage.'_title']))
				{
					$LANG['header_meta_'.$currentPage.'_title'] = $title ;
					return;
				}
			$LANG['header_meta_'.$currentPage.'_title'] = $title ;
			return;
		}

	function regSupportText($text)
		{
			$not_su = array('(', ')', '{', '}', '[', ']', '>', '<', '$', '^');
			foreach($not_su as $value)
				{
					if(strstr($text, $value))
						{
							return false;
						}
				}
			return true;
		}


	function getInitialFilterLink()
		{
			global $CFG;
			global $LANG;

			$url = $CFG['site']['url'].'members/changeContentFilterStatus.php';
			$method_type = 'post';

			$onlink = '<a href="#" onClick="return chnageContentFilter(\''.$url.'\', \'status=On\', \''.$method_type.'\')">'.$LANG['header_off_link'].'</a>';
			$onlink_non_member = '<a href="'.getUrl('profilesettings', '', '', 'members').'">'.$LANG['header_on_link'].'</a>';
			$offlink_non_member = '<a href="'.getUrl('profilesettings', '', '', 'members').'">'.$LANG['header_off_link'].'</a>';
			$offlink = '<a href="#" onClick="return chnageContentFilter(\''.$url.'\', \'status=Off\', \''.$method_type.'\')">'.$LANG['header_on_link'].'</a>';

			if (!chkAllowedModule(array('content_filter')))
				return '';

			if($CFG['admin']['is_logged_in'])
				{
					if($CFG['user']['content_filter'] == 'Off')
						return $onlink;
					else if($CFG['user']['content_filter'] == 'On')
						return $offlink;
					return;
				}

			if(isAdultUser('allow'))
				{
					if(isset($CFG['admin']['videos']['adult_content_view'])
						and $CFG['admin']['videos']['adult_content_view']=='No')
						{
							return $LANG['header_on_link'];
						}
					else
						{
							if($CFG['user']['content_filter'] == 'Off')
								{
									if(isMember())
										return $onlink;
									else
										return $onlink_non_member;
								}
							else if($CFG['user']['content_filter'] == 'On')
								{
									if(isMember())
										return $onlink;
									else
										return $onlink_non_member;
								}
							else if(isset($CFG['admin']['videos']['adult_content_view'])
								and $CFG['admin']['videos']['adult_content_view']!='No')
								{
									if(isMember())
										return $onlink;
									else
										return $onlink_non_member;
								}
						}
				}
			else
				{
					if(isset($CFG['admin']['videos']['adult_content_view'])
						and $CFG['admin']['videos']['adult_content_view']=='No')
						{
							return $LANG['header_on_link'];
						}
					else
						{
							if(isMember())
								{
									return $LANG['header_on_link'];
								}
							else
								{
									return $onlink_non_member;
								}
						}
				}
		}

	function searchJavaScriptCode()
		{
?>
<script type="text/javascript">
function changeAction(){
	var obj = document.formCommonSearch;
	var act_url = '';
	if(obj.tags.value=='')
		return false;
	switch (obj.soption.value){
		case 'videos':
			act_url = '<?php echo getUrl('videolist', '?pg=videonew&tags=', 'videonew/?tags=');?>';
			obj.action = act_url+obj.tags.value;
			return true;
			break;

		case 'members':
			act_url = '<?php echo getUrl('memberslist', '?tags=', '?tags=');?>';
			obj.action = act_url + obj.tags.value;
			return true;

		default:
			return false;
			break;
	}
}
function changeActionSub(){
	var obj = document.formCommonSearchSub;
	var act_url = '';
	if(obj.tagsSub.value=='')
		return false;
	switch (obj.soptionSub.value){
		case 'videos':
			act_url = '<?php echo getUrl('videolist', '?pg=videonew&tags=', 'videonew/?tags=');?>';
			act_url = act_url+obj.tagsSub.value;
			act_url = act_url+'&cid='+obj.catIdSub.value;
			obj.action = act_url;
			return true;
			break;

		case 'members':
			act_url = '<?php echo getUrl('memberslist', '?tags=', '?tags=');?>';
			act_url = act_url + obj.tagsSub.value;
			obj.action = act_url;
			return true;

		default:
			return false;
			break;
	}
}
</script>
<?php
		}

	function chkIsAdultUser($dob)
		{
			global $CFG;
			global $db;
			global $LANG;

			$dob_array = explode('-', $dob);
			$date_to_validation = date('Y')-$CFG['admin']['videos']['adult_minimum_age']-2;
			if($dob_array[0]<=$date_to_validation)
				return true;

			$age = date('Y') - date('Y', strtotime($dob));
			if (date('md') < date('md', strtotime($dob)))
				{
			    	$age--;
			    }
			if($CFG['admin']['videos']['adult_minimum_age']<=$age)
				return true;

			return false;
		}

	/**
	 * isAdultUser()
	 *
	 * @param string $function_for = settings, videolist, allow
	 * @param string $module_config = video/music/.. (default = video)
	 * 						- 's' will be added in coding for config $CFG['admin']['videos]['adult_content_view']
	 * @return boolean
	 */
	function isAdultUser($function_for = '', $module_config = 'video')
		{
			global $CFG;

			if (!chkAllowedModule(array('content_filter')))
				return true;

			if (!chkAllowedModule(array($module_config)))
				return false;

			$module_config .= 's';

			if($CFG['user']['adult'])
				{
					if($function_for == 'settings' or $function_for == 'allow')
						{
							if(isset($CFG['admin'][$module_config]['adult_content_view'])
								and $CFG['admin'][$module_config]['adult_content_view']!='No')
									return true;
						}

					if(isset($CFG['admin'][$module_config]['adult_content_view'])
						and $CFG['admin'][$module_config]['adult_content_view']=='No')
							return true;

					if($CFG['user']['content_filter'] == 'Off')
						return true;

					if($CFG['user']['content_filter'] == 'On')
						return false;
				}
			else
				{
					if(isset($CFG['admin'][$module_config]['adult_content_view'])
						and $CFG['admin'][$module_config]['adult_content_view']!='No')
						{
							if($function_for=='settings' or $function_for=='allow')
								{
									if(isset($CFG['admin'][$module_config]['adult_content_view'])
										and $CFG['admin'][$module_config]['adult_content_view']!='No')
											return true;
								}

							if($CFG['user']['content_filter'] == 'Off')
								return true;

							if($CFG['user']['content_filter'] == 'On')
								return false;
						}
					else
						{
							return false;
						}
				}

			$allowed_pages_array = array();
			if(displayBlock($allowed_pages_array))
				{
					if(isset($CFG['admin'][$module_config]['adult_content_view'])
						and $CFG['admin'][$module_config]['adult_content_view']=='No')
							return true;
					else
						return false;
				}

			if($function_for=='list')
				{
					if(isset($CFG['admin'][$module_config]['adult_content_view'])
						and $CFG['admin'][$module_config]['adult_content_view']!='No')
							return true;
				}

			if(isset($CFG['admin'][$module_config]['adult_content_view'])
				and $CFG['admin'][$module_config]['adult_content_view']=='Yes')
					return true;

			return false;
		}

	function getAdultQuery($alias = '', $table='video')
		{
		    global $db;
		    global $CFG;
		    $additional = '';
		    $additional = ' AND exists(SELECT '.$table.'_category_id FROM '.$CFG['db']['tbl'][$table.'_category'].' AS vca WHERE '.$table.'_category_type!=\'Porn\' AND'.' '.$alias.$table.'_category_id=vca.'.$table.'_category_id)';
			return $additional;
		}

	function getRefererForAffiliate()
		{
			global $CFG;

			if(isset($_REQUEST[$CFG['admin']['referrer_query_string']]) and $_REQUEST[$CFG['admin']['referrer_query_string']])
				{
					$referrer = trim($_REQUEST[$CFG['admin']['referrer_query_string']]);
					if($referrer = getReferrerId($referrer))
						{
							if($referrer != $CFG['user']['user_id'])
								return $referrer;
						}
				}
			return 0;
		}

	function allowedGroupCreate()
		{
			global $CFG;
			//if($CFG['admin']['groups']['group_create_permission'] or $CFG['admin']['is_logged_in'])
			if($CFG['admin']['groups']['group_create_permission'])
				return true;
			return false;
		}

	function hpSolutionsRayzz()
		{
			global $smartyObj;

			$captcha_length = 5;
			$captcha_text = rand(pow(10, $captcha_length-1), pow(10, $captcha_length)-1); // if len is 2, 10 to 99
			$_SESSION['current_honeypot'] = $captcha_text; //stuff to session

			$smartyObj->assign('hpSolutionsRayzz',$captcha_text);
			setTemplateFolder('general/');
			$smartyObj->display('hpSolutionsRayzz.tpl');
		}

	function phFormulaRayzz()
		{
			return (isset($_SESSION['current_honeypot']) and $_SESSION['current_honeypot'])?$_SESSION['current_honeypot']:'';
		}

	function getReferer()
		{
			global $CFG;

			if(isset($_REQUEST[$CFG['admin']['referrer_query_string']]) and $_REQUEST[$CFG['admin']['referrer_query_string']])
				{
					$referrer = trim($_REQUEST[$CFG['admin']['referrer_query_string']]);
					if($referrer = getReferrerId($referrer))
						{
							return $referrer;
						}
				}
			if(isset($_COOKIE[$CFG['cookie']['starting_text'].'_referrer']) and $_COOKIE[$CFG['cookie']['starting_text'].'_referrer'])
				{
					if($referrer = chkValidUserId($_COOKIE[$CFG['cookie']['starting_text'].'_referrer']))
						{
							return $referrer;
						}
				}
			return 0;
		}
	function chkValidUserId($user_id)
		{
			global $CFG;
			global $db;
			$sql = 'SELECT user_id FROM '.$CFG['db']['tbl']['users'].
					' WHERE user_id='.$db->Param('user_id').' AND usr_status=\'Ok\'';

			$stmt = $db->Prepare($sql);
			$rs = $db->Execute($stmt, array($user_id));
			    if (!$rs)
				    trigger_error($db->ErrorNo().' '.$db->ErrorMsg(), E_USER_ERROR);

			if($row = $rs->FetchRow())
				return $row['user_id'];
			return false;
		}

	function getImageName($text,$thumb_name='')
		{
			global $CFG;
			if(!$thumb_name)
				$thumb_name=getFileSettingName($text,'Thumb');

			$text = md5($thumb_name.$text);
			return substr($text, 0, 15);
		}
	function getVideoName($text)
		{
		    global $CFG;
			$file_name=getFileSettingName($text,'Video');
			$text = md5($file_name.$text);
			return substr($text, 0, 15);
		}
	function getTrimVideoName($text)
	{
			global $CFG;
			$file_name=getFileSettingName($text,'Trimed');
			$text = md5($file_name.$text);
			return substr($text, 0, 15);
	}
	function getFileSettingName($video_id,$file_type)
		{
		   	global $CFG;
			global $db;
			$video_file_id=getFileSettingId($video_id,$file_type);
		   	if(!$video_file_id)
			   $video_file_id=getCurrentFileSettingId($file_type);

			 $sql = 'SELECT file_name FROM '.$CFG['db']['tbl']['video_files_settings'].
					' WHERE video_file_id=\''.$video_file_id.'\'';

			$stmt = $db->Prepare($sql);
			$rs = $db->Execute($stmt);
			    if (!$rs)
				    trigger_error($db->ErrorNo().' '.$db->ErrorMsg(), E_USER_ERROR);

			if($row = $rs->FetchRow())
				return $row['file_name'];
			return false;
		}
	function getFileSettingId($video_id,$file_type)
		{
			global $CFG;
			global $db;
			$field_name=1;
			if($file_type=='Thumb')
			  $field_name='thumb_name_id';
			else if($file_type=='Video')
			  $field_name='video_file_name_id';
			else if($file_type=='Trimed')
			  $field_name='trimed_video_name_id';

			$sql = 'SELECT '.$field_name.' FROM '.$CFG['db']['tbl']['video'].
					' WHERE  video_id=\''.$video_id.'\'';
			$stmt = $db->Prepare($sql);
			$rs = $db->Execute($stmt);
			    if (!$rs)
				    trigger_error($db->ErrorNo().' '.$db->ErrorMsg(), E_USER_ERROR);

			if($row = $rs->FetchRow())
				return  $row[$field_name];
			return false;
		}
	function getCurrentFileSettingId($file_type)
		{
			global $CFG;
			global $db;
			$sql = 'SELECT video_file_id FROM '.$CFG['db']['tbl']['video_files_settings'].
					' WHERE  status =\'Yes\' AND  file_type=\''.$file_type.'\'';

			$stmt = $db->Prepare($sql);
			$rs = $db->Execute($stmt);
			    if (!$rs)
				    trigger_error($db->ErrorNo().' '.$db->ErrorMsg(), E_USER_ERROR);

			if($row = $rs->FetchRow())
				return  $row['video_file_id'];
			return false;
		}

	function getTimeDiffernceFormat($time)
		{
			global $LANG;
			$date_added_pc = array();

			$date_added_pc = explode(':', $time);

			if(sizeof($date_added_pc)!=3)
				return '0 '.$LANG['timediff_seconds_ago'];

			$date_added_pc[0] = intval($date_added_pc[0]);
			$date_added_pc[1] = intval($date_added_pc[1]);
			$date_added_pc[2] = intval($date_added_pc[2]);

			if($date_added_pc[0])
				{
					$day = floor($date_added_pc[0]/24);
					if($day>365)
						{
							$year = floor($day/365);
							if($year>1)
								$time = $year.' '.$LANG['timediff_years_ago'];
							else
								$time = $year.' '.$LANG['timediff_year_ago'];
						}
					else if($day>30)
						{
							$month = floor($day/30);
							if($month>1)
								$time = $month.' '.$LANG['timediff_months_ago'];
							else
								$time = $month.' '.$LANG['timediff_month_ago'];
						}
					else if($day)
						{
							if($day>1)
								$time = $day.' '.$LANG['timediff_days_ago'];
							else
								$time = $day.' '.$LANG['timediff_day_ago'];
						}
					else
						{
							if($date_added_pc[0]>1)
								$time = $date_added_pc[0].' '.$LANG['timediff_hours_ago'];
							else
								$time = $date_added_pc[0].' '.$LANG['timediff_hour_ago'];
						}
				}
			else if($date_added_pc[1])
				{
					if($date_added_pc[1]>1)
						$time = $date_added_pc[1].' '.$LANG['timediff_minutes_ago'];
					else
						$time = $date_added_pc[1].' '.$LANG['timediff_minute_ago'];
				}
			else
				{
					if($date_added_pc[2]>1)
						$time = $date_added_pc[2].' '.$LANG['timediff_seconds_ago'];
					else
						$time = $date_added_pc[2].' '.$LANG['timediff_second_ago'];
				}

			return $time;
		}

	function wordWrapManual($text, $length, $total_length=0, $truncate_to_total_length=false)
		{
			$text=stripslashes($text);
			if(!$total_length)
				return wordWrapManualWithSpace($text,$length);
			if($total_length and strlen($text)>$total_length)
				$text = substr($text, 0, $total_length).' ...';
			if($truncate_to_total_length)
				return $text;
			return wordwrap($text, $length, '<br/>', 1);
		}

	function wordWrapManualWithSpace($string, $totlength, $total_length=0)
		{
			$length = strlen($string);
			//$skip=$wrap=$returnvar='';
			for ($i=0; $i<=$length; $i=$i+1)
				{
					$char = substr($string, $i, 1);
					if ($char == "<")
						$skip=1;
					elseif ($char == ">")
						$skip=0;
					elseif ($char == " ")
						$wrap=0;
					if(!isset($skip))
						$skip=0;
					if(!isset($wrap))
						$wrap = 0;
					if ($skip==0)
						$wrap=$wrap+1;

					if(!isset($returnvar))
						$returnvar = '';
					$returnvar = $returnvar . $char;

					if ($wrap>$totlength) // alter this number to set the maximum word length
						{
							$returnvar = $returnvar . "<wbr>";
							$wrap=0;
						}
				}

			if($total_length and strlen($returnvar)>$total_length)
				$returnvar = substr($returnvar, 0, $total_length).' ...';

			return $returnvar;
		}

	function wordWrap_mb_Manual($text, $length, $total_length=0, $truncate_to_total_length=false)
		{
			global $CFG;
			if(!function_exists('mb_strlen'))
				{
					return wordWrapManual($text, $length, $total_length, $truncate_to_total_length);
				}

			$text=stripslashes($text);

			if(!$total_length)
				return wordWrap_mb_ManualWithSpace($text,$length);

			if($total_length and mb_strlen($text,'utf-8')>$total_length)
				$text = mb_substr($text, 0, $total_length,'utf-8').' ...';

			if($truncate_to_total_length)
				return $text;
			return wordwrap($text, $length, '<br>', 1);
		}

	function wordWrap_mb_ManualWithSpace($string, $totlength, $total_length=0)
		{
			global $CFG;

			if(!function_exists('mb_strlen'))
				{
					return wordWrapManualWithSpace($string, $totlength, $total_length);
				}

			$length = mb_strlen($string,'utf-8');
			//$skip=$wrap=$returnvar='';
			for ($i=0; $i<=$length; $i=$i+1)
				{
					$char = mb_substr($string, $i, 1,'utf-8');
					if ($char == "<")
						$skip=1;
					elseif ($char == "&") //Added for Article module to leave HTML Character Entities
						$skip=1;
					elseif ($char == ">")
						$skip=0;
					elseif ($char == " ")
						$wrap=0;
					elseif ($char == ";") //Added for Article module to leave HTML Character Entities
						$wrap=0;
					if(!isset($skip))
						$skip=0;
					if(!isset($wrap))
						$wrap = 0;
					if ($skip==0)
						$wrap=$wrap+1;

					if(!isset($returnvar))
						$returnvar = '';
					$returnvar = $returnvar . $char;

					if ($wrap>$totlength) // alter this number to set the maximum word length
						{
							$returnvar = $returnvar . "<wbr>";
							$wrap=0;
						}
				}


				if($total_length and mb_strlen($returnvar,'utf-8')>$total_length)
				$returnvar = mb_substr($returnvar, 0, $total_length,'utf-8').' ...';

			return $returnvar;
		}

	function getMemberProfileUrl($user_id = 0, $user_name = '', $extra_query_string='')
		{
			global $CFG;
			$normalUrl = '?user='.$user_name;
			$seoUrl    = $user_name.'/';
			if ($extra_query_string)
			    {
					$normalUrl .= '&'.$extra_query_string;
					$seoUrl .= '?'.$extra_query_string;
			    }
			$profileUrl = getUrl('viewprofile', $normalUrl, $seoUrl,'root');
			return $profileUrl;
		}

	function getMemberReferrerUrl($url = '')
		{
			global $CFG;

			if(isloggedIn())
				{
					if(strpos($url, '?'))
						return $url.'&'.$CFG['admin']['referrer_query_string'].'='.$CFG['user']['user_name'];
					else
						return $url.'?'.$CFG['admin']['referrer_query_string'].'='.$CFG['user']['user_name'];
				}
			return $url;
		}

	function isloggedIn()
		{
			if(isset($_SESSION['user']['user_id']) and $_SESSION['user']['user_id'])
				return true;
			return false;
		}
	function getRandomFieldOfVideoTable()
		{
			$rand_fields_arr = array('video_id', 'user_id', 'video_album_id', 'video_category_id', 'rating_total', 'rating_count', 'total_views', 'total_comments', 'total_favorites', 'total_downloads');
			srand((float) microtime() * 10000000);
			$rand_keys = array_rand($rand_fields_arr);
			return $rand_fields_arr[$rand_keys];
		}

		//added this function since we got issue while searching arab tags and used this in videolist and search list

	function getSearchRegularExpressionQueryModified($tags, $field_name, $extra = '')
		{
			global $CFG;
			$tags = addslashes($tags);
			if($CFG['admin']['search']['regular_expression'])
				{
					//$additional_query = ' ('.$field_name.' REGEXP \''.getSearchString($tags).'\') '.$extra.' ';
				}
			else
				{
					//$additional_query = ' MATCH('.$field_name.') AGAINST (\''.addslashes($tags).'\' IN BOOLEAN MODE) '.$extra.' ';
				}
			 $additional_query = ' ('.getSearchStringModified($field_name, $tags).') '.$extra.' ';

			return $additional_query;
		}

	//added this function since we got issue while searching arab tags and used this in videolist and search list
	function getSearchStringModified($field_name, $tags)
		{
			$tags= ($tags);
			$tags=str_replace('%20',' ',$tags);
		//	return $tags = '[[:<:]]'.preg_replace('/\s+/', '|', addslashes($tags)).'[[:>:]]';

			$tags = trim($tags);
			$tags=str_replace('%20',' ',$tags);
			while(strpos($tags, '  '))
				{
					$tags = str_replace('  ', ' ', $tags);
				}
			$tags = addslashes($tags);
			$tags_arr = explode(' ', $tags);
			$tags = '( ';
			foreach($tags_arr as $value)
				{
			 		$tags .= $field_name .' like "%'.validFieldSpecialChr($value).'%"' . ') OR (';
			 	}
			 $tags = substr($tags, 0,  	strrpos($tags, 'OR'));
			//$tags = '[[:<:]]'.implode('[[:>:]]|[[:<:]]', $tags_arr).'[[:>:]]';
			return $tags;
		}

	function rankUsersRayzz($allow_flag=true, $user_id)
		{
			//This function is set because, further this need to be modified for admins ratings.
			global $CFG;
			if($allow_flag)
				return true;
			return ($user_id != $CFG['user']['user_id']);
		}
	function urlDecodeManual($message='')
		{
			return str_replace('%5C%22','',$message);
		}

	function redirectToMemberPage()
		{
			global $CFG;
			if(isset($_SESSION['user']['user_id']) and $_SESSION['user']['user_id'] and !strpos($_SERVER['REQUEST_URI'], 'members/'))
				{
					/*echo $str_replace, '<br>';
					echo $CFG['site']['project_path_relative'], '<br>';
					echo $CFG['site']['project_path_relative'], '<br>';
					echo $_SERVER['REQUEST_URI'], '<br>';*/

					$str_replace = str_replace_once($CFG['site']['project_path_relative'], $CFG['site']['project_path_relative'].'members/', $_SERVER['REQUEST_URI'],1);
					Redirect2URL($str_replace);
				}
		}

	function getSeoTitle($title)
		{
			global $CFG;
			$seoTitle = $title;
			$seoTitle = seoFriendlyText($seoTitle, $CFG['site']['charset']);
			$seoTitle = ereg_replace ('[^a-zA-Z0-9]', '-', trim($seoTitle));
			$seoTitle = preg_replace('/(-)+$/','',$seoTitle);
			$seoTitle = ($seoTitle)?$seoTitle:'1';
			return $seoTitle;
		}

	function seoFriendlyText($text,$from_enc)
		{
		global $CFG;
		if(function_exists('mb_strlen'))
		{
		    $text = mb_convert_encoding($text,'HTML-ENTITIES',$from_enc);
		    $char_search = array('&quot;','&amp;','&lt;','&gt;','ş','ı','&uuml;','&ouml;','&euml;','&auml;','&Auml;','&agrave;','&ccedil;','&eacute;',
								 '&icirc;','&szlig;','&scaron;','ť','ž','ľ','č','ě','ď','ň','ř','ů','ĺ',
								 '&Scaron;','Ť','Ž','Ľ','Č','Ě','Ď','Ň','Ř','Ů','Ĺ',
								 'ł','ą','ż','ę','ć','ń','ś','ź',
								 'Ł','Ą','Ż','Ę','Ć','Ń','Ś','Ź',
								 'Ă','ă','Ş','ş','Ţ','ţ','đ','Đ',
								 'Ő','ő','Ű','ű','Ў','ў','Є','є','Ґ','ґ',
								 '&THORN;','&thorn;','&Ouml;','&ETH;','&eth;');
			$char_replace =array('','and','', '','s','i','u','o','e','a','A','a','c','e',
								 'i','B','s','t','z','l','c','e','d','n','r','u','l',
								 'S','T','Z','L','C','E','D','N','R','U','L',
								 'l','a','z','e','c','n','s','z',
								 'L','A','Z','E','C','N','S','Z',
								 'A','a','S','s','T','t','d','D',
								 'O','o','U','u','Y','y','E','e','R','r',
								 'Th', 'th', 'O', 'D', 'd');
			$text = str_replace($char_search, $char_replace, $text);
		    $text = preg_replace(
		        array('/&szlig;/','/&(..)lig;/',
		             '/&([aouAOU])uml;/','/&(.)[^;]*;/'),
		        array('ss',"$1","$1".'e',"$1"),
		        $text);
			}
		return strtolower($text);
		}
	function stripString($str, $length=25)
		{
			if (strlen($str) > $length )
				$str = substr($str, 0, ($length-3)).'...';
			return $str;
		}
	function getStringLength($string)
	{
		global $CFG;
		if(function_exists('mb_strlen'))
		{
			return mb_strlen($string);
		}
		else
		{
			return strlen($string);
		}
	}
	function getRandomFieldOfPhotoTable()
	{
		$rand_fields_arr = array('photo_id', 'user_id', 'photo_album_id', 'photo_category_id', 'rating_total', 'rating_count', 'total_views', 'total_comments', 'total_favorites');
		srand((float) microtime() * 10000000);
		$rand_keys = array_rand($rand_fields_arr);
		return $rand_fields_arr[$rand_keys];
	}
	function getCategoryFilter($category_type, $module_type='video')
	{
		global $CFG;
		$module_type .= 's';
		$type='';
		if(!isLoggedIn())
			$_SESSION['user']['content_filter'] ='On';

		if($_SESSION['user']['content_filter'] =='On')
			$type=' AND '.$category_type.' = \'General\'';

		if(!isAdultUser())
		{
			if($CFG['admin'][$module_type]['adult_content_view']=='No')
			{
				$type = ' AND '.$category_type.'!=\'Porn\'';
			}
		}
		return $type;
	}
	function rayzzMvInKL($video_id='')
	{
		global $db;
		global $CFG;

		if(!isset($_SESSION['user']['quick_links']))
			return false;
		elseif(!trim($_SESSION['user']['quick_links']))
			return false;

		$avail_quick_link_video_arr=explode(',',$_SESSION['user']['quick_links']);
		if(!is_array($avail_quick_link_video_arr))
			return false;

		$return=in_array($video_id,$avail_quick_link_video_arr);
		if($return!==false)
			return true;
		return false;
	}

	function mvFileRayzz($video_id)
	{
		$text_return=md5($video_id);
		return substr($text_return, 0, 25);
	}
	  function membersRelRayzz($user_details_arr=array(), $menu_coded_manually=false, $id_generate='')
		{
						if(!$user_details_arr)
							return false;
						global $db;
						global $CFG;
						global $LANG;
			?>
			       <div style="visibility: hidden;position: absolute;" <?php if($menu_coded_manually) { ?> onmouseover="mopen('<?php echo $id_generate; ?>')" onmouseout="mclosetime()" id="<?php echo $id_generate; ?>" <?php } ?>  class="clsMenuSearch">


			<?php

					if(chkAllowedModule(array('video')))
						{

			?>
						<a href="<?php echo getUrl('videolist','?pg=uservideolist&user_id='.$user_details_arr['user_id'], 'uservideolist/?user_id='.$user_details_arr['user_id']);?>"><?php echo $LANG['viewprofile_link_view_videos'];?></a>
			<?php
						}
			?>
						<a href="<?php echo getUrl('viewfriends','?user='.$user_details_arr['user_name'], $user_details_arr['user_name'].'/');?>"><?php echo $LANG['viewprofile_link_view_friends'];?></a>
					</div>
			<?php
		}

function getHotLinkProtectionString()
		{
			return;
			global $CFG;
			$filename = $CFG['site']['project_path'].'hotlink.txt';
			if(is_file($filename))
				{
					$handle = fopen($filename, "r");
					$contents = fread($handle, filesize($filename));
					fclose($handle);
					$contents = trim($contents);
					if($contents)
						return $contents.'/';
				}
			return;
		}

		/**
	 * ViewVideo::chkValidVideoId()
	 *
	 * @return
	 **/
	function validVideoIdRevised($video_id)
		{
			global $db;
			global $CFG;
			global $LANG;
			if (!$videoId=$video_id)
		        return false;
			$condition = 'p.video_status=\'Ok\' AND SUBSTRING(MD5(p.video_id), 1, 25)='.$db->Param($videoId);
			$sql = 'SELECT video_id, allow_embed, flv_upload_type, video_flv_url, video_server_url FROM '.$CFG['db']['tbl']['video'].' as p'.
					' WHERE '.$condition.' LIMIT 0,1';
			$stmt = $db->Prepare($sql);
			$rs = $db->Execute($stmt, array($videoId));
			    if (!$rs)
				    trigger_error($db->ErrorNo().' '.$db->ErrorMsg(), E_USER_ERROR);
			if($row = $rs->FetchRow())
				return $row;
			return false;
		}

		function getReferrerId($referrer)
		{
			global $CFG;
			global $db;

			$sql = 'SELECT user_id FROM '.$CFG['db']['tbl']['users'].
					' WHERE user_name='.$db->Param('user_name').' AND usr_status=\'Ok\'';

			$stmt = $db->Prepare($sql);
			$rs = $db->Execute($stmt, array($referrer));
			    if (!$rs)
				    trigger_error($db->ErrorNo().' '.$db->ErrorMsg(), E_USER_ERROR);

			if($row = $rs->FetchRow())
				return $row['user_id'];
			return false;
		}

		function mvKLRmRayzz($video_id)
		{
			//str_replace($videoid.',','',$_SESSION['user']['quick_links']);
			if(isset($_SESSION['user']['quick_links']) and trim($_SESSION['user']['quick_links']))
				{
					$avail_quick_link_video_arr=$to_result_arr=explode(',',$_SESSION['user']['quick_links']);
					if(is_array($avail_quick_link_video_arr))
						{
							foreach($avail_quick_link_video_arr as $index=>$value)
								if($value==$video_id)
									unset($to_result_arr[$index]);
						}
					$_SESSION['user']['quick_links']=implode(',',$to_result_arr);
				}
		}

		function mvKLHRmRayzz($video_id)
		{
			if(isset($_SESSION['user']['quick_history']) and trim($_SESSION['user']['quick_history']))
				{
					$avail_quick_link_video_arr=$to_result_arr=explode(',',$_SESSION['user']['quick_history']);
					if(is_array($avail_quick_link_video_arr))
						{
							foreach($avail_quick_link_video_arr as $index=>$value)
								if($value==$video_id)
									unset($to_result_arr[$index]);
						}
					$_SESSION['user']['quick_history']=implode(',',$to_result_arr);

					//echo 'Removed';
				}
		}


		function fileGetContentsManual($url, $check_for_url_exists=false)
		{

			if($check_for_url_exists)
				{
					if (function_exists('curl_init'))
						{
							$ch = @curl_init();
							if ($ch)
							    {
									curl_setopt($ch, CURLOPT_URL, $url);
									curl_setopt($ch, CURLOPT_HEADER, 0);
									curl_setopt($ch, CURLOPT_NOBODY, 1);
									curl_setopt($ch, CURLOPT_RANGE, "0-1");
									curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
									curl_setopt($ch, CURLOPT_TIMEOUT, 10);
									$result = curl_exec($ch);
									$errno = curl_errno($ch);
									curl_close($ch);
									if ($errno!=0)
										return false;
							    }
						}
					return true;
				}

			if(file_exists($url) or !function_exists('curl_init'))
				return @file_get_contents($url);


			$options = array(
			        CURLOPT_RETURNTRANSFER => true,     // return web page
			        CURLOPT_HEADER         => false,    // don't return headers
			        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
			        CURLOPT_ENCODING       => "",       // handle all encodings
			        CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2", // who am i
			        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
//			        CURLOPT_CONNECTTIMEOUT => 60,      // timeout on connect
			        CURLOPT_TIMEOUT        => 300,      // timeout on response
			        CURLOPT_MAXREDIRS      => 3,       // stop after 10 redirects
			    );

			    $ch      = curl_init( $url );
			    curl_setopt_array( $ch, $options );
			    $content = curl_exec( $ch );
			    $err     = curl_errno( $ch );
			    $errmsg  = curl_error( $ch );
			    $header  = curl_getinfo( $ch );
			    curl_close( $ch );

			    $header['errno']   = $err;
			    $header['errmsg']  = $errmsg;
			    $header['content'] = $content;


				if ( $header['errno'] != 0 )
						return false;

				if ( $header['http_code'] != 200 )
					return false;

				return $content;

		}
		function mvInKLRayzz($video_id='')
		{
			global $db;
			global $CFG;

			if(!isset($_SESSION['user']['quick_links']))
				return false;
			elseif(!trim($_SESSION['user']['quick_links']))
				return false;

			$avail_quick_link_video_arr=explode(',',$_SESSION['user']['quick_links']);
			if(!is_array($avail_quick_link_video_arr))
				return false;

			$return=in_array($video_id,$avail_quick_link_video_arr);
			if($return!==false)
				return true;
			return false;
		}

	function getEncodedFaceBookMsg($msg)
		{
			global $LANG;
			if($msg)
				{
					$msg = urlencode(base64_encode(gzcompress($msg)));
				}
			return $msg;
		}

	function getDecodedFaceBookMsg($msg)
		{
			global $LANG;
			if($msg)
				{
					$msg = nl2br(gzuncompress(base64_decode(urldecode($msg))));
				}
			return $msg;
		}
	function getContentFilterStatusLink($status)
		{
			global $CFG;
			global $LANG;

			$url = $CFG['site']['url'].'members/changeContentFilterStatus.php';
			$method_type = 'post';

			$onlink = '<a href="#" onClick="return chnageContentFilter(\''.$url.'\', \'status=On\', \''.$method_type.'\')">'.$LANG['off_link'].'</a>';
			$onlink_non_member = '<a href="'.getUrl('profilesettings').'">'.$LANG['off_link'].'</a>';
			$offlink = '<a href="#" onClick="return chnageContentFilter(\''.$url.'\', \'status=Off\', \''.$method_type.'\')">'.$LANG['on_link'].'</a>';

			if(isset($CFG['admin']['videos']['adult_content_view']) and $CFG['admin']['videos']['adult_content_view']=='No')
				{
					echo $LANG['on_link'];
				}
			if($status == 'On')
				{
					echo $offlink;
				}
			else
				{
					echo $onlink;
				}
		}

	function getHeadersManual($url)
		{
			if (function_exists('curl_init'))
				{
					$ch = curl_init();
				    curl_setopt($ch, CURLOPT_URL,            $url);
				    curl_setopt($ch, CURLOPT_HEADER,         true);
				    curl_setopt($ch, CURLOPT_NOBODY,         true);
				    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				    curl_setopt($ch, CURLOPT_TIMEOUT,        15);
				    $result = curl_exec($ch);
				    if (!curl_errno($ch))
				    	{
				        	curl_close($ch);
							if(preg_match('/[2][0][0][ ][O][K]/' ,$result))
								{
									return true;
								}
				        }
				}
			else
				{
					$result = @get_headers($url);
					if(preg_match('/[2][0][0][ ][O][K]/' ,$result[0]))
						{
							return true;
						}
				}
			return false;
		}
	function chkAndCreateFolder($folderName)
			{
				$folder_arr = explode('/', $folderName);
				$folderName = '';
				foreach($folder_arr as $key=>$value)
					{
						$folderName .= $value.'/';
						if($value == '..' or $value == '.')
							continue;
						if (!is_dir($folderName))
							{
								mkdir($folderName);
								@chmod($folderName, 0777);
							}
					}
			}

	/**
	 * additionalAdminGeneralMenuLinks()
	 * to display the dynamic links from db.
	 *
	 * @access	public
	 */
	function additionalAdminGeneralMenuLinks(){
			global $CFG;
			global $db;
			global $smartyObj;

			$sql ='SELECT * FROM '.$CFG['db']['tbl']['additional_menu_links'].' WHERE module = \'general\' AND menu_type=\'main\' AND status =\'yes\' AND parent_id =0 ';
			$stmt = $db->Prepare($sql);
			$rs = $db->Execute($stmt);
		    if (!$rs)
			    trigger_error($db->ErrorNo().' '.$db->ErrorMsg(), E_USER_ERROR);

			$row = array();
			$rowValue = array();
			$admin_menu_arrays = array();
			$mainMenuId = '';
			$i = 0;
			if ($rs->PO_RecordCount()){
				while($row = $rs->FetchRow()){
					$admin_menu_arrays[$i]['menu_name'] = $row['menu_name'];
					$row['link_file'] 					= explode('config_file_name=', $row['link_file']);
					$admin_menu_arrays[$i]['menu_id']   = $row['link_file']['1'];
					$admin_menu_arrays[$i]['link_file'] = $row['link_file'];
					$admin_menu_arrays[$i]['module']    = $row['module'];

					$subMenuSql  = 'SELECT * FROM '.$CFG['db']['tbl']['additional_menu_links'].' WHERE status =\'yes\' AND parent_id ='.$row['additional_menu_links_id'];
					$subMenustmt = $db->Prepare($subMenuSql);
					$subMenuRS   = $db->Execute($subMenustmt);
				    if (!$subMenuRS)
					    trigger_error($db->ErrorNo().' '.$db->ErrorMsg(), E_USER_ERROR);
					$j = 0;
					if ($subMenuRS->PO_RecordCount()){
						while($rowValue = $subMenuRS->FetchRow()){
							$admin_menu_arrays[$i]['subMenu'][$j]['menu_name'] = $rowValue['menu_name'];
							$admin_menu_arrays[$i]['subMenu'][$j]['menu_id']   = str_replace('.php','',$rowValue['link_file']);
							$admin_menu_arrays[$i]['subMenu'][$j]['link_file'] = $rowValue['link_file'];
							$admin_menu_arrays[$i]['subMenu'][$j]['module']    = $rowValue['module'];
							$editConfigFile = strpos($rowValue['link_file'],'editConfig');
							if($rowValue['module'] == ''){
								$admin_menu_arrays[$i]['subMenu'][$j]['url']     = $CFG['site']['url'].'admin/'.$rowValue['link_file'].'&div='.$admin_menu_arrays[$i]['menu_id'];
								$listHighLight = explode('config_file_name=',$rowValue['link_file']);
								$admin_menu_arrays[$i]['subMenu'][$j]['menu_id'] = 'edit'.$listHighLight[1];
							}
							else
								$admin_menu_arrays[$i]['subMenu'][$j]['url']   = $CFG['site']['url'].'admin/'.$rowValue['module'].'/'.$rowValue['link_file'];
							$j++;
						}
					}
					$mainMenuId .= $admin_menu_arrays[$i]['menu_id'].',';

					$i++;
				}
				$mainMenuId = substr($mainMenuId,0,-1);
?>
				<script language="javascript" type="text/javascript">
					var inc = divArray.length;
					var temp_menu_array        = '<?php echo $mainMenuId;?>';
					var temp_general_menu_array  = new Array();
					temp_general_menu_array = temp_menu_array.split(',');
					for(jnc=0;jnc<temp_general_menu_array.length;jnc++){
						if((divArray.join().indexOf(temp_general_menu_array[jnc])>=0) == false)
							divArray[inc++] = temp_general_menu_array[jnc];
					}
				</script>
<?
			}
			global $smartyObj;
		    setTemplateFolder('admin/','');
		    $smartyObj->assign('admin_main_menu_arr', $admin_menu_arrays);
		}

	/**
	 * validFieldSpecialChr()
	 *   USED TO CHANGE % to \% in search field if present in Starting or End of the string
	 *
	 * @param string $field
	 * @return string
	 */
	function validFieldSpecialChr($field)
		{
			if($field == '')
				return $field;

			$field=addslashes($field);
			if($field[0]=='%' || substr($field, strlen($field)-1)=='%')
				{
					$field = ereg_replace("%", '\%', $field);
				}
			return $field;
		}
	/**
	 * @highlight words
	 *
	 * @param string $text
	 *
	 * @param array $words
	 *
	 * @return string
	 *
	 */
	function highlightWords($string, $word)
		{
			$words=explode(' ',$word);
			foreach ( $words as $word )
			    {
			        $string = @str_ireplace($word, '<em class="clsHighlight">'.$word.'</em>', $string);
			    }
		     /*** return the text ***/
		     return $string;
		}
?>

Edited by premier213: problem line 3461 and 3462

6
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by diafol
0

LMAO.
Perhaps a mod can replace line 2 .. 3461 with [a lot of irrelevant code that misses one curly bracket] ?
@premier213, your code misses a curly bracket :)

Edit: actually, there are equally as many { as } , what error do you get?

Edited by twiss: n/a

1

:) This guy takes the biscuit. In fact he takes a whole pallet full of them.

Votes + Comments
Now i know how you got so many solved threads. lol
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.