sNews Forum

sNews 1.6 (previous version) => Programming => Topic started by: Joost on July 06, 2007, 08:55:32 am

Title: Multiple installations using one sNews engine and one database.
Post by: Joost on July 06, 2007, 08:55:32 am
This mod makes it possible to run several  installations, whith only one snews.php file. The respective installs are located in their own directories.
The first approach will create independend functioning installation, with different settings and passwords.
The second approach will point all installations to one settings table.

The differences for every install is located in // DATABASE VARIABLES in snews.php.
1) A separate configure file with database variables for each installation has to be created and put into a config.php.
2) Database variables in snews.php have to be deleted.
3) News.php has to be included in each config.php and  each config.php is included in index.php.

A schematic:
(http://kerkelaan.nl/out/multisnews.png)


Database tables
For each installation 4 tables have to be created in the database. The tables have to have a prefix, which basically means you will have to add an extra name before each table like this:

britney_articles,  britney_comments ,britney_settings ,britney_categories.

Do the same for the other installations. The package includes a file to create three times four tables, thus you can create three installs. Alter the prefixes to your convenience and add more tables if needed.

.htaccess
One .htaccess file for each installation is needed. Adjust #RewriteBase for each installation.

folder
For every installation one folder.Every folder contains:
 - index.php
 - .htaccess
 - style.css
 - config.php
(Renaming each config.php to a different name like britney.php or office.php makes it easier to maintain and you could keep all files in one folder with snews.php. Make up your mind before installing.)

Here is the package (http://kerkelaan.nl/out/multi_snews.zip). No snews.php included. Use your favourite modded snews.php (without database variables).
It is not an easy install package. It is merely an example to visualize the structure. In the package Britney and German are subdirectories/folders of office, and will have the following url's.

domain.com/office/
domain.com/office/britney/
domain.com/office/german/
____________

Multiple installations, one settings table

This might be useful if you use the extra installs to expand your website, pretending  it to have subcategories. To achieve this, all installations have to point to one (prefixed) settings table (or the other way around  :rolleyes:  ).

step zero: Backup snews.php
Search and replace in snews.php
Quote
".db('prefix')."settings
with
Quote
prefix_settings
Change prefix_ with the name of the table you want to use. In a default installation you will have to repeat this four times. Now you only be using the settings table of your choice. If you wish, you can safely delete the other settings tables or simply don't create them at all.

Tip: You can attach one stylesheet to all index.php's.
Note: For every installation there is still a separate upload file, a separate archive and a separate sitemap (did I say it was perfect?).


Linking to editors, js and images from snews.php Both approaches
If your snews engine is linking (html) to a file such as editors, js and images, start the path from the root of the site,  like:
Quote
/ office/pencil.js
or
Code: [Select]
http://www.solucija.com/javascript.jsIndex.php links can be treated as usual.
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 06, 2007, 10:06:24 am
Interesting ;)
Few thoughts:
- Might be good to emphasize in description of this the removal/commenting out of function db() from snews.php as separate step to do. That phrase regarding removal of database variables from doesn't exactly cut it through for casual reader :)
- Probably, single approach with fixed name config.php in the root and subdirectories as well would be more handy as well as reduce clutter in the root. Or may be not ;)
Title: Multiple installations using one sNews engine and one database.
Post by: Joost on July 06, 2007, 10:23:33 am
Quote from: codetwist
Interesting ;)
Few thoughts:
- Might be good to emphasize in description of this the removal/commenting out of function db() from snews.php as separate step to do. That phrase regarding removal of database variables from doesn't exactly cut it through for casual reader :)
- Probably, single approach with fixed name config.php in the root and subdirectories as well would be more handy as well as reduce clutter in the root. Or may be not ;)
- Description emphazised
- I am not sure what you mean with 'single approach'
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 06, 2007, 12:59:26 pm
That 'single approach' actually meant only that config.php are named just that and stored in each subfolder without any renaming and keeping them in root folder. I was even looking for these config.php indownloaded example. But that's not big deal as it's just my preferences ;)
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 06, 2007, 02:24:57 pm
This is a most interesting approach Joost. The"Multiple installations with one settings table" will be easier for me to test-run since I've already replaced all table-names file-wide with variables at the top of snews.php in my current mod-pack. I must put other projects aside and try this out today. :)
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 06, 2007, 03:13:43 pm
I want to try this approach with bakercad's Multi-Users mod which has an extra (5th) "Users" table, mainly because I am working on a project that needs multiple admin access and will have several sub-departments or sub-sites within it. So... let me just confirm what I think is how this works (thinking out loud...)

