Html::imagePaste PHP Method

imagePaste() static public method

imagePaste : Show image paste for an item, with TinyMce
static public imagePaste ( $options = [] ) : nothing
$options array of options - name string field name (default filename) - multiple boolean allow multiple file upload (default false - onlyimages boolean restrict to image files (default false) - showfilecontainer string DOM ID of the container showing file uploaded: use selector to display - imagePaste boolean image paste with tinyMce - dropZone string DOM ID of the drop zone - rand string already computed rand value - pasteZone string DOM ID of the paste zone
return nothing (print the image paste)
    static function imagePaste($options = array())
    {
        $rand = mt_rand();
        $p['name'] = 'stock_image';
        $p['multiple'] = true;
        $p['onlyimages'] = true;
        $p['showfilecontainer'] = 'fileupload_info';
        $p['imagePaste'] = 1;
        $p['dropZone'] = 'image_paste';
        $p['rand'] = $rand;
        if (is_array($options) && count($options)) {
            foreach ($options as $key => $val) {
                $p[$key] = $val;
            }
        }
        echo '<script type="text/javascript">';
        echo Html::fileScript($p);
        echo '</script>';
        echo "<div class='fileupload' id='" . $p['dropZone'] . "'></div>\n";
    }

Usage Example

示例#1
0
 /**
  * Init the Image paste System for tiny mce
  *
  * @since version 0.85
  *
  * @param $name          name of the html textarea to use
  * @param $rand          rand of the html textarea to use
  *
  * @return nothing
  **/
 static function initImagePasteSystem($name, $rand)
 {
     global $CFG_GLPI;
     echo Html::imagePaste(array('rand' => $rand));
     $params = array('name' => $name, 'filename' => self::generateImageName(), 'root_doc' => $CFG_GLPI['root_doc'], 'rand' => $rand, 'showfilesize' => 1, 'lang' => array('pasteimage' => _sx('button', 'Drag and drop or paste image'), 'itemnotfound' => __('Item not found'), 'toolarge' => __('Item is too large'), 'save' => _sx('button', 'Save'), 'cancel' => _sx('button', 'Cancel')));
     return html::scriptBlock("if (!tinyMCE.isIE) { // Chrome, Firefox plugin\n                  tinyMCE.imagePaste = \$(document).imagePaste(" . json_encode($params) . ");\n              } else { // IE plugin\n                  tinyMCE.imagePaste = \$(document).IE_support_imagePaste(" . json_encode($params) . ");\n              }\n              uploadFile{$rand}();");
 }
All Usage Examples Of Html::imagePaste
Html