The SVG converter is a web frontend to a jQuery Plugin, that allows you to include those line drawings on your webpage.
Single inheritance has often been the limitation for PHP. This means that a class can only inherit from one other class. Often classes share the same methods and it would be beneficial to allow reuse and prevent duplication.
In PHP 5.4 a new feature was added, known as Traits. A Trait is like a Mixin, allowing to use / mix classes into existing classes. This means code reduction and less duplication.
Example of a Trait
1 2 3 4 5 6 7 8 |
trait Sharable { public function share($item) { return 'share this item'; } } |
This trait can than be used in other classes:
1 2 3 4 5 6 7 8 9 10 11 |
class Post { use Sharable; } class Comment { use Sharable; } |
Both classes can now use the Shareable trait.
1 2 3 4 5 |
$post = new Post; echo $post->share(''); // 'share this item' $comment = new Comment; echo $comment->share(''); // 'share this item' |
The benefit is less code duplication. The drawback is, that not all used methods are visible within the source-code of the class. So before moving a method to a trait, make sure that you will actually reuse it ;)
I have been restructuring huge amounts of code over the past months and traits are helping to keep things far more organized.
In combination with __autoload its a real nice way to cleanup your code toolbox.
Happy coding
Alex
When projects are getting bigger, its always nice to split things up and prepare parts of your code for general reuse.
PHP Traits (PHP 5.4+) are a nice way to do this. Adding multiple Traits or classes, requires you to make sure all are being included.
Here is a nice way to register both with the __autoload function
1 2 3 4 5 6 7 8 9 10 11 12 13 |
spl_autoload_register(function($className) { $fileName = __DIR__.'/class/class.' . $className . '.php'; if (file_exists($fileName)) { include $fileName; } }); spl_autoload_register(function($traitName) { $fileName = __DIR__.'/trait/trait.' . $traitName . '.php'; if (file_exists($fileName)) { include $fileName; } }); |
Traits are loaded when you specify their use in a class.
1 2 3 |
class{ use traitOne, traitTwo; } |
Normally the functions.php in your CHILD theme is called before the PARENT functions.php. In some cases, you might like to alter functionality loaded through the PARENT theme in your CHILD theme, which is not possible without some changes.
From the WordPress Codex :”Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)”
For our new setup, I am using a base class in our PARENT theme to define all our defaults. Some of the CHILD themes need to overwrite or adjust functionality. This allows to have a pure foundation, than alter and extend as needed.
PARENT functions.php
is extending the TimberSite class in my case, as I am using Timber (TWIG for WordPress) for my themes
1 2 3 4 5 6 7 8 9 10 11 |
class cubicFusionBase extends TimberSite { function __construct(){ parent::__construct(); } } // If no CHILD theme is loading init the parent class if(CHILD_THEME_LOADED != 1){ new cubicFusionBase(); } |
CHILD functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Do not init the parent class define("CHILD_THEME_LOADED", 1); // Wait for theme setup to be finished add_action( 'after_setup_theme', function() { // Extend parent theme class class cubicFusionChild extends cubicFusionBase { function __construct() { // Call parent class constructor parent::__construct(); } /* Add or extend any other functionality here */ } // Init Child class new cubicFusionChild(); }, 42 ); |
Cheers
Alex
At portalZINE TV we produce Internet TV since 2008. “Das Magazin” is our flagship magazine format that started in 2010 and was broadcasted via satellite for over 3 years (Tec Time TV).
I have been working on a full integration of fullpage.js into Visual Composer for WordPress. This allows to easily build fullpage layouts, with different pages and full slide capabilities. Also added iScroller functionality, to allow overflow content to work nicely on certain pages. All of this is working with simple drag & drop :) and can be used by any unexperienced user.
I am currently cleaning up the addon, but I am not sure yet if I will offer it as a commercial addon or keep it for my internal projects only :)
Will post a video later this week.
Cheers
Alex
Currently reading up on the IMAP protocol, as one of my customers is using a server without IMAP support compiled :)
I will be using a simple INBOX check for failed email notifications (sockets are your best friend). That will allow me to set a flag for every new user account that is still unconfirmed and used a broken email address for their registration. These accounts can than be verified manually :)
Happy socket = happy customer.
Btw, here is a nice piece of code to quickly parse the email header in PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$parsed = array(); $blocks = preg_split('/\n\n/', $response['data']); $lines = array(); $matches = array(); foreach ($blocks as $i => $block) { $parsed[$i] = array(); $lines = preg_split('/\n(([\w.-]+)\: *((.*\n\s+.+)+|(.*(?:\n))|(.*))?)/', $block, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($lines as $line) { if(preg_match('/^\n?([\w.-]+)\: *((.*\n\s+.+)+|(.*(?:\n))|(.*))?$/', $line, $matches)) { $parsed[$i][$matches[1]] = preg_replace('/\n +/', ' ', trim($matches[2])); } } } |
Time to give all our network sites some fresh paint :)
Cheers
Alex
The PCTV Broadway HD-S2 is currently my favorite network sat receiver. It is tightly integrated into many of our network clients.
As the PCTV Broadway HD-S2 provides a nice and clean REST Api, I decided to start writing a small desktop client to access the streams and recordings (My main focus is Mac OSX / Linux for now). Sure, you can use VLC for that or just use the web interface, but I wanted something more customizable .
The Broadway PHP Api is working nicely and I am tempted to integrate the same functionality into the desktop client :)
Basic functionality working so far:
Cheers
Alex
“A widget for running scripts in the Today View in OS X Yosemite’s Notification Center”
Here a nice list of sample uses
Wiki
Reddit 1
Reddit 2
Example of colorized memory display
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
ps xmo rss=,pmem=,comm= | while read rss pmem comm; ((n++<5)); do size="$[rss/1024]"; short=$[4-${#size}]; size="(${size}M)"; i=0; while ((i++ < short)); do size=" $size"; done; pmem="${pmem%%.*}" if (($pmem >= 20)); then color=$'\e[31m'; elif (($pmem >= 10)); then color=$'\e[33m'; else color=$'\e[32m '; fi; echo "$color$pmem% $size $(basename "$comm")"$'\e[0m'""; done |