Merge pull request #306 from marc1706/ticket/305
[ticket/305] Turn phpbb_fetch_posts into service
This commit is contained in:
@@ -59,7 +59,7 @@ script:
|
||||
- ../board3/Board3-Portal/travis/run-testsuite.sh $DB $TRAVIS_PHP_VERSION
|
||||
|
||||
after_script:
|
||||
- php ../board3/Board3-Portal/vendor/bin/coveralls -v
|
||||
- sh -c "if [ '$COVERALLS' != '0' ]; then ../board3/Board3-Portal/travis/run-coveralls.sh $DB $TRAVIS_PHP_VERSION; fi"
|
||||
|
||||
notifications:
|
||||
email:
|
||||
|
||||
@@ -13,6 +13,7 @@ services:
|
||||
- %core.php_ext%
|
||||
- %core.root_path%
|
||||
- @user
|
||||
- @board3.portal.fetch_posts
|
||||
tags:
|
||||
- { name: board3.module }
|
||||
|
||||
@@ -186,6 +187,7 @@ services:
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
- @user
|
||||
- @board3.portal.fetch_posts
|
||||
tags:
|
||||
- { name: board3.module }
|
||||
|
||||
|
||||
@@ -55,3 +55,13 @@ services:
|
||||
class: board3\portal\includes\modules_helper
|
||||
arguments:
|
||||
- @auth
|
||||
|
||||
board3.portal.fetch_posts:
|
||||
class: board3\portal\portal\fetch_posts
|
||||
arguments:
|
||||
- @auth
|
||||
- @cache
|
||||
- @config
|
||||
- @dbal.conn
|
||||
- @board3.portal.modules_helper
|
||||
- @user
|
||||
|
||||
@@ -90,284 +90,19 @@ function obtain_portal_modules()
|
||||
return $portal_modules;
|
||||
}
|
||||
|
||||
// fetch post for news & announce
|
||||
/**
|
||||
* Fetch post for news & announce
|
||||
*
|
||||
* @deprecated 2.1.0-b1 (To be removed: 2.2.0)
|
||||
*/
|
||||
function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start = 0, $invert = false)
|
||||
{
|
||||
global $db, $phpbb_root_path, $auth, $user, $bbcode_bitfield, $bbcode, $portal_config, $config, $cache, $phpbb_container;
|
||||
global $phpbb_container;
|
||||
|
||||
$posts = $update_count = array();
|
||||
$post_time = ($time == 0) ? '' : 'AND t.topic_time > ' . (time() - $time * 86400);
|
||||
$forum_from = (strpos($forum_from, ',') !== false) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array());
|
||||
$str_where = '';
|
||||
$topic_icons = array(0);
|
||||
$have_icons = 0;
|
||||
$modules_helper = $phpbb_container->get('board3.portal.modules_helper');
|
||||
$fetch_posts = $phpbb_container->get('board3.portal.fetch_posts');
|
||||
$fetch_posts->set_module_id($module_id);
|
||||
|
||||
// Get disallowed forums
|
||||
$disallow_access = $modules_helper->get_disallowed_forums($permissions);
|
||||
|
||||
if ($invert == true)
|
||||
{
|
||||
$disallow_access = array_merge($disallow_access, $forum_from);
|
||||
$forum_from = array();
|
||||
}
|
||||
|
||||
$global_f = 0;
|
||||
|
||||
if (sizeof($forum_from))
|
||||
{
|
||||
$disallow_access = array_diff($forum_from, $disallow_access);
|
||||
if (!sizeof($disallow_access))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($disallow_access as $acc_id)
|
||||
{
|
||||
$acc_id = (int) $acc_id;
|
||||
$str_where .= "t.forum_id = $acc_id OR ";
|
||||
if ($type == 'announcements' && $global_f < 1 && $acc_id > 0)
|
||||
{
|
||||
$global_f = $acc_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($disallow_access as $acc_id)
|
||||
{
|
||||
$acc_id = (int) $acc_id;
|
||||
$str_where .= "t.forum_id <> $acc_id AND ";
|
||||
}
|
||||
}
|
||||
|
||||
switch($type)
|
||||
{
|
||||
case "announcements":
|
||||
$topic_type = '((t.topic_type = ' . POST_ANNOUNCE . ') OR (t.topic_type = ' . POST_GLOBAL . '))';
|
||||
$str_where = (strlen($str_where) > 0) ? 'AND (t.forum_id = 0 OR (' . trim(substr($str_where, 0, -4)) . '))' : '';
|
||||
$user_link = 't.topic_poster = u.user_id';
|
||||
$post_link = 't.topic_first_post_id = p.post_id';
|
||||
$topic_order = 't.topic_time DESC';
|
||||
break;
|
||||
case "news":
|
||||
$topic_type = 't.topic_type = ' . POST_NORMAL;
|
||||
$str_where = (strlen($str_where) > 0) ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : '';
|
||||
$user_link = ($config['board3_news_style_' . $module_id]) ? 't.topic_poster = u.user_id' : (($config['board3_news_show_last_' . $module_id]) ? 't.topic_last_poster_id = u.user_id' : 't.topic_poster = u.user_id' ) ;
|
||||
$post_link = ($config['board3_news_style_' . $module_id]) ? 't.topic_first_post_id = p.post_id' : (($config['board3_news_show_last_' . $module_id]) ? 't.topic_last_post_id = p.post_id' : 't.topic_first_post_id = p.post_id' ) ;
|
||||
$topic_order = ($config['board3_news_show_last_' . $module_id]) ? 't.topic_last_post_time DESC' : 't.topic_time DESC' ;
|
||||
break;
|
||||
case "news_all":
|
||||
$topic_type = '(t.topic_type <> ' . POST_ANNOUNCE . ') AND (t.topic_type <> ' . POST_GLOBAL . ')';
|
||||
$str_where = (strlen($str_where) > 0) ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : '';
|
||||
$user_link = ($config['board3_news_style_' . $module_id]) ? 't.topic_poster = u.user_id' : (($config['board3_news_show_last_' . $module_id]) ? 't.topic_last_poster_id = u.user_id' : 't.topic_poster = u.user_id' ) ;
|
||||
$post_link = ($config['board3_news_style_' . $module_id]) ? 't.topic_first_post_id = p.post_id' : (($config['board3_news_show_last_' . $module_id]) ? 't.topic_last_post_id = p.post_id' : 't.topic_first_post_id = p.post_id' ) ;
|
||||
$topic_order = ($config['board3_news_show_last_' . $module_id]) ? 't.topic_last_post_time DESC' : 't.topic_time DESC' ;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Method was called with unsupported type
|
||||
throw new \InvalidArgumentexception($user->lang('B3P_WRONG_METHOD_CALL', __FUNCTION__));
|
||||
}
|
||||
|
||||
if ($type == 'announcements' && $global_f < 1)
|
||||
{
|
||||
if (!empty($str_where) || ($row = $cache->get('_forum_id_first_forum_post')) === false)
|
||||
{
|
||||
$sql = 'SELECT forum_id
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE forum_type = ' . FORUM_POST . '
|
||||
' . str_replace('t.', '', $str_where) . '
|
||||
ORDER BY forum_id';
|
||||
$result = $db->sql_query_limit($sql, 1);
|
||||
$row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (empty($str_where))
|
||||
{
|
||||
// Cache first forum ID for one day = 86400 s
|
||||
$cache->put('_forum_id_first_forum_post', $row, 86400);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sizeof($row))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
$global_f = $row['forum_id'];
|
||||
}
|
||||
|
||||
$sql_array = array(
|
||||
'SELECT' => 't.forum_id,
|
||||
t.topic_id,
|
||||
t.topic_last_post_id,
|
||||
t.topic_last_post_time,
|
||||
t.topic_time,
|
||||
t.topic_title,
|
||||
t.topic_attachment,
|
||||
t.topic_views,
|
||||
t.poll_title,
|
||||
t.topic_posts_approved,
|
||||
t.topic_posts_unapproved,
|
||||
t.topic_posts_softdeleted,
|
||||
t.topic_poster,
|
||||
t.topic_type,
|
||||
t.topic_status,
|
||||
t.topic_last_poster_name,
|
||||
t.topic_last_poster_id,
|
||||
t.topic_last_poster_colour,
|
||||
t.icon_id,
|
||||
u.username,
|
||||
u.user_id,
|
||||
u.user_type,
|
||||
u.user_colour,
|
||||
p.post_id,
|
||||
p.poster_id,
|
||||
p.post_time,
|
||||
p.post_text,
|
||||
p.post_attachment,
|
||||
p.post_username,
|
||||
p.enable_smilies,
|
||||
p.enable_bbcode,
|
||||
p.enable_magic_url,
|
||||
p.bbcode_bitfield,
|
||||
p.bbcode_uid,
|
||||
f.forum_name,
|
||||
f.enable_icons',
|
||||
'FROM' => array(
|
||||
TOPICS_TABLE => 't',
|
||||
),
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(USERS_TABLE => 'u'),
|
||||
'ON' => $user_link,
|
||||
),
|
||||
array(
|
||||
'FROM' => array(FORUMS_TABLE => 'f'),
|
||||
'ON' => 't.forum_id=f.forum_id',
|
||||
),
|
||||
array(
|
||||
'FROM' => array(POSTS_TABLE => 'p'),
|
||||
'ON' => $post_link,
|
||||
),
|
||||
),
|
||||
'WHERE' => $topic_type . '
|
||||
' . $post_time . '
|
||||
AND t.topic_status <> ' . ITEM_MOVED . '
|
||||
AND t.topic_visibility = 1
|
||||
AND t.topic_moved_id = 0
|
||||
' . $str_where,
|
||||
'ORDER_BY' => $topic_order,
|
||||
);
|
||||
|
||||
$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
|
||||
$sql_array['SELECT'] .= ', tp.topic_posted';
|
||||
$sql = $db->sql_build_query('SELECT', $sql_array);
|
||||
|
||||
if ($number_of_posts != 0)
|
||||
{
|
||||
$result = $db->sql_query_limit($sql, $number_of_posts, $start);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $db->sql_query($sql);
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$attachments = array();
|
||||
if (($auth->acl_get('u_download') && ($auth->acl_get('f_download', $row['forum_id']) || $row['forum_id'] == 0)) && $config['allow_attachments'] && $row['post_id'] && $row['post_attachment'])
|
||||
{
|
||||
// Pull attachment data
|
||||
$sql2 = 'SELECT *
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE post_msg_id = '. $row['post_id'] .'
|
||||
AND in_message = 0
|
||||
ORDER BY filetime DESC';
|
||||
$result2 = $db->sql_query($sql2);
|
||||
|
||||
while ($row2 = $db->sql_fetchrow($result2))
|
||||
{
|
||||
$attachments[] = $row2;
|
||||
}
|
||||
$db->sql_freeresult($result2);
|
||||
}
|
||||
|
||||
$posts[$i]['bbcode_uid'] = $row['bbcode_uid'];
|
||||
$len_check = $row['post_text'];
|
||||
$maxlen = $text_length;
|
||||
|
||||
if (($text_length != 0) && (strlen($len_check) > $text_length))
|
||||
{
|
||||
$message = str_replace(array("\n", "\r"), array('<br />', "\n"), $row['post_text']);
|
||||
$message = get_sub_taged_string($message, $row['bbcode_uid'], $maxlen);
|
||||
$posts[$i]['striped'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = str_replace("\n", '<br/> ', $row['post_text']);
|
||||
}
|
||||
|
||||
$row['bbcode_options'] = (($row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
|
||||
$message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
|
||||
|
||||
if (!empty($attachments))
|
||||
{
|
||||
parse_attachments($row['forum_id'], $message, $attachments, $update_count);
|
||||
}
|
||||
|
||||
if ($global_f < 1)
|
||||
{
|
||||
$global_f = $row['forum_id'];
|
||||
}
|
||||
|
||||
$topic_icons[] = $row['enable_icons'];
|
||||
$have_icons = ($row['icon_id'] > 0) ? 1 : $have_icons;
|
||||
|
||||
$posts[$i] = array_merge($posts[$i], array(
|
||||
'post_text' => ap_validate($message),
|
||||
'topic_id' => $row['topic_id'],
|
||||
'topic_last_post_id' => $row['topic_last_post_id'],
|
||||
'topic_type' => $row['topic_type'],
|
||||
'topic_posted' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
|
||||
'icon_id' => $row['icon_id'],
|
||||
'topic_status' => $row['topic_status'],
|
||||
'forum_id' => $row['forum_id'],
|
||||
'topic_replies' => $row['topic_posts_approved'] + $row['topic_posts_unapproved'] + $row['topic_posts_softdeleted'],
|
||||
'topic_replies_real' => $row['topic_posts_approved'],
|
||||
'topic_time' => $user->format_date($row['post_time']),
|
||||
'topic_last_post_time' => $row['topic_last_post_time'],
|
||||
'topic_title' => $row['topic_title'],
|
||||
'username' => $row['username'],
|
||||
'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['post_username']),
|
||||
'username_full_last' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour'], $row['topic_last_poster_name']),
|
||||
'user_id' => $row['user_id'],
|
||||
'user_type' => $row['user_type'],
|
||||
'user_colour' => $row['user_colour'],
|
||||
'poll' => ($row['poll_title']) ? true : false,
|
||||
'attachment' => ($row['topic_attachment']) ? true : false,
|
||||
'topic_views' => $row['topic_views'],
|
||||
'forum_name' => $row['forum_name'],
|
||||
'attachments' => (!empty($attachments)) ? $attachments : array(),
|
||||
));
|
||||
$posts['global_id'] = $global_f;
|
||||
++$i;
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$posts['topic_icons'] = ((max($topic_icons) > 0) && $have_icons) ? true : false;
|
||||
$posts['topic_count'] = $i;
|
||||
|
||||
if ($global_f < 1)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $posts;
|
||||
}
|
||||
return $fetch_posts->get_posts($forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start, $invert);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,6 +74,9 @@ class announcements extends module_base
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var \board3\portal\portal\fetch_posts */
|
||||
protected $fetch_posts;
|
||||
|
||||
/**
|
||||
* Construct an announcements object
|
||||
*
|
||||
@@ -88,8 +91,9 @@ class announcements extends module_base
|
||||
* @param string $phpEx php file extension
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param \phpbb\user $user phpBB user object
|
||||
* @param \board3\portal\portal\fetch_posts $fetch_posts Fetch posts object
|
||||
*/
|
||||
public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user)
|
||||
public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user, $fetch_posts)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
@@ -102,6 +106,7 @@ class announcements extends module_base
|
||||
$this->php_ext = $phpEx;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->user = $user;
|
||||
$this->fetch_posts = $fetch_posts;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,9 +119,19 @@ class announcements extends module_base
|
||||
$start = $this->request->variable('ap', 0);
|
||||
$start = ($start < 0) ? 0 : $start;
|
||||
|
||||
// Fetch announcements from porta functions.php with check if "read full" is requested.
|
||||
// Fetch announcements from portal functions.php with check if "read full" is requested.
|
||||
$portal_announcement_length = ($announcement < 0) ? $this->config['board3_announcements_length_' . $module_id] : 0;
|
||||
$fetch_news = phpbb_fetch_posts($module_id, $this->config['board3_global_announcements_forum_' . $module_id], $this->config['board3_announcements_permissions_' . $module_id], $this->config['board3_number_of_announcements_' . $module_id], $portal_announcement_length, $this->config['board3_announcements_day_' . $module_id], 'announcements', $start, $this->config['board3_announcements_forum_exclude_' . $module_id]);
|
||||
$this->fetch_posts->set_module_id($module_id);
|
||||
$fetch_news = $this->fetch_posts->get_posts(
|
||||
$this->config['board3_global_announcements_forum_' . $module_id],
|
||||
$this->config['board3_announcements_permissions_' . $module_id],
|
||||
$this->config['board3_number_of_announcements_' . $module_id],
|
||||
$portal_announcement_length,
|
||||
$this->config['board3_announcements_day_' . $module_id],
|
||||
'announcements',
|
||||
$start,
|
||||
$this->config['board3_announcements_forum_exclude_' . $module_id]
|
||||
);
|
||||
|
||||
// Any announcements present? If not terminate it here.
|
||||
if (sizeof($fetch_news) == 0)
|
||||
|
||||
@@ -74,6 +74,9 @@ class news extends module_base
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var \board3\portal\portal\fetch_posts */
|
||||
protected $fetch_posts;
|
||||
|
||||
/**
|
||||
* Construct a news object
|
||||
*
|
||||
@@ -88,8 +91,9 @@ class news extends module_base
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param string $phpEx php file extension
|
||||
* @param \phpbb\user $user phpBB user object
|
||||
* @param \board3\portal\portal\fetch_posts $fetch_posts Fetch posts object
|
||||
*/
|
||||
public function __construct($auth, $cache, $config, $db, $pagination, $modules_helper, $request, $template, $phpbb_root_path, $phpEx, $user)
|
||||
public function __construct($auth, $cache, $config, $db, $pagination, $modules_helper, $request, $template, $phpbb_root_path, $phpEx, $user, $fetch_posts)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
@@ -102,6 +106,7 @@ class news extends module_base
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $phpEx;
|
||||
$this->user = $user;
|
||||
$this->fetch_posts = $fetch_posts;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +122,17 @@ class news extends module_base
|
||||
|
||||
// Fetch news from portal functions.php with check if "read full" is requested.
|
||||
$portal_news_length = ($news < 0) ? $this->config['board3_news_length_' . $module_id] : 0;
|
||||
$fetch_news = phpbb_fetch_posts($module_id, $this->config['board3_news_forum_' . $module_id], $this->config['board3_news_permissions_' . $module_id], $this->config['board3_number_of_news_' . $module_id], $portal_news_length, 0, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news', $start, $this->config['board3_news_exclude_' . $module_id]);
|
||||
$this->fetch_posts->set_module_id($module_id);
|
||||
$fetch_news = $this->fetch_posts->get_posts(
|
||||
$this->config['board3_news_forum_' . $module_id],
|
||||
$this->config['board3_news_permissions_' . $module_id],
|
||||
$this->config['board3_number_of_news_' . $module_id],
|
||||
$portal_news_length,
|
||||
0,
|
||||
($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news',
|
||||
$start,
|
||||
$this->config['board3_news_exclude_' . $module_id]
|
||||
);
|
||||
|
||||
// Any news present? If not terminate it here.
|
||||
if (sizeof($fetch_news) == 0)
|
||||
|
||||
537
portal/fetch_posts.php
Normal file
537
portal/fetch_posts.php
Normal file
@@ -0,0 +1,537 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package Board3 Portal v2.1
|
||||
* @copyright (c) 2014 Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace board3\portal\portal;
|
||||
|
||||
class fetch_posts
|
||||
{
|
||||
/**
|
||||
* phpBB auth
|
||||
* @var \phpbb\auth\auth
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* phpBB cache
|
||||
* @var \phpbb\cache\driver
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* phpBB config
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* phpBB db driver
|
||||
* @var \phpbb\db\driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Modules helper
|
||||
* @var \board3\portal\includes\modules_helper
|
||||
*/
|
||||
protected $modules_helper;
|
||||
|
||||
/**
|
||||
* phpBB user
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* SQL Query where constraint
|
||||
* @var string
|
||||
*/
|
||||
protected $where_string = '';
|
||||
|
||||
/**
|
||||
* SQL topic type constraint
|
||||
* @var string
|
||||
*/
|
||||
protected $topic_type = '';
|
||||
|
||||
/**
|
||||
* SQL user link constraint
|
||||
* @var string
|
||||
*/
|
||||
protected $user_link = '';
|
||||
|
||||
/**
|
||||
* SQL post link constraint
|
||||
* @var string
|
||||
*/
|
||||
protected $post_link = '';
|
||||
|
||||
/**
|
||||
* SQL topic order constraint
|
||||
* @var string
|
||||
*/
|
||||
protected $topic_order = '';
|
||||
|
||||
/**
|
||||
* Module ID
|
||||
* @var int
|
||||
*/
|
||||
protected $module_id;
|
||||
|
||||
/**
|
||||
* Forum ID to use for global topics
|
||||
* @var int
|
||||
*/
|
||||
protected $global_id;
|
||||
|
||||
/**
|
||||
* Type of posts to fetch
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* NOTE: The parameters of this method must match in order and type with
|
||||
* the dependencies defined in the services.yml file for this service.
|
||||
* @param \phpbb\auth\auth $auth phpBB auth object
|
||||
* @param \phpbb\cache\driver $cache phpBB cache driver
|
||||
* @param \phpbb\config\config $config phpBB config
|
||||
* @param \phpbb\db\driver_interface $db phpBB database driver
|
||||
* @param \board3\portal\includes\modules_helper $modules_helper Board3 modules helper
|
||||
* @param \phpbb\user $user phpBB user object
|
||||
*/
|
||||
public function __construct($auth, $cache, $config, $db, $modules_helper, $user)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->modules_helper = $modules_helper;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts defined by type and other settings
|
||||
*
|
||||
*/
|
||||
public function get_posts($forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start = 0, $invert = false)
|
||||
{
|
||||
$posts = $update_count = array();
|
||||
$post_time = ($time == 0) ? '' : 'AND t.topic_time > ' . (time() - $time * 86400);
|
||||
$forum_from = (strpos($forum_from, ',') !== false) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array());
|
||||
$topic_icons = array(0);
|
||||
$have_icons = 0;
|
||||
$this->global_id = 0;
|
||||
$this->type = $type;
|
||||
$this->reset_constraints();
|
||||
|
||||
// Get disallowed forums
|
||||
$disallow_access = $this->modules_helper->get_disallowed_forums($permissions);
|
||||
|
||||
// Set forums that should be excluded or included
|
||||
if (!$this->set_forum_constraints($forum_from, $disallow_access, $invert))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// Get SQL constraints
|
||||
$this->get_type_constraints();
|
||||
|
||||
// Get global forum ID for announcements
|
||||
if (!$this->get_global_id())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$result = $this->run_sql_query($post_time, $number_of_posts, $start);
|
||||
|
||||
$i = 0;
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$attachments = array();
|
||||
if (($this->auth->acl_get('u_download') && ($this->auth->acl_get('f_download', $row['forum_id']) || $row['forum_id'] == 0)) && $this->config['allow_attachments'] && $row['post_id'] && $row['post_attachment'])
|
||||
{
|
||||
// Pull attachment data
|
||||
$sql2 = 'SELECT *
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE post_msg_id = '. $row['post_id'] .'
|
||||
AND in_message = 0
|
||||
ORDER BY filetime DESC';
|
||||
$result2 = $this->db->sql_query($sql2);
|
||||
|
||||
while ($row2 = $this->db->sql_fetchrow($result2))
|
||||
{
|
||||
$attachments[] = $row2;
|
||||
}
|
||||
$this->db->sql_freeresult($result2);
|
||||
}
|
||||
|
||||
$posts[$i]['bbcode_uid'] = $row['bbcode_uid'];
|
||||
$len_check = $row['post_text'];
|
||||
$maxlen = $text_length;
|
||||
|
||||
if (($text_length != 0) && (strlen($len_check) > $text_length))
|
||||
{
|
||||
$message = str_replace(array("\n", "\r"), array('<br />', "\n"), $row['post_text']);
|
||||
$message = get_sub_taged_string($message, $row['bbcode_uid'], $maxlen);
|
||||
$posts[$i]['striped'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = str_replace("\n", '<br/> ', $row['post_text']);
|
||||
}
|
||||
|
||||
$row['bbcode_options'] = (($row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
|
||||
$message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
|
||||
|
||||
if (!empty($attachments))
|
||||
{
|
||||
parse_attachments($row['forum_id'], $message, $attachments, $update_count);
|
||||
}
|
||||
|
||||
if ($this->global_id < 1)
|
||||
{
|
||||
$this->global_id = $row['forum_id'];
|
||||
}
|
||||
|
||||
$topic_icons[] = $row['enable_icons'];
|
||||
$have_icons = ($row['icon_id'] > 0) ? 1 : $have_icons;
|
||||
|
||||
$posts[$i] = array_merge($posts[$i], array(
|
||||
'post_text' => ap_validate($message),
|
||||
'topic_id' => $row['topic_id'],
|
||||
'topic_last_post_id' => $row['topic_last_post_id'],
|
||||
'topic_type' => $row['topic_type'],
|
||||
'topic_posted' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
|
||||
'icon_id' => $row['icon_id'],
|
||||
'topic_status' => $row['topic_status'],
|
||||
'forum_id' => $row['forum_id'],
|
||||
'topic_replies' => $row['topic_posts_approved'] + $row['topic_posts_unapproved'] + $row['topic_posts_softdeleted'],
|
||||
'topic_replies_real' => $row['topic_posts_approved'],
|
||||
'topic_time' => $this->user->format_date($row['post_time']),
|
||||
'topic_last_post_time' => $row['topic_last_post_time'],
|
||||
'topic_title' => $row['topic_title'],
|
||||
'username' => $row['username'],
|
||||
'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['post_username']),
|
||||
'username_full_last' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour'], $row['topic_last_poster_name']),
|
||||
'user_id' => $row['user_id'],
|
||||
'user_type' => $row['user_type'],
|
||||
'user_colour' => $row['user_colour'],
|
||||
'poll' => ($row['poll_title']) ? true : false,
|
||||
'attachment' => ($row['topic_attachment']) ? true : false,
|
||||
'topic_views' => $row['topic_views'],
|
||||
'forum_name' => $row['forum_name'],
|
||||
'attachments' => (!empty($attachments)) ? $attachments : array(),
|
||||
));
|
||||
$posts['global_id'] = $this->global_id;
|
||||
++$i;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$posts['topic_icons'] = ((max($topic_icons) > 0) && $have_icons) ? true : false;
|
||||
$posts['topic_count'] = $i;
|
||||
|
||||
if ($this->global_id < 1)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $posts;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run SQL query for fetching posts from database
|
||||
*
|
||||
* @param int $post_time Post time
|
||||
* @param int $number_of_posts Number of posts to fetch
|
||||
* @param int $start Start of query
|
||||
*
|
||||
* @return int Result pointer
|
||||
*/
|
||||
protected function run_sql_query($post_time, $number_of_posts, $start)
|
||||
{
|
||||
$sql_array = array(
|
||||
'SELECT' => 't.forum_id,
|
||||
t.topic_id,
|
||||
t.topic_last_post_id,
|
||||
t.topic_last_post_time,
|
||||
t.topic_time,
|
||||
t.topic_title,
|
||||
t.topic_attachment,
|
||||
t.topic_views,
|
||||
t.poll_title,
|
||||
t.topic_posts_approved,
|
||||
t.topic_posts_unapproved,
|
||||
t.topic_posts_softdeleted,
|
||||
t.topic_poster,
|
||||
t.topic_type,
|
||||
t.topic_status,
|
||||
t.topic_last_poster_name,
|
||||
t.topic_last_poster_id,
|
||||
t.topic_last_poster_colour,
|
||||
t.icon_id,
|
||||
u.username,
|
||||
u.user_id,
|
||||
u.user_type,
|
||||
u.user_colour,
|
||||
p.post_id,
|
||||
p.poster_id,
|
||||
p.post_time,
|
||||
p.post_text,
|
||||
p.post_attachment,
|
||||
p.post_username,
|
||||
p.enable_smilies,
|
||||
p.enable_bbcode,
|
||||
p.enable_magic_url,
|
||||
p.bbcode_bitfield,
|
||||
p.bbcode_uid,
|
||||
f.forum_name,
|
||||
f.enable_icons',
|
||||
'FROM' => array(
|
||||
TOPICS_TABLE => 't',
|
||||
),
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(USERS_TABLE => 'u'),
|
||||
'ON' => $this->user_link,
|
||||
),
|
||||
array(
|
||||
'FROM' => array(FORUMS_TABLE => 'f'),
|
||||
'ON' => 't.forum_id=f.forum_id',
|
||||
),
|
||||
array(
|
||||
'FROM' => array(POSTS_TABLE => 'p'),
|
||||
'ON' => $this->post_link,
|
||||
),
|
||||
),
|
||||
'WHERE' => $this->topic_type . '
|
||||
' . $post_time . '
|
||||
AND t.topic_status <> ' . ITEM_MOVED . '
|
||||
AND t.topic_visibility = 1
|
||||
AND t.topic_moved_id = 0
|
||||
' . $this->where_string,
|
||||
'ORDER_BY' => $this->topic_order,
|
||||
);
|
||||
|
||||
$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $this->user->data['user_id']);
|
||||
$sql_array['SELECT'] .= ', tp.topic_posted';
|
||||
$sql = $this->db->sql_build_query('SELECT', $sql_array);
|
||||
|
||||
if ($number_of_posts != 0)
|
||||
{
|
||||
$result = $this->db->sql_query_limit($sql, $number_of_posts, $start);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->db->sql_query($sql);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type constraints for database query
|
||||
*
|
||||
* @return null
|
||||
* @throws \InvalidArgumentexception If unknown type is used
|
||||
*/
|
||||
protected function get_type_constraints()
|
||||
{
|
||||
switch($this->type)
|
||||
{
|
||||
case "announcements":
|
||||
$this->get_announcements_constraints();
|
||||
break;
|
||||
case "news":
|
||||
$this->get_news_constraints();
|
||||
break;
|
||||
case "news_all":
|
||||
$this->get_news_all_constraints();
|
||||
break;
|
||||
|
||||
default:
|
||||
// Method was called with unsupported type
|
||||
throw new \InvalidArgumentexception($this->user->lang('B3P_WRONG_METHOD_CALL', __FUNCTION__));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type constraints for announcements
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function get_announcements_constraints()
|
||||
{
|
||||
$this->topic_type = '((t.topic_type = ' . POST_ANNOUNCE . ') OR (t.topic_type = ' . POST_GLOBAL . '))';
|
||||
$this->where_string = (strlen($this->where_string) > 0) ? 'AND (t.forum_id = 0 OR (' . trim(substr($this->where_string, 0, -4)) . '))' : '';
|
||||
$this->user_link = 't.topic_poster = u.user_id';
|
||||
$this->post_link = 't.topic_first_post_id = p.post_id';
|
||||
$this->topic_order = 't.topic_time DESC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type constraints for news
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function get_news_constraints()
|
||||
{
|
||||
$this->topic_type = 't.topic_type = ' . POST_NORMAL;
|
||||
$this->where_string = (strlen($this->where_string) > 0) ? 'AND (' . trim(substr($this->where_string, 0, -4)) . ')' : '';
|
||||
$this->user_link = ($this->config['board3_news_style_' . $this->module_id]) ? 't.topic_poster = u.user_id' : (($this->config['board3_news_show_last_' . $this->module_id]) ? 't.topic_last_poster_id = u.user_id' : 't.topic_poster = u.user_id' ) ;
|
||||
$this->post_link = ($this->config['board3_news_style_' . $this->module_id]) ? 't.topic_first_post_id = p.post_id' : (($this->config['board3_news_show_last_' . $this->module_id]) ? 't.topic_last_post_id = p.post_id' : 't.topic_first_post_id = p.post_id' ) ;
|
||||
$this->topic_order = ($this->config['board3_news_show_last_' . $this->module_id]) ? 't.topic_last_post_time DESC' : 't.topic_time DESC' ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional type constraints for all news
|
||||
* Overwrites topic type of get_news_constraints().
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function get_news_all_constraints()
|
||||
{
|
||||
$this->get_news_constraints();
|
||||
$this->topic_type = '(t.topic_type <> ' . POST_ANNOUNCE . ') AND (t.topic_type <> ' . POST_GLOBAL . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set module id
|
||||
*
|
||||
* @param int $module_id Module ID
|
||||
* @return null
|
||||
*/
|
||||
public function set_module_id($module_id)
|
||||
{
|
||||
$this->module_id = $module_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set forums to exclude or include
|
||||
*
|
||||
* @param array $forum_from Forums that should be shown or
|
||||
* excluded from being shown
|
||||
* @param array $disallowed_forums Forums that user is not
|
||||
* allowed to see
|
||||
* @param bool $invert Whether forum IDs in forum_from
|
||||
* should be used for excluding or
|
||||
* including forums
|
||||
* @return bool True if valid constraints were generated, false if not
|
||||
*/
|
||||
protected function set_forum_constraints($forum_from, $disallowed_forums, $invert = false)
|
||||
{
|
||||
if ($invert == true)
|
||||
{
|
||||
$access_list = array_merge($disallowed_forums, $forum_from);
|
||||
$sql_operator = '<>';
|
||||
$sql_append = 'AND';
|
||||
}
|
||||
else
|
||||
{
|
||||
$access_list = array_diff($forum_from, $disallowed_forums);
|
||||
$sql_operator = '=';
|
||||
$sql_append = 'OR';
|
||||
|
||||
if (empty($access_list) && !empty($forum_from))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate where string
|
||||
$this->generate_where_string($access_list, $sql_operator, $sql_append);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate where string for database query
|
||||
*
|
||||
* @param array $access_list Array containing the forum IDs
|
||||
* the user has access to
|
||||
* @param string $sql_operator The sql operator to use
|
||||
* @param string $sql_append The sql append type to use.
|
||||
* Should be either AND or OR
|
||||
* @return null
|
||||
*/
|
||||
protected function generate_where_string($access_list, $sql_operator, $sql_append)
|
||||
{
|
||||
foreach ($access_list as $acc_id)
|
||||
{
|
||||
$acc_id = (int) $acc_id;
|
||||
$this->where_string .= 't.forum_id ' . $sql_operator . " $acc_id $sql_append ";
|
||||
if ($sql_operator === '=' && $this->type == 'announcements' && $this->global_id < 1 && $acc_id > 0)
|
||||
{
|
||||
$this->global_id = $acc_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the a global forum ID for global announcements
|
||||
*
|
||||
* @return bool True if proper ID was selected, false if not
|
||||
*/
|
||||
protected function get_global_id()
|
||||
{
|
||||
if ($this->type == 'announcements' && $this->global_id < 1)
|
||||
{
|
||||
if (!empty($this->where_string) || ($row = $this->cache->get('_forum_id_first_forum_post')) === false)
|
||||
{
|
||||
$row = $this->get_first_forum_id();
|
||||
}
|
||||
|
||||
if (empty($row))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$this->global_id = $row['forum_id'];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first forum_id of FORUM_POST type forums
|
||||
*
|
||||
* @return array Database row of query
|
||||
*/
|
||||
protected function get_first_forum_id()
|
||||
{
|
||||
$sql = 'SELECT forum_id
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE forum_type = ' . FORUM_POST . '
|
||||
' . str_replace('t.', '', $this->where_string) . '
|
||||
ORDER BY forum_id';
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (empty($this->where_string))
|
||||
{
|
||||
// Cache first forum ID for one day = 86400 s
|
||||
$this->cache->put('_forum_id_first_forum_post', $row, 86400);
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets constraints that might have been set before
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function reset_constraints()
|
||||
{
|
||||
$this->where_string = '';
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(false));
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_content.php');
|
||||
$config = new \phpbb\config\config(array('allow_attachments' => 1));
|
||||
$this->config = new \phpbb\config\config(array('allow_attachments' => 1));
|
||||
$auth = new \phpbb\auth\auth();
|
||||
$userdata = array(
|
||||
'user_id' => 2,
|
||||
@@ -48,8 +48,12 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
|
||||
$auth->acl[0][0] = true;
|
||||
// Pretend to allow downloads in forum 1
|
||||
$auth->acl[1][0] = true;
|
||||
$this->auth = $auth;
|
||||
$this->user = $user;
|
||||
$phpbb_container = new \phpbb_mock_container_builder();
|
||||
$phpbb_container->set('board3.portal.modules_helper', new \board3\portal\includes\modules_helper($auth));
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth);
|
||||
$phpbb_container->set('board3.portal.modules_helper', $this->modules_helper);
|
||||
$phpbb_container->set('board3.portal.fetch_posts', new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user));
|
||||
$template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display'));
|
||||
}
|
||||
|
||||
@@ -223,7 +227,7 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
|
||||
|
||||
public function test_cached_first_forum_id()
|
||||
{
|
||||
global $cache;
|
||||
global $cache, $phpbb_container;
|
||||
|
||||
$cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'get', 'sql_exists', 'put'));
|
||||
$cache->expects($this->any())
|
||||
@@ -235,6 +239,7 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$phpbb_container->set('board3.portal.fetch_posts', new \board3\portal\portal\fetch_posts($this->auth, $cache, $this->config, $this->db, $this->modules_helper, $this->user));
|
||||
$fetch_posts = phpbb_fetch_posts(5, '', false, 5, 150, time(), 'announcements');
|
||||
$this->assertEmpty($fetch_posts);
|
||||
}
|
||||
|
||||
259
tests/unit/portal/fetch_posts_test.php
Normal file
259
tests/unit/portal/fetch_posts_test.php
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package Board3 Portal Testing
|
||||
* @copyright (c) Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_acp.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php');
|
||||
|
||||
class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
protected $default_main_columns = array('topic_count', 'global_id', 'topic_icons');
|
||||
protected $fetch_posts;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
global $auth, $cache, $phpbb_dispatcher, $template, $user;;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$user = new \phpbb\user();
|
||||
$user->data['user_id'] = 2;
|
||||
$user->timezone = new \DateTimeZone('UTC');
|
||||
$user->add_lang('common');
|
||||
$user->add_lang('../../ext/board3/portal/language/en/portal');
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
$cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'get', 'sql_exists', 'put', 'obtain_attach_extensions'));
|
||||
$cache->expects($this->any())
|
||||
->method('obtain_word_list')
|
||||
->with()
|
||||
->will($this->returnValue(array()));
|
||||
$cache->expects($this->any())
|
||||
->method('get')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(false));
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_content.php');
|
||||
$this->config = new \phpbb\config\config(array('allow_attachments' => 1));
|
||||
$auth = new \phpbb\auth\auth();
|
||||
$userdata = array(
|
||||
'user_id' => 2,
|
||||
);
|
||||
$auth->acl($userdata);
|
||||
// Pretend to allow downloads
|
||||
$auth->acl[0][0] = true;
|
||||
// Pretend to allow downloads in forum 1
|
||||
$auth->acl[1][0] = true;
|
||||
$this->auth = $auth;
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth);
|
||||
$this->user = $user;
|
||||
$template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display'));
|
||||
$this->fetch_posts = new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user);
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/news.xml');
|
||||
}
|
||||
|
||||
public function data_phpbb_fetch_news()
|
||||
{
|
||||
return array(
|
||||
array('news', array(
|
||||
'forum_id',
|
||||
'topic_id',
|
||||
'topic_last_post_time',
|
||||
'topic_replies',
|
||||
'topic_replies_real',
|
||||
'topic_type',
|
||||
'topic_status',
|
||||
'topic_posted',
|
||||
'attachment',
|
||||
'forum_name',
|
||||
'topic_title',
|
||||
'username',
|
||||
'username_full',
|
||||
'username_full_last',
|
||||
'user_type',
|
||||
'user_id',
|
||||
'topic_time',
|
||||
'post_text',
|
||||
'topic_views',
|
||||
'icon_id',
|
||||
'poll',
|
||||
'attachments',
|
||||
'forum_name',
|
||||
)),
|
||||
array('news_all', array(
|
||||
'forum_id',
|
||||
'topic_id',
|
||||
'topic_last_post_time',
|
||||
'topic_replies',
|
||||
'topic_replies_real',
|
||||
'topic_type',
|
||||
'topic_status',
|
||||
'topic_posted',
|
||||
'attachment',
|
||||
'forum_name',
|
||||
'topic_title',
|
||||
'username',
|
||||
'username_full',
|
||||
'username_full_last',
|
||||
'user_type',
|
||||
'user_id',
|
||||
'topic_time',
|
||||
'post_text',
|
||||
'topic_views',
|
||||
'icon_id',
|
||||
'poll',
|
||||
'attachments',
|
||||
'forum_name',
|
||||
)),
|
||||
array('announcements', array(), array('topic_icons', 'topic_count'), 5, ''),
|
||||
array('news', array(), array(), 0),
|
||||
array('foobar', array(), array(), 5, '', false, false, false, 150, '\InvalidArgumentException'),
|
||||
array('news', array(
|
||||
'forum_id',
|
||||
'topic_id',
|
||||
'topic_last_post_time',
|
||||
'topic_replies',
|
||||
'topic_replies_real',
|
||||
'topic_type',
|
||||
'topic_status',
|
||||
'topic_posted',
|
||||
'attachment',
|
||||
'forum_name',
|
||||
'topic_title',
|
||||
'username',
|
||||
'username_full',
|
||||
'username_full_last',
|
||||
'user_type',
|
||||
'user_id',
|
||||
'topic_time',
|
||||
'post_text',
|
||||
'topic_views',
|
||||
'icon_id',
|
||||
'poll',
|
||||
'attachments',
|
||||
'forum_name',
|
||||
), array(), 5, '', false, true),
|
||||
array('announcements', array(), array('topic_icons', 'topic_count'), 5, '3'),
|
||||
array('announcements', array(), array('topic_icons', 'topic_count'), 5, '1,2', false, true),
|
||||
array('news', array(), array(), 5, '1,2', true, false, true),
|
||||
array('announcements', array(), array('topic_icons', 'topic_count'), 5, '', false, true),
|
||||
array('announcements', array(), array(), 5, '1,2', true, true, true),
|
||||
array('news', array(
|
||||
'forum_id',
|
||||
'topic_id',
|
||||
'topic_last_post_time',
|
||||
'topic_replies',
|
||||
'topic_replies_real',
|
||||
'topic_type',
|
||||
'topic_status',
|
||||
'topic_posted',
|
||||
'attachment',
|
||||
'forum_name',
|
||||
'topic_title',
|
||||
'username',
|
||||
'username_full',
|
||||
'username_full_last',
|
||||
'user_type',
|
||||
'user_id',
|
||||
'topic_time',
|
||||
'post_text',
|
||||
'topic_views',
|
||||
'icon_id',
|
||||
'poll',
|
||||
'attachments',
|
||||
'forum_name',
|
||||
), array(), 5, '', false, true, false, 5),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_phpbb_fetch_news
|
||||
*/
|
||||
public function test_phpbb_fetch_news($type, $expected_columns, $expected_main_columns = array(), $number_of_posts = 5, $forum_from = '', $empty = false, $permissions = false,
|
||||
$invert = false, $text_length = 150, $expected_exception = false)
|
||||
{
|
||||
$module_id = 5;
|
||||
$time = time();
|
||||
$start = 0;
|
||||
|
||||
if ($expected_exception)
|
||||
{
|
||||
$this->setExpectedException($expected_exception);
|
||||
}
|
||||
|
||||
$this->fetch_posts->set_module_id($module_id);
|
||||
$fetch_posts = $this->fetch_posts->get_posts($forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start, $invert);
|
||||
|
||||
if (!$empty)
|
||||
{
|
||||
if (empty($expected_main_columns))
|
||||
{
|
||||
$expected_main_columns = $this->default_main_columns;
|
||||
}
|
||||
|
||||
foreach ($expected_main_columns as $main_column)
|
||||
{
|
||||
$this->assertArrayHasKey($main_column, $fetch_posts);
|
||||
unset($fetch_posts[$main_column]);
|
||||
}
|
||||
|
||||
foreach ($fetch_posts as $post)
|
||||
{
|
||||
foreach ($expected_columns as $column)
|
||||
{
|
||||
$this->assertArrayHasKey($column, $post);
|
||||
$this->assertNotNull($post[$column]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!empty($fetch_posts))
|
||||
{
|
||||
var_export($fetch_posts);
|
||||
}
|
||||
$this->assertEmpty($fetch_posts);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_cached_first_forum_id()
|
||||
{
|
||||
global $cache;
|
||||
|
||||
$cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'get', 'sql_exists', 'put'));
|
||||
$cache->expects($this->any())
|
||||
->method('obtain_word_list')
|
||||
->with()
|
||||
->will($this->returnValue(array()));
|
||||
$cache->expects($this->any())
|
||||
->method('get')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$this->fetch_posts = new \board3\portal\portal\fetch_posts($this->auth, $cache, $this->config, $this->db, $this->modules_helper, $this->user);
|
||||
$this->fetch_posts->set_module_id(5);
|
||||
|
||||
$fetch_posts = $this->fetch_posts->get_posts('', false, 5, 150, time(), 'announcements');
|
||||
$this->assertEmpty($fetch_posts);
|
||||
}
|
||||
|
||||
public function test_no_allowed_forums()
|
||||
{
|
||||
global $auth;
|
||||
|
||||
$auth = new \phpbb\auth\auth();
|
||||
|
||||
$this->fetch_posts->set_module_id(5);
|
||||
$fetch_posts = $this->fetch_posts->get_posts('2', true, 5, 150, time(), 'announcements');
|
||||
$this->assertSame(array(), $fetch_posts);
|
||||
}
|
||||
}
|
||||
193
tests/unit/portal/fixtures/news.xml
Normal file
193
tests/unit/portal/fixtures/news.xml
Normal file
@@ -0,0 +1,193 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_acl_options">
|
||||
<column>auth_option_id</column>
|
||||
<column>auth_option</column>
|
||||
<column>is_global</column>
|
||||
<column>is_local</column>
|
||||
<column>founder_only</column>
|
||||
<row>
|
||||
<value>93</value>
|
||||
<value>u_download</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>7</value>
|
||||
<value>f_download</value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_attachments">
|
||||
<column>attach_id</column>
|
||||
<column>post_msg_id</column>
|
||||
<column>topic_id</column>
|
||||
<column>poster_id</column>
|
||||
<column>physical_filename</column>
|
||||
<column>real_filename</column>
|
||||
<column>attach_comment</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>foobar</value>
|
||||
<value>foobar</value>
|
||||
<value>foobar</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_topics">
|
||||
<column>forum_id</column>
|
||||
<column>topic_id</column>
|
||||
<column>topic_last_post_id</column>
|
||||
<column>topic_last_post_time</column>
|
||||
<column>topic_time</column>
|
||||
<column>topic_title</column>
|
||||
<column>topic_attachment</column>
|
||||
<column>topic_views</column>
|
||||
<column>poll_title</column>
|
||||
<column>topic_posts_approved</column>
|
||||
<column>topic_posts_unapproved</column>
|
||||
<column>topic_posts_softdeleted</column>
|
||||
<column>topic_poster</column>
|
||||
<column>topic_type</column>
|
||||
<column>topic_status</column>
|
||||
<column>topic_last_poster_name</column>
|
||||
<column>topic_last_poster_id</column>
|
||||
<column>topic_last_poster_colour</column>
|
||||
<column>icon_id</column>
|
||||
<column>topic_visibility</column>
|
||||
<column>topic_first_post_id</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>1404830663</value>
|
||||
<value>1404830663</value>
|
||||
<value>test post</value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value>foobar</value>
|
||||
<value>2</value>
|
||||
<value></value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_posts">
|
||||
<column>post_id</column>
|
||||
<column>poster_id</column>
|
||||
<column>post_time</column>
|
||||
<column>post_text</column>
|
||||
<column>post_attachment</column>
|
||||
<column>post_username</column>
|
||||
<column>enable_smilies</column>
|
||||
<column>enable_bbcode</column>
|
||||
<column>enable_magic_url</column>
|
||||
<column>bbcode_bitfield</column>
|
||||
<column>bbcode_uid</column>
|
||||
<column>forum_id</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>1404830663</value>
|
||||
<value>foobar post</value>
|
||||
<value>1</value>
|
||||
<value>foobar</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value>1404830663</value>
|
||||
<value>foobar post</value>
|
||||
<value>0</value>
|
||||
<value>foobar</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_forums">
|
||||
<column>forum_id</column>
|
||||
<column>parent_id</column>
|
||||
<column>forum_parents</column>
|
||||
<column>forum_desc</column>
|
||||
<column>forum_rules</column>
|
||||
<column>forum_type</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_topics_posted">
|
||||
<column>topic_id</column>
|
||||
<column>user_id</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_users">
|
||||
<column>username</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_id</column>
|
||||
<column>user_type</column>
|
||||
<column>user_colour</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<row>
|
||||
<value>foobar</value>
|
||||
<value>foobar</value>
|
||||
<value>2</value>
|
||||
<value>5</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>barfoo</value>
|
||||
<value>barfoo</value>
|
||||
<value>3</value>
|
||||
<value>5</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
||||
17
travis/run-coveralls.sh
Executable file
17
travis/run-coveralls.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# This file is part of the Board3 Portal package.
|
||||
#
|
||||
# @copyright (c) Board3 Group <http://www.board3.de>
|
||||
# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
#
|
||||
set -e
|
||||
set -x
|
||||
|
||||
DB=$1
|
||||
TRAVIS_PHP_VERSION=$2
|
||||
|
||||
if [ "$TRAVIS_PHP_VERSION" == "5.5" -a "$DB" == "mysqli" ]
|
||||
then
|
||||
php ../board3/Board3-Portal/vendor/bin/coveralls -v
|
||||
fi
|
||||
Reference in New Issue
Block a user