* added news preview function (news, ticker, article)

* update TODO
This commit is contained in:
slawkens1 2018-01-03 23:49:46 +01:00
parent 4a948b8ba2
commit 854560b2f5
7 changed files with 200 additions and 25 deletions

11
TODO
View File

@ -2,30 +2,27 @@
0.*
* support duplicated vocation names with different ids
* cache Menus in templates
* sandbox for plugins, don't install when requirements are not passed
* load items & weapons on install, preferably with ajax
* add changelog management interface
* option to require php extension to be installed
* save detected country in session
* tibiacom template - show status on top 5
* kathrine tickets - show/hide
* highscores - by balance
* admin panel Menus:
* open in external window (_blank option)
* color of the link
* should the link blink?
* cache hooks
* cache fieldExist and tableExist functions
* cache:
* hooks
* fieldExist and tableExist functions
* Menus in templates
* forum:
* show position of the player
* replace forum actions links for admin (move, remove) with images
* redirect directly to the thread on user login
* latest news:
* warning about leaving page with changes
* news preview option
* characters: edit in admin panel option
* fix bug on othire with config.account_premium_days
* move highscores to twig
1.0:

View File

@ -37,7 +37,8 @@ Twig_Autoloader::register();
$twig_loader = new Twig_Loader_Filesystem(SYSTEM . 'templates');
$twig = new Twig_Environment($twig_loader, array(
'cache' => CACHE . 'twig/',
'auto_reload' => true
'auto_reload' => true,
//'debug' => true
));
$function = new Twig_SimpleFunction('getStyle', function ($i) {

View File

@ -387,7 +387,7 @@ class News
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, 'article_text' => $article_text, 'article_image' => $article_image));
$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' => ($type == 3 ? $article_text : ''), 'article_image' => ($type == 3 ? $article_image : '')));
return true;
}

View File

