source: sipes/cord/modules/path/path.module @ b354002

stableversion-3.0
Last change on this file since b354002 was b354002, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio del cord

  • Propiedad mode establecida a 100755
File size: 8.1 KB
Línea 
1<?php
2
3/**
4 * @file
5 * Enables users to rename URLs.
6 */
7
8/**
9 * Implementation of hook_help().
10 */
11function path_help($path, $arg) {
12  switch ($path) {
13    case 'admin/help#path':
14      $output = '<p>'. t('The path 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>';
15      $output .= t('<p>Some examples of URL aliases are:</p>
16<ul>
17<li>user/login =&gt; login</li>
18<li>image/tid/16 =&gt; store</li>
19<li>taxonomy/term/7+19+20+21 =&gt; store/products/whirlygigs</li>
20<li>node/3 =&gt; contact</li>
21</ul>
22');
23      $output .= '<p>'. t('The path 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>';
24      $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>';
25      $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@path">Path module</a>.', array('@path' => 'http://drupal.org/handbook/modules/path/')) .'</p>';
26      return $output;
27    case 'admin/build/path':
28      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 path 'node/1', creating a more meaningful URL. Each system path can have multiple aliases.") .'</p>';
29    case 'admin/build/path/add':
30      return '<p>'. t('Enter the path you wish to create the alias for, followed by the name of the new alias.') .'</p>';
31  }
32}
33
34/**
35 * Implementation of hook_menu().
36 */
37function path_menu() {
38  $items['admin/build/path'] = array(
39    'title' => 'URL aliases',
40    'description' => "Change your site's URL paths by aliasing them.",
41    'page callback' => 'path_admin_overview',
42    'access arguments' => array('administer url aliases'),
43    'file' => 'path.admin.inc',
44  );
45  $items['admin/build/path/edit'] = array(
46    'title' => 'Edit alias',
47    'page callback' => 'path_admin_edit',
48    'access arguments' => array('administer url aliases'),
49    'type' => MENU_CALLBACK,
50    'file' => 'path.admin.inc',
51  );
52  $items['admin/build/path/delete'] = array(
53    'title' => 'Delete alias',
54    'page callback' => 'drupal_get_form',
55    'page arguments' => array('path_admin_delete_confirm'),
56    'access arguments' => array('administer url aliases'),
57    'type' => MENU_CALLBACK,
58    'file' => 'path.admin.inc',
59  );
60  $items['admin/build/path/list'] = array(
61    'title' => 'List',
62    'type' => MENU_DEFAULT_LOCAL_TASK,
63    'weight' => -10,
64  );
65  $items['admin/build/path/add'] = array(
66    'title' => 'Add alias',
67    'page callback' => 'path_admin_edit',
68    'access arguments' => array('administer url aliases'),
69    'type' => MENU_LOCAL_TASK,
70    'file' => 'path.admin.inc',
71  );
72
73  return $items;
74}
75
76/**
77 * Post-confirmation; delete an URL alias.
78 */
79function path_admin_delete($pid = 0) {
80  db_query('DELETE FROM {url_alias} WHERE pid = %d', $pid);
81  drupal_set_message(t('The alias has been deleted.'));
82}
83
84/**
85 * Set an aliased path for a given Drupal path, preventing duplicates.
86 */
87function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') {
88  $path = urldecode($path);
89  $alias = urldecode($alias);
90  // First we check if we deal with an existing alias and delete or modify it based on pid.
91  if ($pid) {
92    // An existing alias.
93    if (!$path || !$alias) {
94      // Delete the alias based on pid.
95      db_query('DELETE FROM {url_alias} WHERE pid = %d', $pid);
96    }
97    else {
98      // Update the existing alias.
99      db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE pid = %d", $path, $alias, $language, $pid);
100    }
101  }
102  else if ($path && $alias) {
103    // Check for existing aliases.
104    if ($alias == drupal_get_path_alias($path, $language)) {
105      // There is already such an alias, neutral or in this language.
106      // Update the alias based on alias; setting the language if not yet done.
107      db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE dst = '%s'", $path, $alias, $language, $alias);
108    }
109    else {
110      // A new alias. Add it to the database.
111      db_query("INSERT INTO {url_alias} (src, dst, language) VALUES ('%s', '%s', '%s')", $path, $alias, $language);
112    }
113  }
114  else {
115    // Delete the alias.
116    if ($alias) {
117      db_query("DELETE FROM {url_alias} WHERE dst = '%s'", $alias);
118    }
119    else {
120      db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path);
121    }
122  }
123  drupal_clear_path_cache();
124}
125
126
127/**
128 * Implementation of hook_nodeapi().
129 *
130 * Allows URL aliases for nodes to be specified at node edit time rather
131 * than through the administrative interface.
132 */
133function path_nodeapi(&$node, $op, $arg) {
134  // Permissions are required for everything except node loading.
135  if (user_access('create url aliases') || user_access('administer url aliases') || ($op == 'load')) {
136    $language = isset($node->language) ? $node->language : '';
137    switch ($op) {
138      case 'validate':
139        if (isset($node->path)) {
140          $node->path = trim($node->path);
141          if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) {
142            form_set_error('path', t('The path is already in use.'));
143          }
144        }
145        break;
146
147      case 'load':
148        $path = 'node/'. $node->nid;
149        $alias = drupal_get_path_alias($path, $language);
150        if ($path != $alias) {
151          $node->path = $alias;
152        }
153        break;
154
155      case 'insert':
156        // Don't try to insert if path is NULL. We may have already set
157        // the alias ahead of time.
158        if (isset($node->path)) {
159          path_set_alias('node/'. $node->nid, $node->path, NULL, $language);
160        }
161        break;
162
163      case 'update':
164        path_set_alias('node/'. $node->nid, isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language);
165        break;
166
167      case 'delete':
168        $path = 'node/'. $node->nid;
169        if (drupal_get_path_alias($path) != $path) {
170          path_set_alias($path);
171        }
172        break;
173    }
174  }
175}
176
177/**
178 * Implementation of hook_form_alter().
179 */
180function path_form_alter(&$form, $form_state, $form_id) {
181  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
182    $path = isset($form['#node']->path) ? $form['#node']->path : NULL;
183    $form['path'] = array(
184      '#type' => 'fieldset',
185      '#title' => t('URL path settings'),
186      '#collapsible' => TRUE,
187      '#collapsed' => empty($path),
188      '#access' => user_access('create url aliases'),
189      '#weight' => 30,
190    );
191    $form['path']['path'] = array(
192      '#type' => 'textfield',
193      '#default_value' => $path,
194      '#maxlength' => 128,
195      '#collapsible' => TRUE,
196      '#collapsed' => TRUE,
197      '#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 path and don\'t add a trailing slash or the URL alias won\'t work.'),
198    );
199    if ($path) {
200      $form['path']['pid'] = array(
201        '#type' => 'value',
202        '#value' => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $path, $form['#node']->language))
203      );
204    }
205  }
206}
207
208/**
209 * Implementation of hook_perm().
210 */
211function path_perm() {
212  return array('create url aliases', 'administer url aliases');
213}
214
215/**
216 * Fetch a specific URL alias from the database.
217 */
218function path_load($pid) {
219  return db_fetch_array(db_query('SELECT * FROM {url_alias} WHERE pid = %d', $pid));
220}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.