1: <?php
  2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14: 
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18:  19:  20:  21:  22:  23: 
 24: function checkExistingPlugin($db, $sPluginname) {
 25:     global $cfg;
 26: 
 27:     
 28:     if ($_SESSION["setuptype"] == "setup") {
 29:         return true;
 30:     }
 31: 
 32:     $sPluginname = (string) $sPluginname;
 33:     $sTable = $cfg['tab']['nav_sub'];
 34:     $sSql = '';
 35: 
 36:     switch ($sPluginname) {
 37:         case 'plugin_cronjob_overview':
 38:             $sSql = "SELECT * FROM %s WHERE idnavs=950";
 39:             break;
 40:         case 'plugin_conman':
 41:             $sSql = "SELECT * FROM %s WHERE idnavs=900";
 42:             break;
 43:         case 'plugin_content_allocation':
 44:             $sSql = "SELECT * FROM %s WHERE idnavs=800";
 45:             break;
 46:         case 'plugin_newsletter':
 47:             $sSql = "SELECT * FROM %s WHERE idnavs=610";
 48:             break;
 49:         case 'plugin_mod_rewrite':
 50:             $sSql = "SELECT * FROM %s WHERE idnavs=700 OR location='mod_rewrite/xml/;navigation/content/mod_rewrite'";
 51:             break;
 52:         default:
 53:             $sSql = '';
 54:             break;
 55:     }
 56: 
 57:     if ($sSql) {
 58:         $db->query($sSql, $sTable);
 59:         if ($db->nextRecord()) {
 60:             return true;
 61:         }
 62:     }
 63: 
 64:     return false;
 65: }
 66: 
 67:  68:  69:  70:  71: 
 72: function updateSystemProperties($db, $table) {
 73:     $table = $db->escape($table);
 74: 
 75:     $aStandardvalues = array(
 76:         array('type' => 'pw_request', 'name' => 'enable', 'value' => 'true'),
 77:         array('type' => 'system', 'name' => 'mail_sender_name', 'value' => 'CONTENIDO Backend'),
 78:         array('type' => 'system', 'name' => 'mail_sender', 'value' => 'info@contenido.org'),
 79:         array('type' => 'system', 'name' => 'mail_host', 'value' => 'localhost'),
 80:         array('type' => 'maintenance', 'name' => 'mode', 'value' => 'disabled'),
 81:         array('type' => 'codemirror', 'name' => 'activated', 'value' => 'true'),
 82:         array('type' => 'update', 'name' => 'check', 'value' => 'false'),
 83:         array('type' => 'update', 'name' => 'news_feed', 'value' => 'false'),
 84:         array('type' => 'update', 'name' => 'check_period', 'value' => '60'),
 85:         array('type' => 'system', 'name' => 'clickmenu', 'value' => 'false'),
 86:         array('type' => 'versioning', 'name' => 'activated', 'value' => 'true'),
 87:         array('type' => 'versioning', 'name' => 'prune_limit', 'value' => ''),
 88:         array('type' => 'versioning', 'name' => 'path', 'value' => ''),
 89:         array('type' => 'system', 'name' => 'insite_editing_activated', 'value' => 'true'),
 90:         array('type' => 'backend', 'name' => 'backend_label', 'value' => ''),
 91:         array('type' => 'generator', 'name' => 'xhtml', 'value' => 'true'),
 92:         array('type' => 'generator', 'name' => 'basehref', 'value' => 'true'),
 93:         array('type' => 'debug', 'name' => 'module_translation_message', 'value' => 'true')
 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: 120: 121: 122: 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:         
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: 140: 141: 142: 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: function updateSysadminPassword($db, $table, $password, $mail) {
157:     $sql = "SELECT password FROM %s WHERE username='sysadmin'";
158:     $db->query(sprintf($sql, $db->escape($table)));
159: 
160:     if ($db->nextRecord()) {
161:         $sql = "UPDATE %s SET password='%s', email='%s' WHERE username='sysadmin'";
162:         $db->query(sprintf($sql, $db->escape($table), md5($password), $mail));
163:         return true;
164:     } else {
165: 
166:         return false;
167:     }
168: }
169: 
170: 
171: function listClients($db, $table) {
172:     global $cfgClient;
173: 
174:     $sql = "SELECT idclient, name FROM %s";
175: 
176:     $db->query(sprintf($sql, $db->escape($table)));
177: 
178:     $clients = array();
179: 
180:     while ($db->nextRecord()) {
181:         $frontendPath = $cfgClient[$db->f('idclient')]['path']['frontend'];
182:         $htmlPath = $cfgClient[$db->f('idclient')]['path']['htmlpath'];
183:         $clients[$db->f("idclient")] = array("name" => $db->f("name"), "frontendpath" => $frontendPath, "htmlpath" => $htmlPath);
184:     }
185: 
186:     return $clients;
187: }
188: 
189: 
190: function updateClientPath($db, $table, $idclient, $frontendpath, $htmlpath) {
191:     global $cfg, $cfgClient;
192:     checkAndInclude($cfg['path']['contenido'] . 'includes/functions.general.php');
193: 
194:     updateClientCache($idclient, $htmlpath, $frontendpath);
195: }
196: 
197: 
198: function stripLastSlash($sInput) {
199:     if (substr($sInput, strlen($sInput) - 1, 1) == "/") {
200:         $sInput = substr($sInput, 0, strlen($sInput) - 1);
201:     }
202: 
203:     return $sInput;
204: }
205: 
206: 
207: function getSystemDirectories($bOriginalPath = false) {
208:     $root_path = stripLastSlash(CON_FRONTEND_PATH);
209: 
210:     $root_http_path = dirname(dirname($_SERVER["PHP_SELF"]));
211:     $root_http_path = str_replace("\\", "/", $root_http_path);
212: 
213:     $port = "";
214:     $protocol = "http://";
215: 
216:     if ($_SERVER["SERVER_PORT"] != 80) {
217:         if ($_SERVER["SERVER_PORT"] == 443) {
218:             $protocol = "https://";
219:         } else {
220:             $port = ":" . $_SERVER["SERVER_PORT"];
221:         }
222:     }
223: 
224:     $root_http_path = $protocol . $_SERVER["SERVER_NAME"] . $port . $root_http_path;
225: 
226:     if (substr($root_http_path, strlen($root_http_path) - 1, 1) == "/") {
227:         $root_http_path = substr($root_http_path, 0, strlen($root_http_path) - 1);
228:     }
229: 
230:     if ($bOriginalPath == true) {
231:         return array($root_path, $root_http_path);
232:     }
233: 
234:     if (isset($_SESSION["override_root_path"])) {
235:         $root_path = $_SESSION["override_root_path"];
236:     }
237: 
238:     if (isset($_SESSION["override_root_http_path"])) {
239:         $root_http_path = $_SESSION["override_root_http_path"];
240:     }
241: 
242:     $root_path = stripLastSlash($root_path);
243:     $root_http_path = stripLastSlash($root_http_path);
244: 
245:     return array($root_path, $root_http_path);
246: }
247: 
248: 
249: function findSimilarText($string1, $string2) {
250:     for ($i = 0; $i < strlen($string1); $i++) {
251:         if (substr($string1, 0, $i) != substr($string2, 0, $i)) {
252:             return $i - 1;
253:         }
254:     }
255: 
256:     return $i - 1;
257: }
258: 
259: ?>