heck... i figure someone might ask for the whole thing, so why not post in now. Here's the whole page (of a multi-file app)
Code: Select all
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 Pictura Database Publishing bv |
// | Heiloo, the Netherlands |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Mark Lindeman <mark@pictura-dp.nl> |
// +----------------------------------------------------------------------+
//
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
// load the html drawing class, MUST include the option for components
require_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/classes/html/HTML_content.php');
require_once( $mainframe->getPath( 'front_html', 'com_newsletter' ) );
$pop = mosGetParam( $_REQUEST, 'pop', 0 );
$access = !$mainframe->getCfg( 'shownoauth' );
$task = trim( mosGetParam( $_REQUEST, 'task', "" ) );
$id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );
// Editor usertype check
$is_editor = (strtolower($my->usertype) == 'editor' || strtolower($my->usertype) == 'administrator' || strtolower($my->usertype) == 'superadministrator' );
$Itemid = intval( mosGetParam( $_REQUEST, 'Itemid', 0 ) );
$database->setQuery ( "SELECT name FROM #__menu WHERE id='$Itemid'" );
$menuname = $database->loadResult();
switch ($task) {
case 'view':
showItem( $id, MASK_BACKTOLIST|MASK_PRINT|MASK_MAIL|MASK_IMAGES, $gid, $is_editor, $pop, $option );
// showItem ( $id );
break;
case "emailform":
emailContentForm( $id );
break;
case "emailsend":
emailContentSend( $id );
break;
case "pdf":
exit ("PDF");
break;
default:
listAll();
}
function listAll ()
{
global $database, $gid, $mosConfig_offset, $Itemid, $menuname;
$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
$sql = "SELECT id, subject, send, hits FROM #__newsletter"
."\nWHERE published=1"
."\nAND access <= $gid "
."\nAND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now') "
."\nAND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
."\nORDER BY created DESC";
$database->setQuery( $sql );
$newsletters = $database->loadObjectList();
echo $database->getErrorMsg();
newsletter_html::listAll( $menuname , $newsletters);
}
function _showItem ( $id )
{
global $database, $gid, $mosConfig_offset, $Itemid, $id, $menuname, $mainframe;
$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( 'vote' ) ? (MASK_VOTES|MASK_VOTEFORM) : 0;
if (is_int($id)) {
$database->setQuery ( "UPDATE #__newsletter SET hits=hits+1 WHERE id='$id'" );
$database->Query();
}
$sql = "SELECT id, subject, send, hits, message FROM #__newsletter"
."\nWHERE published=1 AND id=$id"
."\nAND access <= $gid "
."\nAND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now') "
."\nAND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
."\nORDER BY created DESC";
$database->setQuery( $sql );
$newsletter = null;
$database->loadObject( $newsletter );
echo $database->getErrorMsg();
// it would be nice to use the standard HTML_content::show()
// please contact me if you have time to do this!
newsletter_html::showItem( $menuname , $newsletter);
}
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 = ""
. "\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;
$sql = "SELECT id, subject AS title, send AS created, hits, message AS text FROM #__newsletter"
."\nWHERE published=1 AND id=$uid $xwhere"
."\nAND access <= $gid "
."\nORDER BY created DESC";
$database->setQuery( $sql );
$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;
if ($is_editor) {
if ($row->id === null || $row->access > $gid) {
echo _NOT_AUTH;
return;
}
} else {
if ($row->id === null ) {
echo _NOT_AUTH;
return;
}
if ($row->access > $gid) {
if ($access) {
echo _NOT_AUTH;
return;
}
}
}
$template='';
if ($pop){
$mask |= MASK_POPUP|MASK_IMAGES;
$database->setQuery( "SELECT cur_template from #__templates" );
$template = $database->loadResult();
}
// record the hit
$database->setQuery ( "UPDATE #__newsletter SET hits=hits+1 WHERE id='$row->id'" );
$database->Query();
// patch the standard output
ob_start();
newsletter_html::show( $row, $mask, $is_editor, $page, $option );
$html = ob_get_contents();
ob_end_clean();
$html = str_replace ("option=content", "option=com_newsletter", $html);
// ugly hack: no pdf support for newsletter
$html = preg_replace ("/<img.+alt="pdf" \/>/i", "<!-- NO PDF -->", $html);
$html = str_replace (""#"", $_SERVERї"REQUEST_URI"], $html);
echo $html;
}
/**
* Shows the email form for a given content item.
*/
function emailContentForm( $uid ) {
global $database, $mainframe, $my;
$sql = "SELECT id, subject AS title, send AS created, hits, message AS text FROM #__newsletter"
."\nWHERE published=1 AND id=$uid ";
$database->setQuery( $sql );
$row = null;
if (!$database->loadObject( $row )) {
echo _NOT_AUTH;
return;
} else {
$template='';
$database->setQuery( "SELECT cur_template from #__templates" );
$template = $database->loadResult();
ob_start();
newsletter_html::emailForm( $row->id, $row->title, $template );
$html = ob_get_contents();
ob_end_clean();
$html = str_replace ("option=content", "option=com_newsletter", $html);
$html = str_replace (""#"", $_SERVERї"REQUEST_URI"], $html);
echo $html;
}
}
/**
* 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,
"\n$mosConfig_live_site/index.php?option=com_newsletter&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+ї\w\.\-]*?\.\w{1,4}/", $email)){
$rBool=true;
}
return $rBool;
}
?>