Each install has its own dbase config file which includes the same snews.php engine file used by all installs but uses its own set of 4 tables... and the config file is included into its respective index.php file... ensuring all the engine functions pass through all config files to all index.php files. I should be able to have separate users tables for each install too... or use just one users table for all.
Title: Multiple installations using one sNews engine and one database.
Post by: TheTick on July 06, 2007, 03:41:31 pm
Question: How does this relate to the Search function? Will someone browsing the "Britney" section searching for a term get results from articles or pages in the "office" & "shop" section as well as the"Britney" section?

That would be a deal breaker for me if you don't have a site-wide search...
Title: Multiple installations using one sNews engine and one database.
Post by: centered on July 06, 2007, 06:15:09 pm
Quote from: TheTick
Question: How does this relate to the Search function? Will someone browsing the "Britney" section searching for a term get results from articles or pages in the "office" & "shop" section as well as the"Britney" section?

That would be a deal breaker for me if you don't have a site-wide search...
QFT. Really Joost, I think you are on to something good.  Where is agent?  Doesn't he have a similar setup?
Title: Multiple installations using one sNews engine and one database.
Post by: Fred K on July 06, 2007, 06:51:09 pm
centered -- yeah, sort of but I haven't gone as far into it as Joost has, yet. I'm actually in the middle of a site where I am/will be doing more or less exactly like Joost has described above. The main difference is this:
Quote from: The Penguin Exterminator
Search and replace in snews.php
Quote
".db('prefix')."settings
with
Quote
prefix_settings
Change prefix_ with the name of the table you want to use. In a default installation you will have to repeat this XX times. Now you only be using the settings table of your choice. If you wish, you can safely delete the other settings tables or simply don't create them at all
:o

@Joost -- User Guide? :lol: (Good use of prefixes. Thanks!)

@key's -- Sharp minds, etc. The site I'm working on also uses the bobster's MU... ;)
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 06, 2007, 06:56:50 pm
As discussed above the search probably goes to this list as well:
Quote from: Joost
...

Note: For every installation there is still a separate upload file, a separate archive and a separate sitemap (did I say it was perfect?).

...
Might be feasible to change approach a little and define a little bit more complex configuration for this one. Like loading all config-s into global assoc array and fixing current 'subsite' (root, britney, whatever)?
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 06, 2007, 07:10:33 pm
Quote from: agentsmith
@key's -- Sharp minds, etc. The site I'm working on also uses the bobster's MU... ;)
@ Agent... I created a new variable array and replaced all table-name instances... file-wide... with the new values... so I can choose to use any combination of tables within the database. I 'spose I could have just added these to the existing $db array and called the values from there but I wanted to test new arrays file-wide anyway. It's useful if you wanted to have several sub-sites running different content and settings tables, but all using the same users table. :)
Quote
function gl($variable) { # for use with the Bobster's 16MU
   $gl = array();
   # Variables replacing table names throughout this file.     - search-for locations
   $gl['articles_table'] = 'articles';   //      ".gl('articles_table')."
   $gl['categories_table'] = 'categories';   //      ".gl('categories_table')."
   $gl['comments_table'] = 'comments';   //      ".gl('comments_table')."
   $gl['settings_table'] = 'settings';   //      ".gl('settings_table')."
   $gl['users_table'] = 'users';      //      ".gl('users_table')."
   return $gl[$variable];
      }
Title: Multiple installations using one sNews engine and one database.
Post by: Joost on July 06, 2007, 07:34:10 pm
Thank you all for the response. Actually it was something I thought about before I ever had installed my first sNews, after reading Keys tutorial how to set up a database with multi installs. Since I am not a good coder I have to think about reusing what is already available in the system. :)
I hasitated for a while, because I had not seen this approach before, but knowing that keyrocks was in the middle of a multi installation project., I thought it was time to test it and publish it.

@TheTick
In both approaches it is not possible to search Britney from within Office.
However, I think you can make the search site wide, when changing the query in function search()
Quote
db('prefix')."articles
has to be replaced with something like
Quote
office_articles, britney_articles etc., (look into the mysql syntax for proper notation)
Could be done for other queries as well.