@ -33,20 +33,20 @@ if($config['template_allow_change'])
}
$template_path = 'templates/' . $template_name;
if(!file_exists($template_path . '/index.php') &&
!file_exists($template_path . '/template.php') &&
!file_exists($template_path . '/layout.php'))
if(!file_exists(BASE . $template_path . '/index.php') &&
!file_exists(BASE . $template_path . '/template.php') &&
!file_exists(BASE . $template_path . '/layout.php'))
{
$template_name = 'kathrine';
$template_path = TEMPLATES . $template_name;
$template_path = 'templates/' . $template_name;
}
$file = $template_path . '/config.ini';
$file = BASE . $template_path . '/config.ini';
$exists = file_exists($file);
if($exists || ($config['backward_support'] && file_exists($template_path . '/layout_config.ini')))
if($exists || ($config['backward_support'] && file_exists(BASE . $template_path . '/layout_config.ini')))
{
if(!$exists)
$file = $template_path . '/layout_config.ini';
$file = BASE . $template_path . '/layout_config.ini';
if($cache->enabled())
{
@ -65,8 +65,8 @@ if($exists || ($config['backward_support'] && file_exists($template_path . '/lay
foreach($template_ini as $key => $value)
$config[$key] = $value;
}
else if(file_exists($template_path . '/config.php'))
require($template_path . '/config.php');
else if(file_exists(BASE . $template_path . '/config.php'))
require(BASE . $template_path . '/config.php');
$template = array();
$template['link_account_manage'] = getLink('account/manage');

View File

@ -1,7 +1,8 @@
<div id="news_preview"></div>
{% if action != 'edit' %}
<a id="news-button" href="#">Add news</a>
{% endif %}
<form method="post" action="{{ news_link_form }}">
<form method="post" action="{{ news_link_form }}" id="news-edit-form">
{% if action == 'edit' %}
<input type="hidden" name="id" value="{{ news_id }}" />
{% endif %}
@ -15,7 +16,7 @@
{% set rows = rows + 1 %}
<tr bgcolor="{{ getStyle(rows) }}">
<td><b>Title:</b></td>
<td><input name="title" value="{{ title }}" size="50" maxlength="100"/></td>
<td><input name="title" id="title" value="{{ title }}" size="50" maxlength="100"/></td>
</tr>
{% set rows = rows + 1 %}
@ -40,7 +41,7 @@
<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>
<textarea name="article_text" id="article_text">{% if article_text is not empty %}{{ article_text }}{% endif %}</textarea>
</td>
</tr>
@ -48,7 +49,7 @@
<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 %}" />
<input type="text" name="article_image" id="article_image" value="{% if article_image is not empty %}{{ article_image }}{% else %}images/news/announcement.jpg{% endif %}" />
</td>
</tr>
@ -70,7 +71,7 @@
<tr bgcolor="{{ getStyle(rows) }}">
<td width="180"><b>{% if action == 'edit' %}Modified by{% else %}Author{% endif %}:</b></td>
<td>
<select name="player_id">
<select name="player_id" id="player_id">
{% for player in account_players %}
<option value="{{ player.getId() }}"{% if player_id is defined and player.getId() == player_id %} selected="selected"{% endif %}>{{ player.getName() }}</option>
{% endfor %}
@ -93,7 +94,7 @@
<tr bgcolor="{{ getStyle(rows) }}">
<td><b>Create forum thread in section:</b></td>
<td>
<select name="forum_section">
<select name="forum_section" id="forum_section">
<option value="-1">None</option>
{% for section in forum_boards %}
<option value="{{ section.id }}" {% if forum_section is defined and forum_section == section.id %}checked="yes"{% endif %}/>{{ section.name }}</option>
@ -102,12 +103,13 @@
</td>
</tr>
{% elseif comments is not null%}
<input type="hidden" name="forum_section" value="{{ comments }}" />
<input type="hidden" name="forum_section" id="forum_section" value="{{ comments }}" />
{% endif %}
{% set rows = rows + 1 %}
<tr bgcolor="{{ getStyle(rows) }}">
<td align="right">
<a id="preview" style="cursor: pointer;">Preview</a>
<input type="submit" value="Submit"/>
</td>
<td align="left">
@ -170,6 +172,58 @@
unsaved = false;
window.location = '{{ news_link }}';
});
$("#news-edit-form").submit(function( event ) {
unsaved = false;
});
if($("#news.Box").length > 0) {
$('<div id="article_preview"></div>').insertBefore("#news.Box");
$('<div id="ticker_preview"></div>').insertBefore("#news.Box");
}
else {
$('<div id="article_preview"></div>').insertBefore("#news-edit");
$('<div id="ticker_preview"></div>').insertBefore("#news-edit");
}
$("#preview").click(function(e) {
var title = document.getElementById("title").value;
var body = tinyMCE.activeEditor.getContent();
var player_id = document.getElementById("player_id").value;
var category = $('input[name=category]:checked').val();
var forum_section = document.getElementById("forum_section").value;
var type = document.getElementById("select-type").value;
var params = { title: title, body: body, player_id: player_id, category: category, forum_section: forum_section, template_path: '{{ template_path }}', type: type, uid: Math.random() }
if(type == 3) {
params.article_text = document.getElementById("article_text").value;
params.article_image = document.getElementById("article_image").value;
}
$.getJSON("tools/news_preview.php", params, function(data){
if(data.hasOwnProperty('success')) {
if(type == 3) { // ARTICLE
$('#news_preview').html('');
$('#ticker_preview').html('');
$('#article_preview').html(data.success);
}
else if(type == 2) { // TICKER
$('#news_preview').html('');
$('#ticker_preview').html(data.success);
$('#article_preview').html('');
}
else { // NEWS
$('#news_preview').html(data.success);
$('#ticker_preview').html('');
$('#article_preview').html('');
}
}
else if(data.hasOwnProperty('error')) {
$('#news_preview').html(data.error);
}
});
});
lastContent = $("#body").val();
});

