[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/gallery/gallery_g2image/ -> gallery_g2image.module (source)

   1  <?php
   2  // $Id: gallery_g2image.module,v 1.1.2.2 2008/06/10 14:58:13 profix898 Exp $
   3  
   4  /**
   5   * gallery_g2image.module
   6   */
   7  
   8  /**
   9   * Implementation of hook_theme().
  10   */
  11  function gallery_g2image_theme() {
  12    return array(
  13      'gallery_g2image_textarea_link' => array(
  14        'arguments' => array('element' => NULL, 'link' => NULL),
  15      )
  16    );
  17  }
  18  
  19  /**
  20   * Implementation of hook_perm().
  21   */
  22  function gallery_g2image_perm() {
  23    return array('access standalone g2image');
  24  }
  25  
  26  /**
  27   * Implementation of hook_menu().
  28   */
  29  function gallery_g2image_menu() {
  30    $items = array();
  31    if (variable_get('gallery_valid', 0)) {
  32      $items['admin/settings/gallery/g2image'] = array(
  33        'title' => 'G2Image',
  34        'access callback' => 'user_access',
  35        'access arguments' => array('administer gallery settings'),
  36        'file' => 'gallery_g2image_settings.inc',
  37        'page callback' => 'drupal_get_form',
  38        'page arguments' => array('_gallery_g2image_settings'),
  39        'type' => MENU_LOCAL_TASK,
  40        'weight' => 3
  41      );
  42    }
  43    
  44    return $items;
  45  }
  46  
  47  /**
  48   * Implementation of hook_elements().
  49   */
  50  function gallery_g2image_elements() {
  51    $type['textarea'] = array('#process' => array('gallery_g2image_textarea'));
  52    return $type;
  53  }
  54  
  55  /**
  56   * Function gallery_g2image_textarea().
  57   * (add image link underneath textareas)
  58   */
  59  function gallery_g2image_textarea($element) {
  60    if (!isset($element['#disabled']) && _gallery_g2image_page_match()
  61        && (variable_get('gallery_g2image_mode', 'disabled') == 'standalone')
  62        && (user_access('access standalone g2image'))) {
  63      gallery_g2image_add_js();
  64      $link = theme('gallery_g2image_textarea_link', $element);
  65      $element['#suffix'] = (isset($element['#suffix']) ? $element['#suffix'] : '') . $link;
  66    }
  67  
  68    return $element;
  69  }
  70  
  71  /**
  72   * Function _gallery_g2image_page_match().
  73   * (determine if g2image button should be attached to the page/textarea)
  74   *
  75   * @return
  76   *   TRUE if can render, FALSE if not allowed.
  77   */
  78  function _gallery_g2image_page_match() {
  79    require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
  80  
  81    $page_match = FALSE;
  82    $visibility = variable_get('gallery_g2image_visibility', 1);
  83    if ($pages = variable_get('gallery_g2image_visibility_pages', "node/add/*\ncomment/*")) {
  84      $path = drupal_get_path_alias($_GET['q']);
  85      $page_match = !($visibility xor drupal_match_path($path, $pages));
  86    }
  87  
  88    return $page_match;
  89  }
  90  
  91  /**
  92   * Function gallery_g2image_add_js().
  93   */
  94  function gallery_g2image_add_js() {
  95    // Ensure only sent once
  96    static $sent = FALSE;
  97    
  98    if (!$sent) {
  99      if ($path = variable_get('gallery_g2image_path', FALSE)) {
 100        drupal_add_js(array('gallery' => array('g2image_uri' => base_path() . $path)), 'setting');
 101        drupal_add_js(drupal_get_path('module', 'gallery_g2image') .'/gallery_g2image.js');
 102      }
 103  
 104      $sent = TRUE;
 105    }
 106  }
 107  
 108  /**
 109   * Theme function : theme_gallery_g2image_textarea_link().
 110   * (for adding an image link underneath textareas)
 111   */
 112  function theme_gallery_g2image_textarea_link($element) {
 113    $output = '<div class="g2image-button"><a class="g2image-link" id="g2image-link-'. $element['#id']
 114      .'" title="'. t('Click here to add images from Gallery2 albums')
 115      .'" href="#" onclick="g2image_open(\''. $element['#id'] .'\');">';
 116    $output .= t('Add Gallery2 images');
 117    $output .= '</a></div>';
 118  
 119    return $output;
 120  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7