Ich habe nicht alle Posts in der Vergangenheit gelesen, vielleicht ist es ja schon erwähnt worden: die Emailadresse in account_name ist NICHT deine Google email sondern die Email, die im developer center unter der client ID.
db_host = "localhost"
db_name = "infoframe"
db_user = "root"
db_password = "passwort"
zendfw_path = "c:\xampp\htdocs\zendfw\library\"
google_api_path = "c:\xampp\htdocs\zendfw\google-api-php-client\"
image_width = 800
image_height = 600
; updateintervall der Plugins (Mail, Kalender, Wetter...) in Minuten
updatetime = 30
[CalendarPlugin]
client_id = "381048971205-c2a97vdgml3oi9q8ev5vdutsvn4f538p.apps.googleusercontent.com"
account_name = "381048971205-c2a97vdgml3oi9q8ev5vdutsvn4f538p@developer.gserviceaccount.com"
project_name = "InfoFrame"
key_file= "c:\xampp\htdocs\infoframe\Infoframe-3999c7729ff4.p12"
calendar_ID_1 = "de.german#[email protected]"
calendar_ID_color_1 = "#ffff00"
number_of_days = 7
<?php
/***************************************************************************
* InfoFrame (image generator for digital picture frames)
* Copyright (C) 2009 Tobias Kolb
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
***************************************************************************/
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
class CalendarPlugin implements IPlugin
{
private $dbconn = NULL;
private $config = NULL;
public function __construct($dbconn, $config) {
$this->dbconn = $dbconn;
$this->config = $config;
}
public function doUpdate()
{
require_once 'zendfw/google-api-php-client/autoload.php';
// get calendar entries
session_start();
$client_id = $this->config['client_id'];
$service_account_name = $this->config['account_name'];
try
{
$client = new Google_Client();
$client->setApplicationName($this->config['project_name']);
$cal = new Google_Service_Calendar($client);
}
catch (Exception $e)
{
die ('Folgender Fehler trat auf: ' . $e->getMessage());
}
if (isset($_SESSION['service_token']))
$client->setAccessToken($_SESSION['service_token']);
$key = file_get_contents($this->config['key_file']);
$cred = new Google_Auth_AssertionCredentials($service_account_name, array('https://www.googleapis.com/auth/calendar'), $key);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired())
$client->getAuth()->refreshTokenWithAssertion($cred);
$_SESSION['service_token'] = $client->getAccessToken();
//set startDate, endDate, eventParams
$cal_date = new DateTime('NOW');
$startDate = date_format($cal_date, DateTime::W3C);
$cal_date = date_modify($cal_date, "+".$this->config['number_of_days']." day");
$endDate = date_format($cal_date, DateTime::W3C);
$eventParams = array('timeMin' => $startDate,
'timeMax' => $endDate,
'singleEvents' => 'true');
//get Calendar Id´s
$calendarList = $cal->calendarList->listCalendarList();
// delete all old calendar entries
mysql_query("START TRANSACTION", $this->dbconn);
$query = "Delete from if_calendar";
mysql_query($query, $this->dbconn) or die('Error, delete query failed');
// get all calendars
foreach ($calendarList->getItems() as $calendar)
{
$calendarID = $calendar->getID();
$color = $calendar->getBackgroundColor();
$entries = $cal->events->listEvents($calendarID, $eventParams);
foreach ($entries->getItems() as $entry)
{
if (!empty($entry['modelData']['start']['dateTime']))
{
$begin = strtotime($entry['modelData']['start']['dateTime']);
$end = strtotime($entry['modelData']['end']['dateTime']);
}
else
{
$begin = strtotime($entry['modelData']['start']['date']);
$end = strtotime($entry['modelData']['end']['date']);
}
$title = $entry->getSummary();
$location = $entry->getLocation();
$this->addCalendar($color, $begin, $end, $title, $location);
}
}
// get all public calendars
$calender_num = 0;
while ($calendarID = $this->config['calendar_ID_' . ++$calender_num])
{
$color = $this->config['calendar_ID_color_' . $calender_num];
$entries = $cal->events->listEvents($calendarID, $eventParams);
foreach ($entries->getItems() as $entry)
{
if (!empty($entry['modelData']['start']['dateTime']))
{
$begin = strtotime($entry['modelData']['start']['dateTime']);
$end = strtotime($entry['modelData']['end']['dateTime']);
}
else
{
$begin = strtotime($entry['modelData']['start']['date']);
$end = strtotime($entry['modelData']['end']['date']);
}
$title = $entry->getSummary();
$location = $entry->getLocation();
$this->addCalendar($color, $begin, $end, $title, $location);
}
}
mysql_query("COMMIT", $this->dbconn);
}
public function doOutput($image, $style, $updateData, &$yoffset) {
if ($updateData)
$this->doUpdate();
$query = "SELECT * FROM `if_calendar` WHERE (`end` > NOW()) ORDER BY `begin` ASC";
$result = mysql_query($query, $this->dbconn);
if (mysql_num_rows($result) > 0) {
// define styles
$opt_header = array(
'width' => imagesx($image)-290,
'line_height' => 8,
'align' => ALIGN_LEFT
);
$opt_day = array(
'width' => imagesx($image)-290,
'height' => 14,
'line_height' => 14,
'align' => ALIGN_LEFT
);
$opt_entry = array(
'width' => imagesx($image)-290,
'height' => 12,
'line_height' => 12,
'align' => ALIGN_LEFT,
'word_wrap_hyphen' => '...',
'aggressive_word_wrap' => true,
);
// print header
imagettftextboxopt($image, 18, 0, 50, $yoffset, $style['textcolor'], $style['font'], "Nächste Termine", $opt_header);
$icon = ImageCreateFromPNG ( 'resources/icons/clock.png' );
ImageCopy($image, $icon, 20, $yoffset-12, 0, 0, imagesx($icon), imagesy($icon));
ImageDestroy($icon);
$yoffset += 14;
// print calendar
$counter = 0;
$formatDate = "%d.%m.%Y";
$formatTime = "%H:%M";
$today = strftime( $formatDate );
$tomorrow = strftime( $formatDate, strtotime("+1 day", time() ) );
$currently_displayed_day = 0;
while ($row = mysql_fetch_assoc($result)) {
$counter++;
// if end of screen is reached and more than one items left -> cut off and show hint "x more appointments..."
$rest = (mysql_num_rows($result) - $counter) + 1;
if (($yoffset >= (imagesy($image) - 36)) && ($rest > 1)) {
$text = "... $rest weitere Termine";
imagettftextboxopt($image, 14, 0, 24, $yoffset, $style['textcolor'], $style['fontb'], $text, $opt_entry);
$yoffset += 0;
break;
}
// print day name
$begin_date = strftime( $formatDate, strtotime($row['begin']));
// if begin day is before today set begin to today
if (strtotime($begin_date) < strtotime($today))
$begin_date = $today;
// now if begin is after $currently_displayed_day update $currently_displayed_day
if (strtotime($begin_date) > $currently_displayed_day) {
// update currently_displayed_day
$currently_displayed_day = strtotime($begin_date);
// print day name
if( $begin_date == $today )
$dayname = "Heute";
else if( $begin_date == $tomorrow )
$dayname = "Morgen";
else
//$dayname = strftime("%A, ".$formatDate, strtotime($begin_date));
$dayname = datumDeutsch(strftime("%A, ".$formatDate, strtotime($begin_date)));
imagettftextboxopt($image, 14, 0, 50, $yoffset-1, $style['textcolor'], $style['fontb'], $dayname, $opt_day);
$yoffset += 22;
}
// build appointment time text
$end_date = strftime( $formatDate, strtotime($row['end']));
$begin_time = strftime( $formatTime, strtotime($row['begin']));
$end_time = strftime( $formatTime, strtotime($row['end']));
$text = $row['title'];
if ($row['location'] != null)
$text = $text . ", " . $row['location'];
if (($begin_time == "00:00") && ($end_time == "00:00")) {
// all day event (substract 1 second to get the real end date at 23:59)
$end_date = strftime( $formatDate, strtotime($row['end'])-1);
// if all day event is longer than one day -> print end date
if (strtotime($end_date) != $currently_displayed_day)
$text = $text." (bis ".$end_date.")";
} else {
// normal event with start and end time
$text = $text." (".$begin_time." - ";
// if event ends not this day -> display end date additionally to time
if (strtotime($end_date) != $currently_displayed_day)
$text = $text.$end_date.", ";
$text = $text.$end_time.")";
}
// roundboxtrans_middel($image, $xleft, $xend, $yoffset+2, $yoffset_abstand, $yoffset_end, $inhalt_zeilen_hoehe);
// roundboxtrans_bottom($image, $xleft, $xend, $yoffset, $yoffset_diff, $yoffset_abstand, $yoffset_end, $radius, $bottom_zeilen_hoehe);
/*
if ($letzter_eintrag == $currently_displayed_day) {
if (strlen($text) >= 15) $xoffset = 150;
$xoffset += 130;
$yoffset -= 25;
}else{
$xoffset = 0;
roundboxtrans_middel($image, $xleft, $xend, $yoffset, $yoffset_abstand+1, $yoffset_end, $inhalt_zeilen_hoehe+1);
}
*/
// ------------------------------------------- Müllabfuhr----------------------------------------
if (($row['color']) == "#711616") {
if (strpos($row['title'], 'Blaue') !== false)
$icon = ImageCreateFromPNG ( 'resources/icons/tonne_blau.png' );
if (strpos($row['title'], 'Biotonne') !== false)
$icon = ImageCreateFromPNG ( 'resources/icons/tonne_gruen.png' );
if (strpos($row['title'], 'Gelber Sack') !== false)
$icon = ImageCreateFromPNG ( 'resources/icons/gelber_sack.png' );
if (strpos($row['title'], 'Restabfall') !== false)
$icon = ImageCreateFromPNG ( 'resources/icons/tonne_schwarz.png' );
ImageCopy($image, $icon, $xoffset+25, $yoffset-20, 0, 0, imagesx($icon), imagesy($icon));
ImageDestroy($icon);
}
// ------------------------------------------- Geburtstag ----------------------------------------
if (($row['color']) == "#711616") {
if (strpos($row['title'], 'Geburtstag') !== false)
$icon = ImageCreateFromPNG ( 'resources/icons/birth.png' );
ImageCopy($image, $icon, $xoffset+25, $yoffset-15, 0, 0, imagesx($icon), imagesy($icon));
ImageDestroy($icon);
}
// ------------------------------------------- Namenstag ----------------------------------------
if (($row['color']) == "#711616") {
$icon = ImageCreateFromPNG ( 'resources/icons/name.png' );
ImageCopy($image, $icon, $xoffset+27, $yoffset+1, 0, 0, imagesx($icon), imagesy($icon));
ImageDestroy($icon);
} else {
// ------------------------------------------- Standard - Button ----------------------------------------
// determine button color
$colorArray = htmlColorToRgb($row['color']);
$color = ImageColorAllocate ($image, $colorArray[0], $colorArray[1], $colorArray[2]);
// print appointment text and button
drawGlassButton($image, $color, $xoffset+30, $yoffset-2);
}
imagettftextboxopt($image, 12, 0, $xoffset+50, $yoffset-6, $style['textcolor'], $style['font'], $text, $opt_entry);
$yoffset += 10;
$letzter_eintrag = $currently_displayed_day;
}
$yoffset += 2;
}
// roundboxtrans_bottom($image, $xleft, $xend, $yoffset, $yoffset_diff, $yoffset_abstand+16, $yoffset_end, $radius, $bottom_zeilen_hoehe);
mysql_free_result($result);
}
private function addCalendar($color, $begin, $end, $title, $location) {
$query = "INSERT INTO `if_calendar` (`id`, `color`, `begin`, `end`, `title`, `location`)
VALUES (NULL,
'".mysql_real_escape_string($color)."', FROM_UNIXTIME($begin), FROM_UNIXTIME($end),
'".mysql_real_escape_string($title)."',
'".mysql_real_escape_string($location)."'
)";
mysql_query($query, $this->dbconn) or die('CalendarPlugin: '.mysql_error());
}
}
Fatal error: Using $this when not in object context in C:\xampp\htdocs\infoframe\test.php on line 11
<?php
// ********
// bitte check nochmal hier, ob der Pfad stimmt
require_once 'c:/xampp/htdocs/zendfw/google-api-php-client/autoload.php';
session_start();
// ********
// bitte check nochmal hier, ob die ID stimmt
$client_id = "381048971205-c2a97vdgml3oi9q8ev5vdutsvn4f538p.apps.googleusercontent.com";
// ********
// bitte check nochmal hier, ob die ID stimmt
$service_account_name = "381048971205-c2a97vdgml3oi9q8ev5vdutsvn4f538p@developer.gserviceaccount.com";
try {
$client = new Google_Client();
// ********
// bitte check nochmal hier, ob der Name stimmt
$client->setApplicationName('InfoFrame');
$service = new Google_Service_Calendar($client);
}
catch (Exception $e) {
die ('Folgender Fehler trat auf: ' . $e->getMessage());
}
if (isset($_SESSION['service_token']))
$client->setAccessToken($_SESSION['service_token']);
// ********
// bitte check nochmal hier, ob der Pfad stimmt
$key = file_get_contents("c:/xampp/htdocs/infoframe/Infoframe-3999c7729ff4.p12");
$cred = new Google_Auth_AssertionCredentials($service_account_name, array('https://www.googleapis.com/auth/calendar'), $key);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired())
$client->getAuth()->refreshTokenWithAssertion($cred);
$_SESSION['service_token'] = $client->getAccessToken();
$now = new DateTime('NOW');
$clone = clone $now;
$clone = date_modify($clone, '+1 month');
$startDate = date_format($now, DateTime::W3C);
$endDate = date_format($clone, DateTime::W3C);
$eventParams = array('timeMin' => $startDate,
'timeMax' => $endDate,
'singleEvents' => 'true');
//get Calendar Id´s
$calendarList = $service->calendarList->listCalendarList();
echo '<table border="1">';
foreach ($calendarList->getItems() as $calendarListEntry) {
$calendarID = $calendarListEntry->getID();
$color = $calendarListEntry->getBackgroundColor();
$events = $service->events->listEvents($calendarID, $eventParams);
foreach ($events->getItems() as $event) {
if (!empty($event['modelData']['start']['dateTime'])) {
$begin = date_format(date_create($event['modelData']['start']['dateTime']), 'Y-m-d H:i:s');
$end = date_format(date_create($event['modelData']['end']['dateTime']), 'Y-m-d H:i:s');
}else{
$begin = $event['modelData']['start']['date'];
$end = $event['modelData']['end']['date'];
}
$title = $event->getSummary();
echo '<tr><td>' . $color . '</td><td>' . $begin . '</td><td>' . $end. '</td><td>' .$title . '</td></tr>';
}
}
echo '</table>';
Schau mal einfach in die SQL-Tabelle.
Wie der apache stürzt ab? muss doch was im error.log stehenTut mir leid aber ich bekomme es nicht hin,wenn ich den Code jetzt eingebe und die test.php aufrufe stürtzt mein Apache ab.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
echo "<h1 align='center'>TEST</h1>";
echo "<h3>includePath: ".get_include_path()."</h3>".PHP_EOL;
echo "<h4>DOCUMENT_ROOT: ".$_SERVER['DOCUMENT_ROOT']."</h4>".PHP_EOL;
require_once 'c:/xampp/htdocs/zendfw/google-api-php-client/autoload.php';
$key = file_get_contents("c:/xampp/htdocs/infoframe/Infoframe-3999c7729ff4.p12", TRUE);
echo "<h4>Hier kommt jetzt unleserliches Zeug: </h4><br>".$key;
?>