1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of mkcompat, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2009 Dotclear Team and contributors |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')) { return; } |
---|
14 | |
---|
15 | class mkcompat { |
---|
16 | |
---|
17 | public static function themeNeedUpgrade ($theme_path) |
---|
18 | { |
---|
19 | if (!is_dir($theme_path.'/tpl')) |
---|
20 | return false; |
---|
21 | |
---|
22 | $dir_contents = files::getDirList($theme_path.'/tpl'); |
---|
23 | foreach ($dir_contents['files'] as $file) |
---|
24 | if (self::checkFile($file)) |
---|
25 | return true; |
---|
26 | |
---|
27 | return false; |
---|
28 | } |
---|
29 | |
---|
30 | public static function pluginNeedUpgrade ($theme_path) |
---|
31 | { |
---|
32 | $dir_contents = files::getDirList($theme_path); |
---|
33 | |
---|
34 | foreach ($dir_contents['files'] as $file) |
---|
35 | if (self::checkFile($file)) |
---|
36 | return true; |
---|
37 | |
---|
38 | return false; |
---|
39 | } |
---|
40 | |
---|
41 | public static function moduleUpgrade ($plugin_path) |
---|
42 | { |
---|
43 | $dir_contents = files::getDirList($plugin_path); |
---|
44 | foreach ($dir_contents['files'] as $file) |
---|
45 | self::updateFile($file); |
---|
46 | } |
---|
47 | |
---|
48 | public static function checkFile_html ($filename) |
---|
49 | { |
---|
50 | $oldTags = array( |
---|
51 | 'MetaData','MetaDataHeader','MetaDataFooter','MetaID','MetaPercent', |
---|
52 | 'MetaRoundPercent','MetaURL','MetaAllURL','EntryMetaData' |
---|
53 | ); |
---|
54 | |
---|
55 | if (basename($filename) == '404.html' && |
---|
56 | strpos(file_get_contents($filename), |
---|
57 | 'The document you are looking for does not exists.') != false) |
---|
58 | return true; |
---|
59 | |
---|
60 | $contents = file_get_contents($filename); |
---|
61 | foreach ($oldTags as $tag) |
---|
62 | { |
---|
63 | if (strpos($contents,'tpl:'.$tag) != false) |
---|
64 | return true; |
---|
65 | } |
---|
66 | return false; |
---|
67 | } |
---|
68 | |
---|
69 | public static function checkFile_php ($filename) |
---|
70 | { |
---|
71 | $pattern = '/(<script[^>]*>(?(?!script).)*)\[@(.*?<\/script>)/s'; |
---|
72 | |
---|
73 | if (strpos($contents = file_get_contents($filename),'[@') != false) |
---|
74 | if (preg_match_all($pattern,$contents,$scripts)) |
---|
75 | return true; |
---|
76 | } |
---|
77 | |
---|
78 | public static function checkFile_js ($filename) |
---|
79 | { |
---|
80 | if (strpos(file_get_contents($filename),'[@') != false) |
---|
81 | return true; |
---|
82 | return false; |
---|
83 | } |
---|
84 | |
---|
85 | public static function updateFile_html ($filename) |
---|
86 | { |
---|
87 | $oldTags = array( |
---|
88 | 'tpl:MetaData','tpl:MetaID','tpl:MetaPercent','tpl:MetaRoundPercent', |
---|
89 | 'tpl:MetaURL','tpl:MetaAllURL','tpl:EntryMetaData', |
---|
90 | 'The document you are looking for does not exists.' |
---|
91 | ); |
---|
92 | $newTags = array( |
---|
93 | 'tpl:Tags','tpl:TagID','tpl:TagPercent','tpl:TagRoundPercent', |
---|
94 | 'tpl:TagURL','tpl:TagCloudURL','tpl:EntryTags', |
---|
95 | 'The document you are looking for does not exist.' |
---|
96 | ); |
---|
97 | |
---|
98 | if (!$contents = file_get_contents ($filename)) |
---|
99 | throw new exception (__('cannot read file: ').$filename); |
---|
100 | |
---|
101 | $newcontents = str_replace($oldTags,$newTags,$contents,$count); |
---|
102 | if ($count > 0) files::putContent($filename,$newcontents); |
---|
103 | } |
---|
104 | |
---|
105 | public static function updateFile_php ($filename) |
---|
106 | { |
---|
107 | $pattern = '/(<script[^>]*>(?(?!script).)*)\[@(.*?<\/script>)/s'; |
---|
108 | $replace = '$1[$2'; |
---|
109 | |
---|
110 | if (!$contents = file_get_contents ($filename)) |
---|
111 | throw new exception (__('cannot read file: ').$filename); |
---|
112 | |
---|
113 | $newcontents = preg_replace($pattern,$replace,$contents,-1,$count); |
---|
114 | if ($count > 0) |
---|
115 | { |
---|
116 | while ($count > 0) $newcontents = preg_replace($pattern,$replace,$newcontents,-1,$count); |
---|
117 | files::putContent($filename,$newcontents); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | public static function updateFile_js ($filename) |
---|
122 | { |
---|
123 | if (!$contents = file_get_contents ($filename)) |
---|
124 | throw new exception (__('cannot read file: ').$filename); |
---|
125 | |
---|
126 | $newcontents = str_replace('[@','[',$contents,$count); |
---|
127 | if ($count > 0) files::putContent($filename,$newcontents); |
---|
128 | } |
---|
129 | |
---|
130 | public static function checkFile ($filename) |
---|
131 | { |
---|
132 | $file_ext = files::getExtension($filename); |
---|
133 | |
---|
134 | if (method_exists(get_class(),'checkFile_'.$file_ext)) |
---|
135 | { |
---|
136 | return call_user_func(array(get_class(),'checkFile_'.$file_ext),$filename); |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | return false; |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | public static function updateFile ($filename) |
---|
145 | { |
---|
146 | $file_ext = files::getExtension($filename); |
---|
147 | |
---|
148 | if (method_exists(get_class(),'updateFile_'.$file_ext)) |
---|
149 | call_user_func(array(get_class(),'updateFile_'.$file_ext),$filename); |
---|
150 | } |
---|
151 | } |
---|
152 | ?> |
---|