1<?php 2/** 3 * dokubookmark plugin helper functions 4 * Dokuwiki website tagger - act like a weblog 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Robin Gareus <robin@gareus.org> 8 * @based_on http://wiki.splitbrain.org/wiki:tips:weblog_bookmarklet by riny [at] bk [dot] ru 9 */ 10 11 /** 12 * - TODO this should use the dokuwiki template header. 13 */ 14 function printHeader() { 15 global $conf; 16?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 17 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 18<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > 19<head> 20<title>Dokuwiki Website Tagger</title> 21<?php tpl_metaheaders()?> 22<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 23<link rel="shortcut icon" href="<?php echo DOKU_TPL?>images/favicon.ico" /> 24 25<script type="text/javascript"> 26/* <![CDATA[ */ 27function initTagEntry() { 28 document.getElementById('blogtng__tags').value = 'Bookmark, '; 29} 30/* ]]> */ 31</script> 32</head> 33<body> 34<script type="text/javascript"> 35/* <![CDATA[ */ 36window.onload=initTagEntry; 37/* ]]> */ 38</script> 39<div class="dokuwiki" style="background: #fff; border:0px; color: #000"> 40<?php 41 } 42 43 44 /** 45 * 46 */ 47 function printFooter() { ?> 48</div> <!-- class="dokuwiki" --> 49</body> 50</html> 51<?php 52 } 53 54 function escapeJSstring ($o) { 55 return ( # TODO: use JSON ?! 56 str_replace("\n", '\\n', 57 str_replace("\r", '', 58 str_replace('\'', '\\\'', 59 str_replace('\\', '\\\\', 60 $o))))); 61 } 62 63 function parseWikiIdTemplate($idx, $data) { 64 if (empty($data['name'])) { 65 $n=''; 66 # check for single word selection -> use this 67 if (!strstr($data['selection'], ' ')) 68 $n=$data['selection']; 69 # check if title is a not empty 70 if (empty($n)) 71 $n=$data['title']; 72 # if still empty.. mmh - use URL or use 'noname' 73 if (empty($n)) $n='noname'; 74 75 #-> replace ': ' and ASCIIfy 76 $n=strtr($n, ': ','__'); 77 # [^\x20-\x7E] or [^A-Za-z_0-9] 78 $n=preg_replace('@[^A-Za-z_0-9]@', '', $n); 79 $n=preg_replace('@__*@', '_', $n); 80 # trim to 64 chars. 81 $data['name']=substr($n,0,64); 82 } 83 # TODO: replace Placeholders alike ../../../inc/common.php pageTemplate() ?! 84 return str_replace("@D@",$data['timestamp'], 85 str_replace("@S@",$data['selection'], 86 str_replace("@U@",$data['url'], 87 str_replace("@N@",$data['name'], 88 str_replace("@F@",$data['foo'], 89 str_replace("@T@",$data['title'], $idx)))))); 90 } 91 92 93 /** 94 * 95 */ 96 function printForm ($data, $options, $alltags = NULL) { 97 global $ID; 98 global $REV; 99 global $DATE; 100 global $PRE; 101 global $SUF; 102 global $INFO; 103 global $SUM; 104 global $lang; 105 global $conf; 106 global $TEXT; 107 global $RANGE; 108 109 $SUM = htmlentities($data['title'], ENT_COMPAT, 'UTF-8'); 110 111 echo '<h3>Dokuwiki - add bookmark / weblog entry</h3>'; 112 113 if (isset($_REQUEST['changecheck'])) { 114 $check = $_REQUEST['changecheck']; 115 } elseif(!$INFO['exists']){ 116 // $TEXT has been loaded from page template 117 $check = md5(''); 118 } else { 119 $check = md5($TEXT); 120 } 121 $mod = md5($TEXT) !== $check; 122 123 $wr = $INFO['writable'] && !$INFO['locked']; 124 $include = 'edit'; 125 if($wr){ 126 if ($REV) $include = 'editrev'; 127 }else{ 128 // check pseudo action 'source' 129 if(!actionOK('source')){ 130 msg('Command disabled: source',-1); 131 return; 132 } 133 $include = 'read'; 134 } 135 136 global $license; 137 138 $wikitext = parseWikiIdTemplate($data['wikitpl'], $data); 139 $id = parseWikiIdTemplate($data['wikiidtpl'], $data); 140 $TEXT = $wikitext; 141 $ID = $id; 142 143 $form = new Doku_Form(array('id' => 'dw__editform', 'action' => $data['baseurl'])); 144 $form->addHidden('rev', $REV); 145 $form->addHidden('date', $DATE); 146 $form->addHidden('prefix', $PRE . '.'); 147 $form->addHidden('suffix', $SUF); 148 $form->addHidden('changecheck', $check); 149 150 151 $dataNew = array('form' => $form, 152 'wr' => $wr, 153 'media_manager' => true, 154 'target' => (isset($_REQUEST['target']) && $wr && 155 $RANGE !== '') ? $_REQUEST['target'] : 'section', 156 'intro_locale' => $include); 157 158 $data = array_merge($data, $dataNew); 159 160 $form->addElement(form_makeOpenTag('p')); 161 $form->addElement(form_makeTextField('id', htmlentities(parseWikiIdTemplate($data['wikiidtpl'], $data), ENT_COMPAT, 'UTF-8'), 'Id:', 'i_id')); 162 163 if ($options['preset']) { 164 $form->addElement('<br/> Preset:'); 165 $i=0; 166 foreach ($options['presets'] as $n => $ps) { 167 $id_ = parseWikiIdTemplate($ps['id'], $data); 168 $wikitext_ = parseWikiIdTemplate($ps['tpl'], $data); 169 170 if ($i>0) 171 $form->addElement(','); 172 else 173 $form->addElement(' '); 174 175 $form->addElement(' '); 176 $additionalJs = ''; 177 if (!empty($wikitext_)) { 178 $additionalJs = 'document.getElementById(\'wiki__text\').value=\''.escapeJSstring($wikitext_).'\';'; 179 } 180 $form->addElement(form_makeTag('input', array( 181 'type' => 'button', 182 'value' => $n, 183 'class' => 'button', 184 'title' => $n, 185 'onclick' => 'document.getElementById(\'i_id\').value=\''.escapeJSstring($id_).'\';document.getElementById(\'id\').value=\''.escapeJSstring($id_).'\';'.$additionalJs 186 ))); 187 188 $i++; 189 } 190 } ### done Preset Buttons 191 $form->addElement(form_makeCloseTag('p')); 192 193 194 if ($data['target'] !== 'section') { 195 // Only emit event if page is writable, section edit data is valid and 196 // edit target is not section. 197 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 198 } else { 199 html_edit_form($data); 200 } 201 202 //if (isset($data['intro_locale'])) { 203 // echo p_locale_xhtml($data['intro_locale']); 204 //} 205 206 207 $form->addHidden('target', $data['target']); 208 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar'))); 209 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 210 $form->addElement(form_makeCloseTag('div')); 211 if ($wr) { 212 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 213 if ($options['enable_save']) { 214 $form->addHidden('sectoc', getSecurityToken()); 215 $form->addElement(form_makeTag('input', array( 216 'id' => 'edbtn__save', 217 'type' => 'submit', 218 'name' => 'do[dokubookmark]', 219 'value' => $lang['btn_save'], 220 'class' => 'button', 221 'title' => $lang['btn_save'] . ' [S]', 222 'accesskey' => 's', 223 'tabindex' => '4' 224 ))); 225 226 } 227 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 228 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex' => '6', 'onclick' => 'window.close()'))); 229 $form->addElement(form_makeCloseTag('div')); 230 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 231 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 232 $elem = html_minoredit(); 233 if ($elem) $form->addElement($elem); 234 $form->addElement(form_makeCloseTag('div')); 235 } 236 $form->addElement(form_makeCloseTag('div')); 237 if($wr && $conf['license']){ 238 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 239 $out = $lang['licenseok']; 240 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 241 if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"'; 242 $out .= '>'.$license[$conf['license']]['name'].'</a>'; 243 $form->addElement($out); 244 $form->addElement(form_makeCloseTag('div')); 245 } 246 247 if ($wr) { 248 // sets changed to true when previewed 249 echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL; 250 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 251 echo '//--><!]]></script>' . NL; 252 } ?> 253 <div style="width:99%;"> 254 255 <div class="toolbar"> 256 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 257 <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 258 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 259 260 </div> 261 <?php 262 263 html_form('edit', $form); 264 print '</div>'.NL; 265 266 } 267 268 269 /** 270 * - unused javascript redirect/POST - 271 * 272 * - could be made into a non-interactive bookmarklet - 273 */ 274 function printPost($targeturl, $path, $wikiid, $timestamp, $title, $wikitext) { 275?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 276 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 277<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > 278<head> 279<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 280<head> 281<script type="text/javascript"> 282/* <![CDATA[ */ 283function postit() { 284 f = document.createElement('form'); 285 f.method = 'post'; 286 f.action = '<?php echo $targeturl;?>'; 287 288 i0 = document.createElement('input'); 289 i0.type = 'hidden'; 290 i0.name = 'wikitext'; 291 i0.value = '<?php echo implode('\n', explode("\n",str_replace("'","\\'",$wikitext)));?>'; 292 293 i1 = document.createElement('input'); 294 i1.type = 'hidden'; 295 i1.name = 'do'; 296 i1.value = 'preview'; 297 298 i3 = document.createElement('input'); 299 i3.type = 'hidden'; 300 i3.name = 'summary'; 301 i3.value = '<?php echo str_replace("'","\\'",rawurlencode($title));?>'; 302 303 i4 = document.createElement('input'); 304 i4.type = 'hidden'; 305 i4.name = 'sectok'; 306 i4.value = '<?php echo getSecurityToken();?>'; 307 308 f.appendChild(i0); 309 f.appendChild(i1); 310 f.appendChild(i3); 311 f.appendChild(i4); 312 b = document.getElementsByTagName('body')[0]; 313 b.appendChild(f); 314 f.submit(); 315 } 316/* ]]> */ 317</script> 318<body onload="postit();"> 319</body> 320</html> 321<?php 322 } 323 324//Setup VIM: ex: et ts=2 : 325