Hi guys,
I posted much of this question, but if didn't include all the Zend stuff because I thought it'd be overkill, but now I'm thinking it's not easy to figure out an OO way of doing this without that code...
So with that said, please forgive the verbose code.
I'm learning how to use MVC and OO in general, and I have a website that is all in PHP but most of the pages are basic static pages.
I have already converted them all to views in Zend
Framework, and have the Controller and layout set. All is good there.
The one remaining page I have is the main reason I did this...it in fact uses Zend library (for gData connection and pulling info from a Google Calendar and displaying it on the page.
I don't know enough about this to know where to begin to refactor the code to fit in the Zend
Framework MVC model. Any help would be greatly appreciated!!
.phtml view page:
<div id="dhtmltooltip" align="left"></div>
<script src="../js/tooltip.js" type="text/javascript">
</script>
<div id="container">
<div id="conten">
<a name="C4"></a>
<?php
function get_desc_second_part(&$value) {
list(,$val_b) = explode('==',$value);
$value = trim($val_b);
}
function filterEventDetails($contentText) {
$data = array();
foreach($contentText as $row) {
if(strstr($row, 'When: ')) {
##cleaning "when" string to get date in the format "May 28, 2009"##
$data['duration'] = str_replace('When: ','',$row);
list($when, ) = explode(' to ',$data['duration']);
$data['when'] = substr($when,4);
if(strlen($data['when'])>13)
$data['when'] = trim(str_replace(strrchr($data['when'], ' '),'',$data['when']));
$data['duration'] = substr($data['duration'], 0, strlen($data['duration'])-4); //trimming time zone identifier (UTC etc.)
}
if(strstr($row, 'Where: ')) {
$data['where'] = str_replace('Where: ','',$row);
//pr($row);
//$where = strstr($row, 'Where: ');
//pr($where);
}
if(strstr($row, 'Event Description: ')) {
$event_desc = str_replace('Event Description: ','',$row);
//$event_desc = strstr($row, 'Event Description: ');
## Filtering event description and extracting venue, ticket urls etc from it.
//$event_desc = str_replace('Event Description: ','',$contentText[3]);
$event_desc_array = explode('|',$event_desc);
array_walk($event_desc_array,'get_desc_second_part');
//pr($event_desc_array);
$data['venue_url'] = $event_desc_array[0];
$data['details'] = $event_desc_array[1];
$data['tickets_url'] = $event_desc_array[2];
$data['tickets_button'] = $event_desc_array[3];
$data['facebook_url'] = $event_desc_array[4];
$data['facebook_icon'] = $event_desc_array[5];
}
}
return $data;
}
// load library
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');
// create authenticated HTTP client for Calendar service
$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "
[email protected]";
$pass = "xxxxxxxx";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
$gcal = new Zend_Gdata_Calendar($client);
$query = $gcal->newEventQuery();
$query->setUser('
[email protected]');
$secondary=true;
$query->setVisibility('private');
$query->setProjection('basic');
$query->setOrderby('starttime');
$query->setSortOrder('ascending');
//$query->setFutureevents('true');
$startDate=date('Y-m-d h:i:s');
$endDate="2015-12-31";
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$query->setMaxResults(30);
try {
$feed = $gcal->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getResponse();
}
?>
<h1><?php echo $feed->title; ?></h1>
<?php echo $feed->totalResults; ?> event(s) found.
<table width="90%" border="3" align="center">
<tr>
<td width="20%" align="center" valign="middle"><b>;DATE</b></td>
<td width="25%" align="center" valign="middle"><b>VENUE</b></td>
<td width="20%" align="center" valign="middle"><b>CITY</b></td>
<td width="20%" align="center" valign="middle"><b>DETAILS</b></td>
<td width="15%" align="center" valign="middle"><b>LINKS</b></td>
</tr>
<?php
if((int)$feed->totalResults>0) { //checking if at least one event is there in this date range
foreach ($feed as $event) { //iterating through all events
//pr($event);die;
$contentText = stripslashes($event->content->text); //striping any escape character
$contentText = preg_replace('/\<br \/\>[\n\t\s]{1,}\<br \/\>/','<br />',stripslashes($event->content->text)); //replacing multiple breaks with a single break
//die();
$contentText = explode('<br />',$contentText); //splitting data by break tag
$eventData = filterEventDetails($contentText);
$when = $eventData['when'];
$where = $eventData['where'];
$duration = $eventData['duration'];
$venue_url = $eventData['venue_url'];
$details = $eventData['details'];
$tickets_url = $eventData['tickets_url'];
$tickets_button = $eventData['tickets_button'];
$facebook_url = $eventData['facebook_url'];
$facebook_icon = $eventData['facebook_icon'];
$title = stripslashes($event->title);
echo '<tr>';
echo '<td width="20%" align="center" valign="middle" nowrap="nowrap">';
echo $when;
echo '</td>';
echo '<td width="20%" align="center" valign="middle">';
if($venue_url!='') {
echo '<a href="'.$venue_url.'" target="_blank">'.$title.'</a>';
} else {
echo $title;
}
echo '</td>';
echo '<td width="20%" align="center" valign="middle">';
echo $where;
echo '</td>';
echo '<td width="20%" align="center" valign="middle">';
$details = str_replace("\n","<br>",htmlentities($details));
$duration = str_replace("\n","<br>",$duration);
$detailed_description = "<b>When</b>: <br>".$duration."<br><br>";
$detailed_description .= "<b>Description</b>: <br>".$details;
echo '<a href="javascript:void(0);" onmouseover="ddrivetip(\''.$detailed_description.'\')" onmouseout="hideddrivetip()" onclick="return false">View Details</a>';
echo '</td>';
echo '<td width="20%" valign="middle">';
if(trim($tickets_url) !='' && trim($tickets_button)!='') {
echo '<a href="'.$tickets_url.'" target="_blank"><img src="'.$tickets_button.'" border="0" ></a>';
}
if(trim($facebook_url) !='' && trim($facebook_icon)!='') {
echo '<a href="'.$facebook_url.'" target="_blank"><img src="'.$facebook_icon.'" border="0" ></a>';
} else {
echo '......';
}
echo '</td>';
echo '</tr>';
}
} else { //else show 'no event found' message
echo '<tr>';
echo '<td width="100%" align="center" valign="middle" colspan="5">';
echo "No event found";
echo '</td>';
}
?>
</table>
<h3><a href="#pastevents">Scroll down for a list of past shows.</a></h3>
<br />
<a name="pastevents"></a>
<ul class="pastShows">
<?php
$startDate='2005-01-01';
$endDate=date('Y-m-d');
/*$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "
[email protected]";
$pass = "silverroof10";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
$gcal = new Zend_Gdata_Calendar($client);
$query = $gcal->newEventQuery();
$query->setUser('
[email protected]');
$query->setVisibility('private');
$query->setProjection('basic');*/
$query->setOrderby('starttime');
$query->setSortOrder('descending');
$query->setFutureevents('false');
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$query->setMaxResults(1000);
try {
$feed = $gcal->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getResponse();
}
if((int)$feed->totalResults>0) { //checking if at least one event is there in this date range
foreach ($feed as $event) { //iterating through all events
$contentText = stripslashes($event->content->text); //striping any escape character
$contentText = preg_replace('/\<br \/\>[\n\t\s]{1,}\<br \/\>/','<br />',stripslashes($event->content->text)); //replacing multiple breaks with a single break
$contentText = explode('<br />',$contentText); //splitting data by break tag
$eventData = filterEventDetails($contentText);
$when = $eventData['when'];
$where = $eventData['where'];
$duration = $eventData['duration'];
$title = stripslashes($event->title);
echo '<li class="pastShows">' . $when . " - " . $title . ", " . $where . '</li>';
}
}
?>
</div>
</div>