| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
function iMinR () { |
|---|
| 31 |
wp_iminr_insert_tracker(); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
function wp_iminr_meta() { |
|---|
| 36 |
wp_iminr_insert_tracker('meta'); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
function wp_iminr_footer() { |
|---|
| 41 |
wp_iminr_insert_tracker('footer'); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
function wp_iminr_insert_tracker($location='') { |
|---|
| 46 |
global $wp_iminr_tracker_inserted; |
|---|
| 47 |
|
|---|
| 48 |
if (!$wp_iminr_tracker_inserted) { |
|---|
| 49 |
$account_id = wp_iminr_get_option('account_id'); |
|---|
| 50 |
if ($account_id != '' && wp_iminr_enable_for_user()) { |
|---|
| 51 |
echo "<!-- iMinR for WordPress is enable -->\n"; |
|---|
| 52 |
$wp_iminr_tracker_inserted = true; |
|---|
| 53 |
|
|---|
| 54 |
if (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on') { |
|---|
| 55 |
$tracker = "<script language=\"javascript\" src=\"http://tag.iminr.com/audit/tag.aspx?id=$account_id\"></script>"; |
|---|
| 56 |
} else { |
|---|
| 57 |
$tracker = "<script language=\"javascript\" src=\"https://tags.iminr.com/audit/tag.aspx?id=$account_id\"></script>"; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
switch ($location) { |
|---|
| 61 |
case 'meta': |
|---|
| 62 |
echo wp_iminr_get_option('tracker_in_meta_before') . $tracker . wp_iminr_get_option('tracker_in_meta_after'); |
|---|
| 63 |
break; |
|---|
| 64 |
case 'footer': |
|---|
| 65 |
echo wp_iminr_get_option('tracker_in_footer_before') . $tracker . wp_iminr_get_option('tracker_in_footer_after'); |
|---|
| 66 |
break; |
|---|
| 67 |
default: |
|---|
| 68 |
echo $tracker; |
|---|
| 69 |
} |
|---|
| 70 |
} elseif ($account_id != '' && !wp_iminr_enable_for_user()) { |
|---|
| 71 |
echo "<!-- iMinR for WordPress is desable for current user -->\n"; |
|---|
| 72 |
} else { |
|---|
| 73 |
echo "<!-- iMinR for WordPress is desable because account id isn\'t set -->\n"; |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
function wp_iminr_get_option($option_name) { |
|---|
| 80 |
|
|---|
| 81 |
$wp_iminr_options = get_option('wp_iminr_options'); |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
// create default options array |
|---|
| 85 |
if (!$wp_iminr_options || !array_key_exists($option_name, $wp_iminr_options) ) { |
|---|
| 86 |
$wp_iminr_default_options = array(); |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
$wp_iminr_default_options['account_id'] = ''; |
|---|
| 90 |
|
|---|
| 91 |
$wp_iminr_default_options['enable_tracker'] = false; |
|---|
| 92 |
$wp_iminr_default_options['tracker_in_meta'] = true; |
|---|
| 93 |
$wp_iminr_default_options['tracker_in_meta_before'] = '<li>'; |
|---|
| 94 |
$wp_iminr_default_options['tracker_in_meta_after'] = '</li>'; |
|---|
| 95 |
$wp_iminr_default_options['tracker_in_footer'] = false; |
|---|
| 96 |
$wp_iminr_default_options['tracker_in_footer_before'] = '<br />'; |
|---|
| 97 |
$wp_iminr_default_options['tracker_in_footer_after'] = ''; |
|---|
| 98 |
$wp_iminr_default_options['desable_for_roles'] = array('administrator'); |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
add_option('wp_iminr_options', $wp_iminr_default_options, 'Settings for iMinR for WordPress plugin'); |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
return $wp_iminr_default_options[$option_name]; |
|---|
| 105 |
} else { |
|---|
| 106 |
|
|---|
| 107 |
return $wp_iminr_options[$option_name]; |
|---|
| 108 |
} |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
function wp_iminr_admin() { |
|---|
| 113 |
if (function_exists('add_options_page')) { |
|---|
| 114 |
add_options_page(__('iMinR for WorldPress'), 'iMinR', 8, basename(__FILE__), 'wp_iminr_options'); |
|---|
| 115 |
} |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
function wp_iminr_options() { |
|---|
| 120 |
if (isset($_POST['info_update'])) { |
|---|
| 121 |
?><div class="updated"><p><strong><?php |
|---|
| 122 |
|
|---|
| 123 |
$wp_iminr_options = get_option('wp_iminr_options'); |
|---|
| 124 |
|
|---|
| 125 |
$wp_iminr_options['account_id'] = $_POST['account_id']; |
|---|
| 126 |
|
|---|
| 127 |
$wp_iminr_options['enable_tracker'] = ($_POST['enable_tracker'] == 'true' ? true : false); |
|---|
| 128 |
$wp_iminr_options['tracker_in_meta'] = ($_POST['tracker_in'] == 'meta' ? true : false); |
|---|
| 129 |
$wp_iminr_options['tracker_in_meta_before'] = $_POST['tracker_in_meta_before']; |
|---|
| 130 |
$wp_iminr_options['tracker_in_meta_after'] = $_POST['tracker_in_meta_after']; |
|---|
| 131 |
$wp_iminr_options['tracker_in_footer'] = ($_POST['tracker_in'] == 'footer' ? true : false); |
|---|
| 132 |
$wp_iminr_options['tracker_in_footer_before'] = $_POST['tracker_in_footer_before']; |
|---|
| 133 |
$wp_iminr_options['tracker_in_footer_after'] = $_POST['tracker_in_footer_after']; |
|---|
| 134 |
$wp_iminr_options['desable_for_roles'] = $_POST['desable_for_roles']; |
|---|
| 135 |
|
|---|
| 136 |
update_option('wp_iminr_options', $wp_iminr_options); |
|---|
| 137 |
|
|---|
| 138 |
_e('Options saved', 'wp_iminr') |
|---|
| 139 |
?></strong></p></div><?php |
|---|
| 140 |
} |
|---|
| 141 |
?> |
|---|
| 142 |
<div class=wrap> |
|---|
| 143 |
<form method="post"> |
|---|
| 144 |
<h2><?php _e('iMinR for WordPress'); ?></h2> |
|---|
| 145 |
<fieldset class="options" name="general"> |
|---|
| 146 |
<legend><?php _e('General settings', 'wp_iminr') ?></legend> |
|---|
| 147 |
|
|---|
| 148 |
<table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 149 |
<tr> |
|---|
| 150 |
<th nowrap valign="top"><label for="account_id"><?php _e('Account ID', 'wp_iminr') ?></label></th> |
|---|
| 151 |
<td valign="top"> |
|---|
| 152 |
<input type="text" name="account_id" id="account_id" value="<?php echo wp_iminr_get_option('account_id'); ?>" size="50" /> |
|---|
| 153 |
<br /><small><?php _e('Enter your iMinR account ID.', 'wp_iminr') ?></small> |
|---|
| 154 |
</td> |
|---|
| 155 |
</tr> |
|---|
| 156 |
</table> |
|---|
| 157 |
|
|---|
| 158 |
</fieldset> |
|---|
| 159 |
<fieldset class="options" name="integration"> |
|---|
| 160 |
<legend><?php _e('Tracker integration', 'wp_iminr') ?></legend> |
|---|
| 161 |
<p><?php _e('Enable tracker inclusion or copy this code in your template to activate iMinR for this site: <code><?php iMinR(); ?></code> ', 'wp_iminr') ?></p> |
|---|
| 162 |
|
|---|
| 163 |
<table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 164 |
<tr> |
|---|
| 165 |
<th nowrap valign="top"><label for="enable_tracker"><?php _e('Enable tracker', 'wp_iminr') ?></label></th> |
|---|
| 166 |
<td valign="top"> |
|---|
| 167 |
<input type="checkbox" name="enable_tracker" id="enable_tracker" value="true" <?php if (wp_iminr_get_option('enable_tracker')) echo 'checked="checked"'; ?> /> |
|---|
| 168 |
<br /><small><?php _e('By unchecking this checkbox tracker will be not included on the page.', 'wp_iminr') ?></small> |
|---|
| 169 |
</td> |
|---|
| 170 |
</tr> |
|---|
| 171 |
<tr> |
|---|
| 172 |
<th nowrap valign="top"><label for="tracker_in_meta"><?php _e('Add in sidebar', 'wp_iminr') ?></label></th> |
|---|
| 173 |
<td valign="top"> |
|---|
| 174 |
<input type="radio" name="tracker_in" id="tracker_in_meta" value="meta" <?php if (wp_iminr_get_option('tracker_in_meta')) echo 'checked="checked"'; ?> /> |
|---|
| 175 |
<small><?php _e('By checking this radio button tracker will be included in meta (if template implemente this option).', 'wp_iminr') ?></small> |
|---|
| 176 |
<br /><input type="text" name="tracker_in_meta_before" id="tracker_in_meta_before" value="<?php echo wp_iminr_get_option('tracker_in_meta_before'); ?>" size="25" style="text-align: right;" /> |
|---|
| 177 |
<img src="" alt="iMinR" /> |
|---|
| 178 |
<input type="text" name="tracker_in_meta_after" id="tracker_in_meta_after" value="<?php echo wp_iminr_get_option('tracker_in_meta_after'); ?>" size="25" /> |
|---|
| 179 |
<br /><small><?php _e('This tags inclose iMinR javascript, useful with logo.', 'wp_iminr') ?></small> |
|---|
| 180 |
</td> |
|---|
| 181 |
</tr> |
|---|
| 182 |
<tr> |
|---|
| 183 |
<th nowrap valign="top"><label for="tracker_in_footer"><?php _e('Add in footer', 'wp_iminr') ?></label></th> |
|---|
| 184 |
<td valign="top"> |
|---|
| 185 |
<input type="radio" name="tracker_in" id="tracker_in_footer" value="footer" <?php if (wp_iminr_get_option('tracker_in_footer')) echo 'checked="checked"'; ?> /> |
|---|
| 186 |
<small><?php _e('By checking this radio button tracker will be included in footer.', 'wp_iminr') ?></small> |
|---|
| 187 |
<br /> |
|---|
| 188 |
<input type="text" name="tracker_in_footer_before" id="tracker_in_footer_before" value="<?php echo wp_iminr_get_option('tracker_in_footer_before'); ?>" size="25" style="text-align: right;" /> |
|---|
| 189 |
<img src="" alt="iMinR" /> |
|---|
| 190 |
<input type="text" name="tracker_in_footer_after" id="tracker_in_footer_after" value="<?php echo wp_iminr_get_option('tracker_in_footer_after'); ?>" size="25" /> |
|---|
| 191 |
<br /><small><?php _e('This tags inclose iMinR javascript, useful with logo.', 'wp_iminr') ?></small> |
|---|
| 192 |
</td> |
|---|
| 193 |
</tr> |
|---|
| 194 |
<tr> |
|---|
| 195 |
<th nowrap valign="top"><?php _e('Desable for roles', 'wp_iminr') ?></th> |
|---|
| 196 |
<td valign="top"> |
|---|
| 197 |
<select name="desable_for_roles[]" id="desable_for_roles" multiple="multiple"> |
|---|
| 198 |
<?php wp_iminr_roles_options_for_select(wp_iminr_get_option('desable_for_roles')); ?> |
|---|
| 199 |
</select> |
|---|
| 200 |
<br /><small><?php _e('Desable tracker for selected roles. Use CTRL+Click to select multiple entries', 'wp_iminr') ?></small> |
|---|
| 201 |
<?php |
|---|
| 202 |
?> |
|---|
| 203 |
</td> |
|---|
| 204 |
</tr> |
|---|
| 205 |
</table> |
|---|
| 206 |
|
|---|
| 207 |
</fieldset> |
|---|
| 208 |
|
|---|
| 209 |
<div class="submit"> |
|---|
| 210 |
<input type="submit" name="info_update" value="<?php _e('Update options', 'wp_iminr') ?>" /> |
|---|
| 211 |
</div></form> |
|---|
| 212 |
</div><?php |
|---|
| 213 |
} |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
function wp_iminr_roles_options_for_select( $default = array() ) { |
|---|
| 217 |
global $wp_roles; |
|---|
| 218 |
if (!is_array($default)) { |
|---|
| 219 |
$default = array($default); |
|---|
| 220 |
} |
|---|
| 221 |
|
|---|
| 222 |
foreach( $wp_roles->role_names as $role => $name ) { |
|---|
| 223 |
if (in_array($role, $default)) { |
|---|
| 224 |
$selected = 'selected="selected"'; |
|---|
| 225 |
} else { |
|---|
| 226 |
$selected = ''; |
|---|
| 227 |
} |
|---|
| 228 |
echo "\n\t<option $selected value='$role'>$name</option>"; |
|---|
| 229 |
} |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
function wp_iminr_enable_for_user() { |
|---|
| 234 |
foreach( wp_get_current_user()->roles as $role ) { |
|---|
| 235 |
if (in_array($role, wp_iminr_get_option('desable_for_roles'))) { |
|---|
| 236 |
return false; |
|---|
| 237 |
} |
|---|
| 238 |
} |
|---|
| 239 |
return true; |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
load_plugin_textdomain('wp_iminr','wp-content/plugins/wp_iminr/lang'); |
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
add_action('admin_menu', 'wp_iminr_admin'); |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
if ( wp_iminr_get_option('enable_tracker') && wp_iminr_get_option('tracker_in_meta') ) { |
|---|
| 253 |
add_action('wp_meta', 'wp_iminr_meta'); |
|---|
| 254 |
} elseif ( wp_iminr_get_option('enable_tracker') && wp_iminr_get_option('tracker_in_footer') ) { |
|---|
| 255 |
add_action('wp_footer', 'wp_iminr_footer'); |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
?> |
|---|