Location: PHPKode > projects > mBlog > includes/local.php
<?php
// check cookie, untuk memeriksa kebenaran cookie. jika ada yang mencurigakan akan langsung di DIE!
// jika benar nilai kembalian = 1: lainnya 0
function isMember ()
{
	global $config;

	$status = 0;
	if (!empty($_COOKIE["m_user"]) && !empty($_COOKIE["m_passwd"]))
	{
		// username & passwd SET -> member
		$user_id = cookie_param ('m_user');
		$user_passwd = cookie_param ('m_passwd');
		$sql = "SELECT * FROM m_user WHERE user_id='$user_id' AND md5(user_passwd) = '$user_passwd' LIMIT 1";
		$row = sql_fetch_array (sql_query ($sql));

		if (!empty($row['user_id']))
			$status = 1;
		else
			redir ($config['site_url'].'/includes/logout.php');
   	}
   	else
   	{
   		// username SET & password EMPTY -> temporary member
		$username = cookie_param ('m_user');
		$passwd = '';
		$status = 0;
   	}
	return $status;
}


// create thumbnail
// mode = 'list' => small size, non clickable
//        'detail' => medium size, clickable
//        'feature' => medium size, non clickable
function make_thumb ($image_id, $mode, $dir = '')
{
	global $config;
	$thumb_on = $config['thumb_on'];
	$thumb_size = $config['thumb_size'];
	$quality = $config['thumb_quality'];

	$img_src = $dir."images/products/$image_id.jpg";
	$img_th  = $dir."images/products_thumbs/$image_id.jpg";

	if (!file_exists ($img_src))   // jika gambar tdk ada maka
	{
		if ($mode == 'feature') $mode = 'detail';
		return "<img border=\"0\" src=\"$config[skin]/images/nothumb_$mode.gif\" title=\"No thumbnail\" alt=\"No thumbnail\" />";
	}
	else                           // jika gambar ada maka SIAP tampilkan thumbnailnya
	{
		if (!file_exists ($img_th))  // if thumbnail image not exists -> create it
		{
			$img_size = GetImageSize ($img_src);
			$img_in = ImageCreateFromJPEG ($img_src);

			if ($thumb_on == 'y')
			{
				$img_x = ($thumb_size/$img_size[1]) * $img_size[0];
				$img_y = $thumb_size;
			}
			else
			{
				$img_y = ($thumb_size/$img_size[0]) * $img_size[1];
				$img_x = $thumb_size;
			}

			image_optimizer ($img_src, $img_th, $img_x, $img_y, $quality);
		}
	}

	// get image size, and display it ...
	$img_tsize = GetImageSize ($img_th);
	$img_tx = $img_tsize[0];
	$img_ty = $img_tsize[1];

	if ($mode == 'list')
      {
		$img_tx = (3/4) * $img_tx;
		$img_txt = "<img border=\"0\" src=\"$img_th\" width=\"$img_tx\" alt=\"image\" />";
	}
	elseif ($mode == 'detail')
	{
		$item_id = substr ($image_id, 0, (strpos ($image_id, '_')));
		$img_txt = "<img border=\"0\" src=\"$img_th\" alt=\"image\" />";
		$img_txt = "<a href=\"#\" onclick=\"gallery()\" title=\"Click to open image gallery on this item.\">$img_txt</a>";
	}
	elseif ($mode == 'feature')
	{
		$img_txt = "<img border=\"0\" src=\"$img_th\" alt=\"image\" />";
	}
	elseif ($mode == 'gallery')
	{
		$item_id = substr ($image_id, 0, (strpos ($image_id, '_')));
		$j = strpos ($image_id, '_');
		$x = substr ($image_id, $j+1);
		$img_txt = "<img border=\"0\" src=\"$img_th\" class=\"thumb_gallery\" alt=\"image\" />";
		$img_txt = "<a href=\"gallery.php?item_id=$item_id&amp;x=$x\" title=\"Click for larger size of this image.\">$img_txt</a>";
	}

	return $img_txt;
}


//-- untuk mengambil informasi user
function get_user_info ($usrnm = '')
{
	global $user_id, $user_login;

	// if $usrnm not specified, get $usrnm from cookie ($username)
	if (empty ($usrnm)) $user = $user_id; else $user = $usrnm;

	if (empty ($usrnm) && !$user_login)
	{
		$user = create_blank_tbl ('m_user');
	}
	else
	{
		$sql = "SELECT * FROM m_user WHERE user_id='$user' LIMIT 1";
		$res = sql_query ($sql);
		$user = sql_fetch_array ($res);
	}

	$user['ip'] = $_SERVER['REMOTE_ADDR'];
	return $user;
}


//-- security check for admin
// $level -> 'sa' = site administrator; 'ed' = editor
function admin_check ($level = 'ed')
{
	global $config;

	if (empty ($_COOKIE['admin_usernm']) || empty ($_COOKIE['admin_passwd']))
	{
		redir ($config['site_url'].'/admin/login.php');
		die;
	}

	$admin_name = $_COOKIE['admin_usernm'];
	$admin_passwd = $_COOKIE['admin_passwd'];
	$sql = "SELECT * FROM m_user WHERE user_id='$admin_name' AND md5(user_passwd) = '$admin_passwd' LIMIT 1";
	$row = sql_fetch_array (sql_query ($sql));

	if (!empty ($row['user_id']) && (($row['user_level'] == 'sa') || ($row['user_level'] == 'ed')))
	{
		if (($level == 'sa') && ($row['user_level'] == 'ed')) admin_die ('sa_only', '', -1);
		$status = 1;
	}
	else
		redir ($config['site_url'].'/admin/login.php');
}


function generate_cat_form ($cat_id = 0)
{
	global $tmp_tbl;

	$tmp = $tmp_tbl;
	array_unshift ($tmp, '---------');
	return create_select_form ('cat_id', $tmp, $cat_id);
}
?>
Return current item: mBlog