Quote from: agentsmith
User Guide?
I don't get it.:/
Title: Multiple installations using one sNews engine and one database.
Post by: Fred K on July 06, 2007, 07:38:41 pm
Quote from: Saint Keyrocks
It's useful if you wanted to have several sub-sites running different content and settings tables, but all using the same users table
Makes sense ... keeps things organised.

So, [stupid question #1] you exclude users in each 'prefix_' subset, right? (does that work?)

@Joost: just yanking your chain a little...
Title: Multiple installations using one sNews engine and one database.
Post by: mosh on July 06, 2007, 08:14:59 pm
@agent:  bobster's MU  ?,  is this the same as rui's MU ?
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 06, 2007, 08:16:44 pm
More on what I meant in my post above ... kind of triggered some code excerpting frenzy :D

In index.php apart from inclusion of config.php file the current subsite should be fixed (obviously different for each subsite or root). So at top folder where for example office site is located it could look like this:
Code: [Select]
$curSubsite = 'root';
include( 'config-lib.php' );
//include( '../config-lib.php' );
include( 'config.php' );
Configuration files are created in each subsite and root folders and named just config.php. So, for  example, office site configuration file could look like this:
Code: [Select]
$cfgSubsite = 'root';

$db = array();
$db['website'] = 'http://domainname/office/';// Change this for every directory
$db['dbhost'] = 'localhost'; //MySQL Host
$db['dbname'] = 'insert database name'; //Database Name
$db['dbuname'] = 'insert user'; //Database Username
$db['dbpass'] = 'XXXXXXXX'; //Database password
$db['prefix'] = 'office_'; //Database prefix               INSERT A PREFIX FOR EVERY INSTALLATION
$db['dberror'] = 'There was an error while connecting to the database.
 Check your database settings.'; //Database error message
//
//$db['settings_prefix'] = $db['prefix'];
$db['settings_prefix'] = 'office_';
//
$db['users_prefix'] = $db['prefix'];
$db['users_prefix'] = 'office_';

initDb( $db, $cfgSubsite );

if ($cfgSubsite == 'root') {
   include( 'snews.php' );
}
else {
   include( '../snews.php' );
}
And for britney subsite configuration file could look like this:
Code: [Select]
$cfgSubsite = 'britney';

$db = array();
$db['website'] = 'http://domainname/office/';// Change this for every directory
$db['dbhost'] = 'localhost'; //MySQL Host
$db['dbname'] = 'insert database name'; //Database Name
$db['dbuname'] = 'insert user'; //Database Username
$db['dbpass'] = 'XXXXXXXX'; //Database password
$db['prefix'] = 'britney_'; //Database prefix               INSERT A PREFIX FOR EVERY INSTALLATION
$db['dberror'] = 'There was an error while connecting to the database.
 Check your database settings.'; //Database error message
//
//$db['settings_prefix'] = $db['prefix'];
$db['settings_prefix'] = 'office_';
//
//$db['users_prefix'] = 'office_';

initDb( $db, $cfgSubsite );

if ($cfgSubsite == 'root') {
   include( 'snews.php' );
}
else {
   include( '../snews.php' );
}
For this to work few additional functions are created and stored either in separate config-lib.php file stored at site root folder (this example - office) along with config.php:
Code: [Select]
function initDb( $dbCfg, $subsite = 'root' ) {
   global $dbCfgs;
   //
   if (!isset($dbCfgs) || !is_array($dbCfgs)) {
      $dbCfgs = array();
   }
   //
   $dbCfgs[$subsite] = $dbCfg;
}


function getDbVar( $variable, $subsite = 'root' ) {
   global $dbCfgs;
   //
   if ( is_array($dbCfgs) && is_array($dbCfgs[$subsite])) {
      return $dbCfgs[$subsite][$variable];
   }
}


function prefixTableName( $tableName, $subsite ) {
   if ( $tableName == 'settings' ) {
      if ( $prefix = getDbVar( 'settings_prefix', $subsite ) ) {
         return getDbVar( 'settings_prefix', $subsite ) . $tableName;
      }
      else {
         return getDbVar( 'prefix', $subsite ) . $tableName;
      }
   }
   elseif ( $tableName == 'users' ) {
      if ( $prefix = getDbVar( 'users_prefix', $subsite ) ) {
         return getDbVar( 'users_prefix', $subsite ) . $tableName;
      }
      else {
         return getDbVar( 'prefix', $subsite ) . $tableName;
      }
   }
   else {
      return getDbVar( 'prefix', $subsite ) . $tableName;
   }
}

function db( $variable ) {
   global $curSubsite;
   return getDbVar( $variable, $curSubsite );
}
And finally change from:
Code: [Select]
db('prefix') . 'settings'to:
Code: [Select]
prefixTableName( 'settings', $curSubsite )across all snews.php :/ And same for users if such is use :P
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 06, 2007, 08:21:28 pm
Quote from: agentsmith
So, [stupid question #1] you exclude users in each 'prefix_' subset, right? (does that work?)
Yes... if all sub-sites are using the same users table, you would not need a users table for each subsite... example table structure for an MU site:
Quote
(tables for root installation)
- articles, categories, comments, settings, users.
(tables for sub-site 1)
- sub1_articles, sub1_categories, sub1_comments, sub1_settings.
(table for sub-site 2)
- sub2_articles, sub2_categories, sub2_comments, sub2_settings.
Initial Testing:
Using Joost's structure, I have a primary (root) site with one sub-site in the root. I created the database with the 5 tables (including the users table for Bob's MU-pack) plus the same set of tables prefixed for the sub-site. While I intended to run them all on the same users table... I wanted to see if the sub-site would allow users and logins completely independent of the root install.
Good Result. It works - the sub-site is using its own users table and running as a standalone. :)
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 06, 2007, 08:25:17 pm
Quote from: mo
@agent:  bobster's MU  ?,  is this the same as rui's MU ?
No, they aren't the same. ruis MU is available for public access, bobsters ... dunno, haven't noticed it published as separate MOD code, still WIP?
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 06, 2007, 08:31:52 pm
This one probably is best answer IMHO to one regularly resurfacing question - how to create pages with truly different layout :)
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 06, 2007, 08:39:01 pm
Quote from: codetwist
This one probably is best answer IMHO to one regularly resurfacing question - how to create pages with truly different layout :)
You're right... it does appear to answer it simply.
@ Bob - looks like the idea of "modularity" is coming to fruition...  :cool:
Title: Multiple installations using one sNews engine and one database.
Post by: Fred K on July 07, 2007, 02:59:19 am
@key's: Stupid Question #2 -- How do you use ".gl('blah_tables').'" in this scenario:
Quote from: ~line 2498
function retrieve($column, $table, $field, $value) {
   $query = "SELECT $column FROM ".db('prefix')."$table
ILeave it as it is?
There are a couple of others like that one, for instance in the RSS block. I think I've worked around those though... Or maybe I'm not grasping the concept, what do I know...
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 07, 2007, 04:03:55 am
@ Agent...
You can leave that one as it is...
Quote
$query = "SELECT $column FROM ".db('prefix')."$table ...
The $table variable is already defined elsewhere and only applies when you make use of the prefix variable up in the $db variables array. When using the $gl variables array to replace table names... the prefix variable becomes redundant... since we can now define each table with a variable. In other words... the $gl variables serve the same purpose as the prefix variable did... but we can now apply them to individual tables rather than to all tables at once. (I better stop now before it gets any more confusing).

Module Structure is Born! - I don't know about the rest of you... but I beleive Joost has contributed the first major step towards modular structure for sNews. We are creating modules that stand alone and apart from the engine file and its supporting infrastructure (other under-the-hood stuff-in-the-root). And we have the option of using any number of module-specific tables mixed with any of the root (main site's) tables... (replacing table-names with variable values in the engine file)... and module-specific templates as well. Well done Joost... I think this turned out to be a very productive day... at least for me. :)
Title: Multiple installations using one sNews engine and one database.
Post by: Fred K on July 07, 2007, 04:13:27 am
Ok, so these are some quick reflections after having searched and destroyed the whole snews.php, replacing db('prefix') with ".gl('xxxxxx_table')." as per keyrocks' description - and of course creating some subdirectories with all necessary parts (db tables, prefixed db data, index.php, config.php). Note that this is based on my specific dev site, and also that I'm sure to have fudged some basic things in the process. YMMV, as they say. All that aside, here's what happens for me. The concept is to use a single snews.php, a single stylesheet and (I hoped) a single users table.

