Project

General

Profile

1 989 aldus
<?php
2
/*
3
*	@version	1.0
4
*	@author		Ruud Eisinga (Ruud) John (PCWacht)
5
*	@date		June 2009
6
*
7
*	droplets are small codeblocks that are called from anywhere in the template.
8
* 	To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value&parameter2=value]]
9
*/
10
11
// Direct access prevention
12
defined('WB_PATH') OR die(header('Location: ../index.php'));
13
14
// Load Language file
15
if(LANGUAGE_LOADED) {
16
	if(!file_exists(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php')) {
17
		require_once(WB_PATH.'/modules/droplets/languages/EN.php');
18
	} else {
19
		require_once(WB_PATH.'/modules/droplets/languages/'.LANGUAGE.'.php');
20
	}
21
}
22
23
// check if backend.css file needs to be included into the <body></body>
24
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH .'/modules/droplets/backend.css')) {
25
	echo '<style type="text/css">';
26
	include(WB_PATH .'/modules/droplets/backend.css');
27
	echo "\n</style>\n";
28
}
29
30
// Get userid for showing admin only droplets or not
31
$loggedin_user = $admin->get_user_id();
32
33
// And... action
34
$admintool_url = ADMIN_URL .'/admintools/index.php';
35
36
//removes empty entries from the table so they will not be displayed
37
$database->query("DELETE FROM ".TABLE_PREFIX."mod_droplets WHERE name=''");
38
?>
39
<style type="text/css">
40
a.tooltip span {display:none; margin-left:14px; width:430px;}
41
a.tooltip:hover span{display:inline; position:absolute; padding:5px; border:1px solid #000000; background:#ffffff; color:#000000;}
42
</style>
43
44
<br />
45
<table cellpadding="0" cellspacing="0" border="0" width="100%">
46
<tr>
47
	<td valign="bottom" width="30%">
48
		<button class="add" type="button" name="add_droplet" onclick="javascript: window.location = '<?php echo WB_URL; ?>/modules/droplets/add_droplet.php';"><?php echo $TEXT['ADD'].' '.$DR_TEXT['DROPLETS']; ?></button>
49
	</td>
50
	<td align="center"><img src="<?php echo WB_URL; ?>/modules/droplets/img/droplets_logo.png" border="1" alt=""/></td>
51
	<td valign="top" width="30%" align="right">
52
		<a href="#" onclick="javascript: window.open('<?php echo WB_URL; ?>/modules/droplets/readme/<?php echo $DR_TEXT['README']; ?>','helpwindow','width=700,height=550,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes');"><?php echo $DR_TEXT['HELP']; ?></a>
53
		<br /><br />
54
		<a href="#" onclick="javascript: window.location = '<?php echo WB_URL; ?>/modules/droplets/backup_droplets.php';"><?php echo $DR_TEXT['BACKUP']; ?></a>
55
	</td>
56
</tr>
57
</table>
58
<br />
59
60
<h2><?php echo $TEXT['MODIFY'].'/'.$TEXT['DELETE'].' '.$DR_TEXT['DROPLETS']; ?></h2>
61
<?php
62
if ($loggedin_user == '1') {
63
	$query_droplets = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets ORDER BY modified_when DESC");
64
} else {
65
	$query_droplets = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets WHERE admin_view <> '1' ORDER BY modified_when DESC");
66
}
67
$num_droplets = $query_droplets->numRows();
68
if($num_droplets > 0) {
69
	?>
70
	<table class="row_a" border="0" cellspacing="0" cellpadding="3" width="100%">
71
	<tr>
72
		<thead>
73
			<td width="3%"></td>
74
			<td width="21%"><?php echo $TEXT['NAME']; ?></td>
75
			<td width="68%"><?php echo $TEXT['DESCRIPTION']; ?></td>
76
			<td width="4%"><?php echo $TEXT['ACTIVE']; ?></td>
77
			<td width="3%"></td>
78
		</thead>
79
	</tr>
80
	<?php
81
	$row = 'a';
82
	while($droplet = $query_droplets->fetchRow()) {
83
		$get_modified_user = $database->query("SELECT display_name,username, user_id FROM ".TABLE_PREFIX."users WHERE user_id = '".$droplet['modified_by']."' LIMIT 1");
84
		if($get_modified_user->numRows() > 0) {
85
			$fetch_modified_user = $get_modified_user->fetchRow();
86
			$modified_user = $fetch_modified_user['username'];
87
			$modified_userid = $fetch_modified_user['user_id'];
88
		} else {
89
			$modified_user = $TEXT['UNKNOWN'];
90
			$modified_userid = 0;
91
		}
92
		$comments = str_replace(array("\r\n", "\n", "\r"), '<br />', $droplet['comments']);
93
		if (!strpos($comments,"[[")) $comments = "Use: [[".$droplet['name']."]]<br />".$comments;
94
		$comments = str_replace(array("[[", "]]"), array('<b>[[',']]</b>'), $comments);
95
		$valid_code = check_syntax($droplet['code']);
96
		if (!$valid_code === true) $comments = '<font color=\'red\'><strong>'.$DR_TEXT['INVALIDCODE'].'</strong></font><br /><br />'.$comments;
97
		$unique_droplet = check_unique ($droplet['name']);
98
		if ($unique_droplet === false) $comments = '<font color=\'red\'><strong>'.$DR_TEXT['NOTUNIQUE'].'</strong></font><br /><br />'.$comments;
99
		$comments = '<span>'.$comments.'</span>';
100
		?>
101
102
		<tr class="row_<?php echo $row; ?>" height="20">
103
			<td >
104
				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $droplet['id']?>" title="<?php echo $TEXT['MODIFY']; ?>">
105
					<img src="<?php echo THEME_URL; ?>/images/modify_16.png" border="0" alt="Modify" />
106
				</a>
107
			</td>
108
			<td >
109
				<a href="<?php echo WB_URL; ?>/modules/droplets/modify_droplet.php?droplet_id=<?php echo $droplet['id']?>" class="tooltip">
110
							<?php if ($valid_code && $unique_droplet) { ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/droplet.png" border="0" alt=""/>
111
							<?php } else {  ?><img src="<?php echo WB_URL; ?>/modules/droplets/img/invalid.gif" border="0" title="" alt=""/><?php }  ?>
112
					<?php echo $droplet['name']; ?><?php echo $comments; ?>
113
				</a>
114
			</td>
115
			<td >
116
				<small><?php echo substr($droplet['description'],0,90); ?></small>
117
			</td>
118
			<td >
119
				<b><?php if($droplet['active'] == 1){ echo '<span style="color: green;">'. $TEXT['YES']. '</span>'; } else { echo '<span style="color: red;">'.$TEXT['NO'].'</span>';  } ?></b>
120
			</td>
121
			<td >
122
				<a href="javascript: confirm_link('<?php echo $TEXT['ARE_YOU_SURE']; ?>', '<?php echo WB_URL; ?>/modules/droplets/delete_droplet.php?droplet_id=<?php echo $droplet['id']?>');" title="<?php echo $TEXT['DELETE']; ?>">
123
					<img src="<?php echo THEME_URL; ?>/images/delete_16.png" border="0" alt="X" />
124
				</a>
125
			</td>
126
		</tr>
127
		<?php
128
		// Alternate row color
129
		if($row == 'a') {
130
			$row = 'b';
131
		} else {
132
			$row = 'a';
133
		}
134
	}
135
	?>
136
	</table>
137
	<?php
138
}
139
140
function check_syntax($code) {
141
    return @eval('return true;' . $code);
142
}
143
144
function check_unique($name) {
145
	global $database;
146
	$query_droplets = $database->query("SELECT name FROM ".TABLE_PREFIX."mod_droplets WHERE name = '$name'");
147
	return ($query_droplets->numRows() == 1);
148
149
150
151
}
152
153
?>