| 1 |
<?php
|
| 2 |
|
| 3 |
/* $Id: mybloglog.module,v 1.1 2007/01/07 19:20:17 inactivist Exp $ */
|
| 4 |
|
| 5 |
/**
|
| 6 |
* DESCRIPTION:
|
| 7 |
*
|
| 8 |
*
|
| 9 |
* Copyright (c) 2006 Exodus Development, Inc. All Rights Reserved.
|
| 10 |
* Licensed under the terms of the GNU Public License (GPL) version 2. Please see LICENSE.txt for
|
| 11 |
* license terms. Posession and use of this code signifies acceptance of license
|
| 12 |
* terms.
|
| 13 |
*
|
| 14 |
* Visit Exodus Development at
|
| 15 |
* http://exodusdev.com exodusdev@gmail.com
|
| 16 |
*
|
| 17 |
* Project homepage:
|
| 18 |
* http://exodusdev.com/drupal/4.7/modules/mybloglog.module
|
| 19 |
*/
|
| 20 |
|
| 21 |
|
| 22 |
define('MYBLOGLOG_DEBUG', FALSE); // if TRUE, will show content always (for testing)
|
| 23 |
|
| 24 |
define('MYBLOGLOG_READMORE_TWEAK_DEFAULT', FALSE);
|
| 25 |
define('MYBLOGLOG_READMORE_INLINE_DEFAULT', FALSE);
|
| 26 |
|
| 27 |
define('MYBLOGLOG_MODULE_VERSION', '$Id: mybloglog.module,v 1.1 2007/01/07 19:20:17 inactivist Exp $' );
|
| 28 |
|
| 29 |
define('MYBLOGLOG_SCRIPT_TRACKER_NAME', 'mybloglog_tracker.js');
|
| 30 |
|
| 31 |
define('MYBLOGLOG_CFG_BLOG_ID', 'mybloglog_blog_id');
|
| 32 |
define('MYBLOGLOG_CFG_TRACKING_SCRIPT', 'mybloglog_tracking_script');
|
| 33 |
define('MYBLOGLOG_CFG_TRACKING_SERVER', 'mybloglog_tracking_server');
|
| 34 |
define('MYBLOGLOG_CFG_SCRIPTS_GENERATED', 'mybloglog_scriptgen');
|
| 35 |
define('MYBLOGLOG_CFG_SETTINGS_CHANGED', 'mybloglog_settingschanged');
|
| 36 |
define('MYGLOGLOG_CFG_VISITOR_BLOCK_TITLE', 'mybloglog_block_title_visitor');
|
| 37 |
|
| 38 |
define('MYBLOGLOG_TRACKING_SCRIPT_DEFAULT', '<script type="text/javascript" src="http://%tracking_server/js/jsserv.php?mblID=%blog_id"></script>');
|
| 39 |
define('MYBLOGLOG_TRACKING_SERVER_DEFAULT', '');
|
| 40 |
define('MYBLOGLOG_VISITOR_WIDGET_SCRIPT_DEFAULT', '<script type="text/javascript" src="http://pub.mybloglog.com/comm2.php?mblID=%blog_id&c_width=%widget_c_width&c_sn_opt=%widget_c_sn_opt&c_rows=%widget_c_rows&c_img_size=%widget_c_img_size&c_heading_text=%widget_c_heading_text&c_color_heading_bg=%widget_c_color_heading_bg&c_color_heading=%widget_c_color_heading&c_color_link_bg=%widget_c_color_link_bg&c_color_link=%widget_c_color_link&c_color_bottom_bg=%widget_c_color_bottom_bg"></script>');
|
| 41 |
|
| 42 |
function _mybloglog_widget_vars() {
|
| 43 |
static $_mybloglog_widget_var_list
|
| 44 |
= array(
|
| 45 |
'c_width' => array(180, 'Width of the visitor block'),
|
| 46 |
'c_sn_opt' => array('y', 'Show screen names (y) or (n)?'),
|
| 47 |
'c_img_size' => array('f', 'Show (f)ull or (h)alf sized icons?'), // f=full, h=half.
|
| 48 |
'c_rows' => array(5, 'Number of rows'),
|
| 49 |
'c_heading_text' => array('Recent Readers', 'Heading text'),
|
| 50 |
'c_color_heading' => array('ffffff', 'Heading color'),
|
| 51 |
'c_color_heading_bg' => array('005a94', 'Heading background color'),
|
| 52 |
'c_color_link' => array('005A94', 'Link color'),
|
| 53 |
'c_color_link_bg' => array('E3E3E3', 'Link background color'),
|
| 54 |
'c_color_bottom_bg' => array('005A94', 'Bottom background color')
|
| 55 |
);
|
| 56 |
return $_mybloglog_widget_var_list;
|
| 57 |
}
|
| 58 |
|
| 59 |
/**
|
| 60 |
* Implementation of hook_help().
|
| 61 |
*/
|
| 62 |
function mybloglog_help($section) {
|
| 63 |
switch ($section) {
|
| 64 |
case 'admin/modules#description':
|
| 65 |
return t('Inserts <strong><a target="_blank" href="http://www.mybloglog.com">MyBlogLog</a></strong> tracking scripts, and provides some basic blocks.');
|
| 66 |
}
|
| 67 |
}
|
| 68 |
|
| 69 |
function mybloglog_menu($may_cache) {
|
| 70 |
if (!$may_cache) {
|
| 71 |
// inject our stuff per http://api.drupal.org/api/HEAD/function/hook_init and http://api.drupal.org/api/HEAD/function/hook_menu
|
| 72 |
if ( _mybloglog_allow_tracking_injection())
|
| 73 |
_mybloglog_add_js(); // inject javascript, just once
|
| 74 |
}
|
| 75 |
|
| 76 |
}
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Implementation of hook_perm().
|
| 80 |
*/
|
| 81 |
function mybloglog_perm() {
|
| 82 |
return array('Disable MyBlogLog Visitor Tracking');
|
| 83 |
}
|
| 84 |
|
| 85 |
/**
|
| 86 |
* Should we show block content? Not if admin or user is in a role that
|
| 87 |
* is marked as disabled
|
| 88 |
*/
|
| 89 |
function _mybloglog_show_block_content() {
|
| 90 |
return MYBLOGLOG_DEBUG || !user_access('Disable MyBlogLog Visitor Tracking');
|
| 91 |
}
|
| 92 |
|
| 93 |
/**
|
| 94 |
* Should we inject the tracking script?
|
| 95 |
*/
|
| 96 |
|
| 97 |
function _mybloglog_allow_tracking_injection() {
|
| 98 |
return MYBLOGLOG_DEBUG || !user_access('Disable MyBlogLog Visitor Tracking');
|
| 99 |
}
|
| 100 |
|
| 101 |
function _mybloglog_makepath($filename) {
|
| 102 |
return file_create_path($filename);
|
| 103 |
}
|
| 104 |
|
| 105 |
function _mybloglog_get_widget_varname($name) {
|
| 106 |
return "mybloglog_widget_$name";
|
| 107 |
}
|
| 108 |
|
| 109 |
function _mybloglog_get_widget_template_varname($name) {
|
| 110 |
return "%widget_$name";
|
| 111 |
}
|
| 112 |
|
| 113 |
/**
|
| 114 |
* Get a widget variable value from the variable store, given the name of the url parameter used in the widget script.
|
| 115 |
*/
|
| 116 |
function _mybloglog_get_widget_var($name, $defvalue) {
|
| 117 |
return trim(variable_get(_mybloglog_get_widget_varname($name), $defvalue));
|
| 118 |
}
|
| 119 |
|
| 120 |
|
| 121 |
function _mybloglog_add_widget_cfg(&$array, $name, $defvalue) {
|
| 122 |
$array[_mybloglog_get_widget_template_varname($name)] = _mybloglog_get_widget_var($name, $defvalue);
|
| 123 |
}
|
| 124 |
|
| 125 |
function _mybloglog_get_template_vars() {
|
| 126 |
|
| 127 |
|
| 128 |
// todo: use static; get only if config changed.
|
| 129 |
$keywords =
|
| 130 |
array('%blog_id' => trim(variable_get(MYBLOGLOG_CFG_BLOG_ID, '')),
|
| 131 |
'%tracking_server' => trim(variable_get(MYBLOGLOG_CFG_TRACKING_SERVER, MYBLOGLOG_TRACKING_SERVER_DEFAULT)));
|
| 132 |
// now add in all the widget config vars
|
| 133 |
$widget_vars = _mybloglog_widget_vars();
|
| 134 |
foreach ($widget_vars as $key => $v) {
|
| 135 |
_mybloglog_add_widget_cfg($keywords, $key, $v[0]);
|
| 136 |
//$keywords[_mybloglog_get_widget_template_varname($name)] = _mybloglog_get_widget_var($key, $v);
|
| 137 |
}
|
| 138 |
return $keywords;
|
| 139 |
}
|
| 140 |
|
| 141 |
function _mybloglog_get_visitor_widget() {
|
| 142 |
return strtr(variable_get(MYBLOGLOG_CFG_VISITOR_WIDGET_SCRIPT, MYBLOGLOG_VISITOR_WIDGET_SCRIPT_DEFAULT), _mybloglog_get_template_vars());
|
| 143 |
}
|
| 144 |
|
| 145 |
|
| 146 |
/**
|
| 147 |
* Inject tracking javascript, if possible.
|
| 148 |
* Per MyBlogLog instructions, should inject right after opening
|
| 149 |
* <body> tag.
|
| 150 |
*/
|
| 151 |
function _mybloglog_add_js() {
|
| 152 |
static $mybloglog_add_js_add = true;
|
| 153 |
if ($mybloglog_add_js_add) {
|
| 154 |
// _mybloglog_generate_static_scripts();
|
| 155 |
$script = strtr(variable_get(MYBLOGLOG_CFG_TRACKING_SCRIPT, MYBLOGLOG_TRACKING_SCRIPT_DEFAULT), _mybloglog_get_template_vars());
|
| 156 |
drupal_set_html_head($script); // this will put this in <head> - MyBlogLog site says it should be first thing after <body>
|
| 157 |
// drupal_add_js(_mybloglog_tracking_script_name()); // TODO: need to create this file on settings change.
|
| 158 |
$mybloglog_add_js_add = false;
|
| 159 |
}
|
| 160 |
}
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
/**
|
| 165 |
* Implementation of hook_settings
|
| 166 |
* TODO: add config variable to disable injection/tracking for admin (user 0) and roles (use access rules?)
|
| 167 |
*/
|
| 168 |
function mybloglog_settings() {
|
| 169 |
$form['module_banner'] = array('#type' => 'markup',
|
| 170 |
'#value' => '<div style="border: solid 1px #eee; margin: .5em; padding: .5em;" <strong>Module development sponsored by <a href="http://exodusdev.com">Exodus Development</a></strong><br/>');
|
| 171 |
$form['module_id'] = array('#type' => 'markup', '#value' => MYBLOGLOG_MODULE_VERSION .'<br/></div>');
|
| 172 |
|
| 173 |
$form['mybloglog_blog_id'] =
|
| 174 |
array('#type' => 'textfield',
|
| 175 |
'#title'=> t('Mybloglog blog id'),
|
| 176 |
'#default_value' => variable_get(MYBLOGLOG_CFG_BLOG_ID, NULL),
|
| 177 |
'#description' => t('Enter your Mybloglog id here. This is the mblID # that is assigned to your blog, You can find this value by viewing your site settings, and looking at the provided tracking script (look for the mblID={number} in the script.)'),
|
| 178 |
'#required'=>TRUE);
|
| 179 |
|
| 180 |
$form[MYBLOGLOG_CFG_TRACKING_SERVER] =
|
| 181 |
array('#type' => 'textfield',
|
| 182 |
'#title' => t('MyMybloglog tracking server'),
|
| 183 |
'#default_value' => variable_get(MYBLOGLOG_CFG_TRACKING_SERVER, MYBLOGLOG_TRACKING_SERVER_DEFAULT),
|
| 184 |
'#description' => t('MyBlogLog tracking server name. This is the one specified in the script provided by MyBlogLog.com. Usually in the form of track{n}.mybloglog.com, where {n} is a numeric value. You can find this value by viewing your site settings, and looking at the provided tracking script.'),
|
| 185 |
'#required' => TRUE);
|
| 186 |
|
| 187 |
// now add in all the widget config vars
|
| 188 |
//$form['widget_config'] =
|
| 189 |
// array(
|
| 190 |
|
| 191 |
$form['vwb'] = array(
|
| 192 |
'#type' => 'fieldset',
|
| 193 |
'#collapsible' => TRUE,
|
| 194 |
'#collapsed' => TRUE,
|
| 195 |
'#title' => t('Visitor Widget Block Configuration'),
|
| 196 |
'#description' => t('Variables that affect the visitor widget'),
|
| 197 |
);
|
| 198 |
|
| 199 |
$widget_vars = _mybloglog_widget_vars();
|
| 200 |
|
| 201 |
foreach ($widget_vars as $key => $v) {
|
| 202 |
// _mybloglog_add_widget_cfg($keywords, $key, $v[0]);
|
| 203 |
$form['vwb'][_mybloglog_get_widget_varname($key)] =
|
| 204 |
array('#type' => 'textfield',
|
| 205 |
'#title' => $v[1],
|
| 206 |
'#default_value' => _mybloglog_get_widget_var($key, $v[0]),
|
| 207 |
'#required' => TRUE);
|
| 208 |
}
|
| 209 |
|
| 210 |
/*
|
| 211 |
$form['templates'] = array(
|
| 212 |
'#type' => 'fieldset',
|
| 213 |
'#collapsible' => TRUE,
|
| 214 |
'#collapsed' => FALSE,// TRUE
|
| 215 |
'#title' => t('Insertion templates - For advanced users'),
|
| 216 |
);
|
| 217 |
|
| 218 |
$form['templates'][MYBLOGLOG_CFG_TRACKING_SCRIPT] =
|
| 219 |
array('#type' => 'textarea',
|
| 220 |
'#title'=> t('Tracking script'),
|
| 221 |
'#rows' => 3,
|
| 222 |
'#cols' => 40,
|
| 223 |
'#default_value' => variable_get(MYBLOGLOG_CFG_TRACKING_SCRIPT, MYBLOGLOG_TRACKING_SCRIPT_DEFAULT),
|
| 224 |
'#description' => t('Tracking script to be injected into each page. Use %blog_id to insert the blog id, and %tracking_server for the tracking server'),
|
| 225 |
'#required' => TRUE);
|
| 226 |
*/
|
| 227 |
|
| 228 |
// IMPORTANT: this field is needed so we know if we need to regenerate static scripts.
|
| 229 |
// do not remove!
|
| 230 |
// $form[MYBLOGLOG_CFG_SETTINGS_CHANGED] = array('#type' => 'hidden', '#value' => time());
|
| 231 |
|
| 232 |
return $form;
|
| 233 |
}
|
| 234 |
|
| 235 |
/**
|
| 236 |
* Implementation of hook_block
|
| 237 |
*/
|
| 238 |
|
| 239 |
function mybloglog_block($op = 'list', $delta = 0, $edit = array()) {
|
| 240 |
if ($op == 'list') {
|
| 241 |
$blocks[0]['info'] = t('MyBlogLog - Visitor Widget');
|
| 242 |
return $blocks;
|
| 243 |
}
|
| 244 |
else if ($op == 'configure') {
|
| 245 |
// OPTIONAL: Enter form elements to add to block configuration screen, if required.
|
| 246 |
}
|
| 247 |
else if ($op == 'save') {
|
| 248 |
// OPTIONAL: Add code to trigger when block configuration is saved, if required.
|
| 249 |
}
|
| 250 |
else if ($op == 'view') {
|
| 251 |
switch ($delta) {
|
| 252 |
case 0:
|
| 253 |
if (_mybloglog_show_block_content()) {
|
| 254 |
$content = _mybloglog_get_visitor_widget();
|
| 255 |
}
|
| 256 |
else {
|
| 257 |
$content = t('Block disabled due to access settings');
|
| 258 |
}
|
| 259 |
$block['subject'] = variable_get(MYBLOGLOG_CFG_VISITOR_BLOCK_TITLE, t('Recent Visitors'));
|
| 260 |
$block['content'] = $content;
|
| 261 |
break;
|
| 262 |
// OPTIONAL: Enter additional cases for each additional block, if defined.
|
| 263 |
}
|
| 264 |
return $block;
|
| 265 |
}
|
| 266 |
}
|