Jump to content

showing template files


whatsupron

Recommended Posts

Hi i have setup an ajax function for photo comments and I have called the ajax function but my problem is I cant get the template file to show for photo comments and here is the link for it http://dating.iurate.com/index.php?do=rate&act=profile&view=mypictures&op=comments&user_id=2&photoid=2

here is more information on the script 

<?php

if(!defined("IN_MIPHOTO")) {
trigger_error("Unable to process {$HTTP_SERVER_VARS['PHP_SELF']}", E_USER_ERROR);
}

function returnPhotoComments($iPhotoId, $iStart = 0, $iNumberOfComments = 1) {
global $oDb, $oTpl;

$oTpl->define(array('profile-ViewProfileMyPicturesPhotoCommentsEach'	=>	'profile/my_pictures_comments_default.tpl'));

if($iStart < 0) {
	$iStart = 0;
}
if($iNumberOfComments < 1) {
	$iNumberOfComments = 1;
}
   $rResult = $oDb->select("added,from_user_id,comments","photo_comments","approved=1 AND photo_id='".$oDb->escape($iPhotoId)."'","ORDER BY added DESC LIMIT {$iStart}, {$iNumberOfComments}");
while($aData = $oDb->getRow($rResult)) {
	$oTpl->assign('RateViewProfileMyPicturesPhotoCommentsEachComment',$aData['comments']);
	$oTpl->assign('RateViewProfileMyPicturesPhotoCommentsEachDate',formatDateTime($aData['added']));

	setUserTemplateVariables($aData['from_user_id'],'RateViewProfileMyPicturesPhotoCommentsEach');

	$oTpl->parse('temp','.profile-ViewProfileMyPicturesPhotoCommentsEach');
}
$oDb->freeResult($rResult);

$sComments = $oTpl->getValue('temp');
$oTpl->clearVars('temp');

return $sComments;
}

function addPhotoComment($iPhotoId, $sComments) {
global $oDb;

if(empty($sComments)) {
	return 0;
}

$aFields = array('added'	=>	MYSQL_CHARACTER_SET.'NOW()',
'photo_id'	=>	$iPhotoId,
'from_user_id'	=>	getUserId(),
'comments'	=>	$sComments,
'approved'	=>	getConfig('commentapproval',0)
);

return $oDb->insert("photo_comments",$aFields);
}

function requestGalleryAccess($iGalleryId, $iUserId = -1) {
global $oDb;

$iUserId = intval($iUserId);
$iGalleryId = intval($iGalleryId);

if($iUserId < 1) {
	$iUserId = getUserId();
}

if($iUserId < 1)
	return 0;

// Check to make sure the user and gallery exists
// check to make sure this request isn't already in database
if(!$oDb->getResult($oDb->select("COUNT(*)","users","id=".$iUserId)) ||
	!$oDb->getResult($oDb->select("COUNT(*)","galleries","id=".$iGalleryId)) ||
	!$oDb->getResult($oDb->select("COUNT(*)","galleries_accesslist","user_id=".$iUserId." AND gallery_id=".$iGalleryId))
	) {
	return 0;
}

$aFields = array('added'	=>	MYSQL_NO_QUOTES_ESCAPE_CHARACTERS.'NOW()',
				'gallery_id'	=>	$iGalleryId,
				'user_id'		=>	$iUserId,
				'approved'	=> 0
				);

$oDb->insert("galleries_accesslist",$aFields);

return 1;
}

if(AJAX_CALL) {
return;
}

// END OF AJAX FUNCTIONS
// ***************************************************************************************
// ***************************************************************************************
// ***************************************************************************************

if($sAct == 'requestgalleryaccess') {
requestGalleryAccess($iGalleryId);
}

if($sOp == 'comments') {
returnPhotoComments($iPhotoId, $iStart, 10);
}


$oTpl->assign('RateViewProfileUserGalleries','');

