Archived : Techno Babble

This is the archived version of my b2evolution code blog.
If you require any help regarding b2evolution then
visit it's support forums

You can find my current blogs here
Code : {@link : WafflesOn}
Personal : {@link : InnerVisions}

End of an era?

Posted on 2nd Oct 2009 in : Techno Babble

Or stepping forwards?

I *think* I've come to the conclusion that InnerVisions && WafflesOn won't be moving beyond the 2.x.x series of b2evolution. There's way to much shit in the 3.x+ series that I *really* don't want. With this in mind I'm going to start shutting down my code blog, all comments will be locked and any questions will be redirected to the evo forums. Eventually I'll archive it off to a "static" site ... not that hard really, it lives on it's own domain.

I'll continue to be active in the forums and will, obviously, support all our current plugins for every version they've been released for, and I'll (probably) bring them all up to the 3.x.eventually_stable series, if there's enough demand. Eventually I'll move them all into svn so other people are free to take them over.

What about BOPIT?

BOPIT has already been moved to it's own sub domain, running it's own files/database, and other people have admin/ftp access, so I'm pretty sure it's going to continue ... I'll make sure it does huh? ... with a tad of luck it'll eventually be replaced by core functionality ... until then I'll keep it alive and kicking ;)

The future?

For now it'll be based on 2.x.x, and I'll hack the core files to suit my/our clients needs. After that? I'm really not sure, and that's not a teaser :p

Was it fun?

Yes. b2evo taught me many things, not least of which was php && mysql :D For that alone I'm forever indebted ;)

¥

Custom Admin Pages

Posted on 13th Jul 2009 in : Techno Babble

Add your tabs today!

Unlike most of our other plugins this one does bugger all by itself, it's only reason for existence is to be used by other plugins and at the moment the only plugin that uses it is one that we're currently developing. So, what does it do? What this plugin does is allow your own plugins to easily add their own custom tabs to the admin area. Now, before any of yah point out that plugins already have the ability to easily add their own tab to the tools tab, I know, but this plugin allows you to add tabs to any of the evo tab pages ;)

How it works

There's a couple of rules that your plugin has to play by to make all this work. The first and most obvious one is that it needs to declare this plugin as a dependency to ensure that it's always installed when you need it. You tell evo about dependencies by adding the following code snippet to your plugin.

PHP ( _your_plugin.plugin.php ) :

/**
     * This plugin requires the AM Admin Pages plugin
     *
     * @return array dependencies
     */
    function GetDependencies()
    {
        return array'requires' => array(
            'plugins' => arrayarray'am_adminpages_plugin') ), // requires at least version 1 of the plugin
            ));
    }

Next you need to create a shiny new method in your plugin called GetAdminTabs() which should return an array of all tabs that you wish to add your tabs to, and the tabs that you wish to add ... it's probably simpler to just show you some code ;)

PHP ( _your_plugin.plugin.php ) :

/**
     * Add our tabs to the admin tabs
     *
     * @param array $params
     *    string 'main_tab' : This is the main b2evo tab that is currently being displayed
     * @return array : our tabs
     */
    function GetAdminTabs($params)
    {
        global $admin_url$blog$current_User$user_ID;
        global $AdminUI;
 
        $admin_tabs false;
 
        switch( $params['main_tab'] )
        {
            case 'dashboard' :
            case 'blog_settings' :
                global $blog;
                $bCache get_Cache'BlogCache' );
                if( $blog && $sBlog $bCache->get_by_ID($blog ) )
                {
                    $shop_ID $sBlog->owner_user_ID;
                }
                break;
 
            case 'users' :
                $shop_ID param'user_ID''integer' );
                break;
        }
 
        if( empty$shop_ID ) )
        {
            $shop_ID 0;
        }
 
        switch( $params['main_tab'] )
        {
/* start snippet */
            case 'blog_settings' :
                if( $this->ShopSettings->get('enabled'$shop_ID ) || $current_User->check_perm('blog_properties''edit'false$blog ) )
                {
                    $admin_tabs array(
                        'blogs' => array(
                            'amsc_settings' => array(
                                'text' => $this->T_('Shop Settings' ),
                                'href' => url_add_param$admin_url'ctrl=coll_settings&blog='.$blog.'&amat_tab=amsc_settings' ),
                            ),
                        ),
                    );
                }
                break;
