Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         wysiwyg
6
 * @author          WebsiteBaker Project
7
 * @copyright       WebsiteBaker Org. e.V.
8
 * @link            http://websitebaker.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.3
11
 * @requirements    PHP 5.3.6 and higher
12
 * @version         $Id: upgrade.php 2 2017-07-02 15:14:29Z Manuela $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/modules/wysiwyg/upgrade.php $
14
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
15
 *
16
 */
17

    
18
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
if(defined('WB_PATH') == false) { die('Illegale file access /'.basename(__DIR__).'/'.basename(__FILE__).''); }
21
/* -------------------------------------------------------- */
22
$msg = '';
23
$sTable = TABLE_PREFIX.'mod_wysiwyg';
24
if(($sOldType = $database->getTableEngine($sTable))) {
25
    if(('myisam' != strtolower($sOldType))) {
26
        if(!$database->query('ALTER TABLE `'.$sTable.'` Engine = \'MyISAM\' ')) {
27
            $msg = $database->get_error();
28
        }
29
    }
30
} else {
31
    $msg .= $database->get_error().'<br />';
32
}
33
// sanitize URLs inside mod_wysiwyg.content ----------------------------
34
    $msg = '';
35
    $sRelUrl = preg_replace('/^https?:\/\/[^\/]+(.*)/is', '\1', WB_URL);
36
    $sDocumentRootUrl = str_replace($sRelUrl, '', WB_URL);
37
    $sMediaUrl = WB_URL.MEDIA_DIRECTORY;
38
    $sql = 'SELECT `content`, `section_id` FROM `'.TABLE_PREFIX.'mod_wysiwyg`';
39
    if (($oInstances = $database->query($sql))) {
40
        while (($aInstance = $oInstances->fetchRow(MYSQLI_ASSOC))) {
41
            // add $sDocumentRootUrl to relative URLs
42
            $aPatterns = array(
43
                '/(<[^>]*?=\s*\")(\/+)([^\"]*?\"[^>]*?)/is',
44
                '/(<[^>]*=\s*")('.preg_quote($sMediaUrl, '/').')([^">]*".*>)/siU'
45
            );
46
            $aReplacements = array(
47
                '\1'.$sDocumentRootUrl.'/\3',
48
                '$1{SYSVAR:MEDIA_REL}$3'
49
            );
50
            $aInstance['content'] = preg_replace($aPatterns, $aReplacements, $aInstance['content']);
51
            $sql = 'UPDATE `'.TABLE_PREFIX.'mod_wysiwyg` '
52
                 . 'SET `content`=\''.$database->escapeString($aInstance['content']).'\' '
53
                 . 'WHERE `section_id`='.(int)$aInstance['section_id'];
54
            if (!$database->query($sql)) {
55
                $msg = $database->get_error();
56
                break;
57
            }
58
        }
59
    } else { $msg = $database->get_error(); }
60

    
61
// ---------------------------------------------------------------------
62

    
63
$sql  = 'UPDATE `'.$sTable.'` SET '
64
      . '`content` = REPLACE(`content`, \'"'.WB_URL.MEDIA_DIRECTORY.'\', \'"{SYSVAR:MEDIA_REL}\')';
65
if (!$database->query($sql)) {
66
    $msg .= $database->get_error().'<br />';
67
}
68

    
69
// ------------------------------------
(10-10/11)