Only display this months data in Ushahidi

This is a simple hack to make Ushahidi display only the current months worth of data. This is useful if you have a large dataset with no real need to display historical data to your users.

Modify application/controllers/main.php lines 327 onwards.

                /* Commented out by John McLear */
                // $first_month = 1;
                // $last_month = 12;

                /* Added by John McLear as to only show the current month of data */
                $first_month = date('m');
                $last_month = date('m');
                /* End of new code */

                $i = 0;

                foreach ($query as $data)
                {
                        $date = explode('-',$data->dates);

                        $year = $date[0];
                        $month = $date[1];

                        /* Added by John McLear */
                        // Only includes from the month we are in now, yes this sucks but it works
                        if ($month == $first_month){

                                // Set first year
                                if($i == 0)
                                {
                                        $first_year = $year;
                                        $first_month = $month;
                                }

                                // Set last dates
                                $last_year = $year;
                                $last_month = $month;
                        }

                        $i++;
                }

PHP to create Elgg pages from a mysql database

Installation:
  1. Save to below script to the root of your Elgg install as importelgg.php
  2. Change the bits in bold to suit your environment.
  3. Log into your elgg site as the user you want to upload as then browse to the script.
Code:
<?php
// Modified from edit.php from Elgg doc’s by John McLear – www.mclear.co.uk
set_time_limit(0); // We dont want the script to time out
require_once ‘engine/start.php’;
// Load configuration
global $CONFIG;
$dbhost = ‘localhost‘; // The MySql Hostname
$dbuser = ‘root‘; // MySQL Username
$dbpass = ‘yourpassword‘; // MySQL Password
$conn = mysql_connect($dbhost, $dbuser, $dbpass, TRUE) or die (‘Error connecting to mysql’); // TRUE so we dont overwrite connection
$dbname2 = ‘mydatabase‘; // The databasename
mysql_select_db($dbname2);
$sql=”SELECT title,contents FROM pages“; // Get the content from the source database
$result=mysql_query($sql);
// Go through the records and create what you need from that
while ($row=mysql_fetch_array($result)) {
$title=$row[“title“]; //Set the title value from the mysql title field
$content=$row[“contents“]; // Same as above but for contents
gatekeeper();
set_context(‘pages’);
// Get group fields
$input = array();
foreach($CONFIG->pages as $shortname => $valuetype) {
$input[$shortname] = get_input($shortname);
if ($valuetype == ‘tags’)
$input[$shortname] = string_to_tag_array($input[$shortname]);
}
// Get parent
$parent_guid = (int)get_input(‘parent_guid’, 0);
// New or old?
$page = NULL;
$pages_guid = (int)get_input(‘pages_guid’);
if ($pages_guid)
{
$page = get_entity($pages_guid);
if (!$page->canEdit())
$page = NULL; // if we can’t edit it, go no further.
}
else
{
$page = new ElggObject();
if (!$parent_guid)
$page->subtype = ‘page_top’;
else
$page->subtype = ‘page’;
// New instance, so set container_guid
$container_guid = get_input(‘container_guid’,’8849‘); // Set the container GUID to a static user
$page->container_guid = $container_guid;
}
// Have we got it? Can we edit it?
if ($page instanceof ElggObject)
{
// Save fields – note we always save latest description as both description and annotation
if (sizeof($input) > 0)
{
foreach($input as $shortname => $value) {
if ((!$pages_guid) || (($pages_guid) && ($shortname != ‘title’)))
$page->$shortname = $value;
}
}
// Validate create
$page->title = $title;
if (!$page->title)
{
register_error(elgg_echo(“pages:notitle”));
forward($_SERVER[‘HTTP_REFERER’]);
exit;
}
// Access ids (Make it public)
$page->access_id = 2;
// Get the content
$page->description = $content;
// Write access id (Make it public)
$page->write_access_id = 2;
// Set parent
$page->parent_guid = $parent_guid;
// Ensure ultimate owner
$page->owner_guid = ($page->owner_guid ? $page->owner_guid : $_SESSION[‘user’]->guid);
// finally save
if ($page->save())
{
// Now save description as an annotation
$page->annotate(‘page’, $page->description, $page->access_id);
system_message(elgg_echo(“pages:saved”));
//add to river
add_to_river(‘river/object/page’,’create’,$_SESSION[‘user’]->guid,$page->guid);
echo “$title – DONE<br/>”;
}
else
register_error(elgg_echo(‘pages:notsaved’));
}
else
{
register_error(elgg_echo(“pages:noaccess”));
}
usleep(250000); // Just a little rest not to be overspammy
}
?>

