Mar 27

A very efficient way of instantiating a class dynamically in PHP


Since PHP is a loosely typed language, it provides great flexibility in creating variables and objects at runtime without having to specifically declare them first. It is well known that $i=10, $i=”test”, $i = date() will all work without creating any syntax or compile errors.

A lesser used concept is that this feature can be used to create an object at runtime without having to check for the object type at first. Eg.if you have had 3 classes and only one of them had to be created depending on a condition the following would be the sample code:

<?php
	error_reporting(E_ALL);

	class Generic {
		function xprint() {
			echo("generic");
		}
	}
	class A extends Generic{
		function xprint() {
			echo("A");
		}
	}

	class B extends Generic{
		function xprint() {
			echo ("B");
		}
	}

	class C extends Generic{
		function xprint() {
			echo("C");
		}
	}

	$test = "B";
	if ($test =="B")
		$x = new B();
	else if ($test == "A"
		$x = new A();
    else if ($test == "C")
	    $x = new C();
	$x->xprint();
	echo("end");
?>

Instead of doing multiple checks and then creating the relevant class, a more efficient way is to pass the classname as a string and then create it directly as shown below:

<?php
	error_reporting(E_ALL);

	class Generic {
		function xprint() {
			echo("generic");
		}
	}
	class A extends Generic{
		function xprint() {
			echo("A");
		}
	}

	class B extends Generic{
		function xprint() {
			echo ("B");
		}
	}

	class C extends Generic{
		function xprint() {
			echo("C");
		}
	}

	$test = "B";
	$x = new $test();
	$x->xprint();
	echo("end");
?>

The above code will print “B” since it creates the class B in $x. What about classes where arguments are required in the constructor? Simple call it with the arguments eg. $x = new $test(“arg1″, “arg2″);

Mar 27

List of Web-Browsers with download links & official websites


Well these are a few of the names and their respective links of certain web-browsers over the Internet which you can find and use according to your needs.
Most of the main ones you already know like Internet Explorer, Mozilla Firefox, Google Chrome, Opera, Safari and more.

Below we have a tabular format of information comprising of the browser’s name, developer/company links, download page links, current version available and what types of operating systems do each of them support.

Internet Explorer

Internet Explorer

- Windows

Mozilla Firefox

- click here to download version 4.0
- Windows, Mac OS, Linux, Maemo, Android, Nokia N900

Google Chrome

- click here to download version 10.0.648.151
- Windows, Mac OS, Linux

Opera

- click here to download version 11.01
- Windows, Mac OS, Linux, Android, iPhone, Tablets

Safari

- Windows, Mac OS

Netscape Navigator

- click here to download version 9.0.0.6
- Windows, Mac OS, Linux

Camino

- click here to download version 2.0.7
- Mac OS

Sea Monkey

- click here to download version 2.0.13
- Windows, Mac OS, Linux

K-meleon

- click here to download version 1.5.4
- Windows

Galeon

- click here to download version 2.0.2
- Linux

Konqueror

- click here to download version 4.6
- Mac OS, Linux

Maxthon browser

- click here to download version 3.21.1000
- Windows, Android

Flock browser

- click here to download version 2.6.1
- Windows, Mac OS, Linux

Lunascape

- click here to download version 6.4.4
- Windows

Amaya

- W3C
- click here to download version 11.3.1
- Windows, Mac OS, Linux

iCab

- click here to download version 4.8a
- Mac OS, iPhone, iPod Touch, iPad

Midori

- click here to download version 0.3.3
- Windows, Mac OS, Linux

Uzbl

- Uzbl
- Linux

RockMelt

- click here to download version 0.3.3
- Windows, Mac OS

Voyager

- click here to download version 3.3.125
- Others

Dillo Web Browser

- click here to download version 2.2
- Windows, Mac OS, Linux, *BSD, Solaris

Slim Browser

- click here to download version 5.01.023
- Windows

KidRocket

- KidRocket ( official site not available )
- click here to download version 1.5.0.2
- Windows

Epic Browser

- click here to download version 1.2
- Windows

Iron Browser

- click here to download version 10.0.650.0
- Windows

GNU IceCat

- click here to download version 3.6.9
- Mac OS, Linux

Comodo Dragon

- click here to download version 4.1.1.12
- Windows

OmniWeb

- click here to download version 5.10.3
- Mac OS

Crazy Browser

- click here to download version 3.05
- Windows

ShenzBrowser

- click here to download version 1.1
- Windows

Swiftweasel

- click here to download version 3.5.5
- Linux

Enigma Browser

- Windows

Kazehakase

- click here to download version 0.5.8
- Linux

Shiira

- Shiira Project ( official site not available )
- click here to download version 2.3
- Mac os

Avant Browser

- Windows

xB Browser

- click here to download version 3.9.10.24
- Windows

Sleipnir

- click here to download version 2.9.6
- Windows

Space time

- click here to download version 1.0
- Windows

Browse3D

- click here to download version 3.5
- Windows

3B Rooms

- 3B
- click here to download version 3.11
- Windows

Bitty Browser

- Windows

Lobo java Web Browser

- click here to download version 0.98.4
- Linux

Elinks text www Browser

- click here to download version 0.12
- Linux

Epiphany

- click here to download version 2.30.6
- Mac OS, Linux

Grail

- CNRI
- click here to download version 0.6
- Windows, Mac OS, Linux

Ibrowse

- click here to download version 2.4
- Other
Lynx
- click here to download version 2.8.7
- Windows, Mac OS, Linux

Iceweasel

- click here to download version 1.5.0.8
- Linux

Mozilla Minefield

- click here to download version 4.2
- Windows, Linux

NetSurf

- click here to download version 2.6
- RISC os, Linux, Unix, Haiku & BeOS, AmigaOS
Conkeror
- Windows, Unix/Linux, Debian & derivatives

Deepnet Explorer

- click here to download version 1.5.3
- Windows

PhaseOut

- click here to download version 5.4
- Windows

Wyzo

- click here to download version 3.6.4 (Windows) 3.5.6 (Mac)
- Windows, Mac OS

Zac Browser

- click here to download version 1.5
- Windows, Mac OS

Oregano

- RISC OS

Acoo Browser

- click here to download version 1.98.744
- Windows

Cayman Browser

- click here to download version 2.2
- Windows

GoSurf

- click here to download version 2.84.903.8452
- Windows

GreenBrowser

- click here to download version 5.8.0315
- Windows
Mar 17

Alter/change the width, height, skin and color of CKEditor


Well to change the color or height or width or even change the whole look (skin) of CKEditor , we just need to keep in mind 1 file, and that is the ” config.js ” file in the ckeditor folder.

Any changes made to the main config.js file will reflect on all the pages where the CKEditor has been used.
But if you don’t want the changes to show on all the pages then you only need to add some code in the respective pages where you want the changes to happen.

This code below will give you a nice idea about how to change the properties of your CKEditor using the config.js file
( code inside the config.js file is given below )


CKEDITOR.editorConfig = function( config )
{

// config.language = 'fr';                                                         
// config.customConfig = '/ckeditor/config.js';     
// config.toolbar = 'Basic';
// config.uiColor = '#dfe8f6';

config.height = 200;
config.width = 250;
config.skin = 'v2';      //config.skin = 'office2003'; 
                             //config.skin = 'kama';

CKEDITOR.config.toolbar_Basic = [
['Source','-','Templates'],
['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
'/',
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor'],
['Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
'/',
['Styles','Format','Font','FontSize'],
['TextColor','BGColor'],
['Maximize', 'ShowBlocks','-','About']
]
config.toolbar = 'Basic';
config.extraPlugins = "insert_image";
};

Below is the preview of the toolbar after making the above changes in the config file

After changes made in the config.js

Now let’s try changing only the color of the toolbar, for that you just have to write something like this in the config.js


// config.language = 'fr';
// config.customConfig = '/ckeditor/config.js';
   config.toolbar = 'Basic'; 
   config.uiColor = '#800040'; 
// config.height = 200;
// config.width = 250;
// config.skin = 'v2'; 

Now the toolbar will look something like this

Changed the color of the toolbar from the config.js

But if you don’t want the changes to be shown in every single page where you have used CKEditor then you have to write a few lines of code in the individual pages where you want to change the properties of your CKEditor.

In this case, I want the changes to show up only on one page called “test-editor.html”.

Case 1: changing the skin only

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 strict//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Truelogic.org::TestEditor::CKEditor example &lt;/title&gt;

&lt;script type="text/javascript" src="ckeditor/ckeditor.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;

  &lt;form name="" action="" method=""&gt;
   &lt;textarea id="txtDescrip" name="txtDescrip" cols="20" rows="5" class="ckeditor"&gt;&lt;/textarea&gt;

  &lt;script type="text/javascript"&gt;
    var editor = CKEDITOR.replace( 'txtDescrip',
    {
      toolbar : [
            ['Source','-','Templates'],
            ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
            ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
            '/',
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            ['Link','Unlink','Anchor'],
            ['Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            '/',
            ['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            ['Maximize', 'ShowBlocks','-','About'],['insert_image']
          ],
      skin : 'office2003',  // ALTERED THE SKIN HERE 
    });
  &lt;/script&gt;

  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Case 2: changing the height, width and the color of the toolbar

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 strict//EN"&gt; 
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Truelogic.org::TestEditor::CKEditor example &lt;/title&gt;

&lt;script type="text/javascript" src="ckeditor/ckeditor.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;

  &lt;form name="" action="" method=""&gt;
   &lt;textarea id="txtDescrip" name="txtDescrip" cols="20" rows="5" class="ckeditor"&gt;&lt;/textarea&gt;

  &lt;script type="text/javascript"&gt;
    var editor = CKEDITOR.replace( 'txtDescrip',
    {
      toolbar : [
            ['Source','-','Templates'],
            ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
            ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
            '/',
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            ['Link','Unlink','Anchor'],
            ['Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            '/',
            ['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            ['Maximize', 'ShowBlocks','-','About'],['insert_image']
          ],
      uiColor: 'red', 
      height: 200,
      width: 700,
    });
  &lt;/script&gt;

  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Mar 17

How to create a new toolbar plugin in CKEditor


Hey there, here is something which I learned the hard way while I was trying out my hands on customizing CKEdior for a website, in which I needed to add a new button which enabled the admin to add a particular kind of text or HTML tag in the textarea.

So therefore I thought I would share my experience through a simple step by step process of how I managed to achieve the customized feature of adding a new plugin (new button) in the CKEditor toolbar.

Well I just made a button which when clicked will add an image (in this case Truelogic.org Logo) in the textarea content.
Step 1: The basic directory structure of the CKEditor 3.3

( DO KEEP IN MIND THE VERSION OF THE CKEditor BEING USED HERE, DIFFERENT VERSIONS MAY HAVE DIFFERENT FOLDER/DIRECTORY STRUCTURE )

  ckeditor/
        config.js
        plugins/
             insert_image/
                    insert_image_button.png
                    plugin.js

Step 2: Now, as you may have an idea after seeing the folder structure that you have to create a new folder called “insert_image”, inside the plugins folder.

( IMPORTANT: Folder name is very important because the config.js recognizes the function of the plugin based on the folder name given )

Now the code which you have to paste after creating the “plugin.js” inside the “insert_image” folder is given below , this plugin code allows you to insert a predefined image inside the textarea (in this case Truelogic.org Logo)

(function(){
     //The Code is written here, which will be executed when the button is clicked
     var a= {
     exec:function(editor){
             CKEDITOR.instances.txtDescrip.insertHtml("&lt;img src='http://truelogic.org/simple/images/true.png' border=0 /&gt;");  
     //CKEDITOR.instances.ID OF THE TEXTAREA.insertHtml("IMAGE URL");
     //above line inserts an IMG tag with the predefined url of the image which points to the truelogic logo
              }
},

//The actual button is defined/created here and the associated code is linked with it
b='insert_image';
CKEDITOR.plugins.add(b,{
    init:function(editor){
    editor.addCommand(b,a); // associating the executable code with the button
    editor.ui.addButton('insert_image',{
                                     label:'Insert image',
                                     icon: this.path + 'insert_image_button.png',
                          //defining the path of the icon image which will be displayed on the toolbar for this button
                          //easiest would be to have the icon image in the same folder as the plugin.js

                                     command:b
                             });
   }
});
})();

Step 3:

Here is the “insert_image_button.png” image to make things easier for you guys

This image has to be put inside the “plugins/insert_image/” folder, next to the plugin.js

Step 4:
Here is the code which is going in the config.js:

CKEDITOR.editorConfig = function( config )
{
     CKEDITOR.config.toolbar_Basic = [
                  ['Source','-','Templates'],
                  ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
                  ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
                  ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
                  '/',
                  ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
                  ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
                  ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                  ['Link','Unlink','Anchor'],
                  ['Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
                  '/',
                  ['Styles','Format','Font','FontSize'],
                  ['TextColor','BGColor'],
                  ['Maximize', 'ShowBlocks','-','About'],
                  ['insert_image']                                //Button added to the toolbar
                ]
 config.toolbar = 'Basic';
 config.extraPlugins = "insert_image”;   //registering the plugin
};

Tips:

If you don’t want to alter the default setup of the CKEditor toolbar or if you want to show or hide specific plugins on particular pages or just one page, you can do it by writing a few lines of code in the page where you want to make this happen.

For you to understand more clearly, let me give you an example, say I only want around 10 buttons to be displayed in the toolbar for a specific page called “test-editor.html”

&lt;script type="text/javascript"&gt;

var editor = CKEDITOR.replace( 'txtDescrip',    //var editor = CKEDITOR.replace( 'ID OF THE TEXTAREA', 
{
                toolbar : [
                         ['Source','-','Templates'],
                         ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
                         '/',
                         ['insert_image']
                            ]
 });
&lt;/script&gt;

Using the above code and pasting it in the page where you want to change the look of the toolbar (hide or display a few of the buttons) will allow the page to only show those buttons or plugins which are mentioned in the code

Just to make it even more easier , here is the full code of the “test-editor.html”

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 strict//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Truelogic.org::TestEditor::CKEditor example &lt;/title&gt;

&lt;script type="text/javascript" src="ckeditor/ckeditor.js"&gt;&lt;/script&gt;
 // do keep in mind the include path of the CKEditor folder on the web server or the local server

&lt;/head&gt;

&lt;body&gt;

 &lt;form name="" action="" method=""&gt;
 &lt;textarea id="txtDescrip" cols="20" rows="5"&gt; &lt;/textarea&gt;

&lt;script type="text/javascript"&gt;

 var editor = CKEDITOR.replace( 'txtDescrip',   //var editor = CKEDITOR.replace( 'ID OF THE TEXTAREA', 
 {
 toolbar : [
 ['Source','-','Templates'],
 ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
 ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
 ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton','HiddenField'],
 '/',
 ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
 ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
 ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
 ['Link','Unlink','Anchor'],
 ['Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
 '/',
 ['Styles','Format','Font','FontSize'],
 ['TextColor','BGColor'],
 ['Maximize', 'ShowBlocks','-','About'],['insert_image'] ]
 });
&lt;/script&gt;

&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Small Hints:

‘/’,

- this allows you to add a line break in the middle of the toolbar so that whatever plugin is written after this is displayed in the next line of the toolbar

‘-’

- this allows you to add a small gap between the buttons.
Like for example: the gap between ‘strike-through’ button and the ‘SubScript’ button

Preview of the CKEditor (default) Before adding the new plugin

CKEditor - default toolbar

Preview of the CKEditor (customized) After adding the new plugin

CKEditor - customized toolbar with new plugin

Preview of the textarea when the new plugin button has been clicked

CKEditor - when insert_image button has been clicked