/* end snippet */
        }
        return $admin_tabs;
    }

The important thing to note in that code is the bit of the href which reads 'amat_tab=amsc_settings', this is the parameter that's used to tell our plugin which one of your custom pages you want to display, and it must have a corresponding function with the following naming convention function AdminTabPayload_your_unique_tab_value(). In the above example the corresponding function would be called AdminTabPayload_amsc_settings(), the following is our code for that function :

PHP ( Our Plugin ) :

/**
     * Display our settings
     *
     * @param array $params
     *    string 'main_tab' : This is the main b2evo tab that is currently being displayed
     */
    function AdminTabPayload_amsc_settings($params)
    {
        global $AdminUI;
 
        switch( $ctrl param('ctrl''string' ) )
        {
            case 'dashboard' :
            case 'coll_settings' :
                global $blog;
                $bCache get_Cache'BlogCache' );
                if( $blog && $sBlog $bCache->get_by_ID($blog ) )
                {
                    $shop_ID $sBlog->owner_user_ID;
                }
                break;
 
            case 'users' :
                $shop_ID param'user_ID''integer' );
                break;
        }
 
        if( empty$shop_ID ) )
        {
            $shop_ID 0;
        }
 
        $edited_settings $this->ShopSettings;
        $edited_settings->ID $shop_ID;
        global $Blog;
        amsc_load_disp'shopsettings' );
    }

The final thing you need to do is to inform evo of your shiny new abilities :

PHP ( your_plugin.plugin.php ) :

/**
   * List of events that we handle
   *
   * @return array : events
   */
    function GetExtraEvents()
    {
        return array(
            'GetAdminTabs' => 'Adds all our required tabs',
            'AdminTabPayload_amsc_settings' => 'Displays our settings',
            'AdminTabPayload_amsc_info' => 'Displays our info',
            'AdminTabPayload_amsc_customers' => 'Displays our customers',
            'AdminTabPayload_amsc_invoices' => 'Displays our invoices',
        );
    }

To make life a tad easier I've also coded a demo plugin that uses this plugin so you can (hopefully) see how it all works.

Anyway, enough blather from me, you can download the plugin here am_adminpages_plugin.zip and the demo plugin from here am_adminpagesdemo_plugin.zip
¥

E-commerce plugin?

Posted on 6th Jun 2009 in : Techno Babble

Where the hell do you start?

I've recently found myself in the position where a client has offered to drop ship for me, partly to give me greater freedom of layout/content/style than they'd be happy to risk on their own domain and partly to see if I could come up with some form of drop shipping "template" that could then be rolled out to a wider audience ... either way they're to cheap to pay me the development hours ;) ... So, now I have a conundrum, do I attempt to bend an existing shopping cart to work ( and look ) the way I want it, or do I try and bend b2evo into being an e-commerce solution?

Each has it's own advantages, using off the shelf e-commerce software means that it already does all the tedious stuff required for a shopping cart to function, but I'd spend god knows how many man hours learning the system, and especially the code, before I could begin to use it for a drop shipping site. On the other hand, I'm not to shabby with the evo code base so I'd be able to crack on and add all the custom stuff required to make this all work ... within my lifetime. The downside of using b2evo is that it's not exactly geared up to be an e-commerce solution out of the box.

Decisions, decisions

I guess it all comes down to "which is the better use of my time?", currently my thoughts are "use an e-commerce package and face the 'now make it available to a wider audience' bridge when I get there", by then the chances are that I'd have a much deeper knowledge of the chosen packages code base and in the meantime I could make a few quid ... but ... there's always a "but" huh? ... *if* I went the evo route then I'd save myself a load of learning and, if I needed to, I could change the core in cvs to add any hooks 'n' stuff that would make my life easier long term.

So ... hands up if you think I should go the evo route

¥

Do you captcha your target audience?

Posted on 16th Jun 2008 in : Techno Babble

Seeing is believing

In the past I've ranted about "webmasters" and their total failure when it comes to designing websites that are accessible to everyone on the web, and Scott and myself have had many a conversation on the same subject, especially that favourite of "webmasters" called CAPTCHA's. Not only are they 100% pointless because they can be easily broken but they require that humans jump through hoops to prove that they are a human and are impossible for people with certain conditions to solve .... such as dyslexics :

Ask Oxford wrote :

dyslexia

/disleksia/

