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

Recent

Welcome to TinyPortal. Please login or sign up.

May 01, 2024, 07:22:52 AM

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

An issue and a Question

Started by Zyos, February 03, 2009, 01:09:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zyos

Since you guys have been quite helpful with a couple of my recent problems, I'm wondering if you coding gurus can help me out ...

The issue is as thus:

I am wishing to enable both instant quick reply and enhanced quick reply on my forum, now I had instant quick reply working perfectly, then I tried to add enhanced quick reply, it added the right bbcode buttons etc but now it no longer instantly updates without refreshing.

Here is the code with instant quick reply working.


<?php
        
// Show the quick reply box.
   
if ($context['can_reply'] && !empty($options['display_quick_reply']))
   {
      echo 
'
<a name="quickreply"></a>
<table border="0" cellspacing="1" cellpadding="3" class="bordercolor" width="100%" style="clear: both;">
      <tr>
            <td colspan="2" class="catbg" align="center"><a href="javascript:swapQuickReply();"><img src="'
$settings['images_url'], '/'$options['display_quick_reply'] == 'collapse' 'expand''.gif" alt="+" id="quickReplyExpand" /></a> <a href="javascript:swapQuickReply();">'$txt['quick_reply_1'], '</a></td>
      </tr>
   <tr id="quickReplyOptions"'
$options['display_quick_reply'] == '' ' style="display: none"''>
      
      <td class="windowbg" width="100%" align="right">
         <form action="'
$scripturl'?action=post2" method="post" accept-charset="'$context['character_set'], '" name="postmodify" id="postmodify" onsubmit="submitonce(this);" style="margin: 0;">
            <input type="hidden" name="topic" value="' 
$context['current_topic'] . '" />
            <input type="hidden" name="subject" value="' 
$context['response_prefix'] . $context['subject'] . '" />
            <input type="hidden" name="icon" value="xx" />
            <input type="hidden" name="notify" value="'
$context['is_marked_notify'] || !empty($options['auto_notify']) ? '1' '0''" />
            <input type="hidden" name="goback" value="1" />
            <input type="hidden" name="num_replies" value="'
$context['num_replies'], '" />
            <textarea cols="75" rows="7" style="width: 600px; height: 200px;" name="message" tabindex="1"></textarea><br />
            '
;
            
// We will only do ajax quick reply if
            // 1) the current page is the last page of the topic or
            // 2) 'all' isset in REQUEST
            // otherwise we'll post the old fashioned way.
            
if($context['page_info']['current_page'] == $context['page_info']['num_pages'] || isset($_REQUEST['all']))
               echo 
'<input type="submit" name="post" value="' $txt[105] . '" onclick="return ajax_reply(this);" accesskey="s" tabindex="2" />
            '
;
            else
               echo 
'<input type="submit" name="post" value="' $txt[105] . '" onclick="return submitThisOnce(this);" accesskey="s" tabindex="2" />
            '
;
            echo 
'<input type="submit" name="preview" value="' $txt[507] . '" onclick="return submitThisOnce(this);" accesskey="p" tabindex="4" />';
      if (
$context['show_spellchecking'])
         echo 
'
            <input type="button" value="'
$txt['spell_check'], '" onclick="spellCheck(\'postmodify\', \'message\');" tabindex="5"/>';
      echo 
'
            <input type="hidden" name="sc" value="' 
$context['session_id'] . '" />
            <input type="hidden" name="seqnum" value="'
$context['form_sequence_number'], '" />
         </form>
      </td>
   </tr>
</table>'
;
   }
   if (
$context['show_spellchecking'])
      echo 
'
<form action="'
$scripturl'?action=spellcheck" method="post" accept-charset="'$context['character_set'], '" name="spell_form" id="spell_form" target="spellWindow"><input type="hidden" name="spellstring" value="" /></form>';
}

function 
template_ajax_reply() {
   global 
$context;
   
   
// Load up the index template, since we need it for some theme settings and call the init function
   
loadTemplate('index');
   
template_init();
   
   
// First we'll call the template function above to get the post
   
template_main();
   
   
// Then we'll take the contents of the buffer and throw it into a variable
   
$buffer ob_get_contents();
   
   
// And now we'll clear the buffer out so we can put back in what we want
   
ob_clean();
   
   
// Now lets play with the buffer, first clearing out the stuff before the post we don't need
   
$start_post strpos($buffer'<!-- Start Single Post -->') + 27// Plus 27 because we don't want the HTML comment in the final buffer.
   
$end_post strpos($buffer'<!-- End Single Post -->');
   
$buffer substr($buffer$start_post$end_post $start_post);
   
   
// Now change the windowbg value so the post displays with the right color (if its waiting approval then it won't change)
   
$windowbg = (($_REQUEST['num_replies']+1) % == 0) ? '"windowbg"' '"windowbg2"';
   
$buffer str_replace(array('"windowbg"''"windowbg2"'), $windowbg$buffer);
   
   
// Now we have just the post that we'll insert into the topic, lets add the XML stuff to it for AJAX.
   
$buffer '<?xml version="1.0" encoding="'$context['character_set']. "?>

<smf>
   <post><![CDATA[' .
   $buffer .
   ']]></post>
</smf>';
   
   // Now echo out the buffer
   echo $buffer;
}
?>


Here it is from enhanced quick reply


<?php
   
// Show the quick reply box.
   
if ($context['can_reply'] && !empty($options['display_quick_reply']))
   {
      echo 
'
<a name="quickreply"></a>
<div style="width: 100%;" align="center"><div class="tborder" style="width: 50%;" align="left">
   <div class="catbg" style="padding: 4px;"><a href="javascript:swapQuickReply();"><img src="'
$settings['images_url'], '/'$options['display_quick_reply'] == 'collapse' 'expand''.gif" alt="+" id="quickReplyExpand" /></a> <a href="javascript:swapQuickReply();">'$txt['quick_reply_1'], '</a></div>
   <div class="windowbg" id="quickReplyOptions" style="padding: 1ex;'
$options['display_quick_reply'] == '' ' display: none''">
      '
$context['is_locked'] ? '<b>' $txt['quick_reply_warning'] . '</b><br /><br />' '''
      <form action="'
$scripturl'?action=post2" method="post" accept-charset="'$context['character_set'], '" name="postmodify" id="postmodify" onsubmit="submitonce(this);" style="margin: 0;">
         <input type="hidden" name="topic" value="' 
$context['current_topic'] . '" />
         <input type="hidden" name="subject" value="' 
$context['response_prefix'] . $context['subject'] . '" />
         <input type="hidden" name="icon" value="xx" />
         <input type="hidden" name="notify" value="'
$context['is_marked_notify'] || !empty($options['auto_notify']) ? '1' '0''" />
         <input type="hidden" name="goback" value="'
, empty($options['return_to_post']) ? '0' '1''" />
         <input type="hidden" name="num_replies" value="'
$context['num_replies'], '" />';

      
// Here we show the actual post box with the smileys and BBCode..
      
theme_quickreply_box();

      echo 
'
         <br />
         <input type="submit" name="post" value="' 
$txt[105] . '" onclick="return submitThisOnce(this);" accesskey="s" tabindex="2" />
         <input type="submit" name="preview" value="' 
$txt[507] . '" onclick="return submitThisOnce(this);" accesskey="p" tabindex="4" />';

      if (
$context['show_spellchecking'])
         echo 
'
         <input type="button" value="'
$txt['spell_check'], '" onclick="spellCheck(\'postmodify\', \'message\');" tabindex="5"/>';

         echo 
'
         <input type="hidden" name="sc" value="' 
$context['session_id'] . '" />
         <input type="hidden" name="seqnum" value="'
$context['form_sequence_number'], '" />
      </form>'
;

      echo 
'
   </div>
</div></div>'
;

   }

   if (
$context['show_spellchecking'])
      echo 
'
<form action="'
$scripturl'?action=spellcheck" method="post" accept-charset="'$context['character_set'], '" name="spell_form" id="spell_form" target="spellWindow"><input type="hidden" name="spellstring" value="" /></form>';
}

function 
template_ajax_reply() {
   global 
$context;
   
   
// Load up the index template, since we need it for some theme settings and call the init function
   
loadTemplate('index');
   
template_init();
   
   
// First we'll call the template function above to get the post
   
template_main();
   
   
// Then we'll take the contents of the buffer and throw it into a variable
   
$buffer ob_get_contents();
   
   
// And now we'll clear the buffer out so we can put back in what we want
   
ob_clean();
   
   
// Now lets play with the buffer, first clearing out the stuff before the post we don't need
   
$start_post strpos($buffer'<!-- Start Single Post -->') + 27// Plus 27 because we don't want the HTML comment in the final buffer.
   
$end_post strpos($buffer'<!-- End Single Post -->');
   
$buffer substr($buffer$start_post$end_post $start_post);
   
   
// Now change the windowbg value so the post displays with the right color (if its waiting approval then it won't change)
   
$windowbg = (($_REQUEST['num_replies']+1) % == 0) ? '"windowbg"' '"windowbg2"';
   
$buffer str_replace(array('"windowbg"''"windowbg2"'), $windowbg$buffer);
   
   
// Now we have just the post that we'll insert into the topic, lets add the XML stuff to it for AJAX.
   
$buffer '<?xml version="1.0" encoding="'$context['character_set']. "?>

<smf>
   <post><![CDATA[' .
   $buffer .
   ']]></post>
</smf>';
   
   // Now echo out the buffer
   echo $buffer;
}


// This function displays all the stuff you'd expect to see with a message box, the box, BBC buttons and of course smileys.
// NOTICE: With the exception of some edits, this code was copied from Subs-Post.php, which is the work of the SMF dev team. I only moved things around...so thank them, not me!
function template_quickreply_box()
{
   global $context, $settings, $options, $txt, $modSettings;

   // Assuming BBC code is enabled then print the buttons and some javascript to handle it.
   if ($context['show_bbc'])
   {
      echo '
         <script language="JavaScript" type="text/javascript"><!-- // -->
            function bbc_highlight(something, mode)
            {
               something.style.backgroundImage = "url(" + smf_images_url + (mode ? "/bbc/bbc_hoverbg.gif)" : "/bbc/bbc_bg.gif)");
            }
         // ]]></script>';

      // The below array makes it dead easy to add images to this page. Add it to the array and everything else is done for you!
      $context['bbc_tags'] = array();
      $context['bbc_tags'][] = array(
         'bold' => array('code' => 'b', 'before' => '[b]', 'after' => '[/b]', 'description' => $txt[253]),
         'italicize' => array('code' => 'i', 'before' => '[i]', 'after' => '[/i]', 'description' => $txt[254]),
         'underline' => array('code' => 'u', 'before' => '[u]', 'after' => '[/u]', 'description' => $txt[255]),
         'strike' => array('code' => 's', 'before' => '[s]', 'after' => '[/s]', 'description' => $txt[441]),
         array(),
         'glow' => array('code' => 'glow', 'before' => '[glow=red,2,300]', 'after' => '[/glow]', 'description' => $txt[442]),
         'shadow' => array('code' => 'shadow', 'before' => '[shadow=red,left]', 'after' => '[/shadow]', 'description' => $txt[443]),
         'move' => array('code' => 'move', 'before' => '[move]', 'after' => '[/move]', 'description' => $txt[439]),
         array(),
         'pre' => array('code' => 'pre', 'before' => '[pre]', 'after' => '[/pre]', 'description' => $txt[444]),
         'left' => array('code' => 'left', 'before' => '[left]', 'after' => '[/left]', 'description' => $txt[445]),
         'center' => array('code' => 'center', 'before' => '[center]', 'after' => '[/center]', 'description' => $txt[256]),
         'right' => array('code' => 'right', 'before' => '[right]', 'after' => '[/right]', 'description' => $txt[446]),
         array(),
         'hr' => array('code' => 'hr', 'before' => '[hr]', 'description' => $txt[531]),
         array(),
         'size' => array('code' => 'size', 'before' => '[size=10pt]', 'after' => '[/size]', 'description' => $txt[532]),
         'face' => array('code' => 'font', 'before' => '[font=Verdana]', 'after' => '[/font]', 'description' => $txt[533]),
      );
      $context['bbc_tags'][] = array(
         'flash' => array('code' => 'flash', 'before' => '[flash=200,200]', 'after' => '[/flash]', 'description' => $txt[433]),
         'img' => array('code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $txt[435]),
         'url' => array('code' => 'url', 'before' => '[url]', 'after' => '[/url]', 'description' => $txt[257]),
         'email' => array('code' => 'email', 'before' => '[email]', 'after' => '[/email]', 'description' => $txt[258]),
         'ftp' => array('code' => 'ftp', 'before' => '[ftp]', 'after' => '[/ftp]', 'description' => $txt[434]),
         array(),
         'table' => array('code' => 'table', 'before' => '[table]', 'after' => '[/table]', 'description' => $txt[436]),
         'tr' => array('code' => 'td', 'before' => '[tr]', 'after' => '[/tr]', 'description' => $txt[449]),
         'td' => array('code' => 'td', 'before' => '[td]', 'after' => '[/td]', 'description' => $txt[437]),
         array(),
         'sup' => array('code' => 'sup', 'before' => '[sup]', 'after' => '[/sup]', 'description' => $txt[447]),
         'sub' => array('code' => 'sub', 'before' => '[sub]', 'after' => '[/sub]', 'description' => $txt[448]),
         'tele' => array('code' => 'tt', 'before' => '[tt]', 'after' => '[/tt]', 'description' => $txt[440]),
         array(),
         'code' => array('code' => 'code', 'before' => '[code]', 'after' => '[/ode]', 'description' => $txt[259]),
         'quote' => array('code' => 'quote', 'before' => '[quote]', 'after' => '[/quote]', 'description' => $txt[260]),
         array(),
         'list' => array('code' => 'list', 'before' => '[list]\n[list][li]', 'after' => '[/li][/list]\n[list][li][/li][/list]\n[/list]', 'description' => $txt[261]),
      );

      $found_button = false;
      // Here loop through the array, printing the images/rows/separators!
      foreach ($context['bbc_tags'][0] as $image => $tag)
      {
         // Is there a "before" part for this bbc button? If not, it can't be a button!!
         if (isset($tag['before']))
         {
            // Is this tag disabled?
            if (!empty($context['disabled_tags'][$tag['code']]))
               continue;

            $found_button = true;

            // If there's no after, we're just replacing the entire selection in the post box.
            if (!isset($tag['after']))
               echo '<a href="javascript:void(0);" onclick="replaceText(\'', $tag['before'], '\', document.forms.postmodify.message); return false;">';
            // On the other hand, if there is one we are surrounding the selection ;).
            else
               echo '<a href="javascript:void(0);" onclick="surroundText(\'', $tag['before'], '\', \'', $tag['after'], '\', document.forms.postmodify.message); return false;">';

            // Okay... we have the link. Now for the image and the closing </a>!
            echo '<img onmouseover="bbc_highlight(this, true);" onmouseout="if (window.bbc_highlight) bbc_highlight(this, false);" src="', $settings['images_url'], '/bbc/', $image, '.gif" align="bottom" width="23" height="22" alt="', $tag['description'], '" title="', $tag['description'], '" style="background-image: url(', $settings['images_url'], '/bbc/bbc_bg.gif); margin: 1px 2px 1px 1px;" /></a>';
         }
         // I guess it's a divider...
         elseif ($found_button)
         {
            echo '<img src="', $settings['images_url'], '/bbc/divider.gif" alt="|" style="margin: 0 3px 0 3px;" />';
            $found_button = false;
         }
      }

      // Print a drop down list for all the colors we allow!
      if (!isset($context['disabled_tags']['color']))
         echo ' <select onchange="surroundText(\'[color=\' + this.options[this.selectedIndex].value.toLowerCase() + \']\', \'[/color]\', document.forms.postmodify.message); this.selectedIndex = 0; document.forms.postmodify.message.focus(document.forms.postmodify.message.caretPos);" style="margin-bottom: 1ex;">
            <option value="" selected="selected">', $txt['change_color'], '</option>
            <option value="Black">', $txt[262], '</option>
            <option value="Red">', $txt[263], '</option>
            <option value="Yellow">', $txt[264], '</option>
            <option value="Pink">', $txt[265], '</option>
            <option value="Green">', $txt[266], '</option>
            <option value="Orange">', $txt[267], '</option>
            <option value="Purple">', $txt[268], '</option>
            <option value="Blue">', $txt[269], '</option>
            <option value="Beige">', $txt[270], '</option>
            <option value="Brown">', $txt[271], '</option>
            <option value="Teal">', $txt[272], '</option>
            <option value="Navy">', $txt[273], '</option>
            <option value="Maroon">', $txt[274], '</option>
            <option value="LimeGreen">', $txt[275], '</option>
         </select>';
      echo '<br />';

      $found_button = false;
      // Print the buttom row of buttons!
      foreach ($context['bbc_tags'][1] as $image => $tag)
      {
         if (isset($tag['before']))
         {
            // Is this tag disabled?
            if (!empty($context['disabled_tags'][$tag['code']]))
               continue;

            $found_button = true;

            // If there's no after, we're just replacing the entire selection in the post box.
            if (!isset($tag['after']))
               echo '<a href="javascript:void(0);" onclick="replaceText(\'', $tag['before'], '\', document.forms.postmodify.message); return false;">';
            // On the other hand, if there is one we are surrounding the selection ;).
            else
               echo '<a href="javascript:void(0);" onclick="surroundText(\'', $tag['before'], '\', \'', $tag['after'], '\', document.forms.postmodify.message); return false;">';

            // Okay... we have the link. Now for the image and the closing </a>!
            echo '<img onmouseover="bbc_highlight(this, true);" onmouseout="if (window.bbc_highlight) bbc_highlight(this, false);" src="', $settings['images_url'], '/bbc/', $image, '.gif" align="bottom" width="23" height="22" alt="', $tag['description'], '" title="', $tag['description'], '" style="background-image: url(', $settings['images_url'], '/bbc/bbc_bg.gif); margin: 1px 2px 1px 1px;" /></a>';
         }
         // I guess it's a divider...
         elseif ($found_button)
         {
            echo '<img src="', $settings['images_url'], '/bbc/divider.gif" alt="|" style="margin: 0 3px 0 3px;" />';
            $found_button = false;
         }
      }
   }

   // Now start printing all of the smileys.
   if (!empty($context['smileys']['postform']))
   {
      echo '
         <br />';

      // Show each row of smileys ;).
      foreach ($context['smileys']['postform'] as $smiley_row)
      {
         foreach ($smiley_row['smileys'] as $smiley)
            echo '
         <a href="javascript:void(0);" onclick="replaceText(\' ', $smiley['code'], '\', document.forms.postmodify.message); return false;"><img src="', $settings['smileys_url'], '/', $smiley['filename'], '" align="bottom" alt="', $smiley['description'], '" title="', $smiley['description'], '" /></a>';

         // If this isn't the last row, show a break.
         if (empty($smiley_row['last']))
            echo '<br />';
      }

      // If the smileys popup is to be shown... show it!
      if (!empty($context['smileys']['popup']))
         echo '
         <a href="javascript:moreSmileys();">[', $txt['more_smileys'], ']</a>';
   }

   // If there are additional smileys then ensure we provide the javascript for them.
   if (!empty($context['smileys']['popup']))
   {
      echo '
         <script language="JavaScript" type="text/javascript"><!-- // -->
            var smileys = [';

      foreach ($context['smileys']['popup'] as $smiley_row)
      {
         echo '
               [';
         foreach ($smiley_row['smileys'] as $smiley)
         {
            echo '
                  ["', $smiley['code'], '","', $smiley['filename'], '","', $smiley['js_description'], '"]';
            if (empty($smiley['last']))
               echo ',';
         }

         echo ']';
         if (empty($smiley_row['last']))
            echo ',';
      }

      echo '];
            var smileyPopupWindow;

            function moreSmileys()
            {
               var row, i;

               if (smileyPopupWindow)
                  smileyPopupWindow.close();

               smileyPopupWindow = window.open("", "add_smileys", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=480,height=220,resizable=yes");
               smileyPopupWindow.document.write(\'\n<html>\');
               smileyPopupWindow.document.write(\'\n\t<head>\n\t\t<title>', $txt['more_smileys_title'], '</title>\n\t\t<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css" />\n\t</head>\');
               smileyPopupWindow.document.write(\'\n\t<body style="margin: 1ex;">\n\t\t<table width="100%" cellpadding="5" cellspacing="0" border="0" class="tborder">\n\t\t\t<tr class="titlebg"><td align="left">', $txt['more_smileys_pick'], '</td></tr>\n\t\t\t<tr class="windowbg"><td align="left">\');

               for (row = 0; row < smileys.length; row++)
               {
                  for (i = 0; i < smileys[row].length; i++)
                  {
                     smileys[row][i][2] = smileys[row][i][2].replace(/"/g, \'&quot;\');
                     smileyPopupWindow.document.write(\'<a href="javascript:void(0);" onclick="window.opener.replaceText(&quot; \' + smileys[row][i][0] + \'&quot;, window.opener.document.forms.postmodify.message); window.focus(); return false;"><img src="', $settings['smileys_url'], '/\' + smileys[row][i][1] + \'" alt="\' + smileys[row][i][2] + \'" title="\' + smileys[row][i][2] + \'" style="padding: 4px;" border="0" /></a> \');
                  }
                  smileyPopupWindow.document.write("<br />");
               }

               smileyPopupWindow.document.write(\'</td></tr>\n\t\t\t<tr><td align="center" class="windowbg"><a href="javascript:window.close();\\">', $txt['more_smileys_close_window'], '</a></td></tr>\n\t\t</table>\n\t</body>\n</html>\');
               smileyPopupWindow.document.close();
            }
         // ]]></script>';
   }

   // Finally the most important bit - the actual text box to write in!
   echo '
         <textarea class="editor" cols="75" rows="7" style="width: 95%; height: 100px;" name="message" tabindex="1" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);"></textarea>';
}
?>


If you can figure out how to get instant reply working again I'll have your babies because I'm stumped, maybe I can't see the forest for the trees.

The question is that I've employed a little popup system for small items like forms and such, I use one for logging in, now the only issue is that after logging in the page loads into the iframe I'm using within the div that appears (basically a lightbox)

I've tried an onSubmit with a javascript function to reload, nothing happens, so I would like to know how to modify sources/loginout.php in order to (after log in is completed) to output a body tag with an onload so I can push the code to reload the parent window.

Thanks[/code]

Zetan

Isn't this really a question for SMF?

Zyos

I realise that, I have posted there and as of yet I have no replies, just thought I'd branch out a bit to see if I could find anyone here willing to help, if its against the rules to post things of this nature please remove the topic

Thanks

Zetan

We really only support TP and the themes here. You need to be patient at SMF, it's a busy site.

If somebody wants to help, thats fine.

Zyos

Thanks for the understanding ...

I'm fairly close to finishing the website, and its required before I can start developing quite an extensive mod for a game (microsoft freelancer) the website is the central project hub and I have only this week off to finish it properly.

I know I seem impatient, but I'm somewhat of a perfectionist and it annoys the crap out of me to have things not working lol.

As for the issue with the parent and child window, I managed to sort that out, I'd forgotten you could target a form action to _top (parent window) the results appear there.  That one is officially done.

However I've still been unable to solve the quick reply issue.

Thanks!

JPDeni

I don't understand what the following means
Quoteit no longer instantly updates without refreshing.

I just can't picture what you're talking about.

Zyos

#6
Sorry, I have instant quick reply enabled via ajax, so normally when posting, it doesnt refresh the page it uses javascript to slot the post in, unless there has been a post while you've been typing, in which case it will refresh the page

Like your inline editing how it places a input textarea on the page, it comes up with the same loading bar and slots the post in.

JPDeni

I see. I don't "do" ajax, so it's not something I would think of.

Zyos

No problem, I'm fairly sure the problem is in the html code for the form though, but I just can't pin it down