Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD] Multilingual Content with control via Admin Panel (sNews MU 1.6.3)  (Read 1986 times)

sNews3M

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
  • nothing can be impeccable in this imperfect world
    • Free Multiuser Multilingual Content Management System sNews 3M CMS

[MOD] Multilingual Content with control via Admin Panel (2009/08/23)

Description
This MOD uses idea from method by Joost: Multiple installations using one sNews engine and one database.
Each language version of the same content used separate copies of articles, categories and comments tables, but users and guests tables stayed in a single copy.
The method was slightly improved and now there is only one copy of the engine snewsMU.php with database and language settings, and only one copy of template template.php

MOD allows:
Interface language switching depending to translation files availability which number may be greater than website languages
Automatically switch to language version of contents which language is user prefers
Is possible to administer the website languages via admin panel

Demo
sNews MM (details)

Package (UPDATED 2009/08/29)
Download the ready to work package with the multilingual content support are possible here: sNews MM (snewsmm-latest.zip)
Read about the sNews MM package here: [PACKAGE] sNews MM (Multilingual Multiuser) based on sNews MU 1.6.3
Package includes following interface language translations:
English, Spanish, French, Portuguese, German, Arabic, Russian, Italian, Ukrainian, Dutch, Romanian, Czech, Hebrew, Greek, Latvian
As well included the interface languages without multiuser section translation:
Chinese Simplified, Brazilian Portuguese, Indonesian, Turkish, Polish, Persian, Finnish, Danish, Croatian, Slovak, Norwegian, Icelandic, Lithuanian, Slovene

Installation

STEP 1 - BACKUP


STEP 2 - add files template.php, install.php and snews_EN.php (UPDATED 2009/08/29)

Download template.php here: template.php.txt
Change it according to your template

Download install.php here: install.php.txt

Download snews_EN.php here: snews_EN.php.txt


STEP 3 - change the file stile.css
Add lines
Code: [Select]
#top { float: right; text-align: right}
#flags li { display: inline; margin: 0 0 0 10px; }
Change line
Code: [Select]
#menu li { float: left; }to
Code: [Select]
#menu li { display: inline; }

STEP 4 - change the file index.php
to
Code: [Select]
<?php
$website_language 
'';
include(
'snewsMU.php');

STEP 6 - change the file snewsMU.php (UPDATED 2009/08/29)

Change code
Code: [Select]
/*<?php code */
// DATABASE VARIABLES
function db($variable) {
$db = array();
$db['website'] = 'http://localhost/snewsMU/';
$db['dbhost'] = 'localhost'//MySQL Host
$db['dbname'] = 'dbname'//Database Name
$db['dbuname'] = 'username'//Database Username
$db['dbpass'] = 'password'//Database password
$db['prefix'] = 'snews_'//Database prefix
$db['dberror'] = '<strong>There was an error while connecting to the database.</strong> <br /> Check your database settings.'//Database error message
return $db[$variable];
}
to  (UPDATED 2009/08/29)
Code: [Select]
/*<?php code */
// DATABASE VARIABLES
function db($variable) {
global $website_language;
$db = array();
## ENTER YOUR DATABASE SETTINGS HERE
$db['dbhost'] = 'sql301.byethost4.com'//MySQL Host
$db['dbname'] = 'b4_3908939_snewswork'//Database Name
$db['dbuname'] = 'b4_3908939'//Database Username
$db['dbpass'] = 'vjbcfqns'//Database password
$db['prefix'] = 'snewsmm_'//Database prefix
## END DATABASE SETTINGS
$db['dberror'] = '<strong>There was an error while connecting to the database.</strong> <br /> Check your database settings.'//Database error message
$db['website'] = 'http://'.$_SERVER['SERVER_NAME'].str_replace('index.php'''$_SERVER['SCRIPT_NAME']); //Website root URL
if($variable == 'suffix') {
$language mysql_fetch_array(mysql_query("SELECT value FROM ".$db['prefix']."en_settings WHERE name = 'language'"));
$db['suffix'] = $website_language $website_language.'_' : ($languages['language'] ? strtolower($language['language']).'_' 'en_'); //Suffix of database prefix
}
return $db[$variable];
}


