Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php code works on 2 out of 3 servers
Old 05-02-2008, 12:54 PM php code works on 2 out of 3 servers
Average Talker

Posts: 29
Name: Luke
Trades: 0
I am getting a parse error :

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' on line 5

This is running on a server with php 4.4.8

This file (and the rest of the site) has previously worked on my local machine with php 5.2.5 and is currently working live on another server with php 4.4.7

Thanks in advance!

Here is the code:
Code:
<?php
include('nubedo.class.php');
class page extends nubedo {
 public $slug;
 public $db;
 public $checkGallery;
 
 function __construct($noview=false) {
  parent::__construct();
  $this->getPageData();
  
  if (!$noview) { 
   $this->slug = $this->getSlug();
   if ($this->slug) {
    $this->view();
   }
  }else{
   $this->list = $this->listAllPages();
  }
  
  $this->checkGallery = false;
 }
  
 function getSlug() { 
  
  $url = $_SERVER['REQUEST_URI'];
  if (INSTALL_URI != '/')
   $url = str_replace(INSTALL_URI,'',$url);
   
  if ($url == '/') {
   return 'index';
  }
  
  if (strrpos($url,'/') == strlen($url) -1) { // kill trailing slash
   $url = substr($url,0,strlen($url)-1);
   header("HTTP/1.0 301 Moved Permanently"); // redirect to new location
   header("Status: 301 Moved Permanently");
   header("Location: ".parsePath($url,1));
  }
  
  $query = str_replace(array('.html','.php','.htm','../','.'),'',$url);
  $query = trim($query,'/');
  
  $query = strpos($query,'/') !== false ? explode('/',$query) : array($query);
  
  $query = array_reverse($query);
  if (strlen($query)>0) {
   return $query[0];
  }else{
   return 'index';
  }
  
 }
 
 function view() {
  if (!$this->slug) header("Location: ".parsePath('',1));
  
  if (!$this->checkGallery) {
   $query = "SELECT
     p.id, p.parent, p.title, p.body, p.excerpt, p.seoTitle, p.seoBody, p.seoKeyword, p.slug,
     pp.slug AS parentSlug, p.template, pp.parent AS pParent, p.flash FROM pages p
    LEFT JOIN pages pp ON pp.id = p.parent
    WHERE p.slug = '".$this->slug."' AND p.trash = 0 LIMIT 1";
  
  }else{
   
   $query = "SELECT
     p.id, p.parent, p.title, p.body, p.seoTitle, p.seoBody, p.seoKeyword, p.slug,
     pp.slug AS parentSlug, pp.parent AS pParent FROM gallery p
    LEFT JOIN pages pp ON pp.id = p.parent
    WHERE p.slug = '".$this->slug."' AND p.trash = 0 LIMIT 1";
   
  }
  
  if (!$result = $this->db->query($query)) die('Error grabbing page data: '.$this->db->error);
  
  if ($result->num_rows > 0) {
   $row = $result->fetch_assoc();
   $this->data = $row;
    $this->data['body'] = $this->setContent($row['body']);
    $this->pageTitle = $row['seoTitle'] ? $row['seoTitle'] : $row['title'];
   
   if ($this->checkGallery) {    
    $this->gallery = true;
    $query = 'SELECT id, type, ext, title, body FROM galleryImages WHERE galleryID = '.$this->data['id'].' ORDER BY sort ASC';
    
    if (!$ir = $this->db->query($query)) die('Error grabbing image data: '.$this->db->error);
    
    while($image = $ir->fetch_assoc()) {
     $this->images[] = $image;
    }
    
   }
   
  }else{
   if ($this->slug != 'contact') {
    if (file_exists($this->slug.'.php')) {
     include($this->slug.'.php');
     exit;
    }
    if ($this->checkGallery != true) {
     $this->checkGallery = true;
    
     $this->view();
    }elseif ($this->slug != 'error404') {
     $this->error404();
     $this->view();
    }else{
     die('<h1>Page Not Found</h1><p>The page you requested was not found.</p>');
    }
   }
  }
 }
 
 function setContent($content) {
  if (strpos($content,'{--nubedo--}') !== false) {
   return explode('{--nubedo--}',$content);
  }else{
   return array($content);
  }
 }
 
 function getChildren($level=0,$current=0,$title=true) {
  if ($this->pageList[$level]) {
   if ($title)
    $thePages = '<h3>'.htmlspecialchars($this->pageListFlat[$level]['title']).'</h3>';
    
   $thePages .= "\n<ul class=\"pagelist\">\n";
   foreach($this->pageList[$level] AS $key => $page) {
    $page['slug'] = $this->pageListFlat[$level] && $level != 0 ? $this->pageListFlat[$level]['slug'].'/'.$page['slug'] : $page['slug'];
    $title = $page['seoTitle'] ? $page['seoTitle'] : $page['title'];
    $thePages .= "\n<li";
    $thePages .= $page['id'] == $current ? ' class="currenta">'.htmlspecialchars($title) : '><a href="/'.$page['slug'].'" title="'.htmlspecialchars($title).'">'.htmlspecialchars($page['title']).'</a>';
    $thePages .= "</li>\n";
   }
   $thePages .= "</ul>\n";
   
   return $thePages;
  }else{
   if ($this->pageListFlat[$level]['parent'] != 0)
   return $this->getChildren($this->pageListFlat[$level]['parent'],$level);
  }
 }
 
 function listAllPages($level=0) {
  if ($this->pageList[$level]) {
   
  $thePages .= "\n<ul class=\"pagelist\">\n";
  foreach($this->pageList[$level] AS $key => $page) {
   if ($page['slug'] != 'error404') {
   $page['slug'] = $this->pageListFlat[$level] && $level != 0 ? $this->pageListFlat[$level]['slug'].'/'.$page['slug'] : $page['slug'];
   $title = $page['seoTitle'] ? $page['seoTitle'] : $page['title'];
   $thePages .= "\n<li";
   $thePages .= $page['id'] == $current ? ' class="currenta">'.htmlspecialchars($title) : '><a href="/'.$page['slug'].'" title="'.htmlspecialchars($title).'">'.htmlspecialchars($page['title']).'</a>';
   $thePages .= $this->listAllPages($page['id']);
   $thePages .= "</li>\n";
   }
  }
  $thePages .= "</ul>\n";
  
  return $thePages;
  }
 }
 
 function getSection($id) {
  while ($this->pageListFlat[$id]['parent'] != 0) {
   $id = $this->pageListFlat[$id]['parent'];
  }
  return $this->pageListFlat[$id]['slug'];
 }
 /**
  * Get page information, stores in $pageList & $pageListFlat
  *
  * @return nothing - sets $this->pageList , $this->pageListFlat
  * @access public
  **/
 function getPageData() {
  try {
   $query = "SELECT p.id,p.parent,p.title,p.slug,p.seoTitle,p.excerpt FROM pages AS p
   WHERE trash = 0 AND status = 'public' ORDER BY sort ASC";
   if (!$result = $this->db->query($query)) throw new Exception('Could not get user credits.<br>'.$this->db->error);
   if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
     $this->pageList[$row['parent']][] = $row;
     $this->pageListFlat[$row['id']] = $row;
    }
   }
   $query = "SELECT CONCAT('g',p.id) AS id,p.parent,p.title,p.slug,p.seoTitle FROM gallery AS p
   WHERE trash = 0 AND status = 'public' ORDER BY sort ASC";
   if (!$result = $this->db->query($query)) throw new Exception('Could not get user credits.<br>'.$this->db->error);
   if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
     $this->pageList[$row['parent']][] = $row;
     $this->pageListFlat['g'.$row['id']] = $row;
    }
   }
  } catch(Exception $e) {
   catchError($e);
  }
 }
}
__________________
Luke Robinson

Please login or register to view this content. Registration is FREE

Last edited by lrobinson; 05-02-2008 at 12:56 PM.. Reason: code missing line breaks
lrobinson is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-02-2008, 02:08 PM Re: php code works on 2 out of 3 servers
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
I might be mistaken, but I think that function format is specific to PHP 5. In PHP 4, constructors are handled by mirroring the name of the class.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-02-2008, 02:54 PM Re: php code works on 2 out of 3 servers
Plugin-Developer's Avatar
Weightlifting CS Student

Posts: 504
Name: Nick Ohrn
Trades: 0
VirtuosiMedia is correct. In PHP4 you have to use ClassName as the constructor rather than the __construct magic method. Also, the access modifiers like public, protected, and private aren't supported in PHP4, I believe. If you want this code to run on a PHP4 server, you'll have to use var declarations rather than public or private.
__________________

Please login or register to view this content. Registration is FREE
- Custom plugin development to fit your needs. Plugins available for WordPress and Drupal, among others.
Plugin-Developer is offline
Reply With Quote
View Public Profile Visit Plugin-Developer's homepage!
 
Old 05-02-2008, 03:31 PM Re: php code works on 2 out of 3 servers
Average Talker

Posts: 29
Name: Luke
Trades: 0
Thanks for the input--it seems I was misled. The server where the site is currently hosted has php 4 and 5, but on cpanel it says 4. So now it all makes sense.

Thanks!
__________________
Luke Robinson

Please login or register to view this content. Registration is FREE
lrobinson is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php code works on 2 out of 3 servers
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20322 seconds with 12 queries