[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/xmlsitemap/xmlsitemap_custom/ -> xmlsitemap_custom.admin.inc (source)

   1  <?php
   2  // $Id: xmlsitemap_custom.admin.inc,v 1.1.2.21 2010/04/30 03:31:26 davereid Exp $
   3  
   4  /**
   5   * @file
   6   * Administrative page callbacks for the xmlsitemap_custom module.
   7   */
   8  
   9  function xmlsitemap_custom_list_links() {
  10    $header = array(
  11      'loc' => array('data' => t('Location'), 'field' => 'loc', 'sort' => 'asc'),
  12      'priority' => array('data' => t('Priority'), 'field' => 'priority'),
  13      'changefreq' => array('data' => t('Change frequency'), 'field' => 'changefreq'),
  14      'language' => array('data' => t('Language'), 'field' => 'language'),
  15      'operations' => array('data' => t('Operations')),
  16    );
  17    // Do not include the language column if locale is disabled.
  18    if (!module_exists('locale')) {
  19      unset($header['language']);
  20    }
  21  
  22    $rows = array();
  23    $destination = drupal_get_destination();
  24  
  25    $sql = "SELECT * FROM {xmlsitemap} WHERE type = 'custom'";
  26    $sql .= tablesort_sql($header);
  27    $query = pager_query($sql, 50);
  28  
  29    while ($link = db_fetch_object($query)) {
  30      $row = array();
  31      $row['loc'] = l($link->loc, $link->loc);
  32      $row['priority'] = number_format($link->priority, 1);
  33      $row['changefreq'] = $link->changefreq ? drupal_ucfirst(xmlsitemap_get_changefreq($link->changefreq)) : t('None');
  34      if (isset($header['language'])) {
  35        $row['language'] = module_invoke('locale', 'language_name', $link->language);
  36      }
  37      $operations = array();
  38      $operations['edit'] = array(
  39        'title' => t('Edit'),
  40        'href' => 'admin/settings/xmlsitemap/custom/edit/' . $link->id,
  41        'query' => $destination,
  42      );
  43      $operations['delete'] = array(
  44        'title' => t('Delete'),
  45        'href' => 'admin/settings/xmlsitemap/custom/delete/' . $link->id,
  46        'query' => $destination,
  47      );
  48      $row['operations'] = theme('links', $operations, array('class' => 'links inline nowrap'));
  49      $rows[] = $row;
  50    }
  51  
  52    if (empty($rows)) {
  53      $rows[] = array(
  54        array(
  55          'data' => t('No custom links available.') . ' ' . l(t('Add custom link'), 'admin/settings/xmlsitemap/custom/add', array('query' => $destination)),
  56          'colspan' => count($header),
  57        ),
  58      );
  59    }
  60  
  61    $output = theme('table', $header, $rows);
  62    $output .= theme('pager', NULL, 50, 0);
  63    return $output;
  64  }
  65  
  66  function xmlsitemap_custom_edit_link_form($form_state, $link = array()) {
  67    module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
  68    _xmlsitemap_set_breadcrumb('admin/settings/xmlsitemap/custom');
  69  
  70    $link += array(
  71      'id' => db_result(db_query("SELECT MAX(id) FROM {xmlsitemap} WHERE type = 'custom'")) + 1,
  72      'loc' => '',
  73      'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
  74      'lastmod' => 0,
  75      'changefreq' => 0,
  76      'changecount' => 0,
  77      'language' => '',
  78    );
  79  
  80    $form['type'] = array(
  81      '#type' => 'value',
  82      '#value' => 'custom',
  83    );
  84    $form['id'] = array(
  85      '#type' => 'value',
  86      '#value' => $link['id'],
  87    );
  88    $form['loc'] = array(
  89      '#type' => 'textfield',
  90      '#title' => t('Path to link'),
  91      '#field_prefix' => url('', array('absolute' => TRUE)),
  92      '#default_value' => $link['loc'] ? drupal_get_path_alias($link['loc'], $link['language']) : '',
  93      '#required' => TRUE,
  94      '#size' => 30,
  95    );
  96    $form['priority'] = array(
  97      '#type' => 'select',
  98      '#title' => t('Priority'),
  99      '#options' => xmlsitemap_get_priority_options(),
 100      '#default_value' => number_format($link['priority'], 1),
 101      '#description' => t('The priority of this URL relative to other URLs on your site.'),
 102    );
 103    $form['changefreq'] = array(
 104      '#type' => 'select',
 105      '#title' => t('Change frequency'),
 106      '#options' => array(0 => t('None')) + xmlsitemap_get_changefreq_options(),
 107      '#default_value' => $link['changefreq'],
 108      '#description' => t('How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page.'),
 109    );
 110    $languages = module_exists('locale') ? locale_language_list() : array();
 111    $form['language'] = array(
 112      '#type' => 'select',
 113      '#title' => t('Language'),
 114      '#default_value' => $link['language'],
 115      '#options' => array('' => t('Language neutral')) + $languages,
 116      '#access' => $languages,
 117    );
 118  
 119    $form['actions'] = array(
 120      //'#type' => 'container',
 121      //'#attributes' => array('class' => array('form-actions')),
 122      '#weight' => 100,
 123    );
 124    $form['actions']['submit'] = array(
 125      '#type' => 'submit',
 126      '#value' => t('Save'),
 127      '#weight' => 5,
 128    );
 129    $form['actions']['cancel'] = array(
 130      '#value' => l(t('Cancel'), 'admin/settings/xmlsitemap/custom'),
 131      '#weight' => 10,
 132    );
 133  
 134    return $form;
 135  }
 136  
 137  function xmlsitemap_custom_edit_link_form_validate($form, &$form_state) {
 138    $link = &$form_state['values'];
 139  
 140    // Make sure we trim and normalize the path first.
 141    $link['loc'] = trim($link['loc']);
 142    $link['loc'] = drupal_get_normal_path($link['loc'], $link['language']);
 143  
 144    // Test anonymous user access to the custom link paths.
 145    xmlsitemap_switch_user(0);
 146    $menu_item = menu_get_item($link['loc']);
 147    xmlsitemap_restore_user();
 148  
 149    // Since the menu item access results are cached, manually check the current path.
 150    if ($menu_item && strpos($link['loc'], 'admin/settings/xmlsitemap/custom') === 0 && !user_access('administer xmlsitemap', drupal_anonymous_user())) {
 151      $menu_item['access'] = FALSE;
 152    }
 153  
 154    if (db_result(db_query_range("SELECT 1 FROM {xmlsitemap} WHERE type <> 'custom' AND loc = '%s' AND status = 1 AND access = 1 AND language IN ('%s', '')", $link['loc'], $link['language'], 0, 1))) {
 155      form_set_error('loc', t('There is already an existing link in the sitemap with the path %link.', array('%link' => $link['loc'])));
 156    }
 157    elseif (empty($menu_item['access']) && !is_readable('./' . $link['loc'])) {
 158      // @todo Harden this file exists check to make sure we can't link to files
 159      // like .htaccess.
 160      form_set_error('loc', t('The custom link %link is either invalid or it cannot be accessed by anonymous users.', array('%link' => $link['loc'])));
 161    }
 162  }
 163  
 164  function xmlsitemap_custom_edit_link_form_submit($form, &$form_state) {
 165    $link = $form_state['values'];
 166    xmlsitemap_link_save($link);
 167    drupal_set_message(t('The custom link for %loc was saved.', array('%loc' => $link['loc'])));
 168    $form_state['redirect'] = 'admin/settings/xmlsitemap/custom';
 169  }
 170  
 171  function xmlsitemap_custom_delete_link_form($form_state, array $link) {
 172    _xmlsitemap_set_breadcrumb('admin/settings/xmlsitemap/custom');
 173  
 174    $form['link'] = array(
 175      '#type' => 'value',
 176      '#value' => $link,
 177    );
 178  
 179    return confirm_form(
 180      $form,
 181      t('Are you sure you want to delete the custom link for %loc?', array('%loc' => $link['loc'])),
 182      'admin/settings/xmlsitemap/custom',
 183      t('This action cannot be undone.'),
 184      t('Delete'),
 185      t('Cancel')
 186    );
 187  }
 188  
 189  function xmlsitemap_custom_delete_link_form_submit($form, &$form_state) {
 190    $link = $form_state['values']['link'];
 191    xmlsitemap_link_delete('custom', $link['id']);
 192    drupal_set_message(t('The custom link for %loc has been deleted.', array('%loc' => $link['loc'])));
 193    watchdog('xmlsitemap', 'The custom link for %loc has been deleted.', array('%loc' => $link['loc']), WATCHDOG_NOTICE);
 194    $form_state['redirect'] = 'admin/settings/xmlsitemap/custom';
 195  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7