(UPDATED 2009/08/29)
Code: [Select]
/*<?php code */
// LANGUAGE VARIABLES
function l($variable) {
if (s('language') != 'EN' && file_exists('snews_'.s('language').'.php')) {include('snews_'.s('language').'.php');} else {

......
......
......

} return $l[$variable];
}
/*** END OF SETTINGS & VARIABLES, EDIT BELOW THIS LINE ONLY IF YOU KNOW WHAT YOU'RE DOING ***/
to (UPDATED 2009/08/29)
Code: [Select]
/*<?php code */
/// LANGUAGE VARIABLES
function l($variable) {
## MULTILINGUAL CONTENT
$l = array();
$language strtoupper(language('interface'));
if (file_exists(root().'snews_'.$language.'.php')) {include(root().'snews_'.$language.'.php');} else {include(root().'snews_EN.php');}
## END MULTILINGUAL CONTENT

#SYSTEM VARIABLES (not to be translated)
$l['home_sef'] = s('home_sef') == '' $l['home_sef'] : s('home_sef'); //reassign $l['home_sef'] to system home_sef if system is set.
## MULTI_USER
$l['cat_listSEF'] = $l['home_sef'].',archive,contact,sitemap,rss-articles,rss-pages,rss-comments,login,administration,admin_category,admin_article,article_new,extra_new,page_new,categories,articles,extra_contents,pages,settings,files,logout,register,profile,users,deluser,getpass,bulk_users'//SEF links of the hardcoded categories
## END MULTI_USER
$l['divider'] = '&middot;'//divider character
$l['paginator'] = 'p_'// used in article pagination links
$l['file_include_extensions'] = 'php,txt,inc,htm,html'// list of file types available for inclusion routine
$l['allowed_files'] = 'php,htm,html,txt,inc,css,js,swf'// list of file types available for upload/file list routine
$l['allowed_images'] = 'gif,jpg,jpeg,png'// list of image types available for upload/file list routine
/************************************************************************
2008-1-11
FIX: by bakercad
Problem: snewsMU.php not in ignored_items list
Offening code: N/A
Found here: http://snewscms.com/forum/index.php?topic=6225.0
************************************************************************/
$l['ignored_items'] = '.,..,cgi-bin,.htaccess,Thumbs.db,snewsMU.php,index.php,style.css'// list of files&folders ignored by upload/file list routine
//END FIX
return $l[$variable];
}
/*** END OF SETTINGS & VARIABLES, EDIT BELOW THIS LINE ONLY IF YOU KNOW WHAT YOU'RE DOING ***/


(UPDATED 2009/08/29)
Code: [Select]
/*<?php code */
/// SITE SETTINGS - grab site settings from database
function s($variable) {
$query "SELECT value FROM ".db('prefix')."settings WHERE name = '$variable'";
$result mysql_query($query);
while ($r mysql_fetch_array($result)) {$value $r['value'];}
return $value;
}

// SESSION TOKEN
function token() {
$a =  md5(substr(session_id(), 27));
$b $_SERVER['HTTP_USER_AGENT'];
$c db('website');
$token md5($a.$b.$c);
return $token;
}
to  (UPDATED 2009/08/29)
Code: [Select]
/*<?php code */
// SITE SETTINGS - grab site settings from database
function s($variable) {
## SNEWSMM MULTILINGUAL CONTENT
$query $variable == 'language' "SELECT value FROM ".db('prefix')."en_settings WHERE name = 'language'" "SELECT value FROM ".db('prefix').db('suffix')."settings WHERE name = '$variable'";
## SNEWSMM MULTILINGUAL CONTENT
$result mysql_query($query);
while ($r mysql_fetch_array($result)) {$value $r['value'];}
return $value;
}

// SESSION TOKEN
function token() {
$a =  md5(substr(session_id(), 27));
$b $_SERVER['HTTP_USER_AGENT'];
$c $_SERVER['SERVER_NAME'];
$token md5($a.$b.$c);
return $token;
}


Code: [Select]
/*<?php code */
}}}
snews_startup();
to  (UPDATED 2009/08/29)
Code: [Select]
/*<?php code */
}}}
// RELATIVE OFFSET OF THE WEBSITE ROOT TO INDEX.PHP
function root() {
global $website_language;
$language s('language');
$root $website_language && $language && strcasecmp($language$website_language) ? '../' './'//Website root relative to script
return $root;
}

