All pastes #667233 Raw Edit

Stuff

public text v1 · immutable
#667233 ·published 2007-08-22 20:38 UTC
rendered paste body
<?php
/**
* @package MMS Blog
* @copyright Copyright (C) 2006 Jens-Christian Skibakk
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* MMS Blog is free software and parts of it may contain or be derived from the
* GNU General Public License or other free or open source software licenses.
*/

/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

require_once( $mainframe->getPath( 'front_html' ) );
require_once( $mainframe->getPath( 'class' ) );

// this also includes the configuration
include_once( $mosConfig_absolute_path . '/components/com_mmsblog/update.php' );

$lngfile = $mosConfig_absolute_path . '/components/com_mmsblog/language/' . $mosConfig_lang . '.php';
if( !file_exists($lngfile) ) {
	$lngfile = $mosConfig_absolute_path . '/components/com_mmsblog/language/english.php';
}
require_once ( $lngfile );


$mainframe->setPageTitle( JMMSBlogHelper::title() );
if ($mosMMSblog_tb_image || $mosMMSblog_tb_movie)
{
	$mainframe->addCustomHeadTag( "<script type=\"text/javascript\" src=\"$mosConfig_live_site/components/com_mmsblog/js/jquery.js\"></script>" );
	$mainframe->addCustomHeadTag( "<script type=\"text/javascript\" src=\"$mosConfig_live_site/components/com_mmsblog/js/thickbox.js\"></script>" );
	$mainframe->addCustomHeadTag( "<link href=\"$mosConfig_live_site/components/com_mmsblog/css/thickbox.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />" );
}

$file = mosGetParam( $_REQUEST, 'file', '' );
$id   = intval(mosGetParam( $_REQUEST, 'id', 0 ));
$user = intval(mosGetParam( $_REQUEST, 'user', 0 ));
$page = intval(mosGetParam( $_REQUEST, 'page', 1 ));

switch( $task ) {

	case 'audio':
		HTML_mmsblog::showAudio( $file );
		break;

	case 'video':
		HTML_mmsblog::showVideo( $file );
		break;
		
	case 'show':
		showMMSblog1( $id );
		break;

	case 'users';
		showMMSusers();
		break;

	default:
		updateBlog();
		showMMSblog( $user, $page );
		break;
}

function showMMSusers() {
	global $database, $Itemid, $mainframe;

	if( (!$Itemid) || ($Itemid == 99999999) ) {
		$Itemid = JMMSBlogHelper::itemid();

		if( $Itemid ) {
			mosRedirect( JMMSBlogHelper::linkUsers( $id, $Itemid ) );
		}
	}

	$mainframe->appendPathWay( MMS_USERS );
	
	$query = "SELECT id, name FROM #__mmsblog_user WHERE published=1 ORDER BY name";
	$database->setQuery( $query );
	$rows = $database->loadObjectList();
	if( $database->getErrorNum() > 0 ) {
		echo $database->stderr();
		return;
	}
	
	HTML_mmsblog::showusers( $rows );
}

function showMMSblog1( $id ) {
	global $database, $Itemid, $mainframe;

	if( (!$Itemid) || ($Itemid == 99999999) ) {
		$Itemid = JMMSBlogHelper::itemid();

		if( $Itemid ) {
			mosRedirect( JMMSBlogHelper::linkOne( $id, $Itemid ) );
		}
	}

	$query = "SELECT m.*, u.name FROM #__mmsblog AS m"
		. " \nLEFT JOIN #__mmsblog_user u ON m.uid = u.id"
		. " \nWHERE u.published=1 AND m.published=1 AND m.id=$id"
		. " \nORDER BY m.ordering DESC";
	$database->setQuery( $query );
	$rows = $database->loadObjectList();
	if( $database->getErrorNum() > 0 ) {
		echo $database->stderr();
		return;
	}

	if( count($rows) == 0 ) {
		return;
	}

	for( $i=0, $n=count($rows); $i<$n; $i++) {
		$regex = '/{mmsimg\s(\S*)\s(.*?)}/i';
		$rows[$i]->content = preg_replace_callback( $regex, 'mmsimg_callback', $rows[$i]->content);
		
		$regex = '/{mmsvid\s(\S*)\s(.*?)}/i';
		$rows[$i]->content = preg_replace_callback( $regex, 'mmsvid_callback', $rows[$i]->content);
		
		$regex = '/{mmsaudio\s(\S*)\s(.*?)}/i';
		$rows[$i]->content = preg_replace_callback( $regex, 'mmsaudio_callback', $rows[$i]->content);
	}

	$mainframe->appendPathWay( htmlentities($rows[0]->title) );

	HTML_mmsblog::showMMSblog( $rows );
	HTML_mmsblog::footer();
}