noun a disorder involving difficulty in learning to read or interpret words, letters, and other symbols.
— DERIVATIVES dyslexic adjective & noun.
— ORIGIN from Greek lexis "speech" ( apparently by confusion of Greek legein "to speak" and Latin legere "to read" ).

Why pick Dyslexics?

I single out Dyslexics in particular because I happened to be chatting with Tilqi on IRC about accessibility and the mentality of most "webmasters", the edited version of the conversation went a little like this :

<tilqi> i insist on the impossibility of an absolute globalization / standarization or whatever you call it
<yabba_hh> whilst people think that, you remain correct
<tilqi> when so much obstacle about it
<yabba_hh> the obstacles are 100% man made ;)
<tilqi> i agree the need of it, but like many other things it is both vital and impossible
<tilqi> and you are not very comprimising today (:
<yabba_hh> lol, I'm not compromising on any day when this is the subject, I believe in it passionately ;)
<tilqi> yea but it's like 'world peace' , lol it even sounds funny anymore.. you know it must be established but you can not and never will
<yabba_hh> but you know that it is the right thing ;)
<yabba_hh> accessibility is the same "right thing", and is far more achievable ;)
<yabba_hh> it's only getting "more impossible" because current "webmasters" are making it that way ;)
<tilqi> i mean may be you can do it confiscating all the computers and re distribute and 'locked' computers with firefox installed :P
<yabba_hh> lol, you need to change the mentality of the coders, not the capabilities of computers ;)
<yabba_hh> I have zero problem with using flash / js ... but things *must* work without both
<tilqi> yea but they mostly *dont*
<tilqi> sector leader websites
<yabba_hh> then that's a failure of coding
<tilqi> all the portals in the world
<tilqi> and nba.com uefa.com etc etc
<tilqi> all use flash %90
<yabba_hh> the fact that they use all this stuff doesn't make it right, it's crap coding and excludes a large percentage of web users
<tilqi> there are countries below %90-99 literacy percantage still
<tilqi> and i am not talking about African countries ;)
<yabba_hh> pretty sure that UK is below 90% literacy
<yabba_hh> and that's without taking into account blind people and dyslexics

There must be Dyslexic sites surely?

That sparked off a google search, where I found this site beingdyslexic.co.uk, not that it was that hard to find, it was the top result in a google search for "dyslexic forum". They have a really cool quote on their home page :

beingdyslexic.co.uk wrote :

At Being Dyslexic with have a strong sense of community built upon the ethos that dyslexia is a gift.

Becuase dyslexia has a right brain dominance, this allows you to see every day activities from a slightly different angle. Dyslexics tend to be more creative and inspirational than your average joe.

Our brains are amazing. Try to learn stratagies that help you overcome any day-to-day problems, this will then allow you to explore the world in our unique but amazing way.

Now these people sound like they really know what they're talking about huh? Sooooo you'd expect that their forums, out of all of the forums in the world would be as dyslexic friendly as possible right? Well they pretty much are, low on images, high on text content and lots of other dyslexic members that are eager to help and share, assuming they can register of course. If you click that link and then agree to their terms and conditions and proceed to the next page, guess what you get to see? That's right a bloody CAPTCHA. Misunderstanding your target audience when you run most sites is bad enough, but whoever made the decision to implement a captcha on a dyslexics site should be put against a wall and shot for total stupidity :|

If you use captchas on your own site, whether they're targeted at visually impaired people or not, then I'd advise you put them in the bin where they belong, not only are they a complete waste of time they lock a lot of the web away from people who do not have the ability to complete them ... ohhh, and before anybody mutters anything about audio captchas, don't, there should be no hoops for humans to jump through just to be able to use the web, period.

¥

Opening the blogrums

Posted on 2nd Jun 2008 in : Techno Babble

It's like a forum, but it's a blog

Finally, I've mostly integrated the old blogrum code with InnerVisions .... I've even started a tutorial on how to add a blogrum to your own b2evolution blog .... don't get excited though, it's nowhere near finished and I'm not in any great rush ;). There's still a fair amount of work to do with it before it's anywhere near the end result I have in mind, and the skins a tad shagged in IE6, but I'll be re-skinning it as soon as I've got all the code working and testing, so either put up with it or switch to a browser that it does work in ;)

