Recent Posts

Add admin to glotpress

Add admin to glotpress

Following is the script to add admin to glotpress php scripts/add-admin.php user-name Before run script, check you have configured database properly.

PHP readdir() return false even if permission are right

PHP readdir() return false even if permission are right

Today (So many times ) i face directory read issue using php. If you are trying to read a directory and readdir function is returning false even if php user have right permission (At least read permission) to that directory mainly while your server is 

register_taxonomy reserved terms

register_taxonomy reserved terms

There are some reserved word for register taxonomy. If you are passing the term through the $_GET or $_POST array. Doing so can cause WordPress to respond with a 404 error without any other hint or explanation.

Following is the code snippet to check reserved terms.


//Forbidden attribute names
//http://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms
$reserved_terms = array(
            'attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and', 'category__in', 'category__not_in', 'category_name', 'comments_per_page', 'comments_popup', 'cpage', 'day', 'debug', 'error', 'exact', 'feed', 'hour', 'link_category', 'm', 'minute', 'monthnum', 'more', 'name', 'nav_menu', 'nopaging', 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm', 'post', 'post__in', 'post__not_in', 'post_format', 'post_mime_type', 'post_status', 'post_tag', 'post_type', 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 's', 'search', 'second', 'sentence', 'showposts', 'static', 'subpost', 'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id', 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'type', 'w', 'withcomments', 'withoutcomments', 'year',);

if ( in_array( $taxonomy_name, $reserved_terms )){
    $error = sprintf( __( 'Slug “%s” is not allowed because it is a reserved term. Change it, please.' ), $taxonomy_name );
}
PHP CodeSniffer – Coding standards

PHP CodeSniffer – Coding standards

PHP CodeSniffer scan PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. To install phpcs on ubuntu pear install PHP_CodeSniffer To list all installed coding standards phpcs -i I found great article on rtCamp site. you can read it 

12 String guitar String gauge

12 String guitar String gauge

String Gauge 1st .010 2nd .010 3rd .014 4th .014 5th .023 6th .009 7th .030 8th .012 9th .039 10th .018 11th .047 12th .027

Java User Agent Detection code

Java User Agent Detection code


/* *******************************************
// LICENSE INFORMATION
// The code, "Detecting Smartphones Using PHP"
// by Anthony Hand, is licensed under a Creative Commons
// Attribution 3.0 United States License.
//
// Updated 01 March 2010 by Bryan J Swift
// – Remove un-needed if statements instead just returning the boolean
// inside the if clause
//
// Updated 14 December 2009 by A Hand
// – Added the method for detecting BlackBerry Touch
// devices like the Storm 1 and 2.
//
// Updated 5 December 2009 by A Hand
// – Fixed the DetectPalmOS method. It should filter
// out WebOS devices.
//
// Updated 8 November 2009 by A Hand
// – Added the deviceWebOS variable.
// – Added Palm's WebOS to the DetectPalmOS method.
// – Created a new method to check for Palm's WebOS devices.
// – Added Palm's WebOS to the DetectTierIphone method.
//
// Updated 4 April 2009 by A Hand
// – Changed the name of the class from DetectSmartPhone to UAgentInfo.
// New name is more consistent with PHP and JavaScript classes.
// – Added a method to detect Opera Mobile and Mini. Opera Mobile is new.
// – Updated the algorithm for detecting a Sony Mylo.
// – Added Android to the DetectTierIphone method.
// – Updated comments for Detect Tier methods.
//
// Updated 22 January 2009
// – Ported to Java from the PHP code by
// Satish Kumar Nookala, [email protected]
//
// Anthony Hand, [email protected]
// Web: www.hand-interactive.com
//
// License info: http://creativecommons.org/licenses/by/3.0/us/
//
// This code is provided AS IS with no expressed or implied warranty.
// You have the right to use this code or any portion of it
// so long as you provide credit toward myself as the original author.
//
// *******************************************
*/
package com.handinteractive.mobile;
import javax.servlet.http.HttpServletRequest;
/**
* The DetectSmartPhone class encapsulates information about
* a browser's connection to your web site.
* You can use it to find out whether the browser asking for
* your site's content is probably running on a mobile device.
* The methods were written so you can be as granular as you want.
* For example, enquiring whether it's as specific as an iPod Touch or
* as general as a smartphone class device.
* The object's methods return true, or false.
*/
public class UAgentInfo {
// User-Agent and Accept HTTP request headers
private String userAgent = "";
private String httpAccept = "";
// Initialize some initial smartphone string variables.
public static final String engineWebKit = "webkit";
public static final String deviceAndroid = "android";
public static final String deviceIphone = "iphone";
public static final String deviceIpod = "ipod";
public static final String deviceSymbian = "symbian";
public static final String deviceS60 = "series60";
public static final String deviceS70 = "series70";
public static final String deviceS80 = "series80";
public static final String deviceS90 = "series90";
public static final String deviceWinMob = "windows ce";
public static final String deviceWindows = "windows";
public static final String deviceIeMob = "iemobile";
public static final String enginePie = "wm5 pie"; //An old Windows Mobile
public static final String deviceBB = "blackberry";
public static final String vndRIM = "vnd.rim"; //Detectable when BB devices emulate IE or Firefox
public static final String deviceBBStorm = "blackberry95"; //Storm 1 and 2
public static final String devicePalm = "palm";
public static final String deviceWebOS = "webos"; //For Palm's new WebOS devices
public static final String engineBlazer = "blazer"; //Old Palm
public static final String engineXiino = "xiino"; //Another old Palm
//Initialize variables for mobile-specific content.
public static final String vndwap = "vnd.wap";
public static final String wml = "wml";
//Initialize variables for other random devices and mobile browsers.
public static final String deviceBrew = "brew";
public static final String deviceDanger = "danger";
public static final String deviceHiptop = "hiptop";
public static final String devicePlaystation = "playstation";
public static final String deviceNintendoDs = "nitro";
public static final String deviceNintendo = "nintendo";
public static final String deviceWii = "wii";
public static final String deviceXbox = "xbox";
public static final String deviceArchos = "archos";
public static final String engineOpera = "opera"; //Popular browser
public static final String engineNetfront = "netfront"; //Common embedded OS browser
public static final String engineUpBrowser = "up.browser"; //common on some phones
public static final String engineOpenWeb = "openweb"; //Transcoding by OpenWave server
public static final String deviceMidp = "midp"; //a mobile Java technology
public static final String uplink = "up.link";
public static final String devicePda = "pda"; //some devices report themselves as PDAs
public static final String mini = "mini"; //Some mobile browsers put "mini" in their names.
public static final String mobile = "mobile"; //Some mobile browsers put "mobile" in their user agent strings.
public static final String mobi = "mobi"; //Some mobile browsers put "mobi" in their user agent strings.
//Use Maemo, Tablet, and Linux to test for Nokia"s Internet Tablets.
public static final String maemo = "maemo";
public static final String maemoTablet = "tablet";
public static final String linux = "linux";
public static final String qtembedded = "qt embedded"; //for Sony Mylo
public static final String mylocom2 = "com2"; //for Sony Mylo also
//In some UserAgents, the only clue is the manufacturer.
public static final String manuSonyEricsson = "sonyericsson";
public static final String manuericsson = "ericsson";
public static final String manuSamsung1 = "sec-sgh";
public static final String manuSony = "sony";
//In some UserAgents, the only clue is the operator.
public static final String svcDocomo = "docomo";
public static final String svcKddi = "kddi";
public static final String svcVodafone = "vodafone";
// Standard desktop browser detection strings
public static final String msie = "msie";
public static final String msie60 = "msie 6.0";
public static final String msie61 = "msie 6.1";
public static final String msie7 = "msie 7.0";
public static final String msie8 = "msie 8.0";
public static final String msie9 = "msie 9.0";
public static final String firefox = "firefox";
public static final String safari = "apple";
public static final String chrome = "chrome";
public static final String opera = "presto";
// OS Detection
public static final String windows = "windows";
/**
* Initialize the userAgent and httpAccept variables
*
* @param userAgent the User-Agent header
* @param httpAccept the Accept header
*/
public UAgentInfo(String userAgent, String httpAccept) {
if (userAgent != null) {
this.userAgent = userAgent.toLowerCase();
}
if (httpAccept != null) {
this.httpAccept = httpAccept.toLowerCase();
}
}
/**
* Initialize the userAgent and httpAccept variables by getting the headers
* from the HttpServletRequest
*
* @param request the HttpServletRequest to get the header information from
*/
public UAgentInfo(HttpServletRequest request) {
this(request.getHeader("User-Agent"),request.getHeader("Accept"));
}
/**
* Return the lower case HTTP_USER_AGENT
*/
public String getUserAgent() {
return userAgent;
}
/**
* Return the lower case HTTP_ACCEPT
*/
public String getHttpAccept() {
return httpAccept;
}
/**
* Detects if the current device is an iPhone.
*/
public boolean detectIphone() {
// The iPod touch says it's an iPhone! So let's disambiguate.
return userAgent.indexOf(deviceIphone) != -1 && !detectIpod();
}
/**
* Detects if the current device is an iPod Touch.
*/
public boolean detectIpod() {
return userAgent.indexOf(deviceIpod) != -1;
}
/**
* Detects if the current device is an iPhone or iPod Touch.
*/
public boolean detectIphoneOrIpod() {
//We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
return userAgent.indexOf(deviceIphone) != -1 || userAgent.indexOf(deviceIpod) != -1;
}
/**
* Detects if the current device is an Android OS-based device.
*/
public boolean detectAndroid() {
return userAgent.indexOf(deviceAndroid) != -1;
}
/**
* Detects if the current device is an Android OS-based device and
* the browser is based on WebKit.
*/
public boolean detectAndroidWebKit() {
return detectAndroid() && detectWebkit();
}
/**
* Detects if the current browser is based on WebKit.
*/
public boolean detectWebkit() {
return userAgent.indexOf(engineWebKit) != -1;
}
/**
* Detects if the current browser is the S60 Open Source Browser.
*/
public boolean detectS60OssBrowser() {
//First, test for WebKit, then make sure it's either Symbian or S60.
return detectWebkit() && (userAgent.indexOf(deviceSymbian) != -1 || userAgent.indexOf(deviceS60) != -1);
}
/**
*
* Detects if the current device is any Symbian OS-based device,
* including older S60, Series 70, Series 80, Series 90, and UIQ,
* or other browsers running on these devices.
*/
public boolean detectSymbianOS() {
return userAgent.indexOf(deviceSymbian) != -1 || userAgent.indexOf(deviceS60) != -1 ||
userAgent.indexOf(deviceS70) != -1 || userAgent.indexOf(deviceS80) != -1 ||
userAgent.indexOf(deviceS90) != -1;
}
/**
* Detects if the current browser is a Windows Mobile device.
*/
public boolean detectWindowsMobile() {
//Most devices use 'Windows CE', but some report 'iemobile'
// and some older ones report as 'PIE' for Pocket IE.
return userAgent.indexOf(deviceWinMob) != -1 ||
userAgent.indexOf(deviceIeMob) != -1 ||
userAgent.indexOf(enginePie) != -1 ||
(detectWapWml() && userAgent.indexOf(deviceWindows) != -1);
}
/**
* Detects if the current browser is a BlackBerry of some sort.
*/
public boolean detectBlackBerry() {
return userAgent.indexOf(deviceBB) != -1 || httpAccept.indexOf(vndRIM) != -1;
}
/**
* Detects if the current browser is a BlackBerry Touch
* device, such as the Storm
*/
public boolean detectBlackBerryTouch() {
return userAgent.indexOf(deviceBBStorm) != -1;
}
/**
* Detects if the current browser is on a PalmOS device.
*/
public boolean detectPalmOS() {
//Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
if (userAgent.indexOf(devicePalm) != -1 || userAgent.indexOf(engineBlazer) != -1 ||
userAgent.indexOf(engineXiino) != -1 && !detectPalmWebOS()) {
//Make sure it's not WebOS first
if (detectPalmWebOS()) { return false; }
else { return true; }
}
return false;
}
/**
* Detects if the current browser is on a Palm device
* running the new WebOS.
*/
public boolean detectPalmWebOS() {
return userAgent.indexOf(deviceWebOS) != -1;
}
/**
* Check to see whether the device is any device
* in the 'smartphone' category.
*/
public boolean detectSmartphone() {
return (detectIphoneOrIpod() ||
detectS60OssBrowser() ||
detectSymbianOS() ||
detectWindowsMobile() ||
detectBlackBerry() ||
detectPalmOS() ||
detectPalmWebOS() ||
detectAndroid());
}
/**
* Detects whether the device is a Brew-powered device.
*/
public boolean detectBrewDevice() {
return userAgent.indexOf(deviceBrew) != -1;
}
/**
* Detects the Danger Hiptop device.
*/
public boolean detectDangerHiptop() {
return userAgent.indexOf(deviceDanger) != -1 || userAgent.indexOf(deviceHiptop) != -1;
}
/**
* Detects Opera Mobile or Opera Mini.
* Added by AHand
*/
public boolean detectOperaMobile() {
return userAgent.indexOf(engineOpera) != -1 && (userAgent.indexOf(mini) != -1 || userAgent.indexOf(mobi) != -1);
}
/**
* Detects whether the device supports WAP or WML.
*/
public boolean detectWapWml() {
return httpAccept.indexOf(vndwap) != -1 || httpAccept.indexOf(wml) != -1;
}
/**
* The quick way to detect for a mobile device.
* Will probably detect most recent/current mid-tier Feature Phones
* as well as smartphone-class devices.
*/
public boolean detectMobileQuick() {
//Ordered roughly by market share, WAP/XML > Brew > Smartphone.
if (detectWapWml()) { return true; }
if (detectBrewDevice()) { return true; }
// Updated by AHand
if (detectOperaMobile()) { return true; }
if (userAgent.indexOf(engineUpBrowser) != -1) { return true; }
if (userAgent.indexOf(engineOpenWeb) != -1) { return true; }
if (userAgent.indexOf(deviceMidp) != -1) { return true; }
if (detectSmartphone()) { return true; }
if (detectDangerHiptop()) { return true; }
if (detectMidpCapable()) { return true; }
if (userAgent.indexOf(devicePda) != -1) { return true; }
if (userAgent.indexOf(mobile) != -1) { return true; }
//detect older phones from certain manufacturers and operators.
if (userAgent.indexOf(uplink) != -1) { return true; }
if (userAgent.indexOf(manuSonyEricsson) != -1) { return true; }
if (userAgent.indexOf(manuericsson) != -1) { return true; }
if (userAgent.indexOf(manuSamsung1) != -1) { return true; }
if (userAgent.indexOf(svcDocomo) != -1) { return true; }
if (userAgent.indexOf(svcKddi) != -1) { return true; }
if (userAgent.indexOf(svcVodafone) != -1) { return true; }
return false;
}
/**
* Detects if the current device is a Sony Playstation.
*/
public boolean detectSonyPlaystation() {
return userAgent.indexOf(devicePlaystation) != -1;
}
/**
* Detects if the current device is a Nintendo game device.
*/
public boolean detectNintendo() {
return userAgent.indexOf(deviceNintendo) != -1 || userAgent.indexOf(deviceWii) != -1 ||
userAgent.indexOf(deviceNintendoDs) != -1;
}
/**
* Detects if the current device is a Microsoft Xbox.
*/
public boolean detectXbox() {
return userAgent.indexOf(deviceXbox) != -1;
}
/**
* Detects if the current device is an Internet-capable game console.
*/
public boolean detectGameConsole() {
return detectSonyPlaystation() || detectNintendo() || detectXbox();
}
/**
* Detects if the current device supports MIDP, a mobile Java technology.
*/
public boolean detectMidpCapable() {
return userAgent.indexOf(deviceMidp) != -1 || httpAccept.indexOf(deviceMidp) != -1;
}
/**
* Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
*/
public boolean detectMaemoTablet() {
return (userAgent.indexOf(maemo) != -1 || (userAgent.indexOf(maemoTablet) != -1 && userAgent.indexOf(linux) != -1));
}
/**
* Detects if the current device is an Archos media player/Internet tablet.
*/
public boolean detectArchos() {
return userAgent.indexOf(deviceArchos) != -1;
}
/**
* Detects if the current browser is a Sony Mylo device.
* Updated by AHand
*/
public boolean detectSonyMylo() {
return userAgent.indexOf(manuSony) != -1 && (userAgent.indexOf(qtembedded) != -1 ||
userAgent.indexOf(mylocom2) != -1);
}
/**
* The longer and more thorough way to detect for a mobile device.
* Will probably detect most feature phones,
* smartphone-class devices, Internet Tablets,
* Internet-enabled game consoles, etc.
* This ought to catch a lot of the more obscure and older devices, also —
* but no promises on thoroughness!
*/
public boolean detectMobileLong() {
return detectMobileQuick() || detectMaemoTablet() || detectGameConsole();
}
//*****************************
// For Desktop Browsers
//*****************************
public boolean detectMSIE() {
return userAgent.indexOf(msie) != -1;
}
public boolean detectMSIE6() {
return userAgent.indexOf(msie60) != -1 && userAgent.indexOf(msie61) != -1;
}
public boolean detectMSIE7() {
return userAgent.indexOf(msie7) != -1;
}
public boolean detectMSIE8() {
return userAgent.indexOf(msie8) != -1;
}
public boolean detectMSIE9() {
return userAgent.indexOf(msie9) != -1;
}
public boolean detectFirefox() {
return userAgent.indexOf(firefox) != -1;
}
public boolean detectSafari() {
return userAgent.indexOf(safari) != -1;
}
public boolean detectChrome() {
return userAgent.indexOf(chrome) != -1;
}
public boolean detectOpera() {
return userAgent.indexOf(opera) != -1;
}
public boolean detectWindows() {
return userAgent.indexOf(windows) != -1;
}
//*****************************
// For Mobile Web Site Design
//*****************************
/**
* The quick way to detect for a tier of devices.
* This method detects for devices which can
* display iPhone-optimized web content.
* Includes iPhone, iPod Touch, Android, Palm WebOS, etc.
*/
public boolean detectTierIphone() {
return detectIphoneOrIpod() || detectPalmWebOS() || detectAndroid() || detectAndroidWebKit();
}
/**
* The quick way to detect for a tier of devices.
* This method detects for all smartphones, but
* excludes the iPhone Tier devices.
*/
public boolean detectTierSmartphones() {
return detectSmartphone() && (!detectTierIphone());
}
/**
* The quick way to detect for a tier of devices.
* This method detects for all other types of phones,
* but excludes the iPhone and Smartphone Tier devices.
*/
public boolean detectTierOtherPhones() {
return detectMobileQuick() && (!detectTierIphone()) && (!detectTierSmartphones());
}
}

view raw

UAgentInfo.java

hosted with ❤ by GitHub

PHP profiling using webgrind and Xdebug

PHP profiling using webgrind and Xdebug

Install xdebug sudo apt-get install php5-xdebug Then update config Add following line in /etc/php5/fpm/conf.d/20-xdebug.ini xdebug.profiler_enable = 1 xdebug.profiler_output_dir = /tmp After that please restart php5-fpm sudo service php5-fpm restart Load page you want to optimize It will take time (If its taking too much time 

Nginx forwarding rule

Nginx forwarding rule

server { listen 80 ; listen 443 ssl; server_name oldserver.com; ssl_certificate /var/www/oldserver.com/cert/server.crt; ssl_certificate_key /var/www/oldserver.com/cert/server.key; rewrite ^ $scheme://newserver.com$request_uri? permanent; }

FQL query for all your facebook photos (Uploaded + Tagged)

FQL query for all your facebook photos (Uploaded + Tagged)

In facebook graph api there isn’t any endpoint where you can get all your photos but this can done using very easy FQL query.

SELECT pid, src, caption from photo where owner = me() or pid IN
 (SELECT pid FROM photo_tag WHERE subject = me()) LIMIT 0,25
Debug WordPress, BuddyPress, WooCommerce javascript

Debug WordPress, BuddyPress, WooCommerce javascript

By default in production mode WordPress, BuddyPress and WooCommerce use minified version of css and javascript. If you are developer and want to debug any core(WordPress) and plugins(BuddyPress and WooCommerce) script or css file then just add following line in your wp-config.php file. define(‘SCRIPT_DEBUG’, true);

Delete a remote Git tag

Delete a remote Git tag

This is not advisable to delete any tag(because of why we tag ), but in case you need to delete tag this will help you. For example you have tag v1.1.0 Delete Tag from local git: git tag -d v1.1.0 Delete Tag from remote git