<?php
// $Id: content.php,v 1.66 2003/11/05 13:51:31 saka_car Exp $
/**
* Content frontend event handler
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.66 $
**/// 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' ) );
$sectionid = trim( mosGetParam( $_REQUEST, 'sectionid', 0 ) );
$pop = mosGetParam( $_REQUEST, 'pop', 0 );
// Editor usertype check
$is_editor = (strtolower($my->usertype) == 'editor' || strtolower($my->usertype) == 'administrator' || strtolower($my->usertype) == 'superadministrator' );
$task = mosGetParam( $_REQUEST, 'task', "" );
// option masks
/*
define( "MASK_BACKTOLIST", 0x0001 );
define( "MASK_READON", 0x0002 );
define( "MASK_POPUP", 0x0004 );
define( "MASK_PRINT", 0x0008 );
define( "MASK_MAIL", 0x0010 );
define( "MASK_IMAGES", 0x0020 );
define( "MASK_HIDEAUTHOR", 0x0100 );
define( "MASK_HIDECREATEDATE", 0x0200 );
define( "MASK_HIDEMODIFYDATE", 0x0400 );
*/
$id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );
switch (strtolower($task)) {
case "view":
showItem( $id, MASK_BACKTOLIST|MASK_PRINT|MASK_MAIL|MASK_IMAGES, $gid, $is_editor, $pop, $option );
break;
case "section":
showSection( $id, $gid, $is_editor );
break;
case "category":
showCategory( $id, $gid, $is_editor, $sectionid );
break;
case "blogsection":
showBlogSection( $id, $gid, $is_editor, $pop, $option );
break;
case "blogcategory":
showBlogCategory( $id, $gid, $is_editor, $pop, $option );
break;
case "edit":
editItem( $id, $gid, $is_editor, 0, $task, $Itemid );
break;
case "new":
editItem( 0, $gid, $is_editor, $sectionid, $task, $Itemid );
break;
case "save":
saveContent();
break;
case "cancel":
cancelContent();
break;
case "emailform":
emailContentForm( $id );
break;
case "emailsend":
emailContentSend( $id );
break;
case "vote":
recordVote ( $url , $user_rating , $cid , $database);
break;
default:
showBlogSection( 0, $gid, $is_editor );
break;
}
function showSection( $id, $gid, $is_editor) {
global $database, $mainframe, $mosConfig_offset;
$access = !$mainframe->getCfg( 'shownoauth' );
$section = new mosSection( $database );
$section->load( $id );
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
if ($is_editor) {
$xwhere='';
$xwhere2 = '';
} else {
$xwhere = "AND c.published='1'";
$xwhere2 = "AND b.state='1'"
. "\n AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now')"
. "\n AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
;
}
$database->setQuery( "SELECT c.*, COUNT(b.id) AS numitems"
. "\nFROM #__categories AS c"
. "\nLEFT JOIN #__content AS b ON b.catid = c.id $xwhere2"
. "\nWHERE c.section='$section->id' $xwhere"
. ($access ? "\n AND c.access<='$gid'" : "" )
. "\nGROUP BY c.id"
. "\n HAVING COUNT(b.id) > 0"
. "\nORDER BY c.ordering"
);
$categories = $database->loadObjectList();
$items = array();
HTML_content::showContentList( $section, $categories, $items, $is_editor, $id, 0, $gid);
}
function showCategory( $id, $gid, $is_editor, $sectionid ) {
global $database, $mainframe, $Itemid, $mosConfig_offset;
$access = !$mainframe->getCfg( 'shownoauth' );
$category = new mosCategory( $database );
$category->load( $id );
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
if ($is_editor) {
$xwhere = '';
$xwhere2 = '';
} else {
$xwhere = "\n AND c.published='1'";
$xwhere2 = "AND b.state='1'"
. "\n AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now')"
. "\n AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
;
}
// check if this is a category menu item
if ($Itemid) {
$menu = new mosMenu( $database );
$menu->load( $Itemid );
if ($menu->type == 'content_category') {
$xwhere = "\n AND c.id='$id'";
}
}
// get the list of other categories
$database->setQuery( "SELECT c.*, COUNT(b.id) AS numitems"
. "\nFROM #__categories AS c"
. "\nLEFT JOIN #__content AS b ON b.catid = c.id $xwhere2"
. "\nWHERE c.section='$category->section' $xwhere"
. ($access ? "\n AND c.access<='$gid'" : "" )
. "\nGROUP BY c.id"
. "\n HAVING COUNT(b.id) > 0"
. "\nORDER BY c.ordering"
);
$categories = $database->loadObjectList();
if ($is_editor) {
$xwhere = '';
} else {
$xwhere = "AND c.state='1'"
. "\n AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now')"
. "\n AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
;
}
// get the list of items for this category
$database->setQuery( "SELECT c.id, c.title, c.hits, c.created_by_alias,"
. "\n c.created AS created, c.access, u.name AS author"
. "\nFROM #__content AS c"
. "\nLEFT JOIN #__users AS u ON u.id = c.created_by"
// . "\nWHERE c.catid='$category->id' AND c.access<='$gid' $xwhere "
. "\nWHERE c.catid='$category->id' $xwhere "
. ($access ? "\n AND c.access<='$gid'" : "" )
. "\nORDER BY c.ordering"
);
$items = $database->loadObjectList();
HTML_content::showContentList( $category, $categories, $items, $is_editor, $id, $sectionid, $gid );
}
function showBlogSection( $id=0, $gid, $is_editor, $pop, $option ) {
global $database, $mainframe, $mosConfig_offset;
$access = !$mainframe->getCfg( 'shownoauth' );
$Itemid = mosGetParam( $_REQUEST, 'Itemid', 0 );
$params = new stdClass();
if ($Itemid) {
$menu = new mosMenu( $database );
$menu->load( $Itemid );
$params = mosParseParams( $menu->params );
}
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
$where = array();
if (!$is_editor) {
$where = "a.state='1'";
$where = "(a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '$now')";
$where = "(a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '$now')";
}
if ($access) {
$where = "a.access<='$gid'";
}
if ($id > 0) {
$where = "a.sectionid='$id'";
}
$database->setQuery( "SELECT v.*, a.*, u.name AS author, u.usertype"
. "\nFROM #__content AS a"
. "\nLEFT JOIN #__users AS u ON u.id = a.created_by"
. "\nLEFT JOIN #__votes AS v ON a.id = v.content_id"
. (count( $where ) ? "\nWHERE ".implode( "\n AND ", $where ) : '')
. "\nORDER BY a.sectionid, a.catid, a.ordering ASC"
);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
$count = isset( $params->count ) ? $params->count : 6;
$intro = isset( $params->intro ) ? $params->intro : 3;
$image = @$params->image ? MASK_IMAGES : 0;
$header = @$params->header;
$empty = @$params->empty;
if ($header) {
echo $header;
}
$t = new mosTemplate( $database );
$t->load( 0 );
$n = min( count( $rows ), $count );
if ($n > 0) {
$col=$t->col_main;
echo "\n<table cellspacing=\"0\" cellpadding=\"0\ border=\"0\">\n";
$i2=0;
$n2=$n;
$intro2 = $intro;
// Leading story
if ($col==3) {
echo "<tr>\n";
echo "<td valign=\"top\" colspan=\"2\">\n";
show( $rows, MASK_READON|$image, $gid, $is_editor, $pop, $option );
echo "</td>\n";
echo "</tr>\n";
$i2++;
$n2--;
$intro2--;
}
for ($i=0; $i < $n2; $i++) {
if (!($i%2) || $col==1) {
echo "<tr>\n";
}
echo $col!=1 ? "<td valign=\"top\">\n" : "<td width=\"50%\" valign=\"top\">\n";
if ($i < $intro2) {
show( $rows, MASK_READON|$image, $gid, $is_editor, $pop, $gid );
} else {
HTML_content::showLinks( $rows, $intro, $n );
echo "</td>\n</tr>\n";
break;
}
echo "</td>\n";
if ($i%2 || $col==1) {
echo "</tr>\n";
}
}
echo "\n</table>";
}
}
function showBlogCategory( $id=0, $gid, $is_editor, $pop, $option ) {
global $database, $mainframe, $mosConfig_offset;
$access = !$mainframe->getCfg( 'shownoauth' );
$Itemid = mosGetParam( $_REQUEST, 'Itemid', 0 );
$params = new stdClass();
if ($Itemid) {
$menu = new mosMenu( $database );
$menu->load( $Itemid );
$params = mosParseParams( $menu->params );
}
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
$where = array();
if (!$is_editor) {
$where = "a.state='1'";
$where = "(a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '$now')";
$where = "(a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '$now')";
}
if ($access) {
$where = "a.access<='$gid'";
}
if ($id > 0) {
$where = "a.catid='$id'";
}
$database->setQuery( "SELECT v.*, a.*, u.name AS author, u.usertype"
. "\nFROM #__content AS a"
. "\nLEFT JOIN #__users AS u ON u.id = a.created_by"
. "\nLEFT JOIN #__votes AS v ON a.id = v.content_id"
. (count( $where ) ? "\nWHERE ".implode( "\n AND ", $where ) : '')
. "\nORDER BY a.sectionid, a.catid, a.ordering ASC"
);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
$count = isset( $params->count ) ? $params->count : 6;
$intro = isset( $params->intro ) ? $params->intro : 3;
$image = @$params->image ? MASK_IMAGES : 0;
$header = @$params->header;
$empty = @$params->empty;
if ($header) {
echo $header;
}
$t = new mosTemplate( $database );
$t->load( 0 );
$n = min( count( $rows ), $count );
if ($n > 0) {
$col=$t->col_main;
echo "\n<table cellspacing=\"0\" cellpadding=\"0\ border=\"0\">\n";
$i2=0;
$n2=$n;
$intro2 = $intro;
// Leading story
if ($col==3) {
echo "<tr>\n";
echo "<td valign=\"top\" colspan=\"2\">\n";
show( $rows, MASK_READON|$image, $gid, $is_editor, $pop, $option );
echo "</td>\n";
echo "</tr>\n";
$i2++;
$n2--;
$intro2--;
}
for ($i=0; $i < $n2; $i++) {
if (!($i%2) || $col==1) {
echo "<tr>\n";
}
echo $col!=1 ? "<td valign=\"top\">\n" : "<td width=\"50%\" valign=\"top\">\n";
if ($i < $intro2) {
show( $rows, MASK_READON|$image, $gid, $is_editor, $pop, $gid );
} else {
HTML_content::showLinks( $rows, $intro, $n );
echo "</td>\n</tr>\n";
break;
}
echo "</td>\n";
if ($i%2 || $col==1) {
echo "</tr>\n";
}
}
echo "\n</table>";
}
}
function showItem( $uid, $mask=0, $gid, $is_editor, $pop, $option ) {
global $database, $mainframe;
global $mosConfig_offset, $mosConfig_live_site;
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
if ($is_editor) {
$xwhere='';
} else {
$xwhere = "AND a.state='1'"
. "\n AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now')"
. "\n AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
;
}
$mask |= $mainframe->getCfg( 'hideAuthor' ) ? MASK_HIDEAUTHOR : 0;
$mask |= $mainframe->getCfg( 'hideCreateDate' ) ? MASK_HIDECREATEDATE : 0;
$mask |= $mainframe->getCfg( 'hideModifyDate' ) ? MASK_HIDEMODIFYDATE : 0;
$mask |= $mainframe->getCfg( 'vote' ) ? MASK_VOTES : 0;
$database->setQuery( "SELECT v.*, a.*, u.name AS author, u.usertype"
. "\nFROM #__content AS a"
. "\nLEFT JOIN #__users AS u ON u.id = a.created_by"
. "\nLEFT JOIN #__votes AS v ON a.id = v.content_id"
. "\nWHERE a.id='$uid' $xwhere"
. "\n AND a.access <= $gid"
);
$row = null;
if ($database->loadObject( $row )) {
show( $row, $mask, $gid, $is_editor, $pop, $option );
} else {
echo _NOT_AUTH;
return;
}
}
function show( $row, $mask=0, $gid, $is_editor, $pop, $option ) {
global $database, $mainframe, $Itemid;
global $mosConfig_live_site, $mosConfig_absolute_path;
$access = !$mainframe->getCfg( 'shownoauth' ); // requires honouring of access
$mask |= $mainframe->getCfg( 'hideAuthor' ) ? MASK_HIDEAUTHOR : 0;
$mask |= $mainframe->getCfg( 'hideCreateDate' ) ? MASK_HIDECREATEDATE : 0;
$mask |= $mainframe->getCfg( 'hideModifyDate' ) ? MASK_HIDEMODIFYDATE : 0;
$mask |= $mainframe->getCfg( 'vote' ) ? (MASK_VOTES|MASK_VOTEFORM) : 0;
if ($is_editor) {
if ($row->id === null || $row->access > $gid) {
echo _NOT_AUTH;
return;
}
} else {
if ($row->id === null || $row->state != 1) {
echo _NOT_AUTH;
return;
}
if ($row->access > $gid) {
if ($access) {
echo _NOT_AUTH;
return;
} else {
if (!($mask&MASK_READON)) {
echo _NOT_AUTH;
return;
}
}
}
}
$template='';
if ($pop){
$mask |= MASK_POPUP|MASK_IMAGES;
$database->setQuery( "SELECT cur_template from #__templates" );
$template = $database->loadResult();
}
$row->text = $row->introtext.($mask&MASK_READON ? '' : "$row->fulltext");
$bots = mosReadDirectory( "$mosConfig_absolute_path/mambots", "\.php$" );
sort( $bots );
foreach ($bots as $bot) {
require "mambots/$bot";
}
/*
// replace the {mosimage} mambots in both text areas
if ($mask&MASK_IMAGES) {
$row->images = explode( "\n", $row->images );
$images = array();
foreach ($row->images as $img) {
$temp = explode( '|', trim( $img ) );
if(!isset($temp))
$temp = "left";
if(!isset($temp))
$temp = "Image";
if(!isset($temp))
$temp = "0";
$images = "<img src=\"$mosConfig_live_site/images/stories/$temp\" align=\"$temp\" hspace=\"6\" alt=\"$temp\" border=\"$temp\" />";
}
$text = explode( '{mosimage}', $row->text );
$row->text = $text;
for ($i=0, $n=count( $text )-1; $i < $n; $i++) {
if (isset( $images )) {
$row->text .= $images;
}
if (isset( $text )) {
$row->text .= $text;
}
}
unset( $text );
} else {
$row->text = str_replace( '{mosimage}', '', $row->introtext );
}
*/
// deal with the {mospagebreak} mambots
// only permitted in the full text area
$page = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) );
/*
if (!($mask&MASK_READON)) {
$text = explode( '{mospagebreak}', $row->text );
$n = count( $text );
if ($n > 1) {
// we have found at least one mambot
require_once( "includes/pageNavigation.php" );
$pageNav = new mosPageNav( $n, $page, 1 );
$row->text = "<div align=\"right\">";
$row->text .= $pageNav->writePagesCounter();
$row->text .= "</div>";
$row->text .= $text;
$row->text .= "<br /><br /><br />";
$row->text .= "<div class=\"pagenavbar\" align=\"center\">";
if ($pop) {
$row->text .= $pageNav->writePagesLinks( "index2.php?option=content&task=view&pop=$pop&id=$row->id" );
} else {
$row->text .= $pageNav->writePagesLinks( "index.php?option=content&task=view&id=$row->id&Itemid=$Itemid" );
}
$row->text .= "</div>";
}
}
*/
// record the hit
if (!($mask&MASK_READON)) {
$obj = new mosContent( $database );
$obj->hit( $row->id );
}
HTML_content::show( $row, $mask, $is_editor, $page, $option );
}
function editItem( $uid, $gid, $is_editor, $sectionid=0, $task, $Itemid ){
global $database, $mainframe, $my;
global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_editor;
if (!$my->id || !$is_editor) {
echo _NOT_AUTH;
return;
}
$row = new mosContent( $database );
// load the row from the db table
$row->load( $uid );
if ($uid) {
$sectionid = $row->sectionid;
}
// get list of categories
$categories = mosHTML::makeOption( '0', 'Select Category' );
$database->setQuery( "SELECT id AS value, name AS text FROM #__categories"
. "\nWHERE section='$sectionid' ORDER BY ordering" );
$categories = array_merge( $categories, $database->loadObjectList() );
if (strtolower($task)<>'edit'){
if (count( $categories ) < 2) {
mosRedirect( "index.php?option=categories§ion=$sectionid",
"You must add a category for this section first." );
}
}
if ($uid==0) {
$row->catid = 0;
}
$clist = mosHTML::selectList( $categories, 'catid', 'class="inputbox" size="1"',
'value', 'text', intval( $row->catid ) );
// get the type name - which is a special category
$database->setQuery( "SELECT name FROM #__sections WHERE id=$sectionid" );
$section = $database->loadResult();
// fail if checked out not by 'me'
if ($row->checked_out && $row->checked_out <> $my->id) {
echo"<SCRIPT>alert('The module ".$row->title." is currently being edited by another person.')</script>";
mosRedirect( "index.php?option=content&task=view&id=$row->id");
}
if ($uid) {
$row->checkout( $my->id );
if (trim( $row->images )) {
$row->images = explode( "\n", $row->images );
} else {
$row->images = array();
}
} else {
$row->sectionid = $sectionid;
$row->version = 0;
$row->state = 0;
$row->ordering = 9999;
$row->images = array();
$row->publish_up = date( "Y-m-d", time() );
$row->publish_down = "0000-00-00 00:00:00";
}
// make the select list for the states
$states = mosHTML::makeOption( 0, 'UnPublished' );
$states = mosHTML::makeOption( 1, 'Published' );
$statelist = mosHTML::selectList( $states, 'state', 'class="inputbox" size="1"',
'value', 'text', intval( $row->state ) );
// get list of images
$imgFiles = mosReadDirectory( "$mosConfig_absolute_path/images/stories" );
$images = array();
foreach ($imgFiles as $file) {
if (eregi( "bmp|gif|jpg|png", $file )) {
$images = mosHTML::makeOption( $file );
}
}
$ilist = mosHTML::selectList( $images, 'imagefiles', "class=\"inputbox\" size=\"7\" multiple=\"multiple\""
. " onchange=\"previewImage('imagefiles','view_imagefiles','$mosConfig_live_site/images/stories/')\"",
'value', 'text', null );
// make the list of saved images
$images2 = array();
foreach ($row->images as $file) {
$temp = explode( '|', $file );
$images2 = mosHTML::makeOption( $file, $temp );
}
$i2list = mosHTML::selectList( $images2, 'imagelist', "class=\"inputbox\" size=\"7\""
. " onchange=\"showImageProps('$mosConfig_live_site/images/stories/')\"",
'value', 'text', null );
// make the select list for the image positions
$pos = mosHTML::makeOption( 'left' );
$pos = mosHTML::makeOption( 'center' );
$pos = mosHTML::makeOption( 'right' );
// build the html select list
$poslist = mosHTML::selectList( $pos, '_align', 'class="inputbox" size="2"',
'value', 'text', null );
// get list of groups
$database->setQuery( "SELECT id AS value, name AS text FROM #__groups ORDER BY id" );
$groups = $database->loadObjectList();
// build the html select list
$glist = mosHTML::selectList( $groups, 'access', 'class="inputbox" size="1"',
'value', 'text', intval( $row->access ) );
// get list of other menu items by order
if ($uid) {
// build the html select list for ordering
$order = mosGetOrderingList( "SELECT ordering AS value, title AS text"
. "\nFROM #__content"
. "\nWHERE catid='$row->catid' ORDER BY ordering"
);
$olist = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"',
'value', 'text', intval( $row->ordering ) );
} else {
$olist = "<input type=\"hidden\" name=\"ordering\" value=\"$row->ordering\" />"
. " New items default to the last place";
}
$row->creator = 0;
$row->modifier = 0;
if ($uid) {
$database->setQuery( "SELECT name from #__users"
. "\nWHERE id=$row->created_by"
);
$row->creator = $database->loadResult();
$database->setQuery( "SELECT name from #__users"
. "\nWHERE id=$row->modified_by"
);
$row->modifier = $database->loadResult();
}
HTML_content::editContent( $row, $section, $statelist, $clist, $glist, $ilist, $i2list, $poslist, $olist, $my->id, $sectionid, $task, $Itemid, $mosConfig_editor );
}
/**
* Saves the content item an edit form submit
*/
function saveContent( $Itemid ) {
global $database, $mainframe, $my, $is_editor;
if (!$is_editor) {
return;
}
$row = new mosContent( $database );
if (!$row->bind( $_POST )) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit();
}
if ($row->id) {
$row->modified = date( "Y-m-d H:i:s" );
$row->modified_by = $my->id;
} else {
$row->created = date( "Y-m-d H:i:s" );
$row->created_by = $my->id;
}
$row->mask = intval( $row->mask );
if (!$row->check()) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit();
}
$row->version++;
if (!$row->store()) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit();
}
$row->checkin();
$row->updateOrder( "catid='$row->catid'" );
$Itemid = mosGetParam( $_POST, 'Returnid', '0' );
mosRedirect( "index.php?Itemid=$Itemid" );
}
/**
* Cancels an edit operation
* @param database A database connector object
*/
function cancelContent() {
global $database, $mainframe, $is_editor;
if (!$is_editor) {
return;
}
$row = new mosContent( $database );
$row->bind( $_POST );
$row->checkin();
$Itemid = mosGetParam( $_POST, 'Returnid', '0' );
mosRedirect( "index.php?Itemid=$Itemid" );
}
/**
* Shows the email form for a given content item.
*/
function emailContentForm( $uid ) {
global $database, $mainframe, $my;
$row = new mosContent( $database );
$row->load( $uid );
if ($row->id === null || $row->access > $my->gid) {
echo _NOT_AUTH;
return;
} else {
$template='';
$database->setQuery( "SELECT cur_template from #__templates" );
$template = $database->loadResult();
HTML_content::emailForm( $row->id, $row->title, $template );
}
}
/**
* Shows the email form for a given content item.
*/
function emailContentSend( $uid ) {
global $database;
global $mosConfig_live_site, $mosConfig_sitename;
$email = trim( mosGetParam( $_POST, 'email', '' ) );
$yourname = trim( mosGetParam( $_POST, 'yourname', '' ) );
$youremail = trim( mosGetParam( $_POST, 'youremail', '' ) );
if (!$email || !$youremail || (is_email($email)==false) || (is_email($youremail)==false) ){
echo "<script>alert (\""._EMAIL_ERR_NOINFO."\"); window.history.go(-1);</script>";
exit(0);
}
$template='';
$database->setQuery( "SELECT cur_template from #__templates" );
$template = $database->loadResult();
$msg = sprintf( _EMAIL_MSG,
$mosConfig_sitename,
$yourname,
$youremail,
"$mosConfig_live_site/index.php?option=content&task=view&id=$uid"
);
$recipient = $email;
$subject = _EMAIL_INFO." $yourname";
$headers = "MIME-Version: 1.0\r \n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\r \n";
$headers .= "From: ".$yourname." <".$youremail.">\r \n";
$headers .= "Reply-To: <".$youremail.">\r \n";
$headers .= "X-Priority: 3\r \n";
$headers .= "X-MSMail-Priority: Low\r \n";
$headers .= "X-Mailer: Mambo Open Source 4.5\r \n";
@mail($recipient, $subject, $msg, $headers);
HTML_content::emailSent( $email, $template );
}
function is_email($email){
$rBool=false;
if(preg_match("/+@\w+*?\.\w{1,4}/", $email)){
$rBool=true;
}
return $rBool;
}
function recordVote ( $url , $user_rating , $cid , $database ){
if (($user_rating>=1) and ($user_rating<=5)) {
$sql = "SELECT votes,lastip,allvotes FROM #__votes WHERE content_id = $cid";
$database->setQuery( $sql );
$votesdb=null;
if (!($database->loadObject( $votesdb ))){
$sql="INSERT INTO #__votes (content_id) VALUES ($cid)";
$database->setQuery( $sql );
$database->query();
$votes = '';
$lastip = '';
$allvotes = 0;
}
$currip=getenv("REMOTE_ADDR");
if ($currip<>($votesdb->lastip)){
$allvotes=intval($votesdb->allvotes);
$votes=$user_rating.','.$votesdb->votes;
$votes_arr=explode(",", $votes);
for($x=0;$x<(count($votes_arr)-1);$x++){
$votes_count=$votes_count+$votes_arr;
}
$newrating=$votes_count/(($votesdb->allvotes)+1);
$newrating = intval($newrating);
$sql="UPDATE #__votes SET allvotes=allvotes+1, rating=$newrating, votes='$votes', lastip='$currip' WHERE content_id=$cid";
$database->setQuery( $sql );
$database->query();
mosRedirect ($url, "Thanks For Your Vote!");
} else {
mosRedirect ($url, "You have already voted!");
}
}
}
?>