View File

@ -7,7 +7,9 @@
<div class="Border_2">
<div class="Border_3">
<div class="BoxContent" style="background-image: url({{ template_path }}/images/content/scroll.gif);">
{% if i is not defined %}
{% set i = 0 %}
{% endif %}
{% for ticker in tickers %}
<div id="TickerEntry-{{ i }}" class="Row" onclick='TickerAction("TickerEntry-{{ i }}")'>
<div class="{% if (i / 2) matches '/^\\d+$/' %}Odd{% else %}Even{% endif %}">

121
tools/news_preview.php Normal file
View File

@ -0,0 +1,121 @@
<?php
/**
* News preview
* Returns news preview in json format
*
* @package MyAAC
* @author Slawkens <slawkens@gmail.com>
* @copyright 2017 MyAAC
* @link http://my-aac.org
*/
// we need some functions
require('../common.php');
require_once(SYSTEM . 'functions.php');
require_once(SYSTEM . 'init.php');
require_once(SYSTEM . 'template.php');
$error = '';
if(isset($_GET['title'], $_GET['body'], $_GET['player_id'], $_GET['category'], $_GET['forum_section'], $_GET['template_path'], $_GET['type']))
{
$categories = array();
foreach($db->query(
'SELECT id, name, icon_id FROM ' . TABLE_PREFIX . 'news_categories WHERE hidden != 1') as $cat)
{
$categories[$cat['id']] = array(
'name' => $cat['name'],
'icon_id' => $cat['icon_id']
);
}
/*
$template_path = $_GET['template_path'];
$twig->addGlobal('template_path', $template_path);
if($twig_loader && file_exists(BASE . $template_path))
$twig_loader->prependPath(BASE . $template_path);
*/
$twig->addGlobal('config', $config);
$player = new OTS_Player();
$player->load($_GET['player_id']);
$author = '';
if($player->isLoaded()) {
$author = $player->getName();
}
if($_GET['type'] == 3) { // ARTICLE
if(!isset($_GET['article_text'], $_GET['article_image'])) {
error_('Error: please fill all inputs 2.');
}
$featured_article = '';
if($twig->getLoader()->exists('news.featured_article.html.twig')) {
$featured_article = $twig->render('news.featured_article.html.twig', array(
'article' => array(
'id' => 1,
'title' => $_GET['title'],
'text' => $_GET['article_text'],
'image' => $_GET['article_image'],
'hidden' => 0,
'read_more'=> getLink('news/archive/') . '0'
),
'canEdit' => false
));
}
success_($featured_article);
}
else if($_GET['type'] == 2) { // TICKER
$tickers = array(
array('id' => 1, 'date' => time(), 'body' => $_GET['body'], 'category' => $_GET['category'])
);
foreach($tickers as &$ticker) {
$ticker['icon'] = $categories[$ticker['category']]['icon_id'];
$ticker['body_short'] = short_text(strip_tags($ticker['body']), 100);
}
$tickers_content = $twig->render('news.tickers.html.twig', array(
'tickers' => $tickers,
'canEdit' => false,
'i' => -1
));
success_($tickers_content);
}
else {
success_($twig->render('news.html.twig', array(
'id' => 1,
'title' => $_GET['title'],
'content' => $_GET['body'],
'date' => time(),
'icon' => $categories[$_GET['category']]['icon_id'],
'author' => $config['news_author'] ? $author : '',
'comments' => null,
'news_date_format' => $config['news_date_format'],
'hidden'=> 0
)));
}
}
else
error_('Error: please fill all inputs.');
/**
* Output message & exit.
*
* @param string $desc Description
*/
function success_($desc) {
echo json_encode(array(
'success' => $desc
));
exit();
}
function error_($desc) {
echo json_encode(array(
'error' => $desc
));
exit();
}
?>