1<?php
2/**
3 *
4 * @package plugins
5 * @subpackage deprecated-functions
6*/
7
8/**
9 *
10 * @global type $files
11 * @param type $folder
12 * @param type $exclude
13 * @return string
14 */
15function getPHPFiles($folder, $exclude) {
16	global $files;
17	$dir = opendir($folder);
18	while (($file = readdir($dir)) !== false) {
19		$file = str_replace('\\', '/', $file);
20		if ($file != '.' && $file != '..') {
21			if (is_dir($folder . '/' . $file) && !in_array($file, $exclude)) {
22				getPHPFiles($folder . '/' . $file, $exclude);
23			} else {
24				if (getSuffix($file) == 'php') {
25					$entry = $folder . '/' . $file;
26					$files[] = $entry;
27				}
28			}
29		}
30	}
31	closedir($dir);
32	return $files;
33}
34/**
35 *
36 * @global type $deprecated
37 * @param type $title
38 * @param type $subject
39 * @param type $pattern
40 * @return boolean
41 */
42function formatList($title, $subject, $pattern) {
43	global $deprecated;
44	preg_match_all($pattern, $subject, $matches);
45	$started = false;
46	if ($matches && !empty($matches[0])) {
47		foreach (array_unique($matches[2]) as $key => $match) {
48			$details = $deprecated->unique_functions[strtolower($match)];
49			$found = $matches[1][$key];
50			switch ($details['class']) {
51				case 'static':
52					if ($found == '->' || $found == '::') {
53						$class = '*';
54						break;
55					} else {
56						continue 2;
57					}
58				case 'final static':
59					if ($found == '->' || $found == '::') {
60						$class = '*+';
61						break;
62					} else {
63						continue 2;
64					}
65				case 'public static':
66					if ($found == '->' || $found == '::') {
67						continue 2;
68					} else {
69						$class = '+';
70						break;
71					}
72				default:
73					if ($found == '->' || $found == '::') {
74						continue 2;
75					} else {
76						$class = '';
77						break;
78					}
79			}
80			if (!$started) {
81				$started = true;
82				echo '<li class="warningbox nobullet"> ' . $title;
83				echo '<ul>';
84			}
85			echo '<li>' . $match . $class . '</li>';
86		}
87	}
88	if ($started)
89		echo '</ul></li>';
90
91	return $started;
92}
93/**
94 *
95 * @param type $files
96 * @param type $base
97 * @param type $pattern
98 * @return type
99 */
100function listUses($files, $base, $pattern) {
101	if (is_array($files)) {
102		$open = $output = false;
103		$oldLocation = '';
104		foreach ($files as $file) {
105			if (basename($file) != 'deprecated-functions.php') {
106				@set_time_limit(120);
107				$subject = file_get_contents($file);
108				$location = str_replace($base . '/', '', dirname($file));
109				$folders = explode('/', $location);
110				if ($folders[0] != $oldLocation) {
111					$oldLocation = $folders[0];
112					echo '<br /><strong>' . $location . '</strong>';
113				}
114				if ($open) {
115					echo '</ul>';
116				}
117				$script_location = $base . '/' . $location . '/';
118				$script = str_replace($script_location, '', $file);
119				$open = $output = formatList($script, $subject, $pattern);
120			}
121		}
122		if ($open) {
123			echo '</ul>';
124		}
125		if ($output) {
126			?>
127			<p class="messagebox"><?php echo gettext('No calls on deprecated functions were found.'); ?></p>
128			<?php
129		}
130		return $output;
131	}
132}
133/**
134 *
135 * @param type $pattern
136 * @return boolean
137 */
138function listDBUses($pattern) {
139	$lookfor = array('images', 'albums', 'news', 'pages');
140	$found = array();
141	foreach ($lookfor as $table) {
142		echo '<br /><strong>' . sprintf(gettext('%s table'), $table) . '</strong>';
143		$output = false;
144		$sql = 'SELECT * FROM ' . prefix($table) . ' WHERE `codeblock` <> "" and `codeblock` IS NOT NULL and `codeblock`!="a:0:{}"';
145		$result = query($sql);
146		while ($row = db_fetch_assoc($result)) {
147			$codeblocks = getSerializedArray($row['codeblock']);
148			foreach ($codeblocks as $key => $codeblock) {
149				switch ($table) {
150					case 'news':
151					case 'pages':
152						$what = $row['titlelink'] . '::' . $key;
153						break;
154					case 'images':
155						$album = getItemByID('albums', $row['albumid']);
156						$what = $album->name . ':' . $row['filename'] . '::' . $key;
157						break;
158					case 'albums':
159						$what = $row['folder'] . '::' . $key;
160						break;
161				}
162				if (formatList($what, $codeblock, $pattern))
163					$output = true;
164			}
165		}
166		if ($output) {
167			echo '</ul>';
168		} else {
169			?>
170			<p class="messagebox"><?php echo gettext('No calls on deprecated functions were found.'); ?></p>
171			<?php
172		}
173	}
174	return $output;
175}
176?>
177