-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into release-2.2.2
- Loading branch information
Showing
13 changed files
with
293 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* | ||
* Topic Preview | ||
* | ||
* @copyright (c) 2013 Matt Friedman | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
*/ | ||
|
||
namespace vse\topicpreview\core; | ||
|
||
class base | ||
{ | ||
/** @var \phpbb\config\config */ | ||
protected $config; | ||
|
||
/** @var \phpbb\user */ | ||
protected $user; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \phpbb\config\config $config | ||
* @param \phpbb\user $user | ||
* @access public | ||
*/ | ||
public function __construct(\phpbb\config\config $config, \phpbb\user $user) | ||
{ | ||
$this->config = $config; | ||
$this->user = $user; | ||
} | ||
|
||
/** | ||
* Show topic previews, given current board and user configurations | ||
* | ||
* @return bool | ||
* @access public | ||
*/ | ||
public function is_enabled() | ||
{ | ||
return (bool) !empty($this->config['topic_preview_limit']) && !empty($this->user->data['user_topic_preview']); | ||
} | ||
|
||
/** | ||
* Show avatars, given current board and user configurations | ||
* | ||
* @return bool | ||
* @access public | ||
*/ | ||
public function avatars_enabled() | ||
{ | ||
return (bool) $this->config['topic_preview_avatars'] && $this->config['allow_avatar'] && $this->user->optionget('viewavatars'); | ||
} | ||
|
||
/** | ||
* Show last post text, given current board configuration | ||
* | ||
* @return bool | ||
* @access public | ||
*/ | ||
public function last_post_enabled() | ||
{ | ||
return (bool) $this->config['topic_preview_last_post']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
/** | ||
* | ||
* Topic Preview | ||
* | ||
* @copyright (c) 2013 Matt Friedman | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
*/ | ||
|
||
namespace vse\topicpreview\core; | ||
|
||
class data extends base | ||
{ | ||
/** | ||
* Update an SQL SELECT statement to get data needed for topic previews | ||
* | ||
* @return string SQL SELECT appendage | ||
* @access public | ||
*/ | ||
public function tp_sql_select() | ||
{ | ||
$sql = ', fp.post_text AS first_post_text'; | ||
|
||
if ($this->last_post_enabled()) | ||
{ | ||
$sql .= ', lp.post_text AS last_post_text'; | ||
} | ||
|
||
if ($this->avatars_enabled()) | ||
{ | ||
$sql .= ', fpu.user_avatar AS fp_avatar, | ||
fpu.user_avatar_type AS fp_avatar_type, | ||
fpu.user_avatar_width AS fp_avatar_width, | ||
fpu.user_avatar_height AS fp_avatar_height'; | ||
|
||
if ($this->last_post_enabled()) | ||
{ | ||
$sql .= ', lpu.user_avatar AS lp_avatar, | ||
lpu.user_avatar_type AS lp_avatar_type, | ||
lpu.user_avatar_width AS lp_avatar_width, | ||
lpu.user_avatar_height AS lp_avatar_height'; | ||
} | ||
} | ||
|
||
return $sql; | ||
} | ||
|
||
/** | ||
* Update an SQL JOIN statement to get data needed for topic previews | ||
* | ||
* @return array SQL JOIN params | ||
* @access public | ||
*/ | ||
public function tp_sql_join() | ||
{ | ||
$sql_array = array(); | ||
|
||
$sql_array['LEFT_JOIN'][] = array( | ||
'FROM' => array(POSTS_TABLE => 'fp'), | ||
'ON' => 'fp.post_id = t.topic_first_post_id' | ||
); | ||
|
||
if ($this->avatars_enabled()) | ||
{ | ||
$sql_array['LEFT_JOIN'][] = array( | ||
'FROM' => array(USERS_TABLE => 'fpu'), | ||
'ON' => 'fpu.user_id = t.topic_poster' | ||
); | ||
} | ||
|
||
if ($this->last_post_enabled()) | ||
{ | ||
$sql_array['LEFT_JOIN'][] = array( | ||
'FROM' => array(POSTS_TABLE => 'lp'), | ||
'ON' => 'lp.post_id = t.topic_last_post_id' | ||
); | ||
|
||
if ($this->avatars_enabled()) | ||
{ | ||
$sql_array['LEFT_JOIN'][] = array( | ||
'FROM' => array(USERS_TABLE => 'lpu'), | ||
'ON' => 'lpu.user_id = t.topic_last_poster_id' | ||
); | ||
} | ||
} | ||
|
||
return $sql_array; | ||
} | ||
|
||
/** | ||
* Modify SQL string|array to get post text | ||
* | ||
* @param string|array $sql_stmt SQL string or array to be modified | ||
* @param string $type Type of SQL statement SELECT|JOIN | ||
* @return string|array SQL statement string or array | ||
* @access public | ||
*/ | ||
public function modify_sql($sql_stmt, $type = 'SELECT') | ||
{ | ||
if (!$this->is_enabled()) | ||
{ | ||
return $sql_stmt; | ||
} | ||
|
||
if (is_array($sql_stmt)) | ||
{ | ||
$array = $this->tp_sql_join(); | ||
foreach ($array['LEFT_JOIN'] as $join) | ||
{ | ||
$sql_stmt['LEFT_JOIN'][] = $join; | ||
} | ||
|
||
$sql_stmt['SELECT'] .= $this->tp_sql_select(); | ||
} | ||
else | ||
{ | ||
if ($type == 'SELECT') | ||
{ | ||
$sql_stmt .= $this->tp_sql_select(); | ||
} | ||
else | ||
{ | ||
$array = $this->tp_sql_join(); | ||
foreach ($array['LEFT_JOIN'] as $join) | ||
{ | ||
$sql_stmt .= ' LEFT JOIN ' . key($join['FROM']) . ' ' . current($join['FROM']) . ' ON (' . $join['ON'] . ')'; | ||
} | ||
} | ||
} | ||
|
||
return $sql_stmt; | ||
} | ||
} |
Oops, something went wrong.