' . "\n";
}
/**
* Writes the HTML footer for the demo.
*
* NOTE: We would normally keep the HTML/CSS markup separate from the business
* logic above, but have decided to include it here for simplicity of
* having a single-file sample.
* @return void
*/
function printHTMLFooter() {
print '
' . "\n";
}
/**
* We arrive here when the user first comes to the form. The first step is
* to have them get a single-use token.
*/
function showIntroPage() {
$next_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$scope = ITEMS_FEED_URI;
$secure = false;
$session = true;
$redirect_url = Zend_Gdata_AuthSub::getAuthSubTokenUri($next_url,
$scope,
$secure,
$session);
printHTMLHeader();
print '
Before you get started, please sign in to your personal Google Base account.
' . "\n" .
'
' . "\n";
printHTMLFooter();
}
/**
* Prints the table of recipes the user has already entered
* on the left-hand side of the page.
* @param string $token The session token
* @return void
*/
function showRecipeListPane($token) {
$client = Zend_Gdata_AuthSub::getHttpClient($token);
$gdata = new Zend_Gdata_Gbase($client);
try {
$feed = $gdata->getGbaseItemFeed(ITEMS_FEED_URI . '/-/testrecipes');
print '
' . "\n";
/* Create an Edit button for each existing recipe. */
print '
' . "\n" .
'' . "\n" .
'
' . "\n";
/* Create a Delete button for each existing recipe. */
print '
' . "\n" .
'' . "\n" .
'
' . "\n" .
'
' . "\n";
}
}
/* Create a "Delete all" button" to demonstrate batch requests. */
print '
' . "\n" .
'
' . "\n";
print '
' . "\n";
print '
' . "\n";
} catch (Zend_Gdata_App_Exception $e) {
showMainMenu("Error: " . $e->getMessage(), $token);
}
}
/**
* Prints a small form allowing the user to insert a new
* recipe.
* @param string $sessionToken A session token
* @return void
*/
function showRecipeInsertPane($sessionToken) {
global $cuisines;
print '
' . "\n" .
'
' . "\n" .
'
' .
'Insert a new recipe
' . "\n" .
'
' . "\n" .
'
' . "\n";
}
/**
* Shows a menu allowing the user to update an existing
* recipe with the Base API update feature.
* @return void
*/
function showEditMenu() {
global $cuisines;
$client = Zend_Gdata_AuthSub::getHttpClient($_POST['token']);
$gdata = new Zend_Gdata_Gbase($client);
try {
$feed = $gdata->getGbaseItemFeed(ITEMS_FEED_URI);
foreach ($feed->entries as $feed_entry) {
$editLink = $feed_entry->link[2]->href;
if ($editLink == $_POST['edit']) {
$baseAttributeArr = $feed_entry->getGbaseAttribute('cooking_time');
if (isset($baseAttributeArr[0]) && is_object($baseAttributeArr[0])) {
$splitCookingTime = explode(' ', $baseAttributeArr[0]->text);
}
$baseAttributeArr = $feed_entry->getGbaseAttribute('cuisine');
// Cuisine can have multiple entries
if (isset($baseAttributeArr[0]) && is_object($baseAttributeArr[0])) {
$cuisine = $baseAttributeArr[0]->text;
}
$baseAttributeArr = $feed_entry->getGbaseAttribute('serving_count');
// $serving_count can have multiple entries
if (isset($baseAttributeArr[0]) && is_object($baseAttributeArr[0])) {
$serving_count = $baseAttributeArr[0]->text;
}
$main_ingredient = $feed_entry->getGbaseAttribute('main_ingredient');
// Main_ingredient can have multiple entries
if (is_array($main_ingredient)) {
$main_ingredient = $main_ingredient[0]->text;
}
printHTMLHeader();
print '
' . "\n";
print '
' .
'
Edit recipe:
' .
'
' . "\n";
print "
' . "\n";
printHTMLFooter();
break;
}
}
} catch (Zend_Gdata_App_Exception $e) {
showMainMenu($e->getMessage(), $_POST['token']);
}
}
/**
* Displays both the "List of current recipes" and
* "Insert a new recipe" panels in a single table.
* @param string $tableTitle The title to display in the html table
* @param string $sessionToken A session token
* @return void
*/
function showMainMenu($tableTitle, $sessionToken) {
printHTMLHeader();
print '