Should WordPress developers use tempnam() PHP function?

Sometimes safemode happens and it’s a nightmare.

Warning: tempnam() [function.tempnam]: SAFE MODE Restriction in effect. The script whose uid is 10032 is not allowed to access /tmp owned by uid 0 in /var/www/vhosts/g.nl/httpdocs/wp-content/plugins/_inbound-now/classes/admin/class.download-management.php on line 217

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /var/www/vhosts/g.nl/httpdocs/wp-content/plugins/_inbound-now/classes/admin/class.download-management.php on line 225

Warning: fopen() [function.fopen]: Filename cannot be empty in /var/www/vhosts/g.nl/httpdocs/wp-content/plugins/_inbound-now/classes/admin/class.download-management.php on line 234

Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/vhosts/g.nl/httpdocs/wp-content/plugins/_inbound-now/classes/admin/class.download-management.php on line 235

Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/vhosts/g.nl/httpdocs/wp-content/plugins/_inbound-now/classes/admin/class.download-management.php on line 236

Warning: Unknown: open(/var/lib/php/session/sess_urvaf1vnrouu4n0cmc23ll2p03, O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

 

Image attribution, how can we protect it?

I want a way to hover over an image and show the image meta data. I want this to be everywhere so there is always attribution and a chance for deeper understanding of every image. That way even open domain images can show more information about their origin. Social shares and memes would become more interesting. Not sure how it would affect personal photos.

Space Weather

If you like attempting to understand weather patterns through accountable data then check out the Suspicious0bservers YouTube channel for daily space and macro weather reports

Official Website:
http://www.suspicious0bservers.org/

Testing! Ignore this below!:

Open Broadcast Software – Plugin Request – Show active window / follow cursor

I am working with Open Broadcast Software and working with three monitors. I would like the active window to display at all times. That way when I move to another window to read and click the browser the viewer will be able to see the screen I am looking at as well.

If you know of something that can do this let me know @atwellpub

My thoughts on Sharia circa June 2015

I have to ask myself do we opt for peace and let the middle east stabilize under Sharia law? It might be the only power that can do it. Fear based politics says if we do this they will prosper and become strong and lead to more intense bloodshed at a later pinnacle moment.

Sharia is policy itself right? And Sharia is a never ending war/peace machine aimed at uniting the world, under Sharia, eventually right? That is a zero sum game.

I think about us (Spiritual America) and think it’s our belief that divinity best comes from free will and free will is best served by liberty. We use laws as we must and often judge our own laws and punishments as harsh and change them to become more moderate. We even aspire to decriminalize personal choices that would result in being executed under Sharia. Do I need to go into example?

Although Sharia’s harsh punishments piss Americans off , sometimes I feel a good public whipping is the answer and get upset that we are so weak stomached. Banking crimes… corruption crimes… these are crimes where public whipping seem appropriate. Let’s stripe them and release them. I’m not keen on prolonged periods of psychological torture with the threat of homosexual rape always lingering around the corner…. not for anyone.

No… what really pisses Americans off are theocratic statutes of legislation… not just Sharia’s, but any. Americans don’t want theocracy to rule because theocracy is often presumptuous and rude. We acknowledge that there are competing religious factions out there that would love to have totalitarian rule… and we must ignore them and promote the liberty of personal decision. Do I need to go into further example?

Same sex couples can now marry and peace is on them. With this seemingly anti-theocratic statute they will receive the same legal dignities offered to opposite sex couples. Should traditionalist Christians harbor murderous indignation? No the Jesus in us surely is too good. So we go with the flow. We let our government address the dignity issues of the free world. It’s not a perfect system but there is plenty of breathing room.

Foreign policy is very tough right now. We want to protect those being brutalized and persecuted. We want to meddle. Are we hegemonic? Are we forced into the zero-sum game of liberty versus Sharia law? Somewhere in the mafia novel of humanity we still find old prides and old ideas that inspire us to not keep to ourselves, to go out on a limb and challenge what might not accept our right to be sovereign and unmolested.

Will the Muslim nations give up their liberty in exchange for solidarity under their religious statues?  Or will there be mighty leaders of the same spirit of America’s founding fathers that denounce the perfection of Sharia law for the culturing of the freest possible will with the most limited coercion?

I am thirsting for answers and solutions and hopes. I do not want to see Americans wake up to find themselves in a zero sum game eager to see the end. I want them to wake up and find their roots, and learn to turn the other cheek and wax mighty because of it.

Why I left Notepad++ and moved to PHPStorm

logo-0aa107f965425de0266a7cf172ca0af8 notepad++ phpstorm

I write mostly PHP, Javascript, & Bash. Most of the time I am developing WordPress plugins for Inbound Now. Here’s a journal entry for my love and grievances. Hopefully it will be picked up and used for good.

What I like about NotePad++

  • Extremely fast when loading.
  • Love the GUI
  • Love the functions list (needs improvement for JS files)
  • Their line bookmarking system is fast and easy to use.

What don’t like about NotePad++

  • No setting to trim trailing slashes on save. Forces user to setup a macro.
  • Their functions list needs improving for JavaScript.
  • No support for running Gulp/Grunt tasks at the push of a button.
  • No easy access to command line console / terminal.

What I like about PHPStorm

  • They have a core setting to trim trailing slashes on save.
  • Their settings management system is of the best I have ever seen.
  • Their code tidy is very effective.
  • Their auto documenter is strong. (reads variables requirements and return variables)
  • I can read and run gulp/grunt tasks included in the project I am working on with the click of the mouse button.
  • I can save quick launch spots for bash scripts.
  • Very quick global search / global search & replace.
  • Function list for JavaScript works well.

What I don’t like about PHPStorm

  • Slow to load.
  • When loading slowly it hijacks my monitor several different times while I try to do other things.
  • Tabbing interface is not as good as Notepad++.
  • Often the UI has too many knickknacks eg: information overload and over stimulation.
  • Search & Replace component, although faster for large tasks, is not as intuitive as Notepad++’s. In my opinion it’s Search System’s  UI needs to be redeveloped to follow NotePad++’s example.
  • No matter what theme I use there is pixel blurring on my code text. This is not an issue for Notepad++. Pixels there are sharp. No matter the magnification.
  • Line bookmarking is more complicated and harder to use than with notepad++. With notepad++ it’s a click on the line number and then a function key press to cycle through marked line numbers. With PHPStorm its pressing a function key on a line and then navigating to a bookmarks list and double-clicking bookmarks to navigate to them. Bookmarks also persist after shutdown and startup, which means cleanup duties.
  • I can’t figure out how to turn inspections off by default. When they are on sometimes they help, but oftentimes they cause me to question and investigate my code needlessly and I’ve incorporated pressing cntrl+shift+alt+H on every file to turn inspections off.

I want to use Notepad++ but I can’t!

Don’t get me wrong PHPStorm is an incredibly powerful tool. And I’m using it.  I still miss Notepad++ though beacuse…

  • I refuse to make use of macros because Windows is already cluttered with Macros key combinations. There should be a settings level solution to ‘onsave’ processes.
  • I can live with a broken function/class viewer for Javascript files, but I really want a modern one that reads my js objects as well as it reads my php class objects.
  • I need to be able to run my gulp/grunt tasks quickly from GUI.
  • I also love having a command line utility + console in PHPStorm. Not only can you open one console but you can open as many as needed which is great for processes that require that the console stay open (node server, gulp watch, etc).

As a modern developer I need the Grunt + Gulp + Commandline tools that PHPStorm offers. But Notepad++ is still miles ahead of PHPStorm when it comes to simplicity, intuitive components, and speed. I really want to move back but I can’t.

In the meantime, I still use both side by side.

I’ve also my eye on Atom Editor, though at the time of this article it is not strong enough to replace either… I believe it’s appeal is in how easy it is to extend with self written and community contributed plugins. It will surely become a contender as it’s community empowers it.

 

Visual comparison between PHPStorm & Notepad++
Visual comparison between PHPStorm & Notepad++

Notes on working with Google Calendar API

Get a list of calendars

I want to get a list of google calendars for a google account. I am already authenticated and using the PHP library…. how?

https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list

public static function get_calendar_lists() {

    $client = Inbound_Google_Calendar_Connect::get_client();

    $service = new Google_Service_Calendar($client);
    $calendarList = $service->calendarList->listCalendarList();
    print_r($calendarList);exit;
    while(true) {
        foreach ($calendarList->getItems() as $calendarListEntry) {
            echo $calendarListEntry->getSummary();
        }
        $pageToken = $calendarList->getNextPageToken();
        if ($pageToken) {
            $optParams = array('pageToken' => $pageToken);
            $calendarList = $service->calendarList->listCalendarList($optParams);
        } else {
            break;
        }
    }

}

Embed Calendar By ID

I’ve run into my first problem. I can get the list of calendars no problem, but when I try to get a calendar by id I am getting a ‘(401) Login Required’ error. I should be authenticated. Doesn’t make sense. My scopes seem right too.

Turns out I was not setting my access token correctly. Not sure I need this method anyway since the method above seems to return the same data for all calendars.

/**
 * Get information given calendar id
 */
public static function get_calendar( $calendar_id ) {

    Inbound_Google_Calendar_Connect::get_client();

    $service = new Google_Service_Calendar( self::$client );
    $calendar = $service->calendars->get( $calendar_id );

    print_r($calendar);exit;
}

Generating a Calendar Embed

My next task is to figure out how to take a calendar Id and turn it into an embed. Turns out I can’t find out how to do this. If the user is logged in they can read a normal embedded calandar. If they aren’t then the calendar won’t show.

I would think that we’d be able to render a private calendar using the API. I’ve opened up a git issue here.

 

A unit testing journal: looking to run front end tests.

I need to say… this is a journal entry… not a tutorial. If I’m all over the place with my writing, believe me it mirrors my research timeline. Some things I say might not even be true.

In travis-ci.org  wp_remote_get doesn’t seem to load my custom post type page.  In fact viewing the response of a post’s permalink shows that we are accesing a page unrelated to the blog created by travis-ci.org ( the generated site domain is http://www.example.org).

Looks like travis-ci.org doesn’t offer virtual domains… which is a large setback. Now I will start investigating Vagrant and VVV.

And now I’m trying to investigate using PHPStorm to run tests for all my plugins on my Vagrant machine. I have the Vagrant machine up and running.  In the course of experimenting I learned about using PHPStorm’s built in integration with composer. Composer has been tough for me to understand. I get that it is similar to NodeJs’s NPM installer but for PHP instead.

I like how these package managers have arrived for PHP and JS. Grunt and Gulp are a little difficult to understand too.

In the meantime while I study, enjoy this tasty tune.

 

If I get this to work my travis-ci.org tests are going to fail for my custom Vagrant build… what to do… Ideally I will be able to build domain support into travis.ci? Is that possible? I will find out later.

This resource is being a huge help for what I am doing now.

It seems like it takes a good amount of time to wipe vagrant the box and rebuild it. Maybe the vagrant server should stay up while I develop grunt tasks to wipe the WordPress db instance, and rebuild it then deploy my tests. I bet this is where WP-Cl commands are going to come in handy. They’re included with VVV.

Unless I want to develop directly inside my VVV instance, I’ll have to mirror my XAMP website folders to the Vagrant test blog I’ll work with.  I use Mirror Folder to do this. But I could also create a gulp task to watch and mirror files on change.  I do not know which one is more resource intensive. Mirror Folder seems to work very well. I bet Mirror Folder will perform better (I believe it runs on a RAID protocol)

Ideally when I launch my OS the vagrant server will load as a service and listen for me to launch my tests from PHPStorm.

In order to try and rebuild the Travis-CI continuous integration into my local vagrant server I’ve ended up trying to install JoliCi and Docker [1] and these are things I have never heard of. It seems I have to include docker as a provision in my VVV provision.sh file. (btw I failed at this and changed my strategy again.)

I am trying to run unit tests for 3 plugins at one time using SSH PHPUnit commands on a phpunit.xml file that looks like this.  BTW this is what my bootstrap.php files looks like. I am running into issues where the test classnames conflict with each other. When running tests in Travis-Ci.org , it was only one testing one plugin at a time… so there were no conflicts.

This makes me think that I will not be able to run tests for more than one plugin at a time. Which means I’ll need to either build multiple run configurations with PHPStorm or gulp tasks to quickly power my local tests… if I want to have a local vagrant testing server.

The good news is that I tried removing all plugin test configurations from my phpunit.xml file and the unit tests ran for the plugin that remained. This also means that I figured out my bootstrap.php issue when crafting my phpunit.xml file. I had to load the WordPress Tests suite into my vagrant server and, from my phpunit.xml boostrap.php, run an include to it’s bootstrap.php file to load all the WordPress unit testing helpers.

Still there is nothing setup yet for wiping the db on each test run. I’ve been at it all weekend and I am still in over my hear.

I watched this lecture by Chris Lema on codeception. Codeception seems to support front end testing. I ran a search on Google and have found where people have ran codeception with Travis.Ci…. which is a great sign. I’d rather run there than local anyway…. but the whole reason I have attempted to learn local unit testing through vagrant was because Travis-Ci.org doesn’t provide testable domain names for my generated WordPress instance. Without frontend access there is no frontend testing.

I’ve opened up a stackoverflow issue to try and help me solve this mystery. I’ve also opened up a WPChat discussion thread.

I’ve decide to emulate Conception’s travis.yml file on our landing pages plugin. If they can get Codeception to work on travis.yml then I want to too, and I will migrate away from using PHPUnit. In the pursuit of this new goal I’ve stumbled across this resource.

Let me reiterate… this is so hard!

I believe I have discovered that Travis-ci.org does support virtual hosts. It seems that with my original travisci.yml setup I was not installing and running a linux server. I had thought that my WordPress unit tests were not able to run without Linux already being installed. I had thought that travis instances came preloaded with linux. I was wrong.

It turns out that PHP unit tests that do not require frontend or backend UI rendereing did not even need apache to run. All it needed was PHP, a wordpress filebase, and a MySQL database to run basic unit tests out of the box.

This means my next direction is to create my travis.yml file in a way that installs an Apache server, modifies it’s virtual hosts records to include some sort of domain support, then update my spun WordPress instance to to use that virtual domain instead of the default example.org domain.

Then my wp_remote_get() method should work for rendering self hosted wp pages for my phpunit tests.

It’s taking me a long time to get the virtual hosts to work. I’ve found this guide by digital ocean on how to setup an apache server to be very helpful so far.

I’ve made progress in getting the virtual hosts to work, but now it does not seem like PHP is executing when accessed from the apache server. Trying some new tricks learned from this resource link. Which did help me activate PHP with Apache. It even helped me get around the ‘your php installation appears to be missing the MySQL extension…’ message I was getting when I tried to install PHP via command line.

Now WordPress is loading, but it still is in ‘Setup mode’ and is displaying: ‘WordPress › Setup Configuration File’ in the response HTML. Need to get that out of the way. It looks like I need to setup wp-config.php as well as wordpress-develop’s wp-tests-config.php.

Even when the databases are all setup properly it still is trying to run through the WordPress installation through the front end. This may be when WP CLI comes in handy.

And they did. I used WP CLI to go ahead and preinstall a build, but it look’s like the WordPress Dev Test’s bootstap.php file is running it’s own database whipe and rest, which is changing my site URLs back to ‘example.com’ in the WordPress database.

In order to solve this I’ll have to set my eyes back on PHPUnit’s setUp method to correct the db entries or try to create the db changes immediately after WordPress’s bootstrap runs.

I wish I could use those WPCLI commands within my bootstrap.php file. They were really easy to use.

I’ve decided to kick out the use of WordPress’s own dev environment bootstrap.php and directly include their testcase.php which constains the WP_UnitTestCase my php unit tests depend on. This file also will load their “factory.php” file.

This gets rid of the issue with their boostrap.php overwriting/changing the db I had wp cli setup via command line.

Now everything is working great. I’ve had to use WPCLI to generate an htaccess file to get my custom post type to stop 404ing. I ran into some problems with this but I will have my solution in the tutorial I develope once this process is all over.

So far the project, which was supposed to be a weekend project, has taken 10 days.

There is so much I do not understand about unit testing. I’ve decided to try and run my tests locally again to see if I could use it for quick debugging (I’ve run into an issue on travis ci where I am seeing an unnatural fatal error). Now it seems like the changes I am making to my VVV instance is caching my db enteries rather than updating the actual database. I don’t understand. At this point I have no clue what is going on. I wonder if there is a secret that other unit testers know about the way unit testing and databasing works. As far as I am concerned data changes in a unit test should reflect server side.

As I am getting more certain that I can’t change the database from inside a unit test I am getting more confident in a solution being somewhere at hand already.

And I discovered the issue. My issue is with WP_UnitTestCase, which creates a copy of the blog’s MySQL database and uses it instead of the actual db. For the test I am trying to run I need to test more than just the logic. I need to access the front end as a user to make sure my javascript runs and then use the php side to check the database.

I can do this if I get rid of the WP_UnitTestCase foundation and return to using PHPUnit_Framework_TestCase as the class the tests extends.

I also found out that our Landing Pages plugin does not support Nigx servers, and depends on apache servers with mod rewrite enabled. So I’ve had to ditch my VVV vagrant build for VVV-Apache.

I have it now that my PHPUnit test correctly loads it’s own pages and can interact with the database if it wants to. Now my problem is that wp_remote_get() does not require javascript processing, and so page impression counters are not firing during a request. I’ll have to investigate a PHP alternative to wp_remote_get that makes sure the javascript engine runs.

I’m thinking I am going to have to write a PhantomJS PHP server that I call via POST that returns the page content after the javascript has been loaded. Everwhere I read recommends me to use exec() to run phantomjs but WordPress would hassle me if I did it.

Did I mention I stopped working on Travis and started working locally again?  I ran into some travis errors and I wanted to be able to test locally to save time. It’s been a big pain though.

I’ve found out that the PhantomJs install that is provided by Unbuntu’s apt install command is outdated and has dependancies on X server. Not sure what it is. But maybe that is when it was not all the way ‘headless’.

I am having to install it directly from node. Everyone says that’s what they feel comfortable doing. Here’s the setup code I am using (although I plan to write a thorough tutorial later)

sudo apt-get install nodejs nodejs-dev npm
sudo apt-get install libfontconfig
sudo npm install -g phantomjs

I’ve made some progress using phantom JS and PHP together. But I am still stuck on my local pages not loading via PHP + PhantomJs. I’ve raised an  issue here and a stackoverflow question here.

Question Index:

  • when trying to setup my virtual hosts in my travis-ci.org build I find that /etc/apache2/sites-available/default does not seem to exist.
  • default wordpress domain is example.org in travis ci
  • how to run codeception on travis ci
  • how to install wordpress on travis ci
  • php not rendering when accessed from apache
  • Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
  • Regenerating a .htaccess file requires special configuration. See usage docs.
  • phantomjs: cannot connect to X server

 

 

Who is Susan Lindauer?

US government imprisoned this woman through the patriot act and tried to keep her locked up for 10 years while chemically labodomizing her with drugs because she was a CIA wistleblower trying to get the word out that the US had extensive preparatory knowledge of the 911 attacks.

Lindauer additionally suggests that thermite+sulfer military grade compound was used to assist the demolition of all three towers.