Virtual URL – link shorten service

VUS.me is a new and very simple link shorten service made with simplicity and quick access in mind.
Looks very promising so give it a try.. or more :D .

http://vus.me

Popularity: 2% [?]

How To Setup Wordpress MU with Domain Mapping

Here is explained how I made my Wordpress MU install to work with domain mapping. There are some tutorials out there but they are plain crap and very poorly explained. And the explanations for the domain mapping plugins are even worse. But I managed to make it work in around two days with a lot of testing and trial and error.
These are the steps that I followed. Well.. not really.. but in the end these would have been the steps that I should have followed.

NOTE! This tutorial is based on the fact that you know how to install and configure a simple Wordpress version because I will not offer detailed info about database creation and ftp uploading.

What we want to do here?

- We want to have Wordpress MU so we can create multiple Wordpress blogs but with one main Administration area.
- Create as many sub-domains as we want.
- Map those sub-domains to other domains. (subdomain.master-example.com should be accessible from addon-example.com )

I. Configure domains

  • First you need some domains, for this tutorial at least 2. One to be the master domain which we will call here master-example.com and the other domain that we will map to the blog created as a subdomain on master-example.com whitch we will call addon-example.com.
  • Next you need hosting witch offers WHM with CPanel. WHM not really needed I think. I added the domains and parked them from WHM but that can be done in CPanel also.
  • After you have the main domain configured on a hosting and you have acces to the CPanel you need to go to “Subdomains” and set the subdomains on a wildcard(*). So where it says “Create a Subdomain” enter * , check if your master domain is selected in the next drop down and in Document root is “public_html/” and click Create.
  • In the list of sub-domains now should be: “* .master-example.com Home/public_html not redirected” . What this does it lets Wordpress MU create any kind of sub-domain without first adding it manually in the CPanel.
  • Now we need to add the addon-example.com domain. Go to: “Parked Domains” and enter addon-example.com in the box and press “Add Domain“. This should park addon-example.com on top ofmaster-example.com. Until I used the Park domain option my domain mapping in Wordpress didn’t work.
  • Now go to “Simple DNS Zone Editor” and here you have to set an A record for addon-example.com. So select the addon domain addon-example.com and where it says Add an A Record in the “Name:” field write *.addon-example.com and on the “Address” field put the master domain IP (you should find it in the left sidebar in CPanel.. for example: “Shared Ip Address: 127.0.0.20″ .). Click “Add A Record”.
  • Great. Now you are ready to install Wordpress MU!

Note! I made all of this in the WHM administration but I saw those modifications in CPanel also and I checked if they correspond and it seems that it can be done from CPanel too. For WHM just use “Park a Domain” and “Edit DNS Zone” buttons and make the above modifications.

II. Install Wordpress MU.

  • Create a database and a user in CPanel .. or whatever.
  • Download the Wordpress MU sources from here
  • Copy the files to your main domain. I uploaded them to my domain root but they say it can be installed to a folder or a sub-domain too.
  • Now navigate to your domain (master-example.com) and you should see the installation page. There are some errors for sure and the usual error is that you need to make some folder writable by Wordpress. That means to give those folders 777 permission and you’ll have to reset those to 755 after successful install.
  • Just follow the steps and be careful to specify where it says Blog addresses to use sub-domains and at Server Address your domain without www or http://
  • And, this is very important, after install go to Admin menu (upper right corner) in the Wordpress admin interface and change your password to something you can remember. And don’t forget to change the folder permissions back to 755
  • Now is the time to see if it works. Go to Site Admin -> Blogs and add a new blog. Let’s say subdomain.master-example.com. If the email address is different from the one you used at install a new user will be created when you add a new blog. And this happens every time you use a different email address.
  • OK. Now navigate to: subdomain.master-example.com (or whatever you created) and you should see your blog. Congrats! Now you have a working installation of Wordpress MU. If it doesn’t work repeat the above steps with more attention or if you just registered your domains wait a few hours for DNS registrations.

III. Install the Domain Mapping plugin and map a domain

  • First download the plugin WordPress MU Domain Mapping (http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/). I used version 0.5. Many many thanks to those guys for creating this awesome plugin.
  • Copy sunrise.php into wp-content/
  • Copy domain_mapping.php into wp-content/mu-plugins/
  • Edit wp-config.php and uncomment the SUNRISE definition line: define( ‘SUNRISE’, ‘on’ );
  • Now go to Plugins and activate the mapping plugin for the main domain.
  • After you done those login as the MU admin and go to Site Admin->Domain Mapping and set the server IP address. (you should know this from when you added the A record)
  • Now this is the tricky part on what I wasted a lot of hours. Go to Site Admin -> Options and scroll down at the bottom. And after where it says “Site Wide Settings” click on the check box for the Plugins and click Update Options. This activates the plugins for the sub-domains. If you don’t do this you can’t map domains to the specific sub-domain because you will not see the plugin on your sub-domains admin area. (First I actually edited this directly in the database until I realized this.)
  • Now go to Site admin -> Blogs and when you hover over the added sub-domain some link will appear. Click on “Backend”. This will redirect you to that sub-domain Wordpress administration panel.
  • While in this panel go to Plugins and you should see the mapping plugin. Activate it.
  • And now go to Tools -> Domain mapping. And here is the part that we worked so hard to get to. Under “Add new domain” write the domain that you want to map to this sub-domain.
  • After you clicked “Add” go to the domain that you wanted to map (addon-example.com) and you will see the contents of subdomain.master-example.com

Kind of a long tutorial but hopefully I didn’t forgot anything in the process.
Let me know in the comments if it helped you or if you still got problems with the install flow.

