HomeHelpTrac

source: trunk/install/index.php @ 16175

Revision 16175, 55.0 KB checked in by Anton Lesnikov, 6 weeks ago (diff)

Rebuilding of Template system.

Line 
1<?php
2
3/***************************************************************************
4*                            Dolphin Smart Community Builder
5*                              -----------------
6*     begin                : Mon Mar 23 2006
7*     copyright            : (C) 2006 BoonEx Group
8*     website              : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21
22
23define('CHECK_DOLPHIN_REQUIREMENTS', 1); //Don`t recommend to skip this step
24if (defined('CHECK_DOLPHIN_REQUIREMENTS')) {
25    //check requirements
26    $aErrors = array();
27
28    $aErrors[] = (ini_get('register_globals') == 0) ? '' : '<font color="red">register_globals is On (warning, you should have this param in Off state, or your site will unsafe)</font>';
29    $aErrors[] = (ini_get('safe_mode') == 0) ? '' : '<font color="red">safe_mode is On, disable it</font>';
30    //$aErrors[] = (ini_get('allow_url_fopen') == 0) ? 'Off (warning, better keep this parameter in On to able register Dolphin' : '';
31    $aErrors[] = (version_compare(PHP_VERSION, '5.2.0', '<')) ? '<font color="red">PHP version too old, please update to PHP 5.2.0 at least</font>' : '';
32    $aErrors[] = (! extension_loaded( 'mbstring')) ? '<font color="red">mbstring extension not installed. <b>Warning!</b> Dolphin cannot work without <b>mbstring</b> extension.</font>' : '';
33    // $aErrors[] = (! function_exists('shell_exec')) ? '<font color="red">shell_exec function is unvailable. <b>Warning!</b> Dolphin cannot work without <b>shell_exec</b> function.</font>' : '';
34    $aErrors[] = (ini_get('short_open_tag') == 0) ? '<font color="red">short_open_tag is Off (must be On!)<b>Warning!</b> Dolphin cannot work without <b>short_open_tag</b>.</font>' : '';
35
36    if (version_compare(phpversion(), "5.2", ">") == 1) {
37        $aErrors[] = (ini_get('allow_url_include') == 0) ? '' : '<font color="red">allow_url_include is On (warning, you should have this param in Off state, or your site will unsafe)</font>';
38    };
39
40    $aErrors = array_diff($aErrors, array('')); //delete empty
41    if (count($aErrors)) {
42        $sErrors = implode(" <br /> ", $aErrors);
43        echo <<<EOF
44{$sErrors} <br />
45Please go to the <br />
46<a href="http://www.boonex.com/trac/dolphin/wiki/GenDolTShooter">Dolphin Troubleshooter</a> <br />
47and solve the problem.
48EOF;
49        exit;
50    }
51}
52
53if (version_compare(phpversion(), "5.3.0", ">=")  == 1)
54  error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
55else
56  error_reporting(E_ALL & ~E_NOTICE);
57set_magic_quotes_runtime(0);
58ini_set('magic_quotes_sybase', 0);
59
60/*------------------------------*/
61/*----------Vars----------------*/
62    $aConf = array();
63    $aConf['release'] = '24.03.11';
64    $aConf['iVersion'] = '7.0';
65    $aConf['iPatch'] = '6';
66    $aConf['dolFile'] = '../inc/header.inc.php';
67    $aConf['confDir'] = '../inc/';
68    $aConf['headerTempl'] = <<<EOS
69<?php
70/**
71 * @package     Dolphin Core
72 * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
73 * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
74 */
75
76define ('BX_PROFILER', true);
77if (BX_PROFILER && !isset(\$GLOBALS['bx_profiler_start']))
78    \$GLOBALS['bx_profiler_start'] = microtime ();
79
80
81//--- Version ---//
82define('BX_DOL_VERSION', '{$aConf['iVersion']}');
83define('BX_DOL_BUILD', '{$aConf['iPatch']}');
84
85//--- Main URLs ---//
86define('BX_DOL_URL_ROOT', '%site_url%');
87define('BX_DOL_URL_PLUGINS', BX_DOL_URL_ROOT . 'plugins/');
88define('BX_DOL_URL_MODULES', BX_DOL_URL_ROOT . 'modules/');
89define('BX_DOL_URL_CACHE_PUBLIC', BX_DOL_URL_ROOT . 'cache_public/');
90define('BX_DOL_URL_BASE', BX_DOL_URL_ROOT . 'template/');
91
92//--- Main Pathes ---//
93define('BX_DIRECTORY_PATH_ROOT', '%dir_root%');
94define('BX_DIRECTORY_PATH_INC', BX_DIRECTORY_PATH_ROOT . 'inc/');
95define('BX_DIRECTORY_PATH_BASE', BX_DIRECTORY_PATH_ROOT . 'template/');
96define('BX_DIRECTORY_PATH_CACHE', BX_DIRECTORY_PATH_ROOT . 'cache/');
97define('BX_DIRECTORY_PATH_CACHE_PUBLIC', BX_DIRECTORY_PATH_ROOT . 'cache_public/');
98define('BX_DIRECTORY_PATH_CLASSES', BX_DIRECTORY_PATH_ROOT . 'inc/classes/');
99define('BX_DIRECTORY_PATH_PLUGINS', BX_DIRECTORY_PATH_ROOT . 'plugins/');
100define('BX_DIRECTORY_PATH_MODULES', BX_DIRECTORY_PATH_ROOT . 'modules/');
101define('BX_DIRECTORY_STORAGE', BX_DIRECTORY_PATH_ROOT . 'storage/');
102
103//--- DB Connection ---//
104define('BX_DATABASE_HOST', '%db_host%');
105define('BX_DATABASE_SOCK', '%db_sock%');
106define('BX_DATABASE_PORT', '%db_port%');
107define('BX_DATABASE_USER', '%db_user%');
108define('BX_DATABASE_PASS', '%db_password%');
109define('BX_DATABASE_NAME', '%db_name%');
110
111//--- System settings ---//
112define('BX_SYSTEM_MOGRIFY', '%dir_mogrify%');
113define('BX_SYSTEM_CONVERT', '%dir_convert%');
114define('BX_SYSTEM_COMPOSITE', '%dir_composite%');
115define('BX_SYSTEM_PHPBIN', '%dir_php%');
116
117define('BX_DOL_DIR_RIGHTS', 0777);
118define('BX_DOL_FILE_RIGHTS', 0666);
119
120define('BX_DOL_STORAGE_OBJ_IMAGES', 'sys_images');
121
122define('BX_DOL_INT_MAX', 2147483647);
123
124define('BX_DOL_TRANSCODER_OBJ_ICON_APPLE', 'sys_icon_apple');
125define('BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK', 'sys_icon_facebook');
126define('BX_DOL_TRANSCODER_OBJ_ICON_FAVICON', 'sys_icon_favicon');
127
128//--- Module types ---//
129define('BX_DOL_MODULE_TYPE_MODULE', 'module');
130define('BX_DOL_MODULE_TYPE_LANGUAGE', 'language');
131define('BX_DOL_MODULE_TYPE_TEMPLATE', 'template');
132
133//--- Studio settings ---//
134define('BX_DOL_STUDIO_FOLDER', 'studio');
135
136define('BX_DOL_URL_STUDIO', BX_DOL_URL_ROOT . BX_DOL_STUDIO_FOLDER . '/');
137define('BX_DOL_URL_STUDIO_BASE', BX_DOL_URL_STUDIO . 'template/');
138
139define('BX_DOL_DIR_STUDIO', BX_DIRECTORY_PATH_ROOT . BX_DOL_STUDIO_FOLDER . '/');
140define('BX_DOL_DIR_STUDIO_INC', BX_DOL_DIR_STUDIO . 'inc/');
141define('BX_DOL_DIR_STUDIO_CLASSES', BX_DOL_DIR_STUDIO . 'classes/');
142define('BX_DOL_DIR_STUDIO_BASE', BX_DOL_DIR_STUDIO . 'template/');
143
144//--- User Roles ---//
145define('BX_DOL_ROLE_GUEST', 0);
146define('BX_DOL_ROLE_MEMBER', 1);
147define('BX_DOL_ROLE_ADMIN', 2);
148
149// profile statuses
150define('BX_PROFILE_STATUS_SUSPENDED', 'suspended'); ///< profile status - suspended, profile is syspended by admin/moderator and usually can't access the site
151define('BX_PROFILE_STATUS_ACTIVE', 'active'); ///< profile status - active, profile is active on the site
152define('BX_PROFILE_STATUS_PENDING', 'pending'); ///< profile status - pending, default method of approving is manual approving
153
154define('BX_DOL', 1);
155
156define('BX_DOL_SECRET', 'sdn378vGR35'); // TODO: autogenerate during installation
157
158define('CHECK_DOLPHIN_REQUIREMENTS', 1);
159if (defined('CHECK_DOLPHIN_REQUIREMENTS')) {
160    //check requirements
161    \$aErrors = array();
162
163    \$aErrors[] = (ini_get('register_globals') == 0) ? '' : '<font color="red">register_globals is On (warning, you should have this param in Off state, or your site will unsafe)</font>';
164    \$aErrors[] = (ini_get('safe_mode') == 0) ? '' : '<font color="red">safe_mode is On, disable it</font>';
165    //\$aErrors[] = (ini_get('allow_url_fopen') == 0) ? 'Off (warning, better keep this parameter in On to able register Dolphin' : '';
166    \$aErrors[] = (version_compare(PHP_VERSION, '5.2.0', '<')) ? '<font color="red">PHP version too old, please update to PHP 5.2.0 at least</font>' : '';
167    \$aErrors[] = (! extension_loaded( 'mbstring')) ? '<font color="red">mbstring extension not installed. <b>Warning!</b> Dolphin cannot work without <b>mbstring</b> extension.</font>' : '';
168
169    if (version_compare(phpversion(), "5.2", ">") == 1) {
170        \$aErrors[] = (ini_get('allow_url_include') == 0) ? '' : '<font color="red">allow_url_include is On (warning, you should have this param in Off state, or your site will unsafe)</font>';
171    };
172
173    \$aErrors = array_diff(\$aErrors, array('')); //delete empty
174    if (count(\$aErrors)) {
175        \$sErrors = implode(" <br /> ", \$aErrors);
176        echo <<<EOF
177{\$sErrors} <br />
178Please go to the <br />
179<a href="http://www.boonex.com/trac/dolphin/wiki/GenDolTShooter">Dolphin Troubleshooter</a> <br />
180and solve the problem.
181EOF;
182        exit;
183    }
184}
185
186//check correct hostname
187\$aUrl = parse_url( BX_DOL_URL_ROOT );
188if( isset(\$_SERVER['HTTP_HOST']) and 0 != strcasecmp(\$_SERVER['HTTP_HOST'], \$aUrl['host']) and 0 != strcasecmp(\$_SERVER['HTTP_HOST'], \$aUrl['host'] . ':80') ) {
189    header( "Location:http://{\$aUrl['host']}{\$_SERVER['REQUEST_URI']}" );
190    exit;
191}
192
193// check if install folder exists
194/**
195 * Uncomment for live version
196 *
197if ( !defined ('BX_SKIP_INSTALL_CHECK') && file_exists( BX_DIRECTORY_PATH_ROOT . 'install' ) ) {
198    \$ret = <<<EOJ
199<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
200    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
201        <head>
202            <title>Dolphin Smart Community Builder Installed</title>
203            <link href="install/general.css" rel="stylesheet" type="text/css" />
204            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
205        </head>
206        <body>
207            <div id="main">
208            <div id="header">
209                <img src="install/images/boonex-logo.png" alt="" /></div>
210            <div id="content">
211                <div class="installed_pic">
212                    <img alt="Dolphin Installed" src="install/images/dolphin_installed.jpg" />
213            </div>
214
215            <div class="installed_text">
216                Please, remove INSTALL directory from your server and reload this page to activate your community site.
217            </div>
218            <div class="installed_text">
219                NOTE: Once you remove this page you can safely <a href="administration/modules.php">install modules via Admin Panel</a>.
220            </div>
221        </body>
222    </html>
223EOJ;
224    echo \$ret;
225    exit();
226}
227*/
228
229// set error reporting level
230error_reporting(E_ALL);
231
232ini_set('magic_quotes_sybase', 0);
233
234// set default encoding for multibyte functions
235mb_internal_encoding('UTF-8');
236mb_regex_encoding('UTF-8');
237
238require_once(BX_DIRECTORY_PATH_CLASSES . "BxDol.php");
239require_once(BX_DIRECTORY_PATH_INC . "security.inc.php");
240require_once(BX_DIRECTORY_PATH_INC . "utils.inc.php");
241require_once(BX_DIRECTORY_PATH_INC . "db.inc.php");
242require_once(BX_DIRECTORY_PATH_INC . "profiles.inc.php");
243
244bx_import('BxDolConfig');
245bx_import('BxDolService');
246bx_import('BxDolAlerts');
247
248\$oZ = new BxDolAlerts('system', 'begin', 0);
249\$oZ->alert();
250
251EOS;
252
253    $aConf['periodicTempl'] = <<<EOS
254MAILTO=%site_email%<br />
255* * * * * cd %dir_root%periodic; %dir_php% -q cron.php<br />
256EOS;
257
258    $confFirst = array();
259    $confFirst['site_url'] = array(
260        name => "Site URL",
261        ex => "http://www.mydomain.com/path/",
262        desc => "Your site URL here (backslash at the end required)",
263        def => "http://",
264        def_exp => '
265            $str = "http://".$_SERVER[\'HTTP_HOST\'].$_SERVER[\'PHP_SELF\'];
266            return preg_replace("/install\/(index\.php$)/","",$str);',
267        check => 'return strlen($arg0) >= 10 ? true : false;'
268    );
269    $confFirst['dir_root'] = array(
270        name => "Directory root",
271        ex => "/path/to/your/script/files/",
272        desc => "Path to directory where your php script files stored.",
273        def_exp => '
274            $str = rtrim($_SERVER[\'DOCUMENT_ROOT\'], \'/\').$_SERVER[\'PHP_SELF\'];
275            return preg_replace("/install\/(index\.php$)/","",$str);',
276        check => 'return strlen($arg0) >= 1 ? true : false;'
277    );
278    $confFirst['dir_php'] = array(
279        name => "Path to php binary",
280        ex => "/usr/local/bin/php",
281        desc => "You should specify full path to your PHP interpreter here.",
282        def => "/usr/local/bin/php",
283        def_exp => "
284            if ( file_exists(\"/usr/local/bin/php\") ) return \"/usr/local/bin/php\";
285            \$fp = popen ( \"whereis php\", \"r\");
286            if ( \$fp )
287            {
288                \$s = fgets(\$fp);
289                \$s = sscanf(\$s, \"php: %s\");
290                if ( file_exists(\"\$s[0]\") ) return \"\$s[0]\";
291               }
292               return '';",
293        check => 'return strlen($arg0) >= 7 ? true : false;'
294    );
295    $confFirst['dir_mogrify'] = array(
296        name => "Path to mogrify",
297        ex => "/usr/local/bin/mogrify",
298        desc => "If mogrify binary doesn't exist please install <a href='http://www.imagemagick.org/'>ImageMagick</a>",
299        def => "/usr/local/bin/mogrify",
300        def_exp => "
301            if ( file_exists(\"/usr/X11R6/bin/mogrify\") ) return \"/usr/X11R6/bin/mogrify\";
302            if ( file_exists(\"/usr/local/bin/mogrify\") ) return \"/usr/local/bin/mogrify\";
303            if ( file_exists(\"/usr/bin/mogrify\") ) return \"/usr/bin/mogrify\";
304            if ( file_exists(\"/usr/local/X11R6/bin/mogrify\") ) return \"/usr/local/X11R6/bin/mogrify\";
305            if ( file_exists(\"/usr/bin/X11/mogrify\") ) return \"/usr/bin/X11/mogrify\";
306            return '';",
307        check => 'return strlen($arg0) >= 7 ? true : false;'
308    );
309    $confFirst['dir_convert'] = array(
310        name => "Path to convert",
311        ex => "/usr/local/bin/convert",
312        desc => "If convert binary doesn't exist please install <a href='http://www.imagemagick.org/'>ImageMagick</a>",
313        def => "/usr/local/bin/convert",
314        def_exp => "
315            if ( file_exists(\"/usr/X11R6/bin/convert\") ) return \"/usr/X11R6/bin/convert\";
316            if ( file_exists(\"/usr/local/bin/convert\") ) return \"/usr/local/bin/convert\";
317            if ( file_exists(\"/usr/bin/convert\") ) return \"/usr/bin/convert\";
318            if ( file_exists(\"/usr/local/X11R6/bin/convert\") ) return \"/usr/local/X11R6/bin/convert\";
319            if ( file_exists(\"/usr/bin/X11/convert\") ) return \"/usr/bin/X11/convert\";
320            return '';",
321        check => 'return strlen($arg0) >= 7 ? true : false;'
322    );
323    $confFirst['dir_composite'] = array(
324        name => "Path to composite",
325        ex => "/usr/local/bin/composite",
326        desc => "If composite binary doesn't exist please install <a href='http://www.imagemagick.org/'>ImageMagick</a>",
327        def => "/usr/local/bin/composite",
328        def_exp => "
329            if ( file_exists(\"/usr/X11R6/bin/composite\") ) return \"/usr/X11R6/bin/composite\";
330            if ( file_exists(\"/usr/local/bin/composite\") ) return \"/usr/local/bin/composite\";
331            if ( file_exists(\"/usr/bin/composite\") ) return \"/usr/bin/composite\";
332            if ( file_exists(\"/usr/local/X11R6/bin/composite\") ) return \"/usr/local/X11R6/bin/composite\";
333            if ( file_exists(\"/usr/bin/X11/composite\") ) return \"/usr/bin/X11/composite\";
334            return '';",
335        check => 'return strlen($arg0) >= 7 ? true : false;'
336    );
337
338    $aDbConf = array();
339    $aDbConf['sql_file'] = array(
340        name => "SQL file",
341        ex => "/home/dolphin/public_html/install/sql/vXX.sql",
342        desc => "SQL file location",
343        def => "./sql/vXX.sql",
344        def_exp => '
345            if ( !( $dir = opendir( "sql/" ) ) )
346                return "";
347            while (false !== ($file = readdir($dir)))
348                {
349                if ( substr($file,-3) != \'sql\' ) continue;
350                closedir( $dir );
351                return "./sql/$file";
352            }
353            closedir( $dir );
354            return "";',
355        check => 'return strlen($arg0) >= 4 ? true : false;'
356    );
357    $aDbConf['db_host'] = array(
358        name => "Database host name",
359        ex => "localhost",
360        desc => "Your MySQL database host name here.",
361        def => "localhost",
362        check => 'return strlen($arg0) >= 1 ? true : false;'
363    );
364    $aDbConf['db_port'] = array(
365        name => "Database host port number",
366        ex => "5506",
367        desc => "Leave blank or specify MySQL Database host port number.",
368        def => "",
369        check => ''
370    );
371    $aDbConf['db_sock'] = array(
372        name => "Database socket path",
373        ex => "/tmp/mysql50.sock",
374        desc => "Leave blank or specify MySQL Database socket path.",
375        def => "",
376        check => ''
377    );
378    $aDbConf['db_name'] = array(
379        name => "Database name",
380        ex => "YourDatabaseName",
381        desc => "Your MySQL database name here.",
382        check => 'return strlen($arg0) >= 1 ? true : false;'
383    );
384    $aDbConf['db_user'] = array(
385        name => "Database user",
386        ex => "YourName",
387        desc => "Your MySQL database read/write user name here.",
388        check => 'return strlen($arg0) >= 1 ? true : false;'
389    );
390    $aDbConf['db_password'] = array(
391        name => "Database password",
392        ex => "YourPassword",
393        desc => "Your MySQL database password here.",
394        check => 'return strlen($arg0) >= 0 ? true : false;'
395    );
396
397    $aGeneral = array();
398    $aGeneral['site_title'] = array(
399        name => "Site Title",
400        ex => "The Best Community",
401        desc => "The name of your site",
402        check => 'return strlen($arg0) >= 1 ? true : false;'
403    );
404    $aGeneral['site_desc'] = array(
405        name => "Site Description",
406        ex => "The place to find new friends, communicate and have fun.",
407        desc => "Meta description of your site",
408        check => 'return strlen($arg0) >= 1 ? true : false;'
409    );
410    $aGeneral['site_email'] = array(
411        name => "Site e-mail",
412        ex => "your@email.here",
413        desc => "Your site e-mail.",
414        check => 'return strlen($arg0) > 0 AND strstr($arg0,"@") ? true : false;'
415    );
416    $aGeneral['notify_email'] = array(
417        name => "Notify e-mail",
418        ex => "your@email.here",
419        desc => "Envelope \"From:\" address for notification messages",
420        check => 'return strlen($arg0) > 0 AND strstr($arg0,"@") ? true : false;'
421    );
422    $aGeneral['bug_report_email'] = array(
423        name => "Bug report email",
424        ex => "your@email.here",
425        desc => "Your email for receiving bug reports.",
426        check => 'return strlen($arg0) > 0 AND strstr($arg0,"@") ? true : false;'
427    );
428    $aGeneral['admin_username'] = array(
429        name => "Admin Username",
430        ex => "admin",
431        desc => "Specify the admin name here",
432        check => 'return strlen($arg0) >= 1 ? true : false;'
433    );
434    $aGeneral['admin_password'] = array(
435        name => "Admin Password",
436        ex => "dolphin",
437        desc => "Specify the admin password here",
438        check => 'return strlen($arg0) >= 1 ? true : false;'
439    );
440
441    $aNonDeletableModules = array(
442        'boonex/shared_photo/',
443    );
444
445    $aTemporalityWritableFolders = array(
446        'inc',
447    );
448
449/*----------Vars----------------*/
450/*------------------------------*/
451
452
453$sAction = $_REQUEST['action'];
454$sError = '';
455
456define('BX_SKIP_INSTALL_CHECK', true);
457// --------------------------------------------
458if ($sAction=='step6' || $sAction=='step7' || $sAction=='compile_languages') {
459    require_once('../inc/header.inc.php' );
460    require_once( BX_DIRECTORY_PATH_INC . 'db.inc.php' );
461    require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
462} else {
463    define ('BX_DOL', 1);
464    require_once('../inc/classes/BxDol.php');
465}
466// --------------------------------------------
467require_once('../inc/classes/BxDolIO.php');
468
469
470$sInstallPageContent = InstallPageContent( $sError );
471
472mb_internal_encoding('UTF-8');
473
474echo PageHeader( $sAction, $sError );
475echo $sInstallPageContent;
476echo PageFooter( $sAction );
477
478function InstallPageContent(&$sError) {
479    global $aConf, $confFirst, $aDbConf, $aGeneral;
480
481    $sRet = '';
482
483    switch ($_REQUEST['action']) {
484        case 'compile_languages':
485            performInstallLanguages();
486            $sRet .= 'Default Dolphin language was recompiled';
487            break;
488        /*case 'step8':
489            $sRet .= genMainDolphinPage();
490        break;
491
492        case 'step7':
493            $sInstallLog = '';
494            if ($_REQUEST['sub_action']=='install_modules') {
495                if (is_array($_POST['pathes']) && count($_POST['pathes'])>0) {
496                    $oInstallerUi = new BxDolInstallerUi();
497                    $sInstallLog = $oInstallerUi->actionInstall($_POST['pathes']);
498                }
499            }
500            $sRet .= genInstallModulesPage($sInstallLog);
501        break;*/
502
503        case 'step7':
504            $sRet .= genMainDolphinPage();
505        break;
506
507        case 'step6':
508            $sErrorMessage = checkPostInstallPermissions($sError);
509            $sRet .= (strlen($sErrorMessage)) ? genPostInstallPermissionTable($sErrorMessage) : genMainDolphinPage();
510        break;
511
512        case 'step5':
513            $sRet .= genPostInstallPermissionTable();
514        break;
515
516        case 'step4':
517            $sErrorMessage = checkConfigArray($aGeneral, $sError);
518            $sRet .= (strlen($sErrorMessage)) ? genSiteGeneralConfig($sErrorMessage) : genInstallationProcessPage();
519        break;
520
521        case 'step3':
522            $sErrorMessage = checkConfigArray($aDbConf, $sError);
523            $sErrorMessage .= CheckSQLParams();
524
525            $sRet .=  (strlen($sErrorMessage)) ? genDatabaseConfig($sErrorMessage) : genSiteGeneralConfig();
526        break;
527
528        case 'step2':
529            $sErrorMessage = checkConfigArray($confFirst, $sError);
530            $sRet .= (strlen($sErrorMessage)) ? genPathCheckingConfig($sErrorMessage) : genDatabaseConfig();
531        break;
532
533        case 'step1':
534            $sErrorMessage = checkPreInstallPermission($sError);
535            $sRet .= (strlen($sErrorMessage)) ? genPreInstallPermissionTable($sErrorMessage) : genPathCheckingConfig();
536        break;
537
538        case 'preInstall':
539            $sRet .= genPreInstallPermissionTable();
540        break;
541
542        default:
543            $sRet .= StartInstall();
544        break;
545    }
546
547    return $sRet;
548}
549
550function performInstallLanguages() {
551    db_res("TRUNCATE TABLE `sys_localization_languages`");
552    db_res("TRUNCATE TABLE `sys_localization_keys`");
553    db_res("TRUNCATE TABLE `sys_localization_strings`");
554
555    if (!($sLangsDir = opendir(BX_DIRECTORY_PATH_ROOT . 'install/langs/')))
556        return;
557    while (false !== ($sFilename = readdir($sLangsDir))) {
558        if (substr($sFilename,-3) == 'php') {
559            //$sLangName = substr($sFilename,-6, 2);
560            unset($LANG);
561            unset($LANG_INFO);
562            require_once(BX_DIRECTORY_PATH_ROOT . 'install/langs/' . $sFilename);
563            walkThroughLanguage($LANG, $LANG_INFO);
564        }
565    }
566    closedir ($sLangsDir);
567    require_once('../inc/languages.inc.php');
568    compileLanguage();
569}
570
571function walkThroughLanguage($aLanguage, $aLangInfo) {
572    $sLangName = $aLangInfo['Name'];
573    $sLangFlag = $aLangInfo['Flag'];
574    $sLangTitle = $aLangInfo['Title'];
575    $sInsertLanguageSQL = "INSERT INTO `sys_localization_languages` VALUES (NULL, '{$sLangName}', '{$sLangFlag}', '{$sLangTitle}')";
576    db_res($sInsertLanguageSQL);
577    $iLangKey = db_last_id();
578
579    foreach ($aLanguage as $sKey => $sValue) {
580        $sDqKey = str_replace("'", "''", $sKey);
581        $sDqValue = str_replace("'", "''", $sValue);
582
583        $iExistedKey = (int)db_value("SELECT `ID` FROM `sys_localization_keys` WHERE `Key`='{$sDqKey}'");
584        if ($iExistedKey>0) { //Key existed, no need insert key
585        } else {
586            $sInsertKeySQL = "INSERT INTO `sys_localization_keys` VALUES(NULL, 1, '{$sDqKey}')";
587            db_res($sInsertKeySQL);
588            $iExistedKey = db_last_id();
589        }
590
591        $sInsertValueSQL = "INSERT INTO `sys_localization_strings` VALUES({$iExistedKey}, {$iLangKey}, '{$sDqValue}');";
592        db_res($sInsertValueSQL);
593    }
594}
595
596function genInstallModulesPage($sErrorMessage = '') {
597    global $aNonDeletableModules;
598
599    $sCurPage = $_SERVER['PHP_SELF'];
600
601    if ($_REQUEST['sub_action']!='install_modules') {
602        performInstallLanguages();
603    }
604
605    $sErrors = printInstallError($sErrorMessage);
606
607    $oInstallerUi = new BxDolInstallerUi();
608    $aAdditionalInputs['hidden_sub_action'] = array(
609        'type' => 'hidden',
610        'name' => 'sub_action',
611        'value' => 'install_modules'
612    );
613    $aAdditionalInputs['hidden_action'] = array(
614        'type' => 'hidden',
615        'name' => 'action',
616        'value' => 'step7'
617    );
618
619    $sNotInstalled = $oInstallerUi->getNotInstalled($aAdditionalInputs /*, $aNonDeletableModules*/);
620
621    //module_not_install_form
622    $sSkipStep = '';
623    if ($_REQUEST['sub_action']=='install_modules') {
624        $sSkipStep = <<<EOF
625<div class="button_area_2">
626    <form action="{$sCurPage}" method="post">
627        <input id="button" type="image" src="images/skip.gif" />
628        <input type="hidden" name="action" value="step8" />
629    </form>
630</div>
631EOF;
632    }
633
634    return <<<EOF
635<div class="position">Modules.</div>
636{$sErrors}
637<div class="LeftRight">
638    <div class="clearBoth"></div>
639    <div class="left">&nbsp;</div>
640    <div class="right">
641
642    <script type="text/javascript">
643    <!--
644        function PerformInstall() {
645            var oForm = document.getElementById('module_not_install_form');
646            oForm.submit();
647        }
648    -->
649    </script>
650
651        {$sNotInstalled}
652        <div class="formKeeper1">
653            <div class="button_area_1">
654                <form action="{$sCurPage}" method="post">
655                    <input id="button" type="image" src="images/next.gif" onclick="PerformInstall(); return false;" />
656                    <input type="hidden" name="action" value="step8" />
657                </form>
658            </div>
659            {$sSkipStep}
660        </div>
661    </div>
662    <div class="clearBoth"></div>
663</div>
664EOF;
665}
666
667function genInstallationProcessPage($sErrorMessage = '') {
668    global $aConf, $confFirst, $aDbConf, $aGeneral;
669
670    $sAdminName     = get_magic_quotes_gpc() ? stripslashes($_REQUEST['admin_username']) : $_REQUEST['admin_username'];
671    $sAdminPassword = get_magic_quotes_gpc() ? stripslashes($_REQUEST['admin_password']) : $_REQUEST['admin_password'];
672    $resRunSQL = RunSQL( $sAdminName, $sAdminPassword );
673
674    $sForm = '';
675
676    if ('done' ==  $resRunSQL) {
677        $sForm = '
678        <div class="formKeeper">
679            <form action="' . $_SERVER['PHP_SELF'] . '" method="post">
680                <input type="image" src="images/next.gif" />
681                <input type="hidden" name="action" value="step5" />
682            </form>
683        </div>
684        <div class="clearBoth"></div>';
685    } else {
686        $sForm = $resRunSQL . '
687        <div class="formKeeper">
688            <form action="' . $_SERVER['PHP_SELF'] . '" method="post">
689                <input type="image" src="images/back.gif" />';
690        foreach ($_POST as $sKey => $sValue) {
691            if ($sKey != "action")
692                $sForm .= '<input type="hidden" name="' . $sKey . '" value="' . $sValue . '" />';
693        }
694        $sForm .= '<input type="hidden" name="action" value="step2" />
695            </form>
696        </div>
697        <div class="clearBoth"></div>';
698        return $sForm;
699    }
700
701    foreach ($confFirst as $key => $val) {
702        $aConf['headerTempl'] = str_replace ("%$key%", $_POST[$key], $aConf['headerTempl']);
703    }
704    foreach ($aDbConf as $key => $val) {
705        $aConf['headerTempl'] = str_replace ("%$key%", $_POST[$key], $aConf['headerTempl']);
706    }
707    foreach ($aGeneral as $key => $val) {
708        $aConf['headerTempl'] = str_replace ("%$key%", $_POST[$key], $aConf['headerTempl']);
709    }
710
711    $aConf['periodicTempl'] = str_replace("%site_email%", $_POST['site_email'], $aConf['periodicTempl']);
712    $aConf['periodicTempl'] = str_replace("%dir_root%",   $_POST['dir_root'],   $aConf['periodicTempl']);
713    $aConf['periodicTempl'] = str_replace("%dir_php%",    $_POST['dir_php'],    $aConf['periodicTempl']);
714
715    $sInnerCode = '';
716    $fp = fopen($aConf['dolFile'], 'w');
717    if ($fp) {
718        fputs($fp, $aConf['headerTempl']);
719        fclose($fp);
720        chmod($aConf['dolFile'], 0666);
721        //$sInnerCode .='Config file was successfully written to <strong>' . $aConf['dolFile'] . '</strong><br />';
722    } else {
723        $text = 'Warning!!! can not get write access to config file ' . $aConf['dolFile'] . '. Here is config file</font><br>';
724        $sInnerCode .= printInstallError($text);
725        $trans = get_html_translation_table(HTML_ENTITIES);
726        $templ = strtr($aConf['headerTempl'], $trans);
727        $sInnerCode .= '<textarea cols="20" rows="10" class="headerTextarea">' . $aConf['headerTempl'] . '</textarea>';
728    }
729
730    $sInnerCode .= <<<EOF
731<div class="left">
732    Please, setup Cron Jobs as specified below. Helpful info about Cron Jobs is <a href="http://www.boonex.com/trac/dolphin/wiki/DetailedInstall#InstallScript-Step5-CronJobs">available here</a>.</div>
733    <div class="debug">
734        {$aConf['periodicTempl']}
735    </div>
736EOF;
737
738    return <<<EOF
739<div class="position">Cron Jobs</div>
740<div class="LeftRirght">
741    {$sInnerCode}{$sForm}
742</div>
743EOF;
744}
745
746function isAdmin() { return false; }
747
748// check of step 5
749function checkPostInstallPermissions(&$sError) {
750    global $aTemporalityWritableFolders;
751
752    $sFoldersErr = $sFilesErr = $sErrorMessage = '';
753   
754    require_once('../studio/classes/BxDolStudioTools.php');
755    $oAdmTools = new BxDolAdminTools();
756    $oBxDolIO = new BxDolIO();
757
758    $aInstallDirsMerged = array_merge($aTemporalityWritableFolders, $oAdmTools->aPostInstallPermDirs);
759    foreach ($aInstallDirsMerged as $sFolder) {
760        if ($oBxDolIO->isWritable($sFolder)) {
761            $sFoldersErr .= '&nbsp;&nbsp;&nbsp;' . $sFolder . ';<br />';
762        }
763    }
764    if (strlen( $sFoldersErr)) {
765        $sError = 'error';
766        $sErrorMessage .= '<strong>Next directories have inappropriate permissions</strong>:<br />' . $sFoldersErr;
767    }
768    foreach ($oAdmTools->aPostInstallPermFiles as $sFile) {
769        if ($oBxDolIO->isWritable($sFile)) {
770            $sFilesErr .= '&nbsp;&nbsp;&nbsp;' . $sFile . ';<br /> ';
771        }
772    }
773    if (strlen($sFilesErr)) {
774        $sError = 'error';
775        $sErrorMessage .= '<strong>Next files have inappropriate permissions</strong>:<br />' . $sFilesErr;
776    }
777
778    return $sErrorMessage;
779}
780
781// step 5
782function genPostInstallPermissionTable($sErrorMessage = '') {
783    global $aTemporalityWritableFolders;
784
785    $sCurPage = $_SERVER['PHP_SELF'];
786    $sPostFolders = $sPostFiles = '';
787
788    $sErrors = printInstallError($sErrorMessage);
789
790    require_once('../studio/classes/BxDolStudioTools.php');
791    $oAdmTools = new BxDolAdminTools();
792    $oBxDolIO = new BxDolIO();
793
794    $aInstallDirsMerged = array_merge($aTemporalityWritableFolders, $oAdmTools->aPostInstallPermDirs);
795    $i = 0;
796    foreach($aInstallDirsMerged as $sFolder) {
797        $sStyleAdd = ( ($i%2) == 0 ) ? 'background-color:#ede9e9;' : 'background-color:#fff;';
798
799        $sEachFolder = ( $oBxDolIO->isWritable($sFolder) )
800            ? '<span class="unwritable">Writable</span>' : '<span class="writable">Non-writable</span>';
801
802        $sPostFolders .= <<<EOF
803<tr style="{$sStyleAdd}" class="cont">
804    <td>{$sFolder}</td>
805    <td class="span">
806        {$sEachFolder}
807    </td>
808    <td class="span">
809        <span class="desired">Non-writable</span>
810    </td>
811</tr>
812EOF;
813        $i++;
814    }
815
816    $i = 0;
817    foreach($oAdmTools->aPostInstallPermFiles as $sFile) {
818        $str = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF'];
819        $sFolder = preg_replace("/install\/(index\.php$)/","",$str);
820
821        if (file_exists($sFolder . $sFile)) {
822            $sStyleAdd = ( ($i%2) == 0 ) ? 'background-color:#ede9e9;' : 'background-color:#fff;';
823
824            $sEachFile = ( $oBxDolIO->isWritable($sFile) )
825                ? '<span class="unwritable">Writable</span>'
826                : '<span class="writable">Non-writable</span>';
827
828            $sPostFiles .= <<<EOF
829<tr style="{$sStyleAdd}" class="cont">
830    <td>{$sFile}</td>
831    <td class="span">
832        {$sEachFile}
833    </td>
834    <td class="span">
835        <span class="desired">Non-writable</span>
836    </td>
837</tr>
838EOF;
839            $i++;
840        }
841    }
842
843    return <<<EOF
844<div class="position">Permissions Reversal</div>
845{$sErrors}
846<div class="LeftRight">
847    <div class="clearBoth"></div>
848    <div class="left">Now, when Dolphin completed installation, you should change permissions for some files to keep your site secure. Please, change permissions as specified in the chart below. Helpful info about permissions is <a href="http://www.boonex.com/trac/dolphin/wiki/DetailedInstall#InstallScript-Step1-Permissions" target="_blank">available here</a>.</div>
849    <div class="right">
850        <table cellpadding="0" cellspacing="1" width="100%" border="0" style="background-color:silver;">
851            <tr class="head">
852                <td>Directories</td>
853                <td>Current Level</td>
854                <td>Desired Level</td>
855            </tr>
856            {$sPostFolders}
857            <tr class="head">
858                <td>Files</td>
859                <td>Current Level</td>
860                <td>Desired Level</td>
861            </tr>
862            {$sPostFiles}
863        </table>
864        <div class="formKeeper1">
865            <div class="button_area_1">
866                <form action="{$sCurPage}" method="post">
867                    <input id="button" type="image" src="images/check.gif" />
868                    <input type="hidden" name="action" value="step5" />
869                </form>
870            </div>
871            <div class="button_area_1">
872                <form action="{$sCurPage}" method="post">
873                    <input id="button" type="image" src="images/next.gif" />
874                    <input type="hidden" name="action" value="step6" />
875                </form>
876            </div>
877            <div class="button_area_2">
878                <form action="{$sCurPage}" method="post">
879                    <input id="button" type="image" src="images/skip.gif" />
880                    <input type="hidden" name="action" value="step7" />
881                </form>
882            </div>
883        </div>
884    </div>
885    <div class="clearBoth"></div>
886</div>
887EOF;
888}
889
890function genSiteGeneralConfig($sErrorMessage = '') {
891    global $aGeneral;
892
893    $sCurPage = $_SERVER['PHP_SELF'];
894    $sSGParamsTable = createTable($aGeneral);
895
896    $sErrors = '';
897    if (strlen($sErrorMessage)) {
898        $sErrors = printInstallError($sErrorMessage);
899        unset($_POST['site_title']);
900        unset($_POST['site_email']);
901        unset($_POST['notify_email']);
902        unset($_POST['bug_report_email']);
903    }
904
905    $sOldDataParams = '';
906    foreach($_POST as $postKey => $postValue) {
907        $sOldDataParams .= ('action' == $postKey || isset($aGeneral[$postKey])) ? '' : '<input type="hidden" name="' . $postKey . '" value="' . $postValue . '" />';
908    }
909
910    return <<<EOF
911<div class="position">Configuration</div>
912{$sErrors}
913<div class="LeftRirght">
914    <div class="clearBoth"></div>
915    <div class="left"></div>
916    <div class="right">
917        <form action="{$sCurPage}" method="post">
918            <table cellpadding="0" cellspacing="1" width="100%" border="0" style="background-color:silver;">
919                <tr class="head">
920                    <td>&nbsp;</td>
921                    <td>&nbsp;</td>
922                </tr>
923                {$sSGParamsTable}
924            </table>
925            <div class="formKeeper">
926                <input id="button" type="image" src="images/next.gif" />
927                <input type="hidden" name="action" value="step4" />
928                {$sOldDataParams}
929            </div>
930        </form>
931    </div>
932    <div class="clearBoth"></div>
933</div>
934EOF;
935}
936
937// check of config pages steps
938function checkConfigArray($aCheckedArray, &$sError) {
939    //$error_arr //It is like global variable
940    //$config_arr //It is like global variable, but non used
941
942    $sErrorMessage = '';
943
944    foreach ($aCheckedArray as $sKey => $sValue) {
945        if (! strlen($sValue['check'])) continue;
946
947        $funcbody = $sValue['check'];
948        $func = create_function('$arg0', $funcbody);
949
950        if (! $func($_POST[$sKey])) {
951            $sFieldErr = $sValue['name'];
952            $sErrorMessage .= "Please, input valid data to <b>{$sFieldErr}</b> field<br />";
953            $error_arr[$sKey] = 1;
954            unset($_POST[$sKey]);
955        } else
956            $error_arr[$sKey] = 0;
957
958        //$config_arr[$sKey]['def'] = $_POST[$sKey];
959    }
960
961    if (strlen($sErrorMessage)) {
962        $sError = 'error';
963    }
964
965    return $sErrorMessage;
966}
967
968function genDatabaseConfig($sErrorMessage = '') {
969    global $aDbConf;
970
971    $sCurPage = $_SERVER['PHP_SELF'];
972    $sDbParamsTable = createTable($aDbConf);
973
974    $sErrors = '';
975    if (strlen($sErrorMessage)) {
976        $sErrors = printInstallError($sErrorMessage);
977        unset($_POST['db_name']);
978        unset($_POST['db_user']);
979        unset($_POST['db_password']);
980    }
981
982    $sOldDataParams = '';
983    foreach($_POST as $postKey => $postValue) {
984        $sOldDataParams .= ('action' == $postKey || isset($aDbConf[$postKey])) ? '' : '<input type="hidden" name="' . $postKey . '" value="' . $postValue . '" />';
985    }
986
987    return <<<EOF
988<div class="position">Database</div>
989{$sErrors}
990<div class="LeftRirght">
991    <div class="clearBoth"></div>
992    <div class="left">
993        Please <a target="_blank" href="http://www.boonex.com/trac/dolphin/wiki/DetailedInstall#Part2:CreateaDatabaseandaUser">create a database</a> and tell Dolphin about it.
994    </div>
995    <div class="right">
996        <form action="{$sCurPage}" method="post">
997            <table cellpadding="0" cellspacing="1" width="100%" border="0" style="background-color:silver;">
998                <tr class="head">
999                    <td>&nbsp;</td>
1000                    <td>&nbsp;</td>
1001                </tr>
1002                {$sDbParamsTable}
1003            </table>
1004            <div class="formKeeper">
1005                <input id="button" type="image" src="images/next.gif" />
1006                <input type="hidden" name="action" value="step3" />
1007                {$sOldDataParams}
1008            </div>
1009        </form>
1010    </div>
1011    <div class="clearBoth"></div>
1012</div>
1013EOF;
1014}
1015
1016function genPathCheckingConfig($sErrorMessage = '') {
1017    global  $aConf, $confFirst;
1018
1019    $sCurPage = $_SERVER['PHP_SELF'];
1020
1021    $sGDRes = (extension_loaded('gd')) ? '<span class="writable">GD library installed</span>'
1022        : '<span class="unwritable">GD library NOT installed</span>';
1023
1024    $sError = printInstallError( $sErrorMessage );
1025    $sPathsTable = createTable($confFirst);
1026
1027    return <<<EOF
1028<div class="position">Paths Check</div>
1029{$sError}
1030<div class="LeftRirght">
1031    <div class="clearBoth"></div>
1032    <div class="left">
1033        Dolphin checks general script paths.
1034    </div>
1035    <div class="right">
1036        <form action="{$sCurPage}" method="post">
1037            <table cellpadding="0" cellspacing="1" width="100%" border="0" style="background-color:silver;">
1038                <tr class="head">
1039                    <td>&nbsp;</td>
1040                    <td>&nbsp;</td>
1041                </tr>
1042                {$sPathsTable}
1043                <tr class="cont" style="background-color:#ede9e9;">
1044                    <td>
1045                        Check GD Installed
1046                    </td>
1047                    <td>
1048                        {$sGDRes}
1049                    </td>
1050                </tr>
1051            </table>
1052            <div class="formKeeper">
1053                <input id="button" type="image" src="images/next.gif" />
1054                <input type="hidden" name="action" value="step2" />
1055            </div>
1056        </form>
1057    </div>
1058    <div class="clearBoth"></div>
1059</div>
1060EOF;
1061}
1062
1063function checkPreInstallPermission(&$sError) {
1064    global $aTemporalityWritableFolders;
1065
1066    $sFoldersErr = $sFilesErr = $sErrorMessage = '';
1067
1068    $oBxDolIO = new BxDolIO();
1069
1070    require_once('../studio/classes/BxDolStudioTools.php');
1071    $oAdmTools = new BxDolAdminTools();
1072
1073    $aInstallDirsMerged = array_merge($aTemporalityWritableFolders, $oAdmTools->aInstallDirs);
1074    foreach ($aInstallDirsMerged as $sFolder) {
1075        if (! $oBxDolIO->isWritable($sFolder)) {
1076            $sFoldersErr .= '&nbsp;&nbsp;&nbsp;' . $sFolder . ';<br />';
1077        }
1078    }
1079
1080    foreach ($oAdmTools->aFlashDirs as $sFolder) {
1081        if (! $oBxDolIO->isWritable($sFolder)) {
1082            $sFoldersErr .= '&nbsp;&nbsp;&nbsp;' . $sFolder . ';<br />';
1083        }
1084    }
1085
1086    if( strlen( $sFoldersErr ) ) {
1087        $sError = 'error';
1088        $sErrorMessage .= '<strong>Next directories have inappropriate permissions</strong>:<br />' . $sFoldersErr;
1089    }
1090
1091    foreach ($oAdmTools->aInstallFiles as $sFile) {
1092        if (! $oBxDolIO->isWritable($sFile)) {
1093            $sFilesErr .= '&nbsp;&nbsp;&nbsp;' . $sFile . ';<br /> ';
1094        }
1095    }
1096
1097    foreach( $oAdmTools->aFlashFiles as $sFile ) {
1098        if (strpos($sFile,'ffmpeg') === false) {
1099            if (! $oBxDolIO->isWritable($sFile)) {
1100                $sFilesErr .= '&nbsp;&nbsp;&nbsp;' . $sFile . ';<br /> ';
1101            }
1102        } else {
1103            if (! $oBxDolIO->isExecutable($sFile)) {
1104                $sFilesErr .= '&nbsp;&nbsp;&nbsp;' . $sFile . ';<br /> ';
1105            }
1106        }
1107    }
1108
1109    if (strlen($sFilesErr)) {
1110        $sError = 'error';
1111        $sErrorMessage .= '<strong>Next files have inappropriate permissions</strong>:<br />' . $sFilesErr;
1112    }
1113
1114    return $sErrorMessage;
1115}
1116
1117// pre install
1118function genPreInstallPermissionTable($sErrorMessage = '') {
1119    global $aTemporalityWritableFolders;
1120
1121    $sCurPage = $_SERVER['PHP_SELF'];
1122    $sErrorMessage .= (ini_get('safe_mode') == 1 || ini_get('safe_mode') == 'On') ? "Please turn off <b>safe_mode</b> in your php.ini file configuration" : '';
1123    $sError = printInstallError($sErrorMessage);
1124
1125    require_once('../studio/classes/BxDolStudioTools.php');
1126    $oAdmTools = new BxDolAdminTools();
1127    $oAdmTools->aInstallDirs = array_merge($aTemporalityWritableFolders, $oAdmTools->aInstallDirs);
1128    $sPermTable = $oAdmTools->GenCommonCode();
1129    $sPermTable .= $oAdmTools->GenPermTable();
1130
1131    return <<<EOF
1132<div class="position">Permissions</div>
1133{$sError}
1134<div class="LeftRirght">
1135    <div class="clearBoth"></div>
1136    <div class="left">
1137        Dolphin needs special access for certain files and directories. Please, change permissions as specified in the chart below. Helpful info about permissions is <a href="http://www.boonex.com/trac/dolphin/wiki/DetailedInstall#InstallScript-Step1-Permissions" target="_blank">available here</a>.
1138    </div>
1139    <div class="clear_both"></div>
1140    <div class="right">
1141        <script src="../plugins/jquery/jquery.js" type="text/javascript" language="javascript"></script>
1142        {$sPermTable}
1143        <div class="formKeeper">
1144            <div class="button_area_1">
1145                <form action="{$sCurPage}" method="post">
1146                    <input id="button" type="image" src="images/check.gif" />
1147                    <input type="hidden" name="action" value="preInstall" />
1148                </form>
1149            </div>
1150            <div class="button_area_2">
1151                <form action="{$sCurPage}" method="post">
1152                    <input id="button" type="image" src="images/next.gif" />
1153                    <input type="hidden" name="action" value="step1" />
1154                </form>
1155            </div>
1156            <div class="clearBoth"></div>
1157        </div>
1158    </div>
1159</div>
1160EOF;
1161}
1162
1163function StartInstall() {
1164    global $aConf;
1165
1166    return <<<EOF
1167<div class="install_pic">
1168    Dolphin {$aConf['iVersion']}.{$aConf['iPatch']}
1169</div>
1170
1171<div class="install_text">
1172    Thank you for choosing Dolphin Smart Community Builder!<br />
1173    Click the button below to create your own community.
1174</div>
1175
1176<div class="install_button">
1177    <form action="{$_SERVER['PHP_SELF']}" method="post">
1178    <input id="button" type="image" src="images/install.gif" />
1179    <input type="hidden" name="action" value="preInstall" />
1180    </form>
1181</div>
1182EOF;
1183}
1184
1185function genMainDolphinPage() {
1186    //TODO: Forward into Studio -> Store to install Language(s) or install default one automatically.
1187    //performInstallLanguages();
1188
1189    /**
1190     *  Register System Transcoders
1191     */
1192    $aTranscoders = array(
1193        BX_DOL_TRANSCODER_OBJ_ICON_APPLE,
1194        BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK,
1195        BX_DOL_TRANSCODER_OBJ_ICON_FAVICON
1196    );
1197
1198    bx_import('BxDolImageTranscoder');
1199    foreach($aTranscoders as $sTranscoder)
1200        BxDolImageTranscoder::getObjectInstance($sTranscoder)->registerHandlers();
1201
1202    /**
1203     * Perform admin login.
1204     */
1205    $sExistedAdminPass = db_value("SELECT `password` FROM `sys_accounts` WHERE `id`='1'");
1206
1207    $aUrl = parse_url($GLOBALS['site']['url']);
1208    $sPath = isset($aUrl['path']) && !empty($aUrl['path']) ? $aUrl['path'] : '/';
1209    $sHost = '';
1210
1211    $iCookieTime = 0;
1212    setcookie("memberID", 1, $iCookieTime, $sPath, $sHost);
1213    $_COOKIE['memberID'] = 1;
1214    setcookie("memberPassword", $sExistedAdminPass, $iCookieTime, $sPath, $sHost, false, true /* http only */);
1215    $_COOKIE['memberPassword'] = $sExistedAdminPass;
1216
1217    return <<<EOF
1218<script type="text/javascript">
1219    window.location = "../index.php";
1220</script>
1221EOF;
1222}
1223
1224function PageHeader($sAction = '', $sError = '') {
1225    global $aConf;
1226
1227    $aActions = array(
1228        "startInstall" => "Dolphin Installation",
1229        "preInstall" => "Permissions",
1230        "step1" => "Paths",
1231        "step2" => "Database",
1232        "step3" => "Config",
1233        "step4" => "Cron Jobs",
1234        "step5" => "Permissions Reversal",
1235        "step6" => "Modules"
1236    );
1237
1238    if( !strlen( $sAction ) )
1239        $sAction = "startInstall";
1240
1241    $sActiveStyle = ($sAction == "step6") ? 'Active' : 'Inactive';
1242
1243    $iCounterCurrent = 1;
1244    $iCounterActive     = 1;
1245
1246    foreach ($aActions as $sActionKey => $sActionValue) {
1247        if ($sAction != $sActionKey) {
1248            $iCounterActive++;
1249        } else
1250            break;
1251    }
1252
1253    if (strlen($sError))
1254        $iCounterActive--;
1255
1256    $sSubActions = '';
1257    foreach ($aActions as $sActionKey => $sActionValue) {
1258        if ($iCounterActive == $iCounterCurrent) {
1259            $sSubActions .= '<div id="topActive">' . $sActionValue . '</div>';
1260        } elseif (($iCounterActive - $iCounterCurrent) == -1) {
1261            $sSubActions .= '<img src="images/active_inactive.gif" /><div id="topInactive">' . $sActionValue . '</div><img src="images/inactive_inactive.gif" />';
1262        } elseif (($iCounterActive - $iCounterCurrent) == 1) {
1263            $sSubActions .= '<div id="topInactive">' . $sActionValue . '</div><img src="images/inactive_active.gif" />';
1264        } else {
1265            $sSubActions .= '<div id="topInactive">' . $sActionValue . '</div>';
1266            if ($sActionKey != "step6")
1267                $sSubActions .= '<img src="images/inactive_inactive.gif" />';
1268        }
1269        $iCounterCurrent++;
1270    }
1271
1272    return <<<EOF
1273<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1274    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1275        <head>
1276            <title>Dolphin Smart Community Builder Installation Script</title>
1277            <link href="general.css" rel="stylesheet" type="text/css" />
1278            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1279            <script src="../inc/js/functions.js" type="text/javascript" language="javascript"></script>
1280            <!--[if lt IE 7.]>
1281            <script defer type="text/javascript" src="../inc/js/pngfix.js"></script>
1282            <![endif]-->
1283        </head>
1284        <body>
1285            <div id="main">
1286                <div id="topMenu{$sActiveStyle}">
1287                    {$sSubActions}
1288                </div>
1289            <div id="header">
1290                <img src="images/boonex-logo.png" alt="" /></div>
1291            <div id="content">
1292EOF;
1293}
1294
1295function PageFooter($sAction) {
1296    $sAdminAdd = ($sAction) ? '<div id="footer"><img src="images/dolphin_transparent.jpg" alt="" /></div>' : '';
1297
1298    return <<<EOF
1299            </div>
1300        {$sAdminAdd}
1301        </div>
1302    </body>
1303</html>
1304EOF;
1305}
1306
1307function printInstallError($sText) {
1308    $sRet = (strlen($sText)) ? '<div class="error">' . $sText . '</div>' : '';
1309    return $sRet;
1310}
1311
1312function createTable($arr) {
1313    $ret = '';
1314    $i = '';
1315    foreach($arr as $key => $value) {
1316        $sStyleAdd = (($i%2) == 0) ? 'background-color:#ede9e9;' : 'background-color:#fff;';
1317
1318        $def_exp_text = "";
1319        if (strlen($value['def_exp'])) {
1320            $funcbody = $value['def_exp'];
1321            $func = create_function("", $funcbody);
1322            $def_exp = $func();
1323            if (strlen($def_exp)) {
1324                $def_exp_text = "&nbsp;<font color=green>found</font>";
1325                $value['def'] = $def_exp;
1326            } else {
1327                $def_exp_text = "&nbsp;<font color=red>not found</font>";
1328            }
1329        }
1330
1331        $st_err = ($error_arr[$key] == 1) ? ' style="background-color:#FFDDDD;" ' : '';
1332
1333        $ret .= <<<EOF
1334    <tr class="cont" style="{$sStyleAdd}">
1335        <td>
1336            <div>{$value['name']}</div>
1337            <div>Description:</div>
1338            <div>Example:</div>
1339        </td>
1340        <td>
1341            <div><input {$st_err} size="30" name="{$key}" value="{$value['def']}" /> {$def_exp_text}</div>
1342            <div>{$value['desc']}</div>
1343            <div style="font-style:italic;">{$value['ex']}</div>
1344        </td>
1345    </tr>
1346EOF;
1347        $i ++;
1348    }
1349
1350    return $ret;
1351}
1352
1353function rewriteFile($sCode, $sReplace, $sFile) {
1354    $ret = '';
1355    $fs = filesize($sFile);
1356    $fp = fopen($sFile, 'r');
1357    if ($fp) {
1358        $fcontent = fread($fp, $fs);
1359        $fcontent = str_replace($sCode, $sReplace, $fcontent);
1360        fclose($fp);
1361        $fp = fopen($sFile, 'w');
1362        if ($fp) {
1363            if (fputs($fp, $fcontent)) {
1364                $ret .= true;
1365            } else {
1366                $ret .= false;
1367            }
1368            fclose ( $fp );
1369        } else {
1370            $ret .= false;
1371        }
1372    } else {
1373        $ret .= false;
1374    }
1375    return $ret;
1376}
1377
1378function RunSQL($sAdminName, $sAdminPassword) {
1379    $aDbConf['host']   = $_POST['db_host'];
1380    $aDbConf['sock']   = $_POST['db_sock'];
1381    $aDbConf['port']   = $_POST['db_port'];
1382    $aDbConf['user']   = $_POST['db_user'];
1383    $aDbConf['passwd'] = $_POST['db_password'];
1384    $aDbConf['db']     = $_POST['db_name'];
1385
1386    $aDbConf['host'] .= ( $aDbConf['port'] ? ":{$aDbConf['port']}" : '' ) . ( $aDbConf['sock'] ? ":{$aDbConf['sock']}" : '' );
1387
1388    $pass = true;
1389    $errorMes = '';
1390    $filename = $_POST['sql_file'];
1391
1392    $vLink = @mysql_connect($aDbConf['host'], $aDbConf['user'], $aDbConf['passwd']);
1393
1394    if( !$vLink )
1395        return printInstallError( mysql_error() );
1396
1397    if (!mysql_select_db ($aDbConf['db'], $vLink))
1398        return printInstallError( $aDbConf['db'] . ': ' . mysql_error() );
1399
1400    mysql_query ("SET sql_mode = ''", $vLink);
1401
1402    if (! ($f = fopen ( $filename, "r" )))
1403        return printInstallError( 'Could not open file with sql instructions:' . $filename  );
1404
1405    //Begin SQL script executing
1406    $s_sql = "";
1407    while ($s = fgets ( $f, 10240)) {
1408        $s = trim( $s ); //Utf with BOM only
1409
1410        if (! strlen($s)) continue;
1411        if (mb_substr($s, 0, 1) == '#') continue; //pass comments
1412        if (mb_substr($s, 0, 2) == '--') continue;
1413        if (substr($s, 0, 5) == "\xEF\xBB\xBF\x2D\x2D") continue;
1414
1415        $s_sql .= $s;
1416
1417        if (mb_substr($s, -1) != ';') continue;
1418
1419        $res = mysql_query($s_sql, $vLink);
1420        if (!$res)
1421            $errorMes .= 'Error while executing: ' . $s_sql . '<br />' . mysql_error($vLink) . '<hr />';
1422
1423        $s_sql = '';
1424    }
1425
1426    fclose($f);
1427
1428    $sAdminNameDB = DbEscape($sAdminName, false);
1429    $sSiteEmail = DbEscape($_POST['site_email']);
1430    $sSaltDB = base64_encode(substr(md5(microtime()), 2, 6));
1431    $sAdminPasswordDB = sha1(md5($sAdminPassword) . $sSaltDB); // encryptUserPwd
1432    $sAdminQuery = "
1433        INSERT INTO `sys_accounts`
1434            (`name`, `email`, `email_confirmed`, `receive_updates`, `receive_news`, `password`, `salt`, `role`, `added`)
1435        VALUES
1436            ('{$sAdminNameDB}', '{$sSiteEmail}', 1, 1, 1, '{$sAdminPasswordDB}', '{$sSaltDB}', 3, '" . time() . "')
1437    ";
1438    if (!mysql_query($sAdminQuery, $vLink)) {
1439
1440        $errorMes .= 'Error while executing: ' . $sAdminQuery . '<br />' . mysql_error($vLink) . '<hr />';
1441
1442    } else {
1443
1444        $iAccontId = mysql_insert_id($vLink);
1445        $sAdminQuery = "
1446            INSERT INTO `sys_profiles`
1447                (`account_id`, `type`, `content_id`, `status`)
1448            VALUES
1449                ($iAccontId, 'system', $iAccontId, 'active')
1450        ";
1451        if (!mysql_query($sAdminQuery, $vLink))
1452            $errorMes .= 'Error while executing: ' . $sAdminQuery . '<br />' . mysql_error($vLink) . '<hr />';
1453    }
1454       
1455
1456    $enable_gd_value = extension_loaded('gd') ? 'on' : '';
1457    if (!(mysql_query ("UPDATE `sys_options` SET `VALUE`='{$enable_gd_value}' WHERE `Name`='enable_gd'", $vLink)))
1458        $ret .= "<font color=red><i><b>Error</b>:</i> " . mysql_error($vLink) . "</font><hr>";
1459
1460    $sSiteTitle = DbEscape($_POST['site_title']);
1461    $sSiteDesc = DbEscape($_POST['site_desc']);
1462    $sSiteEmailNotify = DbEscape($_POST['notify_email']);
1463    $sSiteEmailBugReport = DbEscape($_POST['bug_report_email']);
1464    if ($sSiteEmail != '' && $sSiteTitle != '' && $sSiteEmailNotify != '') {
1465        if (! (mysql_query("UPDATE `sys_options` SET `VALUE`='{$sSiteEmail}' WHERE `Name`='site_email'", $vLink)))
1466            $ret .= "<font color=red><i><b>Error</b>:</i> ".mysql_error($vLink)."</font><hr>";
1467        if (! (mysql_query("UPDATE `sys_options` SET `VALUE`='{$sSiteTitle}' WHERE `Name`='site_title'", $vLink)))
1468            $ret .= "<font color=red><i><b>Error</b>:</i> ".mysql_error($vLink)."</font><hr>";
1469        if (! (mysql_query("UPDATE `sys_options` SET `VALUE`='{$sSiteEmailNotify}' WHERE `Name`='site_email_notify'", $vLink)))
1470            $ret .= "<font color=red><i><b>Error</b>:</i> ".mysql_error($vLink)."</font><hr>";
1471        if (! (mysql_query("UPDATE `sys_options` SET `VALUE`='{$sSiteEmailBugReport}' WHERE `Name`='site_email_bug_report'", $vLink)))
1472            $ret .= "<font color=red><i><b>Error</b>:</i> ".mysql_error($vLink)."</font><hr>";
1473        if (! (mysql_query("UPDATE `sys_options` SET `VALUE`='{$sSiteDesc}' WHERE `Name`='MetaDescription'", $vLink)))
1474            $ret .= "<font color=red><i><b>Error</b>:</i> ".mysql_error($vLink)."</font><hr>";
1475    } else {
1476        $ret .= "<font color=red><i><b>Error</b>:</i> Don`t received POSTed site_email or site_title or site_email_notify</font><hr>";
1477    }
1478
1479    mysql_close($vLink);
1480
1481    $errorMes .= $ret;
1482
1483    if (strlen($errorMes)) {
1484        return printInstallError($errorMes);
1485    } else {
1486        return 'done';
1487    }
1488//    return $ret."Truncating tables finished.<br>";
1489}
1490
1491function DbEscape($s, $isDetectMagixQuotes = true) {
1492    if (get_magic_quotes_gpc() && $isDetectMagixQuotes)
1493        $s = stripslashes ($s);
1494    return mysql_real_escape_string($s);
1495}
1496
1497function CheckSQLParams() {
1498    $aDbConf['host']   = $_POST['db_host'];
1499    $aDbConf['sock']   = $_POST['db_sock'];
1500    $aDbConf['port']   = $_POST['db_port'];
1501    $aDbConf['user']   = $_POST['db_user'];
1502    $aDbConf['passwd'] = $_POST['db_password'];
1503    $aDbConf['db']     = $_POST['db_name'];
1504
1505    $aDbConf['host'] .= ( $aDbConf['port'] ? ":{$aDbConf['port']}" : '' ) . ( $aDbConf['sock'] ? ":{$aDbConf['sock']}" : '' );
1506
1507    $vLink = @mysql_connect($aDbConf['host'], $aDbConf['user'], $aDbConf['passwd']);
1508
1509    if (!$vLink)
1510        return printInstallError(mysql_error());
1511
1512    if (!mysql_select_db ($aDbConf['db'], $vLink))
1513        return printInstallError($aDbConf['db'] . ': ' . mysql_error());
1514
1515    mysql_close($vLink);
1516}
1517
1518// set error reporting level
1519if (version_compare(phpversion(), "5.3.0", ">=") == 1)
1520  error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
1521else
1522  error_reporting(E_ALL & ~E_NOTICE);
1523
1524?>
Note: See TracBrowser for help on using the repository browser.