Код: Выделить всё
[phpBB Debug] PHP Notice: in file [ROOT]/ext/alecto/UserTopics/event/listener.php on line 47: Undefined variable: topic_id
Код: Выделить всё
[phpBB Debug] PHP Notice: in file [ROOT]/ext/alecto/UserTopics/event/listener.php on line 47: Undefined variable: topic_id
Код: Выделить всё
$show_results = (isset($topic_id)) ? 'posts' : $this->request->variable('sr', 'posts');
Код: Выделить всё
public function search_modify_param_before($event)
{
$search_fields = $this->request->variable('sf', 'all');
$show_results = (isset($topic_id)) ? 'posts' : $this->request->variable('sr', 'posts');
$show_results = ($show_results == 'posts') ? 'posts' : 'topics';
if ($event['search_id'] == 'egosearch' && $show_results == 'topics')
{
$this->template->assign_vars(array(
'S_EGO_SEARCH' => true,
));
};
}
Код: Выделить всё
$search_fields = $this->request->variable('sf', 'all');
Код: Выделить всё
if ($event['author_id'] != null && $show_results == 'topics')
{
$this->template->assign_vars(array(
'S_USERID_SEARCH' => true,
));
};
Если делать корректно, то вместо этого кода нужно проверять параметр topic_id из запроса.Sheer писал(а):Код: Выделить всё
$show_results = (isset($topic_id)) ? 'posts' : $this->request->variable('sr', 'posts');
isset($topic_id)
в данном случае - "заглушка", поскольку topic_id в коде не задаётся.Код: Выделить всё
public function search_modify_param_before($event)
{
$topic_id = $this->request->variable('t', 0);
$author_id = $this->request->variable('author_id', 0);
$search_fields = $this->request->variable('sf', 'all');
$show_results = ($topic_id) ? 'posts' : $this->request->variable('sr', 'posts');
$show_results = ($show_results == 'posts') ? 'posts' : 'topics';
if ($event['search_id'] == 'egosearch' && $show_results == 'topics')
{
$this->template->assign_vars(array(
'S_EGO_SEARCH' => true,
));
};
// Автор с id == 1 - это любой гость.
if ($author_id >= 1 && $show_results == 'topics')
{
$this->template->assign_vars(array(
'S_USERID_SEARCH' => true,
));
};
}
Конечно не сработает, если author_id не берётся из запроса.
Чтобы делать корректно, нужно видеть весь код (ну и понимать, чего автор добивается. Я не совсем понял, чего он хочет в конце-концов).
Код: Выделить всё
<?php
/**
*
* @package myextension
* @copyright (c) 2014 Nickname
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace alecto\UserTopics\event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class listener implements EventSubscriberInterface
{
public function __construct(\phpbb\template\template $template, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, $phpbb_root_path, $php_ext)
{
$this->template = $template;
$this->db = $db;
$this->request = $request;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
static public function getSubscribedEvents()
{
return array(
'core.user_setup' => 'load_language_on_setup',
'core.memberlist_view_profile' => 'memberlist_view_profile',
'core.page_header_after' => 'page_header_after',
'core.viewtopic_modify_post_row' => 'viewtopic_poster_topics',
'core.search_modify_param_before' => 'search_modify_param_before',
);
}
public function search_modify_param_before($event)
{
$show_results = (isset($topic_id)) ? 'posts' : $this->request->variable('sr', 'posts');
$show_results = ($show_results == 'posts') ? 'posts' : 'topics';
if ($event['search_id'] == 'egosearch' && $show_results == 'topics')
{
$this->template->assign_vars(array(
'S_EGO_TOPICS_SEARCH' => true,
));
};
if ($event['author_id'] != null && $show_results == 'topics')
{
$this->template->assign_vars(array(
'S_USER_TOPICS_SEARCH' => true,
));
};
}
public function viewtopic_poster_topics($event)
{
$postrow = $event['post_row'];
$poster_id = $event['poster_id'];
$postrow = array_merge($postrow, array(
'USER_TOPICS_MINIPROFILE_LINK' => append_sid("{$this->phpbb_root_path}search.$this->php_ext", 'author_id=' . $poster_id . '&sr=topics&sf=firstpost'),
));
$event['post_row'] = $postrow;
}
public function page_header_after($event)
{
//$sort_by_sql = $event['sort_by_sql'];
//$sort_by_sql['t'] = 't.topic_first_post_time';
$author_id = $event['author_id'];
$this->template->assign_vars(array(
'USER_TOPICS_OWN_LINK' => append_sid("{$this->phpbb_root_path}search.$this->php_ext", 'search_id=egosearch&sr=topics&sf=firstpost'),
'USER_BY_ID_TOPICS_LINK' => append_sid("{$this->phpbb_root_path}search.$this->php_ext", 'author_id=' . $author_id . '&sr=topics&sf=firstpost'),
));
//$event['sort_by_sql'] = $sort_by_sql;
}
public function memberlist_view_profile($event)
{
$user_id = $this->request->variable('u', 0);
$sql = 'SELECT COUNT(topic_id) as user_topics FROM ' . TOPICS_TABLE . ' WHERE topic_status <> ' . ITEM_MOVED . ' AND topic_poster = ' . (int) $user_id;
$result = $this->db->sql_query($sql); //Выполняем запрос
$row = $this->db->sql_fetchrow($result); //Получаем одну строку из результата
$this->db->sql_freeresult($result); //Очищаем память от запроса
$user_topics = $row['user_topics']; //Задаём значение результата запроса переменной $user_topics
$this->template->assign_vars(array(
'USER_TOPICS_COUNT' => $user_topics,
'USER_TOPICS_PROFILE_LINK' => append_sid("{$this->phpbb_root_path}search.$this->php_ext", 'author_id=' . $user_id . '&sr=topics&sf=firstpost'),
));
}
public function load_language_on_setup($event)
{
$lang_set_ext = $event['lang_set_ext'];
$lang_set_ext[] = array(
'ext_name' => 'alecto/UserTopics',
'lang_set' => 'UserTopics',
);
$event['lang_set_ext'] = $lang_set_ext;
}
}
Отлаживать пробовали?
$show_results
, по-видимому, имеет значение 'posts'.Код: Выделить всё
$author_id = $this->request->variable('author_id', 0);
Откуда? Оно не передаётся.
Ну да
Код: Выделить всё
SELECT username, user_colour
FROM ...