1
spiff
Press It (WordPress-style hack) for mylinks
  • 2005/1/16 17:49

  • spiff

  • Just popping in

  • Posts: 47

  • Since: 2003/4/16


I spend a fair amount of time building the links database, and find myself regularly cutting and pasting between browser tabs (thank you Firefox) from a cool page to the XOOPS "new link" admin form.

I thought it would be useful if I'd be able to select some text off a page, then have a javascript link paste the page url, title and selected text into the link form.

I looked at the WordPress example, and modified it to do something like this (line breaks inserted for readability, in reality the entire code below needs to fit in one line starting with js without the spaces, and be saved as a bookmark in your browser):
j a v a s c r i p t:if(navigator.userAgent.indexOf('Safari' >= 0){
  
Q=getSelection();
}else{
  
Q=document.selection
    
?document.selection.createRange().text
    
:window.getSelection();
}
void(window.open(
  
'http://my.xoops.site/modules/mylinks/index.php'
    
+'?op=linksConfigMenu'
    
+'&popuptext='+escape(Q)
    +
'&popupurl='+escape(location.href)
    +
'&popuptitle='+escape(document.title),
  
'xoops bookmarklet',
  
'scrollbars=yes,
  width=600,
  height=460,
  left=100,
  top=150,
  status=yes'
));

Passing data into the forms in file /modules/mylinks/admin/index.php (function linksConfigMenu) is just a matter of replacing (around line 185):
echo "<input type=text name=title size=50 maxlength=100>";
echo 
"</td></tr><tr><td align="right" nowrap>"._MD_SITEURL."</td><td>";
echo 
"<input type=text name=url size=50 maxlength=250 value="http://">";
echo "</td></tr>";
echo 
"<tr><td align="right" nowrap>"._MD_CATEGORYC."</td><td>";
$mytree->makeMySelBox("title""title");
echo 
"<tr><td align="right" valign="top" nowrap>"._MD_DESCRIPTIONC."</td><td>n";
xoopsCodeTarea("description",60,8);
with:
echo "<input type=text name=title size=50 maxlength=100 value=".$_GET['popuptitle'].">"/* CHANGE */
echo "</td></tr><tr><td align="right" nowrap>"._MD_SITEURL."</td><td>";
echo 
"<input type=text name=url size=50 maxlength=250 value="".$_GET['popupurl']."">"/* CHANGE */
echo "</td></tr>";
echo 
"<tr><td align="right" nowrap>"._MD_CATEGORYC."</td><td>";
$mytree->makeMySelBox("title""title");
echo 
"<tr><td align="right" valign="top" nowrap>"._MD_DESCRIPTIONC."</td><td>n";
xoopsCodeTarea("description",60,8,null,stripslashes($_GET['popuptext'])); /* CHANGE */

Passing the selected text involves modifying file /include/xoopscode.php, adding a $textarea_content parameter:
function xoopsCodeTarea($textarea_id$cols=60$rows=15$suffix=null$textarea_content='')
then replacing (around line 72):
$areacontent = isset( $GLOBALS[$textarea_id] ) ? $GLOBALS[$textarea_id] : '';
with:
$areacontent = isset( $GLOBALS[$textarea_id] ) ? $GLOBALS[$textarea_id] : $textarea_content;

Presumably, no one would even be able to access the admin add/modify links page without having signed in with proper admin credentials, but I would appreciate if you'd put in your 2 cents and let me know whether the above hack introduces vulnerability.

Thanks,
Eric

P.S. Code wasn't tested under Safari.

Login

Who's Online

153 user(s) are online (96 user(s) are browsing Support Forums)


Members: 0


Guests: 153


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits