4 * This library is GPL
\r
6 class NP_MitasNom extends NucleusPlugin {
\r
7 var $actionplugin=false;
\r
10 $this->_checkVersion();
\r
11 return 'NP_MitasNom';
\r
13 function getMinNucleusVersion() { return 220; }
\r
14 function getAuthor() { return 'Katsumi, Cacher, yamamoto'; }
\r
15 function getVersion() { return '0.6.0'; }
\r
16 function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:mitasnom';}
\r
17 function getDescription() { return $this->translated('WYSIWYG HTML editor plagin using FCKeditor'); }
\r
18 function supportsFeature($what) { return (int)($what=='SqlTablePrefix'); }
\r
19 function install() {
\r
20 // Install, upgrade options, and Refresh member options.
\r
21 // Note: createOption() is overrided (see below).
\r
22 $this->createOption('version','version','text',$this->getVersion(),'access=hidden');
\r
23 $this->createOption('width',$this->translated('Width'),'text','100%');
\r
24 $this->createOption('height',$this->translated('Height'),'text','400');
\r
25 $this->createOption('toolbar',$this->translated('Toolbar'),'select','Default','Default|Default|Full|Full|Basic|Basic|Custom|Custom');
\r
26 $this->createOption('toolbar_custom',$this->translated('Custom Toolbar'), 'textarea',
\r
27 "['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],\n".
\r
28 "['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],\n".
\r
29 "['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],\n".
\r
30 "['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],\n".
\r
32 "['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],\n".
\r
33 "['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],\n".
\r
34 "['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],\n".
\r
35 "['Link','Unlink','Anchor'],\n".
\r
36 "['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak'],\n".
\r
38 "['Style','FontFormat','FontName','FontSize'],\n".
\r
39 "['TextColor','BGColor'],\n".
\r
40 "['FitWindow','ShowBlocks','-','About']");
\r
41 $this->createOption('addremovetoolbar',$this->translated('Add new toolbar to the menu / Delete toolbar from the menu'),'text','');
\r
42 $this->createOption('returnafterbr',$this->translated('"<br />" => "<br />\n" conversion?'),'yesno','yes');
\r
43 $this->createOption('returnafterbrbr',$this->translated('"<br /><br />" => "<br />\n<br />\n" conversion?'),'yesno','no');
\r
44 $this->createOption('dialogwidth',$this->translated('Width of Popup dialog'),'text','500');
\r
45 $this->createOption('dialogheight',$this->translated('Height of Popup dialog'),'text','450');
\r
46 $this->createOption('protectedsource',$this->translated('Protected Sources'), 'textarea',
\r
47 '/<script[\s\S]*?\/script>/gi'."\n".
\r
49 //$this->createOption('additionalpsource',$this->translated('Additional Protected Sources'), 'textarea','');
\r
50 $this->createOption('usemembersettings',$this->translated('Use member-specific settings?'),'yesno','no');
\r
51 $this->createOption('useimagemanager',$this->translated('Use Image-Manager plugin instead of media.php?'),'yesno','no');
\r
52 $this->createOption('usehttps',$this->translated('Use secure server (https) for edititing item?'),'yesno','no');
\r
53 $this->createOption('usep',$this->translated('Use P tag instead of BR for enter key?'),'yesno','no');
\r
54 $this->createOption('alwayswysiwyg',$this->translated('Always use WYSIWYG editor?'),'yesno','no');
\r
56 function getEventList() { return array('EditItemFormExtras','AddItemFormExtras','PrepareItemForEdit',
\r
57 'PreAddItem','PreUpdateItem',
\r
58 'PreItem','PostPluginOptionsUpdate','PrePluginOptionsEdit',
\r
59 'AdminPrePageHead'); }
\r
61 // SkinVar is currently used for showing link to create item
\r
62 function doSkinVar($skinType,$type,$text='') {
\r
63 global $blogid,$CONF,$member;
\r
64 switch (strtolower($type)) {
\r
67 if (!$member->isLoggedIn()) return;
\r
68 if (!$text) $text=$this->translated('New Item with WYSIWYG');
\r
69 $url=$CONF['ActionURL'].'?action=plugin&name=MitasNom&type=createitem&blogid='.$blogid;
\r
70 if ($this->getOption('usehttps')=='yes') $url=preg_replace('/^http:/','https:',$url);
\r
71 $url=htmlspecialchars($url);
\r
72 echo "<a href=\"$url\">$text</a>\n";
\r
77 // TemplateVar is currently used for showing link to edit item
\r
78 function doTemplateVar(&$item,$type,$text='') {
\r
79 global $CONF,$member;
\r
80 switch (strtolower($type)) {
\r
83 if (!$text) $text=$text=$this->translated('Edit Item with WYSIWYG');
\r
84 $itemid=$item->itemid;
\r
85 $url=$CONF['ActionURL'].'?action=plugin&name=MitasNom&type=itemedit&itemid='.$itemid;
\r
86 if ($this->getOption('usehttps')=='yes') $url=preg_replace('/^http:/','https:',$url);
\r
87 $url=htmlspecialchars($url);
\r
88 echo "<a href=\"$url\">$text</a>\n";
\r
93 // Action is used to show item-editing/newitem-creating window.
\r
94 function doAction($type){
\r
95 global $DIR_LIBS,$member,$manager,$CONF,$blogid,$itemid;
\r
96 if (!$member->isLoggedIn()) return _NOTLOGGEDIN;
\r
97 if (!strstr('createitem itemedit',$type)) return _BADACTION;
\r
99 // Resolve itemid and blogid
\r
100 if (!$blogid && $itemid) $blogid=getBlogIDFromItemID($itemid);
\r
101 if (!$blogid) return _BADACTION;
\r
102 if (!$member->teamRights($blogid)) return _ERROR_DISALLOWED;
\r
103 $blog=&$manager->getBlog($blogid);
\r
105 if ($blog) if ($blog->convertBreaks()) $convBreaks=true;
\r
107 // Get editing HTML
\r
108 $this->actionplugin=true;
\r
109 include($DIR_LIBS . 'ADMIN.php');
\r
111 $CONF['DisableJsTools']=1;
\r
115 $a->action_createitem();
\r
116 $buff=ob_get_contents();
\r
121 $a->action_itemedit();
\r
122 $buff=ob_get_contents();
\r
129 // Return if not valid editing HTML
\r
130 // These codes must be changed when non-compatible Nucleus version comes out.
\r
131 if (!preg_match('/<head>/',$buff)) return _ERRORMSG;
\r
132 if (!preg_match('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff)) return _ERRORMSG;
\r
133 if (!preg_match('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff)) return _ERRORMSG;
\r
135 // Create NucleusFCKeditor instances
\r
136 if (!class_exists('NucleusFCKeditor')) include ($this->getDirectory().'fckclass.php');
\r
139 if ($type=='itemedit') {
\r
140 if (preg_match ('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff,$matches))
\r
142 $body=$this->unhtmlentities($body);
\r
143 if (preg_match ('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff,$matches))
\r
145 $more=$this->unhtmlentities($more);
\r
148 $body=addBreaks($body);
\r
149 $more=addBreaks($more);
\r
151 $FCKedit1=new NucleusFCKEditor('body',$this,$body);
\r
152 $FCKedit2=new NucleusFCKEditor('more',$this,$more);
\r
153 $buff1=$FCKedit1->CreateHtml();
\r
154 $buff2=$FCKedit2->CreateHtml();
\r
156 // Replace texts of editing page
\r
157 // These codes must be changed when non-compatible Nucleus version comes out.
\r
158 $buff=preg_replace ('/<head>/','<head><base href="'.htmlspecialchars($CONF['AdminURL']).'">', $buff,1);
\r
159 $buff=preg_replace ('/<textarea([^>]*)inputbody([^>]*)>([^>]*)<\/textarea>/',$buff1, $buff,1);
\r
160 $buff=preg_replace ('/<textarea([^>]*)inputmore([^>]*)>([^>]*)<\/textarea>/',$buff2, $buff,1);
\r
164 // Redirect to WYSIWYG page when the plugin option is set to do so.
\r
165 function event_AdminPrePageHead(&$data){
\r
166 global $CONF,$blogid,$itemid;
\r
167 if ($this->this_getOption('alwayswysiwyg')!='yes') return;
\r
168 switch($data['action']){
\r
170 $type='type=itemedit&itemid='.(int)$itemid;
\r
173 $type='type=createitem&blogid='.(int)$blogid;
\r
178 $url=$CONF['ActionURL'].'?action=plugin&name=MitasNom&'.$type;
\r
179 if ($this->getOption('usehttps')=='yes') $url=preg_replace('/^http:/','https:',$url);
\r
183 // Solve <%image%> tag for showing items
\r
184 function event_PreItem(&$data) {
\r
185 $item=&$data['item'];
\r
186 $pattern=$this->_patternBeforeEdit();
\r
187 $replace=$this->_replaceBeforeEdit($item->authorid);
\r
188 for ($i=0;$i<1;$i++){
\r
189 $item->body=preg_replace($pattern[$i],$replace[$i],$item->body);
\r
190 $item->more=preg_replace($pattern[$i],$replace[$i],$item->more);
\r
194 // NP_MitasNom option in editing dialog.
\r
195 // This is more compatible to newer Nucleus version,
\r
196 // unless 'id="inputbody"' and 'id="inputmore"' changed.
\r
197 function event_AddItemFormExtras(&$data) { return $this->event_EditItemFormExtras($data); }
\r
198 function event_EditItemFormExtras(&$data) {
\r
199 global $DIR_LIBS,$member,$manager,$CONF,$blogid,$itemid;
\r
200 // Resolve itemid and blogid
\r
201 if (!$blogid && $itemid) $blogid=getBlogIDFromItemID($itemid);
\r
202 if (!$blogid) return _BADACTION;
\r
203 if (!$member->teamRights($blogid)) return _ERROR_DISALLOWED;
\r
204 $blog=&$manager->getBlog($blogid);
\r
206 if ($blog) if ($blog->convertBreaks()) $convBreaks=true;
\r
207 $authorid=$member->getID();
\r
209 $item=&$manager->getItem($itemid,1,1);
\r
210 $authorid=$item['authorid'];
\r
213 if ($this->actionplugin) {
\r
214 echo '<input type="hidden" name="mitasnom_wysiwyged" id="mitasnom_wysiwyged" value="full"/>';
\r
216 } else echo '<input type="hidden" name="mitasnom_wysiwyged" id="mitasnom_wysiwyged" value=""/>';
\r
217 $dwidth=$this->this_getOption('dialogwidth');
\r
218 $dheight=$this->this_getOption('dialogheight');
\r
219 $mURL=$CONF['MediaURL'].$member->getID().'/';
\r
221 <h3>NP_MitasNom</h3>
\r
222 <script type="text/javascript">
\r
224 function WYSIWYGpopup(textId){
\r
225 window.open('plugins/mitasnom/popup.php?blogid=<?php echo (int)$blogid; ?>&id='+textId,'name',
\r
226 <?php echo "'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=$dwidth,height=$dheight,top=0,left=0');\n"; ?>
\r
228 function convBreaks(T) {
\r
230 T=T.replace(/\x0D\x0A/g,"\x0A");
\r
231 T=T.replace(/\x0D/g,"\x0A");
\r
232 T=T.replace(/\x0A/g,"<br />\x0A");
\r
235 function rmvBreaks(T) {
\r
237 T=T.replace(/\x0A/g,'');
\r
238 T=T.replace(/\x0D/g,'');
\r
239 T=T.replace(/<br \/>/g,'\n');
\r
241 if ($this->this_getOption('returnafterbrbr')!='yes')
\r
242 echo 'while (T.match(/\n\n/g)) T=T.replace(/\n\n/g,"\n<br />");'."\n";
\r
243 echo 'while (T.match(/<br \/>\n/g)) T=T.replace(/<br \/>\n/g,"<br /><br />");'."\n";
\r
245 T=T.replace(/\n<br \/>/g,'<br />\n');
\r
248 function WYSIWYGgettext(id){
\r
249 var T=document.getElementById(id).value+'';
\r
251 if ($convBreaks) echo "\tT=convBreaks(T);\n";
\r
252 $replacearray=$this->_replaceBeforeEdit($authorid);
\r
253 foreach($this->_patternBeforeEdit() as $key => $pattern) {
\r
254 $replace=$replacearray[$key];
\r
255 echo "\tT=T.replace($pattern"."g,'$replace');\n";
\r
260 function WYSIWYGsettext(id,T){
\r
262 if ($convBreaks) echo "\tT=rmvBreaks(T);\n";
\r
263 $replacearray=$this->_replaceAfterEdit();
\r
264 foreach($this->_patternAfterEdit() as $key => $pattern) {
\r
265 $replace=$replacearray[$key];
\r
266 echo "\tT=T.replace($pattern"."g,'$replace');\n";
\r
269 document.getElementById(id).value=T;
\r
270 document.getElementById('mitasnom_wysiwyged').value='image';
\r
275 <a href="javascript:WYSIWYGpopup('inputbody');" title="Edit by HTML editor"><?php echo $this->translated('WYSIWYG:body'); ?></a>
\r
276 <a href="javascript:WYSIWYGpopup('inputmore');" title="Edit by HTML editor"><?php echo $this->translated('WYSIWYG:more'); ?></a>
\r
281 //<%image%>, <%popup%> conversion
\r
282 function event_PrepareItemForEdit(&$data) {
\r
283 global $CONF,$member;
\r
284 if (!$this->actionplugin) return;
\r
285 $item=&$data['item'];
\r
286 $pattern=$this->_patternBeforeEdit();
\r
287 $replace=$this->_replaceBeforeEdit($item['authorid']);
\r
288 $item['body']=preg_replace($pattern,$replace,$item['body']);
\r
289 $item['more']=preg_replace($pattern,$replace,$item['more']);
\r
292 // Creates Nucleus-specific tags (<%image%> <%popup%>) from general HTML tags.
\r
293 function event_PreAddItem(&$item) { return $this->event_PreUpdateItem($item); }
\r
294 function event_PreUpdateItem(&$item) {
\r
295 if (!requestVar('mitasnom_wysiwyged')) return;
\r
296 $body=&$item['body'];
\r
297 $more=&$item['more'];
\r
298 $blog=&$item['blog'];
\r
299 $body=$this->_restoreImgPopup($body);
\r
300 $more=$this->_restoreImgPopup($more);
\r
301 if (requestVar('mitasnom_wysiwyged')!='full') return;
\r
302 if ($blog->convertBreaks()) {
\r
303 $body=removeBreaks($body);
\r
304 $more=removeBreaks($more);
\r
306 if ($this->this_getOption('returnafterbr')=='yes') {
\r
307 $body=$this->_addEnterAfterBr($body);
\r
308 $more=$this->_addEnterAfterBr($more);
\r
310 $pattern=$this->_patternAfterEdit();
\r
311 $replace=$this->_replaceAfterEdit();
\r
312 $body=preg_replace($pattern,$replace,$body);
\r
313 $more=preg_replace($pattern,$replace,$more);
\r
315 function _addEnterAfterBr(&$data){
\r
316 // <br/> => <br/>\n conversion
\r
317 $array=preg_split('/<br[^>]*>/',str_replace(array("\r","\n"),'',$data));
\r
320 for ($i=1;$i<$c;$i++) {
\r
322 if (strlen($array[$i]) || $this->this_getOption('returnafterbrbr')=='yes') $data.="\n";
\r
327 function _restoreImgPopup(&$data){
\r
328 global $CONF,$member,$DIR_MEDIA;
\r
329 //$mURL=$CONF['MediaURL'].$member->getID().'/';
\r
330 $mURL=$CONF['MediaURL'];
\r
331 $pattern='/<img [^>]*?src="'.str_replace('/','\/',$mURL).'[^"]*?"[^>]*? \/>/';
\r
332 if (preg_match_all ( $pattern, $data, $matches,PREG_SET_ORDER)) {
\r
333 foreach($matches as $match){
\r
334 $subject=$match[0];
\r
335 $src=$width=$height=$alt='';
\r
337 foreach(explode('" ',substr($subject,5)) as $value) {
\r
338 $i=strpos($value,'=');
\r
339 $j=strpos($value,'"');
\r
340 if ($i===false || $j===false) continue;
\r
341 $key=substr($value,0,$i);
\r
342 $value=substr($value,$j+1);
\r
345 if (preg_match('/src="'.str_replace('/','\/',$mURL).'([^"]*?)"/',$subject,$match)) $src=$match[1];
\r
354 $prop[$key]=$value;
\r
358 if (!$prop['title']) $prop['title']=$prop['alt'];
\r
359 if (!$prop['alt']) $prop['alt']=$prop['title'];
\r
360 foreach ($prop as $key => $value) {
\r
361 if (!$alt) $alt.=' ';
\r
362 $alt.=$key.'="'.$value.'"';
\r
364 $data=str_replace($subject,"<%image($src|$width|$height|$alt)%>",$data);
\r
367 $pattern='/<a [\s\S]*?href="'.str_replace('/','\/',$mURL).'[^"]*?"[\s\S]*?<\/a>/';
\r
368 if (preg_match_all ( $pattern, $data, $matches,PREG_SET_ORDER)) {
\r
370 foreach($matches as $match){
\r
371 $subject=$match[0];
\r
372 if (preg_match('/href="'.str_replace('/','\/',$mURL).'([^"]*?)"/',$subject,$match)) $href=$match[1];
\r
374 if (preg_match('/title="width=([^\|]*?)\|height=([^"]*?)"/',$subject,$match)) {
\r
378 $old_level = error_reporting(0);
\r
379 $size = @GetImageSize($DIR_MEDIA.$href);
\r
380 error_reporting($old_level);
\r
381 $width = ($height = 0);
\r
384 $height = $size[1];
\r
387 if (preg_match('/>([^<]*?)<\/a>/',$subject,$match)) $alt=$match[1];
\r
389 if (!$width) $width=100;
\r
390 if (!$height) $height=100;
\r
391 if ($alt) $data=str_replace($subject,"<%popup($href|$width|$height|$alt)%>",$data);
\r
397 //Replacement for <%image%>, <%popup%>
\r
398 function _patternBeforeEdit(){
\r
399 return array( '/<%image\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',
\r
400 '/<%image\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',
\r
401 '/<%image\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)alt="([^"]*?)"([^\)]*?)\)%>/',
\r
402 '/<%image\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
\r
403 '/<%image\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
\r
404 '/<%image\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
\r
405 '/<%popup\(([0-9]*?)\/([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
\r
406 '/<%popup\(([^\|\/]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
\r
407 '/<%popup\(([^\|]*?)\|([0-9]*?)\|([0-9]*?)\|([^\)]*?)\)%>/',
\r
410 function _replaceBeforeEdit($authorid) {
\r
412 $mURL=$CONF['MediaURL'].$authorid.'/';
\r
413 return array( '<img src="'.$CONF['MediaURL'].'$1/$2" width="$3" height="$4" $5 alt="$6"$7 />',
\r
414 '<img src="'.$mURL.'$1" width="$2" height="$3" $4 alt="$5"$6 />',
\r
415 '<img src="'.$CONF['MediaURL'].'$1" width="$2" height="$3" $4 alt="$5"$6 />',
\r
416 '<img src="'.$CONF['MediaURL'].'$1/$2" width="$3" height="$4" alt="$5" title="$5" />',
\r
417 '<img src="'.$mURL.'$1" width="$2" height="$3" alt="$4" title="$4" />',
\r
418 '<img src="'.$CONF['MediaURL'].'$1" width="$2" height="$3" alt="$4" title="$4" />',
\r
419 '<a href="'.$CONF['MediaURL'].'$1/$2" title="width=$3|height=$4">$5</a>',
\r
420 '<a href="'.$mURL.'$1" title="width=$2|height=$3">$4</a>',
\r
421 '<a href="'.$CONF['MediaURL'].'$1" title="width=$2|height=$3">$4</a>',
\r
422 '<table border class="mitasnom"><tr><td>'.
\r
423 '<img src="'.$this->getAdminURL().'editor/plugins/nucleus/nucleus.gif" width="42" height="15" alt="nucleustag" />'.
\r
424 '<%$1%></td></tr></table>');
\r
426 function _patternAfterEdit(){
\r
427 return array('/<table[^>]*class="mitasnom"[^>]*>[\s\S]*?<%([^%]*?)%>[\s\S]*?<\/table>/');
\r
429 function _replaceAfterEdit() {
\r
430 return array('<%$1%>');
\r
433 // Show information when editing plugin option
\r
435 function event_PrePluginOptionsEdit($data){
\r
436 if ($this->errormessage) echo "<h4>".$this->errormessage."</h4>";
\r
438 function returnWithMessage($text) { $this->errormessage=$text;}
\r
440 // Customize toolbar menu
\r
441 function event_PostPluginOptionsUpdate($data) {
\r
442 $plugid=$data['plugid'];
\r
443 if ($plugid!=$this->GetID()) return;
\r
444 $this->install();// Refresh member option settings.
\r
445 if (!($name=$this->getOption('addremovetoolbar'))) return;
\r
446 $name=ereg_replace("[^0-9a-zA-Z]","",$name);
\r
447 $this->setOption('addremovetoolbar','');
\r
448 if (!($toolbar=$this->getOption('toolbar_custom')))
\r
449 return $this->returnWithMessage($this->translated('Toolbar definition is empty'));
\r
450 if (strstr(' default full basic custom ',strtolower($name)))
\r
451 return $this->returnWithMessage($this->translated('Default, Full, Basic and Custom toolbars cannot be removed.'));
\r
452 $ret=$this->getOption('toolbar_'.strtolower($name));//$ret=$this->getOption('toolbar_'.$this);
\r
453 if (!($oid=$this->this_getOid('toolbar'))) return;
\r
454 if (!($extra=$this->this_getExtra($oid))) return;
\r
455 if (strstr(strtolower($extra),strtolower($name))) {
\r
457 $extra=eregi_replace("\|$name\|$name","",$extra);
\r
458 sql_query('UPDATE ' . sql_table('plugin_option_desc') .
\r
459 ' SET oextra = "'.addslashes($extra). '" WHERE oid=' . (int)$oid);
\r
460 $this->deleteOption('toolbar_'.strtolower($name));
\r
461 $this->returnWithMessage($name.$this->translated(' toolbar is deleted.'));
\r
464 $extra=str_replace("|Custom|Custom","|$name|$name|Custom|Custom",$extra);
\r
465 sql_query('UPDATE ' . sql_table('plugin_option_desc') .
\r
466 ' SET oextra = "'.addslashes($extra). '" WHERE oid=' . (int)$oid);
\r
467 $this->createOption('toolbar_'.strtolower($name), $name.$this->translated(' Toolbar'), 'textarea', $toolbar);
\r
468 $this->returnWithMessage($name.$this->translated(' toolbar is added.'));
\r
472 // Member specific stuff
\r
473 function this_getOption($name) {
\r
475 if ($this->getOption('usemembersettings')!='yes') return $this->getOption($name);
\r
476 if (!$this->_useMemberSpecificOption($name)) return $this->getOption($name);
\r
477 return $this->getMemberOption($member->getID(), $name);
\r
479 function _useMemberSpecificOption($name) {
\r
480 foreach ($this->_allMemberSpecificOptions() as $value) if ($name==$value) return true;
\r
483 function _allMemberSpecificOptions() {
\r
484 return array('width','height','toolbar','returnafterbr','returnafterbrbr',
\r
485 'dialogwidth','dialogheight','additionalpsource');
\r
489 function this_getOid($name,$context='global'){
\r
490 $query = 'SELECT oid, oname FROM ' . sql_table('plugin_option_desc') .
\r
491 ' WHERE opid=' . intval($this->plugid).
\r
492 ' and ocontext="'.addslashes($context).'"';
\r
493 $res = sql_query($query);
\r
494 while ($o = mysql_fetch_object($res)) if ($o->oname==$name) return $o->oid;
\r
497 function this_getExtra($oid){
\r
498 $query = 'SELECT oextra FROM ' . sql_table('plugin_option_desc') . ' WHERE oid=' . intval($oid);
\r
499 $res = sql_query($query);
\r
500 if ($o = mysql_fetch_object($res)) return $o->oextra;
\r
504 // Uppgrading stuff
\r
505 function _checkVersion(){
\r
506 if (!$this->this_getOid('version')) $this->install();
\r
507 else if ($this->getVersion()!=$this->getOption('version')) $this->install();
\r
508 $this->setOption('version',$this->getVersion());
\r
511 // Overrided function
\r
512 function createOption($name, $desc, $type, $defValue = '', $typeExtras = '') {
\r
513 if (!$this->this_getOid($name)) parent::createOption($name, $desc, $type, $defValue, $typeExtras);
\r
514 if ($this->_useMemberSpecificOption($name)) {
\r
515 if ($this->getOption('usemembersettings')=='yes') {
\r
516 if (!$this->this_getOid($name,'member')) {
\r
517 if ($name=='toolbar') {
\r
518 $typeExtras=quickQuery(
\r
519 'SELECT oextra as result FROM '.sql_table('plugin_option_desc').
\r
520 ' WHERE opid='.(int)$this->getID().' AND oname="toolbar"');
\r
522 if (($Extras=$typeExtras)=='access=hidden') $Extras='';
\r
523 $Extras=str_replace('|Custom|Custom','',$Extras);
\r
524 $Extras=str_replace('|Full|Full','',$Extras);
\r
525 $this->createMemberOption($name, $desc, $type,$this->getOption($name), $Extras);
\r
528 if ($this->this_getOid($name,'member'))
\r
529 $this->deleteMemberOption($name);
\r
537 function translated($english){
\r
538 if (!is_array($this->langArray)) {
\r
539 $this->langArray=array();
\r
540 $language=$this->getDirectory().'language/'.ereg_replace( '[\\|/]', '', getLanguageName()).'.php';
\r
541 if (file_exists($language)) include($language);
\r
543 if (!($ret=$this->langArray[$english])) $ret=$english;
\r
547 // General function (found on PHP help page) follows
\r
548 function unhtmlentities($string) {
\r
549 $trans_tbl = get_html_translation_table (HTML_ENTITIES);
\r
550 $trans_tbl = array_flip ($trans_tbl);
\r
551 return strtr ($string, $trans_tbl);
\r