Home > drupal > custom module in drupal

custom module in drupal

<?php
// $Id: muthu.module,v 1.138.2.3 2008/11/22 10:49:15 dries Exp $

/**
* @file
* Enables users to rename URLs.
*/

/**
* Implementation of hook_help().
*/
function muthu_help($muthu, $arg) {
switch ($muthu) {
case ‘admin/help#muthu’:
$output = ‘<p>’. t(‘The muthu module allows you to specify aliases for Drupal URLs. Such aliases improve readability of URLs for your users and may help internet search engines to index your content more effectively. More than one alias may be created for a given page.’) .’</p>’;
$output .= t(‘<p>Some examples of URL aliases are:</p>
<ul>
<li>user/login =&gt; login</li>
<li>image/tid/16 =&gt; store</li>
<li>taxonomy/term/7+19+20+21 =&gt; store/products/whirlygigs</li>
<li>node/3 =&gt; contact</li>
</ul>
‘);
$output .= ‘<p>’. t(‘The muthu module enables appropriately permissioned users to specify an optional alias in all node input and editing forms, and provides an interface to view and edit all URL aliases. The two permissions related to URL aliasing are <em>administer url aliases</em> and <em>create url aliases</em>. ‘) .’</p>’;
$output .= ‘<p>’. t(‘This module also provides user-defined mass URL aliasing capabilities, which is useful if you wish to uniformly use URLs different from the default. For example, you may want to have your URLs presented in a different language. Access to the Drupal source code on the web server is required to set up mass URL aliasing. ‘) .’</p>’;
$output .= ‘<p>’. t(‘For more information, see the online handbook entry for <a href=”@muthu”>muthu module</a>.’, array(‘@muthu’ => ‘http://drupal.org/handbook/modules/muthu/’)) .’</p>’;
return $output;
case ‘admin/build/muthu’:
return ‘<p>’. t(“Drupal provides complete control over URLs through aliasing, which is often used to make URLs more readable or easy to remember. For example, the alias ‘about’ may be mapped onto the post at the system muthu ‘node/1′, creating a more meaningful URL. Each system muthu can have multiple aliases.”) .’</p>’;
case ‘admin/build/muthu/add’:
return ‘<p>’. t(‘Enter the muthu you wish to create the alias for, followed by the name of the new alias.’) .’</p>’;
}
}

/**
* Implementation of hook_menu().
*/
function muthu_menu() {

$items['mutu'] = array(
‘path’ => ‘mutu’,
‘title’ => ‘mutu alias’,
‘page callback’ => ‘drupal_get_form’,
‘page arguments’ => array(‘muthu_admin_delete_confirm’),
‘access arguments’ => array(‘administer url aliases’),
);

return $items;
}

/**
* Post-confirmation; delete an URL alias.
*/
function muthu_admin_delete_confirm() {
$options = array(‘1′ => t(‘Enabled’), ‘0′ => t(‘Disabled’));
$form['access'] = array(
‘#type’ => ‘fieldset’,
‘#title’ => t(‘Access log settings’),
‘#tree’ => TRUE,
);
$form['access']['log'] = array(
‘#type’ => ‘radios’,
‘#title’ => t(‘Log’),
‘#default_value’ =>  variable_get(‘log’, 0),
‘#options’ => $options,
‘#description’ => t(‘The log.’),
);
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), ‘format_interval’);
$form['access']['timer'] = array(
‘#type’ => ’select’,
‘#title’ => t(‘Discard logs older than’),
‘#default_value’ => variable_get(‘timer’, 259200),
‘#options’ => $period,
‘#description’ => t(‘The timer.’),
);
// Description
$form['details'] = array(
‘#type’ => ‘fieldset’,
‘#title’ => t(‘Details’),
‘#collapsible’ => TRUE,
‘#collapsed’ => TRUE,
);
$form['details']['description'] = array(
‘#type’ => ‘textarea’,
‘#title’ => t(‘Describe it’),
‘#default_value’ =>  variable_get(‘description’, ”),
‘#cols’ => 60,
‘#rows’ => 5,
‘#description’ => t(‘Log description.’),
);
$form['details']['admin'] = array(
‘#type’ => ‘checkbox’,
‘#title’ => t(‘Only admin can view’),
‘#default_value’ => variable_get(‘admin’, 0),
);
$form['name'] = array(
‘#type’ => ‘textfield’,
‘#title’ => t(‘Name’),
‘#size’ => 30,
‘#maxlength’ => 64,
‘#description’ => t(‘Enter the name for this group of settings’),
);
$form['hidden'] = array(‘#type’ => ‘value’, ‘#value’ => ‘is_it_here’);
$form['submit'] = array(‘#type’ => ’submit’, ‘#value’ => t(‘Save’));

$forms['aaa']=array(‘#value’ =>’<script>javascript:alert(“”);</script>’);
return $forms;

}

function muthu_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .’_node_form’ == $form_id) {
$muthu = isset($form['#node']->muthu) ? $form['#node']->muthu : NULL;
$form['muthu'] = array(
‘#type’ => ‘fieldset’,
‘#title’ => t(‘URL muthu settings’),
‘#collapsible’ => TRUE,
‘#collapsed’ => empty($muthu),
‘#access’ => user_access(‘create url aliases’),
‘#weight’ => 30,
);
$form['muthu']['muthu'] = array(
‘#type’ => ‘textfield’,
‘#default_value’ => $muthu,
‘#maxlength’ => 128,
‘#collapsible’ => TRUE,
‘#collapsed’ => TRUE,
‘#description’ => t(‘Optionally specify an alternative URL by which this node can be accessed. For example, type “about” when writing an about page. Use a relative muthu and don\’t add a trailing slash or the URL alias won\’t work.’),
);
if ($muthu) {
$form['muthu']['pid'] = array(
‘#type’ => ‘value’,
‘#value’ => db_result(db_query(“SELECT pid FROM {url_alias} WHERE dst = ‘%s’ AND language = ‘%s’”, $muthu, $form['#node']->language))
);
}
}
}

/**
* Implementation of hook_perm().
*/
function muthu_perm() {
return array(‘create url aliases’, ‘administer url aliases’);
}

Categories: drupal
  1. No comments yet.
  1. No trackbacks yet.