Location: PHPKode > projects > injooosm > components/com_injooosm/helpers/helper.php
<?php
/**
 * Joomla! 1.5 component injooosm
 *
 * @version $Id: helper.php 2010-02-08 16:55:00$
 * @author Christian Knorr
 * @package injooosm
 * @subpackage frontend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

class injooosmHelper {

	function getConfig() {
		global $mainframe;
		$db =& JFactory::getDBO();
		$query = "SELECT * FROM #__osm_config WHERE id=1";
		$db->setQuery($query);
		$object = $db->loadObject();
		return $object;
	}

/**
 * Fetchs lat/lon from users given ID, otherwise from all users
 */
function getLatLon($uid=false) {
	global $mainframe;
	$db =& JFactory::getDBO();
	$query = "SELECT id,name,username,osmlat,osmlon,osmvisible FROM #__users";
	if ($uid !== false)
		$query .= " WHERE id='".$uid."'";
	$db->setQuery($query);
	$object = $db->loadObjectList();
	return $object;
}

}

	/**
	 *
	 * @param string $distance
	 * @return string
	 */
	function getMiles($distance) {
		$miles = round($distance * 0.621, 2);
		return $miles;
	}

	/**
	 * creates the images
	 * 
	 * @param string $file_tmp_name
	 * @param string $ext
	 * @param string $filepath
	 */
	function createImage($file_tmp_name, $ext, $filepath) {
		switch (strtolower($ext)) {
			case 'jpeg':
			case 'pjpeg':
			case 'jpg':
				$src = ImageCreateFromJpeg($file_tmp_name);
				break;

			case 'png':
				$src = ImageCreateFromPng($file_tmp_name);
				break;

			case 'gif':
				$src = ImageCreateFromGif($file_tmp_name);
				break;

		}
		list($width,$height)=getimagesize($file_tmp_name);
		$newwidth=460;//set file width to 460
		$newheight=($height/$width)*460;//the height are set according to ratio
		$tmp=imagecreatetruecolor($newwidth,$newheight);
		imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);//resample the image
		switch (strtolower($ext)) {
			case 'jpeg':
			case 'pjpeg':
			case 'jpg':
				$statusupload = imagejpeg($tmp,$filepath,100);//upload the image
				break;

			case 'png':
				$filename = explode('.',$filepath);
				$extension = $filename[(count($filename)-1)];
				$filename = str_replace('.'.$extension,'.jpg',$filepath);

				$statusupload = imagejpeg($tmp,$filename,100);//upload the image
// 				$statusupload = imagepng($tmp,$filepath,100);//upload the image
				break;

			case 'gif':
				$filename = explode('.',$filepath);
				$extension = $filename[(count($filename)-1)];
				$filename = str_replace('.'.$extension,'.jpg',$filepath);

				$statusupload = imagejpeg($tmp,$filename,100);//upload the image
// 				$statusupload = imagegif($tmp,$filepath,100);//upload the image
				break;

		}
if($statusupload) return true;
return false;
	}

	/**
	 *
	 * @param string $uid
	 * @param string $username
	 * @return string
	 */
	function getProfileLink($uid, $username) {

		$cfg = injooosmHelper::getConfig();

		switch($cfg->profile) {

		case "cb":
			$link = "<a href=".JRoute::_('index.php?option=com_comprofiler&task=userProfile&user='.$uid)." >".$username."</a>";
			return $link;
			break;

		case "js":
			$jspath = JPATH_BASE.DS.'components'.DS.'com_community';
			include_once($jspath.DS.'libraries'.DS.'core.php');

			$link = "<a href=".CRoute::_('index.php?option=com_community&view=profile&userid='.$uid)." >".$username."</a>";
			return $link;
			break;

		case "ku":
			$link = "<a href=".JRoute::_('index.php?option=com_kunena&func=fbprofile&userid='.$uid)." >".$username."</a>";
			return $link;
			break;

		case "0":
			$link = $username;
			return $link;
			break;

	}
}
Return current item: injooosm