A thumbnailer that works – IIS & PHP

About:

This application downloads a copy of a websites screen capture and creates a small thumbnail. You can see this thumbnailer in action here.

Requirements:
  • IIS on Server 2003/8+
  • PHP (tested working) – To test PHP create a .php file that includes and browse to the file in IE
  • A fully updated IE with a fully updated java & flash (Test by visiting sites)
When you install PHP ensure that PHP GB Library is installed
This application is a modified version of http://www.zubrag.com/scripts/website-thumbnail-generator.php – It relies on IE Capt which is included in the package but is also available from http://iecapt.sourceforge.net/
Installation:
  1. Download it here
  2. Extract the application to c:\inetpub\wwwroot\th
  3. Check that webthumb.php is in c:\inetpub\wwwroot\th
  4. Create c:\caps and set everyone to full control (This will be where the screen caps are stored)
  5. Browse to http://127.0.0.1/th/webthumb.php?url=http://test.com – After a few seconds you should see the thumbnail of test.com
  6. To put a thumbnail on your website simply copy/paste this <img src=”http://yourhostname.com/th/webthumb.php?url=http://thumbnailyouwant.com” /> Replacing yourhostname.com with the hostname of the server hosting this application and thumbnailyouwant with the url of the website you want to thumbnail.
Lastly you can add a level of security by commenting out the line if (0 == 0){} in webthumb.php, afterwards it should look like //if (0 == 0){}. Once this is done you will need to remove the commented lines above that begins with if(stri…. and replace primarygamesarena.com with the URL of your website that you will want thumbnailed images on. This will stop any site other than your own using your thumbnailer application.

Add to my calendar script

I needed a simple one click method to create a calendar event that people could put straight into google calendars and outlook, this function supports outlook, google calendars is done w/ a simple google api function/call that should be treated separately.
I need to create these calendar events dynamically when a page is requested, I was looking for a free downloadable javascript or something that would have this bundled in but I couldn’t find anything for free that did what I wanted so here it is..
You have to pass it startdate, enddate & name in the right format, it’s not that complex to figure out..
In this example I’m getting the values from mysql and creating the code from that, a loto f this code is borrowed from http://sgowtham.net/blog/2008/05/26/php-mysql-ical-ics/ – he is mostly to thank.
You will need to modify the 1203 part too to create a unique file name but that should be easy with a little bit of php knowledge. Writing to the file system then reading it back was the only way I knew to do this, feel free to enlighten me of another way.
Here goes:

<?php
$id=$_GET[‘id’];
// MODIFY THIS LINE — I get $id as a param

include ‘mysql_connect.php’;
// MODIFY THIS LINE — include any files you need for mysql to query
?>

<?php
$ics_contents = “BEGIN:VCALENDAR\n”;
$ics_contents .= “VERSION:2.0\n”;
$ics_contents .= “PRODID:PHP\n”;
$ics_contents .= “METHOD:PUBLISH\n”;
$name = “Awesome”;
$ics_contents .= “X-WR-CALNAME:$name Holiday Dates\n”;

# Change the timezone as well daylight settings if need be
$ics_contents .= “X-WR-TIMEZONE:America/New_York\n”;
$ics_contents .= “BEGIN:VTIMEZONE\n”;
$ics_contents .= “TZID:America/New_York\n”;
$ics_contents .= “BEGIN:DAYLIGHT\n”;
$ics_contents .= “TZOFFSETFROM:-0500\n”;
$ics_contents .= “TZOFFSETTO:-0400\n”;
$ics_contents .= “DTSTART:20070311T020000\n”;
$ics_contents .= “RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\n”;
$ics_contents .= “TZNAME:EDT\n”;
$ics_contents .= “END:DAYLIGHT\n”;
$ics_contents .= “BEGIN:STANDARD\n”;
$ics_contents .= “TZOFFSETFROM:-0400\n”;
$ics_contents .= “TZOFFSETTO:-0500\n”;
$ics_contents .= “DTSTART:20071104T020000\n”;
$ics_contents .= “RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\n”;
$ics_contents .= “TZNAME:EST\n”;
$ics_contents .= “END:STANDARD\n”;
$ics_contents .= “END:VTIMEZONE\n”;