if(empty($iGalleryId)) {
$rResult = $oDb->select("id,title","galleries","user_id='".$oDb->escape($iId)."'","ORDER BY added DESC");

while($aDataGalleries = $oDb->getRow($rResult)) {
	if($oDb->getResult($oDb->select("COUNT(*)","photos","gallery_id='".$oDb->escape($aDataGalleries['id'])."' AND approved='1'","LIMIT 1")) < 1)
		continue;

	$oTpl->assign('RateViewProfileUserGalleriesGalleryThumbnailLink',getImageThumbnailLink(getUserDefaultPhotoId($iId,true,$aDataGalleries['id']),false,THUMBNAIL_SIZE_DEFAULT,true,false,false,true,"index.php?do=rate&act=profile&view={$sView}&user_id={$iId}&gallery_id={$aDataGalleries['id']}"));
	$oTpl->assign('RateViewProfileUserGalleriesGalleryId',$aDataGalleries['id']);
	$oTpl->assign('RateViewProfileUserGalleriesGalleryTitle',htmlspecialchars($aDataGalleries['title']));
	$oTpl->assign('RateViewProfileUserGalleriesGalleryNumberOfPhotos',$oDb->getResult($oDb->select("COUNT(*)","photos","userid='".$oDb->escape($iId)."' AND approved='1' AND gallery_id='".$oDb->escape($aDataGalleries['id'])."'")));

	$oTpl->parse('RateViewProfileUserGalleries','.profile-ViewProfileGalleriesEach');
}
$oDb->freeResult($rResult);
}

$bAccessGallery = true;

$sWhere = "userid=".intval($iId)." AND approved='1'";

$oTpl->assign('RateViewProfileUserGalleryTitle','',false);

if(empty($iGalleryId) || !is_numeric($iGalleryId)) {
$sWhere .= " AND gallery_id=0 ";
} else {
$sWhere .= " AND gallery_id=".intval($iGalleryId)." ";

$oTpl->assign('RateViewProfileUserGalleryTitle',$oDb->getResult($oDb->select("title","galleries","id=".intval($iGalleryId)." AND user_id=".intval($iId),"LIMIT 1")),false);

// Let users see their own galleries
if($iId != getUserId()) {
	// Check that user has access to view this gallery
	$bAccessGallery = userHasAccessToGallery($iGalleryId);

	// Make the SQL query impossible
	if(!$bAccessGallery) {
		$sWhere = "id=0";
	}
}
}

$oCustoms->runCustoms(FILE_CONTENT_PROFILE_MYPICTURES,1);

$oTpl->assign('RateViewProfileUserPhotos','');

$iPhotosPerPage = getConfig('photospergallerypage',0);

if(!userHasAccess(USER_ACCESS_VIEW_ADDITIONAL_PHOTOS)) {
// See if the profile display type is split
if($bSplitProfile) {
	if($gGlobals['user']['loggedin']) {
		$sDo = $HTTP_GET_VARS['do'] = "subscriptions";
		return $cPlugins->callPluginFunction(PLUGIN_FUNCTION_CLIENT_OUTPUT,0,4);
	} else {
		$oTpl->assign('ErrorMessage',getConfig('errormustlogin'),false);
		include_once(dirname(__FILE__)."/login.php");
	}
	return;
} else {
	$oTpl->assign('RateViewProfileUserPhotos',getConfig('errorpremierusersonly'),false);
	return;
}

$rResult = 0;
} else {
$iStart = setPagingTemplateVariables('RateViewProfileUserPictures',"rate&act=profile&id={$iId}&view={$sView}&gallery_id={$iGalleryId}",'photos',$sWhere,$iPage,$iPhotosPerPage);
// Display addition photos
$rResult = $oDb->select("id,ratable".(($gGlobals['rating']['type'] == RATE_PHOTOS_ONLY || $gGlobals['rating']['type'] == RATE_PHOTOS_VIDEOS)?",rating,votes":""),"photos",$sWhere,"ORDER BY added DESC LIMIT {$iStart},{$iPhotosPerPage}");
}

while($aDataPictures = $oDb->getRow($rResult)) {
if(MIPHOTO_FEATURE_PHOTO_DETAILS) {
	setPhotoFieldsTemplateVariables($aDataPictures['id'],'RateViewProfile');
}

$oTpl->assign('RateViewProfileUserPhotosPhoto',getImageThumbnailLink($aDataPictures['id'],false,THUMBNAIL_SIZE_DEFAULT,true,false,false,true,"",$iId));
$oTpl->assign('RateViewProfileUserPhotosPhotoId',$aDataPictures['id']);

// Output the rating bar for the photo if photos are rated
if($gGlobals['rating']['type'] == RATE_PHOTOS_ONLY || $gGlobals['rating']['type'] == RATE_PHOTOS_VIDEOS) {
	if($aDataPictures['ratable']) {
		$oTpl->assign('RateViewProfileUserPhotosPhotoRating',formatRating($aDataPictures['rating'],$aDataPictures['votes'],0));
		$oTpl->assign('RateViewProfileUserPhotosPhotoVotes',$aDataPictures['votes']);
		$oTpl->assign('RateViewProfileUserPhotosPhotoNumericalRating',formatRating($aDataPictures['rating'],$aDataPictures['votes'],0,0,false,true));
	} else {
		$oTpl->assign('RateViewProfileUserPhotosPhotoRating','');
	}
} else {
	$oTpl->assign('RateViewProfileUserPhotosPhotoRating','');
}


if($oCustoms->runCustoms(FILE_CONTENT_PROFILE_MYPICTURES,2)) {}
else {
	$oTpl->parse('RateViewProfileUserPhotos','.profile-ViewProfilePhotosEach');
}
}
$oDb->freeResult($rResult);

if(!$bAccessGallery) {
// See if the user has
$sSQL = sprintf("SELECT COUNT(*) FROM {$oDb->sTablePrefix}_galleries_accesslist WHERE user_id=%d AND gallery_id=%d AND approved=0",getUserId(),$iGalleryId);
if($oDb->getResult($oDb->query($sSQL))) {
	$sErrorMsg = getConfig('errorpendingaccessviewgallery');
	$oTpl->assign('ErrorMessage',$sErrorMsg,false);
} else {
	$sErrorMsg = getConfig('errornoaccessviewgallery');
	$sErrorMsg = replaceVars($sErrorMsg,'GalleryId',$iGalleryId);
	$oTpl->assign('ErrorMessage',$sErrorMsg,false);
}
}

?>

 

and this is what $oTpl stands for

$oTpl = new cMiTemplate($gGlobals['html_directory']);

 

and here is template class

<?php

if(!defined("IN_MIPHOTO")) {
trigger_error("Unable to process {$HTTP_SERVER_VARS['PHP_SELF']}", E_USER_ERROR);
}

class cMiTemplate {
var $aTemplateFileList = array();
var $_aVars = array();
var $_aVarsTemp = array();
var $_aParseVarsTemp = array();

var $sTemplateDir = "html_1";
var $sVariableChar = '$';

var $sStartDelim = '\$';
var $sEndDelim = '\$';
var $sCompileDir = 'include/cache'; // The dir to store compiled templates

var $iTime;

function cMiTemplate($sTemplateDir = "") {
	$this->sTemplateDir = $sTemplateDir;
	$this->sCompileDir = dirname(__FILE__).'/../'.$this->sCompileDir;
}

function define($aArray) {
	$this->aTemplateFileList = array_merge($this->aTemplateFileList,$aArray);
}

function assign($aArray, $sValue="", $bRemoveAfterParse = true) {
	if(is_array($aArray)) {
		foreach($aArray as $sKey => $sValue) {
                if(!empty($sKey)) {
                    $this->_aVars[$sKey] = $sValue;

                    if($bRemoveAfterParse) {
                    	$this->_aVarsTemp[] = $sKey;
                    }
                }
            }
        } else {
            if(!empty($aArray)) {
                $this->_aVars[$aArray] = $sValue;

                if($bRemoveAfterParse) {
                	$this->_aVarsTemp[] = $aArray;
                }
            }
        }
}

function getValue($sTemplateVariable) {
	return $this->_aVars[$sTemplateVariable];
}

function clearAllVars() {
	$this->_aVars = array();
	$this->_aVarsTemp = array();
}

function clearVars($sKey = null) {
	if($sKey == null) {
		foreach($this->_aVarsTemp as $a) {
			if(array_key_exists($a,$this->_aVars)) {
				// Remove this key from the array
				unset($this->_aVars[$a]);
			}
		}
		// Clear the removal list..
		$this->_aVarsTemp = array();
	} else {
		if(array_key_exists($sKey, $this->_aVars)) {
			// Unset this one key in the array
			unset($this->_aVars[$sKey]);
		}
	}
}

function clearParseVars($sKey = null) {
	if($sKey == null) {
		foreach($this->_aParseVarsTemp as $a) {
			if(array_key_exists($a,$this->_aVars)) {
				// Remove this key from the array
				unset($this->_aVars[$a]);
			}
		}
		// Clear the removal list..
		$this->_aParseVarsTemp = array();
	} else {
		if(in_array($sKey, $this->_aVars)) {
			// Unset this one key in the array
			unset($this->_aVars[$sKey]);
		}
	}
}

function append($sKey, $aArray) {
	if(is_array($aArray) && is_array($this->_aVars[$sKey])) {
		$this->_aVars[$sKey] = array_merge($this->_aVars[$sKey],$aArray);
        }
        elseif(is_string($aArray) && is_string($this->_aVars[$sKey])) {
		$this->_aVars[$sKey] .= $aArray;
        } else {
        	$this->assign($sKey,$aArray,false);
        }
}

function parse($sKey, $sValue, $bClearParseVars = false) {
	$bAppend = false;

	if(substr($sValue,0,1) == ".") {
		$bAppend = true;
		$sValue = substr($sValue,1);
	}

	$sTempBuffer = $this->_fetch($this->aTemplateFileList[$sValue]);

	if($bAppend) {
		$this->append($sKey,$sTempBuffer);
	} else {
		$this->assign($sKey,$sTempBuffer,false);
	}

	// Clear up the memory
	unset($sTempBuffer);

	if(!$bAppend) {
		// Clear the temp vars to save memory and time

		// DISABLED FOR NOW... WHAT IF USERS WISH TO MOVE STUFF AROUND.. REALLY MESSES THINGS UP
		//$this->clearVars();
	}

	if($sKey != 'Content') {
		$this->_aParseVarsTemp[] = $sKey;
	}

	if($bClearParseVars) {
		// DISABLED FOR NOW... WHAT IF USERS WISH TO MOVE STUFF AROUND.. REALLY MESSES THINGS UP
		//$this->clearParseVars();
	}
}

function display($sFileName) {
	echo($this->_fetch($this->aTemplateFileList[$sFileName]));
}

function returndisplay($sFileName) {
	return $this->_fetch($this->aTemplateFileList[$sFileName]);
}

function _getTemplatePath($sFileName) {
	$sPath = $this->sTemplateDir;

	if((substr($sPath,-1) != "/" && substr($sPath,-1) != "\\") && (substr($sFileName,0,1) != "/" && substr($sFileName,0,1) != "\\")) {
		// Add /
		$sPath .= "/";
	}

	return $sPath.$sFileName;
}

function _getCompiledPath($sFileName) {
	$sPath = $this->sCompileDir;

	if(substr($sFileName,0,1) == "/" || substr($sFileName,0,1) == "\\") {
		$sFileName = substr($sFileName,1);
	}

	$sFileName = $this->_compiledFileName($sFileName);

	if((substr($sPath,-1) != "/" && substr($sPath,-1) != "\\")) {
		// Add /
		$sPath .= "/";
	}

	return $sPath.$sFileName;
}

function _fetch($sFileName) {
	$sCompiledFile = $this->_getCompiledPath($sFileName);

	//echo "$sFileName - Compiled time: ".filemtime($sCompiledFile)."<br>\n";
	//echo "$sFileName - Template time: ".filemtime($this->_getTemplatePath($sFileName))."<br>\n";

	// Make sure the template file is complied, if not compile it
	// Also check to see if the timestamp on the template file is greater than the compiled file. If it is then we need to rebuild
	if(!$this->_isCompiled($sFileName) || (filemtime($sCompiledFile) < filemtime($this->_getTemplatePath($sFileName)))) {
		$this->_compileFile($sFileName);
	}

	ob_start();
	include($sCompiledFile);
	$output = ob_get_contents();
	ob_end_clean();

	return $output;
}

function _isCompiled($sFileName) {
	return file_exists($this->_getCompiledPath($sFileName));
}

function _compiledFileName($sFileName) {
	return 'c_'.md5($this->sTemplateDir.'/'.$sFileName).'.php';
}

function _compileFile($sFile) {
	$sFilePath = $this->_getTemplatePath($sFile);
	$iFileSize = filesize($sFilePath);

	if($iFileSize) {
		// Open the source template file for reading
		$fp = fopen($sFilePath,"r");

		// Open the compiled file for writing
		$fpC = fopen($this->_getCompiledPath($sFile),"w");

		if($fp && $fpC) {
			$sContents = fread($fp,$iFileSize);

			// Write the compiled template
			fwrite($fpC,$this->_compileContents($sContents));

			// Close the files
			fclose($fp);
			fclose($fpC);
		}
	}
}

function _compileContents($sFileContents) {
	// Replace the template variables with the required PHP code...
	/*return preg_replace("!{$this->sStartDelim}(.*?){$this->sEndDelim}!i","<?php echo \$this->_aVars['\\1']; ?>",$sFileContents);*/
	//  \$(\S[\w]*\S)\$
	// (\S[\w]+\-?[\w]*\S)
	// (\S[\w]+\-?.+\S)

	//([a-zA-Z0-9_\-]{1,})
	//(\S[\w]+\-?[\w]*\S)

	//\$(\S*?)\$
	// Has problems with <a href='index.php?do=rate&act=profile&id=$RateViewProfileUserId$&op=block'>$RateViewProfileBlockOrUnblockUser$</a>
	// But no problems in regex coach?!?!?!

	//([a-zA-Z0-9_\-]{1,})
	// best so far...

	return preg_replace("!{$this->sStartDelim}([a-zA-Z0-9_\-]{1,}){$this->sEndDelim}!iU","<?php echo \$this->_aVars['\\1']; ?>",$sFileContents);
}
}


$aTemplateFileList = array(
				"index"			=> "index.tpl",
				"captchaImage"	=>	"captcha_image.tpl",

				'errorTable'	=>	'error_message.tpl',

				"activeMembers-Default"	=> "activemembers/default.tpl",
				"activeMembers-DefaultEach"	=> "activemembers/default_each.tpl",

        			"joinEmail"			=> "join_email.tpl",
        			"referralEmail"			=> "referral_email.tpl",
        			"refresh"			=> "refresh.tpl",
        			"register"			=> "register.tpl",
        			"report"			=> "report.tpl",
        			"refresh"			=> "refresh.tpl",
        			"register"			=> "register.tpl",
        			"contact"			=> "contact.tpl",

        			"rate-RatingBars"							=>	"rate/rating_bars.tpl",

        			"sideTopNewEach"			=> "side_top_new_each.tpl",

        			"controlPanel-DeleteAccountDefault"		=>	"controlpanel/deleteaccount/default.tpl",

        			"controlPanel-NavBar"		=> "controlpanel/member_navbar.tpl",

        			"controlPanel-MyBlockListAdd"	=>	"controlpanel/myblocklist/add.tpl",
        			"controlPanel-MyBlockListDefault"	=>	"controlpanel/myblocklist/default.tpl",
        			"controlPanel-MyBlockListDefaultEach"	=>	"controlpanel/myblocklist/default_each.tpl",
        			"controlPanel-MyBlockListDelete"	=>	"controlpanel/myblocklist/delete.tpl",

        			"controlPanel-MyCommentsNew"	=> "controlpanel/mycomments/new.tpl",
        			"controlPanel-MyCommentsDelete"	=> "controlpanel/mycomments/delete.tpl",
        			"controlPanel-MyCommentsDefault"	=> "controlpanel/mycomments/default.tpl",
        			"controlPanel-MyCommentsDefaultEach"	=> "controlpanel/mycomments/default_each.tpl",

        			"controlPanel-MyProfile"		=> "controlpanel/myprofile.tpl",

        			"controlPanel-MyPicturesDefault"	=> "controlpanel/mypictures/default.tpl",
        			"controlPanel-MyPicturesDefaultPhotoEach"	=> "controlpanel/mypictures/default_photo_each.tpl",
        			"controlPanel-MyPicturesDefaultPhotoRowEach"	=> "controlpanel/mypictures/default_photo_row_each.tpl",
        			"controlPanel-MyPicturesDelete"	=> "controlpanel/mypictures/delete.tpl",
        			"controlPanel-MyPicturesReset"	=> "controlpanel/mypictures/reset.tpl",

        			"controlPanel-MyStatsReset"		=> "controlpanel/mystats/reset.tpl",
        			"controlPanel-MyStatsDefault"		=> "controlpanel/mystats/default.tpl",
        			"controlPanel-MyStatsDefaultVotesEach"		=> "controlpanel/mystats/default_votes_each.tpl",
        			"controlPanel-MyStatsProfileViewsDefault"		=> "controlpanel/mystats/profile_views_default.tpl",
        			"controlPanel-MyStatsProfileViewsDefaultEach"		=> "controlpanel/mystats/profile_views_default_each.tpl",

        			"controlPanel-PMSDelete"			=> "controlpanel/pms/delete.tpl",
        			"controlPanel-PMSDefault"			=> "controlpanel/pms/default.tpl",
        			"controlPanel-PMSDefaultEach"		=> "controlpanel/pms/default_each.tpl",
        			"controlPanel-PMSSend"			=> "controlpanel/pms/send.tpl",
        			"controlPanel-PMSRead"			=> "controlpanel/pms/read.tpl",
        			"controlPanel-PMSReadMessagesEach"		=> "controlpanel/pms/read_messages_each.tpl",
        			"controlPanel-PMSMassDelete"			=> "controlpanel/pms/mass_delete.tpl",

        			"controlPanel-Email"			=> "controlpanel/email.tpl",

        			"login-SideLogin"				=> "login/side_login.tpl",
        			"login-Default"			=> "login/default.tpl",
        			"login-ForgotPassword"	=> "login/forgot_password.tpl",

        			"main-Default"			=> "main/default.tpl",
        			"main-NewsDefault"			=> "main/news_default.tpl",
        			"main-NewsEach"			=> "main/news_each.tpl",
        			"main-FeaturedUser"			=> "main/featured_user.tpl",
        			"main-RecentCommentsEach"			=> "main/recent_comments_each.tpl",
        			"main-RecentUploadsEach"			=> "main/recent_uploads_each.tpl",


        			"rate-PreviousPhoto"					=> "rate/previous_photo.tpl",


        			"controlPanel-MyPicturesDefaultGalleriesRowEach"	=> "controlpanel/mypictures/default_galleries_row_each.tpl",
											"controlPanel-MyPicturesDefaultGalleriesEach"		=> "controlpanel/mypictures/default_galleries_each.tpl",
											"controlPanel-MyPicturesViewGalleryDefault"		=> "controlpanel/mypictures/view_gallery_default.tpl",

											"controlPanel-MyPicturesGalleryEdit"		=> "controlpanel/mypictures/gallery_edit.tpl",
											"controlPanel-MyPicturesGalleryDelete"		=> "controlpanel/mypictures/gallery_delete.tpl",
											"controlpanel-MyPicturesGalleryEditPrivateUsersEach"	=>	"controlpanel/mypictures/gallery_edit_private_users_each.tpl",
											"controlPanel-MyPicturesGalleryAddUser" => "controlpanel/mypictures/gallery_add_user.tpl",
											"controlPanel-MyPicturesGalleryDeleteUser" => "controlpanel/mypictures/gallery_delete_user.tpl",

											"controlPanel-MyVideosDefault"	=> "controlpanel/myvideos/default.tpl",
						        			"controlPanel-MyVideosDefaultVideoEach"	=> "controlpanel/myvideos/default_video_each.tpl",
						        			"controlPanel-MyVideosDefaultVideoRowEach"	=> "controlpanel/myvideos/default_video_row_each.tpl",
						        			"controlPanel-MyVideosDelete"	=> "controlpanel/myvideos/delete.tpl",

        										"main-RecentUploadsVideosEach"		=> "main/recent_uploads_videos_each.tpl",
						        	);
?>

 

anyone please help to get me the template file to show

 

Link to comment
https://forums.phpfreaks.com/topic/161186-showing-template-files/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.