I've decided that I can't be arsed importing all the current blogrums posts/comments/users, it's more hassle than it's worth so I'll just leave the current version where it is and shut down the ability to post/comment there. I also haven't redone the ability to create a new post from the frontend, I'll work on that when I get more free time. For the moment it's only linked in my drop down menus as I'd need to redo the header graphic to add it to the menu buttons, and I'm liable to go for a whole new skin if I have to go to that effort anyway ;)

Anyway, feel free to have a play, and let me know if you find any bugs/quirks ;)

¥

Bourne to Bash

Posted on 13th Apr 2008 in : Techno Babble

Not all shells are on a beach

I decided to have a play with Bash this weekend as I'd been asked if I could come up with a backup process that was simple enough for the average joe blogs to configure to suit their needs. The script needed to be able to do daily/weekly/monthly backups of selected databases and files/folders and store them on a different server, as a nice touch it also emails the user to let them know that the backup had been done and which databases/files/folders had been included. As well as doing the backups it also keeps the latest 3 in a grandfather/father/son rotation which gives the user 9 potential backups which they can recover from.

As I haven't had a shedload of experience in using bash I spent a fair amount of time hunting round the web looking for clues as to how to do some bits and bats so I thought I'd share some snippets as some of them took a fair amount of searching for/solving and you never know, it may just help someone else in the future ..... probably me :p

Bash:

#!/usr/bin/env bash
#
# Read a named file into a variable
#
 
# read "file_you_want" into $variable_name
contents=$(<foo.txt)
 
echo "${contents}"
 
#
# Read a variable file into a variable
#
 
# set $variable_name = "file_you_want"
my_file='/path/foo.txt'
 
# read file $variable_name into $variable_name
contents=$(<"${my_file}")
 
echo "${contents}"

Bash:

#!/usr/bin/env bash
#
# Convert windows line endings to linux line endings
#
 
# set $variable_name = "file_you_want_to_convert"
filename='/path/foo.txt'
 
# remove all \r and save the output to $variable_name.linux
tr -d '\r' < ${filename} > ${filename}.linux
 
# remove original file
rm ${filename} -f
 
# rename $variable_name.linux to $variable_name
mv ${filename}.linux ${filename}

Bash:

#!/usr/bin/env bash
#
# check if a process is already running
#
 
# name of the process to check for
# add [] around the first letter to stop the "grep process" from showing
check_process='[f]oo'
 
if ps aux | grep -q "${check_process}"
  then
    echo 'running'
  else
    echo 'not running'
fi

Bash:

#!/usr/bin/env bash
#
# switch between 2 directories
#
 
# switch to directory 1
cd /path/foo/
 
# show current directory
pwd
 
# switch to directory 2 and "remember" previous directory
pushd /path/bar/
 
# show current directory
pwd
 
# switch back to directory 1
popd
 
# show current directory
pwd
 
# alternative method
 
# switch to directory 1
cd /path/foo/
 
# show current directory
pwd
 
# switch to directory 2 and "remember" previous directory
pushd /path/bar/
 
# show current directory
pwd
 
# switch back to directory 1
pushd
 
# show current directory
pwd
 
# switch back to directory 2
pushd
 
# show current directory
pwd

Bash:

#!/usr/bin/env bash
#
# send an email using echo
#
 
echo 'your email content' | mail -s 'your email subject' email_1@domain.com email_2@domain.com
 
#
# send an email using a file as content
#
 
mail -s 'your email subject' email_1@domain.com email_2@domain.com < email_content.txt
 
#
# send an email using a variable file for content
#
 
# set $variable_name = "file_you_want_to_use_as_content"
email_body='/path/foo.txt'
 
mail -s 'your email subject' email_1@domain.com email_2@domain.com < ${email_body}
 
#
# send an email using a file and replace "%placeholders%" with variables
#
 
# set $variable_name = "file_you_want_to_use_as_content"
email_body='/path/foo.txt'
 
# set $variable_name = "replacement_value"
foo='bar'
 
# replace the placeholders and email the results
# replaces %placeholder% with $foo
sed -e "s!%placeholder%!${foo}!;" ${email_body}" | mail -s 'your email subject' email_1@domain.com email_2@domain.com

Bash:

#!/usr/bin/env bash
#
# find the directory your script lives in
#
 
foo= `dirname $0`
echo $foo

¥

Tags: bash, snippets
Page archived : 9th Nov 2009
 

X