Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2012, 03:55 PM   PM User | #1
Angiec
New Coder

 
Join Date: Apr 2012
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Angiec is an unknown quantity at this point
Parse error- can anyone find the issue?

The error is on this page: http://dstone1029.net/box-office-analyst-dev/

Can anyone tell me what's wrong with the corresponding code below? Thanks for any help you can offer!
Code:
<p>
	&nbsp;
</p>
<p><!-- Import and render trailer links {{{-->
	<?php>
print <<< HERE
<table width="100%" class="table1">
<tr>
<th id="mythead" style="text-align:left; font-size:12px;">Film Title </th>
<th id="mythead" style="text-align:left; font-size:12px;">Release Date</th>
</tr>
<p>HERE;</p>
<p>$data = file("http://dstone1029.net/textuploads/trailers.txt");
foreach ($data as $line){
  $lineArray = explode("|", $line);</p>
<p> list($moviename, $releasedate, $trailerlink) = $lineArray;
  print <<< HERE
<tr>
<td id="leftcell" style="color:#0000ff; font-size:12px;"> <a style="color:#0000ff;" href="$trailerlink" target="youtube">$moviename</a></td>
<td id="leftcell" style="font-size:12px;">$releasedate</td>
</tr>
<p>HERE;
} // end foreach</p>
<p>//print the bottom of the table
print "</table>
<p> \n";</p>
<p>?><!-- Trailer links rendering end }}}-->
</p>
Angiec is offline   Reply With Quote
Old 12-27-2012, 04:08 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Post the actual error itself.
In this case, I'd expect that it'll be an unexpected $end error. This is invalid: <?php>. Depending on configurations one of the following must be used:
<?php ... ?>
<? ... ?>
<% ... %>
<script language="php"> ... </script>

Edit:
Also, things like this are invalid: <p>HERE;</p>. HEREDOC ending delimiters MUST be on a line by themselves and not be preceded by any characters.

Last edited by Fou-Lu; 12-27-2012 at 04:12 PM..
Fou-Lu is offline   Reply With Quote
Old 12-27-2012, 04:10 PM   PM User | #3
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
That is some truly disgusting code...

Could you give us a large snippet?

Your error:

PHP Code:
Parse errorsyntax errorunexpected $end in /home/content/12/9807012/html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 30 
Suggests that you haven't given us the right snippet of code; we need this file: (that riduclous location here)/includes/runtime.php

Just post the entire thing if you could
TFlan is offline   Reply With Quote
Old 12-27-2012, 04:16 PM   PM User | #4
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
You have done a lot of stuff wrong. You have used the HEREDOC wrongly, dropped into and out of PHP and HTML code terribly.

The following will probably not work as you wanted your code to work because I do not see the rest of your code but it should start you off as to how you should drop into and out of PHP code.
PHP Code:
<p>
    &nbsp;
</p>
<p><!-- Import and render trailer links {{{-->
    <?php
print <<< HERE
<table width="100%" class="table1">
<tr>
<th id="mythead" style="text-align:left; font-size:12px;">Film Title </th>
<th id="mythead" style="text-align:left; font-size:12px;">Release Date</th>
</tr>
<p>
</p>
<p>
HERE;
$data file("http://dstone1029.net/textuploads/trailers.txt");
foreach (
$data as $line){
  
$lineArray explode("|"$line);
print <<<CODE
</p>
<p> 
CODE;
list(
$moviename$releasedate$trailerlink) = $lineArray;

print <<<HEREP
<tr>
<td id="leftcell" style="color:#0000ff; font-size:12px;"> <a style="color:#0000ff;" href="$trailerlink" target="youtube">$moviename</a></td>
<td id="leftcell" style="font-size:12px;">$releasedate</td>
</tr>
<p>
HEREP;
}
 
// end foreach
 
print <<<CODE
 </p>
<p>//print the bottom of the table
print "</table>
<p> \n";</p>
<p><!-- Trailer links rendering end }}}-->
</p>
CODE;
?>
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 12-27-2012, 04:18 PM   PM User | #5
Angiec
New Coder

 
Join Date: Apr 2012
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Angiec is an unknown quantity at this point
Thanks for the replies... I'm aware it's hideous. I didn't write it, but was asked to work with it. Here's the includes/runtime.php:

