Skip to content

Commit

Permalink
Merge branch 'master' into release-2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
iMattPro committed Sep 15, 2015
2 parents 1cfaace + c00990b commit 352c36c
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 231 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ env:
- EPV="1" # Should we run EPV (Extension Pre Validator) on your code?
- PHPBB_BRANCH="3.1.x"

#branches:
# only:
# - master
# - develop
# - /^develop-.*$/
branches:
only:
- master
- develop
- /^develop-.*$/

install:
- composer install --dev --no-interaction --prefer-source
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ A phpBB 3.1 extension that displays a short excerpt of text from the first post
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/VSEphpbb/topicpreview/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/VSEphpbb/topicpreview/?branch=master)

## Browser support
![Chrome 4+](http://mattfriedman.me/software/browsericons/chrome.png "Chrome 4+")4+    
![Firefox 3.5+](http://mattfriedman.me/software/browsericons/firefox.png "Firefox 3.5+")3.5+    
![Safari 3+](http://mattfriedman.me/software/browsericons/safari.png "Safari 3+")3+    
![Internet Explorer 6+](http://mattfriedman.me/software/browsericons/ie.png "Internet Explorer 6+")6+    
![Opera 10.5+](http://mattfriedman.me/software/browsericons/opera.png "Opera 10.5+")10.5+
![Chrome 4+](http://vsephpbb.github.io/browsericons/chrome.png "Chrome 4+")4+    
![Firefox 3.5+](http://vsephpbb.github.io/browsericons/firefox.png "Firefox 3.5+")3.5+    
![Safari 3+](http://vsephpbb.github.io/browsericons/safari.png "Safari 3+")3+    
![Internet Explorer 6+](http://vsephpbb.github.io/browsericons/ie.png "Internet Explorer 6+")6+    
![Opera 10.5+](http://vsephpbb.github.io/browsericons/opera.png "Opera 10.5+")10.5+

## Features
* Let your visitors peek at what's inside a topic before they click on it
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"extra": {
"display-name": "Topic Preview",
"soft-require": {
"phpbb/phpbb": ">=3.1.2,<3.2.*@dev"
"phpbb/phpbb": ">=3.1.2"
},
"version-check": {
"host": "www.phpbb.com",
Expand Down
14 changes: 10 additions & 4 deletions config/services.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
services:
vse.topicpreview.manager:
class: vse\topicpreview\core\topic_preview
vse.topicpreview.data:
class: vse\topicpreview\core\data
arguments:
- @config
- @user

vse.topicpreview.display:
class: vse\topicpreview\core\display
arguments:
- @config
- @dbal.conn
- @dispatcher
- @template
- @user
Expand All @@ -18,7 +23,8 @@ services:
vse.topicpreview.listener:
class: vse\topicpreview\event\listener
arguments:
- @vse.topicpreview.manager
- @vse.topicpreview.data
- @vse.topicpreview.display
tags:
- { name: event.listener }

Expand Down
66 changes: 66 additions & 0 deletions core/base.php
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'];
}
}
134 changes: 134 additions & 0 deletions core/data.php
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;
}
}
Loading

0 comments on commit 352c36c

Please sign in to comment.