Project

General

Profile

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