TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 18, 2024, 06:52:52 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,164
  • Total Topics: 21,219
  • Online today: 203
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 123
  • Total: 123

Block Tweak

Started by darkorical, February 19, 2010, 10:38:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

darkorical

alright I had an idea for a basic ajax  inplace block edit I built most of it and got side tracked and never finished it so I thought I would offer what I had here and see if it merited inclusion or my finishing it as an addon.

basically it adds another button beside the edit button that pulls the block code to the page for immediate editing (quite usefull for fixing typos and other small tweaks)





if someone wants to finish this for me or include it Id be more than willing to provide all the bits of code I used I honestly think the only thing I didn't do was actually update the block code when the submit button was clicked.


ZarPrime

darkorical,

Interesting.  Does it work except for updating the code when you click the save button?

I don't think this is something that can make it into beta 5 at this point but it sounds like a good feature.  I have moved it up one level to the Feedback Board.  If Bloc likes it, he will move it back to Proposed Features where you originally posted it.  I will mention to him to take a look at this topic.

ZarPrime


Skhilled

I'm liking this also. It would be an excellent feature to have. :)

darkorical

alright I was snowed in yesterday I will try to get a chance to look into exactly how far I got with this today

darkorical

#4
alright so I got looking and discovered that I had cheated and hard coded one block to work that way so I went ahead and worked on it more. I have attached all three files needed to make it work as I have it thus far but I am running into an issue where no matter what I do it brings the code into the last block on the page not the one Im working with

TPTweek.gif is the button itself and should go into
Themes/default/images/tinyportal

blocktweek.php is the quick and dirty script I built to control it (Idealy this would become another function inside another file but to keep things clean I made it an external file. It goes in the root of SMF install. it currently has a site specific update block section commented out to avoid unwanted breakage on my site so updating wont work for anyone else yet

TPBlockLayout.template.php is my version of the file that includes the edits I made

now for what is in those files
blocktweek.php
******************************************
<?php
$q
=$_GET["q"];
$action=$_POST['action'];
$blocknum=$_POST['blocknum'];
$bbod=$_POST['bbod'];
require 
'../config.php';
mysql_select_db("smf"$con1);
 if (
$action == 1){
/*$updatest = "UPDATE smf_tp_blocks
body = '$bbod',
WHERE id = '$blocknum'";
$results = mysql_query($updatest);*/
echo'Block Updated!';
include (
"index.php");
}

 else{
$sql =  "SELECT * FROM smf_tp_blocks WHERE id = '".$q."'";
$result mysql_query($sql);
while(
$row mysql_fetch_array($result))
  {
echo 
'<form action="blocktweek.php" method="post">
<input type="hidden" id="action" name="action" value="1" />
<input type="hidden" id="blocknum" name="blocknum" id="blocknum" value="'
.$q.'" /> 
<textarea style="width: 100%; height: 130px;" id="bbod" name="bbod">'
.$row['body'].'</textarea>
<br /><input type="submit" value="Save">'
;
  }}
?>

*********************************

and the edits to TPBlockLayout.template.php
*************************************
FIND

// can you edit the block?
if($block['can_edit'] && !$context['TPortal']['blocks_edithide'])
echo '<a href="',$scripturl,'?action=tpmod;sa=editblock'.$block['id'].';sesc='.$context['session_id'].'"><img style="margin-right: 4px;" border="0" align="right" src="' .$settings['tp_images_url']. '/TPedit2.gif" alt="" title="'.$txt['edit_description'].'" /></a>';
elseif($block['can_manage'] && !$context['TPortal']['blocks_edithide'])
echo '<a href="',$scripturl,'?action=tpadmin;blockedit='.$block['id'].';fromblock='.$context['TPortal']['serialize_url'].';sesc='.$context['session_id'].'"><img border="0" style="margin-right: 4px;" align="right" src="' .$settings['tp_images_url']. '/TPedit2.gif" alt="" title="'.$txt['edit_description'].'" /></a>';


----------------------------------------------------------------------

Add After
// can you tweek the block?
if($block['can_manage'])
echo '<img border="0" style="margin-right: 4px;" align="right" src="' .$settings['tp_images_url']. '/TPTweek.gif" alt="" title="tweek" onclick="blocktweek'.$block['id'].'()" />
<script language="Javascript" type="text/javascript">
var xmlhttp;

function blocktweek'.$block['id'].'()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="blocktweek.php";
url=url+"?q='.$block['id'].'";
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById(\'block'.$block['id'].'\').innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}</script>
';


unless I have forgotten something that should get it functional except updating blocks

IchBin

Looks like a nice feature. There are some security issues I wonder about though. Since you're not using any of the SMF database functions you aren't getting any cleaning of the input. I'm not a security guru or anything, just want to bring it up.

What's in config.php? I think I may have missed something with you including that file.

darkorical

oh I agree about security issues I circumvented all that for ease of coding on my end and this was done mostly as a proof of concept and config.php should have been taken out its my own setting.php file for easy access to my database again a short cut I took to keep smf/tp clean while adding on to it.