/***************************************************************************
* Dolphin Smart Community Builder
* -------------------
* begin : Mon Mar 23 2006
* copyright : (C) 2007 BoonEx Group
* website : http://www.boonex.com
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the
* License, or any later version.
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Dolphin,
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/
bx_import('BxDolTwigTemplate');
bx_import('BxDolCategories');
/*
* Traveler module View
*/
class BxTravelerTemplate extends BxDolTwigTemplate {
var $_iPageIndex = 500;
var $oDb;
/**
* Constructor
*/
function BxTravelerTemplate(&$oConfig, &$oDb) {
parent::BxDolTwigTemplate($oConfig, $oDb);
$this->oDb = $oDb;
}
function order_unit ($aData, $sTemplateName, &$oVotingView) {
if (null == $this->_oMain)
$this->_oMain = BxDolModule::getInstance('BxTravelerModule');
$sAuthorName = getNickName($aData['author_id']);
$sAuthorLink = getProfileLink($aData['author_id']);
$sCreateDate = $this->filterDate($aData['order_date']);
$sDueDate = $this->filterDate($aData['expiry_date']);
$sPackageName = $this->_oMain->_oDb->getPackageName($aData['package_id']);
$aVars = array (
'id' => $aData['id'],
'traveler_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aData['uri'],
'traveler_title' => $aData['traveler_name'] .' '. $aData['title'],
'create_date' => $sCreateDate,
'due_date' => $sDueDate,
'author_username' => $sAuthorName,
'author_url' => $sAuthorLink,
'invoice_no' => $aData['invoice_no'],
'order_no' => $aData['order_no'],
'package' => $sPackageName,
'product_status' => $this->getStatus($aData['status']),
'order_status' => $this->getStatus($aData['order_status']),
'payment_method' => $aData['payment_method'],
'invoice_no' => $aData['invoice_no'],
);
return $this->parseHtmlByName($sTemplateName, $aVars);
}
function invoice_unit ($aData, $sTemplateName, &$oVotingView) {
if (null == $this->_oMain)
$this->_oMain = BxDolModule::getInstance('BxTravelerModule');
$sAuthorName = getNickName($aData['author_id']);
$sAuthorLink = getProfileLink($aData['author_id']);
$sCreateDate = $this->filterDate($aData['invoice_date']);
$sDueDate = $this->filterDate($aData['invoice_due_date']);
$sExpiryDate = $this->filterDate($aData['invoice_expiry_date']);
$sPackageName = $this->_oMain->_oDb->getPackageName($aData['package_id']);
$aVars = array (
'id' => $aData['traveler_id'],
'traveler_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aData['uri'],
'traveler_title' => $aData['traveler_name'] .' '. $aData['title'],
'create_date' => $sCreateDate,
'due_date' => $sDueDate,
'expiry_date' => $sExpiryDate,
'author_username' => $sAuthorName,
'author_url' => $sAuthorLink,
'invoice_id' => $aData['id'],
'invoice_no' => $aData['invoice_no'],
'package' => $sPackageName,
'invoice_status' => $this->getStatus($aData['invoice_status']),
'total' => number_format($aData['price']),
);
return $this->parseHtmlByName($sTemplateName, $aVars);
}
function unit ($aData, $sTemplateName, &$oVotingView) {
if (null == $this->_oMain)
$this->_oMain = BxDolModule::getInstance('BxTravelerModule');
if (!$this->_oMain->isAllowedView ($aData)) {
$aVars = array ('extra_css_class' => 'desa_traveler_unit');
return $this->parseHtmlByName('browse_unit_private', $aVars);
}
$aAuthor = getProfileInfo($aData['author_id']);
/*
$sImageUrl = '';
$sImageTitle = '';
$a = array ('ID' => $aData['author_id'], 'Avatar' => $aData['thumb']);
$aImage = BxDolService::call('photos', 'get_image', array($a, 'file'), 'Search');
*/
$sImage = '';
if ($aData['thumb']) {
$a = array ('ID' => $aData['author_id'], 'Avatar' => $aData['thumb']);
$aImage = BxDolService::call('photos', 'get_image', array($a, 'browse'), 'Search');
$sImage = $aImage['no_image'] ? '' : $aImage['file'];
}
desa_traveler_import('Voting');
$oRating = new BxTravelerVoting ('desa_traveler', $aData['id']);
$sOwnerThumb = $GLOBALS['oFunctions']->getMemberIcon($aAuthor['ID'], 'left');
$sDateTime = defineTimeInterval($aData['created']);
$sPostText = $aData['desc'];
$iLimitChars = (int)getParam('desa_traveler_max_preview');
if (strlen($sPostText) > $iLimitChars) {
$sLinkMore = '...';
$sPostText = mb_substr(strip_tags($sPostText), 0, $iLimitChars) . $sLinkMore;
}
$aVars = array (
'id' => $aData['id'],
'image_url' => !$aImage['no_image'] && $aImage['file'] ? $aImage['file'] : $this->getIconUrl('no-photo-110.png'),
'image_title' => !$aImage['no_image'] && $aImage['title'] ? $aImage['title'] : '',
'thumb_url' => $sImage ? $sImage : $this->getIconUrl('no-photo.png'),
'traveler_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aData['uri'],
'traveler_title' => $aData['traveler_name'] .' - '. $aData['title'],
'traveler_description' => $sPostText,
'comments_count' => $aData['comments_count'],
'post_date' => strtolower($sDateTime),
'post_uthumb' => $sOwnerThumb,
'post_picture2' => $sPostPicture,
'all_categories' => $this->_oMain->parseCategories($aData['categories']),
'post_tags' => $this->_oMain->parseTags($aData['tags']),
'author_title' => _t('_From'),
'author_username' => $sAuthorName,
'author_url' => $sAuthorLink,
'rating' => $oRating->isEnabled() ? $oRating->getJustVotingElement (true, $aData['id']) : '',
);
return $this->parseHtmlByName($sTemplateName, $aVars);
}
// ======================= ppage compose block functions
function blockDesc (&$aDataEntry) {
$aVars = array (
'description' => $aDataEntry['desc'],
'title' => $aDataEntry['title'],
);
return $this->parseHtmlByName('block_description', $aVars);
}
function blockBio (&$aDataEntry) {
$aVars = array (
'description' => $aDataEntry['desc'],
);
return $this->parseHtmlByName('block_bio', $aVars);
}
function blockCredits (&$aDataEntry) {
$aVars = array (
'description' => $aDataEntry['credits'],
);
return $this->parseHtmlByName('block_description', $aVars);
}
function blockFields (&$aDataEntry) {
$bHasValues = false;
$sRet = '
';
desa_traveler_import ('FormAdd');
$oForm = new BxTravelerFormAdd ($GLOBALS['oBxTravelerModule'], $_COOKIE['memberID']);
foreach ($oForm->aInputs as $k => $a) {
if (!isset($a['display'])) continue;
$sRet .= ''. $a['caption'] . ' | | ';
if (is_string($a['display']) && is_callable(array($this, $a['display'])))
$sRet .= call_user_func_array(array($this, $a['display']), array($aDataEntry[$k]));
else
$sRet .= $aDataEntry[$k];
$sRet .= ' | |
';
$bHasValues = true;
}
if(!$bHasValues)
return;
$sRet .= '
';
return $sRet;
}
function getStateName($sCountry, $sState){
return $this->oDb->getStateName($sCountry, $sState);
}
function blockCustomFields (&$aDataEntry, $aShow=array()) {
$bHasValues = false;
$sRet = '';
desa_traveler_import ('FormAdd');
$oForm = new BxTravelerFormAdd ($GLOBALS['oBxTravelerModule'], $_COOKIE['memberID']);
foreach ($oForm->aInputs as $k => $a) {
if (!isset($a['display'])) continue;
if (!in_array($a['name'],$aShow)) continue;
if (!trim($aDataEntry[$k])) continue;
$sRet .= ''. $a['caption'] . ' | | ';
if (is_string($a['display']) && is_callable(array($this, $a['display']))){
if($a['name'] == 'state'){
$sRet .= $this->getStateName($aDataEntry['country'], $aDataEntry[$k]);
}else{
$sRet .= call_user_func_array(array($this, $a['display']), array($a['listname'],$aDataEntry[$k]));
}
}else{
$sRet .= $aDataEntry[$k];
}
$sRet .= ' | |
';
$bHasValues = true;
}
if(!$bHasValues)
return;
$sRet .= '
';
return $sRet;
}
function getOptionDisplay($sField='',$sVal='')
{
return ucwords($sVal);
}
function getStatus($sStatus){
switch($sStatus){
case "pending":
$sLangStatus = _t("_desa_traveler_pending");
break;
case "paid":
$sLangStatus = _t("_desa_traveler_paid");
break;
case "active":
$sLangStatus = _t("_desa_traveler_active");
break;
case "inactive":
$sLangStatus = _t("_desa_traveler_inactive");
break;
case "approved":
$sLangStatus = _t("_desa_traveler_approved");
break;
case "expired":
$sLangStatus = _t("_desa_traveler_expired");
break;
}
return $sLangStatus;
}
function filterDate ($i, $bLongFormat = false) {
if($bLongFormat)
return getLocaleDate($i, BX_DOL_LOCALE_DATE) . ' ('.defineTimeInterval($i) . ')';
else
return getLocaleDate($i, BX_DOL_LOCALE_DATE);
}
function displayAvailableLevels($aValues) {
$sCurrencyCode = strtolower($this->_oConfig->getCurrencyCode());
$sCurrencySign = $this->_oConfig->getCurrencySign();
$aMemberships = array();
foreach($aValues as $aValue) {
$aMemberships[] = array(
'url_root' => BX_DOL_URL_ROOT,
'id' => $aValue['id'],
'title' => $aValue['name'],
'description' => str_replace("\$", "$", $aValue['description']),
'days' => $aValue['days'] > 0 ? $aValue['days'] . ' ' . _t('_desa_traveler_days') : _t('_desa_traveler_expires_never') ,
'price' => number_format($aValue['price'],2),
'currency_icon' => $this->getIconUrl($sCurrencyCode . '.png'),
'currency_sign' => $sCurrencySign,
'videos' => ($aValue['videos']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
'photos' => ($aValue['photos']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
'sounds' => ($aValue['sounds']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
'files' => ($aValue['files']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
'featured' => ($aValue['featured']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
);
}
$aVars = array('bx_repeat:levels' => $aMemberships);
$this->addCss('levels.css');
return $this->parseHtmlByName('available_packages', $aVars);
}
function getFormPackageDesc($iPackageId) {
$sCurrencyCode = strtolower($this->_oConfig->getCurrencyCode());
$sCurrencySign = $this->_oConfig->getCurrencySign();
$aPackage = $this->_oDb->getPackageById($iPackageId);
$aVars = array(
'url_root' => BX_DOL_URL_ROOT,
'id' => $aPackage['id'],
'title' => $aPackage['name'],
'description' => str_replace("\$", "$", $aPackage['description']),
'days' => $aPackage['days'] > 0 ? $aPackage['days'] . ' ' . _t('_desa_traveler_days') : _t('_desa_traveler_expires_never') ,
'price' => number_format($aPackage['price'],2),
'currency_icon' => $this->getIconUrl($sCurrencyCode . '.png'),
'currency_sign' => $sCurrencySign,
'videos' => ($aPackage['videos']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
'photos' => ($aPackage['photos']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
'sounds' => ($aPackage['sounds']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
'files' => ($aPackage['files']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
'featured' => ($aPackage['featured']) ? ucwords(_t('_desa_traveler_yes')) : ucwords(_t('_desa_traveler_no')),
);
$this->addCss('levels.css');
return $this->parseHtmlByName('form_package', $aVars);
}
function parseSex ($sVal) {
switch($sVal){
case "male":
$sVal = _t('_desa_traveler_male');
break;
case "female":
$sVal = _t('_desa_traveler_female');
break;
}
return $sVal;
}
function parseYesNo ($sName='', $sVal='') {
switch($sVal){
case "no":
$sVal = _t('_desa_traveler_no');
break;
case "yes":
$sVal = _t('_desa_traveler_yes');
break;
case "maybe":
$sVal = _t('_desa_traveler_maybe');
break;
case "depends":
$sVal = _t('_desa_traveler_depends');
break;
}
return $sVal;
}
function parseYes ($sVal) {
switch($sVal){
case "no":
$sVal = _t('_desa_traveler_no');
break;
case "yes":
$sVal = _t('_desa_traveler_yes');
break;
case "maybe":
$sVal = _t('_desa_traveler_maybe');
break;
case "depends":
$sVal = _t('_desa_traveler_depends');
break;
}
return $sVal;
}
function parseLink ($sName='', $sVal='') {
$sLink = (substr($sVal,0,3)=="www") ? "http://" . $sVal : $sVal;
return ''.$sLink.'';
}
function parsePreValues ($sName, $sVal='') {
return htmlspecialchars_adv( _t($GLOBALS['aPreValues'][$sName][$sVal]['LKey']) );
}
function parseMultiPreValues ($sName, $sVal='') {
$sStr = '';
$aVals = split(';',$sVal);
foreach($aVals as $aEachVal){
if($GLOBALS['aPreValues'][$sName][$aEachVal]['LKey'])
$sStr .= htmlspecialchars_adv( _t($GLOBALS['aPreValues'][$sName][$aEachVal]['LKey'])) . '
';
else
$sStr .= $aEachVal . '
';
}
return $sStr;
}
function blockSubProfileInfo ($sType, &$aData) {
$this->_oMain = BxDolModule::getInstance('BxTravelerModule');
$aAuthor = getProfileInfo($aData['author_id']);
$aVars = array (
'author_thumb' => get_member_thumbnail($aAuthor['ID'], 'none'),
'date' => getLocaleDate($aData['created'], BX_DOL_LOCALE_DATE_SHORT),
'date_ago' => defineTimeInterval($aData['created']),
'tags' => $this->parseSubTags($aData['tags']),
'author_username' => $aAuthor ? $aAuthor['NickName'] : _t('_desa_traveler_admin'),
'author_url' => $aAuthor ? getProfileLink($aAuthor['ID']) : 'javascript:void(0)',
);
return $this->parseHtmlByName('block_subprofile_info', $aVars);
}
function blockSubProfileFields ($sType, &$aDataEntry) {
$bHasValues = false;
$sRet = '';
switch($sType){
case 'notice';
desa_traveler_import ('NoticeFormAdd');
$oForm = new BxTravelerNoticeFormAdd ($GLOBALS['oBxTravelerModule'], $_COOKIE['memberID']);
break;
}
if($sType != 'notice')
return;
foreach ($oForm->aInputs as $k => $a) {
if (!isset($a['display'])) continue;
if (!$aDataEntry[$k]) continue;
$sRet .= ''. $a['caption'] . ' | | ';
if (is_string($a['display']) && is_callable(array($this, $a['display']))){
if($a['name'] == 'state'){
$sRet .= $this->getStateName($aDataEntry['country'], $aDataEntry[$k]);
}else{
if($a['listname'])
$sRet .= call_user_func_array(array($this, $a['display']), array($a['listname'],$aDataEntry[$k]));
else
$sRet .= call_user_func_array(array($this, $a['display']), array($aDataEntry[$k]));
}
}else{
$sRet .= $aDataEntry[$k];
}
$sRet .= ' | |
';
$bHasValues = true;
}
if(!$bHasValues)
return;
$sRet .= '
';
return $sRet;
}
function faq_unit ($aData, $sTemplateName) {
if (null == $this->_oMain)
$this->_oMain = BxDolModule::getInstance('BxTravelerModule');
$aVars = array (
'id' => $aData['id'],
'question' => $aData['question'],
'answer' => $aData['answer']
);
return $this->parseHtmlByName($sTemplateName, $aVars);
}
function notice_unit ($aData, $sTemplateName, &$oVotingView) {
if (null == $this->_oMain)
$this->_oMain = BxDolModule::getInstance('BxTravelerModule');
$aNoticeEntry = $this->_oDb->getNoticeEntryById($aData['id']);
if (!$this->_oMain->isAllowedViewSubProfile ($this->_oDb->_sTableNotice,$aNoticeEntry)) {
$aVars = array ('extra_css_class' => 'desa_traveler_unit');
return $this->parseHtmlByName('browse_unit_private', $aVars);
}
$aTraveler = $this->_oDb->getEntryById($aData['traveler_id']);
$sImage = '';
if ($aData['thumb']) {
$a = array ('ID' => $aTraveler['author_id'], 'Avatar' => $aData['thumb']);
$aImage = BxDolService::call('photos', 'get_image', array($a, 'browse'), 'Search');
$sImage = $aImage['no_image'] ? '' : $aImage['file'];
}
$sDateTime = defineTimeInterval($aData['created']);
$sPostText = $aData['snippet'];
if(!$sPostText){
$iLimitChars = 400;
if (strlen($sPostText) > $iLimitChars) {
$sLinkMore = '...';
$sPostText = process_line_output(mb_substr(strip_tags($sPostText), 0, $iLimitChars)) . $sLinkMore;
}
}
$aVars = array (
'id' => $aData['id'],
'thumb_url' => $sImage ? $sImage : $this->getIconUrl('no-photo.png'),
'notice_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'notice/view/' . $aData['uri'],
'traveler_name' => $aTraveler['traveler_name'],
'traveler_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aTraveler['uri'],
'author_username' => getNickName($aData['author_id']),
'author_url' => getProfileLink($aData['author_id']),
'notice_title' => $aData['title'],
'notice_description' => $sPostText,
'comments_count' => $aData['comments_count'],
'post_date' => strtolower($sDateTime),
'category' => _t('_desa_traveler_'.$aData['category']),
'post_tags' => $this->_oMain->parseTags($aData['tags']),
'from_date' => date("M d, Y", $aData['start']),
'to_date' => date("M d, Y", $aData['end']),
'country_city' => _t($GLOBALS['aPreValues']['Country'][$aData['country']]['LKey']) . (trim($aData['city']) ? ', '.$aData['city'] : '')
);
$aVars['rating'] = $oVotingView ? $oVotingView->getJustVotingElement(0, $aData['id'], $aData['rate']) : ' ';
return $this->parseHtmlByName($sTemplateName, $aVars);
}
function review_unit ($aData, $sTemplateName, &$oVotingView) {
if (null == $this->_oMain)
$this->_oMain = BxDolModule::getInstance('BxTravelerModule');
$aReviewEntry = $this->_oDb->getReviewEntryById($aData['id']);
if (!$this->_oMain->isAllowedViewSubProfile ($this->_oDb->_sTableReview,$aReviewEntry)) {
$aVars = array ('extra_css_class' => 'desa_traveler_unit');
return $this->parseHtmlByName('browse_unit_private', $aVars);
}
$aTraveler = $this->_oDb->getEntryById($aData['traveler_id']);
$sTravelerThumb = get_member_thumbnail($aData['author_id'], 'left');
$sDateTime = defineTimeInterval($aData['created']);
$sPostText = $aData['desc'];
if(!$sPostText){
$iLimitChars = 400;
if (strlen($sPostText) > $iLimitChars) {
$sLinkMore = '...';
$sPostText = process_line_output(mb_substr(strip_tags($sPostText), 0, $iLimitChars)) . $sLinkMore;
}
}
$aVars = array (
'id' => $aData['id'],
'review_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'review/view/' . $aData['uri'],
'traveler_name' => $aTraveler['traveler_name'],
'traveler_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aTraveler['uri'],
'author_username' => getNickName($aData['author_id']),
'author_url' => getProfileLink($aData['author_id']),
'review_title' => $aData['title'],
'review_description' => $sPostText,
'comments_count' => $aData['comments_count'],
'post_date' => strtolower($sDateTime),
'post_uthumb' => $sTravelerThumb,
);
$aVars['rating'] = $oVotingView ? $oVotingView->getJustVotingElement(0, $aData['id'], $aData['rate']) : ' ';
return $this->parseHtmlByName($sTemplateName, $aVars);
}
function parseSubTags($s){
$sRet = '';
$a = explode (',', $s);
foreach ($a as $sName)
$sRet .= $sName.' ';
return $sRet;
}
}
?>