1) Setup is not a problem. Root site (unprefixed) works as expected, pages works as they should. Subcategory setup also works as expected, just remember to search your snews.php for hardcoded image or script URLs. So far so good. Single snews.php: check. Single stylesheet: check.

2) I am logged in as Admin in root. When I go to my subdir, I'm no longer logged in. So I log in again as Admin. In Bakercad's MU which isn't publicly released yet, Admin has s-user strength, he/she/it can do anything. Not so in subdir mode, which isn't a fault in the mod itself, I think, just an effect of this particular combo. For those who might want to know about it. Anyway, it seems that having one single user table works, but not the way I had imagined, so I'm going to try with separate user tables for each subdir.

3) The big strangeness, which I guess could be caused by my built-in denseness, but I'm not sure. In subdir (for example: root/issues/) create a new category, create an article, go home, then click the category link in the cat menu: 404. Go to Archive, click the article's link: 404. Look in the cat menu list: the categories created on the root are visible here; click one of them (news): 404. The first two 404's are irrational: an article created in a category on the subdir I'm standing in should not throw a 404. Which is where I'm thinking, "ok, did something wrong".

Conclusion: get some sleep, reset snews.php and try one of the other solutions offered above to see if I can get it to work as I want it to work.

The basics of the mod works fine, it's just a matter of keeping within its perimeter I guess. Not wander off too far out.

