Joomla Love Factory legacy.php getInstance

时间:2013-09-19 11:57:26

标签: php joomla require-once

我在 Joomla 中有一个Love Factory扩展。

爱工厂4.1.1

Joomla 3.1版

我扩展了互动,因此用户可以成为粉丝。 但是当JModelLegacy::getInstance(html.php)尝试获取实例时,它会在legacy.php中require_once $path崩溃。

我尝试仅更改朋友模式中的格式,然后它也不会加载它。

它只是从必需的类中获取部分代码并将其粘贴到屏幕上。来自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; 
}

是否有必要编写文件的特殊方法?或者其他人有同样的问题吗?

1 个答案:

答案 0 :(得分:0)

问题是由行结尾引起的。 NetBeans更改了行结尾,然后服务器无法通过函数require_once正确加载内容。

解决方案是向NetBeans下载一个允许更改行结尾的插件。