[cvs] [Wiki] changed: ScreenScrapingKronolith

Wiki Guest wikiguest at horde.org
Mon Jul 20 20:01:36 UTC 2009


guest [216.158.163.227]  Mon, 20 Jul 2009 16:01:36 -0400

Modified page: http://wiki.horde.org/ScreenScrapingKronolith
New Revision:  2.0
Change log:  Adding content for screen scraping

@@ -1,2 +1,122 @@
  This how-to explains how to integrate public kronolith calendars  
with your other websites through screen scraping with PHP.  There are  
other methods of embedding kronolith calendars with javascript, but  
they don't provide the same level of functionality.

+Assumptions:
+# Your horde installation is located in '''/calendar'''
+# You have a file named '''calendar.horde.inc.php''' in your include path
+
+
+This setup uses two files, one to provide the necessary functions and  
another that you can put anywhere on your site (or multiple places)  
where you'd like the calendar displayed.
+
+The file used to display the calendars is fairly simple, it includes  
a link to appropriate stylesheets, the call to the calendar with  
associated config variables and if necessary header and footer  
information.  This example is designed to go inside the <body> tags on  
your page.
+'''Place this in the php file where you would like to have the  
calendar display'''
+<code type="php">
+<link href="/calendars/kronolith/themes/categoryCSS.php"  
rel="stylesheet" type="text/css" />
+
+<?php
+// kronolith location
+$url = "http://" . $_SERVER['HTTP_HOST'] . "/calendars/kronolith/";
+// this is an array of calendar ids you would like to display (you  
can get this by clicking on the lightbulb in kronolith)
+$display_cals = array('5a56e1e7765e778876dd389e4b35a66f');
+$default_view = "month";
+// bring in the functions
+require_once('calendar.horde.inc.php');
+// display the calendar
+post_calendar($url, $display_cals, $default_view);
+</code>
+
+'''Place this file in your php include path''' or adjust the  
require_once call above
+<code type="php">
+<?
+function post_calendar($url_base, $display_cals, $default_view) {
+
+// date cases
+// Day
+if(isset($_REQUEST['mday']) && isset($_REQUEST['month']) &&  
isset($_REQUEST['year'])) {
+	 $time = 'month=' . $_REQUEST['month'] . '&mday=' .  
$_REQUEST['mday'] . '&year=' . $_REQUEST['year'];
+}
+// Week & Work Week
+else if (isset($_REQUEST['week']) && isset($_REQUEST['year'])) {
+	 $time = 'week=' . $_REQUEST['week'] . '&year=' . $_REQUEST['year'];
+}
+// Month
+else if (isset($_REQUEST['month']) && isset($_REQUEST['year'])) {
+	 $time = 'month=' . $_REQUEST['month'] . '&year=' . $_REQUEST['year'];
+}
+// Year
+else if (isset($_REQUEST['year'])) {
+	 $time = 'year=' . $_REQUEST['year'];
+}
+else if (isset($_REQUEST['timestamp'])) {
+	$time = 'timestamp=' . $_REQUEST['timestamp'];
+} else {
+	$time = 'timestamp=' . time();
+}
+if(!isset($_REQUEST['view'])) {
+	$_REQUEST['view'] = $default_view;
+}
+
+#construct the URL we want to get content from
+$view = $_REQUEST['view'];
+
+
+foreach ($display_cals as $display_cal) {
+	$calendars .= '&display_cal[]=' . $display_cal;
+}
+
+if($_REQUEST['view'] == 'event') {
+	$targetfile = $url_base . $view . ".php?" . $time . '&calendar=' .  
$_REQUEST['calendar'] . '&eventID=' . $_REQUEST['eventID'];
+} else {
+	$targetfile = $url_base . $view . ".php?" . $time . $calendars;
+}
+//print $targetfile;
+
+
+$targetfile = str_replace(" ","%20",$targetfile);
+$file = file($targetfile);
+$calendarfile = implode('',$file);
+
+$calendar_array = explode("<body>", $calendarfile);
+$calendar_array = explode("</body>", $calendar_array[1]);
+$calendarfile = $calendar_array[0];
+
+// Convert day/week/month/year links to local links
+$calendarfile = str_replace('/calendars/kronolith/day.php?',  
$_SERVER['SCRIPT_URL'] . '?view=day' . $calendars . '&',$calendarfile);
+$calendarfile = str_replace('/calendars/kronolith/week.php?',  
$_SERVER['SCRIPT_URL'] . '?view=week'  . $calendars .  
'&',$calendarfile);
+$calendarfile = str_replace('/calendars/kronolith/workweek.php?',  
$_SERVER['SCRIPT_URL'] . '?view=workweek'  . $calendars .  
'&',$calendarfile);
+$calendarfile = str_replace('/calendars/kronolith/month.php?',  
$_SERVER['SCRIPT_URL'] . '?view=month'  . $calendars .  
'&',$calendarfile);
+$calendarfile = str_replace('/calendars/kronolith/year.php?',  
$_SERVER['SCRIPT_URL'] . '?view=year'  . $calendars .  
'&',$calendarfile);
+$calendarfile = str_replace('/calendars/kronolith/academicyear.php?',  
$_SERVER['SCRIPT_URL'] . '?view=academicyear'  . $calendars .  
'&',$calendarfile);
+
+// Deal with individual events
+$calendarfile = str_replace('/calendars/kronolith/event.php?',  
$_SERVER['SCRIPT_URL'] . '?view=event' . '&',$calendarfile);
+
+
+// Cleanup display
+// Remove the category lines
+$calendarfile = preg_replace('/<!-- category  
-->.*\s*.*\s*.*\s*.*\s*.*\s*.*\s/', '' ,$calendarfile);
+// Remove the owner lines
+$calendarfile = preg_replace('/<!-- owner  
-->.*\s*.*\s*.*\s*.*\s*.*\s*/', '' ,$calendarfile);
+// Remove the status lines
+$calendarfile = preg_replace('/<!-- status  
-->.*\s*.*\s*.*\s*.*\s*.*/', '' ,$calendarfile);
+// Remove alarm and created lines
+$calendarfile = preg_replace('/<!-- alarm  
-->.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*/', '<tr><td  
style="width: 10%"></td><td style="width:90%"></td></tr>'  
,$calendarfile);
+// Clean up quotes
+$calendarfile = stripslashes($calendarfile);
+// Remove titles because the are broken
+$calendarfile = preg_replace('/(title=")(.*?)(")/e', "", $calendarfile);
+// Remove script files because they are broken too
+$calendarfile = str_replace('<script type="text/javascript"  
src="/calendars/kronolith/js/QuickFinder.js"></script>', '',  
$calendarfile);
+$calendarfile = str_replace('<script type="text/javascript"  
src="/calendars/kronolith/js/redbox.js"></script>', '', $calendarfile);
+$calendarfile = str_replace('<script type="text/javascript"  
src="/calendars/kronolith/js/calendar-panel.js"></script>', '',  
$calendarfile);
+
+?>
+
+<div class="calendar">
+<?
+echo $calendarfile;
+?>
+</div>
+
+<?
+}
+</code>



More information about the cvs mailing list