Yeah. Sleep.
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 07, 2007, 07:44:41 am
Of course it will throw 404 ;) Unless You have modded .htaccess and probably snews_startup() as well to account for these modules/subsites in folders.
Title: Multiple installations using one sNews engine and one database.
Post by: Fred K on July 07, 2007, 01:59:58 pm
That was done in 1). I may be seriously dense when it comes to scripting. But not that dense.
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 08, 2007, 11:00:44 pm
Quote from: agentsmith
That was done in 1). I may be seriously dense when it comes to scripting. But not that dense.
Ok, my point of view follows. If following assumptions are correct:
   a) there is category created in subsite
   b) link for calling that category contains valid href
   c) using that valid link throws 404
then most probable cause might be setup (aka .htaccess) and initialization problems (aka snews_startup). I don't think that default setup of those two really accounted for nested snews configuration.
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 08, 2007, 11:04:05 pm
---------------------------------------------
In function breadcrumbs:
---------------------------------------------
When a site visitor is on the home page of a given sub-site module, it is desirable to replace the "Home" link in the breadcrumbs links line with the actual name of the module. This can be done by replacing the l('home') language variable value... in function breadcrumbs()... with s('website_title');. This will change the "home" link in the breadcrumbs link string to display the Website Title defined in the Admin's Settings >> Settings panel. As an example, if you set the Website Title as "Cool Cars"... the "Home" link in the breadcrumbs line gets replaced with "Cool Cars"... telling the site visitor he/she is in the Cool Cars module.

Making the Mod:
In function breadcrumbs()... locate this string:
Quote
echo (!empty($categorySEF) || $categorySEF == $home || !empty($articleSEF)) ?
$link.'"title="'.l('home').'">'.l('home').'' : l('home');
... and replace itwith:
Quote
echo (!empty($categorySEF) || $categorySEF == $home || !empty($articleSEF)) ?
$link.'"title="'.s('website_title').'">'.s('website_title').'' : s('website_title');
Update:
So far it is NOT working... needs more work. As change occur, I will note them here in this post.
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 08, 2007, 11:22:53 pm
Quote from: agentsmith
2) I am logged in as Admin in root. When I go to my subdir, I'm no longer logged in. So I log in again as Admin. In Bakercad's MU which isn't publicly released yet, Admin has s-user strength, he/she/it can do anything. Not so in subdir mode, which isn't a fault in the mod itself, I think, just an effect of this particular combo. For those who might want to know about it. Anyway, it seems that having one single user table works, but not the way I had imagined, so I'm going to try with separate user tables for each subdir.
Per chance, function token() used for session status checking isn't  using website parameter as one of building  blocks? Might have different values for root where login was done and for subsite where it's checked later. Same story and possible solutions as for settings, etc. here IMHO.
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 08, 2007, 11:55:11 pm
Hmmm... so I am finally getting to add some categories and articles to my first sub-site module and... although they are all being saved to the correct dbase tables... clicking on any article or category link always displays a BLANK white page... pretty much the same as Agentsmith was experiencing in getting the four-0-four error message... more work to do... (aw shucks!)  :/

NOTE: I returned my function breadcrumbs() to normal for now. Both the root install and sub-site module are using their own table-sets separate from each other (10 tables in the dbase). I am not working with a single users table at this point. The blank pages display whether I am logged in or not.

UPDATE:
I've run out of time on my sub-sites project and I hate to say it... but I am coming to the conclusion that this method of running sub-sites as modules will require a lot of changes in the engine file... as Codetwist is suggesting. I need a working demo for this coming Thursday and will revert to using separate engine fines in each install... but still use the same database... since it was working for me earlier.
Title: Multiple installations using one sNews engine and one database.
Post by: Joost on July 09, 2007, 09:15:17 am
Quote from: agentsmith
2) I am logged in as Admin in root. When I go to my subdir, I'm no longer logged in.
More or less expected.
I did a little test using a one admin snews.php and this function token():
Quote
$token = '4'
After log into office (root), I had to log into Britney (a dirty job, but someone has got to do it).
Then I went back to the office admin, without problem. After changing function token(), I was logged out.

So it seems a session can contain several tokens with different values or several tokens with the same value. Of course all tokens are destroyed when logging out.
I hope this little exercise clarifies the limitations of this approach, without additional modding.
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 09, 2007, 10:38:41 am
@ Joost : Limitations, heh ;) You weren't  really hoping to avoid modifications at all were You? After all, there was changes if small already in Your original example - function with configuration variables had to be changed/comented out/ whatever. I think, this one requires surprisingly few modifications to have a huge benefits for setting up complex configurations. Need a little brewing ... errr ... thinking on implementation aspects. Should beat anything here around on benefits/modifications needed ratio IMHO. So, potential is good and 'forget' the limitations - they are for overcoming :)
Title: Multiple installations using one sNews engine and one database.
Post by: Joost on July 09, 2007, 10:57:37 am
@codetwist
I was just tempering expectations :)  and trying to locate a weak spot, or challenge if you wish. I am a bit overwhelmed by all activity, to be honest.
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 09, 2007, 02:51:35 pm
New day... new approach... better result...
I took a few minutes this morning and configured another sub-site module using Bob's  default MU engine file (no other mods). Result... all the articles and categories are displaying properly. So... the problems I was experiencing with mis-directed URLs (to blank web pages) is not caused by the sNews engine core. A couple more mods are necessary when using the table-names variables array mod.

The Solution when using Table-name Variables:
This solution deals with Agentsmith's Not-so-Stupid Question #2 (http://www.solucija.com/forum/viewtopic.php?pid=34265#p34265) posed several posts back. The answer WAS.. indeed... in the Smart Retrieve function(s).

1. In the default snews.php engine file, find the // SMART RETRIEVE FUNCTION and insert a new "case-switch" block as shown in blue in the block below. This allows the $query string below it to retrieve data from whichever table it needs to.
Quote
// SMART RETRIEVE FUNCTION
# this 1.6.0 function is the same as in 1.5.31.
function retrieve($column, $table, $field, $value) {

        switch ($table) {
        case 'articles': $table = "".gl('articles_table').""; break;
        case 'categories': $table = "".gl('categories_table').""; break;
        case 'comments': $table = "".gl('comments_table').""; break;
        case 'settings': $table = "".gl('settings_table').""; break;
        case 'users': $table = "".gl('users_table').""; break;
        }

   $query = "SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'";
   $result = mysql_query($query);
   while ($r = mysql_fetch_array($result)) {$retrieve = $r[$column];}
   return $retrieve;
}
2. This applies only to "sNews Dudes" working with Bob's MU engine file. Below the above function, Bob uses a modded duplicate of it... as an array... with an additional string... in the MU engine file. We need to insert the same "case-switch" set in there too, as shown below:
Quote
## MULTI_USER
// SMART RETRIEVE FUNCTION AS ARRAY
function retrieve_array($column, $table, $field, $value) {

        switch ($table) {
        case 'articles': $table = "".gl('articles_table').""; break;
        case 'categories': $table = "".gl('categories_table').""; break;
        case 'comments': $table = "".gl('comments_table').""; break;
        case 'settings': $table = "".gl('settings_table').""; break;
        case 'users': $table = "".gl('users_table').""; break;
        }

   $query = "SELECT $column FROM ".db('prefix')."$table WHERE $field = '$value'";
   $result = mysql_query($query);
   $retrieve = array();
   while ($r = mysql_fetch_array($result)) {$retrieve[] = $r[$column];}
   return $retrieve;
}
[
3.  Scroll further down in whichever engine file you are using and locate the // CHECK IF UNIQUE function. It contains a "case-switch" set which checks the unique-ness of article and category titles. You'll notice that the default "case-switch" set is looking for them in the default-named articles and categories tables. Comment the 4 case strings out and insert the ones below... they replace the default article and category table-names with the variable values.

Code: [Select]
case 'article_seftitle': $sql = "".gl('articles_table')." WHERE seftitle = '".clean($text)."' AND id != '".$not_id."'"; break;
case 'article_title': $sql = "".gl('articles_table')." WHERE title = '".clean($text)."' AND id != '".$not_id."'"; break;
case 'category_seftitle': $sql = "".gl('categories_table')." WHERE seftitle = '".clean($text)."' AND id != '".$not_id."'"; break;
case 'category_name': $sql = "".gl('categories_table')." WHERE name = '".clean($text)."' AND id != '".$not_id."'"; break;
Summary Notes:
1. As I noted above... these changes now allow the use of the table-name variables without using the $db-prefix string... and all content now displays fine. A few hours of testing have proven the table-name variable mod to be stable. :)

