* added featured article to tibiacom template (you can add them with add news button)

* added networks (facebook and twitter) and highscores (top 5) boxes to tibiacom template, configurable in templates/tibiacom/config.php
* fixed polls box in tibiacom template
* (internal) moved tibiacom boxes to separate directory
* (internal) renamed constant TICKET -> TICKER
This commit is contained in:
slawkens
2017-10-26 15:35:22 +02:00
parent 5e414ebda8
commit 583f3394fc
29 changed files with 795 additions and 121 deletions

View File

@@ -414,11 +414,11 @@ function short_text($text, $limit)
function tickers()
{
global $tickers_content;
global $tickers_content, $featured_article;
if(PAGE == 'news') {
if(isset($tickers_content))
return $tickers_content;
return $tickers_content . $featured_article;
}
return '';
@@ -949,6 +949,40 @@ function unsetSession($key) {
unset($_SESSION[$config['session_prefix'] . $key]);
}
function getTopPlayers($limit = 5) {
global $cache, $config, $db;
$fetch_from_db = true;
if($cache->enabled())
{
$tmp = '';
if($cache->fetch('top_' . $limit . '_level', $tmp))
{
$players = unserialize($tmp);
$fetch_from_db = false;
}
}
if($fetch_from_db)
{
$deleted = 'deleted';
if(fieldExist('deletion', 'players'))
$deleted = 'deletion';
$players = $db->query('SELECT `name`, `level`, `experience` FROM `players` WHERE `group_id` < ' . $config['highscores_groups_hidden'] . ' AND `' . $deleted . '` = 0 AND account_id != 1 ORDER BY `experience` DESC LIMIT 5')->fetchAll();
$i = 0;
foreach($players as &$player) {
$player['rank'] = ++$i;
}
if($cache->enabled())
$cache->set('top_' . $limit . '_level', serialize($players), 120);
}
return $players;
}
// validator functions
require_once(LIBS . 'validator.php');
require_once(SYSTEM . 'compat.php');

View File

@@ -108,7 +108,7 @@ class Plugins {
$query = $query->fetch();
$db->update(TABLE_PREFIX . 'hooks', array('type' => $hook, 'file' => $info['file']), array('id' => (int)$query['id']));
} else {
$db->insert(TABLE_PREFIX . 'hooks', array('id' => 'NULL', 'name' => $_name, 'type' => $hook, 'file' => $info['file']));
$db->insert(TABLE_PREFIX . 'hooks', array('id' => null, 'name' => $_name, 'type' => $hook, 'file' => $info['file']));
}
} else
self::$warnings[] = 'Unknown event type: ' . $info['type'];

6
system/migrations/18.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
$db->query("ALTER TABLE `" . TABLE_PREFIX . "news` ADD `article_text` VARCHAR(300) NOT NULL DEFAULT '' AFTER `comments`;");
$db->query("ALTER TABLE `" . TABLE_PREFIX . "news` ADD `article_image` VARCHAR(100) NOT NULL DEFAULT '' AFTER `article_text`;");
?>

View File

@@ -89,8 +89,8 @@ function clearCache()
if($cache->fetch('news' . $template_name . '_' . NEWS, $tmp))
$cache->delete('news' . $template_name . '_' . NEWS);
if($cache->fetch('news' . $template_name . '_' . TICKET, $tmp))
$cache->delete('news' . $template_name . '_' . TICKET);
if($cache->fetch('news' . $template_name . '_' . TICKER, $tmp))
$cache->delete('news' . $template_name . '_' . TICKER);
if($cache->fetch('template_ini' . $template_name, $tmp))
$cache->delete('template_ini' . $template_name);

View File

