PHP HTTP 500 Error [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I decompined this script of ioncube. The encripted script runs totally fine. But when I run the decrypt script the page gives me 500 Http error. The decrypt script is this:
<?php
/
$_X=base64_decode($_X);$_X=strtr($_X,'123456aouie','aouie123456');$_R=ereg_replace('__FILE__',"'".$_F."'",$_X);eval($_R);$_R=0;$_X=0;
?>
<?php
/
?><?php
#author: A S M Abdur Rab [shibly], shibly#divine-it.net
#abstract: Class for authentication.
#abstract: Helpful methods to make the session/cookies handling, login, logout,
timedout, admin/user authentication, redirection and other authentication
related process safe.
PHP versions 4 and 5
#name: Authentication Class.
#category: Class.
#uses:
#version:
#package: divin_framework
#subpackage: divin_framework.libs
/
class AuthComponent extends Component
{
set allowable IP addresses here/
var $allowedIpAddresses = array('127.0.0.1','192.210.144.165',
'::1');
var $productId = '1001';
var $model = '';
var $condition = '';
var $secretSalt = 'dddonteeeventtthinkaaaboutiiit';
var $msgLogout = 'Logout Successfully.';
var $msgLoggedIn = 'Already logged in.';
var $msgNotLoggedIn = 'You are not logged in.';
var $msgInvalidUser = 'Username and/or Password invalid.';
var $msgTooManyAttempts = 'You have exceeded maximum login attempt limit.';
var $loginPage = 'Login';
var $afterLogoutPage = 'Login';
var $logoutPage = 'Logout';
var $homePage = 'index';
var $site = 'DivineIT';
var $fields = array('login', 'password');
var $timeOffset = 180;
var $loginRequired = false;
var $loginController = null;
var $_authSession = null;
var $_authModel = null;
var $_sessionName = null;
var $sessionId = null;
function __construct()
{
global $AUTH;
if(isset($AUTH))
{
$this->loginRequired = true;
foreach($AUTH as $key => $value)
$this->{$key} = $value;
}
if(!empty($this->model))
{
$this->_sessionName = $this->site . '.' . $this->model;
$this->_authSession = &App::loadModel('AuthSession');
$this->_authModel = &App::loadModel($this->model);
}
}
function startup(&$controller)
{
$permitted = false;
foreach($this->allowedIpAddresses as $ipAddress)
{
if($_SERVER['SERVER_ADDR']===$ipAddress)
{
$permitted = true;
break;
}
}
if(!$permitted)
{
header('Location: forbidden.php');
return;
}
if(defined('PREFIX'))
$prefix = PREFIX;
else
$prefix = '';
if($this->_authModel === null || $this->_authSession === null)
{
if($this->loginRequired === true)
{
$controller->redirect($this->loginController, $this->loginPage);
}
return;
}
$count = count($this->fields);
if($prefix.$this->loginPage == Router::$action && isset($controller->data[$this->model]) && (count($controller->data[$this->model]) == $count))
{
max login attempts#start/
$tryInfo = null;
$tryInfo = $this->Session->get('login_attempts');
if(!is_null($tryInfo))
{
$firstImpression = $tryInfo['first_impression'];
$loginAttempts = $tryInfo['login_attempts'];
$lastImpression = strtotime($tryInfo['last_impression']);
$currentTime = strtotime(currentTime());
if(($currentTime - $lastImpression)>$this->loginLockDuration60)
{
$loginAttempts = 1;
}
if(($loginAttempts>$this->maxLoginAttempts)&&($currentTime - $lastImpression)<$this->loginLockDuration60)
{
$controller->setFlash($this->msgTooManyAttempts);
$controller->redirect($this->loginController, $this->loginPage);
return;
}
else
{
$loginAttempts++;
$tryInfo['login_attempts'] = $loginAttempts;
$tryInfo['last_impression']= currentTime();
$this->Session->set('login_attempts', $tryInfo);
}
}
else
{
$tryInfo['login_attempts'] = 1;
$tryInfo['first_impression'] = currentTime();
$tryInfo['last_impression'] = currentTime();
$this->Session->set('login_attempts', $tryInfo);
}
max login attempts#start/
$this->loggedIn = $this->__login($controller->data[$this->model], $this->condition);
if($this->loggedIn)
{
$requestedPage = $this->Session->get('requested_url');
if(!is_null($requestedPage)&&(count($requestedPage)>0))
{
$requestedController = Inflector::underscore($requestedPage['controller']);
$requestedAction = Inflector::underscore($requestedPage['action']);
$requestedParams = $requestedPage['params'];
$requestedMoreAttrs = $requestedPage['more'];
$requestedScript = $requestedPage['script'];
$this->Session->remove('requested_url');
//$controller->redirect($requestedController, $requestedAction,$requestedParams, $requestedMoreAttrs);
$link = $requestedScript . '?action=' . $requestedController . '-' .
$requestedAction . (!empty($requestedParams) ? ('-'.implode('-', $requestedParams)) : '');
if(!empty($requestedMoreAttrs))
{
foreach($requestedMoreAttrs as $key=>$value)
{
$link .= '&'.$key.'='.$value;
}
}
header('location: ' . $link);
}
else
{
$controller->redirect($this->loginController, $this->homePage);
}
return;
}
else
{
$controller->setFlash($this->msgInvalidUser);
$controller->redirect($this->loginController, $this->loginPage);
}
}
else
{
if(Router::$action != $prefix.$this->loginPage)
{
if(Router::$action === $prefix.$this->logoutPage)
{
$this->__logout();
$controller->setFlash($this->msgLogout);
$controller->redirect($this->loginController, $this->afterLogoutPage);
}
else if($this->__checkValidSession() === false)
{
$requestedPage = $this->Session->get('requested_url');
$requestedPage['controller'] = Router::$controller;
$requestedPage['action'] = Router::$originalAction;
$requestedPage['params'] = Router::$params;
$requestedPage['more'] = Router::$more;
$requestedPage['script'] = Router::$script;
$this->Session->set('requested_url', $requestedPage);
$controller->setFlash($this->msgNotLoggedIn);
$controller->redirect($this->loginController, $this->loginPage);
}
else
{
$this->loggedIn = true;
}
}
}
}
function __login($values, $condition)
{
if(method_exists($this->model, 'authenticate'))
{
$userData = $this->_authModel->authenticate($values, $condition);
}
else
{
foreach($this->fields as $field)
{
if($field === 'password')
{
if($this->encryptPassword)
{
$value = &Database::escape($this->password($values[$field]));
}
else
{
$value = &Database::escape($values[$field]);
}
}
else
{
$value = &Database::escape($values[$field]);
}
$condition .= (empty($condition)?'':' AND ') . '`' . $this->model . '`.' .'`'.$field.'` COLLATE latin1_bin = \''.$value."'";
}
$userData = $this->_authModel->find($condition);
}
if($userData != null)
{
/ TODO: if disable /
// $this->Session->regenerate();
$userSessionId = $this->Session->sessionId();
$this->Session->set( $this->_sessionName, $userSessionId );
$userSessionId = sha1($this->_sessionName . $userSessionId . $this->secretSalt);
$userSessionData = array('AuthSession' =>
array('session_id' => $userSessionId,
'login_time' => currentTime(),
'last_impression' => currentTime(),
'ip' => $_SERVER['REMOTE_ADDR'],
'user_id'=> $userData[$this->model][$this->_authModel->primaryKey],
'model'=> $this->model,
'user_data'=>serialize($userData)
)
);
if($this->_authSession->save($userSessionData, false) === true)
{
$this->userData = &$userData;
$this->sessionId = $userSessionId;
$this->Session->remove('login_attempts');
return true;
}
}
return false;
}
function __logout()
{
Remove from session table.
/
$sessionId = sha1($this->_sessionName . $this->Session->get($this->_sessionName) . $this->secretSalt);
$condition = '`session_id` = \'' . $sessionId . '\' AND `model` = \''.$this->model.'\'';
//$condition.= ' AND `ip`=\'' . $_SERVER['REMOTE_ADDR'] .'\'';
$this->_authSession->delete($condition);
Remove all invalid/expired sessions.
/
$sessionDuration = $this->timeOffset 60;
$inactivityInterval = $this->inactivityInterval 60;
$condition = '(UNIX_TIMESTAMP(\'' . currentTime() . '\') - UNIX_TIMESTAMP(last_impression)) > ' . $inactivityInterval;
$this->_authSession->delete($condition);
$condition = '';
$this->Session->destroySession();
}
function __checkValidSession()
{
$sessionId = sha1($this->_sessionName . $this->Session->get($this->_sessionName) . $this->secretSalt);
// check if session available
$sessionDuration = $this->timeOffset 60;
$inactivityInterval = $this->inactivityInterval 60;
$condition = '(UNIX_TIMESTAMP(\'' . currentTime() . '\') - UNIX_TIMESTAMP(last_impression)) > ' . $inactivityInterval;
$this->_authSession->delete($condition);
$condition = '';
$condition = "session_id = '" . $sessionId . "' AND `model`= '{$this->model}'";
//$condition .= ' AND ip=\'' . $_SERVER['REMOTE_ADDR'] . '\'';
$checkValidSession = $this->_authSession->find($condition);
if(count($checkValidSession) === 1)
{
// check if session expired
$timeOut = strtotime($checkValidSession['AuthSession']['login_time']) + $sessionDuration;
$currentTime = strtotime(currentTime());
if($timeOut > $currentTime)
{
// find logged in user
if(method_exists($this->_authModel, 'checkSession'))
{
$userData = &$this->_authModel->checkSession(unserialize($checkValidSession['AuthSession']['user_data']));
}
else
{
$conditions = $this->model . '.' . $this->_authModel->primaryKey.'=' . $checkValidSession['AuthSession']['user_id'];
$userData = & $this->_authModel->find($conditions);
}
if($userData != null)
{
/ TODO: if disable /
$sessionId = sha1($this->_sessionName . $this->Session->get($this->_sessionName) . $this->secretSalt);
$condition = '`session_id` = \'' . $sessionId . '\' AND `model` = \''.$this->model.'\'';
//$condition.= ' AND `ip`=\'' . $_SERVER['REMOTE_ADDR']. '\'';
$data = array();
$data['AuthSession']['last_impression'] = currentTime();
$this->_authSession->update($data, '', $condition);
$this->userData = & $userData;
return true;
}
}
}
$this->_authSession->delete($condition);
$this->Session->destroySession();
return false;
}
function password($password)
{
return sha1($password);
}
function user($field)
{
if(isset($this->userData[$this->model][$field]))
return $this->userData[$this->model][$field];
return null;
}
}
?>
?>
What's wrong in this script that is giving me 500 error?

There are Multiple Errors in the code. Here is the List!
Syntax Error : MultiLine Comments
Line 8 : Unexpected "/" # it Should be /* or */
Line 20: Unexpected "/" # It should be /* or */
Lines 24-39 : You forgot to start the MultiLine Comment!
Line 43 : Again you forgot to Start single Line Comment!
Line 122 : Again you forgot to start and end Single Line comment!
Line 159 : Don't know if you forgot to start comment or bad code!
Line 261 : Again forgot to start and end the comment!
Line 290 and 297 : Forgot to start and end the comment!
Line 291 and 298 : Syntax error! Looks like you wanted to start comment!
Line 339 : Syntax Error In MultiLine Comment! I am tired of writing again! :v
These are just Comment Errors!
There are multiple Variable Definition errors too! There are other Multiple errors! Check the full code once!

Related

Object of type mysqli_result error in old vBulletin product

I am trying to update an old vBulletin product and it keeps throwing an error for me.
Cannot use object of type mysqli_result as array in C:\wamp\www\mem_payment.php on line 124
Line 124:
$vbma->setCustomerNumber(unserialize($purchase['info']), $product['pur_group'], false, $userinfo);
Line 102 - 130
$purchase = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX .
"ma_purchases WHERE id = '" . $id . "'");
$order = unserialize($purchase['order']);
if ($order[0] !== $vbulletin->GPC['business'])
{
$status_code = '503 Service Unavailable';
// Paypal likes to get told its message has been received
if (SAPI_NAME == 'cgi' or SAPI_NAME == 'cgi-fcgi')
{
header('Status: ' . $status_code);
}
else
{
header('HTTP/1.1 ' . $status_code);
}
}
unset($order[0]);
if ($purchase and !in_array($order[1], array('renew', 'upgrade')))
{
$product = $vbulletin->db->query_read("SELECT pur_group FROM " . TABLE_PREFIX .
"ma_products WHERE id = '" . $order[1] . "'");
$userinfo = fetch_userinfo($purchase['userid']);
$vbma->setCustomerNumber(unserialize($purchase['info']), $product['pur_group'], false,
$userinfo);
$rand = rand($vbulletin->options['memarea_numstart'], $vbulletin->options['memarea_numend']);
$licnum = substr(md5($prodid . rand(0, 20000) . $rand . $rand), 0, rand(10, $vbulletin->
options['memarea_custnumleng']));
$licensedm = datamanager_init('License', $vbulletin, ERRTYPE_ARRAY);
$licensedm->setr('userid', $userinfo['userid']);
I have been reading numerous questions regarding this error stating to essentially:
define your query
query your query
then associate the query
IE:
$query = "SELECT 1";
$result = $mysqli->query($query);
$followingdata = $result->fetch_assoc()
Almost all of the answers are along those lines, although I am failing to see where this needs to be done.
I'm not sure if it has anything to do with the function, but I will add that as well:
function setCustomerNumber($ma_info, $usergroup = '', $usevb = true, $userinfo = '')
{
if ($usevb == false)
{
$this->vbulletin->userinfo = &$userinfo;
}
$fcust = $this->fields['custnum'];
$fpass = $this->fields['mpassword'];
$finfo = $this->fields['info'];
$userdm = datamanager_init('User', $this->vbulletin, ERRTYPE_ARRAY);
$userinfo = fetch_userinfo($this->vbulletin->userinfo['userid']);
$userdm->set_existing($userinfo);
if (!$this->vbulletin->userinfo["$fcust"] and !$this->vbulletin->userinfo["$fpass"])
{
$rand = rand($this->vbulletin->options['memarea_numstart'], $this->vbulletin->
options['memarea_numend']);
$num = $this->vbulletin->options['custnum_prefix'] . substr(md5($rand), 0, $this->
vbulletin->options['memarea_custnumleng'] - strlen($this->vbulletin->options['custnum_prefix']));
$userdm->set($fcust, $num);
$pass = substr(md5(time() . $num . $rand . rand(0, 2000)), 0, $this->vbulletin->
options['memarea_custnumleng']);
$userdm->set($fpass, $pass);
$this->sendCustomerInfo($this->vbulletin->userinfo['userid'], $this->vbulletin->
userinfo['username'], $this->vbulletin->userinfo['email'], $num, $pass);
}
if ($usergroup or $usergroup !== '' or $usergroup !== '0')
{
if ($usergroup != $this->vbulletin->userinfo['usergroupid'])
{
$ma_info['oldgroup'] = $this->vbulletin->userinfo['usergroupid'];
$userdm->set('usergroupid', $usergroup);
}
}
if ($ma_info)
{
$ma_info = serialize($ma_info);
$userdm->set($finfo, $ma_info);
}
$userdm->pre_save();
if (count($userdm->errors) == 0)
{
$userdm->save();
return true;
}
else
{
var_dump($userdm->errors);
return false;
}
}
Why am I getting this error? In your answer could you please explain to me what needs to be changed.
query_read returns mysqli_result&, you need convert it to an array first.
$query_result = $vbulletin->db->query_read(...);
$product = $query_result->fetch_assoc();

Joomla 3.3 Cart not emptying after purchase when sef enabled, can someone check my router file please?

I'm having a problem with my Joomla 3 mijoshop cart not emptying after purchases when SEF is enabled, if I turn SEF off then it works fine. After some searching around I believe it could be a problem with the carts router.php file, so I was wondering if anyone could help me out with this. I have pasted my current router.php files code below.
defined('_JEXEC') or die ('Restricted access');
require_once(JPATH_ROOT . '/components/com_mijoshop/mijoshop/mijoshop.php');
if (!class_exists('MiwisoftComponentRouterBase')) {
if (class_exists('JComponentRouterBase')) {
abstract class MiwisoftComponentRouterBase extends JComponentRouterBase {}
}
else {
class MiwisoftComponentRouterBase {}
}
}
class MijoShopRouter extends MiwisoftComponentRouterBase
{
static $cats = array();
static $path = array();
public function build(&$query) {
return $this->buildRoute($query);
}
public function parse(&$segments) {
return $this->parseRoute($segments);
}
public function buildRoute(&$query)
{
$Itemid = null;
$segments = array();
$menu = $this->getMenu();
$_get_itemid = 0;
if($menu->getActive()){
$_get_itemid = $menu->getActive()->id;
}
$_get_route = JRequest::getVar('route', '');
if( isset($query['Itemid']) and $_get_itemid != $query['Itemid'] and $_get_route == 'product/category' and isset($query['route']) and $query['route'] == 'product/product' ){
$query['Itemid'] = $_get_itemid;
}
if (!empty($query['Itemid'])) {
$Itemid = $query['Itemid'];
} else {
$Itemid = $this->getItemid();
}
if (empty($Itemid)) {
$a_menu = $menu->getActive();
} else {
$a_menu = $menu->getItem($Itemid);
}
if (isset($query['view'])) {
if ($query['view'] == 'admin') {
unset($query['view']);
return $segments;
}
$_route = $this->getRoute($query['view'], false);
if (!empty($_route)) {
$query['route'] = $_route;
unset($query['view']);
}
else {
$segments[] = $query['view'];
unset($query['view']);
}
}
if (isset($query['route'])) {
switch ($query['route']) {
case 'product/product':
if (is_object($a_menu) and $a_menu->query['view'] == 'product' and $a_menu->query['product_id'] == #$query['product_id']) {
unset($query['path']);
unset($query['product_id']);
unset($query['manufacturer_id']);
break;
}
$segments[] = 'product';
if (isset($query['product_id'])) {
$id = $query['product_id'];
$name = MijoShop::get('db')->getRecordAlias($id);
if (!empty($name)) {
$segments[] = $id . ':' . $name;
} else {
$segments[] = $id;
}
unset($query['path']);
unset($query['product_id']);
unset($query['manufacturer_id']);
unset($query['sort']);
unset($query['order']);
unset($query['filter_name']);
unset($query['filter_tag']);
unset($query['limit']);
unset($query['page']);
}
break;
case 'product/category':
$_path = explode('_', #$query['path']);
$m_id = end($_path);
if (is_object($a_menu) and $a_menu->query['view'] == 'category' and $a_menu->query['path'] == $m_id) {
unset($query['path']);
break;
}
$segments[] = 'category';
if (isset($query['path'])) {
$id = $query['path'];
if (strpos($id, '_')) {
$old_id = $id;
$_id = explode('_', $id);
$id = end($_id);
self::$cats[$id] = $old_id;
} else {
self::$cats[$id] = $id;
}
$name = MijoShop::get('db')->getRecordAlias($id, 'category');
if (!empty($name)) {
$segments[] = $id . ':' . $name;
} else {
$segments[] = $id;
}
unset($query['path']);
}
break;
case 'product/manufacturer/info':
if (is_object($a_menu) and $a_menu->query['view'] == 'manufacturer' and $a_menu->query['manufacturer_id'] == #$query['manufacturer_id']) {
unset($query['manufacturer_id']);
break;
}
$segments[] = 'manufacturer';
if (isset($query['manufacturer_id'])) {
$id = $query['manufacturer_id'];
$name = MijoShop::get('db')->getRecordAlias($id, 'manufacturer');
if (!empty($name)) {
$segments[] = $id . ':' . $name;
} else {
$segments[] = $id;
}
unset($query['manufacturer_id']);
}
break;
case 'information/information':
if (is_object($a_menu) and $a_menu->query['view'] == 'information' and $a_menu->query['information_id'] == #$query['information_id']) {
unset($query['information_id']);
break;
}
$segments[] = 'information';
if (isset($query['information_id'])) {
$id = $query['information_id'];
$name = MijoShop::get('db')->getRecordAlias($id, 'information');
if (!empty($name)) {
$segments[] = $id . ':' . $name;
} else {
$segments[] = $id;
}
unset($query['information_id']);
}
Thanks in advance to anyone that can help :)
The problem has nothing to do with your router.php file, it has to do with the checkout process since those cart items are actually stored in the database.
When you add items to your cart, they are added to a table in the database, once you checkout, your items are usually added to an order_item table, and order table is populated with your order information, and the cart is emptied.
I would check the controller/model files to see where the checkout code is - the bug is definitely there.

Previous/next button in PHP

I´m pretty much entirely new to PHP, so please bear with me.
I´m trying to build a website running on a cms called Core. I'm trying to make it so that the previous/next buttons cycle through tags rather than entries. Tags are stored in a database as core_tags. Each tag has it own tag_id, which is a number. I've tried changing the excisting code for thep previous/next buttons, but it keeps giving me 'Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/core/functions/get_entry.php on line 50'.'
Any help would be greatly appreciated.
Get_entry.php:
<?php
$b = $_SERVER['REQUEST_URI'];
if($entry) {
$b = substr($b,0,strrpos($b,"/")) . "/core/";
$id = $entry;
$isPerma = true;
} else {
$b = substr($b,0,mb_strrpos($b,"/core/")+6);
$id = $_REQUEST["id"];
}
$root = $_SERVER['DOCUMENT_ROOT'] . $b;
$http = "http://" . $_SERVER['HTTP_HOST'] . substr($b,0,strlen($b)-5);
require_once($root . "user/configuration.php");
require_once($root . "themes/".$theme."/configuration.php");
require_once($root . "functions/session.php");
if(is_numeric($id)) {
$type = "entry";
} else {
$type = "page";
}
$id = secure($id);
if($type == "page") {
$data = mysql_query("SELECT p.* FROM core_pages p WHERE p.page_title = \"$id\"");
$page_clicks = 0;
while($p = mysql_fetch_array($data)) {
$url = $p["page_url"];
$path = $root . "user/pages/" . $url;
$page_clicks = $p['hits']+1;
require($path);
}
mysql_query("UPDATE core_pages p SET
p.hits = $page_clicks
WHERE p.page_title = $id");
}
if($type == "entry") {
// queries the dbase
$data_tags = mysql_query("SELECT entry_id,entry_title FROM core_entries WHERE entry_show = 1 ORDER BY entry_position DESC") or die(mysql_error());
$navArr=array();
while($tmparray = mysql_fetch_array($data_entries,MYSQL_ASSOC)){
array_push($navArr,$tmparray['entry_id']);
}
function array_next_previous($array, $value) {
$index = array_search($value,$array);
//if user clicked to view the very first entry
if($value == reset($array)){
$return['prev'] = end($array);
$return['next'] = $array[$index + 1];
//if user clicked to view the very last entry
}else if($value == end($array)){
$return['prev'] = $array[$index - 1];
reset($array);
$return['next'] = current($array);
}else{
$return['next'] = $array[$index + 1];
$return['prev'] = $array[$index - 1];
}
return $return;
}
$data = mysql_query("SELECT e.* FROM core_entries e WHERE e.entry_id = $id AND e.entry_show = 1");
$entry_clicks = 0;
if(#mysql_num_rows($data) < 1) {
die("Invalid id, no entry to be shown");
}
while($e = mysql_fetch_array($data)) {
$nextPrevProject = array_next_previous($navArr,$id);
$entry_id = $e['entry_id'];
$entry_title = $e['entry_title'];
// DATE
$t = $e["entry_date"];
$y = substr($t,0,4);
$m = substr($t,5,2);
$d = substr($t,8,2);
$entry_date = date($date_format,mktime(0,0,0,$m,$d,$y));
$entry_text = $e['entry_text'];
$entry_extra1 = $e['entry_extra1'];
$entry_extra2 = $e['entry_extra2'];
$entry_client = $e['entry_client'];
$entry_position = $e['entry_position'];
$entry_hits = $e['hits']+1;
$entry_new = $e['entry_new'];
if($entry_new == 1) {
$isNew = true;
} else {
$isNew = false;
}
if($nice_permalinks) {
$entry_perma = "$http".$entry_id;
} else {
$entry_perma = "$http"."?entry=$entry_id";
}
$data_e2t = #mysql_query("SELECT e2t.tag_id FROM core_entry2tag e2t WHERE e2t.entry_id = $entry_id");
$tag_str = "";
while($e2t = #mysql_fetch_array($data_e2t)) {
$tag_id = $e2t["tag_id"];
$data_tags = #mysql_query("SELECT t.tag_text FROM core_tags t WHERE t.tag_id = $tag_id");
while($t = #mysql_fetch_array($data_tags)) {
$tag_text = $t["tag_text"];
$tag_str = $tag_str . "<a class=\"tag-link\" name=\"tag".$tag_id."\" href=\"#tag-"._encode($tag_text)."\">".$tag_text."</a>".$separator_tags;
}
}
$entry_tags = substr($tag_str,0,strlen($tag_str)-strlen($separator_tags));
$layout_path = $root . "user/uploads/" . treat_string($entry_title) . "/layout.php";
if(is_file($layout_path) && (#filesize($layout_path) > 0)) {
require($layout_path);
} else {
require($theme_path . "parts/entry.php");
}
}
mysql_query("UPDATE core_entries e SET
e.hits = $entry_hits
WHERE e.entry_id = $id");
}
if($isPerma) {
echo "<a class=\"index-link\" href=\"$http\">back to index</a>";
}
?>
You have not defined $data_entries, before using it here:
while($tmparray = mysql_fetch_array($data_entries,MYSQL_ASSOC)){
array_push($navArr,$tmparray['entry_id']);
}
That is why you get the very descriptive error message.
Did you mean to use $data_tags?
Use: "SELECT p.* FROM core_pages p WHERE p.page_title = '".$id."'
Note: mysql_connect is not sql-injection save. If you use mysql_connect, change to PDO.
$data_entries is not defined on line 50, then mysql_fetch_array return an exception of null value given.
Try to change $tmparray = mysql_fetch_array($data_entries,MYSQL_ASSOC) to $tmparray = mysql_fetch_array($data_tags,MYSQL_ASSOC).
Hope this help!

Joomla Love Factory legacy.php getInstance

I have a Love Factory extension in Joomla.
Love Factory 4.1.1
Joomla version 3.1
I extended interaction so the user can become a fan.
But when the JModelLegacy::getInstance (html.php) tries to get an Instance it crashed on require_once $path in legacy.php.
I tried to change only format in friends model and then it does not load it too.
It just take part of the code from required class and paste it on the screen. Example from friend.php
<?php
//class definition missing
//function definition missing
if (friendsLimitReached()) {
$this->setError(FactoryText::_('membership_restriction_error_friends_limit'));
$this->setState('membership_restriction_error', true);
return false;
}
// Load friendship request.
$table = $this->getTable('Friend');
$result = $table->load(array('sender_id' => $userId, 'receiver_id' => $user->id, 'pending' => 1));
// Check if friendship request was found.
if (!$result) {
$this->setError(FactoryText::_('friend_task_accept_error_request_not_found'));
return false;
}
// Check if it's relationship request and if users already have a relationship.
if (2 == $table->type && $this->usersInRelationship($user->id, $userId)) {
return false;
}
$table->accept();
return true;
}
public function reject($userId) {
// Initialise variables.
$user = JFactory::getUser();
// Load friendship request.
$table = $this->getTable('Friend');
$result = $table->load(array('sender_id' => $userId, 'receiver_id' => $user->id, 'pending' => 1));
// Check if friendship request was found.
if (!$result) {
$this->setError(FactoryText::_('friend_task_accept_error_request_not_found'));
return false;
}
$table->remove();
return true;
}
public function cancel($userId) {
$user = JFactory::getUser();
$table = $this->getTable('Friend');
$return = $table->load(array('sender_id' => $user->id, 'receiver_id' => $userId, 'type' => 1, 'pending' => 1));
// Check if request exists.
if (!$return) {
$this->setError(FactoryText::_('friend_task_cancel_error_request_not_found'));
return false;
}
if (!$table->delete()) {
$this->setError($table->getError());
return false;
}
return true;
}
public function request($userId) {
// Initialise variables.
$user = JFactory::getUser();
// Check friends limit
$model = JModelLegacy::getInstance('Friends', 'FrontendModel');
if ($model->friendsLimitReached()) {
$this->setError($model->getError());
$this->setState('membership_restriction_error', true);
return false;
}
// Check if sending request to self
if ($userId == $user->id) {
$this->setError(FactoryText::_('friend_taks_request_error_self_request'));
return false;
}
// Check if user is blacklisted
$model = JModelLegacy::getInstance('Blacklist', 'FrontendModel');
if ($model->isBlacklisted($user->id, $userId)) {
$this->setError($model->getError());
return false;
}
// Check if user is allowed to interact with members of same gender
$my_profile = $this->getTable('Profile', 'Table');
$profile = $this->getTable('Profile', 'Table');
$my_profile->loadAndMembership($user->id);
$profile->load($userId);
if (!$my_profile->membership_sold->same_gender_interaction && $my_profile->sex == $profile->sex) {
$this->setError(FactoryText::_('membership_restriction_error_same_gender_interaction'));
$this->setState('membership_restriction_error', true);
return false;
}
// Check if request already sent or friends already
$query = ' SELECT id' . ' FROM #__lovefactory_friends' . ' WHERE ((sender_id = ' . $userId . ' AND receiver_id = ' . $user->id . ')' . ' OR (sender_id = ' . $user->id . ' AND receiver_id = ' . $userId . '))' . ' AND type = 1';
$this->_db->setQuery($query);
$result = $this->_db->loadResult();
if ($result) {
$this->setError(FactoryText::_('friend_task_request_error_alredy_friends_or_pending'));
return false;
}
$message = JRequest::getVar('message', '', 'POST', 'string');
$friend = $this->getTable('Friend');
$friend->request($user->id, $userId, $message);
// Send notification
$mailer = FactoryMailer::getInstance();
$mailer->send( 'friend_request', $userId, array( JFactory::getUser($userId)->username, JFactory::getUser($user->id)->username, ) );
return true;
}
public function remove($userId) {
$friendship = $this->getFriendship($userId, 1);
if (!$friendship || 1 == $friendship->pending) {
$this->setError(FactoryText::_('friend task remove friend not found'));
return false;
}
$table = $this->getTable('Friend', 'Table');
$table->bind($friendship);
if (!$table->remove()) {
$this->setError($table->getError());
return false;
}
return true;
}
public function promote($mode, $userId) {
if ('promote' == $mode) {
return $this->promoteFriend($userId);
}
return $this->demoteFriend($userId);
}
public function getFriendshipStatus($firstUser, $secondUser, $type = 1) {
if (!$firstUser || ! $secondUser) {
return 0;
}
$dbo = $this->getDbo();
$query = $dbo->getQuery(true) ->select('f.*') ->from('#__lovefactory_friends f') ->where('((f.sender_id = ' . $dbo->quote($firstUser) . ' AND f.receiver_id = ' . $dbo->quote($secondUser) . ') OR (f.sender_id = ' . $dbo->quote($secondUser) . ' AND f.receiver_id = ' . $dbo->quote($firstUser) . '))') ->where('f.type = ' . $dbo->quote($type));
$result = $dbo->setQuery($query) ->loadObject();
if (!$result) {
return 0;
}
if ($result->pending) {
return $firstUser == $result->sender_id ? 2 : 3;
}
return 1;
}
protected function promoteFriend($userId) {
// Initialise variables.
$friendship = $this->getFriendship($userId);
$user = JFactory::getUser();
// Check if users are friends.
if (!$friendship || $friendship->pending == 1) {
$this->setError(FactoryText::_('friend_task_promote_friend_not_found'));
return false;
}
// Check if user is already a top friend.
if (($friendship->sender_id == $user->id && $friendship->sender_status) || ($friendship->receiver_id == $user->id && $friendship->receiver_status)) {
$this->setError(FactoryText::_('friend task promote already top friend'));
return false;
}
// Check if top friends limit is reached.
$friends = JModelLegacy::getInstance('Friends', 'FrontendModel');
if ($friends->friendsLimitReached(1)) {
$this->setError(FactoryText::_('friend task promote top friends limit reached'));
$this->setState('membership_restriction_error', true);
return false;
}
// Promote friend.
$table = $this->getTable('Friend', 'Table');
$table->id = $friendship->id;
if ($friendship->sender_id == $user->id) {
$table->sender_status = 1;
}
else {
$table->receiver_status = 1;
}
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
return true;
}
protected function demoteFriend($userId) {
// Initialise variables.
$friendship = $this->getFriendship($userId);
$user = JFactory::getUser();
// Check if users are friends.
if (!$friendship || $friendship->pending == 1) {
$this->setError(FactoryText::_('friend_task_promote_friend_not_found'));
return false;
}
// Check if user is top friend.
if (($friendship->sender_id == $user->id && !$friendship->sender_status) || ($friendship->receiver_id == $user->id && !$friendship->receiver_status)) {
$this->setError(FactoryText::_('friend task demote not top friend'));
return false;
}
// Demote friend.
$table = $this->getTable('Friend', 'Table');
$table->id = $friendship->id;
if ($friendship->sender_id == $user->id) {
$table->sender_status = 0;
}
else {
$table->receiver_status = 0;
}
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
return true;
}
public function getFriendship($userId, $type = 1) {
$user = JFactory::getUser();
$dbo = $this->getDbo();
$query = $dbo->getQuery(true) ->select('f.*') ->from('#__lovefactory_friends f') ->where('((f.sender_id = ' . $dbo->quote($userId) . ' AND f.receiver_id = ' . $dbo->quote($user->id) . ') OR (f.sender_id = ' . $dbo->quote($user->id) . ' AND f.receiver_id = ' . $dbo->quote($userId) . '))') ->where('f.type = ' . $dbo->quote($type));
$result = $dbo->setQuery($query) ->loadObject();
return $result;
}
public function usersInRelationship($receiverId, $senderId) {
$dbo = $this->getDbo();
$users = array($dbo->quote($receiverId), $dbo->quote($senderId));
$query = $dbo->getQuery(true) ->select('f.id, f.sender_id, f.receiver_id') ->from('#__lovefactory_friends f') ->where('(f.sender_id IN ('.implode(',', $users).') OR f.receiver_id IN ('.implode(',', $users).'))') ->where('f.type = ' . $dbo->quote(2)) ->where('f.pending = ' . $dbo->quote(0));
$result = $dbo->setQuery($query) ->loadObject();
if ($result) {
if ($receiverId == $result->sender_id || $receiverId == $result->receiver_id) {
$this->setError(FactoryText::_('friend_task_accept_error_you_already_are_in_a_relationship'));
}
else {
$this->setError(FactoryText::_('friend_task_accept_error_requesting_user_already_is_in_a_relationship'));
}
return true;
}
return false;
}
Is there any special way how the file must be written? Or did anyone else had the same problem?
The problem was caused by the line endings.
NetBeans changed the line endings and then the server was not able with function require_once load the content correctly.
Solution was download a plugin to NetBeans that allows to change line endings.

How to handle Exception when Zend_Acl is On? it gives Resource 'default::error::error' not found'

i've implemeted the Zend_Acl and its seems to be working.my resources are links :
module_name . "::" . controller_name . "::" . action_name;
i've added something in my code that's breaking and it seems that's i'm redirected to the usual error page but that the Acl comes in saying
Fatal error: Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'default::error::error' not found' in F:\work\php\zendworkspace\myproject\library\Zend\Acl.php on line 365
i have added the default::error::error to the resources but the error is still the same.
when i remove the code that's breaking the whole thing works again.
So i would definitely have the same error when something breaks in my code.
I would like to find out how to solve this. thanks for reading and sharing your experience.
Edit:
the code to implement that is kind of long. this is a db driven ACL with doctrine.
i've modified this tutorial to implement mine.i've cut out the myACL class, looks the same as the one in the tutorial, and the ACL plugin is kind of the same.i've registerd it in the application.ini.
// this class build all the roles and resouces and add 2 users to 2 differents roles and so on
class CMS_Util_AddResourcesAndRoles {
private $arrModules = array();
private $arrControllers = array();
public $arrActions = array();
private $arrIgnores = array('.', '..', '.svn');
public function BuildMCAArrays() {
$this->BuildModuleArray();
$this->BuildControllersArray();
$this->BuildActionArray();
return $this;
}
public function CheckData() {
if (count($this->arrModules) < 1)
throw new CMS_Exception_ResourceNotFound("No Modules found ..");
if (count($this->arrControllers) < 1)
throw new CMS_Exception_ResourceNotFound("No Controllers found ..");
if (count($this->arrActions) < 1)
throw new CMS_Exception_ResourceNotFound("No Actions found ..");
}
public function BuildModuleArray() {
$cmsApplicationModules = opendir(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules');
while (false !== ($cmsFile = readdir($cmsApplicationModules))) {
if (!in_array($cmsFile, $this->arrIgnores)) {
if (is_dir(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $cmsFile)) {
$this->arrModules[] = $cmsFile;
}
}
}
closedir($cmsApplicationModules);
return $this->arrModules;
}
public function BuildControllersArray() {
if (count($this->arrModules) > 0) {
foreach ($this->arrModules as $strModuleName) {
$cmsControllerFolder = opendir(APPLICATION_PATH . DIRECTORY_SEPARATOR . "modules" . DIRECTORY_SEPARATOR . $strModuleName . DIRECTORY_SEPARATOR . "controllers");
while (false !== ($cmsFile = readdir($cmsControllerFolder))) {
if (!in_array($cmsFile, $this->arrIgnores)) {
if (preg_match('/Controller/', $cmsFile)) {
// if(strtolower(substr($cmsFile, 0, -14)) != "error")
// $this->arrControllers[$strModuleName][] = strtolower(substr($cmsFile, 0, -14));
$this->arrControllers[$strModuleName][] = strtolower (substr($cmsFile, 0, -14));
}
}
}
closedir($cmsControllerFolder);
}
}
return $this->arrControllers;
}
private function BuildActionArray() {
// $arrMethods = array();
if (count($this->arrControllers) > 0) {
foreach ($this->arrControllers as $strModule => $strController) {
foreach ($strController as $strController) {
if ($strModule == "default") {
$strClassName = ucfirst($strController . 'Controller');
} else {
$strClassName = ucfirst($strModule) . '_' . ucfirst($strController . 'Controller');
}
if (!class_exists($strClassName)) {
Zend_Loader::loadFile(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $strModule . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . ucfirst($strController) . 'Controller.php');
}
$objReflection = new Zend_Reflection_Class($strClassName);
$arrMethods = $objReflection->getMethods();
foreach ($arrMethods as $arrMethod) {
if (preg_match('/Action/', $arrMethod->name)) {
$this->arrActions[$strModule][$strController][] = substr($arrMethod->name, 0, -6);
// $this->arrActions[$strModule][$strController][] = substr($this->_camelCaseToHyphens($objMethods->name), 0, -6);
}
}
}
}
}
return $this->arrActions;
}
private function _camelCaseToHyphens($string) {
if ($string == 'currentPermissionsAction') {
$found = true;
}
$length = strlen($string);
$convertedString = '';
for ($i = 0; $i < $length; $i++) {
if (ord($string[$i]) > ord('A') && ord($string[$i]) < ord('Z')) {
$convertedString .= '-' . strtolower($string[$i]);
} else {
$convertedString .= $string[$i];
}
}
return strtolower($convertedString);
}
public function WriteResourcesToDb() {
$this->BuildMCAArrays();
$this->CheckData();
$resources = array();
foreach ($this->arrModules as $strModuleName) {
if (array_key_exists($strModuleName, $this->arrControllers)) {
foreach ($this->arrControllers[$strModuleName] as $strControllerName) {
if (array_key_exists($strControllerName, $this->arrActions[$strModuleName])) {
foreach ($this->arrActions[$strModuleName][$strControllerName] as $strActionName) {
$res = new CMS_Model_Resource();
$res->module_name = $strModuleName;
$res->controller_name = $strControllerName;
$res->action_name = $strActionName;
$res->name = $strModuleName . "_" . $strControllerName . "_" . $strActionName;
$resources[] = $res;
$this->PersistResource($resources);
}
}
}
}
}
return $this;
}
private function PersistResource(array $resourceobject) {
try {
$collection = new Doctrine_Collection("CMS_Model_Resource");
foreach ($resourceobject as $resource) {
$collection->add($resource);
}
$collection->save();
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}
}
public function WriteRoleAndUserstoDb(){
$guest = new CMS_Model_Role();
$guest->name = "guest";
$guest->description = "simple user";
$guest->canbedeleted = true;
$member = new CMS_Model_Role();
$member->name = "member";
$member->description = "member with limited privileges,can access member reserved resources";
$member->canbedeleted = true;
$publisher = new CMS_Model_Role();
$publisher->name = "publisher";
$publisher->description = "publisher with publish an unpublished privileges";
$publisher->canbedeleted = true;
$manager = new CMS_Model_Role();
$manager->name = "manager";
$manager->description = "manager with privileges to publish, to unpublish, general manager of the site";
$manager->canbedeleted = true;
$admin = new CMS_Model_Role();
$admin->name = "administrator";
$admin->description = "admin with all privileges";
$admin->canbedeleted = false;
$superadmin = new CMS_Model_Role();
$superadmin->name = "superadmin";
$superadmin->description = "superadmin to rule them all";
$superadmin->canbedeleted = false;
$superadmin->Parents[0] = $admin;
$admin->Parents[0] = $manager;
$manager->Parents[0] = $publisher;
$publisher->Parents[0] = $member;
$member->Parents[0] = $guest;
$adminname = new CMS_Model_User();
$adminname->id = CMS_Util_Common::uuid();
$adminname->first_name = "adminname";
$adminname->last_name = "surname";
$adminname->full_name = "adminname surname";
$adminname->password = "password";
$adminname->email = "mister#somemail.com";
$adminname->is_active = true;
$adminname->is_verified = true;
$adminname->username ="superadmin";
$adminname->Role = $superadmin;
$adminname2 = new CMS_Model_User();
$adminname2->id = CMS_Util_Common::uuid();
$adminname2->first_name = "adminname2";
$adminname2->last_name = "adminsurname";
$adminname2->email="shallom#someemail.fr";
$adminname2->full_name = "adminname2 adminsurname";
$adminname2->password = "adminadmin";
$adminname2->is_active = true;
$adminname2->is_verified = true;
$adminname2->username ="admin";
$adminname2->Role = $admin;
$thepublisher = new CMS_Model_User();
$thepublisher->id = CMS_Util_Common::uuid();
$thepublisher->first_name = "one publisher";
$thepublisher->last_name = "lastname";
$thepublisher->full_name = "something something";
$thepublisher->email = "user#somegmail.com";
$thepublisher->password = "password";
$thepublisher->username = "publisher";
$thepublisher->is_active = true;
$thepublisher->is_verified = true;
$thepublisher->Role = $publisher;
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
$conn->flush();
return $this;
}
public function AssignResourcesToRoles(){
$guestcollection = new Doctrine_Collection("CMS_Model_RoleResource");
$guestroles = Doctrine_Core::getTable("CMS_Model_Role")->GetRoleByName("guest");
$defautresources = Doctrine_Core::getTable("CMS_Model_Resource")->GetResourceByModule("default");
foreach($defautresources as $resource){
$guestroleresource = new CMS_Model_RoleResource();
$guestroleresource->Role = $guestroles;
$guestroleresource->Resource = $resource;
$guestcollection->add($guestroleresource);
}
$guestcollection->save();
$admincollection = new Doctrine_Collection("CMS_Model_RoleResource");
$adminroles = Doctrine_Core::getTable("CMS_Model_Role")->GetRoleByName("superadmin");
$adminresources = Doctrine_Core::getTable("CMS_Model_Resource")->GetResourceByModule("admin");
foreach($adminresources as $resource){
$adminroleresource = new CMS_Model_RoleResource();
$adminroleresource->Role = $adminroles;
$adminroleresource->Resource = $resource;
$admincollection->add($adminroleresource);
}
$admincollection->save();
return $this;
}
public function SetAclUp(){
$this->WriteResourcesToDb();
$this->WriteRoleAndUserstoDb();
$this->AssignResourcesToRoles();
return $this;
}
}
as you can see i've granted all links under default to role guest meaning guest can see the default::error::error page when there is a problem.
I can also assure you that, when nothing is broken in my code, i can login with the publisher credential and get bounced anytime i'm trying to go to the admin panel.
The most popular error is that you have not added the resource for any instance.

Categories