Code:
<?php

require_once(dirname(__FILE__).'/cache.php');
require_once(dirname(__FILE__).'/const.php');

// -----------------------------------------------------------------------------
// the ExecPhp_Runtime class handles the execution of PHP code during
// access to the articles content or widget including checks against
// the exec_php / edit_others_php capability or plugin options respectivly
// -----------------------------------------------------------------------------

if (!class_exists('ExecPhp_Runtime')) :
class ExecPhp_Runtime
{
	var $m_cache = NULL;

	// ---------------------------------------------------------------------------
	// init
	// ---------------------------------------------------------------------------

	function ExecPhp_Runtime(&$cache)
	{
		$this->m_cache =& $cache;

		add_filter('the_content', array(&$this, 'filter_user_content'), 1);
		add_filter('the_content_rss', array(&$this, 'filter_user_content'), 1);
		add_filter('the_excerpt', array(&$this, 'filter_user_content'), 1);
		add_filter('the_excerpt_rss', array(&$this, 'filter_user_content'), 1);
		add_filter('widget_text', array(&$this, 'filter_widget_content'), 1);
		add_filter('user_has_cap', array(&$this, 'filter_user_has_cap'), 10, 3);
	}

	// ---------------------------------------------------------------------------
	// tools
	// ---------------------------------------------------------------------------

