b2evolution - comment forms stalling - version 4+
Jun 17th
This is a b2evolution blog. There’s a second blog running from the same installation, and the comment form was stalling on page load, displaying ‘Loading …’ and the icon, but never finishing.
The first action I took was to upgrade the blog. Many times, issues like that are resolved on an upgrade.
Unfortunately, that didn’t solve the problem.
Next, I reviewed the configuration of both blogs through the admin interface, taking care to clear the cache after each change.
Unfortunately this didn’t solve the problem either, so I grepped through the code until I found where the $baseurl is set. It is in these lines in conf/_basic_config.php. Uncommenting these lines solves the problem.
conf/_basic_config.php
// Use the following if you want to use the current domain:
if( isset($_SERVER['HTTP_HOST']) )
{ // This only works if HOSt provided by webserver (i-e DOES NOT WORK IN PHP CLI MODE)
$baseurl = ( (isset($_SERVER['HTTPS']) && ( $_SERVER['HTTPS'] != 'off' ) ) ?'https://':'http://')
.$_SERVER['HTTP_HOST'].'/';
}
Passing Structured Data from Perl to PHP
Jun 14th
After writing many lines of Perl to decode data returned from database queries which must then be passed back to PHP, I found JSON conversion routines which are much faster and more reliable. In addition, unlike my awkward Perl, they work!
::::::::::::::
test.pl
::::::::::::::
#!/usr/bin/perl
use strict;
use JSON::XS;
# Thanks to: http://stackoverflow.com/questions/8463919/how-to-convert-a-simple-hash-to-json-in-perl
my $json=JSON::XS->new->utf8->pretty->allow_nonref;
my %data=('one',1,'two',"bee's",'three',0,'four',('a','monkey','b','cat'));
my $json_text=$json->encode(\%data);
# Escape the single quotes
$json_text=~s/(')/\\$1/g;
# Remove carriage returns
$json_text=~s/(\n)//g;
print<<RETURN;
json=$json_text
RETURN
::::::::::::::
test.php
::::::::::::::
<?php
include 'Zend/Json.php';
$aResult=null;
$aResponseLines=$aResult=array();
$sResponse=`perl test.pl`;
$aResponseLines=explode("\n",$sResponse);
if (count($aResponseLines)>0)
foreach ($aResponseLines as $k => $v)
{
$e=strpos($v,'=');
if ($e!==false)
$aResult[substr($v,0,$e)]=substr($v,$e+1);
}
var_dump($aResult);
var_dump(Zend_Json::decode($aResult['json']));
bash Version Control Check-In
May 30th
To make it easier to copy code from a development server to a version control server, check the file, then check it in, I created a bash script.
This script is also supported with ssh keys so the password does not need to be entered with each copy request. Thanks to: http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/
#!/bin/bash
# This script requires three parameters
# server - The name of the server where the code will be retrieved from
# file - The name of the file. In this case, the path is hardcoded.
# comment - A comment to include when checking in the file
if [ $# -lt 3 ]; then
echo 'usage:'
echo ' ~/get.sh server file comment'
else
# Copy the file
scp root@$1.domain.com:/opt/system/web/portal/$2 NEW
# If the files can be compared
if [ -r NEW -a -r "$2" ]; then
# Create tmp file for the diff results
TMP=`mktemp`
diff NEW "$2" > "$TMP"
# If the files are different
if [ $? -ne 0 ]; then
more "$TMP"
echo -n 'Update? y/[n]? '
read
if [ $REPLY == 'y' ]; then
# Checkout the file
cleartool co -nc "$2"
# Copy the new file over
cp NEW $2
# Checkin the updated file
cleartool ci -c "$3" "$2"
else
echo 'no changes made'
fi
else
echo 'files are the same'
fi
rm $TMP
else
echo 'scp failed or files missing'
fi
fi
Thanks to:
http://www.cyberciti.biz/tips/shell-scripting-bash-how-to-create-temporary-random-file-name.html
Dynamic Banner - js and css
May 7th
This post provides code to create a dynamic banner which sources images from Flickr.
Using a dynamic banner has several advantages:
- The banner is assembled dynamically, it is more engaging
- The images aren’t stored or managed on local servers
- The banner images can be changed by modifying the images at the source
- It would be possible to customize the source of the images for demonstrations
- Clicking on the banner displays the image credits
This is an extension of the code listed in link above. It is running nicely with dojo 1.3.0, tested under IE7, FF11&12, and Chrome 17.
The banner is 160px high, and 1024px wide, it is overlaid with an image which includes a gradient to fade the banner images from full color to white, using transparency. The banner includes an icon for the product on the far right.
#header img,#header a
{
height:160px;
overflow:hidden;
}
#gradient-overlay
{
background:transparent url(images/banner.png) no-repeat;
height:160px;
width:1024px;
position:fixed;
}
#header
{
cursor:pointer;
height:160px;
width:100%;
margin:25px;
overflow:hidden;
}
#dlgCredit div p
{
display:none;
}
#dlgCredit div p:first-of-type,
#dlgCredit div p:nth-child(2)
{
display:block;
}
This is the javascript to create the banner. The remaining code should be collected from the link above.
The image list received from flickr is accessed randomly, using the splice function. This allows each banner to be created differently. Images are added to the banner until the width exceeds the width of the gradient overlay. The image credits are place in a dialog box.
function gotItems(items, request){
var list = dojo.byId("header");
if(list){
var span=dojo.create("span",{'id':'gradient-overlay'});
list.appendChild(span);
var width,pick,credit_text='',done=false;
width=span.clientWidth;
while (!done)
{
index=Math.floor(Math.random()*(items.length-1));
pick=items.splice(index,1);
if (pick.length>0)
{
var item=pick[0];
var image = dojo.create("img",
{ "src":flickrStore.getValue(item, "imageUrlMedium"),
"title": flickrStore.getValue(item, "title"),
"alt": flickrStore.getValue(item, "title")});
if ((image.width==0)||(image.width>width))
{
/* Limit the width of the banner */
dojo.destroy(image);
if (image.width>width)
done=true;
/* You can also continue to see if later images will fit */
}
else
{
width-=image.width;
list.appendChild(image);
var str=flickrStore.getValue(item,'description');
var n=str.indexOf('');
n=str.indexOf('',n+1);
var truncated=str.substr(0,n);
credit_text+='<div>'+truncated+'</div>';
}
}
else
done=true;
}
var credit=dojo.create("div",{'id':'credit'});
var dlgCredit=new dijit.Dialog({
'id': 'dlgCredit',
'content':credit_text},
'credit');
list.setAttribute('title','Click for image credits');
list.onclick=function(){dlgCredit.show()};
list.appendChild(credit);
}
The HTML creates the flickrStore and sets up the header div.
<div dojoType="dojox.data.FlickrStore" jsId="flickrStore"></div>
<div id="header"></div>
This post courtesy of Lyrix, Inc
dojox.data.FlickrStore - Source from favorites
May 7th
I wanted to use a favorites list on Flickr (http://flickr.com) as a source for images.
dojo 1.3.0’s dojox.data.FlickrStore sources images from a public photo feed:
reg.register("default",function(_2f){return true;},_2d+"photos_public.gne");
Since I only wanted to change the feed URL, I used the following code to indicate that the request should be made to the favorites feed.
var reg=dojox.data.FlickrStore.urlRegistry;
reg.unregister("default");
reg.register("default",function(a){
return true;
},"http://api.flickr.com/services/feeds/photos_faves.gne");