AndyB
Well-known member
In post #5 the first line you can see I have not extended the XFCP properly. Once I fixed that I have successfully extended XenForo_ControllerPublic_Forum using XFCP.
However there's a problem, as soon as I go to create a thread and type into the thread title area, I get the following error.
Apparently the AJAX code and/or Route Prefix are not working with the XFCP system.
Here's my code.
However there's a problem, as soon as I go to create a thread and type into the thread title area, I get the following error.
An exception occurred: Cannot load class using XFCP. Load the class using the correct loader first. in /home/southbay/www/forums/library/XenForo/Autoloader.php on line 108
Apparently the AJAX code and/or Route Prefix are not working with the XFCP system.
Here's my code.
PHP:
<?php
class Andy_SimilarThreads_ControllerPublic_Forum extends XFCP_Andy_SimilarThreads_ControllerPublic_Forum
{
public function actionIndex()
{
// call parent function
parent::actionIndex();
// declare variables
$currentNodeId = '';
$currentThreadId = '';
$similarThreads = array();
$searchWords = array();
$searchWord1 = '';
$searchWord2 = '';
$safeSearchWord1 = '';
$safeSearchWord2 = '';
// get options from Admin CP -> Options -> Similar Threads -> Show Create Thread
$showCreateThread = XenForo_Application::get('options')->showCreateThread;
if ($showCreateThread == 1)
{
// get newTitle
$newTitle = $this->_request->getParam('title');
// put into array
$newTitle = explode(' ', $newTitle);
// get options from Admin CP -> Options -> Similar Threads -> Common Words
$commonWords = XenForo_Application::get('options')->commonWords;
// convert to lowercase
$commonWords = strtolower($commonWords);
// put $commonWordsLower into an array
$commonWords = explode(' ', $commonWords);
// remove any common words from array
foreach($newTitle as $var)
{
if (!in_array(strtolower($var), $commonWords))
{
// get options from Admin CP -> Options -> Similar Threads -> Miniumum Common Word Length
$minimumCommonWordLength = XenForo_Application::get('options')->minimumCommonWordLength;
if (strlen($var) >= $minimumCommonWordLength)
{
$searchWords[] = $var;
}
}
}
$count = count($searchWords);
// only continue if we have a search word
if ($count > 0)
{
// get first search word
$searchWord1 = $searchWords[0];
// make safe for query
$safeSearchWord1 = addslashes($searchWords[0]);
if ($count > 1)
{
// get second search word
$searchWord2 = $searchWords[1];
// make safe for query
$safeSearchWord2 = addslashes($searchWords[1]);
}
}
// run query only if we have a search and option is selected
if ($safeSearchWord1 != '' AND $showCreateThread == 1)
{
// run query in model
$similarThreads = $this->getModelFromCache('Andy_SimilarThreads_Model')->getThreads($safeSearchWord1,$safeSearchWord2,$currentNodeId,$currentThreadId);
}
// prepare $viewParams for template
$viewParams = array(
'similarThreads' => $similarThreads,
'searchWord1' => $searchWord1,
'searchWord2' => $searchWord2,
);
// send to template
return $this->responseView('Andy_SimilarThreads_ViewPublic_SimilarThreads', 'andy_similarthreads_create_thread', $viewParams);
}
}
}
?>
Last edited: