Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 188 additions & 6 deletions hak_tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@
add_privs('hak_tinymce_compressor_js','1,2,3,4,5,6');
add_privs('hak_txpimage','1,2,3,4,5,6');
add_privs('hak_txpcatselect','1,2,3,4,5,6');

add_privs('hak_txpcountselect','1,2,3,4,5,6');

register_callback(array("hak_tinymce","js_prep"), "hak_tinymce_js");
register_callback(array("hak_tinymce","compressor_js_prep"), "hak_tinymce_compressor_js");
register_callback("hak_txpimage", "hak_txpimage");
register_callback("hak_txpcatselect", "hak_txpcatselect");
register_callback("hak_txpcountselect", "hak_txpcountselect");

register_tab('extensions', 'hak_tinymce_prefs', 'hak_tinymce');
register_callback(array('hak_tinymce','prefs'), 'hak_tinymce_prefs');
Expand Down Expand Up @@ -557,7 +558,7 @@ function install() {
$hak_mceSettings_default .= "theme_advanced_buttons3 : \"\",\n";
$hak_mceSettings_default .= "theme_advanced_toolbar_location : \"top\",\n";
$hak_mceSettings_default .= "theme_advanced_toolbar_align : \"left\",";
$hak_mceSettings_default .= "entity_encoding : \"numeric\",";
$hak_mceSettings_default .= "entity_encoding : \"raw\",";

$hak_mceSettings_compressor = "theme : \"advanced\",\n";
$hak_mceSettings_compressor .= "plugins : \"searchreplace,txpimage\",\n";
Expand Down Expand Up @@ -638,9 +639,21 @@ function map_attribs($arr) {
$format .= (!empty($arr["height"])) ? ',height:'.$arr["height"] : '';
$format .= (!empty($arr["alt"])) ? ',alt:"'.$arr["alt"].'"' : '';
$format .= (!empty($arr["title"])) ? ',title:"'.$arr["title"].'"' : '';
$format .= ',srcf:""';
$format .= '}';
return $format;
}

function map_attribsf($arr) {
$format = '{src:"'.$arr["path"].'"';
$format .= (!empty($arr["width"])) ? ',width:'.$arr["width"] : '';
$format .= (!empty($arr["height"])) ? ',height:'.$arr["height"] : '';
$format .= (!empty($arr["alt"])) ? ',alt:"'.$arr["alt"].'"' : '';
$format .= (!empty($arr["title"])) ? ',title:"'.$arr["title"].'"' : '';
$format .= (!empty($arr["srcf"])) ? ',srcf:"'.$arr["srcf"].'"' : '';
$format .= '}';
return $format;
}
} //--- End Class

