Language specific images

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
snafumaster
Registered User
Posts: 77
Joined: Wed Jun 23, 2004 11:07 am
Location: S. of Boston
Name: Matthew Gendreau
Contact:

Language specific images

Post by snafumaster »

I am working on a MOD for a dhtml quick reply. Yes, I know it's been done, but that's not my issue. What I need is for the "quick reply" button to be laguage specific. I started by adding this below...

Code: Select all

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/subSiver.cfg

#
#-----[ FIND ]------------------------------------------
#
$images['reply_new'] = "$current_template_images/{LANG}/reply.gif";

#
#-----[ AFTER, ADD ]------------------------------------
#
$images['quick_reply'] = "$current_template_images/{LANG}/quick_reply.gif";
What I am having problems with is what do I add and specifically where would I add the variable in viewtopic.php. I figure it should start with

Code: Select all

#
#-----[ FIND ]------------------------------------------
#
	'REPLY_IMG' => $reply_img,

#
#-----[ AFTER, ADD ]------------------------------------
#
But I am not sure what I should add.

Placing it in the .tpl is the easy part, as all I have to do is replace the

Code: Select all

<img alt="quick reply" title="quick reply" src="templates/subSilver/images/quick_reply.gif">
with whatever the variable is to be.

So, I guess I have two questions.
  1. What should I add in viewtopic.php?
  2. Am I leaving anything out?

User avatar
D¡cky
Former Team Member
Posts: 11812
Joined: Tue Jan 25, 2005 8:38 pm
Location: New Hampshire, USA
Name: Richard Foote
Contact:

Post by D¡cky »

You need to define your $quick_reply_img and the url for the image in this section

//
// Post, reply and other URL generation for
// templating vars

after

$reply_topic_url =

and

$reply_img =
and
$reply_alt =
Have you hugged someone today?

snafumaster
Registered User
Posts: 77
Joined: Wed Jun 23, 2004 11:07 am
Location: S. of Boston
Name: Matthew Gendreau
Contact:

Post by snafumaster »

I thought I had already difined the location of the image in subSilver.cfg file. :?

Would it help if I posted the mod as it was before. I have the MOD working perfectly, but someone suggested making the image "language specific" and I thought it was a good idea...oh heck why not...here's the code.

Code: Select all

##############################################################
## MOD Title: DHTML Quick-Reply w/ Quote v1.0.1
## MOD Author: snafumaster < matty@snafumaster.com > (Matthew Gendreau) http://badmatty.com
## MOD Description: This MOD uses smartor's quickreply with quote MOD. Using this method, it makes it so there 
##                  is a button to make the text box appear and disapear.
## MOD Version: 1.0.1
##
## Installation Level: (Easy)
## Installation Time: 10 Minutes
## Files To Edit: viewtopic.php,
##      languages/lang_english/lang_main.php
##      templates/subSilver/overall_header.tpl,
##      templates/subSilver/viewtopic_body.tpl
##	
## Included Files: (templates/subSilver/images/quick_reply.gif)
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## For security purposes, please check: http://www.phpbb.com/mods/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://www.phpbb.com/mods/
##############################################################
## Author Notes:Thanks to Smartor and his site, http://smartor.is-root.com for this and the other great MODs there.
##		Thanks to Dynamic Drive for thier excellent code. http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm
##		Thanks to markus_petrux of http://phpbb.com for the idea (I don't think he meant it...lol)
##		Thanks to Minc for cleaning up the syntax and making it work well with EZmod
##
##############################################################
## MOD History:
##
##   2005-09-19 - Version 1.0.0 [beta]
##      - Absolute first try :-[]
##   2005-09-19 - Version 1.0.0 [beta]
##	- Minor Syntax correction :thumbsup: to Minc
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ COPY ]------------------------------------------
#
copy templates/subSilver/images/quick_reply.gif to templates/subSilver/images/quick_reply.gif

#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php

#
#-----[ FIND ]------------------------------------------
#
$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

#
#-----[ BEFORE, ADD ]------------------------------------
#
//
// Quick Reply Mod
//
if ( ((!$is_auth['auth_reply']) or ($forum_topic_data['forum_status'] == FORUM_LOCKED) or ($forum_topic_data['topic_status'] == TOPIC_LOCKED)) and ($userdata['user_level'] != ADMIN) )
{
   $quick_reply_form = "";
}
else
{
   if ($can_watch_topic and $is_watching_topic)
   {
      $notify_user = 1;
   }
   else
   {
      $notify_user = $userdata['user_notify'];
   }
   $bbcode_uid = $postrow[$total_posts - 1]['bbcode_uid'];
   $last_poster = $postrow[$total_posts - 1]['username'];
   $last_msg = $postrow[$total_posts - 1]['post_text'];
   $last_msg = str_replace(":1:$bbcode_uid", "", $last_msg);
   $last_msg = str_replace(":u:$bbcode_uid", "", $last_msg);
   $last_msg = str_replace(":o:$bbcode_uid", "", $last_msg);
   $last_msg = str_replace(":$bbcode_uid", "", $last_msg);
   $last_msg = str_replace("'", "'", $last_msg);
   $last_msg = "[QUOTE=\"$last_poster\"]" . $last_msg . "[/QUOTE]";
   $quick_reply_form = "
   <script language='JavaScript' type='text/javascript'>
      function checkForm()
      {
         formErrors = false;
         document.post.message.value = '';
         if (document.post.input.value.length < 2) {
            formErrors = '" . $lang['Empty_message'] . "';
         }
         if (formErrors) {
            alert(formErrors);
            return false;
         } else {
            if (document.post.quick_quote.checked) {
               document.post.message.value = document.post.last_msg.value;
            }
            document.post.message.value += document.post.input.value;
            return true;
         }
      }
   </script>
   <form action='".append_sid("posting.$phpEx")."' method='post' name='post' onsubmit='return checkForm(this)'>
   <span class='genmed'><b>".$lang["Quick_Reply"].":</b><br />";

   if (!$userdata['session_logged_in'])
   {
      $quick_reply_form .= $lang['Username'] . ":&nbsp;<input class='post' type='text' name='username' size='25' maxlength='25' value='' /><br />";
   }

   $quick_reply_form .= "<textarea name='input' rows='10' cols='50' wrap='virtual' class='post''></textarea><br />
   <input type='checkbox' name='quick_quote' />".$lang["Quick_quote"]."<br />
   <input type='checkbox' name='attach_sig' checked='checked' />".$lang["Attach_signature"]."<br />
   <input type='hidden' name='mode' value='reply' />
   <input type='hidden' name='sid' value='" . $userdata['session_id'] . "' />
   <input type='hidden' name='t' value='" . $topic_id . "' />
   <input type='hidden' name='message' value='' />
   <input type='hidden' name='notify' value=" . $notify_user  . " />
   <input type='hidden' name='last_msg' value='" . $last_msg  . "' />
   <input type='submit' name='preview' class='liteoption' value='".$lang['Preview']."' />&nbsp;
   <input type='submit' name='post' class='mainoption' value='".$lang["Submit"]."' />
   </form></span>";
}

$template->assign_vars(array(
   'QUICK_REPLY_FORM' => $quick_reply_form)
);
//
// END Quick Reply Mod
//

#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_main.php

#
#-----[ FIND ]------------------------------------------
#
//
// That's all, Folks!

#
#-----[ BEFORE, ADD ]------------------------------------
#
// Quick Reply Mod
$lang['Quick_Reply'] = 'Quick Reply';
$lang['Quick_quote'] = 'Quote the last message';

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/subSiver.cfg

#
#-----[ FIND ]------------------------------------------
#
$images['reply_new'] = "$current_template_images/{LANG}/reply.gif";

#
#-----[ AFTER, ADD ]------------------------------------
#
$images['quick_reply'] = "$current_template_images/{LANG}/quick_reply.gif";

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/overall_header.tpl

#
#-----[ FIND ]------------------------------------------
#
</head>

#
#-----[ BEFORE, ADD ]------------------------------------
#
<script type="text/javascript">