$sql=”select * from sh_dates where id = ‘$id'”;
// MODIFY THIS LINE — obvious.

$result=mysql_query($sql);
while ($row=mysql_fetch_array($result))
{
$id=$row[“id”];
// MODIFY THIS LINE —

$term=$row[“term”];
// MODIFY THIS LINE —

$start_date=$row[“startdate”];
// MODIFY THIS LINE —

$end_date=$row[“enddate”];
// MODIFY THIS LINE —

$name = “Event at Awesome”;
// MODIFY THIS LINE —

// $id = $schedule_details[‘ID’];
// $start_date = $schedule_details[‘StartDate’];
// $start_time = $schedule_details[‘StartTime’];
// $end_date = $schedule_details[‘EndDate’];
// $end_time = $schedule_details[‘EndTime’];
// $category = $schedule_details[‘Category’];

// $location = $schedule_details[‘Location’];
// $description = $schedule_details[‘Description’];

# Remove ‘-‘ in $start_date and $end_date
$estart_date = str_replace(“-“, “”, $start_date);
$eend_date = str_replace(“-“, “”, $end_date);

# Remove ‘:’ in $start_time and $end_time
$estart_time = str_replace(“:”, “”, $start_time);
$eend_time = str_replace(“:”, “”, $end_time);

# Replace some HTML tags
$name = str_replace(“<br>”, “\\n”, $name);
$name = str_replace(“&”, “&”, $name);
$name = str_replace(“→”, “–>”, $name);
$name = str_replace(“←”, “<–“, $name);
$name = str_replace(“,”, “\\,”, $name);
$name = str_replace(“;”, “\\;”, $name);

$location = str_replace(“<br>”, “\\n”, $location);
$location = str_replace(“&”, “&”, $location);
$location = str_replace(“→”, “–>”, $location);
$location = str_replace(“←”, “<–“, $location);
$location = str_replace(“,”, “\\,”, $location);
$location = str_replace(“;”, “\\;”, $location);

$description = str_replace(“<br>”, “\\n”, $description);
$description = str_replace(“&”, “&”, $description);
$description = str_replace(“→”, “–>”, $description);
$description = str_replace(“←”, “<–“, $description);
$description = str_replace(“<em>”, “”, $description);
$description = str_replace(“</em>”, “”, $description);

# Change TZID if need be
$ics_contents .= “BEGIN:VEVENT\n”;
$ics_contents .= “DTSTART;TZID=America/New_York” . $estart_date . “T”. $estart_time . “\n”;
$ics_contents .= “DTEND:” . $eend_date . “T”. $eend_time . “\n”;
$ics_contents .= “DTSTAMP:” . date(‘Ymd’) . “T”. date(‘His’) . “Z\n”;
$ics_contents .= “LOCATION:” . $location . “\n”;
$ics_contents .= “DESCRIPTION:” . $description . “\n”;
$ics_contents .= “SUMMARY:” . $name . “\n”;
$ics_contents .= “UID:” . $id . “\n”;
$ics_contents .= “SEQUENCE:0\n”;
$ics_contents .= “END:VEVENT\n”;
}

$ics_contents .= “END:VCALENDAR\n”;

# File to write the contents
$ics_file = ‘/var/www/ics/1203.ics’;
// MODIFY THIS LINE —

if (is_writable($ics_file)) {
if (!$handle = fopen($ics_file, ‘w’)) {
echo “Cannot open file ($ics_file)\n\n”;
exit;
}

# Write $ics_contents to opened file
if (fwrite($handle, $ics_contents) === FALSE) {
echo “Cannot write to file ($ics_file)\n\n”;
exit;
}

# echo “Success, wrote to <b>1203.ics</b><br>\n\n”;
// MODIFY THIS LINE —

fclose($handle);

} else {
echo “The file <b>$ics_file</b> is not writable\n\n”;
}
?>

<?php
//header( ‘Location: http://mywebsite.com/ics/1203.ics’ ) ;
// MODIFY THIS LINE —

echo $ics_contents;
?>

By clicking this php page a user will be presented with a downloable/clickable .ics file which can be imoprted into an outlook calendar.