If you do not specify Google Calendar URI, the event will be added to the primary calendar. So, you need to figure out which URI of calendar is the right URI you want to update.
In “Calendar Settings” -> “Calendars”, Select the calendar which you want to update. You will see the link of XML. The XML link will like below :
http://www.google.com/calendar/feeds/#KEY#%40group.calendar.google.com/public/basic
#KEY# is your secret.
Replacing the “public/basic” part with “private/full“. It will become the Google Calendar URI.
http://www.google.com/calendar/feeds/#KEY#%40group.calendar.google.com/private/full
Add the URI as the second parameter in the insertEvent function. Like below :
1 2 | // $createdEntry = $gc->insertEvent($newEntry); $createdEntry = $gc->insertEvent($newEntry, "http://www.google.com/calendar/feeds/#KEY#%40group.calendar.google.com/private/full"); |
Following example is “Creating single-occurrence events” from Google web site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | function createEvent ($client, $title = 'Tennis with Beth', $desc='Meet for a quick lesson', $where = 'On the courts', $startDate = '2008-01-20', $startTime = '10:00', $endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08') { $gdataCal = new Zend_Gdata_Calendar($client); $newEvent = $gdataCal->newEventEntry(); $newEvent->title = $gdataCal->newTitle($title); $newEvent->where = array($gdataCal->newWhere($where)); $newEvent->content = $gdataCal->newContent("$desc"); $when = $gdataCal->newWhen(); $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00"; $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00"; $newEvent->when = array($when); // Upload the event to the calendar server // A copy of the event as it is recorded on the server is returned $createdEvent = $gdataCal->insertEvent($newEvent); return $createdEvent->id->text; } createEvent($client, 'New Years Party', 'Ring in the new year with Kim and I', 'Our house', '2006-12-31', '22:00', '2007-01-01', '03:00', '-08' ); |
How about an all day event? From above example, I can’t simply change start time and end time fields to empty string. It will fail.
So, just modified few lines of createEvent function. Like below :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | function createEvent ($client, $title = 'Tennis with Beth', $desc='Meet for a quick lesson', $where = 'On the courts', $startDate = '2008-01-20', $startTime = '10:00', $endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08') { $gdataCal = new Zend_Gdata_Calendar($client); $newEvent = $gdataCal->newEventEntry(); $newEvent->title = $gdataCal->newTitle($title); $newEvent->where = array($gdataCal->newWhere($where)); $newEvent->content = $gdataCal->newContent("$desc"); $when = $gdataCal->newWhen(); if ($startTime != "") { $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00"; } else { $when->startTime = "{$startDate}"; } if ($endTime != "") { $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00"; } else { $when->endTime = "{$endDate}"; } $newEntry->when = array($when); // Upload the event to the calendar server // A copy of the event as it is recorded on the server is returned $createdEvent = $gdataCal->insertEvent($newEvent); return $createdEvent->id->text; } createEvent($client, 'New Years Party', 'Ring in the new year with Kim and I', 'Our house', '2006-12-31', '', '2007-01-01', '', '' ); |
After run it, that event will be updated on 12/31/2006 and 1/1/2007.
I’m going to use the Google Mini pdf file as this demonstration. Please download that file to the same directory of your php script in advance. Check it out here. You can see how GOOD Google did the document preview function is. Of course, I’m not as well as Google’s experts. But, I just knew a small trick.
我將使用Google Mini pdf 檔案進行這個範例解說. 請先將這個檔案下載到你的php程式相同目錄. 按這裡. , 你可以先看看 Google 的 document preview 的功能已經相當完善. 當然, 我不像 Google 的專業人士那麼厲害. 但是, 我知道一點小技巧.
Before you start to generate pdf file preview, you need to make sure your system is installed the GhostScript and the ImageMagick.
在開始產生pdf預覽前, 你先在你的系統安裝 GhostScript與ImageMagick程式.
Following php script to generate thumbnails pdf files:
下列php程式碼會產生縮圖:
1 | exec('/usr/bin/convert "googlemini_datasheet.pdf" -geometry 200 "googlemini_thumbnails.png"'); |
Output :

file name : googlemini_thumbnails-0.png

file name : googlemini_thumbnails-1.png
Following php script to generate large pdf files:
下列php程式碼會產生大圖:
1 | exec('/usr/bin/convert "googlemini_datasheet.p22df" -density 1200x1200 -geometry 1024 -quality 100 "googlemini_large.png"'); |
Output :

file name : googlemini_large-0.png

file name : googlemini_large-1.png
From above php scripts, you can see the convert command generated two png files. Because, the Google Mini pdf file has two pages. If there are many pages in pdf file, It will be generated some file name with “-0″, “-1″, “-2″, “-3″ and so on.
從上列php程式碼, 你可以了解 convert 指令幫你產生了兩張 png 圖. 因為那個 Google Mini pdf 檔案有兩頁. 如果pdf檔案有很多頁面, 那會產生”-0″, “-1″, “-2″, “-3″…等.
If you would like to generate the first page, you can use following php script:
如果你只想產生第一頁, 你可以使用下列php程式.
1 | exec('/usr/bin/convert "googlemini_datasheet.pdf[0]" -geometry 200 "googlemini_page1.png"'); |
Just add the [0] after the pdf file name. How about the second page? Just change inside number of [ ] from 0 to 1.
只要在pdf檔案後面加入[0]就可以了. 那如果要只輸出第二頁? 只要改變 [ ] 裡面的數子. 從 0 到 1.
References :
建立 rrd 檔案. 然後更新溫度資訊到 rrd 檔案內 :
initial rrd file and update temperature into rrd file :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | // update.php $rrd_file = "r733.rrd"; function init_rrd() { global $rrd_file; $opts = array("--step", "300", "--start", 0, "DS:Battery:GAUGE:600:1:100", "DS:EMU:GAUGE:600:1:100", "RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:288:797"); $rtn = rrd_create($rrd_file, $opts, count($opts)); if ($rtn == 0) { $err = rrd_error(); exit("ERROR : $err\n"); } } // end function init_rrd() function update_rrd() { global $rrd_file; $battery_cmd = "/usr/bin/snmpwalk -v 1 -c tiara_pub 192.168.170.250 1.3.6.1.4.1.318.1.1.1.2.2.2.0"; $emu_cmd = "/usr/bin/snmpwalk -v 1 -c tiara_pub 192.168.170.250 1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1"; $flag = true; while($flag) { $battery_temperature = ""; $emu_temperature = ""; while($battery_temperature == "") { $output = shell_exec($battery_cmd); $battery_temperature = trim(str_replace("SNMPv2-SMI::enterprises.318.1.1.1.2.2.2.0 = Gauge32:", "", $output)); if ($battery_temperature == "") sleep(5); } while($emu_temperature == "") { $output = shell_exec($emu_cmd); $emu_temperature = trim(str_replace("SNMPv2-SMI::enterprises.318.1.1.10.2.3.2.1.4.1 = INTEGER:", "", $output)); if ($emu_temperature == "") sleep(5); } $battery_temperature = (int)$battery_temperature; $emu_temperature = (int)$emu_temperature; $rtn = rrd_update($rrd_file, "N:$battery_temperature:$emu_temperature"); if ($rtn == 0) { $err = rrd_error(); exit("ERROR : $err\n"); } if (isset($_GET["t"])) { sleep(300); } else { $flag = false; } } // end while(true) } // end function update_rrd() if (file_exists($rrd_file)) { update_rrd(); } else { init_rrd(); update_rrd(); } |
畫 rrd 圖 :
draw rrd graphs :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | // index.php $rrd_file = "r733.rrd"; include_once "update_r733.php"; function draw_rrd() { global $rrd_file; $opts = array( "--start", "-1h", "--vertical-label=deg C", "--title=R733 Temperature last hour", "DEF:battery=".$rrd_file.":Battery:AVERAGE", "DEF:emu=".$rrd_file.":EMU:AVERAGE", "COMMENT: Max Average Last\\n", "AREA:battery#99CC00:Battery \:", "GPRINT:battery:MAX:%2.0lfdeg C", "GPRINT:battery:AVERAGE:%2.0lfdeg C", "GPRINT:battery:LAST:%2.0lfdeg C\\r", "LINE2:emu#6699CC:EMU \:", "GPRINT:emu:MAX:%2.0lfdeg C", "GPRINT:emu:AVERAGE:%2.0lfdeg C", "GPRINT:emu:LAST:%2.0lfdeg C\\r" ); $ret = rrd_graph("r733_1h.gif", $opts, count($opts)); if(!is_array($ret)) { $err = rrd_error(); exit("draw_rrd() ERROR: $err\n"); } $opts = array( "--start", "-1d", "--vertical-label=deg C", "--title=R733 Temperature last day", "DEF:battery=".$rrd_file.":Battery:AVERAGE", "DEF:emu=".$rrd_file.":EMU:AVERAGE", "COMMENT: Max Average Last\\n", "AREA:battery#99CC00:Battery \:", "GPRINT:battery:MAX:%2.0lfdeg C", "GPRINT:battery:AVERAGE:%2.0lfdeg C", "GPRINT:battery:LAST:%2.0lfdeg C\\r", "LINE2:emu#6699CC:EMU \:", "GPRINT:emu:MAX:%2.0lfdeg C", "GPRINT:emu:AVERAGE:%2.0lfdeg C", "GPRINT:emu:LAST:%2.0lfdeg C\\r" ); $ret = rrd_graph("r733_1d.gif", $opts, count($opts)); if(!is_array($ret)) { $err = rrd_error(); exit("draw_rrd() ERROR: $err\n"); } $opts = array( "--start", "-1w", "--vertical-label=deg C", "--title=R733 Temperature last week", "DEF:battery=".$rrd_file.":Battery:AVERAGE", "DEF:emu=".$rrd_file.":EMU:AVERAGE", "COMMENT: Max Average Last\\n", "AREA:battery#99CC00:Battery \:", "GPRINT:battery:MAX:%2.0lfdeg C", "GPRINT:battery:AVERAGE:%2.0lfdeg C", "GPRINT:battery:LAST:%2.0lfdeg C\\r", "LINE2:emu#6699CC:EMU \:", "GPRINT:emu:MAX:%2.0lfdeg C", "GPRINT:emu:AVERAGE:%2.0lfdeg C", "GPRINT:emu:LAST:%2.0lfdeg C\\r" ); $ret = rrd_graph("r733_1w.gif", $opts, count($opts)); if(!is_array($ret)) { $err = rrd_error(); exit("draw_rrd() ERROR: $err\n"); } $opts = array( "--start", "-1m", "--vertical-label=deg C", "--title=R733 Temperature last month", "DEF:battery=".$rrd_file.":Battery:AVERAGE", "DEF:emu=".$rrd_file.":EMU:AVERAGE", "COMMENT: Max Average Last\\n", "AREA:battery#99CC00:Battery \:", "GPRINT:battery:MAX:%2.0lfdeg C", "GPRINT:battery:AVERAGE:%2.0lfdeg C", "GPRINT:battery:LAST:%2.0lfdeg C\\r", "LINE2:emu#6699CC:EMU \:", "GPRINT:emu:MAX:%2.0lfdeg C", "GPRINT:emu:AVERAGE:%2.0lfdeg C", "GPRINT:emu:LAST:%2.0lfdeg C\\r" ); $ret = rrd_graph("r733_1m.gif", $opts, count($opts)); if(!is_array($ret)) { $err = rrd_error(); exit("draw_rrd() ERROR: $err\n"); } $opts = array( "--start", "-1y", "--vertical-label=deg C", "--title=R733 Temperature last year", "DEF:battery=".$rrd_file.":Battery:AVERAGE", "DEF:emu=".$rrd_file.":EMU:AVERAGE", "COMMENT: Max Average Last\\n", "AREA:battery#99CC00:Battery \:", "GPRINT:battery:MAX:%2.0lfdeg C", "GPRINT:battery:AVERAGE:%2.0lfdeg C", "GPRINT:battery:LAST:%2.0lfdeg C\\r", "LINE2:emu#6699CC:EMU \:", "GPRINT:emu:MAX:%2.0lfdeg C", "GPRINT:emu:AVERAGE:%2.0lfdeg C", "GPRINT:emu:LAST:%2.0lfdeg C\\r" ); $ret = rrd_graph("r733_1y.gif", $opts, count($opts)); if(!is_array($ret)) { $err = rrd_error(); exit("draw_rrd() ERROR: $err\n"); } } // end function draw_rrd() draw_rrd(); ?> <img src="r733_1h.gif"><br> <img src="r733_1d.gif"><br> <img src="r733_1w.gif"><br> <img src="r733_1m.gif"><br> <img src="r733_1y.gif"> |
在 linux 內執行 curl http://xxx.liho.tw/temperature/update.php & 這樣就可以每 300 秒回報一次溫度.
展示畫一天的溫度的rrd圖 :

下面這個. 會把輸出儲存在$output
1 2 | $cmd = "ls -l"; $output = shell_exec($cmd); |
還有另外一種作法用 system function . 這個在執行過程就會直接顯示出來.
1 2 | $cmd = "ls -l"; $output = system($cmd, $retval); |
Using php to create openldap sha password hash
應該很少有人有這樣的需求. 不過我就是有. 下面程式可以讓你產生 ldap sha 密碼 hash :
1 2 | $passwd = "TOP_SECRET"; $ldap_passwd = "{SHA}".base64_encode(pack("H*", sha1($passwd))); |
First of all, you need to install Zend Gdata on your web server. Using following codes. Just modified at 12, 13 and 105 lines to your own. Make sure your username and password is safe. You better don’t write your password in your php codes. You can design your input form. And using https to send your password to your web server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | <? /** * Author : Sam Tseng * Date : 18-MAY-2009 * * Program Name : Accessing Google Calendar Demo * Function : Using php to add a Google Calendar event and a reminder. * */ // Please use your username and password at your google service. $username = "username@gmail.com"; $password = "xxxxxxxxxxxxxxxxxxxxxx"; $alarm_method = ""; 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_HttpClient'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); function getClientLoginHttpClient($user, $pass) { $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service); return $client; } function createEvent($client, $title, $desc, $where, $startDate, $startTime, $endDate, $endTime, $tzOffset = '+08') { $gc = new Zend_Gdata_Calendar($client); $newEntry = $gc->newEventEntry(); $newEntry->title = $gc->newTitle(trim($title)); $newEntry->where = array($gc->newWhere($where)); $newEntry->content = $gc->newContent($desc); $newEntry->content->type = 'text'; $when = $gc->newWhen(); $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00"; $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00"; $newEntry->when = array($when); $createdEntry = $gc->insertEvent($newEntry); return $createdEntry->id->text; } function setReminder($client, $eventId, $minutes=15) { $gc = new Zend_Gdata_Calendar($client); global $alarm_method; $method = $alarm_method; if ($event = getEvent($client, $eventId)) { $times = $event->when; foreach ($times as $when) { $reminder = $gc->newReminder(); $reminder->setMinutes($minutes); $reminder->setMethod($method); $when->reminders = array($reminder); } $eventNew = $event->save(); return $eventNew; } else { return null; } } function getEvent($client, $eventId) { $gdataCal = new Zend_Gdata_Calendar($client); $query = $gdataCal->newEventQuery(); $query->setUser('default'); $query->setVisibility('private'); $query->setProjection('full'); $query->setEvent($eventId); try { $eventEntry = $gdataCal->getCalendarEventEntry($query); return $eventEntry; } catch (Zend_Gdata_App_Exception $e) { var_dump($e); return null; } } function triger_event_now($method, $title, $desc, $where) { global $username, $password, $alarm_method; $alarm_method = $method; $client = getClientLoginHttpClient($username, $password); $today = date("Y-m-d"); $now = date("H:i", mktime(date("H"), date("i") + 12, date("s"), date("m"), date("d"), date("Y"))); // by default, I use Taiwan timezone. You should modify your own timezone. $id = createEvent($client, $title, $desc, $where, $today, $now, $today, $now, "+08"); $id = str_replace("http://www.google.com/calendar/feeds/default/private/full/", "", $id); setReminder($client, $id, 10); } // There are three type of reminders which are "sms", "email" and "alert". // The below is using sms to send the event to your mobile. This program will delay two minutes. triger_event_now("sms", "surf The Paradiso blog", "http://www.samtseng.liho.tw/~samtz/blog/", "Anywhere"); ?> |
使用 php 傳送 Google Calendar 簡訊
首先,你需要在你的網頁伺服器安裝 Zend Gdata. 更改下列程式碼 :
改成你的 Google 帳號與密碼. 你要確保這個檔案不會被其他人讀取到. 最好不要把密碼寫在程式內. 你可以設計你的表單使用 https 傳遞你的密碼到你的網頁伺服器.
11 12 13 | // Please use your username and password at your google service. $username = "username@gmail.com"; $password = "xxxxxxxxxxxxxxxxxxxxxx"; |
觸發事件有三種方式 “sms”, “email” and “alert”. 下面展示是用 sms 提醒. 兩分鐘後簡訊就會傳送到你的手機.
102 103 104 | // There are three type of reminders which are "sms", "email" and "alert". // The below is using sms to send the event to your mobile. This program will delay two minutes. triger_event_now("sms", "surf The Paradiso blog", "http://www.samtseng.liho.tw/~samtz/blog/", "Anywhere"); |
如果有問題歡迎留言一起討論.
這個主要是練習使用 jQuery 做 ajax POST 的動作.然後把結果塞回網頁上面.
先簡單寫個 helloworld 的 php. 限定它只接收 POST method.
1 2 3 4 5 6 7 | <? if (isset($_POST["name"])) { echo “aloha “.$_POST["name"]; } else { echo “get out!”; } ?> |
在html內弄個區塊顯示回傳值:
1 | <div class=”message”></div> |
jQuery 部份只要寫下面給行 codes就可以達成 :
1 2 3 4 5 6 7 8 9 | <script type=”text/javascript”> $(document).ready(function() { $.post(’helloworld.php’,{ name: “sam” }, function(txt){ $(’div.message’).html(txt); }); }); </script> |
這樣就完成了簡單的 jQuery 使用 ajax 呼叫POST method. 看一下 DEMO
透過 iTunes Library 的 Cover Flow 你們可以知道我都聽哪些音樂
雖然你們不見得有興趣知道.
終於找到這隻程式. 但是, 還不能正常顯示中文. 看誰有 flash 的編輯器幫忙一下. 如果有那位善心人士. 能提供中文顯示的 .swf 感激不盡! 謝謝!
按這裡全螢幕顯示.
我在玩這個flash. 但是我一直搞不清楚要怎麼透過xml顯示中文.
我的xml 如下.
1 2 3 4 5 6 7 8 9 10 | <?xml version=”1.0″ encoding=”utf-8″ ?> <artworkinfo> <albuminfo> <artLocation>./getartwork.php?no=31</artLocation> <artist>合輯</artist> <albumName>放耳朵去流浪</albumName> <artistLink></artistLink> <albumLink></albumLink> </albuminfo> </artworkinfo> |
在 flash 內 action內設定了 System.useCodepage = false; or System.useCodepage = true; 都還是不能顯示中文.
在檔案的最前面也加入了 //!– UTF8
還有那個顯示的區塊也設定”新細明體”. 請問一下還有什麼可以設定. :$
如果你是 flash 達人請您教教我. 謝謝.
–
解決了!!!
因為 xml 本身是 utf-8. Flash CS4 內建也是用 unicode 所以不需要設定 System.useCodepage = true; 除非你要用 big-5.
再來就是要嵌入某些字集. 如下圖 :

黑皮!! 搞定了.



Recent Comments