// WEBSITE LANGUAGE PREFERRED BY BROWSER
function language($target) {
$http_accept_language explode(','str_replace(' '''$_SERVER['HTTP_ACCEPT_LANGUAGE']));
$language 'en';
if($target == 'contents') {
$languages s('language');
}
elseif($target == 'interface') {
global $interface_languages;
if(isset($interface_languages)) { $languages $interface_languages; }
else {
$dir opendir(root());
rewinddir($dir);
$languages 'EN';
while (($file readdir($dir)) !== FALSE)
if(preg_match('/^snews_([A-Z]{2}(-[A-Z]{2})?).php$/'$file))
$languages .= ','.preg_replace('/^snews_([A-Z]{2}(-[A-Z]{2})?).php$/''\1'$file);
closedir($dir);
}
}
foreach($http_accept_language as $l) {
$lang preg_replace('/^([a-zA-Z]{2}(-[a-zA-Z]{2})?).*$/''\1'$l);
if(stripos($languages$lang) !== FALSE) { $language $lang; break; }
}
return $language;
}

// SHOW LANGUAGE LOCALES FLAGS
function flags() {
global $website_language;
$language explode(','strtoupper(str_replace(' '''s('language'))));
if(count($language) > 1) {
foreach($language as $l) {
$pattern = array('/\/'.$website_language.'\//''/index.+task=save_(settings)$/''/index.+task=(profile|deluser)$/''/index.+=admin_category.*$/''/index.+=admin_article.*$/''/index.+comment&comment.+/');
$replace = array('/'.strtolower($l).'/''\1/''users/''categories/''administration/''');
$link preg_replace($pattern$replace$_SERVER['REQUEST_URI']);
$img file_exists($img root()."flag_".$l.".gif") ? "<img src='".$img."' title='".$l."' border='0' />" $l;
echo "<li><a href='".$link."'>".$img."</a></li>";
}
}
}

// REDIRECT TO LANGUAGE FOLDER
connect_to_db();
if(!
$website_language) {
include(root().'install.php');
snewsMU();
$website_language strtolower(language('contents'));
if(root() == '../') { header('Location: '.db('website').$website_language.'/'); exit; }
}
session_start();
snews_startup();
include(
root().'template.php');

delete from function snews_startup() (UPDATED 2009/08/29)
Code: [Select]
connect_to_db();

in the function processing()
Code: [Select]
/*<?php code */
while (list($key$value) = each($ufield)) {
mysql_query("UPDATE ".db('prefix')."settings SET VALUE = '$value' WHERE name = '$key' LIMIT 1;");}
$query_begin "UPDATE ".db('prefix')."settings SET VALUE = ";
to (UPDATED 2009/08/29)
Code: [Select]
/*<?php code */
## MULTILINGUAL CONTENT
if(!preg_match("/^([A-Z]{2}(-[A-Z]{2})? *,? *)+$/"$language)) $ufield['language'] = $language 'EN';
$lang explode(','strtolower(str_replace(' '''$language)));
if(!in_array('en'$lang)) array_push($lang'en');
foreach($ufield as $key => $value) {
switch($key) {
case 'website_title':
case 'home_sef':
case 'website_description':
case 'website_keywords':
case 'contact_subject':
case 'charset':
case 'date_format':
case 'display_page':
mysql_query("UPDATE ".db('prefix').db('suffix')."settings SET VALUE = '$value' WHERE name = '$key'");
break;
default:
foreach($lang as $lmysql_query("UPDATE ".db('prefix').$l."_settings SET VALUE = '$value' WHERE name = '$key'");
}
}
## END MULTILINGUAL CONTENT


Code: [Select]
/*<?php code */
// SMART RETRIEVE FUNCTION
function retrieve($column$table$field$value) {
$query "SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'";
to
Code: [Select]
/*<?php code */
// SMART RETRIEVE FUNCTION
function retrieve($column$table$field$value) {
$query = ($table != 'users') ? "SELECT $column FROM ".db('prefix').db('suffix')."$table WHERE $field = '$value'" "SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'";

Change all entries
Quote
$_SESSION[db('website').'Logged_In']
to
Quote
$_SESSION[$_SERVER['SERVER_NAME'].'Logged_In']


Quote
db('prefix')."articles(categories|comments|settings)
to
Quote
db('prefix').db('suffix')."articles(categories|comments|settings)

END CHANGES
« Last Edit: July 26, 2012, 08:19:18 am by sNews3M »
Logged
Free Multiuser Multilingual
Content Management System
sNews 3M CMS
sNews MM 1.6.3
please forgive my terrible english :)