Compare commits

...

4 Commits

7 changed files with 100 additions and 20 deletions

View File

@ -1,3 +1,7 @@
Version 1.20 - May 15, 2016
Add setting in profile to allow offline inbox for: staff, members or everyone
Completely fix link-redirection
Version 1.19.2 - May 7, 2016
Remove JavaScript "load only new messages" feature
Add JS auto-refresh to header instead

1
README
View File

@ -60,6 +60,7 @@ When you are done, you have to edit the chat script, to include your translation
'lang_code' =>'Language name',
to the $L array in the load_lang() function at the bottom, similar to what I did for the German translation.
Please share your translation with me, so I can add it to the official version.
To update your translation, you can copy each new string to your translation file or edit the automated lang_update.php script to reflect you language and run it.
REGEX:

View File

@ -64,6 +64,7 @@ When you are done, you have to edit the chat script, to include your translation
'lang_code' =>'Language name',
to the $L array in the load_lang() function at the bottom, similar to what I did for the German translation.
Please share your translation with me, so I can add it to the official version.
To update your translation, you can copy each new string to your translation file or edit the automated lang_update.php script to reflect you language and run it.
Regex:
------

View File

@ -275,7 +275,7 @@ function thr(){
echo '<tr><td><hr></td></tr>';
}
function print_start($class='', $ref=0, $url=''){
function print_start($class='', $ref=0, $url=''){
global $H, $I;
if(!empty($url)){
$url=str_replace('&amp;', '&', $url);// Don't escape "&" in URLs here, it breaks some (older) browsers and js refresh!
@ -284,7 +284,8 @@ function print_start($class='', $ref=0, $url=''){
echo "<!DOCTYPE html><html><head>$H[meta_html]";
if(!empty($url)){
echo "<meta http-equiv=\"Refresh\" content=\"$ref; URL=$url\">";
$ref*=1000;
$ref+=5;//only use js if browser refresh stopped working
$ref*=1000;//js uses milliseconds
echo "<script type=\"text/javascript\">setTimeout(function(){window.location.replace(\"$url\");}, $ref);</script>";
}
if($class==='init'){
@ -299,6 +300,7 @@ function print_start($class='', $ref=0, $url=''){
function send_redirect($url){
global $I;
$url=htmlspecialchars_decode(rawurldecode($url));
preg_match('~^(.*)://~', $url, $match);
$url=preg_replace('~^(.*)://~', '', $url);
$escaped=htmlspecialchars($url);
@ -1304,7 +1306,7 @@ function send_messages(){
echo '</div><div id="chatters">';
print_chatters();
echo "</div><a style=\"position:fixed;top:0.5em;right:0.5em\" href=\"#bottom\">$I[bottom]</a><div id=\"messages\">";
if($U['status']>=2 && $U['eninbox']==1){
if($U['status']>=2 && $U['eninbox']!=0){
$stmt=$db->prepare('SELECT COUNT(*) FROM ' . PREFIX . 'inbox WHERE recipient=?;');
$stmt->execute(array($U['nickname']));
$tmp=$stmt->fetch(PDO::FETCH_NUM);
@ -1620,8 +1622,8 @@ function send_post(){
$ignored[]=$ign['ignored'];
}
}
$stmt=$db->prepare('SELECT nickname, style, status FROM ' . PREFIX . 'members WHERE eninbox=1 AND nickname NOT IN (SELECT nickname FROM ' . PREFIX . 'sessions WHERE incognito=0) AND nickname NOT IN (SELECT ign FROM ' . PREFIX . 'ignored WHERE ignby=?) AND nickname NOT IN (SELECT ignby FROM ' . PREFIX . 'ignored WHERE ign=?);');
$stmt->execute(array($U['nickname'], $U['nickname']));
$stmt=$db->prepare('SELECT nickname, style, status FROM ' . PREFIX . 'members WHERE eninbox!=0 AND eninbox<=? AND nickname NOT IN (SELECT nickname FROM ' . PREFIX . 'sessions WHERE incognito=0) AND nickname NOT IN (SELECT ign FROM ' . PREFIX . 'ignored WHERE ignby=?) AND nickname NOT IN (SELECT ignby FROM ' . PREFIX . 'ignored WHERE ign=?);');
$stmt->execute(array($U['status'], $U['nickname'], $U['nickname']));
while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
$P[$tmp['nickname']]=["$tmp[nickname] $I[offline]", $tmp['style'], $tmp['status']];
}
@ -1780,9 +1782,6 @@ function send_profile($arg=''){
if($U['status']>=5 && get_setting('incognito')){
$bool_settings[]='incognito';
}
if($U['status']>=2 && get_setting('eninbox')){
$bool_settings[]='eninbox';
}
foreach($bool_settings as $setting){
echo '<tr><td><table class="left-table"><tr><th>'.$I[$setting].'</th><td class="right">';
echo "<input type=\"checkbox\" name=\"$setting\" id=\"$setting\" value=\"on\"";
@ -1792,6 +1791,32 @@ function send_profile($arg=''){
echo "><label for=\"$setting\"><b>$I[enabled]</b></label></td></tr></table></td></tr>";
thr();
}
if($U['status']>=2 && get_setting('eninbox')){
echo "<tr><td><table class=\"left-table\"><tr><th>$I[eninbox]</th><td class=\"right\">";
echo "<select name=\"eninbox\" id=\"eninbox\">";
echo '<option value="0"';
if($U['eninbox']==0){
echo ' selected';
}
echo ">$I[disabled]</option>";
echo '<option value="1"';
if($U['eninbox']==1){
echo ' selected';
}
echo ">$I[eninall]</option>";
echo '<option value="3"';
if($U['eninbox']==3){
echo ' selected';
}
echo ">$I[eninmem]</option>";
echo '<option value="5"';
if($U['eninbox']==5){
echo ' selected';
}
echo ">$I[eninstaff]</option>";
echo '</select></td></tr></table></td></tr>';
thr();
}
echo "<tr><td><table class=\"left-table\"><tr><th>$I[tz]</th><td class=\"right\">";
echo "<select name=\"tz\" id=\"tz\">";
$tzs=[-12=>'-12', -11=>'-11', -10=>'-10', -9=>'-9', -8=>'-8', -7=>'-7', -6=>'-6', -5=>'-5', -4=>'-4', -3=>'-3', -2=>'-2', -1=>'-1', 0=>'', 1=>'+1', 2=>'+2', 3=>'+3', 4=>'+4', 5=>'+5', 6=>'+6', 7=>'+7', 8=>'+8', 9=>'+9', 10=>'+10', 11=>'+11', 12=>'+12', 13=>'+13', 14=>'+14'];
@ -2564,10 +2589,8 @@ function amend_profile(){
$U['tz']=$_REQUEST['tz'];
}
}
if(isSet($_REQUEST['eninbox'])){
$U['eninbox']=1;
}else{
$U['eninbox']=0;
if(isSet($_REQUEST['eninbox']) && $_REQUEST['eninbox']>=0 && $_REQUEST['eninbox']<=5){
$U['eninbox']=$_REQUEST['eninbox'];
}
}
@ -2730,8 +2753,8 @@ function validate_input(){
$stmt=$db->prepare('SELECT * FROM ' . PREFIX . 'ignored WHERE (ignby=? AND ign=?) OR (ignby=? AND ign=?);');
$stmt->execute(array($U['nickname'], $_REQUEST['sendto'], $_REQUEST['sendto'], $U['nickname']));
if(!$stmt->fetch(PDO::FETCH_NUM)){
$stmt=$db->prepare('SELECT nickname, style, status FROM ' . PREFIX . 'members WHERE eninbox=1 AND nickname NOT IN (SELECT nickname FROM ' . PREFIX . 'sessions WHERE incognito=0) AND nickname NOT IN (SELECT ign FROM ' . PREFIX . 'ignored WHERE ignby=?) AND nickname NOT IN (SELECT ignby FROM ' . PREFIX . 'ignored WHERE ign=?);');
$stmt->execute(array($U['nickname'], $U['nickname']));
$stmt=$db->prepare('SELECT nickname, style, status FROM ' . PREFIX . 'members WHERE eninbox!=0 AND eninbox<=? AND nickname NOT IN (SELECT nickname FROM ' . PREFIX . 'sessions WHERE incognito=0) AND nickname NOT IN (SELECT ign FROM ' . PREFIX . 'ignored WHERE ignby=?) AND nickname NOT IN (SELECT ignby FROM ' . PREFIX . 'ignored WHERE ign=?);');
$stmt->execute(array($U['status'], $U['nickname'], $U['nickname']));
while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
$P[$tmp['nickname']]=[$tmp['nickname'], $tmp['style'], $tmp['status']];
$inboxes[$tmp['nickname']]=true;
@ -2846,7 +2869,7 @@ function apply_linkfilter(){
if(get_setting('forceredirect')){
$U['message']=preg_replace_callback('/<a href="([^"]+)" target="_blank">(.*?(?=<\/a>))<\/a>/',
function ($matched) use($redirect){
return "<a href=\"$redirect".$matched[1]."\" target=\"_blank\">$matched[2]</a>";
return "<a href=\"$redirect".rawurlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>";
}
, $U['message']);
}elseif(preg_match_all('/<a href="([^"]+)" target="_blank">(.*?(?=<\/a>))<\/a>/', $U['message'], $matches)){
@ -2854,7 +2877,7 @@ function apply_linkfilter(){
if(!preg_match('~^http(s)?://~', $match)){
$U['message']=preg_replace_callback('/<a href="('.str_replace('/', '\/', $match).')\" target=\"_blank\">(.*?(?=<\/a>))<\/a>/',
function ($matched) use($redirect){
return "<a href=\"$redirect".$matched[1]."\" target=\"_blank\">$matched[2]</a>";
return "<a href=\"$redirect".rawurlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>";
}
, $U['message']);
}
@ -3074,7 +3097,7 @@ function prepare_message_print(&$message, $injectRedirect, $redirect, $removeEmb
if($injectRedirect){
$message['text']=preg_replace_callback('/<a href="([^"]+)" target="_blank">(.*?(?=<\/a>))<\/a>/',
function ($matched) use($redirect) {
return "<a href=\"$redirect".$matched[1]."\" target=\"_blank\">$matched[2]</a>";
return "<a href=\"$redirect".rawurlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>";
}
, $message['text']);
}
@ -3717,7 +3740,7 @@ function load_lang(){
function load_config(){
date_default_timezone_set('UTC');
define('VERSION', '1.19.2'); // Script version
define('VERSION', '1.20'); // Script version
define('DBVERSION', 23); // Database version
define('MSGENCRYPTED', false); // Store messages encrypted in the database to prevent other database users from reading them - true/false - visit the setup page after editing!
define('ENCRYPTKEY', 'MY_KEY'); // Encryption key for messages

View File

@ -342,6 +342,9 @@ $T=array(
'eninbox' => 'Offline Posteingang aktivieren',
'inboxmsgs' => '%d Nachrichten im Posteingang lesen',
'offline' => '(offline)',
'deleteacc' => 'Konto löschen'
'deleteacc' => 'Konto löschen',
'eninall' => 'Für jeden',
'eninmem' => 'Nur für Mitglieder',
'eninstaff' => 'Nur für Moderatoren'
);
?>

View File

@ -342,6 +342,9 @@ $I=array(
'eninbox' => 'Enable offline inbox',
'inboxmsgs' => 'Read %d messages in your inbox',
'offline' => '(offline)',
'deleteacc' => 'Delete account'
'deleteacc' => 'Delete account',
'eninall' => 'For everyone',
'eninmem' => 'For members only',
'eninstaff' => 'For staff only'
);
?>

45
lang_update.php Normal file
View File

@ -0,0 +1,45 @@
<?php
$native = 'Deutsch'; // Native lanugae name
$english = 'German'; // Enlish language name
$code = 'de'; // Language code
ob_start();
echo "<?php
/*
* LE CHAT-PHP - a PHP Chat based on LE CHAT - $english translation
*
* Copyright (C) 2015-2016 Daniel Winzen <d@winzen4.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//Native language name: $native
\$T=array(
";
if(file_exists("lang_$code.php")){
include("lang_$code.php");
}
include('lang_en.php');
foreach($T as $id=>$value){
if(isSet($I[$id])){
$I[$id]=$value;
}
}
foreach($I as $id=>$value){
echo "\t'$id' => '".str_replace("'", "\'", $value)."',\n";
}
echo ");\n?>\n";
$file=ob_get_clean();
file_put_contents("lang_$code.php", $file);
?>