19 include_once($ROOT_PATH.
'wysiwyg_plugin.inc');
46 wysiwyg_plugin::wysiwyg_plugin($wysiwyg);
47 $this->
_add_button(
'matrixinsertimage',
'MatrixInsertImage',
'Insert Image',
'false',
'34');
63 <script type=
"text/javascript" language=
"Javascript">
65 HTMLArea.prototype._matrixinsertImage =
function() {
83 var sel = this._getSelection();
84 var range = this._createRange(sel);
86 if (HTMLArea.is_gecko) {
87 var fragment = this._doc.createDocumentFragment();
88 var div = this._doc.createElement(
"div");
89 div.innerHTML = this.getSelectedHTML();
90 while (div.firstChild) {
91 if (div.firstChild.tagName ==
"IMG") {
93 var image_tag = div.firstChild;
97 fragment.appendChild(div.firstChild);
99 }
else if (HTMLArea.is_ie) {
101 if (range.item(0).tagName ==
"IMG") {
103 var image_tag = range.item(0);
109 if (is_image && image_tag) {
111 align = image_tag.align;
113 title = image_tag.title;
114 image_class = image_tag.className;
115 image_id = image_tag.id;
116 width = (!image_tag.width) ?
"" : image_tag.width;
117 height = (!image_tag.height) ?
"" : image_tag.height;
118 hspace = (!image_tag.hspace) ?
"" : image_tag.hspace;
119 vspace = (!image_tag.vspace) ?
"" : image_tag.vspace;
122 if (!image_tag.border && !image_tag.style.border) {
125 if (image_tag.border) {
126 border = image_tag.border;
127 }
else if (image_tag.style.border) {
128 border = image_tag.style.border;
129 border = border.match(/(\d{1})px/)[1];
133 longdesc = (!image_tag.longDesc) ?
"" : image_tag.longDesc;
134 if (image_tag.longDesc) {
135 var result = image_tag.longDesc.match(/(.+)\/\?a=(\d+)/);
136 if (result != null) {
138 longdesc = result[2];
141 e =
'http[s]?://<?php echo $_SERVER['HTTP_HOST
'].$_SERVER['PHP_SELF
']?>';
142 re =
new RegExp(e,
"gi");
143 longdesc = image_tag.longDesc.replace(re,
"");
149 imageid = editor.make_relative_hrefs(url);
150 e =
'.*\\?a=([0-9]+)((:[^$]*)\\$)?';
151 re =
new RegExp(e,
"gi");
152 imageid = imageid.replace(re,
"$1$3");
156 if (this._inPopup ==
true) { in_popup =
'1'; }
158 editor_<?php echo $this->
wysiwyg->name?>._object =
this;
159 strPage =
"<?php echo $this->get_popup_href('insert_image_frames.php')?>?f_imageid=" + escape(imageid) +
"&f_align=" + escape(align) +
"&f_width=" + escape(width) +
"&f_height=" + escape(height) +
"&f_alt=" + escape(alt) +
"&f_title=" + escape(title) +
"&f_longdesc=" + escape(longdesc) +
"&f_horiz=" + escape(hspace) +
"&f_vert=" + escape(vspace) +
"&f_border=" + escape(border) +
"&f_image_class=" + escape(image_class) +
"&f_image_id=" + escape(image_id) +
"&editor_name=" + escape(
"<?php echo $this->wysiwyg->name; ?>") +
"&in_popup=" + escape(in_popup);
161 var popup_height = 630;
164 if (HTMLArea.is_safari) popup_height += 35;
165 if (HTMLArea.is_linux && HTMLArea.is_gecko) popup_height += 35;
167 this._popupDialog(
"matrixInsertImage", strPage, 800, popup_height,
true,
function(param) {
174 if (param[
"f_imageid"] != 0) {
175 var url =
'./?a=' + param[
"f_imageid"];
177 if (param[
"f_imageid"].search(/:/) != -1) {
181 if (is_image && image_tag) {
182 if (image_tag.src !=
'') {
190 var html =
'<img src="' + url +
'"';
191 if (param[
"f_align"] !=
"") {
192 html +=
' align="' + param[
"f_align"] +
'"';
194 if (param[
"f_width"] !=
"") {
195 html +=
' width="' + param[
"f_width"] +
'"';
197 if (param[
"f_height"] !=
"") {
198 html +=
' height="' + param[
"f_height"] +
'"';
200 if (param[
"f_alt"] !=
"") {
201 html +=
' alt="' + param[
"f_alt"] +
'"';
203 if (param[
"f_title"] !=
"") {
204 html +=
' title="' + param[
"f_title"] +
'"';
206 if (param[
"f_image_id"] !=
"") {
207 html +=
' id="' + param[
"f_image_id"] +
'"';
209 if (param[
"f_image_class"] !=
"") {
210 html +=
' class="' + param[
"f_image_class"] +
'"';
213 if (param[
"f_longdesc"] != null && param[
"f_longdesc"] !=
"") {
214 var result = param[
"f_longdesc"].match(/(\d)+/);
215 if (result != null) {
216 if (result[1] !=
"0") {
217 html +=
' longdesc="<?php echo sq_web_path('root_url
'); ?>' +
'/?a=' + param[
"f_longdesc"] +
'"';
220 html +=
' longdesc="' + param[
"f_longdesc"] +
'"';
224 if (param[
"f_horiz"] !=
"") {
225 html +=
' hspace="' + param[
"f_horiz"] +
'"';
227 if (param[
"f_vert"] !=
"") {
228 html +=
' vspace="' + param[
"f_vert"] +
'"';
230 if (param[
"f_border"] !=
"") {
231 html +=
' style="border: ' + param[
"f_border"] +
'px solid rgb(0, 0, 0);"';
234 html = editor.make_absolute_urls(html);
236 if (!is_image || HTMLArea.is_gecko) {
238 editor.insertHTML(html, range);
241 image_tag.outerHTML = html;
258 function print_plugin_button_click()
261 case "matrixinsertimage":
262 this._matrixinsertImage();
279 function process(&$html)
282 $disable_resize = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'content_type_wysiwyg',
'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE');
283 if ($disable_resize ==
'yes') {
284 $new_html = rawurldecode($html);
286 preg_match_all(
'/<img[^>]*>/i', $new_html, $images);
287 if (!empty($images)) {
288 $html_updated = FALSE;
289 foreach ($images[0] as $img_tag) {
292 preg_match(
'/src=["\']?\.\/\?a=([^ "\'>]*)["\']?/i', $img_tag, $src);
293 $style_width_changed = FALSE;
294 $style_height_changed = FALSE;
295 $attr_width_changed = FALSE;
296 $attr_height_changed = FALSE;
297 $tmp_img_tag = $img_tag;
300 $id_parts = explode(
':', $src[1]);
301 if (isset($id_parts[1]))
continue;
303 $img_asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($src[1]);
304 $width = $img_asset->attr(
'width');
305 $height = $img_asset->attr(
'height');
309 preg_match(
'/style=["\']?([^>"\']*)["\']?/i', $img_tag, $style);
310 if (!empty($style)) {
311 $style_width = Array();
312 preg_match(
'/width: *(\d+) *(px)?/i', $img_tag, $style_width);
313 if (!empty($style_width)) {
314 $style_w = (int) $style_width[1];
315 if ($style_w != $width) {
316 $style_width_changed = TRUE;
317 $replacement =
'width: '.$width.
'px';
318 $tmp_img_tag = str_replace($style_width[0], $replacement, $tmp_img_tag);
322 $style_height = Array();
323 preg_match(
'/height: *(\d+) *(px)?/i', $img_tag, $style_height);
324 if (!empty($style_height)) {
325 $style_h = (int) $style_height[1];
326 if ($style_h != $height) {
327 $style_height_changed = TRUE;
328 $replacement =
'height: '.$height.
'px';
329 $tmp_img_tag = str_replace($style_height[0], $replacement, $tmp_img_tag);
336 $width_attr = Array();
337 preg_match(
'/width=["\']?([^> "\']*)["\']?/i', $img_tag, $width_attr);
338 if (!empty($width_attr)) {
339 $w_attr = (int) $width_attr[1];
340 if ($w_attr != $width) {
341 $attr_width_changed = TRUE;
342 $replacement =
'width="'.$width.
'"';
343 $tmp_img_tag = str_replace($width_attr[0], $replacement, $tmp_img_tag);
348 $height_attr = Array();
349 preg_match(
'/height=["\']?([^> "\']*)["\']?/i', $img_tag, $height_attr);
350 if (!empty($height_attr)) {
351 $h_attr = (int) $height_attr[1];
352 if ($h_attr != $height) {
353 $attr_height_changed = TRUE;
354 $replacement =
'height="'.$height.
'"';
355 $tmp_img_tag = str_replace($height_attr[0], $replacement, $tmp_img_tag);
359 if ($style_width_changed || $style_height_changed || $attr_width_changed || $attr_height_changed) {
360 $new_html = str_replace($img_tag, $tmp_img_tag, $new_html);
361 if (!$html_updated) $html_updated = TRUE;
367 if ($html_updated) $html = $new_html;