//----------------------------------------
Expand All @@ -656,8 +669,27 @@ function hak_compressor_path($file) {
function hak_txpimage() {
global $img_dir,$path_to_site,$txpcfg;
$category = gps("c");
$category = (!empty($category)) ? "and category='".doSlash($category)."'" : "";
$rs = safe_rows_start("*", "txp_image","1=1 ".$category." order by category,name");
$author = gps("a");
$limit_image = gps("limimg");
$limit_img_count = gps("limcount");

if(empty($author)) { $author = ""; }
else { $author = " and author='".doSlash($author)."' "; }
if(empty($category)) { $category = ""; }
else { $category = " and category='".doSlash($category)."' "; }

if(empty($limit_img_count)) { $limit_img_count = 0; }
else { $limit_img_count = intval($limit_img_count); }
if($limit_image=='0') { $limit_image = ""; }
elseif(empty($limit_image)) { $limit_image = " limit 0,10"; }
else {
if(intval($limit_image)==0) { $limit_image = " limit 0,10"; }
else { $limit_image = " limit ".$limit_img_count*intval($limit_image).",".intval($limit_image); }
}
$srcf2 = gps("srcf2");
$srcf2 = (!empty($srcf2))? true : false;

$rs = safe_rows_start("*", "txp_image","1=1 ".$category.$author." order by id desc,category,name".$limit_image);
$src = gps("src");


Expand All @@ -682,9 +714,19 @@ function hak_txpimage() {
$thumb["height"] = $thumb_h;
$thumb["alt"] = $image["alt"];
$thumb["caption"] = $image["caption"];
$thumbf["path"] = hu.$img_dir.'/'.$id.'t'.$ext;
$thumbf["width"] = $thumb_w;
$thumbf["height"] = $thumb_h;
$thumbf["alt"] = $image["alt"];
$thumbf["caption"] = $image["caption"];
$thumbf["srcf"] = $image["path"];
$preview = $thumb;
$thumbclick = 'onclick=\'TxpImageDialog.insertImage(this,'.hak_tinymce::map_attribs($thumb).');return'.n.'false;\'';
$thumbclickf = 'onclick=\'TxpImageDialog.insertImage(this,'.hak_tinymce::map_attribsf($thumbf).');return'.n.'false;\'';
$thumbclick = '<a href="#" '.$thumbclick.'><img src="img/pictures.png" width="18" height="18" title="'.hak_tinymce::mce_gTxt('insert_thumb').'" alt="'.hak_tinymce::mce_gTxt('insert_thumb').'" /></a>';
if($srcf2) {
$thumbclick .= '<a href="#" class="thumbclickf" '.$thumbclickf.'><img src="img/picturef.png" width="18" height="18" title="'.hak_tinymce::mce_gTxt('insert_thumb').'" alt="'.hak_tinymce::mce_gTxt('insert_fancy').'" /></a>';
}
}

//$desiredheight = $preview["height"];
Expand Down Expand Up @@ -719,15 +761,155 @@ function hak_txpimage() {
}

function hak_txpcatselect() {
global $img_dir,$path_to_site,$txpcfg;
$num = 10;
$category = gps("c");
$author = gps("a");
$limit_image = gps("limimg");
$limit_img_count = gps("limcount");

if(empty($author) || $author=='0') { $author = ""; }
else { $author = " and author='".doSlash($author)."' "; }
if(empty($category) || $category=='0') { $category = ""; }
else { $category = " and category='".doSlash($category)."' "; }

$rs = getTree("root",'image');

$a_out = array();
$a_out[] = array('name'=>'0','title'=>'All','level'=>0);
$rs_author = safe_rows_start("name, RealName", "txp_users","1=1");
if($rs_author) {
while ($a = nextRow($rs_author)) {
extract($a);
$a_out[] = array('name'=>$name,'title'=>$RealName,'level'=>0);
}
}

$lim_out = array();
$lim_out[] = array('name'=>'0','title'=>'All','level'=>0);
$lim_out[] = array('name'=>'10','title'=>'10','level'=>0);
$lim_out[] = array('name'=>'20','title'=>'20','level'=>0);
$lim_out[] = array('name'=>'30','title'=>'30','level'=>0);
$lim_out[] = array('name'=>'50','title'=>'50','level'=>0);

$t_ar = array("id"=>0,"name"=>'0',"title"=>'All',"level"=>0,"children"=>0,"parent"=>'root');
array_unshift($rs, $t_ar);

if ($rs) {
echo tag(gTxt('category'),"legend").
treeSelectInput("category",$rs,"","txpCategory");
echo '<div id="cat_aut_lim_count"><div id="left_panel"><div><label id="labelCategory">'.gTxt('Category').'</label><br />'.
treeSelectInput2("category",$rs,"0","txpCategory").
'</div><div><label id="labelAuthor">'.gTxt('Author').'</label><br />'.
treeSelectInput2("author",$a_out,"0","txpAuthor").'</div></div>'.
'<div id="right_panel"><div>'.
'<label id="labelLimit">'.gTxt('Lim-img').'</label><br />'.
treeSelectInput2("LimitImages",$lim_out,"10","txpLimitImages").'</div><div id="imagesmax"></div></div></div>';
}
exit(0);
}
function hak_txpcountselect() {
global $img_dir,$path_to_site,$txpcfg;
$num = 10;
$category = gps("c");
$author = gps("a");
$limit_image = gps("limimg");
$limit_img_count = gps("limcount");

if(empty($author) || $author=='0') { $author = ""; }
else { $author = " and author='".doSlash($author)."' "; }
if(empty($category) || $category=='0') { $category = ""; }
else { $category = " and category='".doSlash($category)."' "; }

if(empty($limit_img_count)) { $limit_img_count = 0; }
else { $limit_img_count = intval($limit_img_count); }

if($limit_image=='0') { $limit_image = 1; }
elseif(empty($limit_image)) { $limit_image = 10; }
else { $limit_image = (intval($limit_image)==0)? 1 : intval($limit_image); }

$rcount = safe_count("txp_image", "1=1 ".$category.$author);
$count = 0; $min_count = 0; $max_count = 0; $lim_count_out = array();
$count = ceil($rcount/$limit_image);
if($count<=$num) { $min_count = 0; $max_count = $count; }
elseif($limit_img_count>$count) { $min_count=($count-$num>0)? $count-$num: 0; $max_count = $count; }
elseif($count<$num) { $min_count=0; $max_count=$count; }
else{
$pol = ceil($num/2);
$max_count=($limit_img_count+$pol>=$count)? $count : (($limit_img_count+$pol<=$num)? $num : $limit_img_count+$pol);
$min_count=($limit_img_count-$pol<=0)? 0 : (($max_count-$num>0)? $max_count-$num : $limit_img_count-$pol);
}
for($i=0; $i<$count; $i++) {
$lim_count_out[] = array('count_li'=>$i);
}
if ($rcount>$limit_image && $limit_image>1) { echo liLinks2($lim_count_out, $limit_img_count, $count, $min_count, $max_count, $num); }
else { echo ''; }
exit(0);
}

function treeSelectInput2($select_name = '', $array = '', $value = '', $select_id = '', $truncate = 0) {
$out = array();
$selected = false;
foreach ($array as $a)
{
if ($a['name'] == 'root')
{
continue;
}
extract($a);
if ($name == $value)
{
$sel = ' selected="selected"';
$selected = true;
}
else
{
$sel = '';
}
$sp = str_repeat(sp.sp, $level);

if (($truncate > 3) && (strlen(utf8_decode($title)) > $truncate)) {
$htmltitle = ' title="'.htmlspecialchars($title).'"';
$title = preg_replace('/^(.{0,'.($truncate - 3).'}).*$/su','$1',$title);
$hellip = '&#8230;';
} else {
$htmltitle = $hellip = '';
}
$out[] = n.t.'<option value="'.htmlspecialchars($name).'"'.$htmltitle.$sel.'>'.$sp.htmlspecialchars($title).$hellip.'</option>';
}

return n.'<select'.( $select_id ? ' id="'.$select_id.'" ' : '' ).' name="'.$select_name.'" class="list">'.
( $out ? join('', $out) : '').
n.'</select>';
}

function liLinks2($array = '', $value = '', $count = 0, $min_count = 0, $max_count = 0, $num = 10) {
$out = array();
if($count>0) {
foreach ($array as $a) {
extract($a);
if($count_li == $value) { $class = ' class="li_links active" style="font-weight: bold;color:red;" '; }
else { $class = ' class="li_links"'; }
if($count_li>=($min_count-1) && $count_li<=$max_count) {
$out[] = n.t.'<li><a onclick="TxpImageDialog.loadCountBrowser(tinyMCEPopup.dom.get(\'txpCategory\').value || \'0\', tinyMCEPopup.dom.get(\'txpAuthor\').value || \'0\', tinyMCEPopup.dom.get(\'txpLimitImages\').value || \'0\', '.$count_li.');return false;" href="#'.$count_li.'" rel="'.$count_li.'" '.$class.'>'.htmlspecialchars($count_li + 1).'</a></li>';
}
if($count_li==$max_count) { break; }
}
if($count>$num && $out) {
$out2x = n.t.'<li><a onclick="TxpImageDialog.loadCountBrowser(tinyMCEPopup.dom.get(\'txpCategory\').value || \'0\', tinyMCEPopup.dom.get(\'txpAuthor\').value || \'0\', tinyMCEPopup.dom.get(\'txpLimitImages\').value || \'0\', 0);return false;" href="#0" rel="0" '.$class.'>&laquo;</a></li>';
$tmin = ($min_count-1<0)? 0 : $min_count-1;
$value_min = ($value-1<0)? 0 : $value-1;
$out1x = n.t.'<li><a onclick="TxpImageDialog.loadCountBrowser(tinyMCEPopup.dom.get(\'txpCategory\').value || \'0\', tinyMCEPopup.dom.get(\'txpAuthor\').value || \'0\', tinyMCEPopup.dom.get(\'txpLimitImages\').value || \'0\', '.$value_min.');return false;" href="#'.$value_min.'" rel="'.$value_min.'" '.$class.'>&lt;</a></li>';
array_unshift($out, $out2x, $out1x);
//$tmax = ($max_count+1>$count)? $count-1 : $max_count+1;
$value_max = ($value+1>=$count)? $count-1 : $value+1;
$out[$count] = n.t.'<li><a onclick="TxpImageDialog.loadCountBrowser(tinyMCEPopup.dom.get(\'txpCategory\').value || \'0\', tinyMCEPopup.dom.get(\'txpAuthor\').value || \'0\', tinyMCEPopup.dom.get(\'txpLimitImages\').value || \'0\', '.$value_max.');return false;" href="#'.$value_max.'" rel="'.$value_max.'" '.$class.'>&gt;</a></li>';
$count2 = $count-1;
$out[$count+1] = n.t.'<li><a onclick="TxpImageDialog.loadCountBrowser(tinyMCEPopup.dom.get(\'txpCategory\').value || \'0\', tinyMCEPopup.dom.get(\'txpAuthor\').value || \'0\', tinyMCEPopup.dom.get(\'txpLimitImages\').value || \'0\', '.$count2.');return false;" href="#'.$count2.'" rel="'.$count2.'" '.$class.'>&raquo;</a></li>';
}
}
return n.'<ul id="txpLimitCount" class="pagination">'.
( $out ? join('', $out) : '' ).
n.'</ul>';
}

# --- END PLUGIN CODE ---
if (0) {
Expand Down
5 changes: 4 additions & 1 deletion txpimage/css/txpimage.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ input {width: 280px;}
border:1px solid silver;
background:white;
}

#left_panel{float:left;width:140px;}
#labelCategory, #labelAuthor, #labelLimit {font-size: 8px;}
ul.pagination {margin: 1em 0; padding: 0.5em; text-align: left;}
ul.pagination li {display: inline; padding: 0.1em; border:none;}
4 changes: 2 additions & 2 deletions txpimage/editor_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

ed.windowManager.open({
file : url + '/image.htm',
width : 480 + parseInt(ed.getLang('advimage.delta_width', 0), 10),
height : 480 + parseInt(ed.getLang('advimage.delta_height', 0), 10),
width : 530 + parseInt(ed.getLang('advimage.delta_width', 0), 10),
height : 510 + parseInt(ed.getLang('advimage.delta_height', 0), 10),
inline : 1
}, {
plugin_url : url
Expand Down
4 changes: 3 additions & 1 deletion txpimage/image.htm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
<tr>
<td class="column1"><label id="srclabel" for="src">{#txpimage_dlg.src}</label></td>
<td colspan="2"><table border="0" cellspacing="0" cellpadding="0">
<tr>
<tr>
<input type="hidden" id="srcf" name="srcf" value="" />
<input type="hidden" id="srcf2" name="srcf2" value="1" />
<td><input name="src" type="text" id="src" value="" class="mceFocus" /></td>
<td id="srcbrowsercontainer">&nbsp;</td>
</tr>
Expand Down
Binary file added txpimage/img/picturef.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 54 additions & 10 deletions txpimage/js/txpimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var TxpImageDialog = {
nl.usemap.value = dom.getAttrib(n, 'usemap');
nl.longdesc.value = dom.getAttrib(n, 'longdesc');
nl.insert.value = ed.getLang('update');
nl.srcf2.value = '0';

if (/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/.test(dom.getAttrib(n, 'onmouseover'))) {
nl.onmouseoversrc.value = dom.getAttrib(n, 'onmouseover').replace(/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/, '$1');
Expand Down Expand Up @@ -126,7 +127,7 @@ var TxpImageDialog = {
},

insertAndClose : function() {
var ed = tinyMCEPopup.editor, f = document.forms[0], nl = f.elements, v, args = {}, el;
var ed = tinyMCEPopup.editor, f = document.forms[0], nl = f.elements, v, args = {}, argsf = {}, el;

tinyMCEPopup.restoreSelection();

Expand Down Expand Up @@ -166,6 +167,11 @@ var TxpImageDialog = {
longdesc : nl.longdesc.value
});

tinymce.extend(argsf, {
href : nl.srcf.value,
'class' : 'fancybox'
});

args.onmouseover = args.onmouseout = '';

if (f.onmousemovecheck.checked) {
Expand All @@ -182,11 +188,20 @@ var TxpImageDialog = {
if (el && el.nodeName == 'IMG') {
ed.dom.setAttribs(el, args);
} else {
ed.execCommand('mceInsertContent', false, '<img id="__mce_tmp" />', {skip_undo : 1});
ed.dom.setAttribs('__mce_tmp', args);
ed.dom.setAttrib('__mce_tmp', 'id', '');
ed.undoManager.add();
}
if(argsf.href != "") {
ed.execCommand('mceInsertContent', false, '<a id="__mce_tmp_a"><img id="__mce_tmp" /></a>', {skip_undo : 1});
ed.dom.setAttribs('__mce_tmp', args);
ed.dom.setAttrib('__mce_tmp', 'id', '');
ed.dom.setAttribs('__mce_tmp_a', argsf);
ed.dom.setAttrib('__mce_tmp_a', 'id', '');
ed.undoManager.add();
} else {
ed.execCommand('mceInsertContent', false, '<img id="__mce_tmp" />', {skip_undo : 1});
ed.dom.setAttribs('__mce_tmp', args);
ed.dom.setAttrib('__mce_tmp', 'id', '');
ed.undoManager.add();
}
}

tinyMCEPopup.close();
},
Expand Down Expand Up @@ -464,18 +479,47 @@ var TxpImageDialog = {
success: function (response) {
tinyMCEPopup.dom.setHTML('catselect', response);
tinymce.dom.Event.add(tinyMCEPopup.dom.get('txpCategory'), 'change', function (e) {
this.loadImageBrowser(e.target.value);
tinyMCEPopup.dom.setHTML('image_browse', '<img src="img/loading.gif" width="32" height="32" alt="" id="loading" />');
this.loadCountBrowser(e.target.value, tinyMCEPopup.dom.get('txpAuthor').value || '0', tinyMCEPopup.dom.get('txpLimitImages').value || '0', '0');
}, this);
tinymce.dom.Event.add(tinyMCEPopup.dom.get('txpAuthor'), 'change', function (e) {
tinyMCEPopup.dom.setHTML('image_browse', '<img src="img/loading.gif" width="32" height="32" alt="" id="loading" />');
this.loadCountBrowser(tinyMCEPopup.dom.get('txpCategory').value || '0', e.target.value, tinyMCEPopup.dom.get('txpLimitImages').value || '0', '0');
}, this);
this.loadImageBrowser();
tinymce.dom.Event.add(tinyMCEPopup.dom.get('txpLimitImages'), 'change', function (e) {
tinyMCEPopup.dom.setHTML('image_browse', '<img src="img/loading.gif" width="32" height="32" alt="" id="loading" />');
this.loadCountBrowser(tinyMCEPopup.dom.get('txpCategory').value || '0', tinyMCEPopup.dom.get('txpAuthor').value || '0', e.target.value, '0');
}, this);
this.loadCountBrowser();
}
});
},
loadImageBrowser: function (category) {
loadCountBrowser: function (category, author, limit, limcount) {
var selCat = category || "";
var selAuthor = author || "";
var selLimit = limit || 10;
var selLimCount = limcount || 0;
var src = tinyMCEPopup.dom.get('src').value || '';
tinymce.util.XHR.send({
url:this.txpEndPoint + '?event=hak_txpcountselect&src='+ src + '&c='+ selCat + '&a=' + selAuthor + '&limimg=' + selLimit + '&limcount=' + selLimCount + '&_rnd=' + new Date().getTime(),
type: 'GET',
scope: this,
success: function (response) {
tinyMCEPopup.dom.setHTML("imagesmax", response);
this.loadImageBrowser(selCat,selAuthor,selLimit,selLimCount);
}
});
},
loadImageBrowser: function (category, author, limit, limcount) {
var selCat = category || "";
var selAuthor = author || "";
var selLimit = limit || 10;
var selLimCount = limcount || 0;
var src = tinyMCEPopup.dom.get('src').value || '';
var srcf2 = tinyMCEPopup.dom.get('srcf2').value || 1;

tinymce.util.XHR.send({
url:this.txpEndPoint + '?event=hak_txpimage&src='+ src + '&c='+ selCat + '&_rnd=' + new Date().getTime(),
url:this.txpEndPoint + '?event=hak_txpimage&src='+ src + '&c='+ selCat + '&a=' + selAuthor + '&limimg=' + selLimit + '&limcount=' + selLimCount + '&srcf2=' + srcf2 + '&_rnd=' + new Date().getTime(),
type: 'GET',
success: function (response) {
tinyMCEPopup.dom.setHTML("image_browse", response);
Expand Down