[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/yui_editor/plugins/ -> img_upload.inc (source)

   1  <?php
   2  // $Id: img_upload.inc,v 1.1.2.4.2.3 2008/11/21 22:54:27 jeffcd Exp $
   3  
   4  /**
   5   * @file
   6   * Image upload plugin for the YUI Editor.
   7   */
   8  
   9  /**
  10   * Menu-callback for JavaScript-based uploads.
  11   */
  12  function yui_editor_image_upload() {
  13    header('content-type: text/html'); // the return type must be text/html
  14    $response = NULL;
  15    $path = file_directory_path();
  16  
  17    // Append trailing slash to path if not there
  18    if (!(substr($path, -1) == '/')) {
  19      $path .= '/';
  20    }
  21    $path .= 'images';
  22    $file = file_save_upload('upload', array(), $path, FILE_EXISTS_REPLACE);
  23    if (!$file) {
  24      $response->status = t('Error reading uploaded file.');
  25      print drupal_to_js($response);
  26      exit;
  27    }
  28  
  29    $response->status = 'UPLOADED';
  30    $response->image_url = $file->filepath;
  31  
  32    // Set it to permanent so it doesn't get wiped on the next cron run!
  33    file_set_status($file, FILE_STATUS_PERMANENT);
  34  
  35    print drupal_to_js($response);
  36    exit;
  37  }
  38  
  39  function yui_editor_img_upload_menu(&$items) {
  40    $items['yui_editor/image_upload'] = array(
  41      'page callback' => 'yui_editor_image_upload',
  42      'access callback' => 'user_access',
  43      'access arguments' => array('upload files'),
  44      'type' => MENU_CALLBACK,
  45    );
  46  
  47    return $items;
  48  }
  49  
  50  function yui_editor_img_upload_render(&$profile) {
  51    $profile['img_upload'] = (user_access('upload files') ? $profile['img_upload'] : 0);
  52    if ($profile['img_upload'] == 1) {
  53      $yui_source = variable_get('yui_source', 'http://yui.yahooapis.com/2.6.0');
  54      if (preg_match('/2.6.[0-9]$/iU', $yui_source)) {
  55        drupal_add_js(drupal_get_path('module', 'yui_editor') .'/plugins/img_upload.2.6.js', 'module', 'footer');
  56      }
  57      else {
  58        drupal_add_js(drupal_get_path('module', 'yui_editor') .'/plugins/img_upload.js', 'module', 'footer');
  59      }
  60    }
  61  }
  62  
  63  function yui_editor_img_upload_settings(&$form, &$profile) {
  64    $form['plugins']['img_upload'] = array(
  65      '#type' => 'checkbox',
  66      '#title' => t('Image upload'),
  67      '#default_value' => $profile['img_upload'],
  68      '#description' => t('Allow users to upload images directly from the editor for insertion into the editor. Note: Users must also have \'upload files\' permission set for this functionality to be made available.'),
  69    );
  70  }


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