@@ -34,7 +34,7 @@ if(isset($_GET['archive']))
if($_REQUEST['id'] < 100000)
$field_name = 'id';
$news = $db->query('SELECT * FROM '.$db->tableName(TABLE_PREFIX . 'news').' WHERE `type` = 1 AND `hidden` != 1 AND `' . $field_name . '` = ' . (int)$_REQUEST['id'] . '');
$news = $db->query('SELECT * FROM `'.TABLE_PREFIX . 'news` WHERE `hidden` != 1 AND `' . $field_name . '` = ' . (int)$_REQUEST['id'] . '');
if($news->rowCount() == 1)
{
$news = $news->fetch();
@@ -102,21 +102,24 @@ $news_cached = false;
// some constants, used mainly by database (cannot by modified without schema changes)
define('TITLE_LIMIT', 100);
define('BODY_LIMIT', 65535); // maximum news body length
define('ARTICLE_TEXT_LIMIT', 300);
define('ARTICLE_IMAGE_LIMIT', 100);
$canEdit = hasFlag(FLAG_CONTENT_NEWS) || superAdmin();
if($canEdit)
{
if(!empty($action))
{
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : NULL;
$p_title = isset($_REQUEST['title']) ? $_REQUEST['title'] : NULL;
$body = isset($_REQUEST['body']) ? stripslashes($_REQUEST['body']) : NULL;
$comments = isset($_REQUEST['comments']) ? $_REQUEST['comments'] : NULL;
$type = isset($_REQUEST['type']) ? (int)$_REQUEST['type'] : NULL;
$category = isset($_REQUEST['category']) ? (int)$_REQUEST['category'] : NULL;
$player_id = isset($_REQUEST['player_id']) ? (int)$_REQUEST['player_id'] : NULL;
$forum_section = isset($_REQUEST['forum_section']) ? $_REQUEST['forum_section'] : NULL;
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
$p_title = isset($_REQUEST['title']) ? $_REQUEST['title'] : null;
$body = isset($_REQUEST['body']) ? stripslashes($_REQUEST['body']) : null;
$comments = isset($_REQUEST['comments']) ? $_REQUEST['comments'] : null;
$type = isset($_REQUEST['type']) ? (int)$_REQUEST['type'] : null;
$category = isset($_REQUEST['category']) ? (int)$_REQUEST['category'] : null;
$player_id = isset($_REQUEST['player_id']) ? (int)$_REQUEST['player_id'] : null;
$article_text = isset($_REQUEST['article_text']) ? $_REQUEST['article_text'] : null;
$article_image = isset($_REQUEST['article_image']) ? $_REQUEST['article_image'] : null;
$forum_section = isset($_REQUEST['forum_section']) ? $_REQUEST['forum_section'] : null;
$errors = array();
if($action == 'add') {
@@ -124,8 +127,8 @@ if($canEdit)
$forum_add = Forum::add_thread($p_title, $body, $forum_section, $player_id, $account_logged->getId(), $errors);
}
if(News::add($p_title, $body, $type, $category, $player_id, isset($forum_add) && $forum_add != 0 ? $forum_add : 0, $errors)) {
$p_title = $body = $comments = '';
if(News::add($p_title, $body, $type, $category, $player_id, isset($forum_add) && $forum_add != 0 ? $forum_add : 0, $article_text, $article_image, $errors)) {
$p_title = $body = $comments = $article_text = $article_image = '';
$type = $category = $player_id = 0;
}
}
@@ -142,15 +145,17 @@ if($canEdit)
$type = $news['type'];
$category = $news['category'];
$player_id = $news['player_id'];
$article_text = $news['article_text'];
$article_image = $news['article_image'];
}
else {
if(News::update($id, $p_title, $body, $type, $category, $player_id, $forum_section, $errors)) {
if(News::update($id, $p_title, $body, $type, $category, $player_id, $forum_section, $article_text, $article_image, $errors)) {
// update forum thread if exists
if(isset($forum_section) && Validator::number($forum_section)) {
$db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `author_guid` = ".(int) $player_id.", `post_text` = ".$db->quote($body).", `post_topic` = ".$db->quote($p_title).", `edit_date` = " . time() . " WHERE `id` = " . $db->quote($forum_section));
}
$action = $p_title = $body = $comments = '';
$action = $p_title = $body = $comments = $article_text = $article_image = '';
$type = $category = $player_id = 0;
}
}
@@ -165,7 +170,7 @@ if($canEdit)
if($cache->enabled())
{
$cache->set('news_' . $template_name . '_' . NEWS, '', 120);
$cache->set('news_' . $template_name . '_' . TICKET, '', 120);
$cache->set('news_' . $template_name . '_' . TICKER, '', 120);
}
}
}
@@ -176,7 +181,7 @@ if(!$news_cached)
{
$categories = array();
foreach($db->query(
'SELECT id, name, icon_id FROM ' . TABLE_PREFIX . 'news_categories WHERE hidden != 1') as $cat)
'SELECT `id`, `name`, `icon_id` FROM `' . TABLE_PREFIX . 'news_categories` WHERE `hidden` != 1') as $cat)
{
$categories[$cat['id']] = array(
'name' => $cat['name'],
@@ -186,11 +191,11 @@ if(!$news_cached)
$tickers_db =
$db->query(
'SELECT * FROM ' . $db->tableName(TABLE_PREFIX . 'news') . ' WHERE ' . $db->fieldName('type') . ' = ' . TICKET .
($canEdit ? '' : ' AND ' . $db->fieldName('hidden') . ' != 1') .
' ORDER BY ' . $db->fieldName('date') . ' DESC' .
' LIMIT ' . $config['news_ticker_limit']);
'SELECT * FROM `' . TABLE_PREFIX . 'news` WHERE `type` = ' . TICKER .
($canEdit ? '' : ' AND `hidden` != 1') .
' ORDER BY `date` DESC LIMIT ' . $config['news_ticker_limit']);
$tickers_content = '';
if($tickers_db->rowCount() > 0)
{
$tickers = $tickers_db->fetchAll();
@@ -199,20 +204,47 @@ if(!$news_cached)
$ticker['body_short'] = short_text(strip_tags($ticker['body']), 100);
}
$tickers_to_add = $twig->render('news.tickers.html.twig', array(
$tickers_content = $twig->render('news.tickers.html.twig', array(
'tickers' => $tickers,
'canEdit' => $canEdit
));
}
if($cache->enabled() && !$canEdit)
$cache->set('news_' . $template_name . '_' . TICKER, $tickers_content, 120);
$featured_article_db =
$db->query(
'SELECT `id`, `title`, `article_text`, `article_image`, `hidden` FROM `' . TABLE_PREFIX . 'news` WHERE `type` = ' . ARTICLE .
($canEdit ? '' : ' AND `hidden` != 1') .
' ORDER BY `date` DESC LIMIT 1');
$article = '';
if($featured_article_db->rowCount() > 0) {
$article = $featured_article_db->fetch();
$featured_article = '';
if($twig->getLoader()->exists('news.featured_article.html.twig')) {
$featured_article = $twig->render('news.featured_article.html.twig', array(
'article' => array(
'id' => $article['id'],
'title' => $article['title'],
'text' => $article['article_text'],
'image' => $article['article_image'],
'hidden' => $article['hidden'],
'read_more'=> getLink('news/archive/') . $article['id']
),
'canEdit' => $canEdit
));
}
if($cache->enabled() && !$canEdit)
$cache->set('news_' . $template_name . '_' . ARTICLE, $featured_article, 120);
}
}
else
$tickers_to_add = News::getCached(TICKET);
if(isset($tickers_to_add[0]))
{
$tickers_content = $tickers_to_add;
if($cache->enabled() && !$news_cached && !$canEdit)
$cache->set('news_' . $template_name . '_' . TICKET, $tickers_to_add, 120);
else {
$tickers_content = News::getCached(TICKER);
$featured_article = News::getCached(ARTICLE);
}
if(!$news_cached)
@@ -243,7 +275,9 @@ if(!$news_cached)
'categories' => $categories,
'forum_boards' => getForumBoards(),
'forum_section' => isset($forum_section) ? $forum_section : null,
'comments' => isset($comments) ? $comments : null
'comments' => isset($comments) ? $comments : null,
'article_text' => isset($article_text) ? $article_text : null,
'article_image' => isset($article_image) ? $article_image : null
));
}
@@ -271,7 +305,7 @@ if(!$news_cached)
$admin_options = '<br/><br/><a href="?subtopic=news&action=edit&id=' . $news['id'] . '" title="Edit">
<img src="images/edit.png"/>Edit
</a>
<a id="delete" href="' . BASE_URL . '?subtopic=news&action=delete&id=' . $news['id'] . '" onclick="return confirm(\'Are you sure?\');" title="Delete">
<a id="delete" href="?subtopic=news&action=delete&id=' . $news['id'] . '" onclick="return confirm(\'Are you sure?\');" title="Delete">
<img src="images/del.png"/>Delete
</a>
<a href="?subtopic=news&action=hide&id=' . $news['id'] . '" title="' . ($news['hidden'] != 1 ? 'Hide' : 'Show') . '">
@@ -292,13 +326,15 @@ if(!$news_cached)
}
echo $twig->render('news.html.twig', array(
'id' => $news['id'],
'title' => stripslashes($news['title']),
'content' => $content_ . $admin_options,
'date' => $news['date'],
'icon' => $categories[$news['category']]['icon_id'],
'author' => $config['news_author'] ? $author : '',
'comments' => $news['comments'] != 0 ? getForumThreadLink($news['comments']) : null,
'news_date_format' => $config['news_date_format']
'news_date_format' => $config['news_date_format'],
'hidden'=> $news['hidden']
));
}
}
@@ -316,7 +352,7 @@ else
class News
{
static public function verify($title, $body, &$errors)
static public function verify($title, $body, $article_text, $article_image, &$errors)
{
if(!isset($title[0]) || !isset($body[0])) {
$errors[] = 'Please fill all inputs.';
@@ -333,16 +369,26 @@ class News
return false;
}
if(strlen($article_text) > ARTICLE_TEXT_LIMIT) {
$errors[] = 'Article text cannot be longer than ' . ARTICLE_TEXT_LIMIT . ' characters.';
return false;
}
if(strlen($article_image) > ARTICLE_IMAGE_LIMIT) {
$errors[] = 'Article image cannot be longer than ' . ARTICLE_IMAGE_LIMIT . ' characters.';
return false;
}
return true;
}
static public function add($title, $body, $type, $category, $player_id, $comments, &$errors)
static public function add($title, $body, $type, $category, $player_id, $comments, $article_text, $article_image, &$errors)
{
global $db;
if(!News::verify($title, $body, $errors))
if(!self::verify($title, $body, $article_text, $article_image, $errors))
return false;
$db->insert(TABLE_PREFIX . 'news', array('title' => $title, 'body' => $body, 'type' => $type, 'date' => time(), 'category' => $category, 'player_id' => isset($player_id) ? $player_id : 0, 'comments' => $comments));
$db->insert(TABLE_PREFIX . 'news', array('title' => $title, 'body' => $body, 'type' => $type, 'date' => time(), 'category' => $category, 'player_id' => isset($player_id) ? $player_id : 0, 'comments' => $comments, 'article_text' => $article_text, 'article_image' => $article_image));
return true;
}
@@ -351,13 +397,13 @@ class News
return $db->select(TABLE_PREFIX . 'news', array('id' => $id));
}
static public function update($id, $title, $body, $type, $category, $player_id, $comments, &$errors)
static public function update($id, $title, $body, $type, $category, $player_id, $comments, $article_text, $article_image, &$errors)
{
global $db;
if(!News::verify($title, $body, $errors))
if(!self::verify($title, $body, $article_text, $article_image, $errors))
return false;
$db->update(TABLE_PREFIX . 'news', array('title' => $title, 'body' => $body, 'type' => $type, 'category' => $category, 'last_modified_by' => isset($player_id) ? $player_id : 0, 'last_modified_date' => time(), 'comments' => $comments), array('id' => $id));
$db->update(TABLE_PREFIX . 'news', array('title' => $title, 'body' => $body, 'type' => $type, 'category' => $category, 'last_modified_by' => isset($player_id) ? $player_id : 0, 'last_modified_date' => time(), 'comments' => $comments, 'article_text' => $article_text, 'article_image' => $article_image), array('id' => $id));
return true;
}
@@ -396,7 +442,7 @@ class News
static public function getCached($type)
{
global $cache, $config, $template_name;
global $cache, $template_name;
if($cache->enabled())
{
$tmp = '';

View File

@@ -20,10 +20,10 @@ CREATE TABLE `z_polls` (
`id` int(11) NOT NULL auto_increment,
`question` varchar(255) NOT NULL,
`description` varchar(255) NOT NULL,
`end` int(11) NOT NULL,
`start` int(11) NOT NULL,
`answers` int(11) NOT NULL,
`votes_all` int(11) NOT NULL,
`end` int(11) NOT NULL DEFAULT 0,
`start` int(11) NOT NULL DEFAULT 0,
`answers` int(11) NOT NULL DEFAULT 0,
`votes_all` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;');
@@ -33,7 +33,7 @@ $db->query('
`poll_id` int(11) NOT NULL,
`answer_id` int(11) NOT NULL,
`answer` varchar(255) NOT NULL,
`votes` int(11) NOT NULL
`votes` int(11) NOT NULL DEFAULT 0
) ENGINE=MyISAM DEFAULT CHARSET=latin1;');
if(!fieldExist('vote', 'accounts'))
@@ -346,10 +346,23 @@ function getColorByPercent($percent)
for( $x = 1; $x <= getSession('answers'); $x++ )
{
$INSERT_answer = $db->query('INSERT INTO `z_polls_answers` (`poll_id`,`answer_id`,`answer`) VALUES ('.$db->quote($id_next).','.$db->quote($x).','.$db->quote($_POST[$x]).')');
$db->insert('z_polls_answers', array(
'poll_id' => $id_next,
'answer_id' => $x,
'answer' => $_POST[$x],
'votes' => 0
));
}
$end = $time+24*60*60*$_POST['end'];
$INSERT_poll = $db->query('INSERT INTO `z_polls` (`id`,`question`, `description`,`end`,`answers`,`start`) VALUES ('.$db->quote($id_next).','.$db->quote($_POST['question']).','.$db->quote($_POST['description']).','.$db->quote($end).','.$db->quote(getSession('answers')).','.$db->quote($time).')');
$db->insert('z_polls', array(
'id' => $id_next,
'question' => $_POST['question'],
'description' => $_POST['description'],
'end' => $end,
'answers' => getSession('answers'),
'start' => $time,
'votes_all' => 0
));
}
$POLLS_check = $db->query('SELECT MAX(end) FROM '.$db->tableName('z_polls').'');

View File

@@ -1,7 +1,7 @@
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector : "textarea",
selector : "#body",
theme : "modern",
plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount spellchecker imagetools contextmenu colorpicker textpattern help code',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat code',
@@ -31,21 +31,37 @@
{% set rows = rows + 1 %}
<tr bgcolor="{{ getStyle(rows) }}">
<!--td>Description:</td-->
<td colspan="2"><textarea name="body" maxlength="{{ constant('BODY_LIMIT') }}" class="tinymce">{{ body }}</textarea></td>
<td colspan="2"><textarea name="body" id="body" maxlength="{{ constant('BODY_LIMIT') }}" class="tinymce">{{ body }}</textarea></td>
<tr/>
{% set rows = rows + 1 %}
<tr bgcolor="{{ getStyle(rows) }}">
<td><b>Type:</b></td>
<td>
<select name="type">
<select name="type" id="select-type"{% if action == 'edit' %} disabled{% endif %}>
<option value="{{ constant('NEWS') }}" {% if type is defined and type == constant('NEWS') %}selected="yes"{% endif %}>News</option>
<option value="{{ constant('TICKET') }}" {% if type is defined and type == constant('TICKET') %}selected="yes"{% endif %}>Ticket</option>
<!--option value="{{ constant('ARTICLE') }}">Article</option-->
<option value="{{ constant('TICKER') }}" {% if type is defined and type == constant('TICKER') %}selected="yes"{% endif %}>Ticket</option>
<option value="{{ constant('ARTICLE') }}" {% if type is defined and type == constant('ARTICLE') %}selected="yes"{% endif %}>Article</option>
</select>
</td>
</tr>
{% set rows = rows + 1 %}
<tr id="article-text" bgcolor="{{ getStyle(rows) }}"{% if article_text is empty %} style="display: none;"{% endif %}>
<td><b>Article short text:<br/>This will be displayed on news page.<br/>Rest will be available on "read more" page.</b></td>
<td>
<textarea name="article_text">{% if article_text is not empty %}{{ article_text }}{% endif %}</textarea>
</td>
</tr>
{% set rows = rows + 1 %}
<tr id="article-image" bgcolor="{{ getStyle(rows) }}"{% if article_image is empty %} style="display: none;"{% endif %}>
<td><b>Article image:</b></td>
<td>
<input type="text" name="article_image" value="{% if article_image is not empty %}{{ article_image }}{% else %}images/news/announcement.jpg{% endif %}" />
</td>
</tr>
{% if action == 'edit' %}
{% set rows = rows + 1 %}
{% if player is defined %}
@@ -115,11 +131,23 @@
<script type="text/javascript">
$(document).ready(function() {
$("#news-edit").hide();
});
$("#news-button").click(function() {
$("#news-edit").toggle();
return false;
$("#news-button").click(function() {
$("#news-edit").toggle();
return false;
});
$('#select-type').change(function() {
var value = $('#select-type').val();
if(value == {{ constant('ARTICLE') }}) {
$('#article-text').show();
$('#article-image').show();
}
else {
$('#article-text').hide();
$('#article-image').hide();
}
});
});
</script>
{% endif %}