Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cCLISetup
  • cSetupLanguageChooser
  • cSetupNotInstallable
  • cSetupTypeChooser

Functions

  • checkAndInclude
  • checkExistingPlugin
  • checkInstallationSettings
  • findSimilarText
  • getArgs
  • getContenidoVersion
  • getSystemDirectories
  • initializeVariables
  • listClients
  • passwordPrompt
  • printHelpText
  • prnt
  • prntln
  • prntst
  • progressBar
  • stripLastSlash
  • updateClientPath
  • updateContenidoVersion
  • updateSysadminPassword
  • updateSystemProperties
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * Several functions to help the cli setup of CONTENIDO
  4:  *
  5:  * @package Setup
  6:  * @subpackage Setup
  7:  * @author Mischa Holz
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 14: 
 15: /**
 16:  * Prints some text to the console
 17:  *
 18:  * @param string $str string which should be printed
 19:  * @param int $tab number of tab characters which should preceed the string
 20:  */
 21: function prnt($str = '', $tab = 0) {
 22:     for ($i = 0; $i < $tab; $i++) {
 23:         echo("\t");
 24:     }
 25:     echo($str);
 26: }
 27: 
 28: /**
 29:  * Prints some text and a new line to the console
 30:  *
 31:  * @param string $str string which should be printed
 32:  * @param int $tab number of tab characters which should preceed the string
 33:  */
 34: function prntln($str = '', $tab = 0) {
 35:     prnt($str . "\n\r", $tab);
 36: }
 37: 
 38: /**
 39:  * Prints some text to the console and jumps back to the beginning of the line
 40:  *
 41:  * @param string $str string which should be printed
 42:  */
 43: function prntst($str = '') {
 44:     echo($str . "\r");
 45: }
 46: 
 47: /**
 48:  * Ask the user for a password and erase it if he is done entering it.
 49:  * Since the Windows console does not understand ANSI sequences the
 50:  * function will print a warning for the user instead.
 51:  *
 52:  * @param string $title label text
 53:  * @param int $tab number of tabs which should preceed the label text
 54:  * @return string user entered password
 55:  */
 56: function passwordPrompt($title, $tab = 0) {
 57:     if (cString::toUpperCase(cString::getPartOfString(PHP_OS, 0, 3)) === 'WIN') {
 58:         prntln(i18n('Be careful! The password will be readable in the console window!', 'setup'), $tab);
 59:     }
 60:     prnt($title . ': ', $tab);
 61:     $line = trim(fgets(STDIN));
 62:     if (!(cString::toUpperCase(cString::getPartOfString(PHP_OS, 0, 3)) === 'WIN')) {
 63:         echo("\033[1A"); // move the cursor up one line
 64:         prnt($title . ': ', $tab); // reprint the label
 65:         for ($i = 0; $i < cString::getStringLength($line); $i++) {
 66:             echo("*"); // replace the password with asterisks
 67:         }
 68:         echo("\r\n");
 69:     }
 70:     return $line;
 71: }
 72: 
 73: /**
 74:  * Prints a progress bar to the console
 75:  *
 76:  * @param int $width Widht of the progress bar in characters
 77:  * @param int $filled Percent value to which it should be filled (e.g. 45)
 78:  */
 79: function progressBar($width, $filled) {
 80:     echo("\r");
 81:     echo("|");
 82:     $i = 0;
 83:     for ($i = 0; $i <= $filled / 100 * $width; $i++) {
 84:         echo("#");
 85:     }
 86:     for ($j = $i; $j <= $width; $j++) {
 87:         echo(" ");
 88:     }
 89:     echo("| ");
 90:     prnt(round($filled) . "%");
 91: }
 92: 
 93: /**
 94:  * Initializes the globals the CONTENIDO setup needs
 95:  */
 96: function initializeVariables() {
 97:     global $cfg, $_SESSION;
 98: 
 99:     $cfg['db'] = array(
100:         'connection' => array(
101:             'host'     => '',
102:             'user'     => '',
103:             'password' => '',
104:             'charset'  => '',
105:             'database' => ''
106:         ),
107:         'haltBehavior'    => 'report',
108:         'haltMsgPrefix'   => (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] . ' ' : '',
109:         'enableProfiling' => false
110:     );
111:     $_SESSION['setuptype'] = 'setup';
112:     $_SESSION['dbname'] = '';
113:     $_SESSION['configmode'] = 'save';
114:     $_SESSION["override_root_http_path"] = '';
115:     $_SESSION['clientmode'] = '';
116:     $_SESSION['adminpass'] = '';
117:     $_SESSION['adminmail'] = '';
118:     $_SESSION['dbprefix'] = '';
119: }
120: 
121: /**
122:  * Checks to see if all the installation settings are valid and have been entered
123:  *
124:  * @return boolean true if every setting has been entered
125:  */
126: function checkInstallationSettings() {
127:     global $cfg, $_SESSION;
128: 
129:     $fine = true;
130: 
131:     if ($cfg['db']['connection']['host'] == '') {
132:         prntln(i18n('You did not specify a database host!', 'setup'));
133:         $fine = false;
134:     }
135:     if ($cfg['db']['connection']['user'] == '') {
136:         prntln(i18n('You did not specify a database user!', 'setup'));
137:         $fine = false;
138:     }
139:     if ($cfg['db']['connection']['password'] == '') {
140:         prntln(i18n('You did not specify a database password!', 'setup'));
141:         $fine = false;
142:     }
143:     if ($cfg['db']['connection']['charset'] == '') {
144:         prntln(i18n('You did not specify a database charset!', 'setup'));
145:         $fine = false;
146:     }
147:     if ($_SESSION['dbcollation'] == '') {
148:         prntln(i18n('You did not specify a database collation!', 'setup'));
149:         $fine = false;
150:     }
151:     if ($cfg['db']['connection']['database'] == '') {
152:         prntln(i18n('You did not specify a database name!', 'setup'));
153:         $fine = false;
154:     }
155:     if ($_SESSION['dbprefix'] == '') {
156:         prntln(i18n('You did not specify a database prefix!', 'setup'));
157:         $fine = false;
158:     }
159: 
160:     // append a slash to the http path if it isn't there already
161:     if (!(cString::getPartOfString($_SESSION['override_root_http_path'], -cString::getStringLength("/")) === "/")) {
162:         $_SESSION['override_root_http_path'] = $_SESSION['override_root_http_path'] . "/";
163:     }
164:     if ($_SESSION['override_root_http_path'] == '') {
165:         prntln(i18n('You did not specify an http root path!', 'setup'));
166:         $fine = false;
167:     }
168:     if ($_SESSION['clientmode'] == '') {
169:         prntln(i18n('You did not specify if you want to install the example client or not!', 'setup'));
170:         $fine = false;
171:     }
172:     if (!($_SESSION['clientmode'] == "CLIENTEXAMPLES" || $_SESSION['clientmode'] == "CLIENTMODULES" || $_SESSION['clientmode'] == "NOCLIENT")) {
173:         prntln(i18n('You did not specify if you want to install the example client or not!', 'setup'));
174:         $fine = false;
175:     }
176:     if ($_SESSION['adminpass'] == '') {
177:         prntln(i18n('You did not specify an admin password!', 'setup'));
178:         $fine = false;
179:     }
180:     if ($_SESSION['adminmail'] == '') {
181:         prntln(i18n('You did not specify an admin email!', 'setup'));
182:         $fine = false;
183:     }
184: 
185:     return $fine;
186: }
187: 
188: /**
189:  * Converts unix-style CLI arguments into an array
190:  *
191:  * @return array An array representing the arguments and switches provided to the script
192:  */
193: function getArgs() {
194:     $args = $_SERVER['argv'];
195: 
196:     $out = array();
197:     $last_arg = null;
198: 
199:     for ($i = 1, $il = sizeof($args); $i < $il; $i++) {
200:         if (preg_match("/^--(.+)/", $args[$i], $match)) {
201:             $parts = explode("=", $match[1]);
202:             $key = preg_replace("/[^a-z0-9]+/", "", $parts[0]);
203: 
204:             if (isset($parts[1])) {
205:                 $out[$key] = $parts[1];
206:             } else {
207:                 $out[$key] = true;
208:             }
209:             $last_arg = $key;
210:         } else if (preg_match("/^-([a-zA-Z0-9]+)/", $args[$i], $match)) {
211:             for ($j = 0, $jl = cString::getStringLength($match[1]); $j < $jl; $j++) {
212:                 $key = $match[1]{$j};
213:                 $out[$key] = true;
214:             }
215:             $last_arg = $key;
216:         } else if ($last_arg !== null) {
217:             $out[$last_arg] = $args[$i];
218:         }
219:     }
220:     return $out;
221: }
222: 
223: /**
224:  * Prints the help text
225:  */
226: function printHelpText() {
227:     prntln("\r" . i18n('CONTENIDO setup script', 'setup'));
228:     prntln(i18n('This script will install CONTENIDO to your computer', 'setup'));
229:     prntln();
230:     prntln(i18n("CONTENIDO can be installed using the interactive mode or a non-interactive mode.", 'setup'));
231:     prntln(i18n("If the script is executed without any parameters it will look for the\nautoinstall.ini file (or any other file specified with \"--file\").", 'setup'));
232:     prntln(i18n("If that file is present, the non-interactive mode will be used. The script will\nask for user input in the case of errors though.\nIf you want to prevent the script from ever waiting for user input use\n\"--non-interactive\".", 'setup'));
233:     prntln(i18n("In case the ini file can not be found, the script will wait for user input\non all relevant information.", 'setup'));
234:     prntln();
235:     prntln('--interactive, -i');
236:     prntln(i18n("Forces the script to be interactive and wait for user input even if the\n\tautoinstall.ini file is present.", 'setup'), 1);
237:     prntln('--non-interactive');
238:     prntln(i18n("Will prevent all waiting for user input. The script will abort\n\tin case of any errors", 'setup'), 1);
239:     prntln('--file [' . i18n('file', 'setup') . ']');
240:     prntln(i18n('Use [file] instead of the default autoinstall.ini.', 'setup'), 1);
241:     prntln('--locale [' . i18n('language code', 'setup') . ']');
242:     prntln(i18n("Provide a country and language code to use. Defaults to \"en_US\"", 'setup'), 1);
243:     prntln('--help, -h');
244:     prntln(i18n('Prints this help text', 'setup'), 1);
245:     prntln();
246:     prntln(i18n("Furthermore, you can use parameters to overwrite setup settings.\nUse \"--[ini-group].[ini-name]=\"value\" (e.g. --db.host=\"localhost\")", 'setup'));
247:     prntln();
248:     prntln('CONTENIDO version ' . CON_SETUP_VERSION);
249: }
250: 
251: ?>
252: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0