2007-11-02 22:01:47 +00:00
< ? php
2006-12-02 04:36:16 +00:00
/*
2008-12-15 21:16:32 +00:00
* e107 website system
*
2013-02-27 15:18:48 +01:00
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
2008-12-15 21:16:32 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Administration Area - Language check
* With code from Izydor and Lolo .
*
2006-12-02 04:36:16 +00:00
*/
2015-07-08 14:52:16 -07:00
if ( ! defined ( 'e107_INIT' ))
{
2021-01-16 13:32:35 -08:00
require_once ( __DIR__ . '/../class2.php' );
2015-07-08 14:52:16 -07:00
}
2017-01-17 01:33:03 +01:00
e107 :: coreLan ( 'lancheck' , true );
2009-08-28 16:11:02 +00:00
2007-10-07 22:01:43 +00:00
$e_sub_cat = 'language' ;
2013-10-27 21:28:40 -07:00
// require_once("auth.php");
2008-12-15 21:16:32 +00:00
2013-02-25 20:14:59 +01:00
$frm = e107 :: getForm ();
$mes = e107 :: getMessage ();
2015-07-08 14:52:16 -07:00
// $lck = new lancheck;
2009-11-05 08:07:53 +00:00
2013-10-27 21:28:40 -07:00
/*
2007-10-07 22:01:43 +00:00
$qry = explode ( " | " , e_QUERY );
$f = $qry [ 0 ];
$lan = $qry [ 1 ];
$mode = $qry [ 2 ];
2006-12-02 04:36:16 +00:00
// Write the language file.
if ( isset ( $_POST [ 'submit' ]))
{
unset ( $input );
$kom_start = chr ( 47 ) . " * " ;
$kom_end = " * " . chr ( 47 );
2007-10-07 22:01:43 +00:00
if ( $_POST [ 'root' ])
2006-12-02 04:36:16 +00:00
{
2007-10-07 22:01:43 +00:00
$writeit = $_POST [ 'root' ];
2006-12-02 04:36:16 +00:00
}
$old_kom = " " ;
$in_kom = 0 ;
$data = file ( $writeit );
foreach ( $data as $line )
{
2007-10-07 22:01:43 +00:00
if ( strpos ( $line , $kom_start ) !== False && $old_kom == " " )
2006-12-02 04:36:16 +00:00
{
2007-10-07 22:01:43 +00:00
$in_kom = 1 ;
}
if ( $in_kom ) { $old_kom .= $line ; }
if ( strpos ( $line , $kom_end ) !== False && $in_kom ) { $in_kom = 0 ;}
}
2006-12-02 04:36:16 +00:00
$message = " <div style='text-align:left'><br /> " ;
$input .= chr ( 60 ) . " ?php \n " ;
if ( $old_kom == " " )
{
// create CVS compatible description.
$diz = chr ( 47 ) . " * \n " ;
2008-12-15 21:16:32 +00:00
$diz .= " * e107 website system \n " ;
$diz .= " * \n " ;
2009-11-18 01:06:08 +00:00
$diz .= " * Copyright (C) 2008-2009 e107 Inc (e107.org) \n " ;
2008-12-15 21:16:32 +00:00
$diz .= " * Released under the terms and conditions of the \n " ;
$diz .= " * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) \n " ;
$diz .= " * \n " ;
$diz .= " * Language File \n " ;
$diz .= " * \n " ;
$diz .= " * " . chr ( 36 ) . " Source: " . str_replace ( array ( e_LANGUAGEDIR , e_PLUGIN ), array ( e_LANGUAGEDIR_ABS , e_PLUGIN_ABS ), $writeit ) . " " . chr ( 36 ) . " \n " ;
$diz .= " * " . chr ( 36 ) . " Revision: 1.0 " . chr ( 36 ) . " \n " ;
$diz .= " * " . chr ( 36 ) . " Date: " . date ( " Y/m/d H:i:s " ) . " " . chr ( 36 ) . " \n " ;
$diz .= " * " . chr ( 36 ) . " Author: " . USERNAME . " " . chr ( 36 ) . " \n " ;
$diz .= " * \n " ;
2006-12-02 04:36:16 +00:00
$diz .= " * " . chr ( 47 ) . " \n \n " ;
}
else
{
$diz = $old_kom ;
}
$input .= $diz ;
$message .= str_replace ( " \n " , " <br /> " , $diz );
for ( $i = 0 ; $i < count ( $_POST [ 'newlang' ]); $i ++ )
{
$notdef_start = " " ;
$notdef_end = " \n " ;
$deflang = ( MAGIC_QUOTES_GPC === TRUE ) ? stripslashes ( $_POST [ 'newlang' ][ $i ]) : $_POST [ 'newlang' ][ $i ];
$func = " define " ;
$quote = chr ( 34 );
if ( strpos ( $_POST [ 'newdef' ][ $i ], " ndef++ " ) !== FALSE )
{
2007-10-07 22:01:43 +00:00
$defvar = str_replace ( " ndef++ " , " " , $_POST [ 'newdef' ][ $i ]);
$notdef_start = " if (!defined( " . chr ( 34 ) . $defvar . chr ( 34 ) . " )) { " ;
$notdef_end = " } \n " ;
2006-12-02 04:36:16 +00:00
}
2013-10-27 21:28:40 -07:00
else
{
$defvar = $_POST [ 'newdef' ][ $i ];
}
if ( $_POST [ 'newdef' ][ $i ] == " LC_ALL " && isset ( $_POST [ 'root' ]))
{
$message .= $notdef_start . 'setlocale(' . htmlentities ( $defvar ) . ',' . $deflang . ');<br />' . $notdef_end ;
$input .= $notdef_start . " setlocale( " . $defvar . " , " . $deflang . " ); " . $notdef_end ;
}
else
{
$message .= $notdef_start . $func . '(' . $quote . htmlentities ( $defvar ) . $quote . ',"' . $deflang . '");<br />' . $notdef_end ;
$input .= $notdef_start . $func . " ( " . $quote . $defvar . $quote . " , " . chr ( 34 ) . $deflang . chr ( 34 ) . " ); " . $notdef_end ;
}
}
$message .= " <br /> " ;
$message .= " </div> " ;
$input .= " \n \n ?> " ;
// Write to file.
$fp = @ fopen ( $writeit , " w " );
if ( !@ fwrite ( $fp , $input ))
{
$caption = LAN_CHECK_PAGE_TITLE . ' - ' . LAN_ERROR ;
$message = '' ;
$mes -> addError ( LAN_CHECK_17 );
}
else
{
2016-10-10 20:06:43 +01:00
$caption = LAN_CHECK_PAGE_TITLE . ' - ' . LAN_SUMMARY ;
2013-10-30 13:55:19 -07:00
$mes -> addSuccess ( sprintXXX ( str_replace ( " [x] " , " %s " , LAN_CHECK_23 ), basename ( $writeit )));
2013-10-27 21:28:40 -07:00
}
fclose ( $writeit );
$message .= "
< form method = 'post' action = '".e_SELF."' id = 'core-lancheck-save-file-form' >
< div class = 'center' >
" . $frm->admin_button ('language_sel', LAN_BACK). "
" . $frm->hidden ('language', $lan ). "
</ div >
</ form > " ;
$ns -> tablerender ( $caption , $mes -> render () . $message );
// require_once(e_ADMIN."footer.php");
exit ;
}
// ============================================================================
// Edit the Language File.
if ( $f != " " ){
if ( ! $mode )
{
$dir1 = e_BASE . $LANGUAGES_DIRECTORY . " English/ " ;
$f1 = $f ;
$dir2 = e_BASE . $LANGUAGES_DIRECTORY . $lan . " / " ;
$f2 = $f ;
}
else
{
$fullpath_orig = $f ;
$fullpath_trans = str_replace ( " English " , $lan , $f );
$f1 = basename ( $fullpath_orig );
$f2 = basename ( $fullpath_trans );
$dir1 = dirname ( $fullpath_orig ) . " / " ;
$dir2 = dirname ( $fullpath_trans ) . " / " ;
}
$lck -> edit_lanfiles ( $dir1 , $dir2 , $f1 , $f2 );
}
// ===========================================================================
$core_plugins = array (
" alt_auth " , " banner_menu " , " blogcalendar_menu " , " calendar_menu " , " chatbox_menu " ,
" clock_menu " , " comment_menu " , " content " , 'download' , " featurebox " , " forum " ,
" gsitemap " , " links_page " , " linkwords " , " list_new " , " log " , " login_menu " ,
" newforumposts_main " , " newsfeed " , " newsletter " , " online " , " other_news_menu " ,
" pdf " , " pm " , " poll " , " rss_menu " , " search_menu " , " siteinfo " , " trackback " ,
" tree_menu " , " user_menu "
);
$core_themes = array ( " bootstrap " , $pref [ 'sitetheme' ]);
if ( isset ( $_POST [ 'language_sel' ]) && isset ( $_POST [ 'language' ]))
{
$text = $lck -> check_core_lanfiles ( $_POST [ 'language' ]) . $lck -> check_core_lanfiles ( $_POST [ 'language' ], " admin/ " );
$text .= "
< fieldset id = 'core-lancheck-plugin' >
< legend > " .ADLAN_CL_7. " </ legend >
< table class = 'table adminlist' >
< colgroup >
< col style = 'width: 25%' />
< col style = 'width: 25%' />
< col style = 'width: 40%' />
< col style = 'width: 10%' />
</ colgroup >
< thead >
< tr >
< th > " .LAN_PLUGIN. " </ th >
< th > " .LAN_CHECK_16. " </ th >
< th > " . $_POST['language'] . " </ th >
< th class = 'center last' > " .LAN_OPTIONS. " </ th >
</ tr >
</ thead >
< tbody >
" ;
foreach ( $core_plugins as $plugs )
{
if ( is_readable ( e_PLUGIN . $plugs ))
{
$text .= $lck -> check_lanfiles ( 'P' , $plugs , " English " , $_POST [ 'language' ]);
}
}
$text .= "
</ tbody >
</ table >
</ fieldset >
" ;
$text .= "
< fieldset id = 'core-lancheck-theme' >
2016-10-10 20:06:43 +01:00
< legend > " .LAN_THEME. " </ legend >
2013-10-27 21:28:40 -07:00
< table class = 'table adminlist' >
< colgroup >
< col style = 'width: 25%' />
< col style = 'width: 25%' />
< col style = 'width: 40%' />
< col style = 'width: 10%' />
</ colgroup >
< thead >
< tr >
< th > " .LAN_CHECK_21. " </ th >
< th > " .LAN_CHECK_16. " </ th >
< th > " . $_POST['language'] . " </ th >
< th class = 'center last' > " .LAN_OPTIONS. " </ th >
</ tr >
</ thead >
< tbody >
" ;
foreach ( $core_themes as $them )
{
if ( is_readable ( e_THEME . $them ))
{
$text .= $lck -> check_lanfiles ( 'T' , $them , " English " , $_POST [ 'language' ]);
}
}
$text .= "
</ tbody >
</ table >
</ fieldset >
" ;
$mes = e107 :: getMessage ();
if ( $lck -> error_count == 0 )
{
e107 :: getConfig () -> setPref ( 'lancheck/' . $_POST [ 'language' ], 1 );
e107 :: getConfig () -> save ( FALSE );
$mes -> addSuccess ( LAN_CHECK_27 . '<b>: ' . $lck -> error_count . '</b>' );
}
else
{
$mes -> addWarning ( LAN_CHECK_27 . '<b>: ' . $lck -> error_count . '</b>' );
}
2016-10-10 20:06:43 +01:00
$ns -> tablerender ( LAN_THEMES , $mes -> render () . $text );
2013-10-27 21:28:40 -07:00
require_once ( e_ADMIN . " footer.php " );
exit ;
}
*/
class lancheck
{
2015-06-09 18:05:25 -07:00
2020-08-19 10:02:14 -07:00
public $core_plugins = array ();
public $core_themes = array ( " bootstrap3 " , " voux " );
2013-10-27 21:28:40 -07:00
2015-07-10 14:25:16 -07:00
private $errorsOnly = false ;
2013-10-27 21:28:40 -07:00
2015-07-10 14:25:16 -07:00
private $coreImage = array ();
2013-10-27 21:28:40 -07:00
2015-07-09 19:24:59 -07:00
private $transLanguage = '' ;
2015-07-08 14:52:16 -07:00
private $thirdPartyPlugins = true ;
2015-08-31 17:17:28 -07:00
private $deprecatedFiles = array ( 'lan_download.php' , 'lan_parser_functions.php' , 'lan_prefs.php' , 'admin/lan_download.php' , 'admin/lan_modcomment.php' );
2015-07-10 14:25:16 -07:00
2017-04-23 12:38:05 -07:00
private $installed_languages = array ();
2015-07-10 14:25:16 -07:00
2015-07-08 14:52:16 -07:00
function __construct ()
{
$this -> core_plugins = e107 :: getPlugin () -> getCorePlugins ();
}
public function thirdPartyPlugins ( $val )
{
$this -> thirdPartyPlugins = $val ;
}
2015-07-10 14:25:16 -07:00
public function errorsOnly ( $val )
{
$this -> errorsOnly = $val ;
}
2013-10-27 21:28:40 -07:00
2015-07-08 14:52:16 -07:00
public function init ()
2013-10-27 21:28:40 -07:00
{
2015-07-09 19:24:59 -07:00
$mode = $_GET [ 'sub' ];
$lan = $_GET [ 'lan' ];
$file = $_GET [ 'file' ];
$this -> transLanguage = $lan ;
2013-10-27 21:28:40 -07:00
$ns = e107 :: getRender ();
$tp = e107 :: getParser ();
$pref = e107 :: getPref ();
// Check current theme also (but do NOT add to generated zip)
2017-04-23 12:38:05 -07:00
if ( deftrue ( 'e_DEBUG' ))
{
$this -> core_themes [] = $pref [ 'sitetheme' ];
$this -> core_themes = array_unique ( $this -> core_themes );
2020-08-19 10:02:14 -07:00
} /*
2015-06-09 18:05:25 -07:00
if ( E107_DEBUG_LEVEL > 0 )
{
2020-08-19 10:02:14 -07:00
print_a ( $this -> core_plugins );
} */
2015-06-09 18:05:25 -07:00
2013-10-27 21:28:40 -07:00
$acceptedLans = explode ( " , " , e_LANLIST );
2015-07-09 19:24:59 -07:00
if ( ! empty ( $_POST [ 'ziplang' ]))
2013-10-27 21:28:40 -07:00
{
2015-07-09 19:24:59 -07:00
$lang = key ( $_POST [ 'ziplang' ]);
return $this -> zipLang ( $lang );
}
// Verify
if ( $mode == 'verify' && ! empty ( $lan ))
{
2015-07-10 14:25:16 -07:00
// $_SESSION['lancheck-errors-only'] = ($_POST['errorsonly']==1 ) ? 1 : 0;
// $this->errorsOnly = ($_POST['errorsonly']==1) ? TRUE : FALSE;
2015-07-09 19:24:59 -07:00
return $this -> check_all ( 'render' , $lan );
2013-10-27 21:28:40 -07:00
}
// Write the language file.
2015-07-09 19:24:59 -07:00
if ( isset ( $_POST [ 'saveLanguageFile' ]) && vartrue ( $_POST [ 'lan' ]) && in_array ( $_POST [ 'lan' ], $acceptedLans ))
2013-10-27 21:28:40 -07:00
{
$this -> write_lanfile ( $_POST [ 'lan' ]);
2015-07-09 19:24:59 -07:00
return true ;
2013-10-27 21:28:40 -07:00
}
// Edit the Language File.
2015-07-09 19:24:59 -07:00
if ( $mode == 'edit' && vartrue ( $file ) && ! empty ( $lan ) && in_array ( $lan , $acceptedLans ))
2013-10-27 21:28:40 -07:00
{
2015-07-09 19:24:59 -07:00
if ( empty ( $_GET [ 'type' ]))
2013-10-27 21:28:40 -07:00
{
$dir1 = e_LANGUAGEDIR . " English/ " ;
2015-07-09 19:24:59 -07:00
$f1 = $tp -> toDB ( $file );
$dir2 = e_LANGUAGEDIR . $lan . " / " ;
$f2 = $tp -> toDB ( $file );
2013-10-27 21:28:40 -07:00
}
else
{
2015-07-09 19:24:59 -07:00
$fullpath_orig = $tp -> toDB ( $file );
$fullpath_trans = str_replace ( " English " , $lan , $tp -> toDB ( $file ));
2013-10-27 21:28:40 -07:00
$f1 = basename ( $fullpath_orig );
$f2 = basename ( $fullpath_trans );
$dir1 = dirname ( $fullpath_orig ) . " / " ;
$dir2 = dirname ( $fullpath_trans ) . " / " ;
}
2020-12-30 10:11:04 -08:00
return $this -> edit_lanfiles ( $dir1 , $dir2 , $f1 , $f2 , $lan , varset ( $_GET [ 'type' ]));
2015-07-09 19:24:59 -07:00
// return true;
2013-10-27 21:28:40 -07:00
}
return FALSE ;
}
function countFiles ( $array )
{
foreach ( $array as $k => $val )
{
if ( is_array ( $val ))
{
$key = key ( $val );
$this -> coreImage [ $key ] = $val ;
}
2020-08-19 10:02:14 -07:00
/* elseif ( $val )
2013-10-27 21:28:40 -07:00
{
2020-08-19 10:02:14 -07:00
$this -> totalFiles ++ ;
2013-10-27 21:28:40 -07:00
}
2020-08-19 10:02:14 -07:00
*/
2013-10-27 21:28:40 -07:00
}
}
2015-07-09 19:24:59 -07:00
/**
* @ param $language
* @ return array | string
*/
function zipLang ( $language )
{
$mes = e107 :: getMessage ();
2019-01-27 14:57:10 +01:00
/* NO LONGER USED
2015-07-09 19:24:59 -07:00
$certVal = isset ( $_POST [ 'contribute_pack' ]) ? 1 : 0 ;
if ( ! varset ( $_COOKIE [ 'e107_certified' ]))
{
cookie ( 'e107_certified' , $certVal ,( time () + 3600 * 24 * 30 ));
}
else
{
$_COOKIE [ 'e107_certified' ] = $certVal ;
2019-01-27 14:57:10 +01:00
} */
2015-07-09 19:24:59 -07:00
// $_POST['language'] = key($_POST['ziplang']);
2019-01-27 14:57:10 +01:00
// If no session data, scan before zipping.
2015-07-09 19:24:59 -07:00
if ( ! isset ( $_SESSION [ 'lancheck' ][ $language ][ 'total' ]) || $_SESSION [ 'lancheck' ][ $language ][ 'total' ] != '0' )
{
$this -> check_all ( 'norender' , $language );
}
$status = $this -> makeLanguagePack ( $language );
2019-01-27 14:57:10 +01:00
//print_a($status);
2015-07-09 19:24:59 -07:00
2019-01-27 14:57:10 +01:00
if ( $status [ 'error' ] == FALSE )
2015-07-09 19:24:59 -07:00
{
2019-01-27 14:57:10 +01:00
$srch = array ( '[' , ']' );
$rpl = array ( " <a href='https://github.com/e107translations/Translator-Information' target='_blank'> " , " </a> " );
$text = str_replace ( $srch , $rpl , LANG_LAN_154 );
$text .= " <br /> " ;
$text .= $status [ 'message' ];
//$text .= $this->share($status['file']); // no longer notify by email, but only offer to download
$mes -> addSuccess ( $text );
2015-07-09 19:24:59 -07:00
}
else
{
2019-01-27 14:57:10 +01:00
$mes -> addError ( $status [ 'error' ]);
2015-07-09 19:24:59 -07:00
}
2019-01-27 14:57:10 +01:00
return array ( 'text' => $mes -> render (), 'caption' => '' );
2015-07-09 19:24:59 -07:00
}
2015-08-31 17:17:28 -07:00
/**
* Share Language File
2019-01-27 14:57:10 +01:00
*
* DEPRECATED - NO LONGER USED AS TRANSLATIONS ARE NOW MANAGED THROUGH GITHUB REPOSITORIES ( https :// github . com / e107translations )
*
2015-08-31 17:17:28 -07:00
* @ param object $newfile
* Usage of e107 is granted to you provided that this function is not modified or removed in any way .
* @ return
*/
private function share ( $newfile )
{
global $pref ;
if ( ! $newfile || E107_DEBUG_LEVEL > 0 )
{
return ;
}
global $tp ;
$full_link = $tp -> createConstants ( $newfile );
$email_message = " <br />Site: <a href=' " . SITEURL . " '> " . SITENAME . " </a>
< br /> User : " .USERNAME. " \n
< br /> Email : " .USEREMAIL. " \n
< br /> Language : " . $_POST['language'] . " \n
< br /> IP : " .USERIP. "
< br />... would like to contribute the following language pack for e107 . ( see attached ) < br />:
< br /> Missing Files : " . $_SESSION['lancheck'] [ $_POST['language'] ]['file']. "
< br /> Bom Errors : " . $_SESSION['lancheck'] [ $_POST['language'] ]['bom']. "
< br /> UTF Errors : " . $_SESSION['lancheck'] [ $_POST['language'] ]['utf']. "
< br /> Definition Errors : " . $_SESSION['lancheck'] [ $_POST['language'] ]['def']. "
< br /> Total Errors : " . $_SESSION['lancheck'] [ $_POST['language'] ]['total']. "
< br />
< br /> XML file : " . $_SESSION['lancheck'] [ $_POST['language'] ]['xml'];
require_once ( e_HANDLER . " mail.php " );
$send_to = ( ! $_POST [ 'contribute_pack' ]) ? " languagepacks@e107inc.org " : " certifiedpack@e107inc.org " ;
$to_name = " e107 Inc. " ;
$Cc = " " ;
$Bcc = " " ;
$returnpath = '' ;
$returnreceipt = '' ;
$inline = " " ;
$subject = ( ! $_POST [ 'contribute_pack' ]) ? " [0.7 LanguagePack] " : " [0.7 Certified LanguagePack] " ;
$subject .= basename ( $newfile );
if ( !@ sendemail ( $send_to , $subject , $email_message , $to_name , '' , '' , $newfile , $Cc , $Bcc , $returnpath , $returnreceipt , $inline ))
{
$text = " <div style='padding:40px'> " ;
$text .= defined ( 'LANG_LAN_EML' ) ? " <b> " . LANG_LAN_EML . " </b> " : " <b>There was a problem sending the language-pack. Please email your verified language pack to:</b> " ;
$text .= " <a href='mailto: " . $send_to . " ?subject= " . $subject . " '> " . $send_to . " </a> " ;
$text .= " </div> " ;
return $text ;
}
elseif ( $_POST [ 'contribute_pack' ])
{
return " <div style='padding:40px'>Pack Sent to e107 Inc. A confirmation email will be sent to " . $pref [ 'siteadminemail' ] . " once it is received.<br />Please also make sure that email coming from " . $send_to . " is not blocked by your spam filter.</div> " ;
}
}
2015-07-09 19:24:59 -07:00
/**
* @ param $language
* @ return bool | string
*/
private function findLocale ( $language )
{
if ( ! is_readable ( e_LANGUAGEDIR . $language . " / " . $language . " .php " ))
{
return FALSE ;
}
$code = file_get_contents ( e_LANGUAGEDIR . $language . " / " . $language . " .php " );
$tmp = explode ( " \n " , $code );
$srch = array ( " define " , " ' " , '"' , " ( " , " ) " , " ; " , " CORE_LC2 " , " CORE_LC " , " , " );
foreach ( $tmp as $line )
{
if ( strpos ( $line , " CORE_LC " ) !== FALSE && ( strpos ( $line , " CORE_LC2 " ) === FALSE ))
{
$lc = trim ( str_replace ( $srch , " " , $line ));
}
elseif ( strpos ( $line , " CORE_LC2 " ) !== FALSE )
{
$lc2 = trim ( str_replace ( $srch , " " , $line ));
}
}
if ( ! isset ( $lc ) || ! isset ( $lc2 ) || $lc == " " || $lc2 == " " )
{
return FALSE ;
}
return substr ( $lc , 0 , 2 ) . " _ " . strtoupper ( substr ( $lc2 , 0 , 2 ));
//
}
/**
* @ param $language
* @ return array
*/
private function makeLanguagePack ( $language )
{
$tp = e107 :: getParser ();
$ret = array ();
$ret [ 'file' ] = " " ;
if ( $_SESSION [ 'lancheck' ][ $language ][ 'total' ] > 0 && ! E107_DEBUG_LEVEL )
{
$ret = array ();
$ret [ 'error' ] = TRUE ;
2015-07-10 14:25:16 -07:00
$message = LANG_LAN_115 ;
2015-07-09 19:24:59 -07:00
$ret [ 'message' ] = str_replace ( " [x] " , $_SESSION [ 'lancheck' ][ $language ][ 'total' ], $message );
return $ret ;
}
if ( ! isset ( $_SESSION [ 'lancheck' ][ $language ]))
{
$ret = array ();
$ret [ 'error' ] = TRUE ;
2015-07-10 14:25:16 -07:00
$ret [ 'message' ] = LANG_LAN_116 ;
2015-07-09 19:24:59 -07:00
return $ret ;
}
if ( varset ( $_POST [ 'contribute_pack' ]) && varset ( $_SESSION [ 'lancheck' ][ $language ][ 'total' ]) != '0' )
{
$ret [ 'error' ] = TRUE ;
2015-07-10 14:25:16 -07:00
$ret [ 'message' ] = LANG_LAN_117 ;
2015-07-09 19:24:59 -07:00
$ret [ 'message' ] .= " <br /> " ;
2015-07-10 14:25:16 -07:00
$ret [ 'message' ] .= LANG_LAN_116 ;
2015-07-09 19:24:59 -07:00
return $ret ;
}
require_once ( e_HANDLER . 'pclzip.lib.php' );
2017-04-27 15:21:20 -07:00
list ( $ver , $tmp ) = explode ( " " , e_VERSION );
2015-07-09 19:24:59 -07:00
if ( ! $locale = $this -> findLocale ( $language ))
{
$ret [ 'error' ] = TRUE ;
$file = " e107_languages/ { $language } / { $language } .php " ;
$def = ( defined ( 'LANG_LAN_25' )) ? LANG_LAN_25 : LANG_LAN_119 ;
$ret [ 'message' ] = str_replace ( " [x] " , $file , $def ); //
return $ret ;
}
global $THEMES_DIRECTORY , $PLUGINS_DIRECTORY , $LANGUAGES_DIRECTORY , $HANDLERS_DIRECTORY , $HELP_DIRECTORY ;
if (( $HANDLERS_DIRECTORY != " e107_handlers/ " ) || ( $LANGUAGES_DIRECTORY != " e107_languages/ " ) || ( $THEMES_DIRECTORY != " e107_themes/ " ) || ( $HELP_DIRECTORY != " e107_docs/help/ " ) || ( $PLUGINS_DIRECTORY != " e107_plugins/ " ))
{
$ret [ 'error' ] = TRUE ;
$ret [ 'message' ] = ( defined ( 'LANG_LAN_26' )) ? LANG_LAN_26 : LANG_LAN_120 ;
return $ret ;
}
$newfile = e_MEDIA_FILE . " e107_ " . $ver . " _ " . $language . " _ " . $locale . " -utf8.zip " ;
$archive = new PclZip ( $newfile );
2017-11-07 14:21:06 -08:00
$file = $this -> getFileList ( $language );
2015-08-31 19:36:35 -07:00
2015-07-09 19:24:59 -07:00
$data = implode ( " , " , $file );
if ( $archive -> create ( $data , PCLZIP_OPT_REMOVE_PATH , e_BASE ) == 0 )
{
$ret [ 'error' ] = TRUE ;
$ret [ 'message' ] = $archive -> errorInfo ( true );
return $ret ;
}
else
{
$fileName = e_FILE . " public/ " . $language . " .xml " ;
if ( is_readable ( $fileName ))
{
@ unlink ( $fileName );
}
$fileData = ' < ? xml version = " 1.0 " encoding = " utf-8 " ?>
< e107Language name = " '. $language .' " compatibility = " '. $ver .' " date = " '.date( " Y - m - d " ).' " >
< author name = " '.USERNAME.' " email = " '.USEREMAIL.' " url = " '.SITEURL.' " />
</ e107Language > ' ;
if ( file_put_contents ( $fileName , $fileData ))
{
$addTag = $archive -> add ( $fileName , PCLZIP_OPT_ADD_PATH , 'e107_languages/' . $language , PCLZIP_OPT_REMOVE_PATH , e_FILE . 'public/' );
$_SESSION [ 'lancheck' ][ $language ][ 'xml' ] = " Yes " ;
}
else
{
$_SESSION [ 'lancheck' ][ $language ][ 'xml' ] = " No " ;
}
@ unlink ( $fileName );
$ret [ 'file' ] = $newfile ;
$ret [ 'message' ] = str_replace ( " ../ " , " " , e_MEDIA_FILE ) . " <a href=' " . $newfile . " ' > " . basename ( $newfile ) . " </a> " ;
$ret [ 'error' ] = FALSE ;
return $ret ;
}
}
2017-11-07 14:21:06 -08:00
private function getFileList ( $language )
{
if ( empty ( $language ))
{
return false ;
}
$PLUGINS_DIRECTORY = e107 :: getFolder ( 'plugins' );
$THEMES_DIRECTORY = e107 :: getFolder ( 'themes' );
$HELP_DIRECTORY = e107 :: getFolder ( 'help' );
$HANDLERS_DIRECTORY = e107 :: getFolder ( 'handlers' );
$core = $this -> getFilePaths ( e_LANGUAGEDIR . $language . " / " , $language , '' ); // includes admin area.
// $core_admin = $this->getFilePaths(e_BASE.$LANGUAGES_DIRECTORY.$language."/admin/", $language,'');
$core_admin = array ();
$plugs = $this -> getFilePaths ( e_BASE . $PLUGINS_DIRECTORY , $language , $this -> core_plugins ); // standardized path.
$theme = $this -> getFilePaths ( e_BASE . $THEMES_DIRECTORY , $language , $this -> core_themes );
$docs = $this -> getFilePaths ( e_BASE . $HELP_DIRECTORY , $language );
$handlers = $this -> getFilePaths ( e_BASE . $HANDLERS_DIRECTORY , $language ); // standardized path.
$file = array_merge ( $core , $core_admin , $plugs , $theme , $docs , $handlers );
$file = array_unique ( $file );
return $file ;
}
2020-08-19 10:02:14 -07:00
/** todo */
/* function removeLanguagePack ( $language )
2017-11-07 14:21:06 -08:00
{
$files = $this -> getFileList ( $language );
2020-08-19 10:02:14 -07:00
} */
2017-11-07 14:21:06 -08:00
2015-07-09 19:24:59 -07:00
/**
* @ param $path
* @ param $language
* @ param string $filter
* @ return array | bool
*/
2016-04-04 17:33:51 -07:00
public function getFilePaths ( $path , $language , $restrict = array ())
2015-07-09 19:24:59 -07:00
{
$fl = e107 :: getFile ();
2015-08-31 19:36:35 -07:00
if ( $lanlist = $fl -> get_files ( $path , " " , " standard " , 4 )) // (\.php|\.xml)$
2015-07-09 19:24:59 -07:00
{
sort ( $lanlist );
}
else
{
2015-08-31 19:36:35 -07:00
return array ();
2015-07-09 19:24:59 -07:00
}
2015-08-31 19:36:35 -07:00
2015-07-09 19:24:59 -07:00
$pzip = array ();
foreach ( $lanlist as $p )
{
$fullpath = $p [ 'path' ] . $p [ 'fname' ];
if ( strpos ( $fullpath , $language ) !== false )
{
$pzip [] = $fullpath ;
}
}
2015-08-31 19:36:35 -07:00
if ( ! empty ( $restrict )) // strip the list according to inclusion list.
{
$newlist = array ();
foreach ( $pzip as $k => $p )
{
foreach ( $restrict as $accept )
{
2016-04-04 17:33:51 -07:00
if ( strpos ( $p , '/' . $accept . '/' ) !== false )
2015-08-31 19:36:35 -07:00
{
$newlist [] = $p ;
}
}
}
$pzip = $newlist ;
}
2015-07-09 19:24:59 -07:00
return $pzip ;
}
/**
2017-04-23 12:38:05 -07:00
* Get Installed Language - Pack Meta Data .
* @ return array
2015-07-09 19:24:59 -07:00
*/
2017-04-23 12:38:05 -07:00
function getLocalLanguagePacks ()
2015-07-09 19:24:59 -07:00
{
2017-04-23 12:38:05 -07:00
$this -> installed_languages = e107 :: getLanguage () -> installed ();
2015-07-09 19:24:59 -07:00
2017-04-23 12:38:05 -07:00
$xml = e107 :: getXml ();
2015-07-09 19:24:59 -07:00
2017-04-23 12:38:05 -07:00
$arr = array ();
2015-07-09 19:24:59 -07:00
2017-04-23 12:38:05 -07:00
foreach ( $this -> installed_languages as $language )
2015-07-09 19:24:59 -07:00
{
if ( $language == " English " )
{
continue ;
}
2017-04-23 12:38:05 -07:00
2015-07-09 19:24:59 -07:00
$metaFile = e_LANGUAGEDIR . $language . " / " . $language . " .xml " ;
if ( is_readable ( $metaFile ))
{
2017-04-23 12:38:05 -07:00
$rawData = $xml -> loadXMLfile ( $metaFile , true );
2015-07-09 19:24:59 -07:00
if ( $rawData )
{
2017-04-23 12:38:05 -07:00
$value = $rawData [ '@attributes' ];
2015-07-09 19:24:59 -07:00
}
else
{
$value = array (
'date' => " " ,
'compatibility' => ' '
);
}
}
else
{
$value = array (
'date' => " " ,
'compatibility' => ' '
);
}
2017-04-23 12:38:05 -07:00
$value [ 'type' ] = 'local' ;
2015-07-09 19:24:59 -07:00
2017-04-23 12:38:05 -07:00
$arr [ $language ] = $value ;
2015-07-09 19:24:59 -07:00
}
2017-04-23 12:38:05 -07:00
return $arr ;
}
2015-07-09 19:24:59 -07:00
2017-04-23 12:38:05 -07:00
/**
* Get Online Language - Pack Meta Data .
* @ return array | bool
*/
public function getOnlineLanguagePacks ()
2015-07-09 19:24:59 -07:00
{
$xml = e107 :: getXml ();
2017-04-23 12:38:05 -07:00
$feed = 'https://e107.org/languagepacks.xml' ;
2015-07-09 19:24:59 -07:00
2018-08-24 12:51:06 -07:00
$version = e_VERSION ;
if ( ! empty ( $version ))
2017-11-07 14:21:06 -08:00
{
2020-08-19 10:02:14 -07:00
list ( $ver , $tmp ) = explode ( " - " , $version );
$feed .= " ?ver= " . preg_replace ( '/[^\d\.]/' , '' , $ver );
2017-11-07 14:21:06 -08:00
}
2020-08-19 10:02:14 -07:00
e107 :: getDebug () -> log ( " Language Pack Feed: " . $feed );
2017-04-23 12:38:05 -07:00
$languages = array ();
2015-07-09 19:24:59 -07:00
2017-09-14 12:07:30 -07:00
if ( $rawData = $xml -> loadXMLfile ( $feed , true ))
2015-07-09 19:24:59 -07:00
{
2017-04-23 12:38:05 -07:00
if ( empty ( $rawData [ 'language' ]))
2015-07-09 19:24:59 -07:00
{
2017-04-23 12:38:05 -07:00
return false ;
2015-07-09 19:24:59 -07:00
}
2018-07-04 12:09:25 +02:00
foreach ( $rawData [ 'language' ] as $key => $att )
2015-07-09 19:24:59 -07:00
{
2018-08-04 20:53:01 +02:00
// issue #3059 in case array @attributes is in $att
if ( is_int ( $key ) && is_array ( $att ) && array_key_exists ( '@attributes' , $att ))
{
$att = $att [ '@attributes' ];
}
2018-07-04 12:09:25 +02:00
// issue #3059 Language list didn't load
2018-08-04 20:53:01 +02:00
elseif ( $key != '@attributes' )
{
continue ;
}
2015-07-09 19:24:59 -07:00
2017-04-23 12:38:05 -07:00
$id = $att [ 'name' ];
2015-07-09 19:24:59 -07:00
2018-07-04 12:09:25 +02:00
// fix github double url bug...
if ( stripos ( $att [ 'url' ], 'https://github.comhttps://github.com' ) !== false )
{
$att [ 'url' ] = str_ireplace ( 'https://github.comhttps://github.com' , 'https://github.com' , $att [ 'url' ]);
}
if ( stripos ( $att [ 'infourl' ], 'https://github.comhttps://github.com' ) !== false )
{
$att [ 'infourl' ] = str_ireplace ( 'https://github.comhttps://github.com' , 'https://github.com' , $att [ 'infourl' ]);
}
2017-04-23 12:38:05 -07:00
$languages [ $id ] = array (
'name' => $att [ 'name' ],
'author' => $att [ 'author' ],
'infoURL' => $att [ 'infourl' ],
2017-11-07 14:21:06 -08:00
'tag' => $att [ 'tag' ],
2017-04-23 12:38:05 -07:00
// 'folder' => $att['folder'],
'version' => $att [ 'version' ],
'date' => $att [ 'date' ],
'compatibility' => $att [ 'compatibility' ],
'url' => $att [ 'url' ],
'type' => 'online'
);
2015-07-09 19:24:59 -07:00
}
}
2017-09-14 12:07:30 -07:00
else
{
e107 :: getDebug () -> log ( " Language Pack Feed Failed: " . $xml -> getLastErrorMessage ());
}
2015-07-09 19:24:59 -07:00
2017-04-23 12:38:05 -07:00
return $languages ;
}
2015-07-09 19:24:59 -07:00
function check_all ( $mode = 'render' , $lan = null )
2013-10-27 21:28:40 -07:00
{
// global $ns,$tp;
$mes = e107 :: getMessage ();
$tp = e107 :: getParser ();
2015-07-09 19:24:59 -07:00
if ( empty ( $lan ))
{
echo " debug: " . __METHOD__ . " missing \$ lan " ;
return false ;
}
2013-10-27 21:28:40 -07:00
2015-07-09 19:24:59 -07:00
// $lan = key($_POST['language_sel']);
2013-10-27 21:28:40 -07:00
2015-07-09 19:24:59 -07:00
$_SESSION [ 'lancheck' ][ $lan ] = array ();
$_SESSION [ 'lancheck' ][ $lan ][ 'file' ] = 0 ;
$_SESSION [ 'lancheck' ][ $lan ][ 'def' ] = 0 ;
$_SESSION [ 'lancheck' ][ $lan ][ 'bom' ] = 0 ;
$_SESSION [ 'lancheck' ][ $lan ][ 'utf' ] = 0 ;
$_SESSION [ 'lancheck' ][ $lan ][ 'total' ] = 0 ;
2013-10-27 21:28:40 -07:00
2015-07-09 19:24:59 -07:00
$core_text = $this -> check_core_lanfiles ( $lan );
$core_admin = $this -> check_core_lanfiles ( $lan , " admin/ " );
2013-10-27 21:28:40 -07:00
$plug_text = " " ;
$theme_text = " " ;
// Plugins -------------
$plug_header = " <table class='table table-striped'>
< tr >
< td class = 'fcaption' > " .LAN_PLUGIN. " </ td >
< td class = 'fcaption' > " .LAN_CHECK_16. " </ td >
2015-07-09 19:24:59 -07:00
< td class = 'fcaption' > " . $lan . " </ td >
2013-10-27 21:28:40 -07:00
< td class = 'fcaption' > " .LAN_OPTIONS. " </ td ></ tr > " ;
foreach ( $this -> core_plugins as $plugs )
{
if ( is_readable ( e_PLUGIN . $plugs ))
{
2015-07-09 19:24:59 -07:00
$plug_text .= $this -> check_lanfiles ( 'P' , $plugs , " English " , $lan );
2013-10-27 21:28:40 -07:00
}
}
$plug_footer = " </table> " ;
// Themes -------------
$theme_header = " <table class='table table-striped'>
< tr >
2016-10-10 20:06:43 +01:00
< td class = 'fcaption' > " .LAN_THEME. " </ td >
2013-10-27 21:28:40 -07:00
< td class = 'fcaption' > " .LAN_CHECK_16. " </ td >
2015-07-09 19:24:59 -07:00
< td class = 'fcaption' > " . $lan . " </ td >
2013-10-27 21:28:40 -07:00
< td class = 'fcaption' > " .LAN_OPTIONS. " </ td ></ tr > " ;
foreach ( $this -> core_themes as $them )
{
if ( is_readable ( e_THEME . $them ))
{
2015-07-09 19:24:59 -07:00
$theme_text .= $this -> check_lanfiles ( 'T' , $them , " English " , $lan );
2013-10-27 21:28:40 -07:00
}
}
$theme_footer = " </table> " ;
// -------------------------
if ( $mode != 'render' )
{
2020-08-19 10:02:14 -07:00
return null ;
2013-10-27 21:28:40 -07:00
}
2015-07-09 19:24:59 -07:00
$message = "
2017-04-23 12:38:05 -07:00
< form id = 'lancheck' method = 'post' action = '".e_ADMIN."language.php?mode=main&action=tools' >
2013-10-27 21:28:40 -07:00
< div > \n " ;
2020-08-19 10:02:14 -07:00
// $icon = ($_SESSION['lancheck'][$lan]['total']>0) ? ADMIN_FALSE_ICON : ADMIN_TRUE_ICON;
2013-10-27 21:28:40 -07:00
2015-02-14 23:34:15 -08:00
$errors_diz = ( deftrue ( 'LAN_CHECK_23' )) ? LAN_CHECK_23 : " Errors Found " ;
2017-04-23 12:38:05 -07:00
2015-07-09 19:24:59 -07:00
$message .= $errors_diz . " : " . $_SESSION [ 'lancheck' ][ $lan ][ 'total' ];
2013-10-27 21:28:40 -07:00
2015-02-14 23:34:15 -08:00
$just_go_diz = ( deftrue ( 'LAN_CHECK_20' )) ? LAN_CHECK_20 : " Generate Language Pack " ;
$lang_sel_diz = ( deftrue ( 'LAN_CHECK_21' )) ? LAN_CHECK_21 : " Verify Again " ;
$lan_pleasewait = ( deftrue ( 'LAN_PLEASEWAIT' )) ? $tp -> toJS ( LAN_PLEASEWAIT ) : " Please Wait " ;
2013-10-27 21:28:40 -07:00
$message .= "
< br />< br />
2015-07-09 19:24:59 -07:00
< input type = 'hidden' name = 'language' value = '".$lan."' />
2013-10-27 21:28:40 -07:00
< input type = 'hidden' name = 'errorsonly' value = '".$_SESSION[' lancheck - errors - only ']."' />
2015-07-09 19:24:59 -07:00
< input class = 'btn btn-primary' type = 'submit' name = 'ziplang[".$lan."]' value = \ " " . $just_go_diz . " \" onclick= \" this.value = ' " . $lan_pleasewait . " ' \" />
2017-02-26 05:52:47 +01:00
< a href = '".e_REQUEST_URI."' class = 'btn btn-default' > " . $lang_sel_diz . " </ a >
2013-10-27 21:28:40 -07:00
</ div >
</ form >
" ;
2015-07-09 19:24:59 -07:00
// print_a($_SESSION['lancheck'][$lan]);
2013-10-27 21:28:40 -07:00
2015-07-09 19:24:59 -07:00
$plug_text = ( $plug_text ) ? $plug_header . $plug_text . $plug_footer : " <div class='alert alert-success'> " . LAN_OK . " </div> " ;
$theme_text = ( $theme_text ) ? $theme_header . $theme_text . $theme_footer : " <div class='alert alert-success'> " . LAN_OK . " </div> " ;
2013-10-27 21:28:40 -07:00
2015-07-09 19:24:59 -07:00
$mesStatus = ( $_SESSION [ 'lancheck' ][ $lan ][ 'total' ] > 0 ) ? E_MESSAGE_INFO : E_MESSAGE_SUCCESS ;
2013-10-27 21:28:40 -07:00
$mes -> add ( $message , $mesStatus );
2016-10-10 20:06:43 +01:00
// $ns -> tablerender(LAN_SUMMARY.": ".$lan,$message);
2015-07-09 19:24:59 -07:00
$ret = array ();
$ret [ 'text' ] = $mes -> render ();
$tabs = array (
2016-10-10 20:06:43 +01:00
'core' => array ( 'caption' => LAN_CHECK_26 , 'text' => $core_text ),
'admin' => array ( 'caption' => LAN_ADMIN , 'text' => $core_admin ),
'plugin' => array ( 'caption' => ADLAN_CL_7 , 'text' => $plug_text ),
'theme' => array ( 'caption' => LAN_THEMES , 'text' => $theme_text ),
2015-07-09 19:24:59 -07:00
);
$ret [ 'text' ] .= e107 :: getForm () -> tabs ( $tabs );
$ret [ 'caption' ] = LAN_CHECK_2 . SEP . $lan ;
return $ret ;
/*
$ns -> tablerender ( LANG_LAN_21 . SEP . $lan . SEP . LAN_CHECK_2 , $core_text );
$ns -> tablerender ( LAN_CHECK_3 . " : " . $lan . " /admin " , $core_admin );
2013-10-27 21:28:40 -07:00
$ns -> tablerender ( ADLAN_CL_7 , $plug_text );
2016-10-10 20:06:43 +01:00
$ns -> tablerender ( LAN_THEMES , $theme_text ); */
2015-07-09 19:24:59 -07:00
//TODO Add a return statement here.
2013-10-27 21:28:40 -07:00
}
2015-07-09 19:24:59 -07:00
2013-10-27 21:28:40 -07:00
function write_lanfile ( $lan = '' )
{
if ( ! $lan ){ return ; }
2017-10-14 14:55:30 -07:00
2013-10-27 21:28:40 -07:00
global $ns ;
unset ( $input );
$kom_start = chr ( 47 ) . " * " ;
$kom_end = " * " . chr ( 47 );
2017-11-06 17:32:00 -08:00
if ( ! empty ( $_SESSION [ 'lancheck-edit-file' ]))
2013-10-27 21:28:40 -07:00
{
$writeit = $_SESSION [ 'lancheck-edit-file' ];
}
else
{
2017-11-06 17:32:00 -08:00
e107 :: getMessage () -> addError ( " There is a problem with sessions " );
return ;
2013-10-27 21:28:40 -07:00
}
$old_kom = " " ;
$in_kom = 0 ;
if ( is_readable ( $writeit )) // File Exists;
{
$data = file ( $writeit );
foreach ( $data as $line )
{
if ( strpos ( $line , $kom_start ) !== False && $old_kom == " " )
{
$in_kom = 1 ;
}
if ( $in_kom ) { $old_kom .= $line ; }
if ( strpos ( $line , $kom_end ) !== False && $in_kom ) { $in_kom = 0 ;}
}
}
$message = " <div style='text-align:left'><br /> " ;
2015-07-09 19:24:59 -07:00
$input = chr ( 60 ) . " ?php \n " ;
2013-10-27 21:28:40 -07:00
if ( $old_kom == " " )
{
// create CVS compatible description.
$diz = chr ( 47 ) . " * \n " ;
$diz .= " +---------------------------------------------------------------+ \n " ;
$diz .= " | e107 website content management system " . $lan . " Language File \n " ;
$diz .= " | Released under the terms and conditions of the \n " ;
$diz .= " | GNU General Public License (http://gnu.org). \n " ;
2015-08-31 17:17:28 -07:00
$diz .= " | Last Modified: " . date ( " Y/m/d H:i:s " ) . " \n " ;
2013-10-27 21:28:40 -07:00
$diz .= " | \n " ;
2015-08-31 17:17:28 -07:00
// $diz .= "| ".chr(36)."URL: $writeit ".chr(36)."\n";
// $diz .= "| ".chr(36)."Revision: 1.0 ".chr(36)."\n";
// $diz .= "| ".chr(36)."Id: ".date("Y/m/d H:i:s")." ".chr(36)."\n";
2013-10-27 21:28:40 -07:00
$diz .= " | " . chr ( 36 ) . " Author: " . USERNAME . " " . chr ( 36 ) . " \n " ;
$diz .= " +---------------------------------------------------------------+ \n " ;
$diz .= " * " . chr ( 47 ) . " \n \n " ;
}
else
{
$diz = $old_kom ;
}
$input .= $diz ;
$message .= str_replace ( " \n " , " <br /> " , $diz );
2020-12-20 11:50:10 -08:00
for ( $i = 0 , $iMax = count ( $_POST [ 'newlang' ]); $i < $iMax ; $i ++ )
2013-10-27 21:28:40 -07:00
{
$notdef_start = " " ;
$notdef_end = " \n " ;
$deflang = ( MAGIC_QUOTES_GPC === TRUE ) ? stripslashes ( $_POST [ 'newlang' ][ $i ]) : $_POST [ 'newlang' ][ $i ];
$func = " define " ;
$quote = chr ( 34 );
if ( strpos ( $_POST [ 'newdef' ][ $i ], " ndef++ " ) !== FALSE )
{
$defvar = str_replace ( " ndef++ " , " " , $_POST [ 'newdef' ][ $i ]);
$notdef_start = " if (!defined( " . chr ( 34 ) . $defvar . chr ( 34 ) . " )) { " ;
$notdef_end = " } \n " ;
}
else
{
$defvar = $_POST [ 'newdef' ][ $i ];
}
2017-10-14 14:55:30 -07:00
if ( empty ( $deflang ))
{
continue ;
}
2013-10-27 21:28:40 -07:00
2015-02-14 23:34:15 -08:00
if ( $_POST [ 'newdef' ][ $i ] == " LC_ALL " && vartrue ( $_SESSION [ 'lancheck-edit-file' ]))
2013-10-27 21:28:40 -07:00
{
$message .= $notdef_start . 'setlocale(' . htmlentities ( $defvar ) . ',' . $deflang . ');<br />' . $notdef_end ;
$input .= $notdef_start . " setlocale( " . $defvar . " , " . $deflang . " ); " . $notdef_end ;
}
else
{
$message .= $notdef_start . $func . '(' . $quote . htmlentities ( $defvar ) . $quote . ',"' . $deflang . '");<br />' . $notdef_end ;
$input .= $notdef_start . $func . " ( " . $quote . $defvar . $quote . " , " . chr ( 34 ) . $deflang . chr ( 34 ) . " ); " . $notdef_end ;
}
}
$message .= " <br /> " ;
$message .= " </div> " ;
2017-10-14 15:51:27 -07:00
/*
$input .= " \n \n ?> " ;
*/
2013-10-27 21:28:40 -07:00
// Write to file.
$writeit = str_replace ( " // " , " / " , $writeit ); // Quick Fix.
$fp = @ fopen ( $writeit , " w " );
if ( !@ fwrite ( $fp , $input ))
{
$caption = LAN_ERROR ;
$message = LAN_CHECK_17 ;
2015-07-09 19:24:59 -07:00
$status = e107 :: getMessage () -> addError ( $caption ) -> render ();
2013-10-27 21:28:40 -07:00
}
else
{
2020-12-30 10:11:04 -08:00
// $caption = LAN_SAVED." <b>".$lan."/".$writeit."</b>";
$caption = LAN_SAVED . " <b> " . $writeit . " </b> " ;
2015-07-09 19:24:59 -07:00
$status = e107 :: getMessage () -> addSuccess ( $caption ) -> render ();
2013-10-27 21:28:40 -07:00
}
fclose ( $fp );
2015-07-09 19:24:59 -07:00
/*
2013-10-27 21:28:40 -07:00
$message .= " <form method='post' action=' " . e_SELF . " ?tools' id='select_lang'>
< div style = 'text-align:center' >< br /> " ;
$message .= " <br /><br /><input class='btn' type='submit' name='language_sel[ " . $lan . " ]' value= \" " . LAN_BACK . " \" />
2015-07-09 19:24:59 -07:00
</ div ></ form > " ;*/
2013-10-27 21:28:40 -07:00
unset ( $_SESSION [ 'lancheck-edit-file' ]);
2015-07-09 19:24:59 -07:00
$ns -> tablerender ( $caption , $status . $message );
2013-10-27 21:28:40 -07:00
}
function check_core_lanfiles ( $checklan , $subdir = '' )
{
2015-07-10 14:25:16 -07:00
$tp = e107 :: getParser ();
2013-10-27 21:28:40 -07:00
// $sql->db_Mark_Time('Start Get Core Lan Phrases English');
2016-03-30 19:01:51 +02:00
$English = $this -> get_comp_lan_phrases ( e_LANGUAGEDIR . " English/ " . $subdir , " English " );
2013-10-27 21:28:40 -07:00
// $sql->db_Mark_Time('End Get Core Lan Phrases English');
$check = $this -> get_comp_lan_phrases ( e_LANGUAGEDIR . $checklan . " / " . $subdir , $checklan );
// print_a($check);
// return;
$text = " " ;
$header = " <table class='table table-striped'>
< tr >
< th > " .LAN_CHECK_16. " </ th >
2015-07-10 14:25:16 -07:00
< th > " . $this->transLanguage . " " .LAN_FILE. " </ th >
2013-10-27 21:28:40 -07:00
< th > " .LAN_OPTIONS. " </ th ></ tr > " ;
$keys = array_keys ( $English );
sort ( $keys );
$er = " " ;
foreach ( $keys as $k )
{
2015-07-09 19:24:59 -07:00
if ( $k == 'bom' )
2013-10-27 21:28:40 -07:00
{
2015-07-09 19:24:59 -07:00
continue ;
}
2013-10-27 21:28:40 -07:00
$lnk = $k ;
$k_check = str_replace ( " English " , $checklan , $k );
if ( array_key_exists ( $k , $check ))
{
// $text .= "<tr><td class='forumheader3' style='width:45%'>{$lnk}</td>";
$subkeys = array_keys ( $English [ $k ]);
$er = " " ;
$utf_error = " " ;
$bomkey = str_replace ( " .php " , " " , $k_check );
2015-07-10 14:25:16 -07:00
2013-10-27 21:28:40 -07:00
2015-07-09 19:24:59 -07:00
if ( ! empty ( $check [ 'bom' ][ $bomkey ]))
2013-10-27 21:28:40 -07:00
{
2015-07-10 14:25:16 -07:00
$bom_error = " <i> " . $tp -> lanVars ( LAN_CHECK_15 , array ( " '<?php' " , " '?>' " )) . " </i><br /> " ; // illegal chars
2015-07-09 19:24:59 -07:00
$this -> checkLog ( 'bom' , 1 );;
2013-10-27 21:28:40 -07:00
}
else
{
$bom_error = " " ;
}
foreach ( $subkeys as $sk )
{
2015-07-09 19:24:59 -07:00
if ( $utf_error == " " && ! empty ( $check [ $k ][ $sk ]) && ! $this -> is_utf8 ( $check [ $k ][ $sk ]))
2013-10-27 21:28:40 -07:00
{
$utf_error = " <i> " . LAN_CHECK_19 . " </i><br /> " ;
$this -> checkLog ( 'utf' , 1 );
}
if ( $sk == " LC_ALL " ){
$check [ $k ][ $sk ] = str_replace ( chr ( 34 ) . chr ( 34 ), " " , $check [ $k ][ $sk ]);
}
$er .= $this -> check_lan_errors ( $English [ $k ], $check [ $k ], $sk );
}
if ( $this -> errorsOnly == TRUE && ! $er && ! $utf_error && ! $bom_error )
{
continue ;
}
$text .= " <tr><td class='forumheader3' style='width:45%'> { $lnk } </td> " ;
$style = ( $er ) ? " forumheader2 " : " forumheader3 " ;
$text .= " <td class=' { $style } ' style='width:50%'><div class='smalltext'> " ;
$text .= $bom_error . $utf_error ;
2017-04-23 12:38:05 -07:00
$text .= ( ! $er && ! $bom_error && ! $utf_error ) ? ADMIN_TRUE_ICON : $er . " <br /> " ;
2013-10-27 21:28:40 -07:00
$text .= " </div></td> " ;
}
else
{
$this -> checkLog ( 'file' , 1 );
2015-07-10 15:41:07 -07:00
// $this->newFile(e_LANGUAGEDIR.$checklan."/".$subdir.$lnk,$checklan);
2013-10-27 21:28:40 -07:00
$text .= " <tr>
< td class = 'forumheader3' style = 'width:45%' > { $lnk } </ td >
< td class = 'forumheader' style = 'width:50%' > " .LAN_CHECK_4. " </ td > " ; // file missing.
}
2015-07-09 19:24:59 -07:00
2013-10-27 21:28:40 -07:00
// Leave in EDIT button for all entries - to allow re-translation of bad entries.
$subpath = ( $subdir != '' ) ? $subdir . $k : $k ;
2015-07-09 19:24:59 -07:00
$parms = $_GET ;
$parms [ 'sub' ] = 'edit' ;
$parms [ 'file' ] = $subpath ;
$parms [ 'lan' ] = $this -> transLanguage ;
$parms [ 'iframe' ] = 1 ;
$editUrl = e_REQUEST_SELF . " ? " . http_build_query ( $parms , '&' );
2013-10-27 21:28:40 -07:00
$text .= " <td class='center' style='width:5%'>
2017-02-21 07:09:58 +01:00
< a href = '".$editUrl."' data - modal - caption = '".$subpath."' class = 'e-modal btn btn-primary' type = 'button' > " .LAN_EDIT. " </ a > " ;
2013-10-27 21:28:40 -07:00
$text .= " </td></tr> " ;
2015-07-09 19:24:59 -07:00
2013-10-27 21:28:40 -07:00
}
$footer = " </table> " ;
if ( $text )
{
return $header . $text . $footer ;
}
else
{
return " <div> " . LAN_OK . " </div> " ;
}
}
2017-10-17 07:49:13 -07:00
function check_lan_errors ( $english , $translation , $def , $opts = array ())
2013-10-27 21:28:40 -07:00
{
$eng_line = $english [ $def ];
2015-07-09 19:24:59 -07:00
$trans_line = ! empty ( $translation [ $def ]) ? $translation [ $def ] : '' ;
2013-10-27 21:28:40 -07:00
// return $eng_line."<br />".$trans_line."<br /><br />";
$error = array ();
2015-05-26 13:08:09 -07:00
$warning = array ();
2013-10-27 21:28:40 -07:00
2017-11-06 13:27:44 -08:00
if (( is_array ( $translation ) && ! array_key_exists ( $def , $translation ) && $eng_line != " " ) || ( trim ( $trans_line ) == " " && $eng_line != " " ))
2013-10-27 21:28:40 -07:00
{
$this -> checkLog ( 'def' , 1 );
return $def . " : " . LAN_CHECK_5 . " <br /> " ;
}
2015-05-26 13:08:09 -07:00
2017-10-17 07:49:13 -07:00
if ( empty ( $opts [ 'no-warning' ]) && ( $eng_line == $trans_line && ! empty ( $eng_line )))
2015-05-26 13:08:09 -07:00
{
2017-04-28 10:51:45 +02:00
$warning [] = " <span class='text-warning'> " . $def . " : " . LAN_CHECK_29 . " </span> " ;
2015-05-26 13:08:09 -07:00
}
2013-10-27 21:28:40 -07:00
if (( strpos ( $eng_line , " [link= " ) !== FALSE && strpos ( $trans_line , " [link= " ) === FALSE ) || ( strpos ( $eng_line , " [b] " ) !== FALSE && strpos ( $trans_line , " [b] " ) === FALSE ))
{
2017-04-28 10:51:45 +02:00
$error [] = $def . " : " . LAN_CHECK_30 ;
2013-10-27 21:28:40 -07:00
}
elseif (( strpos ( $eng_line , " [ " ) !== FALSE && strpos ( $trans_line , " [ " ) === FALSE ) || ( strpos ( $eng_line , " ] " ) !== FALSE && strpos ( $trans_line , " ] " ) === FALSE ))
{
2017-04-28 10:51:45 +02:00
$error [] = $def . " : " . LAN_CHECK_31 ;
2013-10-27 21:28:40 -07:00
}
2015-09-05 20:02:51 -07:00
if (( strpos ( $eng_line , " --LINK-- " ) !== false && strpos ( $trans_line , " --LINK-- " ) === false ))
2013-10-27 21:28:40 -07:00
{
$error [] = $def . " : Missing --LINK-- " ;
}
2015-09-05 20:02:51 -07:00
if (( strpos ( $eng_line , " e107.org " ) !== false && strpos ( $trans_line , " e107.org " ) === false ))
2013-10-27 21:28:40 -07:00
{
$error [] = $def . " : Missing e107.org URL " ;
}
2015-09-05 20:02:51 -07:00
if (( strpos ( $eng_line , " e107coders.org " ) !== FALSE && strpos ( $trans_line , " e107coders.org " ) === false ))
2013-10-27 21:28:40 -07:00
{
$error [] = $def . " : Missing e107coders.org URL " ;
}
if ( strip_tags ( $eng_line ) != $eng_line )
{
$stripped = strip_tags ( $trans_line );
if (( $stripped == $trans_line ))
{
// echo "<br /><br />".$def. "<br />".$stripped."<br />".$trans_line;
2017-04-28 10:51:45 +02:00
$error [] = $def . " : " . LAN_CHECK_32 ;
2013-10-27 21:28:40 -07:00
}
}
$this -> checkLog ( 'def' , count ( $error ));
2015-05-26 13:08:09 -07:00
$text = ( $error ) ? implode ( " <br /> " , $error ) . " <br /> " : " " ;
$text .= ( $warning ) ? implode ( " <br /> " , $warning ) . " <br /> " : " " ;
if ( $text )
{
return $text ;
}
2013-10-27 21:28:40 -07:00
}
2020-11-27 17:00:32 +01:00
function checkLog ( $type = 'error' , $count = 1 )
2013-10-27 21:28:40 -07:00
{
2015-07-09 19:24:59 -07:00
$lan = $this -> transLanguage ;
$_SESSION [ 'lancheck' ][ $lan ][ $type ] += $count ;
$_SESSION [ 'lancheck' ][ $lan ][ 'total' ] += $count ;
2013-10-27 21:28:40 -07:00
}
function get_lan_file_phrases ( $dir1 , $dir2 , $file1 , $file2 ){
$ret = array ();
$fname = $dir1 . $file1 ;
$type = 'orig' ;
if ( is_file ( $fname ))
{
$data = file_get_contents ( $fname );
$ret = $ret + $this -> fill_phrases_array ( $data , $type );
if ( substr ( $data , 0 , 5 ) != " <?php " )
{
$key = str_replace ( " .php " , " " , $fname );
$ret [ 'bom' ][ $key ] = $fname ;
}
}
$fname = $dir2 . $file2 ;
$type = 'tran' ;
if ( is_file ( $fname ))
{
$data = file_get_contents ( $fname );
$ret = $ret + $this -> fill_phrases_array ( $data , $type );
if ( substr ( $data , 0 , 5 ) != " <?php " )
{
$key = str_replace ( " .php " , " " , $fname );
$ret [ 'bom' ][ $key ] = $fname ;
}
}
elseif ( substr ( $fname , - 4 ) == " .php " )
{
file_put_contents ( $fname , " <?php \n \n ?> " );
}
return $ret ;
}
function get_comp_lan_phrases ( $comp_dir , $lang , $depth = 0 )
{
if ( ! is_dir ( $comp_dir ))
{
return array ();
}
2015-07-08 14:52:16 -07:00
$fl = e107 :: getFile ();
2015-08-31 17:17:28 -07:00
$tp = e107 :: getParser ();
2015-07-08 14:52:16 -07:00
2013-10-27 21:28:40 -07:00
$ret = array ();
if ( $lang_array = $fl -> get_files ( $comp_dir , " .php $ " , " standard " , $depth )){
sort ( $lang_array );
}
2015-08-31 17:17:28 -07:00
foreach ( $lang_array as $k => $f )
{
2016-03-30 19:01:51 +02:00
$path = str_replace ( e_LANGUAGEDIR . $lang . " / " , " " , $f [ 'path' ] . $f [ 'fname' ]);
2015-08-31 17:17:28 -07:00
if ( in_array ( $path , $this -> deprecatedFiles ))
{
unset ( $lang_array [ $k ]);
}
}
2015-07-08 14:52:16 -07:00
if ( strpos ( $comp_dir , e_LANGUAGEDIR ) !== false )
{
$regexp = " #.php# " ;
$mode = 'core' ;
}
2017-10-14 13:05:59 -07:00
elseif ( strpos ( $comp_dir , e_THEME ) !== false )
{
$regexp = " # " . $lang . " # " ;
$mode = 'themes' ;
// var_dump($lang_array);
}
2015-07-08 14:52:16 -07:00
else
{
$regexp = " # " . $lang . " # " ;
$mode = 'plugins' ;
}
2013-10-27 21:28:40 -07:00
2015-07-08 14:52:16 -07:00
// $regexp = (strpos($comp_dir,e_LANGUAGEDIR) !== FALSE) ? "#.php#" : "#".$lang."#";
2017-10-14 13:05:59 -07:00
2013-10-27 21:28:40 -07:00
foreach ( $lang_array as $f )
{
2015-07-08 14:52:16 -07:00
if ( $mode == 'plugins' )
{
$tmpDir = str_replace ( $comp_dir , '' , $f [ 'path' ]);
// echo "<br />".$tmpDir;
list ( $pluginDirectory , $other ) = explode ( " / " , $tmpDir , 2 );
if ( $mode == 'plugins' && ( $this -> thirdPartyPlugins !== true ) && ! in_array ( $pluginDirectory , $this -> core_plugins ))
{
continue ;
}
}
2017-10-14 13:05:59 -07:00
if ( $mode == 'themes' )
{
$tmpDir = str_replace ( $comp_dir , '' , $f [ 'path' ]);
// echo "<br />".$tmpDir;
list ( $themeDirectory , $other ) = explode ( " / " , $tmpDir , 2 );
if ( $mode == 'themes' && ( $this -> thirdPartyPlugins !== true ) && ! in_array ( $themeDirectory , $this -> core_themes ))
{
continue ;
}
}
2013-10-27 21:28:40 -07:00
if ( preg_match ( $regexp , $f [ 'path' ] . $f [ 'fname' ]) && is_file ( $f [ 'path' ] . $f [ 'fname' ]))
{
$allData = file_get_contents ( $f [ 'path' ] . $f [ 'fname' ]);
$data = explode ( " \n " , $allData );
// $data = file($f['path'].$f['fname']);
$relpath = str_replace ( $comp_dir , " " , $f [ 'path' ]);
$key = str_replace ( " .php " , " " , $relpath . $f [ 'fname' ]);
if ( substr ( $data [ 0 ], 0 , 5 ) != " <?php " )
{
$ret [ 'bom' ][ $key ] = $f [ 'fname' ];
}
$end_of_file = 0 ;
foreach ( $data as $line )
{
if ( $end_of_file == 1 )
{
$ret [ 'bom' ][ $key ] = $f [ 'fname' ];
}
$line = trim ( $line );
if ( $line == " ?> " )
{
$end_of_file = 1 ;
}
}
if ( $f [ 'path' ] . $f [ 'fname' ] == e_LANGUAGEDIR . $lang . " / " . $lang . " .php " )
{
$f [ 'fname' ] = " English.php " ; // change the key for the main language file.
}
if ( $f [ 'path' ] . $f [ 'fname' ] == e_LANGUAGEDIR . $lang . " / " . $lang . " _custom.php " )
{
$f [ 'fname' ] = " English_custom.php " ; // change the key for the main language file.
}
$ret = $ret + $this -> fill_phrases_array ( $allData , $relpath . $f [ 'fname' ]);
}
}
2015-08-31 17:17:28 -07:00
2013-10-27 21:28:40 -07:00
return $ret ;
}
// for plugins and themes - checkes what kind of language files directory structure we have
2020-11-27 17:00:32 +01:00
function check_lanfiles ( $mode , $comp_name , $base_lan = " English " , $target_lan = null )
2015-07-10 14:25:16 -07:00
{
2020-11-27 17:00:32 +01:00
if ( empty ( $target_lan )) throw new RuntimeException ( __METHOD__ . ' requires non-empty $target_lan' );
2015-07-10 14:25:16 -07:00
$tp = e107 :: getParser ();
2013-10-27 21:28:40 -07:00
$folder [ 'P' ] = e_PLUGIN . $comp_name ;
$folder [ 'T' ] = e_THEME . $comp_name ;
$comp_dir = $folder [ $mode ];
$baselang = $this -> get_comp_lan_phrases ( $comp_dir . " /languages/ " , " English " , 1 );
2015-07-22 19:49:02 -07:00
$check = $this -> get_comp_lan_phrases ( $comp_dir . " /languages/ " , $target_lan , 1 );
2013-10-27 21:28:40 -07:00
$text = " " ;
$keys = array_keys ( $baselang );
sort ( $keys );
foreach ( $keys as $k )
{
if ( $k == 'bom' )
{
continue ;
}
$lnk = $k ;
//echo "klucz ".$k."<br />";
$k_check = str_replace ( " English " , $target_lan , $k );
if ( array_key_exists ( $k_check , $check ))
{
$subkeys = array_keys ( $baselang [ $k ]);
$er = " " ;
$utf_error = " " ;
$bomkey = str_replace ( " .php " , " " , $k_check );
if ( $check [ 'bom' ][ $bomkey ])
{
2015-07-10 14:25:16 -07:00
$bom_error = " <i> " . $tp -> lanVars ( LAN_CHECK_15 , array ( " '<?php' " , " '?>' " )) . " </i><br /> " ;
2015-07-09 19:24:59 -07:00
$this -> checkLog ( 'bom' , 1 );
2013-10-27 21:28:40 -07:00
}
else
{
$bom_error = " " ;
}
// $bom_error = ($check['bom'][$bomkey]) ? "<i>".LAN_CHECK_15."</i><br />" : ""; // illegal chars
foreach ( $subkeys as $sk )
{
2015-07-09 19:24:59 -07:00
if ( $utf_error == " " && ! empty ( $check [ $k_check ][ $sk ]) && ! $this -> is_utf8 ( $check [ $k_check ][ $sk ]))
2013-10-27 21:28:40 -07:00
{
$utf_error = " <i> " . LAN_CHECK_19 . " </i><br /> " ;
$this -> checkLog ( 'utf' , 1 );
}
/*
if ( ! array_key_exists ( $sk , $check [ $k_check ]) || ( trim ( $check [ $k_check ][ $sk ]) == " " && $baselang [ $k ][ $sk ] != " " ))
{
$er .= ( $er ) ? " <br /> " : " " ;
$er .= $sk . " " . LAN_CHECK_5 ;
}
*/
$er .= $this -> check_lan_errors ( $baselang [ $k ], $check [ $k_check ], $sk );
}
if ( $this -> errorsOnly == TRUE && ! $er && ! $utf_error && ! $bom_error )
{
continue ;
}
$text .= " <tr>
< td class = 'forumheader3' style = 'width:20%' > " . $comp_name . " </ td >
< td class = 'forumheader3' style = 'width:25%' > " .str_replace( " English / " , " " , $lnk ). " </ td > " ;
$style = ( $er ) ? " forumheader2 " : " forumheader3 " ;
$text .= " <td class=' { $style } ' style='width:50%'><div class='smalltext'> " ;
$text .= $bom_error . $utf_error ;
2017-04-23 12:38:05 -07:00
$text .= ( ! $er && ! $bom_error && ! $utf_error ) ? ADMIN_TRUE_ICON : $er . " <br /> " ;
2013-10-27 21:28:40 -07:00
$text .= " </div></td> " ;
}
else
{
$this -> checkLog ( 'file' , 1 );
$this -> newFile ( $comp_dir . " /languages/ " . $lnk , $target_lan );
$text .= " <tr>
< td class = 'forumheader3' style = 'width:20%' > " . $comp_name . " </ td >
< td class = 'forumheader3' style = 'width:25%' > " .str_replace( " English / " , " " , $lnk ). " </ td >
< td class = 'forumheader' style = 'width:50%' >< span style = 'cursor:pointer' title = \ " " . str_replace ( " English " , $target_lan , $lnk ) . " \" > " . LAN_CHECK_4 . " </span></td> " ;
}
2015-07-09 19:24:59 -07:00
$text .= " <td class='forumheader3' style='width:5%;text-align:center'> " ;
// $text .= "<input class='btn btn-primary' type='button' style='width:60px' name='but_$i' value=\"".LAN_EDIT."\" onclick=\"window.location='".e_SELF."?f=".$comp_dir."/languages/".$lnk."&lan=".$target_lan."&mode={$mode}'\" /> ";
2015-08-31 17:17:28 -07:00
$parms = $_GET ;
$parms [ 'sub' ] = 'edit' ;
2020-12-30 10:11:04 -08:00
$parms [ 'file' ] = $comp_name . " /languages/ " . $lnk ;
2015-08-31 17:17:28 -07:00
$parms [ 'lan' ] = $this -> transLanguage ;
$parms [ 'iframe' ] = 1 ;
$parms [ 'type' ] = $mode ;
$editUrl = e_REQUEST_SELF . " ? " . http_build_query ( $parms , '&' );
2017-03-08 05:19:25 +01:00
$text .= " <a href=' " . $editUrl . " ' class='e-modal btn btn-primary' data-modal-caption=' " . str_replace ( " ../ " , " " , $comp_dir ) . " '> " . LAN_EDIT . " </a> " ; // href='".e_REQUEST_URI."&f=".$comp_dir."/languages/".$lnk."&lan=".$target_lan."&type={$mode}'
2015-08-31 17:17:28 -07:00
// <a href='".$editUrl."' data-modal-caption='".$subpath."' class='e-modal btn btn-primary' type='button' style='width:60px'>".LAN_EDIT."</a>";
2015-07-09 19:24:59 -07:00
2013-10-27 21:28:40 -07:00
$text .= " </td></tr> " ;
}
// if (!$known) {$text = LAN_CHECK_18." : --> ".$fname." :: ".$dname;}
return $text ;
}
function newFile ( $lnk , $target_lan )
{
if ( $target_lan == 'English' )
{
return ;
}
$newfile = str_replace ( " English " , $target_lan , $lnk );
$dir = dirname ( $newfile );
if ( $dir != '.' && ! is_dir ( $dir ))
{
// echo "<br />dir: ".$dir;
mkdir ( $dir , 0755 );
}
if ( ! file_exists ( $newfile ))
{
// echo "<br />file: ".$newfile;
2017-10-16 09:39:55 -07:00
$data = chr ( 60 ) . " ?php \n \n // define( \" EXAMPLE \" , \" Generated Empty Language File \" ); " ;
2013-10-27 21:28:40 -07:00
file_put_contents ( $newfile , $data );
}
}
2020-12-30 10:11:04 -08:00
function edit_lanfiles ( $dir1 , $dir2 , $f1 , $f2 , $lan , $type = null )
2013-10-27 21:28:40 -07:00
{
if ( $lan == '' )
{
echo " Language selection was lost. " ;
2020-08-19 10:02:14 -07:00
return null ;
2013-10-27 21:28:40 -07:00
}
2020-12-30 10:11:04 -08:00
if ( $type === 'P' )
{
$dir1 = e_PLUGIN . $dir1 ;
$dir2 = e_PLUGIN . $dir2 ;
}
if ( $type === 'T' )
{
$dir1 = e_THEME . $dir1 ;
$dir2 = e_THEME . $dir2 ;
}
2013-10-27 21:28:40 -07:00
2020-08-19 10:02:14 -07:00
// $ns = e107::getRender();
2013-10-27 21:28:40 -07:00
$sql = e107 :: getDb ();
/* echo " <br />dir1 = $dir1 " ;
echo " <br />file1 = $f1 " ;
echo " <br />dir2 = $dir2 " ;
echo " <br />file2 = $f2 " ; */
if ( $dir2 . $f2 == e_LANGUAGEDIR . $lan . " /English.php " ) // it's a language config file.
{
$f2 = $lan . " .php " ;
$root_file = e_LANGUAGEDIR . $lan . " / " . $lan . " .php " ;
}
else
{
$root_file = $dir2 . $f2 ;
}
if ( $dir2 . $f2 == e_LANGUAGEDIR . $lan . " /English_custom.php " ) // it's a language config file.
2006-12-02 04:36:16 +00:00
{
2013-10-27 21:28:40 -07:00
$f2 = $lan . " _custom.php " ;
$root_file = e_LANGUAGEDIR . $lan . " / " . $lan . " _custom.php " ;
2007-10-07 22:01:43 +00:00
}
2015-07-10 15:41:07 -07:00
$this -> newFile ( $dir2 . $f2 , $lan );
2020-08-19 10:02:14 -07:00
$writable = is_writable ( $dir2 );
2013-10-27 21:28:40 -07:00
$trans = $this -> get_lan_file_phrases ( $dir1 , $dir2 , $f1 , $f2 );
2020-12-30 10:11:04 -08:00
if ( empty ( $trans ))
{
//return array('caption'=>"Error", 'text'=>"Unable to open file", 'mode'=>'edit', 'file'=>$capFile);
}
2013-10-27 21:28:40 -07:00
$keys = array_keys ( $trans );
sort ( $keys );
$text = " <div style='text-align:center'>
< form method = 'post' action = '".e_SELF."?".e_QUERY."' id = 'transform' >
< table class = 'table table-striped' >
< thead >
< tr >
< th > LAN </ th >
< th > English </ th >
< th > " . $lan . " </ th >
2015-05-23 11:15:10 -07:00
</ tr >
</ thead >< tbody > " ;
2013-10-27 21:28:40 -07:00
$subkeys = array_keys ( $trans [ 'orig' ]);
foreach ( $subkeys as $sk )
2006-12-02 04:36:16 +00:00
{
2013-10-27 21:28:40 -07:00
$rowamount = round ( strlen ( $trans [ 'orig' ][ $sk ]) / 34 ) + 1 ;
$hglt1 = " " ; $hglt2 = " " ;
if ( $trans [ 'tran' ][ $sk ] == " " && $trans [ 'orig' ][ $sk ] != " " ) {
2016-10-18 07:58:24 +01:00
$hglt1 = " <span class='label label-danger label-important e-tip' title=' " . LAN_MISSING . " '> " ; //Missing
2015-05-26 13:08:09 -07:00
$hglt2 = " </span> " ;
}
elseif ( $trans [ 'tran' ][ $sk ] == $trans [ 'orig' ][ $sk ])
{
2016-10-18 07:58:24 +01:00
$hglt1 = " <span class='label label-warning e-tip' title=' " . LAN_CHECK_28 . " '> " ; //Identical
2013-10-27 21:28:40 -07:00
$hglt2 = " </span> " ;
}
$text .= " <tr>
< td style = 'width:10%;vertical-align:top' > " . $hglt1 .htmlentities( $sk ). $hglt2 . " </ td >
< td style = 'width:40%;vertical-align:top' > " .htmlentities(str_replace( " ndef ++ " , " " , $trans['orig'] [ $sk ])) . " </ td > " ;
$text .= " <td class='forumheader3' style='width:50%;vertical-align:top'> " ;
$text .= ( $writable ) ? " <textarea class='input-xxlarge' name='newlang[]' rows=' $rowamount ' cols='45' style='height:100%'> " : " " ;
2018-09-05 01:38:36 +02:00
$text .= htmlentities ( str_replace ( " ndef++ " , " " , $trans [ 'tran' ][ $sk ]));
2013-10-27 21:28:40 -07:00
$text .= ( $writable ) ? " </textarea> " : " " ;
//echo "orig --> ".$trans['orig'][$sk]."<br />";
if ( strpos ( $trans [ 'orig' ][ $sk ], " ndef++ " ) !== False )
{
//echo "+orig --> ".$trans['orig'][$sk]." <> ".strpos($trans['orig'][$sk],"ndef++")."<br />";
$text .= " <input type='hidden' name='newdef[]' value='ndef++ " . $sk . " ' /> " ;
}
else
{
$text .= " <input type='hidden' name='newdef[]' value=' " . $sk . " ' /> " ;
}
$text .= " </td></tr> " ;
2006-12-02 04:36:16 +00:00
}
2013-10-27 21:28:40 -07:00
unset ( $_SESSION [ 'lancheck-edit-file' ]);
//Check if directory is writable
2015-05-23 11:15:10 -07:00
$text .= " </tbody></table> " ;
2013-10-27 21:28:40 -07:00
if ( $writable )
2006-12-02 04:36:16 +00:00
{
2013-10-27 21:28:40 -07:00
$text .= " <div class='buttons-bar center'>
< input type = 'hidden' name = 'lan' value = '{$lan}' />
2015-07-09 19:24:59 -07:00
< input class = 'btn btn-warning' type = 'submit' name = 'saveLanguageFile' value = \ " " . LAN_SAVE . " " . str_replace ( $dir2 , " " , $root_file ) . " \" />
2013-10-27 21:28:40 -07:00
</ div > " ;
if ( $root_file )
{
$_SESSION [ 'lancheck-edit-file' ] = $root_file ;
}
2007-10-07 22:01:43 +00:00
}
2013-10-27 21:28:40 -07:00
$text .= "
</ form >
</ div > " ;
$text .= " <form method='post' action=' " . e_SELF . " ?tools' id='select_lang'>
< div style = 'text-align:center' >< br /> " ;
$text .= ( ! $writable ) ? " <br /> " . $dir2 . $f2 . LAN_NOTWRITABLE : " " ;
2015-07-09 19:24:59 -07:00
// $text .= "<br /><br /><input class='btn' type='submit' name='language_sel[{$lan}]' value=\"".LAN_BACK."\" />";
$text .= " </div></form> " ;
2013-10-27 21:28:40 -07:00
2015-07-09 19:24:59 -07:00
$capFile = str_replace ( " ../ " , " " , $dir2 . $f2 );
$caption = LANG_LAN_21 . SEP . $lan . SEP . LAN_CHECK_2 . SEP . LAN_EDIT . SEP . $capFile ;
return array ( 'caption' => $caption , 'text' => $text , 'mode' => 'edit' , 'file' => $capFile );
// $ns->tablerender($caption, $text);
2006-12-02 04:36:16 +00:00
2013-10-27 21:28:40 -07:00
2007-10-07 22:01:43 +00:00
}
2009-11-05 08:07:53 +00:00
2013-10-27 21:28:40 -07:00
function fill_phrases_array ( $data , $type )
{
$retloc = array ();
if ( preg_match_all ( '/(\/\*[\s\S]*?\*\/)/i' , $data , $multiComment ))
{
$data = str_replace ( $multiComment [ 1 ], '' , $data ); // strip multi-line comments.
}
if ( preg_match ( '/^\s*?setlocale\s*?\(\s*?([\w]+)\s*?,\s*?(.+)\s*?\)\s*?;/im' , $data , $locale )) // check for setlocale();
{
$retloc [ $type ][ $locale [ 1 ]] = $locale [ 2 ];
}
2019-01-23 18:58:50 +01:00
if ( preg_match_all ( '/^\s*?define\s*?\(\s*?(\'|\")([\w]+)(\'|\")\s*?,\s*?(\'|\")([\s\S]*?)\s*?(\'|\")\s*?\)\s*?;/imu' , $data , $matches ))
2013-10-27 21:28:40 -07:00
{
$def = $matches [ 2 ];
$values = $matches [ 5 ];
foreach ( $def as $k => $d )
{
$retloc [ $type ][ $d ] = $values [ $k ];
}
}
return $retloc ;
/*
echo " <h2>Raw Data " . $type . " </h2><pre> " ;
echo htmlentities ( $data );
echo " </pre> " ;
*/
2006-12-02 04:36:16 +00:00
}
2013-10-27 21:28:40 -07:00
//--------------------------------------------------------------------
function is_utf8 ( $str ) {
/*
* @ see http :// hsivonen . iki . fi / php - utf8 / validation . php
*/
if ( strtolower ( CHARSET ) != " utf-8 " || $str == " " )
{
return TRUE ;
}
2020-12-18 13:07:45 -08:00
return ( preg_match ( '/^./us' , $str , $ar ) == 1 );
2007-10-07 22:01:43 +00:00
}
2013-10-27 21:28:40 -07:00
2017-10-16 19:31:31 -07:00
/**
2017-10-17 07:18:51 -07:00
* Clean - up definitions in a language file removed closing php tags and strip specific html ..
2017-10-16 19:31:31 -07:00
* @ param array $defKeys array of constants to comment out .
* @ param string $path path to the language file to edit .
*/
2017-10-16 20:00:04 -07:00
function cleanFile ( $path , $defKeys = null )
2017-10-16 19:31:31 -07:00
{
2017-10-16 20:00:04 -07:00
if ( empty ( $path ) || ! file_exists ( $path ) || stripos ( $path , 'English' ) !== false )
2017-10-16 19:31:31 -07:00
{
return null ;
}
$content = file_get_contents ( $path );
$lines = explode ( " \n " , $content );
$srch = array ();
2017-10-17 07:18:51 -07:00
$repl = array ();
$srch [] = '<b>' ;
$srch [] = '</b>' ;
$repl [] = '[b]' ;
$repl [] = '[/b]' ;
2017-10-16 19:31:31 -07:00
2017-10-16 20:00:04 -07:00
if ( ! empty ( $defKeys ))
2017-10-16 19:31:31 -07:00
{
2017-10-16 20:00:04 -07:00
foreach ( $defKeys as $const )
{
$srch [] = " define(' " . $const . " ' " ;
$srch [] = 'define("' . $const . '"' ;
2017-10-16 19:31:31 -07:00
2017-10-16 20:00:04 -07:00
$repl [] = " // define(' " . $const . " ' " ;
$repl [] = '// define("' . $const . '"' ;
}
2017-10-16 19:31:31 -07:00
}
$new = '' ;
foreach ( $lines as $ln )
{
if ( strpos ( $ln , '?>' ) !== false )
{ continue ;
}
2017-10-23 19:10:24 -07:00
if ( strpos ( $ln , '""' ) !== false || strpos ( $ln , " '' " ) !== false ) // empty
{
continue ;
}
2017-10-16 19:31:31 -07:00
if ( strpos ( $ln , '//' ) !== false )
{
$new .= $ln . " \n " ;
continue ;
}
2017-10-16 20:00:04 -07:00
if ( ! empty ( $srch ))
{
$new .= str_replace ( $srch , $repl , $ln ) . " \n " ;
}
else
{
$new .= $ln . " \n " ;
}
2017-10-16 19:31:31 -07:00
}
if ( file_put_contents ( $path , $new ))
{
return true ;
}
return false ;
}
2019-01-27 14:57:10 +01:00
}