Recent Updates Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 10:01 am on April 13, 2015 Permalink | Reply  
    Categories: Announcements ( 7 ), Linux ( 101 )   

    LAMP Stack for Humans – now available on Amazon 

    Lampstack-SoftcoverMy book LAMP Stack for Humans is now available on Amazon, as paperback and for Kindle Devices!

    In this 284 page guide I’ll walk you through the process of turning an old laptop into an always-on server. You can use it to run web applications in the comfort of your own home or office – no “cloud” required.

    Together we will configure the entire server: you will learn how to install CentOS, Apache, PHP and MySQL (or MariaDB) and WordPress. I will show you how you can reach your server from other computers on the network and how to create regular backups.

    Perfect for the Linux newbie and those who want to get started with web applications without spending money “in the cloud” (in my opinion THE WORST expression for describing remote computers).

    If you’re an avid reader of this site and have always wished that some instructions would be presented in a more cohesive form rather than in snippets, then LAMP Stack for Humans is perfect for you.

    Grab your free sample today, or read the entire book for free via Kindle Unlimited!

     
    • Falkon 2:28 am on October 21, 2015 Permalink | Reply

      Hi Jay
      I have a question regarding WP adding a Landing page for an existing site, meaning to add a new page which only displays a big logo in the start and be able to make that logo a roleover logo, and then the click would navigate a user to the main ( index page) if you will. i am new to WP and PHP wise I am still learning so I would not know how to add an extra page as the index page and the first index page turns say into a home.html. How would you do that? I trying to learn PHP and WP to what I work with in HTML & CSS and front end designs.
      Beforehand allow me to thank you for you time, help and assistance,

      Best Regards
      Falkon

      • Jay Versluis 2:55 pm on October 21, 2015 Permalink | Reply

        Hi Falkon, that’s a VERY off-topic question for this post…

        WordPress does have a way to display a static page as front page, instead of the default blog posts. You can change it like this:

        • for the blog, create a new page with a title (no content is necessary)
        • head over to Settings – Reading
        • under Front Page Displays, select your pages
        • hit Save and refresh the front page

        As for the roll-over image: insert an image into your static front page, then link that image to wherever you want (you can do that with Add Media from the page creation dialogue).

        Hope this helps!

  • Jay Versluis 9:54 am on July 17, 2018 Permalink | Reply
    Tags: Audio   

    Categories: Mac OS X ( 36 )   

    How to transcode an AFIC file with macOS Finder 

    Yesterday I had to transcode some audio files recorded with Quicktime on macOS. Quicktime works great for that, but it only stores files in its native AIFC file format. That’s the Audio Interchange File Format, a format developed by Apple in 1988, storing audio data as uncompressed PCM data.

    Sadly though, AIFC is not commonly readable by many applications, and as such the data needs to be transcoded to be used successfully elsewhere. And Quicktime offers that option too, simply by choosing File – Export – Audio Only. This will create an MPEG 4 audio file with the M4A extension.

    While that file sounds fine, and its size is only a fraction of what the original AIFC file was, this transcoding process does not allow us to choose which compression algorithm to use upon export. As it turns out, Quicktime introduces a very good, albeit lossy compression when it exports files in this manner.

    I wondered if there was a way to extract uncompressed lossless data from the AIFC file, and how to do it. If Quicktime didn’t let me, perhaps there was another way, maybe using some kind of free software tool.

    I was glad to find out that I didn’t have to look far: my good friend the Finder has such an option built in! Thanks go to Jim Tanous for sharing his knowledge with us.

    All we have to do is open a Finder window, right-click the AIFC file in question, and select Encode Selected Files at the bottom of the context menu. We can even select multiple files and transcode them all at once.

    When we do that, a dialogue window comes up. This may take a moment or two, so don’t get nervous if your Mac doesn’t respond instantly to this request (like I did).

    Now we get options! We can pick  destination for our new files, and we even get the choice to delete the original AIFC file if we so desire (and if we’re confident enough about this workflow’s capabilities).

    The best option we get though is that we can pick how the file(s) are to be transcoded though. While we do not get these options during the Quicktime export process, which appears to use the “High Quality” setting (and probably the same tool under the hood), with Finder we can choose the Apple Lossless codec.

    From what I understand, all three options apply a lossy AAC compression in varying degrees, resulting in different file sizes, data rates and of course different levels of quality. The only one that stands out is the Apple Lossless setting, which creates a file still smaller than the AIFC file, but with lossless compression, in M4A format.

    The resulting M4A output is readable by a wide range of applications.

    Thanks, Finder! I didn’t know you did Audio Encoding so well 🙂

     
  • Jay Versluis 12:54 pm on July 12, 2018 Permalink | Reply
    Tags: EPUB, Kindle, MOBI   

    Categories: How To ( 35 ), WordPress ( 145 )   

    How to share ebooks with WordPress (EPUB and MOBI files) 

    If you’ve ever tried to upload an ebook in .MOBI or .EPUB format with the WordPress Media Uploader, you will have noticed an error message appear. Something along the lines of “Sorry, this file type is not permitted for security reasons”.

    The only way then appears to be to ZIP the file and share it. That’s not a great experience for mobile users, who would simply like to click on a file and open it in an application such as iBooks or Kindle.

    The solution to this puzzle lies in adding the required mime types to WordPress, so that these file types are allowed.

    Let me show you how to do it in this article.

    (More …)

     
  • Jay Versluis 9:26 am on May 25, 2018 Permalink | Reply  
    Categories: PHP ( 29 )   

    How to declare Classes in PHP 

    Since PHP 5 we can use object oriented features in PHP. This allows us to not only use functions and variables, but also write classes and create instances of them in our code.

    Here’s quick rundown on how to do it.

    Writing and instantiating a Class

    Creating classes is very similar to writing functions. Here’s an example of a class with one method and one variable:

    // creating a basic class with one method
    
    class Test {
      var $testValue = 47;
      function sampleFunction() {
      echo "Hello from the Sample Function!\n";
      }
    }

    Once declared, we can instantiate our class like this:

    // instantiating the class
    
    $myTest = new Test();

    Accessing variables and methods

    Now we can access any variables in our instance using the -> operator like this:

    // accessing a class variable
    
    echo $myTest->testValue;

    The same principle is true for calling methods in our instance.

    // calling a method
    
    $myTest->sampleFunction();

    Constructor Methods

    A method is nothing other than a function really, but when a function is part of a class, we call it method. I guess that’s done to differentiate it from a “classic” function that’s declared outside of a class.

    There’s a special method we can declare inside our classes called a constructor method. It works just like a regular method, with the only difference that the constructor is called automatically when the class is instantiated. This is useful if we want something to happen as soon as our class is used the first time.

    Constructors have a special name (__construct); here’s an example:

    // creating a class with a constructor method
    
      class Test {
        function __construct() {
          echo "Hello from the Test Constuctor!\n";
      }
    }

    Extending a Class

    Classes can inherit functionality from other classes. When we do that we create an exact duplicate of an existing class. This is useful if we want to change the behaviour of a class, for example by overwriting existing methods or values.

    Here’s how we can extend a class:

    // extending a class
    
    class MegaTest extends Test {
      function __construct() {
      parent::__construct();
      echo "And Hello again from the extended class constructor.\n";
      }
    }

    Overwriting methods and variables is as easy as simply re-declaring them using their original names. Extended classes can be extended again, but a class can only ever inherit from another single class.

    Notice the use of the parent:: keyword in our constructor method. When our extended class is instantiated, our constructor method is called. If our parent class also has a constructor method (which is optional), we must call this before doing anything else to make sure that any functionality that is setup is being kicked off.

    In essence, anything prefixed with the parent:: keyword will call the related function “one level up”.

    Now we can create an instance of our extended class as described above:

    // instantiate the extended class
    
    $myMegaTest = new MegaTest();
     
  • Jay Versluis 9:24 am on May 24, 2018 Permalink | Reply
    Tags:   

    Categories: Linux ( 101 ), Plesk ( 76 )   

    How to switch off emails from Anacron in Plesk Onyx 

    In 2011 I wrote an article about how to avoid emails from Dr. Web. In it I was discussing how to switch off these notifications, which are generated when the Dr. Web service updates itself.

    Here’s an example:

    /etc/cron.daily/drweb-update:
    
    Dr.Web update details:
    Update server: http://update.msk5.drweb.com/plesk/700/unix
    Update has begun at Fri May 18 03:53:47 2018
    Update has finished at Fri May 18 03:53:54 2018
    
    Following files have been updated:
     /var/drweb/bases/drwdaily.vdb
     /var/drweb/bases/drwtoday.vdb
     /var/drweb/bases/dwmtoday.vdb
     /var/drweb/bases/dwntoday.vdb
     /var/drweb/bases/dwrtoday.vdb
     /var/drweb/bases/timestamp
     /var/drweb/updates/timestamp

    Sadly, as of 2018, there is still no way to switch these emails off via a tick box from inside Plesk. It was relatively simple though to redirect the output to /dev/null in Linux, thereby avoiding yet another email in our already overflowing inbox.

    In the latest version of Plesk, the earlier approach is no longer working.

    Instead, we can tweak the Dr. Web configuration file at /etc/drweb/drweb32.ini. In the Updater section, find the following block of code:

    # CronSummary = {Boolean}
    # Enables output of update session log to stdout.
    CronSummary = yes

    Now change the CronSummary value to no and restart the Dr. Web service. On CentOS it’s called drwebd:

    systemctl restart drwebd

    This will ask Dr. Web to not send us an email when he updates himself. The great thing about this solution is that we can still get command line output if we want to run the service manually.

    However, if the service is updated in the future, those emails may re-appear because it’s likely that our configuration file may be overwritten. Only time will tell I guess!

     
  • Jay Versluis 9:46 am on May 23, 2018 Permalink | Reply
    Tags: ,   

    Categories: How To ( 35 )   

    Fan Maintenance on my Samsung NC10 

    My Samsung NC10 Netbook has been in constant operation since 2013, for 24 hours a day, 7 days a week. It’s doing a great job as our internal office server, purring along quietly running CentOS 6.

    When I put it in operation 5 years ago, I made sure no mechanical parts we being used anymore to avoid wear and tear: I’ve added an SSD, and once a day valuable data is backed up on a permanently mounted SD card.

    The only mechanical thing still in use is the internal fan. I knew the day would come on which the poor thing would either give up and need replacing, or at least require some maintenance to make it go a few extra miles. Well, that day has come at the beginning on this month, when I noticed a bit of rattling noise that started happening behind my big monitor. That’s where I keep the little guy.

    Turns out that the fan can be easily whipped back into shape with a drop of bicycle oil. It’s really easy to disassemble too – let me show you how I did it.

    (More …)

     
  • Jay Versluis 9:45 am on May 22, 2018 Permalink | Reply
    Tags: ,   

    Categories: Linux ( 101 )   

    How to host multiple websites with Apache 

    The Apache web server has a convenient feature called Name-based Virtual Hosting. This function allows us to have a single LAMP Stack server configured on one IP address, but serve a different set of files depending on which domain is being requested.

    This sounds more complicated than it is. Say we had example1.com and example2.com, both of which are to be separate websites, but both domains point to the same IP address. Apache’s Name-based Virtual hosting makes this possible. In fact, this feature forms the basis of 90% of this planet’s shared hosting business.

    Let’s see how to do this in CentOS 6 and 7. (More …)

     
  • Jay Versluis 8:51 am on May 20, 2018 Permalink | Reply
    Tags:   

    Categories: Themes ( 28 ), WordPress ( 145 )   

    How to increase the font size in Automattic's P2 Post Box 

    Front page posting is what the P2 theme is all about – but I personally find the default font size on the front page a bit too small. Perhaps it’s my raging tired eyes. In every child theme I write for P2, I usually increase this – both for immediate posting, as well as for text editing (which also happens inline on the front page).

    To do that, add the following to your style.css file:

    /* larger text for post box and editing */
      #postbox textarea #posttext, textarea.posttext {
      font-size: 1.3em !important;
    }

    This will address the font size for both inline editing as well as posting. I’ve chosen 1.3em because it integrates well into my other settings, but feel free to choose something larger or smaller (1.2em or 1.4em respectively). You can also choose a defined point size like 16px if you like.

    To also address the text box for default comments, we can add this:

    #respond textarea, .textedit textarea {
    	font-size: 1.3em !important;
    	color: #555;
    }
    

    By default the font colour is black, so #555 tweaks it to be the dark grey that the rest of the P2 text has.

    Happy hacking!

     
  • Jay Versluis 9:44 am on May 19, 2018 Permalink | Reply
    Tags:   

    Categories: PHP ( 29 )   

    How to update legacy constructor methods in PHP 7 

    When I was fiddling with my P2 Categories theme last week, debug mode generated several warnings when run in PHP 7.2.1. That’s because class methods are no longer allowed to have the same name as the class itself.

    This was allowed in PHP 5 and earlier, but from what I gather it’s no longer the way to do things. Back then such methods were used as constructors, or in other words, methods that would be run automatically when the class is instantiated.

    Let’s take an example from the P2 theme. Here’s the beginning of the P2 class as of version 1.5.8:

    class P2 {
    	// ...
    	function P2() {
                // ...
    

    This will work just fine in PHP 5, but will generate a warning in PHP 7 (even though the code will execute). To update this, all we need to do is change our function name to __construct (notice the two underscores at the beginning of the name):

    class P2 {
    	// ...
    	function __construct() {
                // ...
    

    Anything inside the __construct() function is executed as soon as an instance of the class is created.

    When updating legacy code, there is the risk that the previous function name is called during instantiation. Consider this:

    class P2_Post_List_Creator extends P2_List_Creator {
    	var $form_action_name = 'p2-post-task-list';
    
    	function P2_Post_List_Creator() {
    		parent::P2_List_Creator();
                    // ...
    

    Here a class extends another class and calls a constructor method of the parent class by name. If we had just patched the parent class with _construct(), the child class would throw an “undefined function” error.

    To avoid this we’ll also have to update any calls made to the original constructor method, like so:

    class P2_Post_List_Creator extends P2_List_Creator {
    	var $form_action_name = 'p2-post-task-list';
    
    	function P2_Post_List_Creator() {
    		parent::__construct();
                    // ...
    

    And that’s really all there’s to it.

     
  • Jay Versluis 9:52 am on May 18, 2018 Permalink | Reply
    Tags: , Releases   

    Categories: Themes ( 28 ), WordPress ( 145 )   

    P2 Categories – Version 1.6 released 

     

    Last week I found some time to update my fork of Automattic’s P2 theme, aptly titled P2 Categories. In addition to all the greatness of P2, it’s been adding front-page category posting since 2013 (and hasn’t seen an update since then either).

    Here’s what’s new in the latest version:

    • fixed the drop down menu, which was no longer working since Safari 10
    • rewrote the whole theme from scratch, based on P2 v1.5.8 (2016)
    • fixed a bug that would not show the correct number of posts in a category
    • added new p2-categories-functions.php file
    • updated a call to a deprecated WordPress function with wp_get_current_user()
    • fixed several PHP 7 deprecation warnings
    • updated class constructors to use __construct() methods
    • hunted down undocumented features and documented them
    • added a changelog file

    P2 is no longer maintained by Automattic, except for dire security patches. I’ve noticed several deprecation notices, both for WordPesss 4.9 as well as PHP 7.2.1 and fixed those as well.

    Get the latest version on GitHub

    You can download the latest version of the theme over on the official GitHub Repository. Feel free to examine the code, tinker with amendmends and share with everyone who wants to use P2 with categories:

    Why is this version not on WordPress?

    I had submitted previous versions of P2 Categories to the WordPress repos too, and you can still download version 1.5 there. However, since 2013 web standards have become more strict, and there’s no way my theme would pass modern tests the theme team are using for new submissions. Sadly I’m not a web developer and it’ll be very difficult for me to update aspects of the theme I don’t fully understand.

    Having said that, if you know how to pass modern web standard tests, feel free to send me a pull request on GitHub.

     
  • Jay Versluis 10:04 am on May 17, 2018 Permalink | Reply
    Tags:   

    Categories: Themes ( 28 ), WordPress ( 145 )   

    How to display categories in Automattic’s P2 Theme 

    By default, Automattic’s phenomenal P2 theme does not support posting into categories from the front page, it only supports tags. My fork of the theme called P2 Categories does that though and lets you conveniently select a category from a drop down menu right there on the front page.

    I wrote an update to it last week, and in so doing my article from 2013 came in handy that explains how to add this functionality to P2. Nothing much has changed in the source code, so it’s still relevant and accurate.

    What the above article did not explain however was how to show which category a post belongs to. And because it’s still fresh in my  memory how to do this, I thought I’d better write it down for next time (and anyone who’s interested in how to do it).

    (More …)

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel