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}
Posted on 13th Apr 2008 in : Techno Babble
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 ![]()
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 |
¥
Posted on 23rd Mar 2008 in : Techno Babble
Considering the number of times I've had to re-install ubuntu recently I should be a bloody expert! .... I've learnt not to play with X .... he gets pissed off real easily
..... Saying that, and with shedloads of help from Afwas, I've managed to get it installed with the majority of the software that I need to be able to play on the web, although I was devastated when I couldn't install IE6,7,8beta.....urm, well any IE version really...... the good news is, it would appear that my pc really CAN move files around without having the unsafest pile of crap since ......urm ........ sliced bread? .... is sliced bread unsafe? ..... I suppose you could always cut yourself with the knife while slicing it?
Anyway, I've mostly managed to install all the shit I need on a day to day basis ...... but I might need to reinstall, so this is just to remind me of stuff ![]()
So, now that all y'all think I'm a bloody genius .... which I am of course
...... I should point out that even my dad can run linux, and he's like "really old" and shit. I've still got a fair few things that I'm missing ... like my second screen working, and a decent ssh client that can hold multiple sessions in tabs .... and I must setup all my email accounts, although the lack of spam whilst they're not setup is damn attractive ... ohhh and I must change the desktop background, the swirly modern art brown thing really isn't to my tastes.
Stupid bloody question really, of course it hasn't improved, I've spent the best part of a couple of days just trying to avoid another re-install ..... it's all X's fault .... so I've done bugger all work! ...... mind you, it IS the weekend so maybe I shouldn't feel ...... urm ..... you know, that feeling you get when yer meant to be doing stuff but instead you just piss off an play? ... anyway, I'm not feeling that.
/me wanders off to find a yen sign that I can copy+paste cos I haven't worked out a way to type "¥" from the keyboard yet :S
¥
Posted on 20th Mar 2008 in : Techno Babble, Skins, Hacks, Plugins & Widgets
On the grounds that it's often easier to show something than try explaining it .....go visit the blogrum. Before you ask, no it's not ready for release yet, I need to sort out some permissions stuff to do with comments and tidy up the code and css ..... cos it's a tad messy in there ..... and then it's gonna take a mammoth post to explain what it can do, how, where, why and when. The good news is that it's pretty much just a trick skin with a couple of plugins thrown in, although I have a few more plugins in the works to make it work even more like a forum.
Registration is open, so if you want to have a play then feel free, although guest users can comment in the chatter blogrum so if all you want to do is spam me then there's no need to even register ![]()
¥
Posted on 24th Feb 2008 in : Techno Babble
I've been a smidge quiet lately because we're in the middle of re-skinning an old OS-Commerce store. As always we started by creating a shiny new dev sub-domain for it to live on so we don't break the live site ..... problem number 1, OS-Commerce requires register globals to be enabled before it can run .... wtf? Not a chance that's going to happen on our server, not even a dev site! .... so, joy of joys we now need to find another e-commerce solution as well as skin it!
After wandering around the demo areas for a few other e-commerce solutions and listening to suggestions from other people we eventually ended up picking Magento Commerce ..... cool, decision made, time to go to work.
So, I got handed this shiny new software and a picture of the proposed skin with "let me know when you've sorted all the code out" ... and into the deep end I dived ....... I wish like hell I hadn't ... I have NEVER seen so many files required for a skin in all my life!! ..... seriously, I didn't even bother to count them, mainly because I have trouble with 3 digit numbers, but also because I get bored easily .... but, how hard could it be right? ....... wrong! As well as having more files than a blonde can count before either the boredom threshold or upper number cap is hit, they also have this reaaaaaally "flexible" approach to skinning where everything is controlled by XML files, and some other files.
This one controls the catalogue, note, this is just for viewing the catalogue, there's another for customers, and one for checkout .... ohhh and another for sales, and one for searching the catalogue ...... etc
Bash:
<?xml version="1.0"?> | |
<!−− | |
/** | |
* Magento | |
* | |
* NOTICE OF LICENSE | |
* | |
* This source file is subject to the Open Software License (OSL 3.0) | |
* that is bundled with this package in the file LICENSE.txt. | |
* It is also available through the world-wide-web at this URL: | |
* http://opensource.org/licenses/osl-3.0.php | |
* If you did not receive a copy of the license and are unable to | |
* obtain it through the world-wide-web, please send an email | |
* to license@magentocommerce.com so we can send you a copy immediately. | |
* | |
* @category design_default | |
* @package Mage | |
* @copyright Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com) | |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | |
*/ | |
| |
Supported layout update handles (action): | |
- catalog_product_gallery | |
- catalog_product_compare_index | |
| |
Supported layout update handles (special): | |
- default | |
- catalog_category_default | |
- catalog_category_layered | |
- catalog_product_view | |
| |
−−> | |
<layout version="0.1.0"> | |
| |
<!−− | |
Default layout, loads most of the pages | |
−−> | |
| |
<default> | |
| |
<!−− Mage_Catalog −−> | |
<reference name="top.menu"> | |
<block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/> | |
</reference> | |
<reference name="right"> | |
<block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml"> | |
<action method="setImgSrc"><src>images/media/col_left_callout.jpg</src></action> | |
<action method="setImgAlt" translate="alt" module="catalog"><alt>Our customer service is available 24/7. Call us at (800) DEMO-NUMBER.</alt></action> | |
<action method="setLinkUrl"><url>checkout/cart</url></action> | |
</block> | |
</reference> | |
<reference name="right"> | |
<block type="core/template" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/> | |
<block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml"/> | |
</reference> | |
<reference name="footer_links"> | |
<action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map"><label>Site Map</label><url helper="catalog/map/getCategoryUrl" /><title>Site Map</title><prepare>true</prepare></action> | |
</reference> | |
| |
</default> | |
| |
| |
<!−− | |
Category default layout | |
−−> | |
| |
<catalog_category_default> | |
<reference name="left"> | |
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml"> | |
<block type="catalog/product_list" name="product_list"></block> | |
</block> | |
</reference> | |
</catalog_category_default> | |
| |
<!−− | |
Category layered navigation layout | |
−−> | |
| |
<catalog_category_layered> | |
<reference name="left"> | |
<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml"> | |
<block type="catalog/product_list" name="product_list"></block> | |
</block> | |
</reference> | |
</catalog_category_layered> | |
| |
<!−− | |
Compare products page | |
−−> | |
| |
<catalog_product_compare_index> | |
<!−− Mage_Catalog −−> | |
<reference name="root"> | |
<action method="setTemplate"><template>page/one-column.phtml</template></action> | |
</reference> | |
<reference name="head"> | |
<action method="addJs"><script>scriptaculous/scriptaculous.js</script></action> | |
<action method="addJs"><script>varien/product.js</script></action> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/product_compare_list" name="catalog.compare.list" template="catalog/product/compare/list.phtml"/> | |
</reference> | |
</catalog_product_compare_index> | |
| |
<customer_account_index> | |
| |
<reference name="right"> | |
<action method="unsetChild"><name>catalog_compare_sidebar</name></action> | |
</reference> | |
</customer_account_index> | |
| |
<!−− | |
Product view | |
−−> | |
| |
<catalog_product_view> | |
<!−− Mage_Catalog −−> | |
<reference name="root"> | |
<action method="setTemplate"><template>page/2columns-right.phtml</template></action> | |
</reference> | |
<reference name="head"> | |
<action method="addJs"><script>varien/product.js</script></action> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml"> | |
<block type="catalog/product_view_super_config" name="product.info.config" as="super_config" template="catalog/product/view/super/config.phtml"/> | |
<block type="catalog/product_view_super_group" name="product.info.group" as="super_group" template="catalog/product/view/super/group.phtml"/> | |
<block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml"/> | |
<block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" /> | |
</block> | |
</reference> | |
<reference name="right"> | |
<block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/> | |
</reference> | |
| |
</catalog_product_view> | |
<!−− | |
Product send to friend | |
−−> | |
<catalog_product_send> | |
<!−− Mage_Catalog −−> | |
<reference name="root"> | |
<action method="setTemplate"><template>page/2columns-right.phtml</template></action> | |
</reference> | |
<reference name="head"> | |
<action method="addJs"><script>varien/product.js</script></action> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/product_send" name="product.send" template="catalog/product/send.phtml"> | |
</block> | |
</reference> | |
</catalog_product_send> | |
| |
<!−− | |
Product additional images gallery popup | |
−−> | |
| |
<catalog_product_gallery> | |
<!−− Mage_Catalog −−> | |
<reference name="root"> | |
<action method="setTemplate"><template>page/one-column.phtml</template></action> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/product_gallery" name="catalog_product_gallery" template="catalog/product/gallery.phtml"/> | |
</reference> | |
</catalog_product_gallery> | |
| |
<!−− | |
Site Map block | |
−−> | |
<catalog_seo_sitemap_category> | |
<reference name="root"> | |
<action method="setTemplate"><template>page/1column.phtml</template></action> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/seo_sitemap_container" name="seo.container" template="catalog/seo/sitemap/container.phtml"/> | |
</reference> | |
</catalog_seo_sitemap_category> | |
<catalog_seo_sitemap_product> | |
<reference name="root"> | |
<action method="setTemplate"><template>page/1column.phtml</template></action> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/seo_sitemap_container" name="seo.container" template="catalog/seo/sitemap/container.phtml"/> | |
</reference> | |
</catalog_seo_sitemap_product> | |
<!−− | |
Catalog search terms block | |
−−> | |
<catalog_seo_searchterm_popular> | |
<reference name="root"> | |
<action method="setTemplate"><template>page/1column.phtml</template></action> | |
</reference> | |
<reference name="content"> | |
<block type="catalog/seo_searchterm" name="seo.searchterm" template="catalog/seo/searchterm.phtml"/> | |
</reference> | |
</catalog_seo_searchterm_popular> | |
| |
</layout> |
Ok, I know I'm blonde and it doesn't take a lot to confuse my poor cell, but bloody hell I normally at least have a chance of grasping stuff within a reasonable time frame ........ seven hours later my wall is starting to take on the shape of my forehead but at least I finally managed to move the sidebar from the right side to the left side .... I'm a genius
....... faaaaaaaaaantastic, now all I need to be able to do is move every component to the location of my choice and code up all the extra modules that we require for the proposed template .... suddenly Everest looks like a small rock.
Several days later and I'm a smidge more au fait, or whatever that flash french saying is for "got slightly to grips with", with their templating system, and I've managed to satisfy myself that I can at least achieve our requirements within my lifetime, and I've begun making all the changes that we need.
It didn't take me long to get bored with all the files and folders required for a bloody skin, so instead of altering their files I decided to make a single folder for all my changed files to live in. Compared to their god knows how many, I'm currently floating around the half-dozen mark, mind you, there's a long way to go yet but I should hopefully keep the total to way less than half of theirs, and the framework of the skin is finally coming together ..... which will cheer Dexter up, as he's raring to go with the new shop as soon as possible ![]()
Did I mention I think the skinning system is over complicated? Seriously over complicated. I really hope that the developers of the software do a 100% rethink about their skinning system. Not only is it FAR to complicated for the average joe to contemplate playing with, it *appears* to put a fair load on a server whilst it decodes all the files, there's several posts on their forums about it, I can't really tell as I'm playing with very little test data, but that'll change soon as we start adding more products for a dry run.
Despite all of the above I actually would, as long as you don't have a huge store and either have a masochistic outlook on life or you have enough money to pay somebody to skin it for you. The main things that impressed me about the software was that the default template has an XHTML Strict doc type and the admin area was better than all the others that I'd seen by a long way. Remeber that it's still in beta though, and not really recommended for a live site ![]()
Note : If you're even remotely considering asking us to do a Magento skin for you then our prices start at £2,000 .... or £20 a file, whichever is greater ![]()
¥
Posted on 3rd Jan 2008 in : Plugins & Widgets
After being nudged by Danny about an RSS reader I started a fair while back and never finished, mainly because I didn't have a use for it, I felt obliged to create an RSS Reader widget .... mainly to stop him nagging my arse off
. Fortunately I'd come across an RSS Reader class a tad ago called SimplePie which would make the task a LOT easier, although it took a bit of pissing about to get it working the way I wanted. If you want to skip all the usual babble you can download the current version of the plugin here ( AM RSS Reader ), it does come with some system requirements which can be found on SimplePies System requirements page.
Installing is the same as every other widget, download the file, unzip it, upload the am_rss_reader_plugin folder to your blogs folder. Meander over to admin > global settings > plugin install > install new plugin ( damn that's a hell of a path ), click the install link for the plugin. Now wander over to your skins widgets and click add new widget for whatever skin container you want it in. On the widgets settings page choose a custom title for the feed, the maximum number of items you want to display and slap in the feeds url ( note to self : validate the feed url ). If you feel brave you can play with the items html ( see the readme for replacement values ), the chances are that you won't need to change it. Once you have all your settings done, hit save. That's it, you now have the feed in your skin wherever your container is.
The short answer is "quite a bit actually", the long answer is that it has a bunch of settings which it utilises in a magic ceremony that results in the RSS feed being spat out, wherever you placed the widget, in a totally customised way. This magic is carried out by unemployed elves who are desperate for work now that christmas is over. So not only will you have a really cool widget, you'll also be helping save the elves, now is that cool or what? Of course this means that the widget stops working around the beginning of december for a few weeks but such is life
Rather than repeat all of the settings, what they do, why and how I actually made a readme ( yeah I know, me write a readme, whatever is the world coming to? )
Due to the fact that I dislike having folder permissions set to "let the world rape me", which is unavoidable on some shared hosting, I decided not to use SimplePies caching system, which uses files, and instead the results are cached in the database. You can set the cache duration to absolutely anything you like, the default is 60 minutes. At the moment I've only enabled the simplest of the SimplePies abilities, ( ie/ you can get post author, content, url, date, title ), but if anybody really wants some of the other functionality that's available with the class then just holler, it's not that difficult to incorporate them.
As always this is a pre-release version, although it's been tested in most 2.x flavours, so if it breaks let me know .... if it doesn't break then it'll be released as soon as I come up with a post that doesn't involve elves ![]()
¥
*edit* You can now see the widget in action on my Feeds I read page.
Posted on 20th Dec 2007 in : Plugins & Widgets
Now that the evocore has stabilised a tad we decided that it was time we brought AstonishMe out of the stone age and upgraded it to 2.x. which means that we have quite a bit of custom work to redo. At the same time we decided to convert a skin we'd been playing with a while ago. In for a penny in for a pound and all that. One of the main problems we had was with the core bloglist widget, we needed it to do more than what it currently does .... so we decided to recode it and make it a tad more *flexible* and then we threw in some new bits.
The main problems we needed to overcome were :
This is basically a direct replacement for the current widget except it comes with a fair few new settings. The main ones are the "Current Blog" and "Other Blog" settings which allow you to enter the html to use, either in the settings or from your skin, both settings have some replacement values to allow further customisation :
To achieve the rest we decided it was time to abuse the blogs *notes* field .... mainly because we don't personally use it and it's one of the few fields that you don't end up fighting later. Ordering of the blogs is done by sorting them on the blogs notes field, so depending on what text you have in there depends on where they appear in your blog list ( ours start with "blogorder:1" "blogorder:2" etc ). If you happen to be one of the rare people that actually uses the notes field then just ignore the first line when yer reading them. Since we were abusing the notes field anyway we decided to abuse it a bit more. When the blog list is being displayed the plugin looks for the text "bloglist:hide" anywhere in the notes field. If it finds it then it skips ahead to the next blog in the list.
Until we finish recoding AstonishMe you can find the plugin here. Unzip it, upload it, install it, play with settings. As well as the other settings we threw a few in for Afwas although the rest of you may or may not find them useful. Once we have AstonishMe recoded you'll be able to find all our plugins on one easy page. As always, remember that this is a pre-release version of the plugin, so if you find any bugs or quirks let me know and we'll work at ironing them out.
¥
Page archived : 6th Mar 2010