Page 1 of 1

Trying to fix some php

Posted: Wed Jan 07, 2004 1:53 am
by s_mack
I'm not a php guy at all!

I'm trying to simply install an application but I get an error
Fatal error: Call to undefined function: show() in /home/dabinfo/public_html/components/com_newsletter/newsletter.php on line 180
I can post the entire script if its usefull, but I think I've narrowed down the offending area. To help you identify it, "line 180" is 8th row up from the bottom (not counting blanks or the lone curly at the end)

Code: Select all

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&#1111;"REQUEST_URI"], $html);
    echo $html;
&#125;

I don't know anything about PHP, so I could be wrong - but it seems to me that the function is trying to call itself from within itself?? Anyway - can anyone fix this? Thanks.

Posted: Wed Jan 07, 2004 1:57 am
by s_mack
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) &#123;
    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();
&#125;

function listAll ()
&#123;
    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);

&#125;

function _showItem ( $id )
&#123;
    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)) &#123;
        $database->setQuery ( "UPDATE #__newsletter SET hits=hits+1 WHERE id='$id'" );
        $database->Query();
    &#125;

    $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);

&#125;
function showItem( $uid, $mask=0, $gid, $is_editor, $pop, $option ) &#123;
	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) &#123;
		$xwhere='';
	&#125; else &#123;
		$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')"
		;
	&#125;

	$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 )) &#123;
		show( $row, $mask, $gid, $is_editor, $pop, $option );
	&#125; else &#123;
		echo _NOT_AUTH;
		return;
	&#125;
&#125;

function show( $row, $mask=0, $gid, $is_editor, $pop, $option ) &#123;
	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) &#123;
		if ($row->id === null || $row->access > $gid) &#123;
			echo _NOT_AUTH;
			return;
		&#125;
	&#125; else &#123;
		if ($row->id === null ) &#123;
			echo _NOT_AUTH;
			return;
		&#125;
		if ($row->access > $gid) &#123;
			if ($access) &#123;
				echo _NOT_AUTH;
				return;
			&#125;
		&#125;
	&#125;

	$template='';
	if ($pop)&#123;
		$mask |= MASK_POPUP|MASK_IMAGES;
		$database->setQuery( "SELECT cur_template from #__templates" );
		$template = $database->loadResult();
	&#125;


	// 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&#1111;"REQUEST_URI"], $html);
    echo $html;
&#125;

/**
* Shows the email form for a given content item.
*/
function emailContentForm( $uid ) &#123;
	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 )) &#123;
		echo _NOT_AUTH;
		return;
	&#125; else &#123;
		$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&#1111;"REQUEST_URI"], $html);
        echo $html;
	&#125;
&#125;

/**
* Shows the email form for a given content item.
*/
function emailContentSend( $uid ) &#123;
	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) )&#123;
		echo "<script>alert (""._EMAIL_ERR_NOINFO.""); window.history.go(-1);</script>";
		exit(0);
	&#125;

	$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 );
&#125;

function is_email($email)&#123;
	$rBool=false;

	if(preg_match("/&#1111;\w\.\-]+@\w+&#1111;\w\.\-]*?\.\w&#123;1,4&#125;/", $email))&#123;
		$rBool=true;
	&#125;
	return $rBool;
&#125;

?>