It can be tempting to put down โrevisit to functionalityโ oddities as one off issues not to be concerned about. But this is not always such a good strategy, and is a bit of an arrogant strategy, because it is like you (as programmer) saying โฆ
My code has no bugs
โฆ an out and out lie from whoever says this. Take a scenario to its extreme (eg. natural disaster disabling the hardware behind the software), and such a statement canโt be justified.
Even if an issue canโt be examined there and then, even a repeat of the operation is worth it, as a first check of the optimistic proposition above. If no time now to fix a repeat problem, at least note it down for a revisit, we recommend.
And so we have an example of such an occurrence for us, revisiting the functionality of WordPress Blog Posting Trending Search Primer Tutorial, in (relatively) recent times.
Before todayโs changes (believe me) we were getting a blank webpage screen when we visited thechanged trending_on_wordpressphp live
run link.
Fast forward to todayโs troubleshooting work. We find โtroubleshootingโ and โdebuggingโ requires a shift of mindset, often. This is because it can be tempting to see all this as โsidewaysโ progress. It is a bit, but it is also a learning chance for you. Such as, at the end of it โฆ โam I susceptible to this type of coding weakness into the future?โ. That different mindset, for us, is to be as systematic and logical as you can be.
To help be logical, with web application work, we find the modern non-mobile web browser Web Inspectors invaluable, even with PHP work (as PHP begets HTML, after all โฆ but not always the total โdebugging packageโ (that PHPStorm would more likely to be)). With this in mind, even with the โwindow.openโ popup window scenario of us being โฆ
- in Google Chrome web browser visit this blogโs All Posts (menu) -> Trending Searches on this Blog submenu โฆ getting us to โฆ
- Trending Searches webpage โฆ blank โฆ aaaaarrrrggggh! โฆ so โฆ dooooonnnnnโt pannnnnnnic โฆ
- View -> Developer -> Developer Tools
- Click โConsoleโ tab โฆ getting us the error โฆ
Uncaught SyntaxError: Unexpected identifier trending_on_wordpress.php:25
โฆ and here, we must warn that โ25โ is not necessarily a PHP code line number, but rather a โresultant HTML webpageโ line number โฆ so โฆ - Click that trending_on_wordpress.php:25 link to get to real code of interest โฆ and we note that nothing appears wrong with the left hand side of (the PHP to HTML result of) โฆ
var thecwords=\"" . str_replace("\n"," ",$theswords) . "\"; \n
โฆ that being (up to right hand edge of Web Inspector webpage, for us) โฆ
var thecwords=" PHP PHP Python Overlay WordPress Avatar WordPress PHP Python Python PHP Python WordPress PHP Google@!@Chart Javascript jQuery Reveal Overlay Javascript XML HTML PDF MySql ...
โฆ but that is when you should scroll over to the cursor position of the issue off to the right, to where we see the problem with (later, over to the right) โฆ
... Power@#!@Management "Inhouse@!@Slideshow" Inhouse Inhouse ... ... ... ... ";
โฆ aaaahhhhh โฆ a data related problem we hadnโt catered for (that perhaps we could have envisaged, better, at the time of writing the code, indeed) โฆ remedied by changing that PHP line to โฆ
- better PHP codeline โฆ
var thecwords=\"" . str_replace('"','\"',str_replace("\n"," ",$theswords)) . "\"; \n
โฆ fixing the (unescaped) double quote within a double quote (โUncaught SyntaxError: Unexpected identifierโ) PHP variable definition bug
โฆ a lot of which you can see play out with todayโs tutorial picture.
Especially with the serverside languages such as PHP that can โinfillโ variables via data stored away in an independent datastore, data related bugs like this can be avoided best by programmers who remain sceptical and questioning regarding the implications of the โpower and variety of dataโ โฆ a lifeโs work, we figure?!
Previous relevant WordPress Blog Posting Trending Search Primer Tutorial is shown below.
We wanted to share some search information used by other users of this blog, in case what other people are searching for, might be the thing you didnโt know that you wanted to search for. This is human nature. We learn from each other, and that is why โtrendingโ is such a big word in I.T. these days.
Weโre going to start, limiting the pool of information this functionality reads its information from, to those new โTitle REโ (ie. regular searches of Blog Posting Title) searches we introduced when we presented WordPress Blog Posting Title Regular Expression Search Primer Tutorial.
So there are two parts to this functionality, those being โฆ
- the collection of โTitle REโ search information to the web server โฆ we pick a flat file source of that data โฆ which is then read by โฆ
- reporting of trending โTitle REโ searches made at the blog, reading that dynamically changing pool of โTitle REโ search data
โฆ consecutively handled in โฆ
- (good olโ) header.php of WordPress theme TwentyTen โฆ to gather data โฆ as per โฆ
function asksr() {
var av=prompt('Blog Posting Titles matching Regular Expression?', document.getElementById('s').value);
if (av != null) {
if (av != '') {
if (av.substring(0,1) == '.') {
location.href='//www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(String.fromCharCode(92) + av + 'fRoM');
} else {
location.href='//www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(av + 'fRoM');
}
}
}
}
โฆ helping out mapperphp, that changed in thisway to accommodate along with the new โฆ
- trending_on_wordpress
php โฆ with its live
run for this blogโs trends โฆ PHP to report on those trends via a Javascript alert box window and Google Chart Histogram Chart โฆ thanks to this very useful link regarding some of the suavest logic used in it
So one last thing is, where do we โstoreโ this functionality? We thought, put it on the โAll Postsโ main menu as a submenu option, so that it becomes a piece of functionality only causing web server processing activity loading when a user chooses to ask for this.
Previous relevant WordPress Blog Posting Title Regular Expression Search .htaccess Tutorial is shown below.
As we pick up from yesterdayโs WordPress Blog Posting Title Regular Expression Search Primer Tutorial with explaining the functionality behind our new WordPress Blog Title Regular Expression Search functionality you can โฆ
- take a peak at the URL created during its use on the way .. via (header.phpโs Javascript HTML select element onchange event logic) โฆ
function asksr() {
var av=prompt('Blog Posting Titles matching Regular Expression?', document.getElementById('s').value);
if (av != null) {
if (av != '') {
if (av.substring(0,1) == '.') {
location.href='//www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(String.fromCharCode(92) + av);
} else {
location.href='//www.rjmprogramming.com.au/itblog/match/' + encodeURIComponent(av);
}
}
}
}
โฆ to showing the top of the page HTML select element dropdown โฆ or, be a smart Alec and โฆ - take a peak at the second last word of todayโs blog posting title
โฆ to get the hint that, today (as with WordPress 4.1.1โs WordPress Blog Posting Title Regular Expression Search .htaccess Tutorial), we have on our hands an example of the use of an Apache web server .htaccess approach to URL processing and navigation control.
The use of .htaccess files in Apache web server environments is quite a big subject, and for more far reaching detail than what we provide today, we would like to direct you towards this useful webpage (and while you are at it, read about our upgrade from WordPress 3.0.3 to WordPress 4.1.1 and some .htaccess work via the blog posting thread ending at WordPress Upgrade Crontab Curl Tutorial). What can you do within a subject area you want to learn? Stay informed, read, consult or โฆ take leads from others, and by so doing, know more the specifics of what you need to read and research, we hope?! So it was with us, taking leads off something weโd done earlier taking leads off what WordPress had shown us was possible in that โearlier onโ period.
We find .htaccess work very satisfying, as it is making URLs look less โmanufacturedโ โฆ though, today, it must be admitted, an interim URL we use obfuscates that elegance a fair bit. Nonetheless, having these โmagicalโ URLs with no ? nor & (quite often) doing these strange things happens (with .htaccess work) because โฆ the .htaccess mapped URLโs PHP or HTML code is passed the original URL and it behoves that mapped code to make use of that fact โฆ in other words, the address bar URL will still be the elegant non-?-& URL that the PHP or HTMLโs document.URL sees and can โchameleon fashionโ change its guise, according to โฆ and we go and โchange the guiseโ to a self recalling arrangement of a URL that does contain a ? and is thus available to the PHP we write in the global variable $_GET[โpmโ] as per (hint: mapper.phpโs) code snippet โฆ
if (isset($_GET['pm'])) { // recall scenario
// populate the HTML select element dropdown via $_GET['pm'] ... rest assured, PHP's eregi is used in this logic
} else { // got here via .htaccess in //www.rjmprogramming.com.au/itblog/match/ web server directory
// recall yourself via location.href='//www.rjmprogramming.com.au/itblog/match/mapper.php?pm=' + document.URL.replace(''//www.rjmprogramming.com.au/itblog/match/', '');
}
Okay, so did you โtake a peak at the URL created during its use on the way to showing the top of the page HTML select element dropdownโ? If so youโd have found a sequence of URLs, the first two really hard to get a glimpse of โฆ
- //www.rjmprogramming.com.au/itblog/match/Python
- //www.rjmprogramming.com.au/itblog/match/mapper.php
- //www.rjmprogramming.com.au/itblog/match/mapper.php?pm=Python
โฆ because it all happens so fast, and weโve helped you out in todayโs tutorialpicture imagining it happening. But what happens? Well, the URLโs //www.rjmprogramming.com.au/itblog/match/ underlying web server directory has a special file, at least to Apache web servers, and it is called .htaccess and for the scenario above it comprises โฆ
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /itblog/match/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /itblog/match/mapper.php [L]
</IfModule>
# END WordPress
โฆ about which you need to see that Apacheโs mod_rewrite module needs to be active for this .htaccess file to be noticed and that โRewriteRule . /itblog/match/mapper.php [L]โ is the bit that spurs the โฆ
- //www.rjmprogramming.com.au/itblog/match/Python
- //www.rjmprogramming.com.au/itblog/match/mapper.php
โฆ mapping taking place, and is the doing of the .htaccess file, while the rest happens within our homegrown mapperphp where its navigational progression โฆ
- //www.rjmprogramming.com.au/itblog/match/mapper.php
- //www.rjmprogramming.com.au/itblog/match/mapper.php?pm=Python
โฆ can only feasibly be guessed at by mapper.php because the previous โ//www.rjmprogramming.com.au/itblog/match/Pythonโ URL is available to it in the Javascript DOM client โdocument.URLโ global โฆ cute, huh?! And, that being the case we know to construct HTML select element dropdown contents based on โPythonโ and to populate an HTML iframe below with the landing page of the blog, awaiting any user specified instructions.
You may well reason that you donโt have to involve .htaccess Apache methods to get this job done, and youโd be right, but the topic can be extremely useful regarding Apache web servers, like we have at www.rjmprogramming.com.au โฆ and so we thought weโd show you some details here, and we hope you like it.
Did you know?
Were you a blog reader here when we introduced WordPress version 4.1.1 into the equation? Do you recall us making URLs โฆ
โฆ โequateโ to the same web (blog) application webpage? Please read the โDid you know?โ of WordPress Upgrade Implications Tutorial for more information here, but the gist of making this happen was to place into //www.rjmprogramming.com.au/itblog/ URLโs underlying web server directory the .htaccess file as below โฆ
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /itblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ITblog/index.php [L]
</IfModule>
# END WordPress
โฆ which amounts to a very similar concept to todayโs mapper.php for our Blog Post Title Regular Expression Searches scenario, and is a lesson in how individual web server directories can have tailored .htaccess functionalities.
Previous relevant WordPress Blog Posting Title Regular Expression Search Primer Tutorial is shown below.
One of our chief aims with this blog is to send the user off on a themed โthreadโ of inquiry. What came, by default with our WordPress TwentyTen themed blog was to categorize via โฆ
- Category
- Tag
- Search (string)
โฆ and then โฆ some time back โฆ sun comes up, sun goes down x 100โs โฆ we allowed a Search (string) arrangement within one of the other two โparentโ searches โฆ and today โฆ da da da da da, da da da โฆ we allow a Regular Expression search of Blog Posting titles โฆ because โฆ
- it fits in quite nicely with our long-winded blog posting title regime, which has been designed to tell it like it is โฆ but not great for SEO (you should be warned) โฆ and โฆ
- weโve always felt that an exploration of a topic like โPythonโ, for example, will not necessarily fit into a โCategoryโ nor necessarily even a โTagโ scenario nearly as well, for us, as to allow a (Regular Expression) search of Blog Posting Titles for โPythonโ
โฆ as well as the cute feature that, because it is using PHP Regular Expressions via the eregi method, you could narrow the search via ^Python as an example to ensure Blog Posting Titles have to start with โPythonโ.
There is a dual purpose to this work, but weโll just be discussing the โinterfaceโ to the WordPress blog today, and detail something else regarding it tomorrow. So for today, we add a new HTML input element type=checkbox next to the blogโs Search input textbox, and off whatever might have been entered as text into that field as the default string for a Javascript prompt window asking of what Blog Posting Title Regular Expression Search they want to perform, and this sends the user to a new webpage consisting of โฆ
- one HTML select element dropdown of matching Blog Posting Titles โฆ under which is โฆ
- one HTML iframe element initially showing the blogโs landing page but ready to be repopulated via any choice the user makes regarding the HTML select element dropdown above โฆ like a television with โtopโ control
That HTML input element type=checkbox (that you can see in todayโs tutorialpicture) is coded (in โฆ you guessed it โฆ good olโ header.php) as below โฆ
<input title='WordPress Blog Posting Title RegExp search ...' onclick="asksr();" type='checkbox' id='scbtype' value='Title RE'></input><a style='cursor:pointer;text-decoration:underline;' title='WordPress Blog Posting Title RegExp search ...' onclick="asksr();">Title RE</a>
Weโll be taking off from this point explaining more about the architecture behind this functionality tomorrow. But you being here, up at the Search input box you can try out what we mean, to see all this in action. And it may be worth considering โฆ a โRegular Expressionโ each day keeps you Regular โฆ yes, you heard it first here, folks!
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.