Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: karlbenson on October 14, 2007, 04:51:27 PM

Title: Select All & Copy Code To Clipboard
Post by: karlbenson on October 14, 2007, 04:51:27 PM


SELECT ALL AND COPY CODE TO CLIPBOARD v1.2
By Karl Benson


Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=981) | Comment On This Mod (http://www.simplemachines.org/community/index.php?topic=200407.0)

Introduction
This mod alters the output of the 'code' tag to include links to select all the code and to copy it to clipboard.

Requires 'Flash' to enabled by the browser (as the copying is done by a flash file called _clipboard.swf)

Tested in browsers
IE 6/7
Firefox 1/2
Opera (Select All does not work, but Copy To Clipboard works.)

Features
o Adds "Select Code" Link to each coded section
o Adds "Copy To Clipboard" Link to each coded section

There are no admin settings with this mod. To disable/remove it, you must uninstall it.

Installation
Installation affects source files and a javascript file which is called from the default theme for ALL themes, therefore NO theme edits will be required.
(unless there is a conflict with modifications OR if your not using a supported language)

There are TWO versions of this mod.
One for SMF 1.1.x versions and
one for SMF 2.0 Beta 1 (which is currently available to Charter Members).

If your using a language different than the ones supported this mod (listed below), then you will need to add the following to the Modifications.{language}.php for each theme (The language folder can be found eg Themes/{themename}/languages/)

FIND
?>
ADD BEFORE (and translate as necessary the language strings)
$txt['codeselectall'] = 'Select All';
$txt['codecopytoclipboard'] = 'Copy To Clipboard';
$txt['codedivider'] = '|';


Languages
o Currently Supports
- English/English-utf8
- English_British/English_British-utf8
- Turkish/Turkish-utf8 (Thanks to Kapadokyali & BadBoy)
- Spanish/Spanish-utf8 (Thanks to EgAr)
- Spanish_es/Spanish_es-utf8 (Thanks to EgAr)
- Greek/Greek-utf8 (Thanks to MinasC)
I welcome translations for any other languages which SMF Supports.
Please translate the following and post them in the modification topic.
$txt['codeselectall'] = 'Select All';
$txt['codecopytoclipboard'] = 'Copy To Clipboard';
$txt['codedivider'] = '|';


Support
Please use the modification thread for support with this modification.
(Please don't ask me to do the edits for you)

Changelog
1.0 - 10th October 2007
o Initial release
1.1 - 20th October 2007
o Added languages
- Turkish/Turkish-utf8 (Thanks to Kapadokyali & BadBoy)
- English_British/English_British-utf8
- Spanish/Spanish-utf8 (Thanks to EgAr)
- Spanish_es/Spanish_es-utf8 (Thanks to EgAr)
1.2 - 22nd November 2007
o Added Greek/Greek-utf8 (Thanks to MinasC)
Title: Re: Select All & Copy Code To Clipboard
Post by: MinasC on October 14, 2007, 06:16:33 PM
wow man , productivity day today , right ?
thnx a lot !
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on October 14, 2007, 06:18:13 PM
They have all been approved today.
I created these in the past few days to 1-3 weeks.

and theres still 2 more to be fix then to be approved.
Title: Re: Select All & Copy Code To Clipboard
Post by: MinasC on October 14, 2007, 06:20:28 PM
great work !
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on October 14, 2007, 06:23:45 PM
thanks MinasC
Title: Re: Select All & Copy Code To Clipboard
Post by: MinasC on October 14, 2007, 06:35:36 PM
hey , i just tried to install and got an error : subs.php not found ! i think you have to change install.xml and put "Subs.php" instead of "subs.php" !
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on October 14, 2007, 06:50:27 PM
I was in the process of fixing it when you posted it.

Updated versions of 1.0 are not available via mod section.
Title: Re: Select All & Copy Code To Clipboard
Post by: MinasC on October 14, 2007, 06:54:51 PM
well ,

i installed it fine in one of my forums (i am still testing that one) but i got that text

$txt['codeselectall'] = 'Select All'; $txt['codecopytoclipboard'] ='Copy To Clipboard'; $txt['codedivider'] = '|';

at the top of my pages , and the mod doesn't show ! what's wrong ?
thnx !
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on October 14, 2007, 06:59:54 PM
This one is not my mods fault, but a bug in SMF on some server setups. :P

Open
Modifications.english.php (the location of this file is Themes/default/languages)

Making sure no text strings like those you posted are;
above <?php (which needs to be the first thing in the file)
below ?> (which needs to be the last thing in the file [on a line of its own]

if your using utf8, you will need to do the same for
Modifications.english-utf8.php

Title: Re: Select All & Copy Code To Clipboard
Post by: edi67 on October 15, 2007, 10:47:51 AM
i was searching this by AGEssss thxxxxx   work ok for now
Title: Re: Select All & Copy Code To Clipboard
Post by: MinasC on October 15, 2007, 03:36:03 PM
Quote from: karlbenson on October 14, 2007, 06:59:54 PM
This one is not my mods fault, but a bug in SMF on some server setups. :P

Open
Modifications.english.php (the location of this file is Themes/default/languages)

Making sure no text strings like those you posted are;
above <?php (which needs to be the first thing in the file)
below ?> (which needs to be the last thing in the file [on a line of its own]

if your using utf8, you will need to do the same for
Modifications.english-utf8.php



done , all ok ! thnx !

(by the way , i installed 4 of the mods you posted yesterday and they are all great ! my congrats man !!!)
Title: Re: Select All & Copy Code To Clipboard
Post by: Badboy on October 17, 2007, 02:11:32 AM
Nice mod.

Here are the Turkish and Turkish-utf8 translations

Code (Turkish) Select
$txt['codeselectall'] = 'Hepsini Seç';
$txt['codecopytoclipboard'] = 'Panoya Kopyala';
$txt['codedivider'] = '|';


Code (Turkish-utf8) Select
$txt['codeselectall'] = 'Hepsini Seç';
$txt['codecopytoclipboard'] = 'Panoya Kopyala';
$txt['codedivider'] = '|';
Title: Re: Select All & Copy Code To Clipboard
Post by: EgAr on October 18, 2007, 11:28:03 PM
Hi, for

spanish  ,  spanish_es , spanish-utf8 , spanish_es-utf8


$txt['codeselectall'] = 'Seleccionar todo';
$txt['codecopytoclipboard'] = 'Copiar al Portapapeles';
$txt['codedivider'] = '|';




Saludos   :D
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on October 19, 2007, 09:03:41 PM
gracias.

I've now uploaded v1.1. to add all the languages I've had submitted.

1.1 - 20th October 2007
o Added languages
- Turkish/Turkish-utf8 (Thanks to Kapadokyali & BadBoy)
- English_British/English_British-utf8
- Spanish/Spanish-utf8 (Thanks to EgAr)
- Spanish_es/Spanish_es-utf8 (Thanks to EgAr)
Title: Re: Select All & Copy Code To Clipboard
Post by: MinasC on October 25, 2007, 08:09:33 PM
here is the greek translation :

$txt['codeselectall'] = 'Επιλογή Όλων';
$txt['codecopytoclipboard'] = 'Αντιγραφή στον Πίνακα';
$txt['codedivider'] = '|';
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on November 21, 2007, 09:23:29 PM
Thanks MinasC

I've uploaded v1.2 with theGreek Language strings inside

1.2 - 22nd November 2007
o Added Greek/Greek-utf8 (Thanks to MinasC)
Title: Re: Select All & Copy Code To Clipboard
Post by: MinasC on November 22, 2007, 12:19:36 PM
you are welcome !
Title: Re: Select All & Copy Code To Clipboard
Post by: falguni1 on January 02, 2008, 08:04:33 PM
how to use this mod.
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on January 02, 2008, 08:34:17 PM
It adds two links to the 'code' box.

One to 'select all' the contents of the code box.
Second to Copy it to Clipboard (so you can paste it elsewhere)
Title: Re: Select All & Copy Code To Clipboard
Post by: falguni1 on January 02, 2008, 08:59:21 PM
I cant see links.
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on January 02, 2008, 09:01:01 PM
Are you using a language supported by the mod?
Are you getting any errors in your error log?
Can you link me to a url/page on your forum where url tags are installed?
Title: Re: Select All & Copy Code To Clipboard
Post by: falguni1 on January 02, 2008, 09:02:22 PM
this is my demo site

http://omsites.com/copy1/index.php?topic=16.0
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on January 02, 2008, 09:13:05 PM
Something has gone wrong with SMF package manager.
Its inserted the language strings in the wrong place in the file.

Its not a bug with this mod (or my buy me a beer mod), but for some unknown reason it happens with smf.

Open
Themes/default/Languages/Modifications.english.php

Make sure <?php is at the VERY TOP at the file on its OWN line
and
?> is at the very bottom of the file on its OWN line.

(so as necessary move any language strings in-between).

Do the same for
Themes/default/Languages/Modifications.english-utf8.php
if your using utf8.

And for any other languages you may be using.
Title: Re: Select All & Copy Code To Clipboard
Post by: au8ust on January 07, 2008, 12:52:21 AM
Hm... Weird :( I can't use it in Firefox, Select All and Copy To Clipboard are not working at all. It's working in IE for Select All only.

Any idea?
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on January 07, 2008, 12:53:40 AM
The mod has been tested in firefox.

In firefox Goto
Tools > Error console

is it giving you any error?

Is flash enabled in Firefox?
Title: Re: Select All & Copy Code To Clipboard
Post by: au8ust on January 07, 2008, 12:54:25 AM
Okay I'll try that

BTW, below is Thai and Lao translation ;)


<file name="$languagedir/Modifications.thai-utf8.php" error="skip">
<operation>
<search position="end" />
<add><![CDATA[
$txt['codeselectall'] = 'เลือกทั้งหมด';
$txt['codecopytoclipboard'] = 'สำเนาไว้ใน Clipboard';
$txt['codedivider'] = '|';
]]></add>
</operation>
</file>

<file name="$languagedir/Modifications.lao-utf8.php" error="skip">
<operation>
<search position="end" />
<add><![CDATA[
$txt['codeselectall'] = 'ເລືອກທັງຫມົດ';
$txt['codecopytoclipboard'] = 'ສຳເນົາໄວ້ໃນ Clipboard';
$txt['codedivider'] = '|';
]]></add>
</operation>
</file>
Title: Re: Select All & Copy Code To Clipboard
Post by: au8ust on January 07, 2008, 12:59:44 AM
Quote from: karlbenson on January 07, 2008, 12:53:40 AM
The mod has been tested in firefox.

In firefox Goto
Tools > Error console

is it giving you any error?

Is flash enabled in Firefox?

Okay, it causes from Flashblock extension so I disable it and Select All is working fine now :)

For the Copy to Clipboard shows these errors

Warning: Error in parsing value for property 'opacity'.  Declaration dropped.
Source File: http://mydomain.tld/webboard/index.php/topic,72.msg83.html#msg83
Line: 0
Warning: Error in parsing value for property 'opacity'.  Declaration dropped.
Source File: http://mydomain.tld/webboard/index.php/topic,72.msg83.html#msg83
Line: 0
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on January 07, 2008, 01:08:48 AM
So the Copy to Clipboard bit still isnt working?

The mod doesnt do anything for opacity.
They are probably related to some other javascript on your page.
Title: Re: Select All & Copy Code To Clipboard
Post by: ne.miguelito on January 07, 2008, 03:20:35 AM
Quote from: karlbenson on January 07, 2008, 12:53:40 AM

Is flash enabled in Firefox?

as I can see if it is active in the Firefox?
Title: Re: Select All & Copy Code To Clipboard
Post by: au8ust on January 07, 2008, 05:02:33 AM
NWM, I will use only the Copy All ;)

Thanks for the MOD!
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on January 19, 2008, 12:07:03 AM
I have reuploaded this mod and screenshots for it.

I am in the process of doing it for ALL my other mods aswell.  Please bear with me.
Title: Re: Select All & Copy Code To Clipboard
Post by: Teunel on February 09, 2008, 10:45:12 AM
Hi, Thanks for this great mod. I have one question though.

I have changed my forum a lot, and when I post a topic, it automatically shows the content in a Code box. I'm not using the code tags, I just placed the code divs in my Display.Template.php. An example can be seen here: http://www.krabbelplaatjes.com/grappig/lol-t1201.0.html
Now, I want to show the Select all and Copy to that code box too, but it isn't really working. What do I have to modify to get this working? I tried looking at the source and adding the Javascript in there manually, but this isn't working.

Here is a Dutch translation:

$txt['codeselectall'] = 'Selecteer Alles';
$txt['codecopytoclipboard'] = 'Kopieer naar Klembord';
$txt['codedivider'] = '|';
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on February 09, 2008, 11:25:06 AM
It wouldn't be easy.
The javascript is built on basis of the default code <div>s

I cannot provide support for customizing it.
Title: Re: Select All & Copy Code To Clipboard
Post by: Teunel on February 09, 2008, 12:06:17 PM
Ok, then I will take a look at it myself when I can find some time! :D Thanks anyway for the great mod!
Title: Re: Select All & Copy Code To Clipboard
Post by: Darknico on March 17, 2008, 06:01:23 AM
Good mod!!!
Thanks!

It is possible for tag [php][/php] ?
Title: Re: Select All & Copy Code To Clipboard
Post by: Kimmie on June 01, 2008, 12:06:57 AM
Hi Karl, seems this is my week to "bug" you... heehehe

I tried to install this mod via package manager and got this:

1. Execute Modification ./Themes/default/script.js Test successful
2. Execute Modification ./Sources/Subs.php Test failed  
3. Execute Modification ./Themes/default/languages/Modifications.english.php Test successful
4. Execute Modification ./Themes/default/languages/Modifications.english-utf8.php Skipping file
5. Execute Modification ./Themes/default/languages/Modifications.english_british.php Skipping file
6. Execute Modification ./Themes/default/languages/Modifications.english_british-utf8.php Skipping file
7. Execute Modification ./Themes/default/languages/Modifications.turkish.php Skipping file
8. Execute Modification ./Themes/default/languages/Modifications.turkish-utf8.php Skipping file
9. Execute Modification ./Themes/default/languages/Modifications.spanish.php Skipping file
10. Execute Modification ./Themes/default/languages/Modifications.spanish-utf8.php Skipping file
11. Execute Modification ./Themes/default/languages/Modifications.spanish_es.php Skipping file
12. Execute Modification ./Themes/default/languages/Modifications.spanish_es-utf8.php Skipping file
13. Execute Modification ./Themes/default/languages/Modifications.greek.php Skipping file
14. Execute Modification ./Themes/default/languages/Modifications.greek-utf8.php Skipping file
15. Extract File ./_clipboard.swf


Would the fact I am using 1.1.5 be the issue since you stated that no manual theme edits were needed with this one? I wanted to ask and see what you thought before I tried manually installing it and screwing up something..lol.
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on June 01, 2008, 01:49:16 PM
It must be conflicting with another mod.

Its not a theme edit. Its a conflict. The only solution is to do it manually.
Title: Re: Select All & Copy Code To Clipboard
Post by: Kimmie on June 02, 2008, 12:47:18 AM
ew I was afraid of that...ok one more question and I will leave you alone (for a while anyways..hehe).

In a case like this, which way do you recommend I do it:

1. Install it via package manager and then edit the Subs.php file and make the edits
2. Install the whole thing manually

I am not sure if it really makes a difference but I wanted to ask your professional opinion as to what you think the best way would be. I guess I just need clarification tht if I do it the #1 way, can I be assurred tht it will make the correct edits to the other files? (this is me trying to learn how to do this so I dont have to keep asking hehehe). In most cases I usualy dont have to do manual edits cuz my theme uses mostly the default files - so I havent had a whole lot of practice with manual edits and I want to make sure I do it right. :)

Thanks for ALL your help. Your mods are some of the best I have used (and I have several lol)
Title: Re: Select All & Copy Code To Clipboard
Post by: karlbenson on June 02, 2008, 04:30:25 PM
Thanks.

Generally I'd recommend installing it entirely manually.
But I've done it the other method too.

So its your choice.
Although I would recommend taking full backups of your files and your database before proceeding with such changes.
Title: Re: Select All & Copy Code To Clipboard
Post by: Ni©holąś™ on June 02, 2008, 04:33:30 PM
great mod.Thanks!
Title: Re: Select All & Copy Code To Clipboard
Post by: Kimmie on June 06, 2008, 07:11:14 PM
HI its me again :). Im not sure how to explain this so I will start from the beginning..hehe.

I decide to install the mod via the package manager and then modify the Subs file (less for me to mess up  lol). No errors in the error log, however, the mod isnt working. It hasnt made any changes to the "code" part. Since I have other mods that affect that file - some of the code is in the same section that this mod changes, I couldnt replace that entire section with what the parser said to because it would mess up the other mod(s) that also use that section, so what I did was compare what code you added to that area with what is in my original subs file and made the necessary changes. Basically all I saw that was different was these two sections of code:

// SELECT ALL AND COPY CODE TO CLIPBOARD MOD
static $codecounter = 0;
$codecounter++;
$data = \'<div class="codeheader">\' . $txt[\'smf238\'] . \': \'
.\'<a href="javascript:void(0)" title="\'.$txt[\'codeselectall\'].\'" onclick="javascript:selectall(\\\'code_a\'.$codecounter.\'\\\');return false;">\'.$txt[\'codeselectall\'].\'</a>\'
.\' \'.$txt[\'codedivider\'].\' <a href="javascript:void(0)" title="\'.$txt[\'codecopytoclipboard\'].\'" onclick="javascript:copy(\\\'code_a\'.$codecounter.\'\\\');return false;">\'.$txt[\'codecopytoclipboard\'].\'</a>\'
.\'</div><div class="code" id="code_a\'.$codecounter.\'">\' . ($context[\'browser\'][\'is_gecko\'] ? \'<pre style="margin-top: 0; display: inline;">\'.$data.\'</pre>\' : $data) . \'</div>\';
// END OF SELECT ALL AND COPY TO CLIPBOARD MOD


AND

// SELECT ALL AND COPY CODE TO CLIPBOARD MOD
static $codecounter = 0;
$codecounter++;
$data[0] = \'<div class="codeheader">\' . $txt[\'smf238\'] . \': (\'.$data[1].\') \'
.\'<a href="javascript:void(0)" title="\'.$txt[\'codeselectall\'].\'" onclick="javascript:selectall(\\\'code_b\'.$codecounter.\'\\\');return false;">\'.$txt[\'codeselectall\'].\'</a>\'
.\' \'.$txt[\'codedivider\'].\' <a href="javascript:void(0)" title="\'.$txt[\'codecopytoclipboard\'].\'" onclick="javascript:copy(\\\'code_b\'.$codecounter.\'\\\');return false;">\'.$txt[\'codecopytoclipboard\'].\'</a>\'
.\'</div><div class="code" id="code_b\'.$codecounter.\'">\' . ($context[\'browser\'][\'is_gecko\'] ? \'<pre style="margin-top: 0; display: inline;">\'.$data[0].\'</pre>\' : $data[0]) . \'</div>\';
// END OF SELECT ALL AND COPY TO CLIPBOARD MOD


I added them directly after both of these codes in that file just like the parser said to:

// Fix the PHP code stuff...
$data[0] = str_replace("<pre style=\"display: inline;\">\t</pre>", "\t", implode(\'\', $php_parts));


Could you take a look at my Subs.php file and see if you see anything I missed? It would be greatly appreciated if you could :).

The 1st attachment is my Subs file BEFORE installing the mod. The second one is after I made the edit.
Title: Re: Select All & Copy Code To Clipboard
Post by: fdLP. on May 22, 2009, 01:03:00 PM
bumping it , need it fixed , its not working , it doesnt copy the text when it select it .. Using 1.1.9 (sorry if its aint allowed)
Title: Re: Select All & Copy Code To Clipboard
Post by: fdLP. on May 24, 2009, 10:45:19 AM
anyone got a similar mod working on 1.1.9?