Joomla Love Factory legacy.php getInstance

Joomla Love Factory legacy.php getInstance,php,joomla,require-once,Php,Joomla,Require Once,我在Joomla有一个Love Factory扩展 爱工厂4.1.1 Joomla版本3.1 我扩展了交互,因此用户可以成为粉丝。 但是当JModelLegacy::getInstance(html.php)试图获取实例时,它在legacy.php中的require_once$path上崩溃 我试图在friends模型中只更改格式,但它没有加载它 它只是从所需的类中获取部分代码并将其粘贴到屏幕上。来自friend.php的示例 <?php //class definition missin

我在Joomla有一个Love Factory扩展

爱工厂4.1.1

Joomla版本3.1

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

我试图在friends模型中只更改格式,但它没有加载它

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

问题是由行尾引起的。
NetBeans更改了行尾,一旦正确加载内容,服务器就无法使用require_函数


解决方案是将一个插件下载到NetBeans,该插件允许更改行尾。

您粘贴的内容不是有效的PHP,并且格式不正确。此外,您正在讨论一个专有插件,我怀疑这里的许多人都知道它的内部结构。为什么不向作者寻求支持?此代码示例缺少一个类定义和至少一个函数定义。你复制了文件的全部内容吗?文件的内容并不重要。这是应用程序放在屏幕上的代码。