function showMMSblog( $user=0, $page=1 ) {
	global $database, $Itemid, $mosMMSblog_numonpage;
	$rows[$i]->content = str_replace('Thank you for using easyedgeSM Picture Messaging by U.S. Cellular. See www.uscellular.com for info.', '', $rows[$i]->content);
	global $mainframe;

	if( (!$Itemid) || ($Itemid == 99999999)) {
		$Itemid = JMMSBlogHelper::itemid();

		if( $Itemid ) {
			mosRedirect( JMMSBlogHelper::link( $page, $Itemid, $user ) );
		}
	}

	$where = ( $user != 0 ) ? "AND u.id=$user" : '';

	if( $user ) {
		$tmp = new mosMMSUser();
		$tmp->load( $user );
		$mainframe->appendPathWay( htmlspecialchars($tmp->name) );
	}

	$query = "SELECT count(*) FROM #__mmsblog AS m"
		. " \nLEFT JOIN #__mmsblog_user u ON m.uid = u.id"
		. " \nWHERE u.published=1 AND m.published=1"
		. " \n$where";
	$database->setQuery( $query );
	$total = intval( $database->loadResult() );
	if( $database->getErrorNum() > 0 ) {
		echo $database->stderr();
		return;
	}
	
	$limitstart = $mosMMSblog_numonpage * ($page-1);
	$limit = $mosMMSblog_numonpage;
	$pages = intval($total/$mosMMSblog_numonpage);
	if($total%$mosMMSblog_numonpage) {
		$pages++;
	}

	$query = "SELECT m.*, u.name FROM #__mmsblog AS m"
		. " \nLEFT JOIN #__mmsblog_user u ON m.uid = u.id"
		. " \nWHERE u.published=1 AND m.published=1"
		. " \n$where"
		. " \nORDER BY m.ordering DESC"
		. " \nLIMIT $limitstart, $limit";
	$database->setQuery( $query );
	$rows = $database->loadObjectList();
	if( $database->getErrorNum() > 0 ) {
		echo $database->stderr();
		return;
	}

	for( $i=0, $n=count($rows); $i<$n; $i++) {
		$regex = '/{mmsimg\s(\S*)\s(.*?)}/i';
		$rows[$i]->content = preg_replace_callback( $regex, 'mmsimg_callback', $rows[$i]->content);
		
		$regex = '/{mmsvid\s(\S*)\s(.*?)}/i';
		$rows[$i]->content = preg_replace_callback( $regex, 'mmsvid_callback', $rows[$i]->content);
		
		$regex = '/{mmsaudio\s(\S*)\s(.*?)}/i';
		$rows[$i]->content = preg_replace_callback( $regex, 'mmsaudio_callback', $rows[$i]->content);
	}
	
	HTML_mmsblog::showMMSblog( $rows, $page, $pages, $user );
	HTML_mmsblog::footer(true);
}

function mmsimg_callback( &$matches ) {
	global $mosConfig_absolute_path, $mosConfig_live_site, $mosMMSblog_maxwidth, $mosMMSblog_path, $mosMMSblog_tb_image;

	$file  = $mosConfig_absolute_path . $mosMMSblog_path . $matches[1];
	$url   = $mosConfig_live_site . $mosMMSblog_path . $matches[1];
	$alt   = htmlentities($matches[2]);

	list( $width, $height ) = @getimagesize( $file );
	if( $width > $mosMMSblog_maxwidth ) {
		$height = $height * $mosMMSblog_maxwidth / $width;
		$width  = $mosMMSblog_maxwidth;
	}

	$imgtag = sprintf( '<img src="%s" alt="%s" width="%d" height="%d" border="0" /><br /><br />', $url, $alt, $width, $height );
	if ($mosMMSblog_tb_image) {
		$link   = sprintf( '<a target="_blank" class="thickbox" href="%s">%s</a>', $url, $imgtag );
	} else {
		$link   = sprintf( '<a target="_blank" href="%s">%s</a>', $url, $imgtag );
	}
	
	return $link;
}

function mmsvid_callback( &$matches ) {
	global $mosConfig_absolute_path, $mosConfig_live_site, $mosMMSblog_maxwidth, $mosMMSblog_path, $mosMMSblog_tb_movie;
	
	$file  = $mosConfig_absolute_path . $mosMMSblog_path . $matches[1];
	$url  = $mosConfig_live_site . $mosMMSblog_path . $matches[1];
	$alt = htmlentities($matches[2]);
	
	$href = $mosConfig_live_site . '/index2.php?option=com_mmsblog&amp;task=video&amp;file=' . $matches[1];
	
	if ($mosMMSblog_tb_movie) {
		$href = $href . "&keepThis=true&TB_iframe=true&height=500&width=580";
		$link = sprintf( '<a href="%s" title="%s" class="thickbox">'.MMS_WATCH_MOVIE.': %s</a><br /><br />', $href, $alt, $alt );
	} else {
		$href = "javascript:MMSblog_video('$href',640,480);";
		$link = sprintf( '<a href="%s" title="%s">'.MMS_WATCH_MOVIE.': %s</a><br /><br />', $href, $alt, $alt );
	}
	
	return $link;
}

function mmsaudio_callback( &$matches ) {
	global $mosConfig_absolute_path, $mosConfig_live_site, $mosMMSblog_maxwidth, $mosMMSblog_path, $mosMMSblog_tb_movie;
	
	$file  = $mosConfig_absolute_path . $mosMMSblog_path . $matches[1];
	$url  = $mosConfig_live_site . $mosMMSblog_path . $matches[1];
	$alt = htmlentities($matches[2]);
	
	$href = $mosConfig_live_site . '/index2.php?option=com_mmsblog&amp;task=audio&amp;file=' . $matches[1];
	
	if ($mosMMSblog_tb_movie) {
		$href = $href . "&keepThis=true&TB_iframe=true&height=120&width=250";
		$link = sprintf( '<a href="%s" title="%s" class="thickbox">'.MMS_LISTEN_AUDIO.': %s</a><br /><br />', $href, $alt, $alt );
	} else {
		$href = "javascript:MMSblog_video('$href',250,120);";
		$link = sprintf( '<a href="%s" title="%s">'.MMS_LISTEN_AUDIO.': %s</a><br /><br />', $href, $alt, $alt );
	}
	
	return $link;
}

?>