/***********************************************
* Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated April 2nd, 2005.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='+ ' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

var expandcontract_oldOnLoad = null;
function do_onload(){
if( expandcontract_oldOnLoad ) { expandcontract_oldOnLoad(); expandcontract_oldOnLoad = null; }
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
{ expandcontract_oldOnLoad=window.onload; window.onload=do_onload }

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

</script>

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/viewtopic_body.tpl

#
#-----[ FIND ]------------------------------------------
#
        <td align="left" valign="middle" nowrap="nowrap"><span class="nav"><a href="{U_POST_NEW_TOPIC}"><img src="{POST_IMG}" border="0" alt="{L_POST_NEW_TOPIC}" align="middle" /></a>&nbsp;&nbsp;&nbsp;<a href="{U_POST_REPLY_TOPIC}"><img src="{REPLY_IMG}" border="0" alt="{L_POST_REPLY_TOPIC}" align="middle" /></a>

#
#-----[ AFTER, ADD ]------------------------------------------
#
   <td align="left" onClick="expandcontent(this, 'sc1')" style="cursor:hand; cursor:pointer"><img alt="quick reply" title="quick reply" src="templates/subSilver/images/quick_reply.gif"></span></td>


#
#----[ FIND ]------------------------------------------------
#
     {S_TOPIC_ADMIN}</td>

#

#----[ AFTER, ADD ]-------------------------------------------
#
<td align="left"><div id="sc1" class="switchcontent">{QUICK_REPLY_FORM}</div></td>

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM

User avatar
D¡cky
Former Team Member
Posts: 11812
Joined: Tue Jan 25, 2005 8:38 pm
Location: New Hampshire, USA
Name: Richard Foote
Contact:

Post by D¡cky »

I don't know what your conditions are for displaying the button. If you have no conditions and display it all the time

Code: Select all

OPEN
 viewtopic.php

FIND
'REPLY_IMG' => $reply_img,

AFTER,ADD
'QUICK_REPLY_IMG' => $images['quick_reply_img']

OPEN
templates/subSilver/viewtopic_body.tpl

PLACE
{QUICK_REPLY_IMG}

where you want the image to show
If you have conditions, then you probably want to do something like this:

Code: Select all

OPEN
 viewtopic.php

FIND
$reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];

AFTER, ADD
$quick_reply_img = ( this condition) ? (or this condition) : $images['quick_reply_img']

FIND
'REPLY_IMG' => $reply_img,

AFTER,ADD
'QUICK_REPLY_IMG' => $reply_img

OPEN
templates/subSilver/viewtopic_body.tpl

PLACE
{QUICK_REPLY_IMG}

where you want the image to show
You work in the alt text and url in basically the same way. As you browse through viewtopic.php, you will see how it is done with other buttons
Have you hugged someone today?

snafumaster
Registered User
Posts: 77
Joined: Wed Jun 23, 2004 11:07 am
Location: S. of Boston
Name: Matthew Gendreau
Contact:

Post by snafumaster »

Thanks Dicky, with that info, I think I can finish this off.

I'm glad you pointed out the conditions part, becuse I didn't consider them. The way I have it now, it will always display. That doesn't sound like how it should be. It should have, if I'm not mistaken, the same conditions as regular reply.

This MOD is obviously a very simple MOD that I'm working on, but I want it to appear as much as "stock phpbb" as I can make it.

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 »

also, you should use a template file instead of hard-coding.

snafumaster
Registered User
Posts: 77
Joined: Wed Jun 23, 2004 11:07 am
Location: S. of Boston
Name: Matthew Gendreau
Contact:

Post by snafumaster »

afterlife_69 wrote: also, you should use a template file instead of hard-coding.
are you saying the entire quick reply form should be in a .tpl? Why is this better?

Now I have another question. I want the button to have the same conditions for the most part, but instead of it showing the forum_locked image when the forum is locked, I would rather it show nothing...or at least space.gif Any idea if I can do that? I'm afraid that I may be overreaching at this point :oops:

User avatar
D¡cky
Former Team Member
Posts: 11812
Joined: Tue Jan 25, 2005 8:38 pm
Location: New Hampshire, USA
Name: Richard Foote
Contact:

Post by D¡cky »

To have a space instead of a button when the forum or topic is locked

Code: Select all

$quick_reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? '$nbsp;' : $images['quick_reply'];
Have you hugged someone today?

snafumaster
Registered User
Posts: 77
Joined: Wed Jun 23, 2004 11:07 am
Location: S. of Boston
Name: Matthew Gendreau
Contact:

Post by snafumaster »

That's great, thanks.

Post Reply

Return to “[2.0.x] MOD Writers Discussion”