Cheers!

Popularity: 19% [?]

CKEditor 3.0 Send and Receive data with AJAX

Attention: This is a quick tutorial and no in depth information will be provided. Use Google or whatever you want to learn more about PHP, Javascript and AJAX calls. Also on the CKEditor site you can find more info about the editor itself.

The old FCKEditor is now called CKEditor 3.0 and it’s:

CKEditor is a text editor to be used inside web pages. It’s a WYSIWYG editor, which means that the text being edited on it looks as similar as possible to the results users have when publishing it. It brings to the web common editing features found on desktop editing applications like Microsoft Word and OpenOffice.

You can download it from here: http://ckeditor.com.

OK.. so I wanted to edit some HTML template files from an Admin area module and the new CKEditor looks pretty nice so I gave it a try.
First I install the CKEditor and this is pretty easy to do, just download the editor and copy the files to the server.

Create a link to the editor:

1
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>

and then creat a text field area:

1
<textarea name="template_body" id="template_body" >page content here</textarea>

and add the javascript code to load the editor:

1
2
3
<script type="text/javascript">
            CKEDITOR.replace( 'template_body' );
        </script>

I added also a div to hold the received messages from the AJAX calls:

1
<div id="saveButton" style="font-weight:bold"></div>

Then I generated a tree/file view of all the template files(for sake of simplicity I will not show you how to do that).
The links are generated like this:

1
<a href="" onclick="getFile('test.html'); return false;" id="file" >test.html</a>

The return false is so than I won’t need to use the stupid # on the href=”" so that the page won’t refresh.

And the two Javascript functions that make the Ajax calls are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<script type="text/javascript">
function getFile(file)
{      
    var httpRequest = (!window.XMLHttpRequest)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    httpRequest.onreadystatechange = function()
    {
        if(httpRequest.readyState == 4)
        {
            // send info to editor
            CKEDITOR.instances.template_body.setData(httpRequest.responseText);
            document.getElementById('saveButton').innerHTML = '<a href="" onclick="saveFile(\'' + file + '\'); return false;" >SAVE TEMPLATE</a>';
        }
    }
    httpRequest.open("GET","/ajax/get_file.php?file="+file,true);
    httpRequest.send(null);      
}

function saveFile(filename)
{    
    // get info from editor
    var editordata = CKEDITOR.instances.template_body.getData();

    var httpRequest = (!window.XMLHttpRequest)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    httpRequest.onreadystatechange = function()
    {
        if(httpRequest.readyState == 4)
        {
            if(httpRequest.responseText == "success")
            {
                document.getElementById('saveButton').innerHTML = '<span style="color:red">Template saved</span>';
            }
            else
            {
                document.getElementById('saveButton').innerHTML = httpRequest.responseText;
            }
        }
    }
    var passingData = "file="+filename+"&template_body="+ escape(editordata)
    httpRequest.open("POST", "/ajax/save_file.php?"+passingData, true);
    httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");        
    httpRequest.send(passingData);
}
</script>

The first function getFile(), gets the name of the file to load and send the response text from the PHP script to the editor.
The PHP script gets the name of the file and with file_get_contents function I retrieve that template’s contents.

1
echo file_get_contents('/templates/'.$_GET['file']);

The editor shows the received data with the command:

1
CKEDITOR.instances.template_body.setData(httpRequest.responseText);

“template_body” is the name of the text field that is replaced by the CKEditor.
In this function I also add a new link to the page with innerHTML that makes the reference to the second function: saveFile().

The second function saveFile() get the current name of the loaded template (test.html for example) and saves the data from the editor to
a variable “editordata” with the call:

1
CKEDITOR.instances.template_body.getData();

The editor data is sent to the PHP script, escaped and urlencoded with POST.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// write content to file
$filename = '/templates/'.$_POST['file'];
$template_body = $_POST['template_body'];

if (is_writable($filename)) // check file first
{
    if (!$handle = fopen($filename, 'w'))  // open file
    {
         echo 'fail open';
    }

    if (fwrite($handle, $template_body) === FALSE) // write file
    {
        echo 'fail write';
    }

    fclose($handle); // and close the file
    echo 'success';
}
else
{
    echo 'fail not writable';
}

The PHP code is straight forward: open file, write contents to file, close file.
If success is returned then with innerHTML we write that the template was saved if not the specific fail message will be shown.
(usually those errors appear if the file is missing or the file path is wrong or the file permissions are wrong.)

So here you have it an browser based template editor.
Oh and if your template has

1
<html>, <body>

tags they will be deleted by the editor. Don’t know how to override that shit functionality.

Over and out.

Popularity: 100% [?]

How to block spamm comments in Wordpress

1. Activate Akismet
2. Add this in the .htaccess file.

1
2
3
4
5
6
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Replace yourblog.com with your blog address.
It block all comments from direct access to wp-comments-post.php.

3. Add this to the .htaccess file also.
Block all spammer IP’s one by one:

1
2
3
4
5
6
7
<Limit GET POST>
order allow,deny
deny from 78.133.218.68
deny from 219.159.67.187
deny from 77.41.123.182
allow from all
</Limit>

Just add more IP to this list.

Popularity: 18% [?]

Anti link/email spam script

1
2
3
4
5
6
<script type='text/javascript'>
   function nerf_email(){
      return 'offi'.replace(/i/, 'ice') + '@' + 'point'.replace(/t/, 't47.com');
   }
   document.write(nerf_email());
</script>

The above script will show: office @ point47.com

Popularity: 10% [?]