Categories
post

Multiple WordPress Blogs in One Installation

I have been hosting multiple wordpress blogs in one installation for a few years now. I like that I can upgrade one installation, and they all upgrade. I don’t have to go through 10 different installs/upgrades.

There are a few things that can be considered either a pro or a con based on your point of view. If one blog uploads a theme or a plugin, it is available to all the others. This doesn’t mean that if one enables it, they all have to have it enabled. It’s just there, so each can install if they need to.

One serious downside is customization. If one blog customizes a template, another blog can’t use it unless they too want that customization.

On to the nitty-gritty, all I do is change the wp-load.php file and copy the wp-config.php file. I copy the wp-config.php to wp-config-DOMAINNAME.php (example wp-config-www.johncongdon.com.php). Each config file changes the database table prefix.

Here is a diff for the wp-load.php file. It just changes an if statement to load our individual config, if it doesn’t exist, it loads the original wp-load.php.

--- wp-load-orig.php	2011-03-07 15:18:12.000000000 -0500
+++ wp-load.php	2011-03-07 10:30:04.000000000 -0500
@@ -24,7 +24,12 @@
 else
 	error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
 
-if ( file_exists( ABSPATH . 'wp-config.php') ) {
+if ( file_exists( ABSPATH . 'wp-config-'.$_SERVER['SERVER_NAME'].'.php') ) {
+
+  /** The config file resides in ABSPATH */
+  require_once( ABSPATH . 'wp-config-'.$_SERVER['SERVER_NAME'].'.php' );
+
+} elseif ( file_exists( ABSPATH . 'wp-config.php') ) {
 
 	/** The config file resides in ABSPATH */
 	require_once( ABSPATH . 'wp-config.php' );

Categories
post

Patching osticket for PHP 5.3

OSTicket is a decent piece of software for customer service. I upgraded to PHP 5.3 and had some problems because they are trying to keep it working all the way back to PHP 4. 🙁

Here is a patch to fix the eregi_replace deprecated errors.

diff --git a/osticket/include/class.format.php b/osticket/include/class.format.php
index 6cbb414..0380268 100644
--- a/osticket/include/class.format.php
+++ b/osticket/include/class.format.php
@@ -78,10 +78,10 @@ class Format {

     //make urls clickable. Mainly for display
     function clickableurls($text) {
-        $text=eregi_replace('(((f|ht){1}tp(s?)://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1', $text);
-        $text=eregi_replace("(^|[ \n\r\t])(www\.([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)(/[^/ \n\r]*)*)",
+        $text=preg_replace('#(((f|ht){1}tp(s?)://)[-a-zA-Z0-9@:%_\+.~\#?&//=]+)#','\\1', $text);
+        $text=preg_replace("#(^|[ \n\r\t])(www\.([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)(/[^/ \n\r]*)*)#",
                 '\\1\\2', $text);
-        $text=eregi_replace("(^|[ \n\r\t])([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})",'\\1\\2', $text);
+        $text=preg_replace("#(^|[ \n\r\t])([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})#",'\\1\\2', $text);

         return $text;
     }

diff --git a/osticket/include/class.validator.php b/osticket/include/class.validator.php
index 284d7c7..697d99c 100644
--- a/osticket/include/class.validator.php
+++ b/osticket/include/class.validator.php
@@ -126,15 +126,15 @@ class Validator {

     /* Functione below can be called directly without class instance. Validator::func(var..); */
     function is_email($email) {
-        return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",trim($email));
+        return preg_match("#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$#",trim($email));
     }
     function is_phone($phone) {
-        $stripped=eregi_replace("(\(|\)|\-|\+)","",ereg_replace("([  ]+)","",$phone));
+        $stripped=preg_replace("#(\(|\)|\-|\+)","",preg_replace("/([  ]+)#/","",$phone));
         return (!is_numeric($stripped) || ((strlen($stripped)<7) || (strlen($stripped)>13)))?false:true;
     }

     function is_url($url) { //Thanks to 4ice for the fix.
-        $urlregex = "^(https?)\:\/\/";
+        $urlregex = "#^(https?)\:\/\/";
         // USER AND PASS (optional)
         $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?";
         // HOSTNAME OR IP
@@ -149,9 +149,9 @@ class Validator {
         // GET Query (optional)
         $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?";
         // ANCHOR (optional)
-        $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
+        $urlregex .= "(\#[a-z_.-][a-z0-9+\$_.-]*)?\$#";

-        return eregi($urlregex, $url)?true:false;
+        return preg_match($urlregex, $url)?true:false;
     }


@@ -161,7 +161,7 @@ class Validator {
             return false;

         $ip=trim($ip);
-        if(ereg("^[0-9]{1,3}(.[0-9]{1,3}){3}$",$ip)) {
+        if(preg_match("#^[0-9]{1,3}(.[0-9]{1,3}){3}$#",$ip)) {
             foreach(explode(".", $ip) as $block)
                 if($block<0 || $block>255 )
                     return false;

Categories
post

LESS CSS Strings

I saw a tweet about LESS CSS today that I was able to answer with some simple trials. The question came from @funkatron: “Can any LESS.js nerds tell me how I could use a variable to set a base path for various `url()`s? like `background: url(@BASEPATH/foo.png)`”

The solution was quite simple after some trial and error.

@BASEPATH: ‘/PATH/TO/BASE’;
#element {
url({@BASEPATH}/foo.png);
}

Turns out it doesn’t work in lessc. I use PHP Less CSS. (plessc)

Categories
post

jQuery Panel Slide Out

I was looking for some code to do slide out panels and found http://www.building58.com/examples/tabSlideOut.html

I created a patch that will allow you load the content through AJAX, instead of statically in the HTML.

In the HTML you need to add another element (DIV) that wraps the content to be loaded. Change the example on the page above with the two lines left aligned below.

     <div class=”slide-out-div”>
          <a class=”handle” href=”http://link-for-non-js-users.html”>Content</a>
          <h3>Contact me</h3>
<div id=”CONTENT_TO_REPLACE”>
          <p>Thanks for checking out my jQuery plugin, I hope you find this useful.</p>
          <p>This can be a form to submit feedback, or contact info</p>
</div>
     </div>

And then in the initialization step:

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js” type=”text/javascript”></script>
<script src=”http://tab-slide-out.googlecode.com/files/jquery.tabSlideOut.v1.3.js”></script>

     <script type=”text/javascript”>
      $(function(){
           $(‘.slide-out-div’).tabSlideOut({
                tabHandle: ‘.handle’, //class of the element that will become your tab
                pathToTabImage: ‘images/contact_tab.gif’, //path to the image for the tab //Optionally can be set using css
                imageHeight: ‘122px’, //height of tab image //Optionally can be set using css
                imageWidth: ’40px’, //width of tab image //Optionally can be set using css
      tabLocation: ‘left’, //side of screen where tab lives, top, right, bottom, or left
                speed: 300, //speed of animation
                action: ‘click’, //options: ‘click’ or ‘hover’, action to trigger animation
                topPos: ‘200px’, //position from the top/ use if tabLocation is left or right
                leftPos: ’20px’, //position from left/ use if tabLocation is bottom or top
                fixedPosition: false, //options: true makes it stick(fixed position) on scroll
‘contentURL’: ‘http://URL_TO_YOUR_CONTENT’,
‘contentDiv’: ‘CONTENT_TO_REPLACE’ //This is the id of the content box above in the HTML
          });
});

      </script>

Below is the patch to v1.3

— jquery.tabSlideOut.v1.3.js 2009-09-21 00:00:53.000000000 -0400
+++ jquery.tabSlideOut.ajax.js 2011-02-25 08:38:47.000000000 -0500
@@ -35,11 +35,19 @@
pathToTabImage: null,
imageHeight: null,
imageWidth: null,
– onLoadSlideOut: false
+ onLoadSlideOut: false,
+ contentLoaded: false,
+ contentURL: null,
+ contentDiv: ”
}, callerSettings||{});

settings.tabHandle = $(settings.tabHandle);
var obj = this;
+
+ if (settings.contentURL) {
+ settings.contentDiv = $(settings.contentDiv);
+ }
+
if (settings.fixedPosition === true) {
settings.positioning = ‘fixed’;
} else {
@@ -142,6 +150,10 @@
};

var slideOut = function() {
+
+ if (settings.contentURL && (settings.contentLoaded === false)) {
+ settings.contentDiv.load(settings.contentURL, function() { settings.contentLoaded = true; });
+ }

if (settings.tabLocation == ‘top’) {
obj.animate({top:’-3px’}, settings.speed).addClass(‘open’);

Categories
post

Mobile Website Design

What is mobile web design today? Is there a standard? Or is it just about smaller pages with less images? I don’t do mobile sites very often. With smart phones today, I personally expect the full version. I know I will have to zoom in and out, but I am usually looking for specific information. Do people really do much shopping on mobile?

So many questions. Time will tell.