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:  * This file contains various functions for the setup process.
  4:  *
  5:  * @package    Setup
  6:  * @subpackage Setup
  7:  * @author     Unknown
  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: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Checks if a plugin is already installed
 18:  * @param   cDb  $db
 19:  * @param   string  $sPluginname
 20:  * @return  bool
 21:  */
 22: function checkExistingPlugin($db, $sPluginname) {
 23:     global $cfg;
 24: 
 25:     #new install: all plugins are checked
 26:     if ($_SESSION["setuptype"] == "setup") {
 27:         return true;
 28:     }
 29: 
 30:     $sPluginname = (string) $sPluginname;
 31:     $sTable = $cfg['tab']['nav_sub'];
 32: 
 33:     switch ($sPluginname) {
 34:         case 'plugin_cronjob_overview':
 35:             $sSql = "SELECT * FROM %s WHERE idnavs=950";
 36:             break;
 37:         case 'plugin_conman':
 38:             $sSql = "SELECT * FROM %s WHERE idnavs=900";
 39:             break;
 40:         case 'plugin_content_allocation':
 41:             $sSql = "SELECT * FROM %s WHERE idnavs=800";
 42:             break;
 43:         case 'plugin_newsletter':
 44:             $sSql = "SELECT * FROM %s WHERE idnavs=610";
 45:             break;
 46:         case 'plugin_mod_rewrite':
 47:             $sSql = "SELECT * FROM %s WHERE idnavs=700 OR location='mod_rewrite/xml/;navigation/content/mod_rewrite'";
 48:             break;
 49:         default:
 50:             $sSql = '';
 51:             break;
 52:     }
 53: 
 54:     if ($sSql) {
 55:         $db->query($sSql, $sTable);
 56:         if ($db->nextRecord()) {
 57:             return true;
 58:         }
 59:     }
 60: 
 61:     return false;
 62: }
 63: 
 64: /**
 65:  * Updates system properties
 66:  * @param  cDb $db
 67:  * @param  string  $table  DB table name
 68:  */
 69: function updateSystemProperties($db, $table) {
 70:     $table = $db->escape($table);
 71: 
 72:     $aStandardvalues = array(
 73:         array('type' => 'pw_request', 'name' => 'enable', 'value' => 'true'),
 74:         array('type' => 'system', 'name' => 'mail_transport', 'value' => 'smtp'),
 75:         array('type' => 'system', 'name' => 'mail_sender_name', 'value' => 'CONTENIDO Backend'),
 76:         array('type' => 'system', 'name' => 'mail_sender', 'value' => 'info@contenido.org'),
 77:         array('type' => 'system', 'name' => 'mail_host', 'value' => 'localhost'),
 78:         array('type' => 'maintenance', 'name' => 'mode', 'value' => 'disabled'),
 79:         array('type' => 'codemirror', 'name' => 'activated', 'value' => 'true'),
 80:         array('type' => 'update', 'name' => 'check', 'value' => 'false'),
 81:         array('type' => 'update', 'name' => 'news_feed', 'value' => 'false'),
 82:         array('type' => 'update', 'name' => 'check_period', 'value' => '60'),
 83:         array('type' => 'system', 'name' => 'clickmenu', 'value' => 'false'),
 84:         array('type' => 'versioning', 'name' => 'activated', 'value' => 'true'),
 85:         array('type' => 'versioning', 'name' => 'prune_limit', 'value' => ''),
 86:         array('type' => 'versioning', 'name' => 'path', 'value' => ''),
 87:         array('type' => 'system', 'name' => 'insite_editing_activated', 'value' => 'true'),
 88:         array('type' => 'backend', 'name' => 'backend_label', 'value' => ''),
 89:         array('type' => 'generator', 'name' => 'xhtml', 'value' => 'true'),
 90:         array('type' => 'generator', 'name' => 'basehref', 'value' => 'true'),
 91:         array('type' => 'debug', 'name' => 'module_translation_message', 'value' => 'true'),
 92:         array('type' => 'debug', 'name' => 'debug_for_plugins', 'value' => 'true'),
 93:         array('type' => 'stats', 'name' => 'tracking', 'value' => 'disabled')
 94:     );
 95: 
 96:     foreach ($aStandardvalues as $aData) {
 97:         $sql = "SELECT `value` FROM `%s` WHERE `type` = '%s' AND `name` = '%s'";
 98:         $db->query(sprintf($sql, $table, $aData['type'], $aData['name']));
 99:         if ($db->nextRecord()) {
100:             $sValue = $db->f('value');
101:             if ($sValue == '') {
102:                 $sql = "UPDATE `%s` SET `value` = '%s' WHERE `type` = '%s' AND `name` = '%s'";
103:                 $sql = sprintf($sql, $table, $aData['value'], $aData['type'], $aData['name']);
104:                 $db->query($sql);
105:             }
106:         } else {
107:             $sql = "INSERT INTO `%s` SET `type` = '%s', `name` = '%s', `value` = '%s'";
108:             $sql = sprintf($sql, $table, $aData['type'], $aData['name'], $aData['value']);
109:             $db->query($sql);
110:         }
111: 
112:         if ($db->getErrorNumber() != 0) {
113:             logSetupFailure("Unable to execute SQL statement:\n" . $sql . "\nMysql Error: " . $db->getErrorMessage() . " (" . $db->getErrorNumber() . ")");
114:         }
115:     }
116: }
117: 
118: /**
119:  * Updates contenido version in given table
120:  * @param  cDb $db
121:  * @param  string  $table  DB table name
122:  * @param  string  $version  Version
123:  */
124: function updateContenidoVersion($db, $table, $version) {
125:     $sql = "SELECT `idsystemprop` FROM `%s` WHERE `type` = 'system' AND `name` = 'version'";
126:     $db->query(sprintf($sql, $db->escape($table)));
127: 
128:     if ($db->nextRecord()) {
129:         $sql = "UPDATE `%s` SET `value` = '%s' WHERE `type` = 'system' AND `name` = 'version'";
130:         $db->query(sprintf($sql, $db->escape($table), $db->escape($version)));
131:     } else {
132:         //$id = $db->nextid($table);
133:         $sql = "INSERT INTO `%s` SET `type` = 'system', `name` = 'version', `value` = '%s'";
134:         $db->query(sprintf($sql, $db->escape($table), $db->escape($version)));
135:     }
136: }
137: 
138: /**
139:  * Returns current version
140:  * @param  cDb $db
141:  * @param  string  $table  DB table name
142:  * @return string
143:  */
144: function getContenidoVersion($db, $table) {
145:     $sql = "SELECT `value` FROM `%s` WHERE `type` = 'system' AND `name` = 'version'";
146:     $db->query(sprintf($sql, $db->escape($table)));
147: 
148:     if ($db->nextRecord()) {
149:         return $db->f("value");
150:     } else {
151:         return false;
152:     }
153: }
154: 
155: /**
156:  * Updates the system administrators password. 
157:  * 
158:  * @param $db
159:  * @param $table
160:  * @param $password
161:  * @param $mail
162:  *
163:  * @return bool
164:  */
165: function updateSysadminPassword($db, $table, $password, $mail) {
166:     $sql = "SELECT password FROM %s WHERE username='sysadmin'";
167:     $db->query(sprintf($sql, $db->escape($table)));
168: 
169:     if ($db->nextRecord()) {
170:         $sql = "UPDATE %s SET password='%s', email='%s' WHERE username='sysadmin'";
171:         $db->query(sprintf($sql, $db->escape($table), md5($password), $mail));
172:         return true;
173:     } else {
174: 
175:         return false;
176:     }
177: }
178: 
179: /**
180:  * Reads and returns the total list of system clients.
181:  * @param $db
182:  * @param $table
183:  *
184:  * @return array
185:  */
186: function listClients($db, $table) {
187:     global $cfgClient;
188: 
189:     $sql = "SELECT idclient, name FROM %s";
190: 
191:     $db->query(sprintf($sql, $db->escape($table)));
192: 
193:     $clients = array();
194: 
195:     while ($db->nextRecord()) {
196:         $frontendPath = $cfgClient[$db->f('idclient')]['path']['frontend'];
197:         $htmlPath = $cfgClient[$db->f('idclient')]['path']['htmlpath'];
198:         $clients[$db->f("idclient")] = array("name" => $db->f("name"), "frontendpath" => $frontendPath, "htmlpath" => $htmlPath);
199:     }
200: 
201:     return $clients;
202: }
203: 
204: /**
205:  * Updates the path information of a client and refreshs the configuration file.
206:  * @param $db
207:  * @param $table
208:  * @param $idclient
209:  * @param $frontendpath
210:  * @param $htmlpath
211:  */
212: function updateClientPath($db, $table, $idclient, $frontendpath, $htmlpath) {
213:     global $cfg, $cfgClient;
214:     checkAndInclude($cfg['path']['contenido'] . 'includes/functions.general.php');
215: 
216:     updateClientCache($idclient, $htmlpath, $frontendpath);
217: }
218: 
219: /**
220:  * Removes the trailing slash of a string.
221:  * @param $sInput
222:  *
223:  * @return string
224:  */
225: function stripLastSlash($sInput) {
226:     if (cString::getPartOfString($sInput, cString::getStringLength($sInput) - 1, 1) == "/") {
227:         $sInput = cString::getPartOfString($sInput, 0, cString::getStringLength($sInput) - 1);
228:     }
229: 
230:     return $sInput;
231: }
232: 
233: /**
234:  * Returns the paths to the system directory (filesystem and web).
235:  * @param bool $bOriginalPath
236:  *
237:  * @return array
238:  */
239: function getSystemDirectories($bOriginalPath = false) {
240:     $root_path = stripLastSlash(CON_FRONTEND_PATH);
241: 
242:     $root_http_path = dirname(dirname($_SERVER["REQUEST_URI"]));
243:     $root_http_path = str_replace("\\", "/", $root_http_path);
244: 
245:     $port = "";
246:     $protocol = "http://";
247: 
248:     if ($_SERVER["SERVER_PORT"] != 80) {
249:         if ($_SERVER["SERVER_PORT"] == 443) {
250:             $protocol = "https://";
251:         } else {
252:             $port = ":" . $_SERVER["SERVER_PORT"];
253:         }
254:     }
255: 
256:     $root_http_path = $protocol . $_SERVER["SERVER_NAME"] . $port . $root_http_path;
257: 
258:     if (cString::getPartOfString($root_http_path, cString::getStringLength($root_http_path) - 1, 1) == "/") {
259:         $root_http_path = cString::getPartOfString($root_http_path, 0, cString::getStringLength($root_http_path) - 1);
260:     }
261: 
262:     if ($bOriginalPath == true) {
263:         return array($root_path, $root_http_path);
264:     }
265: 
266:     if (isset($_SESSION["override_root_path"])) {
267:         $root_path = $_SESSION["override_root_path"];
268:     }
269: 
270:     if (isset($_SESSION["override_root_http_path"])) {
271:         $root_http_path = $_SESSION["override_root_http_path"];
272:     }
273: 
274:     $root_path = stripLastSlash($root_path);
275:     $root_http_path = stripLastSlash($root_http_path);
276: 
277:     return array($root_path, $root_http_path);
278: }
279: 
280: /**
281:  * Searchs for a string in a given text and returns the position of it.
282:  * @param $string1
283:  * @param $string2
284:  *
285:  * @return int
286:  */
287: function findSimilarText($string1, $string2) {
288:     for ($i = 0; $i < cString::getStringLength($string1); $i++) {
289:         if (cString::getPartOfString($string1, 0, $i) != cString::getPartOfString($string2, 0, $i)) {
290:             return $i - 1;
291:         }
292:     }
293: 
294:     return $i - 1;
295: }
296: 
297: ?>
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0