	function eval_php($content)
	{
		// to be compatible with older PHP4 installations
		// don't use fancy ob_XXX shortcut functions
		ob_start();
		eval("?>$content<?php ");
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

	// ---------------------------------------------------------------------------
	// hooks
	// ---------------------------------------------------------------------------

	function filter_user_content($content)
	{
		global $post;

		// check whether the article author is allowed to execute PHP code
		if (!isset($post) || !isset($post->post_author))
			return $content;
		$poster = new WP_User($post->post_author);
		if (!$poster->has_cap(ExecPhp_CAPABILITY_EXECUTE_ARTICLES))
			return $content;
		return $this->eval_php($content);
	}

	function filter_widget_content($content)
	{
		// check whether the admin has configured widget support
		$option =& $this->m_cache->get_option();
		if (!$option->get_widget_support())
			return $content;

		return $this->eval_php($content);
	}

	function filter_user_has_cap($allcaps, $caps, $args)
	{
		// $allcaps = Capabilities the user currently has
		// $caps = Primitive capabilities being tested / requested
		// $args = array with:
		// $args[0] = original meta capability requested
		// $args[1] = user being tested
		// See code for assumptions

		// This handler is only set up to deal with the edit_others_pages
		// or edit_others_posts capability. Ignore all other calls into here.
		$pages_request = in_array('edit_others_pages', $caps);
		$posts_request = in_array('edit_others_posts', $caps);
		if ((!$pages_request && !$posts_request)
			|| ($pages_request && $posts_request)
			|| !$args[0] || !$args[1] || $args[1] == 0)
			return $allcaps;

		global $post;
		if (!isset($post))
			return $allcaps;
		$poster = new WP_User($post->post_author);
		if (!$poster->has_cap(ExecPhp_CAPABILITY_EXECUTE_ARTICLES))
			return $allcaps;

		$editor_has_edit_others_php = (in_array(ExecPhp_CAPABILITY_EDIT_OTHERS_PHP, $allcaps)
			&& $allcaps[ExecPhp_CAPABILITY_EDIT_OTHERS_PHP]);
		if ($editor_has_edit_others_php)
			return $allcaps;

		// article may contain PHP code due to the original posters capabilities
		// but the editor is not allowed to edit others PHP code, so filter out
		// requested edit_others_xxx settings from the allowed caps
		if ($pages_request)
			unset($allcaps['edit_others_pages']);
		if ($posts_request)
			unset($allcaps['edit_others_posts']);
		return $allcaps;
	}
}
endif;

?>
Angiec is offline   Reply With Quote
Old 12-27-2012, 04:22 PM   PM User | #6
Angiec
New Coder

 
Join Date: Apr 2012
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Angiec is an unknown quantity at this point
Redcoder-- That did actually work (THANKS!), but to a point... where is it getting the text that rendered before/after the table on the page-- see link here:

http://dstone1029.net/box-office-analyst-dev/


Quote:
Originally Posted by Redcoder View Post
You have done a lot of stuff wrong. You have used the HEREDOC wrongly, dropped into and out of PHP and HTML code terribly.

The following will probably not work as you wanted your code to work because I do not see the rest of your code but it should start you off as to how you should drop into and out of PHP code.
PHP Code:
<p>
    &nbsp;
</p>
<p><!-- Import and render trailer links {{{-->
    <?php
print <<< HERE
<table width="100%" class="table1">
<tr>
<th id="mythead" style="text-align:left; font-size:12px;">Film Title </th>
<th id="mythead" style="text-align:left; font-size:12px;">Release Date</th>
</tr>
<p>
</p>
<p>
HERE;
$data file("http://dstone1029.net/textuploads/trailers.txt");
foreach (
$data as $line){
  
$lineArray explode("|"$line);
print <<<CODE
</p>
<p> 
CODE;
list(
$moviename$releasedate$trailerlink) = $lineArray;

print <<<HEREP
<tr>
<td id="leftcell" style="color:#0000ff; font-size:12px;"> <a style="color:#0000ff;" href="$trailerlink" target="youtube">$moviename</a></td>
<td id="leftcell" style="font-size:12px;">$releasedate</td>
</tr>
<p>
HEREP;
}
 
// end foreach
 
print <<<CODE
 </p>
<p>//print the bottom of the table
print "</table>
<p> \n";</p>
<p><!-- Trailer links rendering end }}}-->
</p>
CODE;
?>
Angiec is offline   Reply With Quote
Old 12-27-2012, 04:31 PM   PM User | #7
Angiec
New Coder

 
Join Date: Apr 2012
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Angiec is an unknown quantity at this point
Code:
<td id="leftcell" style="color:#0000ff; font-size:12px;"> <a style="color:#0000ff;" href="$trailerlink" rel=
"shadowbox">$moviename</a></td>
The above code is now causing the shadowbox text to show up on the live site, see here: http://dstone1029.net/box-office-analyst-dev/. Does anyone know how to fix it so it doesn't show up? All help is soooo appreciated! I'm near the end of a issue that's been plaguing me for days.
Angiec is offline   Reply With Quote
Old 12-27-2012, 04:31 PM   PM User | #8
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Just the comments that were wrongly left in the HTML code. HTML outputs them like normal HTML.

If the above worked, the below should do it. Although I think that at one time it will become unstable because of hanging <p> and such. Try and redo it carefully.

PHP Code:
<p>
    &nbsp;
</p>
<p><!-- Import and render trailer links {{{-->
    <?php
print <<< HERE
<table width="100%" class="table1">
<tr>
<th id="mythead" style="text-align:left; font-size:12px;">Film Title </th>
<th id="mythead" style="text-align:left; font-size:12px;">Release Date</th>
</tr>
<p>
</p>
<p>
HERE;
$data file("http://dstone1029.net/textuploads/trailers.txt");
foreach (
$data as $line){
  
$lineArray explode("|"$line);
print <<<CODE
</p>
<p> 
CODE;
list(
$moviename$releasedate$trailerlink) = $lineArray;

print <<<HEREP
<tr>
<td id="leftcell" style="color:#0000ff; font-size:12px;"> <a style="color:#0000ff;" href="$trailerlink" target="youtube">$moviename</a></td>
<td id="leftcell" style="font-size:12px;">$releasedate</td>
</tr>
<p>
HEREP;
}
 
// end foreach
 
print <<<CODE
 </p>
<p>
</table>
<p> \n</p>
<p><!-- Trailer links rendering end }}}-->
</p>
CODE;
?>
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 12-27-2012, 04:36 PM   PM User | #9
Angiec
New Coder

 
Join Date: Apr 2012
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Angiec is an unknown quantity at this point
You're a genius and I feel like an idiot... got excited and hit the enter key. Thanks for all your work!
Angiec is offline   Reply With Quote
Old 12-27-2012, 04:37 PM   PM User | #10
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
The <a> tag is being closed prematurely. Here's the generated HTML.

PHP Code:
<td id="leftcell" style="color:#0000ff; font-size:12px;"
<
a style="color:#0000ff;" href="http://www.youtube.com/embed/8Ltpa4QmnuU" rel=<br />
"shadowbox">Looper</a>
</
td
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 12-27-2012, 05:42 PM   PM User | #11
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Angiec View Post
Thanks for the replies... I'm aware it's hideous. I didn't write it, but was asked to work with it.
Please don't take this the wrong way but should you be working with it if you're unable to spot basic syntax errors? If I were in your position I'd be asking someone else to deal with it.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 12-27-2012, 05:47 PM   PM User | #12
Angiec
New Coder

 
Join Date: Apr 2012
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Angiec is an unknown quantity at this point
Thanks, TangoForce. I agree with you. I was only called in to add a WP plugin that would enable the links to open in a new window. I am not the PHP person, but was trying to get it to show up on the page, so I could enable the plugin.
Angiec is offline   Reply With Quote
Old 12-27-2012, 05:50 PM   PM User | #13
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Angiec View Post
Thanks for the replies... I'm aware it's hideous. I didn't write it, but was asked to work with it. Here's the includes/runtime.php:

Code:
<?php

require_once(dirname(__FILE__).'/cache.php');
require_once(dirname(__FILE__).'/const.php');
That can't be right. You'd basically have a file path like this:
runtime.php/cache.php
runtime.php/const.php

Edit:
As FouLu has pointed out, I am infact wrong here (forgot that dirname() function was being used).
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.

Last edited by tangoforce; 12-27-2012 at 06:18 PM..
tangoforce is offline   Reply With Quote
Old 12-27-2012, 05:51 PM   PM User | #14
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Angiec View Post
Thanks, TangoForce. I agree with you. I was only called in to add a WP plugin that would enable the links to open in a new window. I am not the PHP person, but was trying to get it to show up on the page, so I could enable the plugin.
If you want my honest opinion, the code is full of so many bodges that you'd be better off getting the original coder to sort it out before it comes back to you for the WP plugin business.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 12-27-2012, 06:06 PM   PM User | #15
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by tangoforce View Post
That can't be right. You'd basically have a file path like this:
runtime.php/cache.php
runtime.php/const.php
No, that's okay, its pulling the directory off of the __FILE__. If you have a newer version of PHP, its better to just use the __DIR__ magic constant instead of the dirname(__FILE__), but __DIR__ is new as of. . . 5.3 I think it was.

Quote:
Originally Posted by tangoforce View Post
If you want my honest opinion, the code is full of so many bodges that you'd be better off getting the original coder to sort it out before it comes back to you for the WP plugin business.
Agreed. If you didn't author it, its so full of syntactical errors that it would never have run properly (unless. . . it uses some type of custom parsing, which it doesn't given what I see in the other blocks). I pull :shiftyeyes: when I see it's eval'ing the code; no wonder the wp is so slow
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:38 AM.


Advertisement
Log in to turn off these ads.