<?php
// +-------------------------------------------------------------------------+
// | Mobile Melody Plug-in for PHP Melody ( www.phpsugar.com )
// +-------------------------------------------------------------------------+
// | MOBILE MELODY IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +-------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2012 PhpSugar.com. All rights reserved.
// +-------------------------------------------------------------------------+
require('../config.php');
require_once('settings.php');
require_once('../include/functions.php');
require_once('../include/user_functions.php');
require_once('../include/islogged.php');
require_once('../include/settings.php');
require_once('functions.php');

$illegal_chars = array(">", "<", "&", "'", '"');

$lastpos = $_POST['lastpos'];
$case = $_POST['case'];
$extradata = magicSlashes($_POST['extradata']);

if ($lastpos == '' || $case == '')
{
	exit();
}

if(isSet($lastpos))
{
	$lastpos = mysql_real_escape_string($lastpos);
	//$result=mysql_query("SELECT * FROM pm_videos WHERE id<'".$lastpos."' ORDER BY id DESC LIMIT 9");
	
	switch ($case)
	{
		case 'new_videos':
			$result = mysql_query("SELECT * FROM pm_videos WHERE added <= '". time() ."' AND id<'".$lastpos."' AND source_id IN (". implode(',', $_mobile_supported_sources) .")  ORDER BY id DESC LIMIT 5");
			$extradata = $extradata;
		break;
		
		case 'browse':
			$result = mysql_query("SELECT * FROM pm_videos WHERE added <= '". time() ."' AND id<'".$lastpos."' AND (category LIKE '%,".$extradata.",%' 
					   OR category LIKE '%,".$extradata."' 
					   OR category LIKE '".$extradata.",%' 
					   OR category='".$extradata."') 
					   AND source_id IN (". implode(',', $_mobile_supported_sources) .") 
					   ORDER BY id DESC LIMIT 5");
		break;
		
		case 'browse_articles':
			$result = mysql_query("SELECT * FROM art_articles WHERE status = '1' 
				AND date<'".$lastpos."' 
				AND (category LIKE '". $extradata ."' 
					 OR category LIKE '". $extradata .",%' 
					 OR category LIKE '%,". $extradata ."' 
					 OR category LIKE '%,". $extradata .",%')  
				ORDER BY date DESC LIMIT 5");

		break;	
		
		case 'video_comments': 
			$result = mysql_query("SELECT * FROM pm_comments WHERE uniq_id = '".$extradata."' AND approved = '1' AND id<'".$lastpos."' ORDER BY added DESC LIMIT 10");
		break;
	
		case 'search': //get keys
		break;
		
		case 'related_videos': // get uniq-id
		break;

	}
	

	while($row=mysql_fetch_array($result))
	{
		$video_id = $row['id'];
		$article_id = $row['date'];
		if($case == 'video_comments') {
?>
			<li>
			<img src="<?php echo getavatar($row['user_id'], $row['username']); ?>" border="0" class="comm_avatar border4" />
			<div class="comment">
				<span class="comm_name"><?php echo $row['username']; ?></span><span class="comm_date"><?php echo time_since($row['added'])." ".$lang['ago']; ?></span>
				<div class="comm_txt"><?php echo htmlentities($row['comment'], ENT_COMPAT, 'UTF-8'); ?></div>
			</div>
			</li>
<?php
		} elseif($case == 'browse') { 
			echo videoLI($row);
		} elseif($case == 'browse_articles') {
			echo articleLI($row);
		} else { 
			echo videoLI($row);
		}
	}
	$total_results = mysql_num_rows($result);
	if($case == "video_comments" && $total_results > 0) {
?>
	<div id="morec<?php echo $video_id; ?>" class="morecbox">
	<div align="center">
	<div id="loader"><img src="<?php echo _URL_MOBI; ?>/images/moreajax.gif" /></div>
	<button class="minimal morec" id="<?php echo $video_id; ?>">
	<?php translate("Load more comments", lmore_comments); ?>
	</button>
	</div>
	<div class="case" id="<?php echo $case; ?>"></div>
	<div class="extra_data" id="<?php echo $extradata; ?>"></div>
	</div>
<?php
	} elseif($case == "browse_articles" && $total_results > 0) {
?>
	<div id="more<?php echo $article_id; ?>" class="morebox">
	<div align="center">
	<div id="loader"><img src="<?php echo _URL_MOBI; ?>/images/moreajax.gif" /></div>
	<button class="minimal more" id="<?php echo $article_id; ?>">
	<?php translate("Load more", lmore); ?>
	</button>
	</div>
	<div class="case" id="<?php echo $case; ?>"></div>
	<div class="extra_data" id="<?php echo $extradata; ?>"></div>
<?php
	}
	elseif($total_results > 0) {
?>
	<div id="more<?php echo $video_id; ?>" class="morebox">
	<div align="center">
	<div id="loader"><img src="<?php echo _URL_MOBI; ?>/images/moreajax.gif" /></div>
	<button class="minimal more" id="<?php echo $video_id; ?>">
	<?php translate("Load more videos", lmore_videos); ?>
	</button>
	</div>
	<div class="case" id="<?php echo $case; ?>"></div>
	<div class="extra_data" id="<?php echo $extradata; ?>"></div>
<?php
	} elseif($total_results == 0) {
	
	}
}
?>