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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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_sender_name', 'value' => 'CONTENIDO Backend'),
 75:         array('type' => 'system', 'name' => 'mail_sender', 'value' => 'info@contenido.org'),
 76:         array('type' => 'system', 'name' => 'mail_host', 'value' => 'localhost'),
 77:         array('type' => 'maintenance', 'name' => 'mode', 'value' => 'disabled'),
 78:         array('type' => 'codemirror', 'name' => 'activated', 'value' => 'true'),
 79:         array('type' => 'update', 'name' => 'check', 'value' => 'false'),
 80:         array('type' => 'update', 'name' => 'news_feed', 'value' => 'false'),
 81:         array('type' => 'update', 'name' => 'check_period', 'value' => '60'),
 82:         array('type' => 'system', 'name' => 'clickmenu', 'value' => 'false'),
 83:         array('type' => 'versioning', 'name' => 'activated', 'value' => 'true'),
 84:         array('type' => 'versioning', 'name' => 'prune_limit', 'value' => ''),
 85:         array('type' => 'versioning', 'name' => 'path', 'value' => ''),
 86:         array('type' => 'system', 'name' => 'insite_editing_activated', 'value' => 'true'),
 87:         array('type' => 'backend', 'name' => 'backend_label', 'value' => ''),
 88:         array('type' => 'generator', 'name' => 'xhtml', 'value' => 'true'),
 89:         array('type' => 'generator', 'name' => 'basehref', 'value' => 'true'),
 90:         array('type' => 'debug', 'name' => 'module_translation_message', 'value' => 'true'),
 91:         array('type' => 'debug', 'name' => 'debug_for_plugins', 'value' => 'true')
 92:     );
 93: 
 94:     foreach ($aStandardvalues as $aData) {
 95:         $sql = "SELECT `value` FROM `%s` WHERE `type` = '%s' AND `name` = '%s'";
 96:         $db->query(sprintf($sql, $table, $aData['type'], $aData['name']));
 97:         if ($db->nextRecord()) {
 98:             $sValue = $db->f('value');
 99:             if ($sValue == '') {
100:                 $sql = "UPDATE `%s` SET `value` = '%s' WHERE `type` = '%s' AND `name` = '%s'";
101:                 $sql = sprintf($sql, $table, $aData['value'], $aData['type'], $aData['name']);
102:                 $db->query($sql);
103:             }
104:         } else {
105:             $sql = "INSERT INTO `%s` SET `type` = '%s', `name` = '%s', `value` = '%s'";
106:             $sql = sprintf($sql, $table, $aData['type'], $aData['name'], $aData['value']);
107:             $db->query($sql);
108:         }
109: 
110:         if ($db->getErrorNumber() != 0) {
111:             logSetupFailure("Unable to execute SQL statement:\n" . $sql . "\nMysql Error: " . $db->getErrorMessage() . " (" . $db->getErrorNumber() . ")");
112:         }
113:     }
114: }
115: 
116: /**
117:  * Updates contenido version in given table
118:  * @param  cDb $db
119:  * @param  string  $table  DB table name
120:  * @param  string  $version  Version
121:  */
122: function updateContenidoVersion($db, $table, $version) {
123:     $sql = "SELECT `idsystemprop` FROM `%s` WHERE `type` = 'system' AND `name` = 'version'";
124:     $db->query(sprintf($sql, $db->escape($table)));
125: 
126:     if ($db->nextRecord()) {
127:         $sql = "UPDATE `%s` SET `value` = '%s' WHERE `type` = 'system' AND `name` = 'version'";
128:         $db->query(sprintf($sql, $db->escape($table), $db->escape($version)));
129:     } else {
130:         //$id = $db->nextid($table);
131:         $sql = "INSERT INTO `%s` SET `type` = 'system', `name` = 'version', `value` = '%s'";
132:         $db->query(sprintf($sql, $db->escape($table), $db->escape($version)));
133:     }
134: }
135: 
136: /**
137:  * Returns current version
138:  * @param  cDb $db
139:  * @param  string  $table  DB table name
140:  * @return string
141:  */
142: function getContenidoVersion($db, $table) {
143:     $sql = "SELECT `value` FROM `%s` WHERE `type` = 'system' AND `name` = 'version'";
144:     $db->query(sprintf($sql, $db->escape($table)));
145: 
146:     if ($db->nextRecord()) {
147:         return $db->f("value");
148:     } else {
149:         return false;
150:     }
151: }
152: 
153: /**
154:  * Updates the system administrators password. 
155:  * 
156:  * @param $db
157:  * @param $table
158:  * @param $password
159:  * @param $mail
160:  *
161:  * @return bool
162:  */
163: function updateSysadminPassword($db, $table, $password, $mail) {
164:     $sql = "SELECT password FROM %s WHERE username='sysadmin'";
165:     $db->query(sprintf($sql, $db->escape($table)));
166: 
167:     if ($db->nextRecord()) {
168:         $sql = "UPDATE %s SET password='%s', email='%s' WHERE username='sysadmin'";
169:         $db->query(sprintf($sql, $db->escape($table), md5($password), $mail));
170:         return true;
171:     } else {
172: 
173:         return false;
174:     }
175: }
176: 
177: /**
178:  * Reads and returns the total list of system clients.
179:  * @param $db
180:  * @param $table
181:  *
182:  * @return array
183:  */
184: function listClients($db, $table) {
185:     global $cfgClient;
186: 
187:     $sql = "SELECT idclient, name FROM %s";
188: 
189:     $db->query(sprintf($sql, $db->escape($table)));
190: 
191:     $clients = array();
192: 
193:     while ($db->nextRecord()) {
194:         $frontendPath = $cfgClient[$db->f('idclient')]['path']['frontend'];
195:         $htmlPath = $cfgClient[$db->f('idclient')]['path']['htmlpath'];
196:         $clients[$db->f("idclient")] = array("name" => $db->f("name"), "frontendpath" => $frontendPath, "htmlpath" => $htmlPath);
197:     }
198: 
199:     return $clients;
200: }
201: 
202: /**
203:  * Updates the path information of a client and refreshs the configuration file.
204:  * @param $db
205:  * @param $table
206:  * @param $idclient
207:  * @param $frontendpath
208:  * @param $htmlpath
209:  */
210: function updateClientPath($db, $table, $idclient, $frontendpath, $htmlpath) {
211:     global $cfg, $cfgClient;
212:     checkAndInclude($cfg['path']['contenido'] . 'includes/functions.general.php');
213: 
214:     updateClientCache($idclient, $htmlpath, $frontendpath);
215: }
216: 
217: /**
218:  * Removes the trailing slash of a string.
219:  * @param $sInput
220:  *
221:  * @return string
222:  */
223: function stripLastSlash($sInput) {
224:     if (substr($sInput, strlen($sInput) - 1, 1) == "/") {
225:         $sInput = substr($sInput, 0, strlen($sInput) - 1);
226:     }
227: 
228:     return $sInput;
229: }
230: 
231: /**
232:  * Returns the paths to the system directory (filesystem and web).
233:  * @param bool $bOriginalPath
234:  *
235:  * @return array
236:  */
237: function getSystemDirectories($bOriginalPath = false) {
238:     $root_path = stripLastSlash(CON_FRONTEND_PATH);
239: 
240:     $root_http_path = dirname(dirname($_SERVER["PHP_SELF"]));
241:     $root_http_path = str_replace("\\", "/", $root_http_path);
242: 
243:     $port = "";
244:     $protocol = "http://";
245: 
246:     if ($_SERVER["SERVER_PORT"] != 80) {
247:         if ($_SERVER["SERVER_PORT"] == 443) {
248:             $protocol = "https://";
249:         } else {
250:             $port = ":" . $_SERVER["SERVER_PORT"];
251:         }
252:     }
253: 
254:     $root_http_path = $protocol . $_SERVER["SERVER_NAME"] . $port . $root_http_path;
255: 
256:     if (substr($root_http_path, strlen($root_http_path) - 1, 1) == "/") {
257:         $root_http_path = substr($root_http_path, 0, strlen($root_http_path) - 1);
258:     }
259: 
260:     if ($bOriginalPath == true) {
261:         return array($root_path, $root_http_path);
262:     }
263: 
264:     if (isset($_SESSION["override_root_path"])) {
265:         $root_path = $_SESSION["override_root_path"];
266:     }
267: 
268:     if (isset($_SESSION["override_root_http_path"])) {
269:         $root_http_path = $_SESSION["override_root_http_path"];
270:     }
271: 
272:     $root_path = stripLastSlash($root_path);
273:     $root_http_path = stripLastSlash($root_http_path);
274: 
275:     return array($root_path, $root_http_path);
276: }
277: 
278: /**
279:  * Searchs for a string in a given text and returns the position of it.
280:  * @param $string1
281:  * @param $string2
282:  *
283:  * @return int
284:  */
285: function findSimilarText($string1, $string2) {
286:     for ($i = 0; $i < strlen($string1); $i++) {
287:         if (substr($string1, 0, $i) != substr($string2, 0, $i)) {
288:             return $i - 1;
289:         }
290:     }
291: 
292:     return $i - 1;
293: }
294: 
295: ?>
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0