dinsdag 24 juli 2012

Creating a popup-bar in Wordpress using jQuery


This is how I made a non-intrusive pop-up-bar with jQuery that I used in Wordpress to notify users when they logged in.

First we should make sure that to load jQuery in a proper way. A common mistake here is to add it hardcoded in the header.php like this:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

The above line will load the jQuery library on all our pages. We do not want that The dashboard pages could have their own libraries that might come into conflict with our jQuery library. The correct way to solve this in Wordpress is to add:

// Load the google API jQuery in.
function load_google_jquery() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' );
    wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts' , 'load_google_jquery' );

To your functions.php file. This will make sure your jQuery library is only loaded on the user pages it was originally intended for.

Building our actual popup-bar. In the <head> we will place our CSS with an if statement to check if we have a 'popup_message' to display.

<?php if ( $popup_message = $_GET['popup_message'] ) : ?> 
  
       <style type="text/css">
        #popup-message {
            display:none;
            text-align:center;
            background-color:#ccccff;
            color:#5c518d;
            font-weight:bold;
            font-size:20px;
        }
        </style>
<?php endif; // END CSS popup message ?>   

We are putting the html for our popup message in our <body> tag right above our other html code containers. Again we check if an actual '$popup_message' exists to begin with. Otherwise this code is not generated. The /*

<?php if ( isset( $popup_message ) ) : // popup ?>
       <script type="text/javascript">
            /* <![CDATA[ */
            $(document).ready(function() {
                // DOM loaded & ready              
                $('#popup-melding').slideDown('slow', function(){ });            
            });
            /* ]]> */
          </script>
        <div id="popup-message">
           <span><?php echo $popup_message; ?></span>
        </div>
       
<?php endif; //END non-intrusive popup message  ?>

A possible use this popup-bar is to notify our user he just logged in after we redirected him back to the home page.
wp_redirect( home_url() . "?popup_message=". urlencode( __( "You are succesfully logged in." ) ) );
exit;

If you’d like to redirect the user to the same page you could use $_SERVER['HTTP_REFERER'] variable to find the URL of the original redirecting page. The __() function is handy to later automate translation of your theme. It is worth reading about internationalisation in wordpress.

zaterdag 5 november 2011

Changing permissions for your files.

I'm messing around with my Ubuntu server once again. I'm trying to get Wakaba running. Wakaba has a lot of Perl scripts that need to the permissions to be set at 755. Here's how you do that.
$ ls |grep .pl > setpermis.txt
$ sudo chmod 755 $(>setpermis.txt)
First we put all the filenames of the files that we'd like to set their permissions into a file named 'setpermis.txt'. And after that we ask chmod to use that file to set all the permissions.

donderdag 9 juni 2011

LowerCase your links with JQuery

A friend recently asked me and some other friends in a chatroom to come up with a way to set href attribute values of all the links to lower-case. Don't really know why he needed it exactly but anyway, here is the solution I came up with.

Put a JavaScript on the webpage with this code
$(document).ready(function(){
//read in the document, this is important

$("a").each(function(index){
//now for each link, take the href make it //lowercase and put it back
$(this).attr('href', ($(this).attr('href').toLowerCase()));


});

});
The big downside here is that it depends on JQuery, you'll have to import a JQuery on that page to. So while this is a really quick fix, this took me like 5 minutes to come up with type in and put on-line, importing the whole JQuery library for this lousy toLowerCase() function isn't really that elegant.

In the end, it'll probably all be done by some Perl script that goes through all the pages and fixes all the html all at once.

donderdag 12 mei 2011

Shows the cpu type:
$ uname -m
Show cpu information:
$ cat /proc/cpuinfo

zondag 6 maart 2011

sFTP and some usefull commands regarding navigation

sFTP stands for secure file transfer protocol. If you are using openSSH you already have sFTP and you can use it in the same port as you are using SSH.

the command:$ ls is handy to determine what is in your current directory. To make it human readable however you might want to use $ ls -h. Lets add a little more detail $ ls -lh and to spice it up even a little more we would like to see our 'hidden' files $ ls -lha. Hidden files are file names that start with '.' (example '.bash_history').

And as we remember from the first lesson, directories are files to[1]. You can also hide directories with this.

something else I used a lot before but I just now fully realised how it actually worked it cat. cat is used to print a text to the prompt this is very useful if you'd like to see some info file like $ cat /proc/cpuinfo

[1]Directories are basically lists of files subdirectories and their location on the hard drive.

zaterdag 5 maart 2011

Working with Byobu

Byobu lets you have multiple virtual terminals which you can switch between. It also gives you some information about your pc like the current load, updates waiting to be installed, ram ect.
Byobu from Putty requires to have Terminal >Change sequence send by: >function keys: Set To VT100+. This will enable you to use F1, F2, F3 and F4. F5 to F6 won't work.
F2 to Create a new window
F3 got to prev window
F4 go to next window
'screen -r' reattach
<ctrl-A> then K → to kill a window

F5 Reload profile
F6 Detach from session
F7 Scrollbakc and search
F8 Rename a window
F9 Configuration
F12 Lock this terminal

Installing openSSH

Install openssh-server
sudo aptitude openssh-server
Okay installation was easy, now the configuration.
nano /etc/ssh/sshd_config
But before we do that we might want to take a backup of that.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.original
After editing the /etc/ssh/sshd_config file you'll have to restart the server to let the changes have an effect. sudo /etc/init.d/ssh restart

Our ISP blocks port 22 so we'll set that to port 5022 in the /etc/ssh/sshd_config. We forward router port 5022 TCP and setup a free dns from dyndns.org. We use the
sudo /etc/init.d/ssh restart
and there we go. SSH is set-up.