| 1 |
<?php
|
| 2 |
// $Id: addtofavorites.module,v 1.4 2007/05/06 16:25:04 thierrygd Exp $
|
| 3 |
|
| 4 |
// Copyright 2007 Thierry GUEGAN http://www.arvoriad.com
|
| 5 |
|
| 6 |
/**
|
| 7 |
* @file
|
| 8 |
* This module create a block for helping users to add the website to their
|
| 9 |
* browser's bookmarks.
|
| 10 |
*/
|
| 11 |
|
| 12 |
function addtofavorites_menu() {
|
| 13 |
$items = array();
|
| 14 |
|
| 15 |
$items['admin/settings/addtofavorites'] = array(
|
| 16 |
'title' => 'Add to favorites module',
|
| 17 |
'description' => 'Add to favorites module configuration.',
|
| 18 |
'page callback' => 'drupal_get_form',
|
| 19 |
'page arguments' => array('addtofavorites_admin_settings'),
|
| 20 |
'access arguments' => array('administer site configuration'),
|
| 21 |
'type' => MENU_NORMAL_ITEM,);
|
| 22 |
|
| 23 |
return $items;
|
| 24 |
}
|
| 25 |
|
| 26 |
function addtofavorites_admin_settings() {
|
| 27 |
$form = array();
|
| 28 |
|
| 29 |
$form['addtofavorites_config'] = array(
|
| 30 |
'#type' => 'fieldset',
|
| 31 |
'#title' => 'Addtofavorites Block Settings',
|
| 32 |
);
|
| 33 |
$form['addtofavorites_config']['addtofavorites_block_title'] = array(
|
| 34 |
'#type' => 'textfield',
|
| 35 |
'#title' => t('Block Title'),
|
| 36 |
'#default_value' => variable_get('addtofavorites_block_title', t("Add the website to your browser's favorites")),
|
| 37 |
'#size' => 70,
|
| 38 |
'#maxlength' => 128,
|
| 39 |
'#description' => t('This will be the title for the addfavorites block.'),
|
| 40 |
);
|
| 41 |
$form['addtofavorites_config']['addtofavorites_site_OK'] = array(
|
| 42 |
'#type' => 'checkbox',
|
| 43 |
'#title' => t('Enable site bookmarking'),
|
| 44 |
'#default_value' => variable_get('addtofavorites_site_OK', 1),
|
| 45 |
);
|
| 46 |
$form['addtofavorites_config']['addtofavorites_page_OK'] = array(
|
| 47 |
'#type' => 'checkbox',
|
| 48 |
'#title' => t('Enable page bookmarking'),
|
| 49 |
'#default_value' => variable_get('addtofavorites_page_OK', 1),
|
| 50 |
);
|
| 51 |
$form['addtofavorites_config']['addtofavorites_homepage_OK'] = array(
|
| 52 |
'#type' => 'checkbox',
|
| 53 |
'#title' => t('Enable making this website as homepage'),
|
| 54 |
'#default_value' => variable_get('addtofavorites_homepage_OK', 1),
|
| 55 |
);
|
| 56 |
$form['addtofavorites_config_links'] = array(
|
| 57 |
'#type' => 'fieldset',
|
| 58 |
'#title' => 'Addtofavorites Links Block Settings',
|
| 59 |
);
|
| 60 |
$form['addtofavorites_config_links']['addtofavorites_links'] = array(
|
| 61 |
'#type' => 'checkbox',
|
| 62 |
'#title' => t('Enable links'),
|
| 63 |
'#default_value' => variable_get('addtofavorites_links', 1),
|
| 64 |
);
|
| 65 |
$form['addtofavorites_config_links']['addtofavorites_site'] = array(
|
| 66 |
'#type' => 'textfield',
|
| 67 |
'#title' => t('Label for site bookmark link and icon alternate text'),
|
| 68 |
'#size' => 20,
|
| 69 |
'#maxlength' => 255,
|
| 70 |
'#default_value' => variable_get('addtofavorites_site', t('Bookmark this site')),
|
| 71 |
);
|
| 72 |
$form['addtofavorites_config_links']['addtofavorites_page'] = array(
|
| 73 |
'#type' => 'textfield',
|
| 74 |
'#title' => t('Label for current page bookmark link and icon alternate text'),
|
| 75 |
'#size' => 20,
|
| 76 |
'#maxlength' => 255,
|
| 77 |
'#default_value' => variable_get('addtofavorites_page', t('Bookmark this page'))
|
| 78 |
);
|
| 79 |
$form['addtofavorites_config_links']['addtofavorites_homepage'] = array(
|
| 80 |
'#type' => 'textfield',
|
| 81 |
'#title' => t("Label for current 'make this website as your homepage' link and icon alternate text"),
|
| 82 |
'#size' => 20,
|
| 83 |
'#maxlength' => 255,
|
| 84 |
'#default_value' => variable_get('addtofavorites_homepage', t('Make Us your homepage'))
|
| 85 |
);
|
| 86 |
$form['addtofavorites_config_icons'] = array(
|
| 87 |
'#type' => 'fieldset',
|
| 88 |
'#title' => 'Addtofavorites Icons Block Settings',
|
| 89 |
);
|
| 90 |
$form['addtofavorites_config_icons']['addtofavorites_icons'] = array(
|
| 91 |
'#type' => 'checkbox',
|
| 92 |
'#title' => t('Enable icons'),
|
| 93 |
'#default_value' => variable_get('addtofavorites_icons', 1),
|
| 94 |
);
|
| 95 |
|
| 96 |
return system_settings_form($form);
|
| 97 |
}
|
| 98 |
|
| 99 |
function addtofavorites_block($op = 'list', $delta = 0, $edit = array()) {
|
| 100 |
// The $op parameter determines what piece of information is being requested.
|
| 101 |
if ($op == 'list') {
|
| 102 |
// If $op is "list", we just need to return a list of block descriptions. This
|
| 103 |
// is used to provide a list of possible blocks to the administrator.
|
| 104 |
$blocks[0]['info'] = t("Addtofavorites : Help users to add this website to their browser's (IE, Mozilla, ...) bookmarks");
|
| 105 |
return $blocks;
|
| 106 |
}
|
| 107 |
else if ($op == 'save' && $delta == 0) {
|
| 108 |
variable_set('addtofavorites_block_title', $edit['addtofavorites_block_title']);
|
| 109 |
}
|
| 110 |
else if ($op == 'view') {
|
| 111 |
switch ($delta) {
|
| 112 |
case 0:
|
| 113 |
$block = array();
|
| 114 |
// If $op is "view", then we need to generate the block for display purposes.
|
| 115 |
// The $delta parameter tells us which block is being requested.
|
| 116 |
// The subject is displayed at the top of the block. Note that it should
|
| 117 |
// be passed through t() for translation.
|
| 118 |
$block['subject'] = variable_get('addtofavorites_block_title', t("Add the website to your browser's favorites"));
|
| 119 |
// The content of the block is typically generated by calling a custom
|
| 120 |
// function.
|
| 121 |
$sitename = variable_get('site_name', 'drupal');
|
| 122 |
$pagetitle = strip_tags(drupal_get_title());
|
| 123 |
$pagetitle = $pagetitle ? $pagetitle . ' | ' . $sitename : $sitename;
|
| 124 |
$siteurl = url('', array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE));
|
| 125 |
$display_links = variable_get('addtofavorites_links',1); //add the links or not
|
| 126 |
$display_site_OK = variable_get('addtofavorites_site_OK', 1); //bookmark the site or not
|
| 127 |
$display_text_site = variable_get('addtofavorites_site', t("Bookmark this site"));
|
| 128 |
$display_page_OK = variable_get('addtofavorites_page_OK', 1); //bookmark the page or not
|
| 129 |
$display_text_page = variable_get('addtofavorites_page', t("Bookmark this page"));
|
| 130 |
$display_icons = variable_get('addtofavorites_icons',1); //add the icons or not
|
| 131 |
$display_icon_site = base_path() . drupal_get_path('module', 'addtofavorites') ."/images/bookmark_site.gif";
|
| 132 |
$display_icon_page = base_path() . drupal_get_path('module', 'addtofavorites') ."/images/bookmark_page.gif";
|
| 133 |
$display_homepage_OK = variable_get('addtofavorites_homepage_OK', 1); //add the site to the browser's homepage
|
| 134 |
$display_text_homepage = variable_get('addtofavorites_homepage', t("Make Us your homepage"));
|
| 135 |
$display_icon_homepage = base_path() . drupal_get_path('module', 'addtofavorites') ."/images/set_homepage.gif";
|
| 136 |
|
| 137 |
|
| 138 |
$path = drupal_get_path('module', 'addtofavorites');
|
| 139 |
|
| 140 |
drupal_add_js($path . '/addtofavorites.js');
|
| 141 |
$links = "";
|
| 142 |
|
| 143 |
if ($display_site_OK) {
|
| 144 |
if ($display_icons) {
|
| 145 |
$links .= "<img src=\"" . $display_icon_site . "\"";
|
| 146 |
$links .= " alt=\"" . $display_text_site . "\" style=\"vertical-align:middle;\" />";
|
| 147 |
}
|
| 148 |
$links .= "<a href=\"#\" onclick=\"javascript:addtofavorites";
|
| 149 |
$links .= "('" . $siteurl . "','" . $sitename . "')\">";
|
| 150 |
if ($display_links) {
|
| 151 |
$links .= $display_text_site;
|
| 152 |
$links .= "<br />\n"; //if we don't display links then align horizontally the icons
|
| 153 |
}
|
| 154 |
$links .= "</a>";
|
| 155 |
}
|
| 156 |
if ($display_page_OK) {
|
| 157 |
if ($display_icons) {
|
| 158 |
$links .= "<img src=\"" . $display_icon_page . "\"";
|
| 159 |
$links .= " alt=\"" . $display_text_page . "\" style=\"vertical-align:middle;\" />";
|
| 160 |
}
|
| 161 |
$links .= "<a href=\"#\" onclick=\"javascript:addtofavorites";
|
| 162 |
$links .= "(top.location.href, '" . $pagetitle . "')\">";
|
| 163 |
if ($display_links) {
|
| 164 |
$links .= $display_text_page;
|
| 165 |
$links .= "<br />\n"; //if we don't display links then align horizontally the icons
|
| 166 |
}
|
| 167 |
$links .= "</a>";
|
| 168 |
}
|
| 169 |
if ($display_homepage_OK) {
|
| 170 |
if ($display_icons) {
|
| 171 |
$links .= "<img src=\"" . $display_icon_homepage . "\"";
|
| 172 |
$links .= " alt=\"" . $display_text_homepage . "\" style=\"vertical-align:middle;\" />";
|
| 173 |
}
|
| 174 |
$links .= "<a href=\"#\" ";
|
| 175 |
$links .= "onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('" . $siteurl . "')\">";
|
| 176 |
if ($display_links) {
|
| 177 |
$links .= $display_text_homepage;
|
| 178 |
}
|
| 179 |
$links .= "</a>";
|
| 180 |
}
|
| 181 |
$block['content'] = $links;
|
| 182 |
}
|
| 183 |
return $block;
|
| 184 |
}
|
| 185 |
}
|