2. The Breadcrumbs line mod (http://www.solucija.com/forum/viewtopic.php?pid=34346#p34346) also works fine now. The mod is made in the single engine file, and that file is shared by both the main site and the module (sub-site). This mod produces this breadcrumb (http://snews.ca/misc/breadcrumb-mod.jpg) for the main site... and this breadcrumb (http://snews.ca/misc/breadcrumb-mod2.jpg) in the module (sub-site).
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 17, 2007, 08:41:42 pm
Another Problem that Needs a Solution
I'd hadn't gotten around to testing the nested (sub-site) module's Admin system until today and noted a serious problem. Since the sub-site's name is added to the site's URL, all of the admin panels that normally appear under the content textarea panel (when creating or editing content)... are not appearing. Obviously this is happening because the links within the snews engine's functions are not working with the sub-site folder name in the URL.

I have moved this whole topic to Programming because it is not fully functional at this time. More work is needed to somehow make the admin system switchable  to work with the various modules in the URL... using more global variables that can be set within each module's config file perhaps.
Title: Multiple installations using one sNews engine and one database.
Post by: Joost on July 17, 2007, 10:53:42 pm
:lol: As a mod it was never meant to be taken to extremes, like you guys do. But have it your way. I am enjoying every bit of it.
I guess my second approach  (using one settings table) must have misled you. I took it one bridge to far. In a previous post (http://#p34362) I've tried to warn you guys, not to get over excited. You didn't get the message though. :(

Additional testing in this set up, showed unwanted behaviour. Going from (sub)site to  (sub)site, there's one session Id, but several tokens, for each site. IMHO, this is a major issue that has to be dealt with.
When treating sub sites as stand-alone sites, this behaviour is what we want; it prevents cross-site access. When treating all sub sites as one,  the token has to be transferable, like settings.
So a lot of modding has to be done.
Smaller issues on functionality: Have you thought about one image-folder to be used site wide (if needed)?

Anyway, my next mod will include an extensive list of limitations and warnings, I promise.
 :D
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on July 17, 2007, 11:02:16 pm
Hey Joost... not to worry about giving us better or clearer warnings. I did not mind taking your idea as far as I could go... in fact I enjoy the challenge and... you never know where it will lead to. I will keep the project installed on my offline environment for ongoing consideration and exploration. :)
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 18, 2007, 08:21:22 am
@ Joost : Might be useful to refine the definition of target or split it into several independent ones ;) Otherwise, it might turn into attempt to blend few different and unrelated things into a single beast. And these ones are fun only drawing wise, not code wise :P
Title: Multiple installations using one sNews engine and one database.
Post by: Joost on July 18, 2007, 05:38:55 pm
Quote from: codetwist
@ Joost : Might be useful to refine the definition of target or split it into several independent ones ;) Otherwise, it might turn into attempt to blend few different and unrelated things into a single beast. And these ones are fun only drawing wise, not code wise :P
That's exactly what I meant, when I said the second approach must have misled you. ;) I have another one up my sleeve, but this time I'll take it to the outer limits, before publishing. I am not saying COMING SOON!!!. I'd rather say: Maņana ;)
Title: Multiple installations using one sNews engine and one database.
Post by: codetwist on July 18, 2007, 09:11:57 pm
:lol: ... that approach didn't mislead me for sure - it correctly lead me to implementation of multiple different layouts (http://www.solucija.com/forum/viewtopic.php?id=5323) MOD for single sNews instance. Damn, I'd say that leap from 1 to many with so simple changes couldn't come from misleading, U know ;)

