OSDN Git Service

version 0.5.9.9.3
[nucleus-jp/nucleus-plugins.git] / trunk / NP_MitasNom / NP_MitasNom.php
index f158c69..7fe7eb9 100644 (file)
-<?php 
-/*
- * NP_MitasNom ver 0.5.9.2
- * Written by Katsumi
- * This library is GPL
- */
-class NP_MitasNom extends NucleusPlugin { 
-       var $actionplugin=false;
-       var $bconvertbreaks;
-       function getName() {
-               $this->_checkVersion();
-               return 'NP_MitasNom'; 
-       }
-       function getMinNucleusVersion() { return 220; }
-       function getAuthor()  { return 'Katsumi'; }
-       function getVersion() { return '0.5.9.2'; }
-       function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:mitasnom';}
-       function getDescription() { return $this->translated('WYSIWYG HTML editor plagin using FCKeditor'); } 
-       function supportsFeature($what) { return (int)($what=='SqlTablePrefix'); }
-       function install() {
-               // Install, upgrade options, and Refresh member options.
-               // Note: createOption() is overrided (see below).
-               $this->createOption('version','version','text',$this->getVersion(),'access=hidden');
-               $this->createOption('width',$this->translated('Width'),'text','100%'); 
-               $this->createOption('height',$this->translated('Height'),'text','400'); 
-               $this->createOption('toolbar',$this->translated('Toolbar'),'select','Default','Default|Default|Full|Full|Basic|Basic|Custom|Custom'); 
-               $this->createOption('toolbar_custom',$this->translated('Custom Toolbar'), 'textarea',
-                       "['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],\n".
-                       "['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],\n".
-                       "['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],\n".
-                       "['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],\n".
-                       "['OrderedList','UnorderedList','-','Outdent','Indent'],\n".
-                       "['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],\n".
-                       "['Link','Unlink','Anchor'],\n".
-                       "['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak','UniversalKey'],\n".
-                       "['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],'/',\n".
-                       "['Style','FontFormat','FontName','FontSize'],\n".
-                       "['TextColor','BGColor'],\n".
-                       "['About']");
-               $this->createOption('addremovetoolbar',$this->translated('Add new toolbar to the menu / Delete toolbar from the menu'),'text',''); 
-               $this->createOption('returnafterbr',$this->translated('"<br />" => "<br />\n" conversion?'),'yesno','yes'); 
-               $this->createOption('returnafterbrbr',$this->translated('"<br /><br />" => "<br />\n<br />\n" conversion?'),'yesno','no'); 
-               $this->createOption('dialogwidth',$this->translated('Width of Popup dialog'),'text','500'); 
-               $this->createOption('dialogheight',$this->translated('Height of Popup dialog'),'text','450'); 
-               $this->createOption('protectedsource',$this->translated('Protected Sources'), 'textarea',
-                       '/<script[\s\S]*?\/script>/gi'."\n".
-                       '/<%[\s\S]*?%>/g');
-               //$this->createOption('additionalpsource',$this->translated('Additional Protected Sources'), 'textarea','');
-               $this->createOption('usemembersettings',$this->translated('Use member-specific settings?'),'yesno','no'); 
-               $this->createOption('useimagemanager',$this->translated('Use Image-Manager plugin instead of media.php?'),'yesno','no'); 
-               $this->createOption('usehttps',$this->translated('Use secure server (https) for edititing item?'),'yesno','no'); 
-               $this->createOption('usep',$this->translated('Use P tag instead of BR for enter key (IE only)?'),'yesno','no'); 
-       }
-       function getEventList() { return array('EditItemFormExtras','AddItemFormExtras','PrepareItemForEdit',
-                                       'PreAddItem','PreUpdateItem',
-                                       'PreItem','PostPluginOptionsUpdate','PrePluginOptionsEdit'); }
-
-       // SkinVar is currently used for showing link to create item
-       function doSkinVar($skinType,$type,$text='') {
-               global $blogid,$CONF,$member;
-               switch (strtolower($type)) {
-               case 'newitem':
-               default:
-                       if (!$member->isLoggedIn()) return;
-                       if (!$text) $text=$this->translated('New Item with WYSIWYG');
-                       $url=$CONF['ActionURL'].'?action=plugin&name=MitasNom&type=createitem&blogid='.$blogid;
-                       $url=htmlspecialchars($url);
-                       if ($this->getOption('usehttps')=='yes') $url=preg_replace('/^http:/','https:',$url);
-                       echo "<a href=\"$url\">$text</a>\n";
-                       break;
-               }
-       }
-
-       // TemplateVar is currently used for showing link to edit item
-       function doTemplateVar(&$item,$type,$text='') {
-               global $CONF,$member;
-               switch (strtolower($type)) {
-               case 'edititem':
-               default:
-                       if (!$text) $text=$text=$this->translated('Edit Item with WYSIWYG');
-                       $itemid=$item->itemid;
-                       $url=htmlspecialchars($url);
-                       if ($this->getOption('usehttps')=='yes') $url=preg_replace('/^http:/','https:',$url);
-                       $url=$CONF['ActionURL'].'?action=plugin&name=MitasNom&type=itemedit&itemid='.$itemid;
-                       echo "<a href=\"$url\">$text</a>\n";
-                       break;
-               }
-       }
-
-       // Action is used to show item-editing/newitem-creating window.
-       function doAction($type){
-               global $DIR_LIBS,$member,$manager,$CONF,$blogid,$itemid;
-               if (!$member->isLoggedIn()) return _NOTLOGGEDIN;
-               if (!strstr('createitem itemedit',$type)) return _BADACTION;
-
-               // Resolve itemid and blogid
-               if (!$blogid && $itemid) $blogid=getBlogIDFromItemID($itemid);
-               if (!$blogid) return _BADACTION;
-               if (!$member->teamRights($blogid)) return _ERROR_DISALLOWED;
-               $blog=&$manager->getBlog($blogid);
-               $convBreaks=false;
-               if ($blog) if ($blog->convertBreaks()) $convBreaks=true;
-
-               // Get editing HTML
-               $this->actionplugin=true;
-               include($DIR_LIBS . 'ADMIN.php');
-               $a=new ADMIN();
-               switch ($type) {
-               case 'createitem':
-                       ob_start();
-                       $a->action_createitem();
-                       $buff=ob_get_contents();
-                       ob_end_clean();
-                       break;
-               case 'itemedit':
-                       ob_start();
-                       $a->action_itemedit();
-                       $buff=ob_get_contents();
-                       ob_end_clean();
-                       break;
-               default:
-                       return _BADACTION;
-               }
-               
-               // Return if not valid editing HTML
-               // These codes must be changed when non-compatible Nucleus version comes out.
-               if (!preg_match('/<head>/',$buff)) return _ERRORMSG;
-               if (!preg_match('/<div class="jsbuttonbar">/',$buff)) return _ERRORMSG;
-               if (!preg_match('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff)) return _ERRORMSG;
-               if (!preg_match('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff)) return _ERRORMSG;
-
-               // Create NucleusFCKeditor instances
-               if (!class_exists('NucleusFCKeditor')) include ($this->getDirectory().'fckclass.php');
-               $body='';
-               $more='';
-               if ($type=='itemedit') {
-                       if (preg_match ('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff,$matches))
-                               $body=$matches[3];
-                               $body=$this->unhtmlentities($body);
-                       if (preg_match ('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff,$matches))
-                               $more=$matches[3];
-                               $more=$this->unhtmlentities($more);
-               }
-               if ($convBreaks) {
-                       $body=addBreaks($body);
-                       $more=addBreaks($more);
-               }
-               $FCKedit1=new NucleusFCKEditor('body',$this,$body);
-               $FCKedit2=new NucleusFCKEditor('more',$this,$more);
-               $buff1=$FCKedit1->CreateHtml();
-               $buff2=$FCKedit2->CreateHtml();
-
-               // Replace texts of editing page
-               // These codes must be changed when non-compatible Nucleus version comes out.
-               $buff=preg_replace ('/<head>/','<head><base href="'.$CONF['AdminURL'].'">', $buff,1);
-               $buff=preg_replace ('/<div class="jsbuttonbar">/','<div class="jsbuttonbar" style="DISPLAY: none;">', $buff,2);
-               $buff=preg_replace ('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff1, $buff,1);
-               $buff=preg_replace ('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff2, $buff,1);
-               echo $buff;
-       }
-       
-       // Solve <%image%> tag for showing items
-       function event_PreItem(&$data) {
-               $item=&$data['item'];
-               $pattern=$this->_patternBeforeEdit();
-               $replace=$this->_replaceBeforeEdit($item->authorid);
-               for ($i=0;$i<1;$i++){
-                       $item->body=preg_replace($pattern[$i],$replace[$i],$item->body);
-                       $item->more=preg_replace($pattern[$i],$replace[$i],$item->more);
-               }
-       }
-       
-       // NP_MitasNom option in editing dialog.
-       // This is more compatible to newer Nucleus version,
-       // unless 'id="inputbody"' and 'id="inputmore"' changed.
-       function event_AddItemFormExtras(&$data) { return $this->event_EditItemFormExtras($data); }
-       function event_EditItemFormExtras(&$data) {
-               global $DIR_LIBS,$member,$manager,$CONF,$blogid,$itemid;
-               // Resolve itemid and blogid
-               if (!$blogid && $itemid) $blogid=getBlogIDFromItemID($itemid);
-               if (!$blogid) return _BADACTION;
-               if (!$member->teamRights($blogid)) return _ERROR_DISALLOWED;
-               $blog=&$manager->getBlog($blogid);
-               $convBreaks=false;
-               if ($blog) if ($blog->convertBreaks()) $convBreaks=true;
-               $authorid=$member->getID();
-               if ($itemid) {
-                       $item=&$manager->getItem($itemid,1,1);
-                       $authorid=$item['authorid'];
-               }
-
-               if ($this->actionplugin) {
-                       echo '<input type="hidden" name="mitasnom_wysiwyged" id="mitasnom_wysiwyged" value="full"/>';
-                       return;
-               } else  echo '<input type="hidden" name="mitasnom_wysiwyged" id="mitasnom_wysiwyged" value=""/>';
-               $dwidth=$this->this_getOption('dialogwidth');
-               $dheight=$this->this_getOption('dialogheight');
-               $mURL=$CONF['MediaURL'].$member->getID().'/';
-?>
-<h3>NP_MitasNom</h3>
-<script type="text/javascript">
-//<![CDATA[
-function WYSIWYGpopup(textId){
-       window.open('plugins/mitasnom/popup.php?blogid=<?php echo (int)$blogid; ?>&id='+textId,'name',
-<?php echo "'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=$dwidth,height=$dheight,top=0,left=0');\n"; ?>
-}
-function convBreaks(T) {
-       T=T+'';
-       T=T.replace(/\x0D\x0A/g,"\x0A");
-       T=T.replace(/\x0D/g,"\x0A");
-       T=T.replace(/\x0A/g,"<br />\x0A");
-       return T;
-}
-function rmvBreaks(T) {
-       T=T+'';
-       T=T.replace(/\x0A/g,'');
-       T=T.replace(/\x0D/g,'');
-       T=T.replace(/<br \/>/g,'\n');
-       <?php
-               if ($this->this_getOption('returnafterbrbr')!='yes') 
-                       echo 'while (T.match(/\n\n/g)) T=T.replace(/\n\n/g,"\n<br />");'."\n"; 
-               echo 'while (T.match(/<br \/>\n/g)) T=T.replace(/<br \/>\n/g,"<br /><br />");'."\n"; 
-       ?>
-       T=T.replace(/\n<br \/>/g,'<br />\n');
-       return T;
-}
-function WYSIWYGgettext(id){
-       var T=document.getElementById(id).value+'';
-<?php
-       if ($convBreaks) echo "\tT=convBreaks(T);\n";
-       $replacearray=$this->_replaceBeforeEdit($authorid);
-       foreach($this->_patternBeforeEdit() as $key => $pattern) {
-               $replace=$replacearray[$key];
-               echo "\tT=T.replace($pattern"."g,'$replace');\n";
-       }
-?>
-       return T;
-}
-function WYSIWYGsettext(id,T){
-<?php
-       if ($convBreaks) echo "\tT=rmvBreaks(T);\n"; 
-       $replacearray=$this->_replaceAfterEdit();
-       foreach($this->_patternAfterEdit() as $key => $pattern) {
-               $replace=$replacearray[$key];
-               echo "\tT=T.replace($pattern"."g,'$replace');\n";
-       }
-?>
-       document.getElementById(id).value=T;
-       document.getElementById('mitasnom_wysiwyged').value='image';
-}
-//]]>
-</script>
-<p>
-<a href="javascript:WYSIWYGpopup('inputbody');" title="Edit by HTML editor"><?php echo $this->translated('WYSIWYG:body'); ?></a>&nbsp;&nbsp;
-<a href="javascript:WYSIWYGpopup('inputmore');" title="Edit by HTML editor"><?php echo $this->translated('WYSIWYG:more'); ?></a>
-</p>
-<?php
-       }
-
-       //<%image%>, <%popup%> conversion
-       function event_PrepareItemForEdit(&$data) {
-               global $CONF,$member;
-               if (!$this->actionplugin) return;
-               $item=&$data['item'];
-               $pattern=$this->_patternBeforeEdit();
-               $replace=$this->_replaceBeforeEdit($item['authorid']);
-               $item['body']=preg_replace($pattern,$replace,$item['body']);
-               $item['more']=preg_replace($pattern,$replace,$item['more']);
-       }
-       
-       // Creates Nucleus-specific tags (<%image%> <%popup%>) from general HTML tags.
-       function event_PreAddItem(&$item) { return $this->event_PreUpdateItem($item); }
-       function event_PreUpdateItem(&$item) {
-               if (!requestVar('mitasnom_wysiwyged')) return;
-               $body=&$item['body'];
-               $more=&$item['more'];
-               $blog=&$item['blog'];
-               $body=$this->_restoreImgPopup($body);
-               $more=$this->_restoreImgPopup($more);
-               if (requestVar('mitasnom_wysiwyged')!='full') return;
-               if ($blog->convertBreaks()) {
-                       $body=removeBreaks($body);
-                       $more=removeBreaks($more);
-               }
-               if ($this->this_getOption('returnafterbr')=='yes') {
-                       $body=$this->_addEnterAfterBr($body);
-                       $more=$this->_addEnterAfterBr($more);
-               }
-               $pattern=$this->_patternAfterEdit();
-               $replace=$this->_replaceAfterEdit();
-               $body=preg_replace($pattern,$replace,$body);
-               $more=preg_replace($pattern,$replace,$more);
-       }
-       function _addEnterAfterBr(&$data){
-               // <br/> => <br/>\n conversion
-               $ret='';
-               $data=str_replace(array("\r","\n"),'',$data);
-               while ($data) {
-                       if (($i=strpos($data,'<br />'))===false) break;
-                       $ret.=substr($data,0,$i+6);
-                       $data=substr($data,$i+6);
-                       if (substr($data,0,1)=="\x0D" || substr($data,0,1)=="\x0A") continue;
-                       if (substr($data,0,6)!='<br />' || $this->this_getOption('returnafterbrbr')=='yes') $ret.="\n";
-               }
-               return $ret.$data;
-       }
-       function _restoreImgPopup(&$data){
-               global $CONF,$member,$DIR_MEDIA;
-               //$mURL=$CONF['MediaURL'].$member->getID().'/';
-               $mURL=$CONF['MediaURL'];
-               $pattern='/<img [^>]*?src="'.str_replace('/','\/',$mURL).'[^"]*?"[^>]*? \/>/';
-               if (preg_match_all ( $pattern, $data, $matches,PREG_SET_ORDER)) {
-                       foreach($matches as $match){
-                               $subject=$match[0];
-                               $src=$width=$height=$alt='';
-                               $prop=array();
-                               foreach(explode('" ',substr($subject,5)) as $value) {
-                                       $i=strpos($value,'=');
-                                       $j=strpos($value,'"');
-                                       if ($i===false || $j===false) continue;
-                                       $key=substr($value,0,$i);
-                                       $value=substr($value,$j+1);
-                                       switch ($key) {
-                                       case 'src':
-                                               if (preg_match('/src="'.str_replace('/','\/',$mURL).'([^"]*?)"/',$subject,$match)) $src=$match[1];
-                                               break;
-                                       case 'width':
-                                               $width=$value;
-                                               break;
-                                       case 'height':
-                                               $height=$value;
-                                               break;
-                                       default:
-                                               $prop[$key]=$value;
-                                               break;
-                                       }
-                               }
-                               if (!$prop['title']) $prop['title']=$prop['alt'];
-                               if (!$prop['alt']) $prop['alt']=$prop['title'];
-                               foreach ($prop as $key => $value) {
-                                       if (!$alt) $alt.=' ';
-                                       $alt.=$key.'="'.$value.'"';
-                               }
-                               $data=str_replace($subject,"<%image($src|$width|$height|$alt)%>",$data);
-                       }
-               }
-               $pattern='/<a [\s\S]*?href="'.str_replace('/','\/',$mURL).'[^"]*?"[\s\S]*?<\/a>/';
-               if (preg_match_all ( $pattern, $data, $matches,PREG_SET_ORDER)) {
-                       $i=0;
-                       foreach($matches as $match){
-                               $subject=$match[0];
-                               if (preg_match('/href="'.str_replace('/','\/',$mURL).'([^"]*?)"/',$subject,$match)) $href=$match[1];
-                               else $href='';
-                               if (preg_match('/title="width=([^\|]*?)\|height=([^"]*?)"/',$subject,$match)) {
-                                       $width=$match[1];
-                                       $height=$match[2];
-                               } else {
-                                       $old_level = error_reporting(0);
-                                       $size = @GetImageSize($DIR_MEDIA.$href); 
-                                       error_reporting($old_level);
-                                       $width = ($height = 0);
-                                       if ($size) {
-                                               $width = $size[0];
-                                               $height = $size[1];
-                                       }
-                               }
-                               if (preg_match('/>([^<]*?)<\/a>/',$subject,$match)) $alt=$match[1];
-                               else $alt='';
-                               if (!$width) $width=100;
-                               if (!$height) $height=100;
-                               if ($alt) $data=str_replace($subject,"<%popup($href|$width|$height|$alt)%>",$data);
-                       }
-               }
-               return $data;
-       }
-
-       //Replacement for <%image%>, <%popup%>
-       function _patternBeforeEdit(){
-               return array(   '/<%image\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',
-                               '/<%image\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',
-                               '/<%image\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',
-                               '/<%image\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
-                               '/<%image\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
-                               '/<%image\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
-                               '/<%popup\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
-                               '/<%popup\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
-                               '/<%popup\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
-                               '/<%([^%]*?)%>/');
-       }
-       function _replaceBeforeEdit($authorid) {
-               global $CONF;
-               $mURL=$CONF['MediaURL'].$authorid.'/';
-               return array(   '<img src="'.$CONF['MediaURL'].'$1/$2" width="$3" height="$4" $5 alt="$6"$7 />',
-                               '<img src="'.$mURL.'$1" width="$2" height="$3" $4 alt="$5"$6 />',
-                               '<img src="'.$CONF['MediaURL'].'$1" width="$2" height="$3" $4 alt="$5"$6 />',
-                               '<img src="'.$CONF['MediaURL'].'$1/$2" width="$3" height="$4" alt="$5" title="$5" />',
-                               '<img src="'.$mURL.'$1" width="$2" height="$3" alt="$4" title="$4" />',
-                               '<img src="'.$CONF['MediaURL'].'$1" width="$2" height="$3" alt="$4" title="$4" />',
-                               '<a href="'.$CONF['MediaURL'].'$1/$2" title="width=$3|height=$4">$5</a>',
-                               '<a href="'.$mURL.'$1" title="width=$2|height=$3">$4</a>',
-                               '<a href="'.$CONF['MediaURL'].'$1" title="width=$2|height=$3">$4</a>',
-                               '<mitasnom title="nucleustag"></mitasnom><%$1%>');
-       }
-       function _patternAfterEdit(){
-               return array(   '/<mitasnom title="nucleustag"><\/mitasnom>/');
-       }
-       function _replaceAfterEdit() {
-               return array(   '');
-       }
-       
-       // Show information when editing plugin option
-       var $errormessage;
-       function event_PrePluginOptionsEdit($data){
-               if ($this->errormessage) echo "<h4>".$this->errormessage."</h4>";
-       }
-       function returnWithMessage($text) { $this->errormessage=$text;}
-
-       // Customize toolbar menu
-       function event_PostPluginOptionsUpdate($data) {
-               $plugid=$data['plugid'];
-               if ($plugid!=$this->GetID()) return;
-               $this->install();// Refresh member option settings.
-               if (!($name=$this->getOption('addremovetoolbar'))) return;
-               $name=ereg_replace("[^0-9a-zA-Z]","",$name);
-               $this->setOption('addremovetoolbar','');
-               if (!($toolbar=$this->getOption('toolbar_custom')))
-                       return $this->returnWithMessage($this->translated('Toolbar definition is empty'));
-               if (strstr(' default full basic custom ',strtolower($name)))
-                       return $this->returnWithMessage($this->translated('Default, Full, Basic and Custom toolbars cannot be removed.'));
-               $ret=$this->getOption('toolbar_'.strtolower($name));//$ret=$this->getOption('toolbar_'.$this);
-               if (!($oid=$this->this_getOid('toolbar'))) return;
-               if (!($extra=$this->this_getExtra($oid))) return;
-               if (strstr(strtolower($extra),strtolower($name))) {
-                       //delete
-                       $extra=eregi_replace("\|$name\|$name","",$extra);
-                       sql_query('UPDATE ' . sql_table('plugin_option_desc') .
-                               ' SET oextra = "'.addslashes($extra). '" WHERE oid=' . (int)$oid);
-                       $this->deleteOption('toolbar_'.strtolower($name));
-                       $this->returnWithMessage($name.$this->translated(' toolbar is deleted.'));
-               } else {
-                       //add
-                       $extra=str_replace("|Custom|Custom","|$name|$name|Custom|Custom",$extra);
-                       sql_query('UPDATE ' . sql_table('plugin_option_desc') .
-                               ' SET oextra = "'.addslashes($extra). '" WHERE oid=' . (int)$oid);
-                       $this->createOption('toolbar_'.strtolower($name), $name.$this->translated(' Toolbar'), 'textarea', $toolbar);
-                       $this->returnWithMessage($name.$this->translated(' toolbar is added.'));
-               }
-       }
-
-       // Member specific stuff
-       function this_getOption($name) {
-               global $member;
-               if ($this->getOption('usemembersettings')!='yes') return $this->getOption($name);
-               if (!$this->_useMemberSpecificOption($name)) return $this->getOption($name);
-               return $this->getMemberOption($member->getID(), $name);
-       }
-       function _useMemberSpecificOption($name) {
-               foreach ($this->_allMemberSpecificOptions() as $value) if ($name==$value) return true;
-               return false;
-       }
-       function _allMemberSpecificOptions() {
-               return array('width','height','toolbar','returnafterbr','returnafterbrbr',
-                               'dialogwidth','dialogheight','additionalpsource');
-       }
-
-       // SQL stuff
-       function this_getOid($name,$context='global'){
-               $query = 'SELECT oid, oname FROM ' . sql_table('plugin_option_desc') . 
-                       ' WHERE opid=' . intval($this->plugid).
-                       ' and ocontext="'.addslashes($context).'"';
-               $res = sql_query($query);
-               while ($o = mysql_fetch_object($res)) if ($o->oname==$name) return $o->oid;
-               return null;
-       }
-       function this_getExtra($oid){
-               $query = 'SELECT oextra FROM ' . sql_table('plugin_option_desc') . ' WHERE oid=' . intval($oid);
-               $res = sql_query($query);
-               if ($o = mysql_fetch_object($res)) return $o->oextra;
-               return null;
-       }
-
-       // Uppgrading stuff
-       function _checkVersion(){
-               if (!$this->this_getOid('version')) $this->install();
-               else if ($this->getVersion()!=$this->getOption('version')) $this->install();
-               $this->setOption('version',$this->getVersion());
-       }
-
-       // Overrided function
-       function createOption($name, $desc, $type, $defValue = '', $typeExtras = '') {
-               if (!$this->this_getOid($name)) parent::createOption($name, $desc, $type, $defValue, $typeExtras);
-               if ($this->_useMemberSpecificOption($name)) {
-                       if ($this->getOption('usemembersettings')=='yes') {
-                               if (!$this->this_getOid($name,'member')) {
-                                       if ($name=='toolbar') {
-                                               $typeExtras=quickQuery(
-                                                       'SELECT oextra as result FROM '.sql_table('plugin_option_desc').
-                                                       ' WHERE opid='.(int)$this->getID().' AND oname="toolbar"');
-                                       }
-                                       if (($Extras=$typeExtras)=='access=hidden') $Extras='';
-                                       $Extras=str_replace('|Custom|Custom','',$Extras);
-                                       $Extras=str_replace('|Full|Full','',$Extras);
-                                       $this->createMemberOption($name, $desc, $type,$this->getOption($name), $Extras);
-                               }
-                       } else {
-                               if ($this->this_getOid($name,'member'))
-                                       $this->deleteMemberOption($name);
-                       }
-               }
-               return 1;
-       }
-
-       // Language stuff
-       var $langArray;
-       function translated($english){
-               if (!is_array($this->langArray)) {
-                       $this->langArray=array();
-                       $language=$this->getDirectory().'language/'.ereg_replace( '[\\|/]', '', getLanguageName()).'.php';
-                       if (file_exists($language)) include($language);
-               }
-               if (!($ret=$this->langArray[$english])) $ret=$english;
-               return $ret;
-       }
-
-       // General function (found on PHP help page) follows
-       function unhtmlentities($string) {
-               $trans_tbl = get_html_translation_table (HTML_ENTITIES);
-               $trans_tbl = array_flip ($trans_tbl);
-               return strtr ($string, $trans_tbl);
-       }
-} 
+<?php \r
+/*\r
+ * NP_MitasNom\r
+ * This library is GPL\r
+ */\r
+class NP_MitasNom extends NucleusPlugin { \r
+       var $actionplugin=false;\r
+       var $bconvertbreaks;\r
+       function getName() {\r
+               $this->_checkVersion();\r
+               return 'NP_MitasNom'; \r
+       }\r
+       function getMinNucleusVersion() { return 220; }\r
+       function getAuthor()  { return 'Katsumi, Cacher, yamamoto'; }\r
+       function getVersion() { return '0.5.9.9.3'; }\r
+       function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:mitasnom';}\r
+       function getDescription() { return $this->translated('WYSIWYG HTML editor plagin using FCKeditor'); } \r
+       function supportsFeature($what) { return (int)($what=='SqlTablePrefix'); }\r
+       function install() {\r
+               // Install, upgrade options, and Refresh member options.\r
+               // Note: createOption() is overrided (see below).\r
+               $this->createOption('version','version','text',$this->getVersion(),'access=hidden');\r
+               $this->createOption('width',$this->translated('Width'),'text','100%'); \r
+               $this->createOption('height',$this->translated('Height'),'text','400'); \r
+               $this->createOption('toolbar',$this->translated('Toolbar'),'select','Default','Default|Default|Full|Full|Basic|Basic|Custom|Custom'); \r
+               $this->createOption('toolbar_custom',$this->translated('Custom Toolbar'), 'textarea',\r
+                       "['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],\n".\r
+                       "['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],\n".\r
+                       "['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],\n".\r
+                       "['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],\n".\r
+                       "'/',\n".\r
+                       "['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],\n".\r
+                       "['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],\n".\r
+                       "['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],\n".\r
+                       "['Link','Unlink','Anchor'],\n".\r
+                       "['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak'],\n".\r
+                       "'/',\n".\r
+                       "['Style','FontFormat','FontName','FontSize'],\n".\r
+                       "['TextColor','BGColor'],\n".\r
+                       "['FitWindow','ShowBlocks','-','About']");\r
+               $this->createOption('addremovetoolbar',$this->translated('Add new toolbar to the menu / Delete toolbar from the menu'),'text',''); \r
+               $this->createOption('returnafterbr',$this->translated('"<br />" => "<br />\n" conversion?'),'yesno','yes'); \r
+               $this->createOption('returnafterbrbr',$this->translated('"<br /><br />" => "<br />\n<br />\n" conversion?'),'yesno','no'); \r
+               $this->createOption('dialogwidth',$this->translated('Width of Popup dialog'),'text','500'); \r
+               $this->createOption('dialogheight',$this->translated('Height of Popup dialog'),'text','450'); \r
+               $this->createOption('protectedsource',$this->translated('Protected Sources'), 'textarea',\r
+                       '/<script[\s\S]*?\/script>/gi'."\n".\r
+                       '/<%[\s\S]*?%>/g');\r
+               //$this->createOption('additionalpsource',$this->translated('Additional Protected Sources'), 'textarea','');\r
+               $this->createOption('usemembersettings',$this->translated('Use member-specific settings?'),'yesno','no'); \r
+               $this->createOption('useimagemanager',$this->translated('Use Image-Manager plugin instead of media.php?'),'yesno','no'); \r
+               $this->createOption('usehttps',$this->translated('Use secure server (https) for edititing item?'),'yesno','no'); \r
+               $this->createOption('usep',$this->translated('Use P tag instead of BR for enter key?'),'yesno','no'); \r
+               $this->createOption('alwayswysiwyg',$this->translated('Always use WYSIWYG editor?'),'yesno','no'); \r
+       }\r
+       function getEventList() { return array('EditItemFormExtras','AddItemFormExtras','PrepareItemForEdit',\r
+                                       'PreAddItem','PreUpdateItem',\r
+                                       'PreItem','PostPluginOptionsUpdate','PrePluginOptionsEdit',\r
+                                       'AdminPrePageHead'); }\r
+\r
+       // SkinVar is currently used for showing link to create item\r
+       function doSkinVar($skinType,$type,$text='') {\r
+               global $blogid,$CONF,$member;\r
+               switch (strtolower($type)) {\r
+               case 'newitem':\r
+               default:\r
+                       if (!$member->isLoggedIn()) return;\r
+                       if (!$text) $text=$this->translated('New Item with WYSIWYG');\r
+                       $url=$CONF['ActionURL'].'?action=plugin&name=MitasNom&type=createitem&blogid='.$blogid;\r
+                       if ($this->getOption('usehttps')=='yes') $url=preg_replace('/^http:/','https:',$url);\r
+                       $url=htmlspecialchars($url);\r
+                       echo "<a href=\"$url\">$text</a>\n";\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // TemplateVar is currently used for showing link to edit item\r
+       function doTemplateVar(&$item,$type,$text='') {\r
+               global $CONF,$member;\r
+               switch (strtolower($type)) {\r
+               case 'edititem':\r
+               default:\r
+                       if (!$text) $text=$text=$this->translated('Edit Item with WYSIWYG');\r
+                       $itemid=$item->itemid;\r
+                       $url=$CONF['ActionURL'].'?action=plugin&name=MitasNom&type=itemedit&itemid='.$itemid;\r
+                       if ($this->getOption('usehttps')=='yes') $url=preg_replace('/^http:/','https:',$url);\r
+                       $url=htmlspecialchars($url);\r
+                       echo "<a href=\"$url\">$text</a>\n";\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // Action is used to show item-editing/newitem-creating window.\r
+       function doAction($type){\r
+               global $DIR_LIBS,$member,$manager,$CONF,$blogid,$itemid;\r
+               if (!$member->isLoggedIn()) return _NOTLOGGEDIN;\r
+               if (!strstr('createitem itemedit',$type)) return _BADACTION;\r
+\r
+               // Resolve itemid and blogid\r
+               if (!$blogid && $itemid) $blogid=getBlogIDFromItemID($itemid);\r
+               if (!$blogid) return _BADACTION;\r
+               if (!$member->teamRights($blogid)) return _ERROR_DISALLOWED;\r
+               $blog=&$manager->getBlog($blogid);\r
+               $convBreaks=false;\r
+               if ($blog) if ($blog->convertBreaks()) $convBreaks=true;\r
+\r
+               // Get editing HTML\r
+               $this->actionplugin=true;\r
+               include($DIR_LIBS . 'ADMIN.php');\r
+               $a=new ADMIN();\r
+               $CONF['DisableJsTools']=1;\r
+               switch ($type) {\r
+               case 'createitem':\r
+                       ob_start();\r
+                       $a->action_createitem();\r
+                       $buff=ob_get_contents();\r
+                       ob_end_clean();\r
+                       break;\r
+               case 'itemedit':\r
+                       ob_start();\r
+                       $a->action_itemedit();\r
+                       $buff=ob_get_contents();\r
+                       ob_end_clean();\r
+                       break;\r
+               default:\r
+                       return _BADACTION;\r
+               }\r
+               \r
+               // Return if not valid editing HTML\r
+               // These codes must be changed when non-compatible Nucleus version comes out.\r
+               if (!preg_match('/<head>/',$buff)) return _ERRORMSG;\r
+               if (!preg_match('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff)) return _ERRORMSG;\r
+               if (!preg_match('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff)) return _ERRORMSG;\r
+\r
+               // Create NucleusFCKeditor instances\r
+               if (!class_exists('NucleusFCKeditor')) include ($this->getDirectory().'fckclass.php');\r
+               $body='';\r
+               $more='';\r
+               if ($type=='itemedit') {\r
+                       if (preg_match ('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff,$matches))\r
+                               $body=$matches[3];\r
+                               $body=$this->unhtmlentities($body);\r
+                       if (preg_match ('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff,$matches))\r
+                               $more=$matches[3];\r
+                               $more=$this->unhtmlentities($more);\r
+               }\r
+               if ($convBreaks) {\r
+                       $body=addBreaks($body);\r
+                       $more=addBreaks($more);\r
+               }\r
+               $FCKedit1=new NucleusFCKEditor('body',$this,$body);\r
+               $FCKedit2=new NucleusFCKEditor('more',$this,$more);\r
+               $buff1=$FCKedit1->CreateHtml();\r
+               $buff2=$FCKedit2->CreateHtml();\r
+\r
+               // Replace texts of editing page\r
+               // These codes must be changed when non-compatible Nucleus version comes out.\r
+               $buff=preg_replace ('/<head>/','<head><base href="'.htmlspecialchars($CONF['AdminURL']).'">', $buff,1);\r
+               $buff=preg_replace ('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff1, $buff,1);\r
+               $buff=preg_replace ('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff2, $buff,1);\r
+               echo $buff;\r
+       }\r
+       \r
+       // Redirect to WYSIWYG page when the plugin option is set to do so.\r
+       function event_AdminPrePageHead(&$data){\r
+               global $CONF,$blogid,$itemid;\r
+               if ($this->this_getOption('alwayswysiwyg')!='yes') return;\r
+               switch($data['action']){\r
+               case 'itemedit':\r
+                       $type='type=itemedit&itemid='.(int)$itemid;\r
+                       break;\r
+               case 'createitem':\r
+                       $type='type=createitem&blogid='.(int)$blogid;\r
+                       break;\r
+               default:\r
+                       return;\r
+               }\r
+               $url=$CONF['ActionURL'].'?action=plugin&name=MitasNom&'.$type;\r
+               if ($this->getOption('usehttps')=='yes') $url=preg_replace('/^http:/','https:',$url);\r
+               redirect($url);\r
+       }\r
+       \r
+       // Solve <%image%> tag for showing items\r
+       function event_PreItem(&$data) {\r
+               $item=&$data['item'];\r
+               $pattern=$this->_patternBeforeEdit();\r
+               $replace=$this->_replaceBeforeEdit($item->authorid);\r
+               for ($i=0;$i<1;$i++){\r
+                       $item->body=preg_replace($pattern[$i],$replace[$i],$item->body);\r
+                       $item->more=preg_replace($pattern[$i],$replace[$i],$item->more);\r
+               }\r
+       }\r
+       \r
+       // NP_MitasNom option in editing dialog.\r
+       // This is more compatible to newer Nucleus version,\r
+       // unless 'id="inputbody"' and 'id="inputmore"' changed.\r
+       function event_AddItemFormExtras(&$data) { return $this->event_EditItemFormExtras($data); }\r
+       function event_EditItemFormExtras(&$data) {\r
+               global $DIR_LIBS,$member,$manager,$CONF,$blogid,$itemid;\r
+               // Resolve itemid and blogid\r
+               if (!$blogid && $itemid) $blogid=getBlogIDFromItemID($itemid);\r
+               if (!$blogid) return _BADACTION;\r
+               if (!$member->teamRights($blogid)) return _ERROR_DISALLOWED;\r
+               $blog=&$manager->getBlog($blogid);\r
+               $convBreaks=false;\r
+               if ($blog) if ($blog->convertBreaks()) $convBreaks=true;\r
+               $authorid=$member->getID();\r
+               if ($itemid) {\r
+                       $item=&$manager->getItem($itemid,1,1);\r
+                       $authorid=$item['authorid'];\r
+               }\r
+\r
+               if ($this->actionplugin) {\r
+                       echo '<input type="hidden" name="mitasnom_wysiwyged" id="mitasnom_wysiwyged" value="full"/>';\r
+                       return;\r
+               } else echo '<input type="hidden" name="mitasnom_wysiwyged" id="mitasnom_wysiwyged" value=""/>';\r
+               $dwidth=$this->this_getOption('dialogwidth');\r
+               $dheight=$this->this_getOption('dialogheight');\r
+               $mURL=$CONF['MediaURL'].$member->getID().'/';\r
+?>\r
+<h3>NP_MitasNom</h3>\r
+<script type="text/javascript">\r
+//<![CDATA[\r
+function WYSIWYGpopup(textId){\r
+       window.open('plugins/mitasnom/popup.php?blogid=<?php echo (int)$blogid; ?>&id='+textId,'name',\r
+<?php echo "'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=$dwidth,height=$dheight,top=0,left=0');\n"; ?>\r
+}\r
+function convBreaks(T) {\r
+       T=T+'';\r
+       T=T.replace(/\x0D\x0A/g,"\x0A");\r
+       T=T.replace(/\x0D/g,"\x0A");\r
+       T=T.replace(/\x0A/g,"<br />\x0A");\r
+       return T;\r
+}\r
+function rmvBreaks(T) {\r
+       T=T+'';\r
+       T=T.replace(/\x0A/g,'');\r
+       T=T.replace(/\x0D/g,'');\r
+       T=T.replace(/<br \/>/g,'\n');\r
+       <?php\r
+               if ($this->this_getOption('returnafterbrbr')!='yes') \r
+                       echo 'while (T.match(/\n\n/g)) T=T.replace(/\n\n/g,"\n<br />");'."\n"; \r
+               echo 'while (T.match(/<br \/>\n/g)) T=T.replace(/<br \/>\n/g,"<br /><br />");'."\n"; \r
+       ?>\r
+       T=T.replace(/\n<br \/>/g,'<br />\n');\r
+       return T;\r
+}\r
+function WYSIWYGgettext(id){\r
+       var T=document.getElementById(id).value+'';\r
+<?php\r
+       if ($convBreaks) echo "\tT=convBreaks(T);\n";\r
+       $replacearray=$this->_replaceBeforeEdit($authorid);\r
+       foreach($this->_patternBeforeEdit() as $key => $pattern) {\r
+               $replace=$replacearray[$key];\r
+               echo "\tT=T.replace($pattern"."g,'$replace');\n";\r
+       }\r
+?>\r
+       return T;\r
+}\r
+function WYSIWYGsettext(id,T){\r
+<?php\r
+       if ($convBreaks) echo "\tT=rmvBreaks(T);\n"; \r
+       $replacearray=$this->_replaceAfterEdit();\r
+       foreach($this->_patternAfterEdit() as $key => $pattern) {\r
+               $replace=$replacearray[$key];\r
+               echo "\tT=T.replace($pattern"."g,'$replace');\n";\r
+       }\r
+?>\r
+       document.getElementById(id).value=T;\r
+       document.getElementById('mitasnom_wysiwyged').value='image';\r
+}\r
+//]]>\r
+</script>\r
+<p>\r
+<a href="javascript:WYSIWYGpopup('inputbody');" title="Edit by HTML editor"><?php echo $this->translated('WYSIWYG:body'); ?></a>&nbsp;&nbsp;\r
+<a href="javascript:WYSIWYGpopup('inputmore');" title="Edit by HTML editor"><?php echo $this->translated('WYSIWYG:more'); ?></a>\r
+</p>\r
+<?php\r
+       }\r
+\r
+       //<%image%>, <%popup%> conversion\r
+       function event_PrepareItemForEdit(&$data) {\r
+               global $CONF,$member;\r
+               if (!$this->actionplugin) return;\r
+               $item=&$data['item'];\r
+               $pattern=$this->_patternBeforeEdit();\r
+               $replace=$this->_replaceBeforeEdit($item['authorid']);\r
+               $item['body']=preg_replace($pattern,$replace,$item['body']);\r
+               $item['more']=preg_replace($pattern,$replace,$item['more']);\r
+       }\r
+       \r
+       // Creates Nucleus-specific tags (<%image%> <%popup%>) from general HTML tags.\r
+       function event_PreAddItem(&$item) { return $this->event_PreUpdateItem($item); }\r
+       function event_PreUpdateItem(&$item) {\r
+               if (!requestVar('mitasnom_wysiwyged')) return;\r
+               $body=&$item['body'];\r
+               $more=&$item['more'];\r
+               $blog=&$item['blog'];\r
+               $body=$this->_restoreImgPopup($body);\r
+               $more=$this->_restoreImgPopup($more);\r
+               if (requestVar('mitasnom_wysiwyged')!='full') return;\r
+               if ($blog->convertBreaks()) {\r
+                       $body=removeBreaks($body);\r
+                       $more=removeBreaks($more);\r
+               }\r
+               if ($this->this_getOption('returnafterbr')=='yes') {\r
+                       $body=$this->_addEnterAfterBr($body);\r
+                       $more=$this->_addEnterAfterBr($more);\r
+               }\r
+               $pattern=$this->_patternAfterEdit();\r
+               $replace=$this->_replaceAfterEdit();\r
+               $body=preg_replace($pattern,$replace,$body);\r
+               $more=preg_replace($pattern,$replace,$more);\r
+       }\r
+       function _addEnterAfterBr(&$data){\r
+               // <br/> => <br/>\n conversion\r
+               $array=preg_split('/<br[^>]*>/',str_replace(array("\r","\n"),'',$data));\r
+               $c=count($array);\r
+               $data=$array[0];\r
+               for ($i=1;$i<$c;$i++) {\r
+                       $data.='<br />';\r
+                       if (strlen($array[$i]) || $this->this_getOption('returnafterbrbr')=='yes') $data.="\n";\r
+                       $data.=$array[$i];\r
+               }\r
+               return $data;\r
+       }\r
+       function _restoreImgPopup(&$data){\r
+               global $CONF,$member,$DIR_MEDIA;\r
+               //$mURL=$CONF['MediaURL'].$member->getID().'/';\r
+               $mURL=$CONF['MediaURL'];\r
+               $pattern='/<img [^>]*?src="'.str_replace('/','\/',$mURL).'[^"]*?"[^>]*? \/>/';\r
+               if (preg_match_all ( $pattern, $data, $matches,PREG_SET_ORDER)) {\r
+                       foreach($matches as $match){\r
+                               $subject=$match[0];\r
+                               $src=$width=$height=$alt='';\r
+                               $prop=array();\r
+                               foreach(explode('" ',substr($subject,5)) as $value) {\r
+                                       $i=strpos($value,'=');\r
+                                       $j=strpos($value,'"');\r
+                                       if ($i===false || $j===false) continue;\r
+                                       $key=substr($value,0,$i);\r
+                                       $value=substr($value,$j+1);\r
+                                       switch ($key) {\r
+                                       case 'src':\r
+                                               if (preg_match('/src="'.str_replace('/','\/',$mURL).'([^"]*?)"/',$subject,$match)) $src=$match[1];\r
+                                               break;\r
+                                       case 'width':\r
+                                               $width=$value;\r
+                                               break;\r
+                                       case 'height':\r
+                                               $height=$value;\r
+                                               break;\r
+                                       default:\r
+                                               $prop[$key]=$value;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               if (!$prop['title']) $prop['title']=$prop['alt'];\r
+                               if (!$prop['alt']) $prop['alt']=$prop['title'];\r
+                               foreach ($prop as $key => $value) {\r
+                                       if (!$alt) $alt.=' ';\r
+                                       $alt.=$key.'="'.$value.'"';\r
+                               }\r
+                               $data=str_replace($subject,"<%image($src|$width|$height|$alt)%>",$data);\r
+                       }\r
+               }\r
+               $pattern='/<a [\s\S]*?href="'.str_replace('/','\/',$mURL).'[^"]*?"[\s\S]*?<\/a>/';\r
+               if (preg_match_all ( $pattern, $data, $matches,PREG_SET_ORDER)) {\r
+                       $i=0;\r
+                       foreach($matches as $match){\r
+                               $subject=$match[0];\r
+                               if (preg_match('/href="'.str_replace('/','\/',$mURL).'([^"]*?)"/',$subject,$match)) $href=$match[1];\r
+                               else $href='';\r
+                               if (preg_match('/title="width=([^\|]*?)\|height=([^"]*?)"/',$subject,$match)) {\r
+                                       $width=$match[1];\r
+                                       $height=$match[2];\r
+                               } else {\r
+                                       $old_level = error_reporting(0);\r
+                                       $size = @GetImageSize($DIR_MEDIA.$href); \r
+                                       error_reporting($old_level);\r
+                                       $width = ($height = 0);\r
+                                       if ($size) {\r
+                                               $width = $size[0];\r
+                                               $height = $size[1];\r
+                                       }\r
+                               }\r
+                               if (preg_match('/>([^<]*?)<\/a>/',$subject,$match)) $alt=$match[1];\r
+                               else $alt='';\r
+                               if (!$width) $width=100;\r
+                               if (!$height) $height=100;\r
+                               if ($alt) $data=str_replace($subject,"<%popup($href|$width|$height|$alt)%>",$data);\r
+                       }\r
+               }\r
+               return $data;\r
+       }\r
+\r
+       //Replacement for <%image%>, <%popup%>\r
+       function _patternBeforeEdit(){\r
+               return array(   '/<%image\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',\r
+                               '/<%image\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',\r
+                               '/<%image\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',\r
+                               '/<%image\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',\r
+                               '/<%image\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',\r
+                               '/<%image\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',\r
+                               '/<%popup\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',\r
+                               '/<%popup\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',\r
+                               '/<%popup\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',\r
+                               '/<%([^%]*?)%>/');\r
+       }\r
+       function _replaceBeforeEdit($authorid) {\r
+               global $CONF;\r
+               $mURL=$CONF['MediaURL'].$authorid.'/';\r
+               return array(   '<img src="'.$CONF['MediaURL'].'$1/$2" width="$3" height="$4" $5 alt="$6"$7 />',\r
+                               '<img src="'.$mURL.'$1" width="$2" height="$3" $4 alt="$5"$6 />',\r
+                               '<img src="'.$CONF['MediaURL'].'$1" width="$2" height="$3" $4 alt="$5"$6 />',\r
+                               '<img src="'.$CONF['MediaURL'].'$1/$2" width="$3" height="$4" alt="$5" title="$5" />',\r
+                               '<img src="'.$mURL.'$1" width="$2" height="$3" alt="$4" title="$4" />',\r
+                               '<img src="'.$CONF['MediaURL'].'$1" width="$2" height="$3" alt="$4" title="$4" />',\r
+                               '<a href="'.$CONF['MediaURL'].'$1/$2" title="width=$3|height=$4">$5</a>',\r
+                               '<a href="'.$mURL.'$1" title="width=$2|height=$3">$4</a>',\r
+                               '<a href="'.$CONF['MediaURL'].'$1" title="width=$2|height=$3">$4</a>',\r
+                               '<table border class="mitasnom"><tr><td>'.\r
+                                       '<img src="'.$this->getAdminURL().'editor/plugins/nucleus/nucleus.gif" width="42" height="15" alt="nucleustag" />'.\r
+                                       '<%$1%></td></tr></table>');\r
+       }\r
+       function _patternAfterEdit(){\r
+               return array('/<table[^>]*class="mitasnom"[^>]*>[\s\S]*?<%([^%]*?)%>[\s\S]*?<\/table>/');\r
+       }\r
+       function _replaceAfterEdit() {\r
+               return array('<%$1%>');\r
+       }\r
+       \r
+       // Show information when editing plugin option\r
+       var $errormessage;\r
+       function event_PrePluginOptionsEdit($data){\r
+               if ($this->errormessage) echo "<h4>".$this->errormessage."</h4>";\r
+       }\r
+       function returnWithMessage($text) { $this->errormessage=$text;}\r
+\r
+       // Customize toolbar menu\r
+       function event_PostPluginOptionsUpdate($data) {\r
+               $plugid=$data['plugid'];\r
+               if ($plugid!=$this->GetID()) return;\r
+               $this->install();// Refresh member option settings.\r
+               if (!($name=$this->getOption('addremovetoolbar'))) return;\r
+               $name=ereg_replace("[^0-9a-zA-Z]","",$name);\r
+               $this->setOption('addremovetoolbar','');\r
+               if (!($toolbar=$this->getOption('toolbar_custom')))\r
+                       return $this->returnWithMessage($this->translated('Toolbar definition is empty'));\r
+               if (strstr(' default full basic custom ',strtolower($name)))\r
+                       return $this->returnWithMessage($this->translated('Default, Full, Basic and Custom toolbars cannot be removed.'));\r
+               $ret=$this->getOption('toolbar_'.strtolower($name));//$ret=$this->getOption('toolbar_'.$this);\r
+               if (!($oid=$this->this_getOid('toolbar'))) return;\r
+               if (!($extra=$this->this_getExtra($oid))) return;\r
+               if (strstr(strtolower($extra),strtolower($name))) {\r
+                       //delete\r
+                       $extra=eregi_replace("\|$name\|$name","",$extra);\r
+                       sql_query('UPDATE ' . sql_table('plugin_option_desc') .\r
+                               ' SET oextra = "'.addslashes($extra). '" WHERE oid=' . (int)$oid);\r
+                       $this->deleteOption('toolbar_'.strtolower($name));\r
+                       $this->returnWithMessage($name.$this->translated(' toolbar is deleted.'));\r
+               } else {\r
+                       //add\r
+                       $extra=str_replace("|Custom|Custom","|$name|$name|Custom|Custom",$extra);\r
+                       sql_query('UPDATE ' . sql_table('plugin_option_desc') .\r
+                               ' SET oextra = "'.addslashes($extra). '" WHERE oid=' . (int)$oid);\r
+                       $this->createOption('toolbar_'.strtolower($name), $name.$this->translated(' Toolbar'), 'textarea', $toolbar);\r
+                       $this->returnWithMessage($name.$this->translated(' toolbar is added.'));\r
+               }\r
+       }\r
+\r
+       // Member specific stuff\r
+       function this_getOption($name) {\r
+               global $member;\r
+               if ($this->getOption('usemembersettings')!='yes') return $this->getOption($name);\r
+               if (!$this->_useMemberSpecificOption($name)) return $this->getOption($name);\r
+               return $this->getMemberOption($member->getID(), $name);\r
+       }\r
+       function _useMemberSpecificOption($name) {\r
+               foreach ($this->_allMemberSpecificOptions() as $value) if ($name==$value) return true;\r
+               return false;\r
+       }\r
+       function _allMemberSpecificOptions() {\r
+               return array('width','height','toolbar','returnafterbr','returnafterbrbr',\r
+                               'dialogwidth','dialogheight','additionalpsource');\r
+       }\r
+\r
+       // SQL stuff\r
+       function this_getOid($name,$context='global'){\r
+               $query = 'SELECT oid, oname FROM ' . sql_table('plugin_option_desc') . \r
+                       ' WHERE opid=' . intval($this->plugid).\r
+                       ' and ocontext="'.addslashes($context).'"';\r
+               $res = sql_query($query);\r
+               while ($o = mysql_fetch_object($res)) if ($o->oname==$name) return $o->oid;\r
+               return null;\r
+       }\r
+       function this_getExtra($oid){\r
+               $query = 'SELECT oextra FROM ' . sql_table('plugin_option_desc') . ' WHERE oid=' . intval($oid);\r
+               $res = sql_query($query);\r
+               if ($o = mysql_fetch_object($res)) return $o->oextra;\r
+               return null;\r
+       }\r
+\r
+       // Uppgrading stuff\r
+       function _checkVersion(){\r
+               if (!$this->this_getOid('version')) $this->install();\r
+               else if ($this->getVersion()!=$this->getOption('version')) $this->install();\r
+               $this->setOption('version',$this->getVersion());\r
+       }\r
+\r
+       // Overrided function\r
+       function createOption($name, $desc, $type, $defValue = '', $typeExtras = '') {\r
+               if (!$this->this_getOid($name)) parent::createOption($name, $desc, $type, $defValue, $typeExtras);\r
+               if ($this->_useMemberSpecificOption($name)) {\r
+                       if ($this->getOption('usemembersettings')=='yes') {\r
+                               if (!$this->this_getOid($name,'member')) {\r
+                                       if ($name=='toolbar') {\r
+                                               $typeExtras=quickQuery(\r
+                                                       'SELECT oextra as result FROM '.sql_table('plugin_option_desc').\r
+                                                       ' WHERE opid='.(int)$this->getID().' AND oname="toolbar"');\r
+                                       }\r
+                                       if (($Extras=$typeExtras)=='access=hidden') $Extras='';\r
+                                       $Extras=str_replace('|Custom|Custom','',$Extras);\r
+                                       $Extras=str_replace('|Full|Full','',$Extras);\r
+                                       $this->createMemberOption($name, $desc, $type,$this->getOption($name), $Extras);\r
+                               }\r
+                       } else {\r
+                               if ($this->this_getOid($name,'member'))\r
+                                       $this->deleteMemberOption($name);\r
+                       }\r
+               }\r
+               return 1;\r
+       }\r
+\r
+       // Language stuff\r
+       var $langArray;\r
+       function translated($english){\r
+               if (!is_array($this->langArray)) {\r
+                       $this->langArray=array();\r
+                       $language=$this->getDirectory().'language/'.ereg_replace( '[\\|/]', '', getLanguageName()).'.php';\r
+                       if (file_exists($language)) include($language);\r
+               }\r
+               if (!($ret=$this->langArray[$english])) $ret=$english;\r
+               return $ret;\r
+       }\r
+\r
+       // General function (found on PHP help page) follows\r
+       function unhtmlentities($string) {\r
+               $trans_tbl = get_html_translation_table (HTML_ENTITIES);\r
+               $trans_tbl = array_flip ($trans_tbl);\r
+               return strtr ($string, $trans_tbl);\r
+       }\r
+} \r
 ?>
\ No newline at end of file