1 |
1457
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category WebsiteBaker
|
5 |
|
|
* @package modules
|
6 |
|
|
* @subpackage news
|
7 |
|
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8 |
|
|
* @link http://www.websitebaker2.org/
|
9 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
10 |
|
|
* @platform WebsiteBaker 2.8.x
|
11 |
|
|
* @requirements PHP 5.2.2 and higher
|
12 |
|
|
* @version $Id$
|
13 |
|
|
* @filesource $HeadURL$
|
14 |
|
|
* @lastmodified $Date$
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
|
|
|
18 |
|
|
// Must include code to stop this file being access directly
|
19 |
1538
|
Luisehahne
|
/* -------------------------------------------------------- */
|
20 |
|
|
if(defined('WB_PATH') == false)
|
21 |
|
|
{
|
22 |
|
|
// Stop this file being access directly
|
23 |
|
|
die('<head><title>Access denied</title></head><body><h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2></body></html>');
|
24 |
|
|
}
|
25 |
1457
|
Luisehahne
|
|
26 |
|
|
/* **** START UPGRADE ******************************************************* */
|
27 |
1477
|
Luisehahne
|
if(!function_exists('mod_news_Upgrade'))
|
28 |
|
|
{
|
29 |
1457
|
Luisehahne
|
function mod_news_Upgrade()
|
30 |
|
|
{
|
31 |
1538
|
Luisehahne
|
global $database, $msg, $admin, $MESSAGE;
|
32 |
1457
|
Luisehahne
|
$callingScript = $_SERVER["SCRIPT_NAME"];
|
33 |
|
|
$tmp = 'upgrade-script.php';
|
34 |
|
|
$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
|
35 |
|
|
|
36 |
|
|
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
37 |
|
|
$sPostsPath = $sPagesPath.'/posts';
|
38 |
|
|
// create /posts/ - directory if not exists
|
39 |
|
|
if(!file_exists($sPostsPath)) {
|
40 |
|
|
if(is_writable($sPagesPath)) {
|
41 |
|
|
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
|
42 |
|
|
}else {
|
43 |
|
|
if(!$globalStarted){
|
44 |
1538
|
Luisehahne
|
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
45 |
1457
|
Luisehahne
|
}else {
|
46 |
1538
|
Luisehahne
|
$msg[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].'<br />';
|
47 |
1457
|
Luisehahne
|
return;
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
if($globalStarted) {echo 'directory "'.PAGES_DIRECTORY.'/posts/" created.<br />'; }
|
51 |
|
|
}
|
52 |
|
|
// check if new fields must be added
|
53 |
|
|
$doImportDate = true;
|
54 |
|
|
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_when')) {
|
55 |
|
|
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_when',
|
56 |
|
|
'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) {
|
57 |
|
|
if($globalStarted){
|
58 |
|
|
echo $MESSAGE['RECORD_MODIFIED_FAILED'].'<br />';
|
59 |
|
|
return;
|
60 |
|
|
}else {
|
61 |
|
|
$admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
if($globalStarted) { echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_when` added.<br />'; }
|
65 |
|
|
}else { $doImportDate = false; }
|
66 |
|
|
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_by')) {
|
67 |
|
|
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_by',
|
68 |
|
|
'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) {
|
69 |
|
|
if($globalStarted){
|
70 |
|
|
echo $MESSAGE['RECORD_MODIFIED_FAILED'].'<br />';
|
71 |
|
|
return;
|
72 |
|
|
}else {
|
73 |
|
|
$admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
if($globalStarted) {echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_by` added.<br />'; }
|
77 |
|
|
}
|
78 |
|
|
// preset new fields `created_by` and `created_when` from existing values
|
79 |
|
|
if($doImportDate) {
|
80 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
81 |
|
|
$sql .= 'SET `created_by`=`posted_by`, `created_when`=`posted_when`';
|
82 |
|
|
$database->query($sql);
|
83 |
|
|
}
|
84 |
|
|
// now iterate through all existing accessfiles,
|
85 |
|
|
// write its creation date into database
|
86 |
|
|
$oDir = new DirectoryIterator($sPostsPath);
|
87 |
|
|
$count = 0;
|
88 |
|
|
foreach ($oDir as $fileinfo)
|
89 |
|
|
{
|
90 |
|
|
$fileName = $fileinfo->getFilename();
|
91 |
|
|
if((!$fileinfo->isDot()) &&
|
92 |
|
|
($fileName != 'index.php') &&
|
93 |
|
|
(substr_compare($fileName,PAGE_EXTENSION,(0-strlen(PAGE_EXTENSION)),strlen(PAGE_EXTENSION)) === 0)
|
94 |
|
|
)
|
95 |
|
|
{
|
96 |
|
|
// save creation date from old accessfile
|
97 |
|
|
if($doImportDate) {
|
98 |
|
|
$link = '/posts/'.preg_replace('/'.preg_quote(PAGE_EXTENSION).'$/i', '', $fileinfo->getFilename());
|
99 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
100 |
|
|
$sql .= 'SET `created_when`='.$fileinfo->getMTime().' ';
|
101 |
|
|
$sql .= 'WHERE `link`=\''.$link.'\'';
|
102 |
|
|
$database->query($sql);
|
103 |
|
|
}
|
104 |
|
|
// delete old access file
|
105 |
|
|
unlink($fileinfo->getPathname());
|
106 |
|
|
$count++;
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
unset($oDir);
|
110 |
|
|
if($globalStarted && $count > 0) {
|
111 |
1538
|
Luisehahne
|
$msg[] = 'save date of creation from '.$count.' old accessfiles and delete these files.<br />';
|
112 |
1457
|
Luisehahne
|
}
|
113 |
|
|
// ************************************************
|
114 |
|
|
// Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp'
|
115 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
116 |
|
|
$sql .= 'SET `created_when`=`published_when` ';
|
117 |
|
|
$sql .= 'WHERE `published_when`<`created_when`';
|
118 |
|
|
$database->query($sql);
|
119 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
120 |
|
|
$sql .= 'SET `created_when`=`posted_when` ';
|
121 |
|
|
$sql .= 'WHERE `published_when`=0 OR `published_when`>`posted_when`';
|
122 |
|
|
$database->query($sql);
|
123 |
|
|
// ************************************************
|
124 |
|
|
|
125 |
|
|
// rebuild all access-files
|
126 |
|
|
$count = 0;
|
127 |
|
|
// $backSteps = preg_replace('/^'.preg_quote(WB_PATH).'/', '', $sPostsPath);
|
128 |
|
|
$backSteps = preg_replace('@^'.preg_quote(WB_PATH).'@', '', $sPostsPath);
|
129 |
|
|
$backSteps = str_repeat( '../', substr_count($backSteps, '/'));
|
130 |
|
|
$sql = 'SELECT `page_id`,`post_id`,`section_id`,`link` ';
|
131 |
|
|
$sql .= 'FROM `'.TABLE_PREFIX.'mod_news_posts`';
|
132 |
|
|
$sql .= 'WHERE `link` != \'\'';
|
133 |
|
|
if( ($resPosts = $database->query($sql)) )
|
134 |
|
|
{
|
135 |
|
|
while( $recPost = $resPosts->fetchRow() )
|
136 |
|
|
{
|
137 |
|
|
$file = $sPagesPath.$recPost['link'].PAGE_EXTENSION;
|
138 |
|
|
$content =
|
139 |
|
|
'<?php'."\n".
|
140 |
|
|
'// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n".
|
141 |
|
|
'// *** Creation date: '.date('c')."\n".
|
142 |
|
|
'// *** Do not modify this file manually'."\n".
|
143 |
|
|
'// *** WB will rebuild this file from time to time!!'."\n".
|
144 |
|
|
'// *************************************************'."\n".
|
145 |
|
|
"\t".'$page_id = '.$recPost['page_id'].';'."\n".
|
146 |
|
|
"\t".'$section_id = '.$recPost['section_id'].';'."\n".
|
147 |
|
|
"\t".'$post_id = '.$recPost['post_id'].';'."\n".
|
148 |
|
|
"\t".'$post_section = '.$recPost['section_id'].';'."\n".
|
149 |
|
|
// "\t".'define(\'POST_SECTION\', '.$recPost['section_id'].');'."\n".
|
150 |
|
|
// "\t".'define(\'POST_ID\', '.$recPost['post_id'].');'."\n".
|
151 |
|
|
"\t".'require(\''.$backSteps.'index.php\');'."\n".
|
152 |
|
|
'// *************************************************'."\n";
|
153 |
|
|
if( file_put_contents($file, $content) !== false ) {
|
154 |
|
|
// Chmod the file
|
155 |
|
|
change_mode($file);
|
156 |
|
|
}else {
|
157 |
|
|
if($globalStarted){
|
158 |
1538
|
Luisehahne
|
$msg[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].'<br />';
|
159 |
1457
|
Luisehahne
|
return;
|
160 |
|
|
}else {
|
161 |
1538
|
Luisehahne
|
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
162 |
1457
|
Luisehahne
|
}
|
163 |
|
|
}
|
164 |
|
|
$count++;
|
165 |
|
|
}
|
166 |
|
|
}
|
167 |
1538
|
Luisehahne
|
if($globalStarted) { $msg[] = 'created '.$count.' new accessfiles.'; }
|
168 |
|
|
// if(!$globalStarted) { $admin->print_footer(); }
|
169 |
1457
|
Luisehahne
|
}
|
170 |
1477
|
Luisehahne
|
}
|
171 |
|
|
|
172 |
1538
|
Luisehahne
|
$msg = array();
|
173 |
|
|
$aTable = array('mod_news_posts','mod_news_groups','mod_news_comments','mod_news_settings');
|
174 |
|
|
for($x=0; $x<sizeof($aTable);$x++) {
|
175 |
|
|
if(($sOldType = $database->getTableEngine(TABLE_PREFIX.$aTable[$x]))) {
|
176 |
|
|
if(('myisam' != strtolower($sOldType))) {
|
177 |
|
|
if(!$database->query('ALTER TABLE `'.TABLE_PREFIX.$aTable[$x].'` Engine = \'MyISAM\' ')) {
|
178 |
|
|
$msg[] = $database->get_error();
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
} else {
|
182 |
|
|
$msg[] = $database->get_error();
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
// ------------------------------------
|
186 |
1457
|
Luisehahne
|
mod_news_Upgrade();
|
187 |
|
|
/* **** END UPGRADE ********************************************************* */
|