P.S. Errr ... this Maņana thingy ... why can't I shake a feeling that it's another incarnation of COMING SOON  :o
Title: Multiple installations using one sNews engine and one database.
Post by: Joost on July 19, 2007, 01:51:27 am
Quote from: codetwist
P.S. Errr ... this Maņana thingy ... why can't I shake a feeling that it's another incarnation of COMING SOON  :o
:P
Title: Multiple installations using one sNews engine and one database.
Post by: piXelatedEmpire on July 19, 2007, 05:22:24 am
:lol:  :lol:  :lol:
Title: Multiple installations using one sNews engine and one database.
Post by: centered on August 16, 2007, 12:44:28 pm
Has this developed further?

I ask because an idea hit as to include an snews image gallery using sub-sNews installation from the root.  Utilizing sNews categories it wouldn't be too hard to do something similar to a default zen-photo setup.

Sub-sNews root
--Index showing categories within the center (category image[saw a mod somewhere for this] + category description [see my new mod for that])
----category 1 utilizing mattonik's image panel, thumbnails can show the gallery set
------utilizing the WIP sub-category mod (or a different method), you can show the full article w/ comments instead of the front article w/o comments

Just an idea I just had....
Title: Multiple installations using one sNews engine and one database.
Post by: Joost on August 16, 2007, 05:14:31 pm
You could use Codetwist's template switcher to display the category + desc function. In one template you insert
the normal in the other insert instead of .
Just a thought

What's the WIP sub-category mod? I can't find it.
Title: Multiple installations using one sNews engine and one database.
Post by: Keyrocks on August 16, 2007, 05:51:43 pm
Quote from: centered
Has this developed further?
I haven't worked on this approach since we ran into a problem (noted above)... where several modules would not deal properly with user sessions from different modules using a single engine file at the same time.

I started working on another "Modular" fork a couple days ago. This one separates the language variables into files in a langauges folder, puts templates (bakercad's mod) into a templates folder so templates can be switched from the Settings Admin Panel, and separates site-wide settings into a config.php file away from the engine file. Once I figure out how to make a language files switch, this package will allow language and template switching. It looks like this so far:

languages folder
   english.php - containing the complete language variables array,
templates folder
   default (default template folder)
      css folder
         style.css
      index.php (modified)
   temp2 folder (template folder)
      css folder
         temp2style.css
      images folder (template images only)
      index.php (modified)
.htaccess (the default file)
config.php (module-specific)
core.php (old snews.php less language and configuration settings)
index.php (opens the session, call config.php and includes the template)

----------------------------------------

Root index.php: opens the session... just as the un-modifed file did. It then includes the config.php file (the sites's settings) and chooses the currently active template from the templates folder.

Root config.php: the site settings, contained in:
1) the database variable array,
2) a new global variable array (dbase table-name variables and others) and
3) a new Files management array, containing the last 4 language variable strings (removed from the language file) so file management changes can be made more easily here. We call the engine file into action at the end of this file with an include string.

Root core.php: This contains all of the engine file functions (formerly snews.php), excluding the database, global and file management variable functions now located in config.php.
 
I don't know where it will lead to but it's working fine offline. Time will tell.
Title: Re: Multiple installations using one sNews engine and one database.
Post by: robsayles on January 23, 2009, 01:54:32 pm
Hi Keyrocks/all

I know this is old Programming, but did anyone get a stable 1.6 multilingual working?
It seems like it was sussed as a workflow (mainly), but never finalised?

I'd be interested in any demos or helping out if I can.

ATB
Rob
Title: Re: Multiple installations using one sNews engine and one database.
Post by: Joost on January 23, 2009, 02:51:36 pm
This (http://snewscms.com/forum/index.php?topic=5266.msg34191#msg34191) is and was stable.

Additionally, you can replace

Code: [Select]
SESSION[db('website').'Logged_In']

with

Code: [Select]
SESSION[__file__]
That way, you don't have log in separately in every language section.

Note: You will still have to change passwords in each language, because the language sections do not share the same password/username table.