Download presentation
Presentation is loading. Please wait.
Published byGrant Harmon Modified over 10 years ago
2
Wen-Nung Tsai http://w3c.org/http://w3c.org/ ( http://www.w3.org )http://www.w3.org HTML and Web Programming Twitter GMail GTalk Facebook Bing Some More Stuff..
3
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 2 Agenda l Review: HTML. DHTML –Web pages ( 網頁 ) is simply an HTML file. l Web Application l Dynamic Web Programming CGI – Common Gateway Interface l XUL ? XML-based User-interface Language l Programming in FaceBook l References
4
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 3 Terminologies WWW – World Wide Web HTML – Hyper Text Markup Language HTTP – Hyper Text Transfer Protocol URL – Uniform Resource Locator l Hyperlinks and Links l Web Browser l Web Server, Application Server l http://w3c.org http://w3c.org
5
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 4
6
5 The Internet versus the Web THE INTERNET The Internet is a collection of interconnected networks. THE WEB The Web is a system that provides access to documents formatted in hypertext that uses languages such as HTML or XML. Slide 5 of 30
7
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 6 Web Application l Web Applications are developed to use a Web browser as the interface to the application to allow users to input, retrieve and process data of certain types. They create dynamic Web pages to dynamically respond to user inputs.
8
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 7 Web Application Architecture Browser DBMS
9
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 8 Layered Web Interoperability Network Hardware HTTP TCP/IP Google API SOAPXMLRPC … REST RSS … …… …OAI-PMH …
10
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 9 What is HTTP? l Protocol for transfer of data between Web servers and Web clients (browsers). l Popular Web servers: –Apache HTTPD –JBoss –Tomcat l Popular Web clients: –Mozilla, Firefox, Netscape, MSIE –Chrome, HotJava, Hotdog, Opera –wget l Defined formally by IETF as RFC2616.
11
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 10 URLs, URNs and URIs l Every resource accessible through HTTP is identified by a Uniform Resource Location (URL), which is a location-specific identifier. –For example, l http://www.cs.uct.ac.za:80/ http://www.cs.uct.ac.za:80/ l ftp://ftp.cs.uct.ac.za/ ftp://ftp.cs.uct.ac.za/ l A Uniform Resource Identifier (URI) is a standard format ( : ) generic identifier. –For example, l mailto:hussein@cs.uct.ac.za l oai:www.ndltd.org:123456-789 l A Uniform Resource Name (URN) is one example of a location- independent URI. –For example, l urn:isbn:123-456-789 l Note: Every URL and URN is also a URI!
12
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 11 What is HTML ? HTML – HyperText Markup Language –HTML file is Essentially a text file, containing small markup tags. ( 排版語言 ) –Markup tags tell the Web Browser how to read and display the page. I.e., how to lay out the information (text, images, etc) in the browser window. –an opening tag and a closing tag with the content that the tag is applied to, in between them.
13
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 12 名稱 內容 … Titile 讓首頁製作者以簡短的文字表達此一首頁之內容。 Title 的內容會出現在瀏覽器的頂端。 若將某個首頁加入書籤,則 Title 內容變成該書籤名稱。 HTML Page (Web Page) 外觀
14
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 13 HTML Elements l Headings, Font Sizes, Color l Comments l Backgrounds l Links and hyperlinks l E-mail l Pictures l Lists l Tables, Frames, …
15
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 14 進階語法- CSS 介紹 (1/2) l 超連結去底線 l 【語法】 l 1. 在 … 加入下列語法 l l a{text-decoration:none} l l 2. 在 … 加入下列語法 l 連結名稱
16
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 15 CSS 應用 a{text-decoration:none} <a style="text-decoration: none " href= " http://www.sinica.edu.tw " > 中央研究院 進階語法- CSS 介紹 (2/2)
17
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 16 Tools to build a Web Page l You can just use NOTE PAD –Write some bunch of code in a HTML filebunch of code Or you can use WYSIWYG ( pronounced "wiz-ee-wig", means “ What You See Is What You Get) editors. –Netscape Composer –Microsoft Front Page –Dreamweaver MX –Hundreds of other Editors available on the Internet – the Cyber spaces
18
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 17 Dynamic Web Programming l HTML + CGI + … l Client side: Java script, VB script l Server side: –CGI : Using PERL, TCL, Python, Ruby, … – ASP, PHP, JSP l DBMS –Oracle, MSSQL, MySQL, … l J2EE, ASP.Net l PHP + MySQL [ + Tomcat ] ( 注意 JavaScript 不是 Java)
19
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 18 Dynamic web pages l Client-side –Examples: java applets, javascript/VBScript, Macromedia Flash l Server-side –Common Gateway Interface (CGI) –Servlets –ASP, PHP, JSP
20
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 19 What is DHTML? (1/2) DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more dynamic. DHTML is NOT a scripting language (like JavaScript), but a browser feature- or enhancement- that makes the browser dynamic It uses a host of different technologies - JavaScript, VBScript, the Document Object Model (DOM), layers, cascading stylesheets - to create HTML that can change even after a page has been loaded into a browser
21
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 20 What is DHTML? (2/2) It is considered to be made up of –HTML –Cascading Style Sheets (CSS) –Scripting Language All three of these components are linked via Document Object Model (DOM) DOM is the interface that allows scripting languages to access the content, style, and structure of the web documents and change them dynamically
22
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 21 Tools of DHTML HTML and XML –Partitions and Organizes the content CSS, XSL - CSS1, CSSP, CSS2 –Defines the Presentation of the content Scripting - JavaScript, JScript, VBScript –Adds interactivity to the page DOM- Document Object Model –Defines what and how elements are exposed for script access
23
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 22 CGI – Common Gateway Interface l CGI = 共通閘道介面 –Standard interface through which users interact with applications on Web servers –Provides way for clients to interact with applications on Web server –CGI script l Can be written in many different languages, including Perl l Practical Extraction and Report Language (Perl) –One of the most widely used language for Web programming l Python -- http://en.wikipedia.org/wiki/Python_(programming_language) http://en.wikipedia.org/wiki/Python_(programming_language) l Ruby -- http://en.wikipedia.org/wiki/Ruby_(programming_language)
24
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 23 Active Server Pages (ASP) l ASP code enclosed in: l When a browser calls an ASP document, the ASP Server reads the.asp document and 1.Substitutes appropriate files for the (server-side) include statements 2.Runs the ASP code (Visual Basic Script – see the Tutorial and Language Reference, … ) Tutorial and Language Reference 3.Returns the resulting HTML code to the browser JSP JSP -- Java Server Page (sun micro)
25
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 24 PHP: Hypertext Preprocessor. l PHP stands for PHP: Hypertext Preprocessor. l HTML embedding scripting language l PHP code enclosed in or l When a browser calls a PHP document, the Server reads the PHP document and –Runs the PHP code –Returns the resulting HTML code to the browser JSP JSP -- Java Server Page (sun micro)
26
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 25 What is XUL ? l XML-based User interface Language (“zool”) l An XML grammar to add/modify UI widgets of the browser l Makes UI building easier and faster l Uses W3C standards: HTML, XML, CSS, DOM l XPToolkit is the finite set of interface-specific elements created in XUL l XPFE (cross Platform Front End) is the front end created from XPToolkit l XUL provides flexibility and ease of use –Cross-platform UI easily –Power enough to build application UI –Ready-made widgets
27
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 26 XUL Widget & Syntax l Widget: –Window, box, menu, button, tabbox, checkbox, … l Syntax & Rules: –XUL is case sensitive: all events and attribute must be written in lower case –All strings must be double quoted –All attributes must have a value –XUL file extension:.xul
28
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 27 Inside XUL package l Main components –Content: l XUL files describes XML description of UI –Appearance: l CSS, images, and others control presentation –Behavior: l JavaScript defines event handling within widgets –Locale: l All localizable strings in external DTD
29
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 28 XUL and JavaScript l XUL interface is a collection of disconnected widgets until programmed l Using JavaScript and/or C++ l JavaScript included in XUL or a separate file function InitWindow( ) { var checkbox = document.getElementByID("remember"); if (checkbox) checkbox.checked = true; }
30
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 29 Adding Event Handlers l JavaScript l DOM Event Listener
31
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 30 Chrome URI’s XUL files are loaded via chrome URI ’ s chrome:// / / l The chrome URI has three parts: Package name : Given by user Type of data : Content or Skin or Locale Content : xul and js files Skin : images and css files Locale : DTD and.properties files File name : Path of the file to load
32
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 31 XUL Overlays l Overlays attach other UI widgets to XUL documents at run time. l XUL fragments are inserted at specific merge points in the master document. l For example: “ status-bar ” is the merge point and “ my- panel ” is the new XUL fragment
33
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 32 XUL file
34
Programming in Facebook Hussein Suleman uct cs honours 2007
35
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 34 What is Facebook?
36
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 35 How Facebook Apps work l Every profile page is made up of many independent portlets or profile boxes. l Each portlet is generated statically by a possibly external application and stored by Facebook. l It could be an iframe, but in most cases is not. Portlets are not actually changed in the profile page – they are changed elsewhere! l Facebook has mechanisms to link in applications, and APIs for applications to communicate with Facebook.
37
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 36 Facebook Communication application (UCT) userfacebook.com request for profile profile request for canvas canvas Facebook API use update profile box, etc. request for canvas content canvas
38
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 37 What can the API do ? l Get a list of friend ids or friends who are running the same app l Get and set notifications of events l Set content of profile box l Get specific information on a user l Add to the Newsfeed for a user l etc. See: http://developers.facebook.com/documentation.php?v=1.0&doc=
39
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 38 FBML l Language used by Facebook to specify any fragment of Web pages. l Mostly just like HTML! l Forms get additional fields added to pass Facebook parameters silently. l Images are redirected to local copies. l Links must be absolute (parameters do not work as expected in all toolkits). l Lots of additional Facebook-specific items – for a user ’ s name – for a user ’ s profile picture
40
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 39 FQL l Facebook Query Language allows access to user database with language that is similar to SQL. l Example: –SELECT first_name FROM user WHERE uid=$params->{user} –To get the first name of a user based on the user-id
41
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 40 Creating an Application l What you need: –Web Server –API toolkit or roll-your-own l Add the Developer application to your profile. l Switch to the Developer application. l Apply for a key.
42
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 41
43
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 42
44
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 43
45
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 44
46
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 45 What does a typical application do? l Check CGI parameters. l Authenticate using Facebook API. l Draw configuration Web page on canvas. Allow user to update options … l Write FBML to profile box. l Save per-user state in database or in filesystem.
47
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 46 Example: Profile Box
48
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 47 Example: Application Canvas
49
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 48 The Code – index.pl l #!/usr/bin/perl l # l # sample adapted from Facebook Perl API example l # hussein suleman l # 31 july 2007 l use strict; l use CGI; l use WWW::Facebook::API; l use Data::Dumper; l use LWP::UserAgent; l use XML::DOM; l # create FB object with keys included l my $facebook = WWW::Facebook::API->new( l api_key => "8a3b63fde6e900f853c51903e6689e5b", l secret => "f1818d69d7140fa0192b623b55e7da59", l app_path => "hussein_testb", l parse => 1, l ); l # remember to add proxy for UCT! l $facebook->ua->proxy ('http', 'http://cache.uct.ac.za:8080/'); l sub main { l # handler CGI parameters l my $q = new CGI; l print $q->header; l redirect("Must be called in facebook canvas") l unless $facebook->canvas->in_fb_canvas($q); l my $params = $facebook->canvas->validate_sig($q); l if ( $params->{user} ) { l # Canvas takes care of setting up a session for us, no need to call the
50
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 49 l # auth methods. l $facebook->session_key( $params->{session_key} ); l } l else { l # User hasn't added app (could reject/display info/whatever) l # (Or handle later when a user is needed). l } l my ( $action, $param ) = ( $q->path_info =~ m!^/(\w+)/?(.*)! ); l # trigger action depending on parameters passed to app l if ($action eq '') l { handle_index($param, $params); } l else l { print_error ("cannot understand request"); } l } l # canvas drawing routine l sub handle_index { l my ( $param, $params ) = @_; l print " "; l print " Watch My Students "; l print " {user}\"/> "; l # list data from disk file with links to delete entries l print " {user}\" useyou=\"false\"/>\'s Current Wat l ched Entries "; l my $fbml = " Watch My Students Sneak peek at what the 1016 stude l nts are chatting about in the class forum... "; l print " ";
51
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 50 l open (my $ofile, "data.txt"); l my $po = 0; l while (my $aline = ) l { l $po++; l chomp $aline; l print " <a href=\"http://banzai.cs.uct.ac.za/~hussein/cgi-bin/2007/face l book/perl/delete.pl?position=$po\">Delete $aline "; l $fbml.= " $aline "; l } l close ($ofile); l print " "; l $fbml.= " "; l print " "; l # list data from RSS feed with links to add entries l print " {user}\" useyou=\"false\"/>\'s Latest RSS l Entries "; l print " "; l my $results = get_RSS(); l $po = 0; l foreach my $aresult (@$results) l { l $po++; l $aresult->[2] =~ s/\ ]+\>//go; l print " <a href=\"http://banzai.cs.uct.ac.za/~hussein/cgi-bin/2007/face l book/perl/add.pl?position=$po\">$aresult->[0] (by $aresult->[1]) $aresul l t->[2] "; l } l print " "; l # add application if it has not been added l if ( !$params ) { l print " get_add_url,
52
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 51 l "'>Add this application."; l } l # update profile box l $facebook->profile->set_fbml (markup => $fbml); l } l # deal with users trying to use app without logging into FB l sub redirect { l div_error("Please go <a href='" l. $facebook->get_app_url l. "'>to facebook " ); l exit; l } l # general error handler l sub print_error { l print " ", join( "", @_ ), " "; l } l # retrieve and parse an RSS feed l sub get_RSS l { l my $ua = new LWP::UserAgent(); l $ua->timeout(10); l $ua->proxy ('http://cache.uct.ac.za:8080/'); l my $response = $ua->get('http://banzai.cs.uct.ac.za/phpBB2-1016/rss.php'); l my @results = (); l if ($response->is_success) { l my $parser = new XML::DOM::Parser; l my $doc = $parser->parse ($response->content); l foreach my $anitem ($doc->getElementsByTagName ('item'))
53
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 52 l { l my $title = ''; l foreach my $anode ($anitem->getElementsByTagName ('title')) l { l if ($anode->hasChildNodes == 1) l { l $title = $anode->getFirstChild->toString; l } l my $author = ''; l foreach my $anode ($anitem->getElementsByTagName ('author')) l { l if ($anode->hasChildNodes == 1) l { l $author = $anode->getFirstChild->toString; l } l my $description = ''; l foreach my $anode ($anitem->getElementsByTagName ('description')) l { l if ($anode->hasChildNodes == 1) l { l $description = $anode->getFirstChild->toString; l } l $description =~ s/</\</go; l $description =~ s/>/\>/go; l $description =~ s/[\n\r]//go; l push (@results, [$title, $author, $description]); l } l \@results; l } l main();
54
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 53 The Code - add.pl l #!/usr/bin/perl l # l # sample adapted from Facebook Perl API example l # hussein suleman l # 31 july 2007 l use strict; l use CGI; l use LWP::UserAgent; l use XML::DOM; l sub main { l my $q = new CGI; l handle_add ($q->param('position')); l print "Location: http://apps.facebook.com/hussein_testb/\n\n"; l }
55
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 54 l sub handle_add { l my ( $position ) = @_; l $position--; l my $results = get_RSS(); l my $aresult = $$results[$position]; l if (defined $aresult) l { l $aresult->[2] =~ s/\ ]+\>//go; l open (my $ofile, ">>data.txt"); l print $ofile " [1]\"> $aresult->[0] $aresult- l >[2]\n"; l close ($ofile); l } l sub get_RSS l { l my $ua = new LWP::UserAgent(); l $ua->timeout(10); l $ua->proxy ('http://cache.uct.ac.za:8080/'); l my $response = $ua->get('http://banzai.cs.uct.ac.za/phpBB2-1016/rss.php'); l my @results = (); l if ($response->is_success) { l my $parser = new XML::DOM::Parser; l my $doc = $parser->parse ($response->content); l foreach my $anitem ($doc->getElementsByTagName ('item')) l { l my $title = ''; l foreach my $anode ($anitem->getElementsByTagName ('title')) l { l if ($anode->hasChildNodes == 1)
56
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 55 l foreach my $anode ($anitem->getElementsByTagName ('title')) l { l if ($anode->hasChildNodes == 1) l { l $title = $anode->getFirstChild->toString; l } l my $guid = ''; l foreach my $anode ($anitem->getElementsByTagName ('guid')) l { l if ($anode->hasChildNodes == 1) l { l $guid = $anode->getFirstChild->toString; l } l my $description = ''; l foreach my $anode ($anitem->getElementsByTagName ('description')) l { l if ($anode->hasChildNodes == 1) l { l $description = $anode->getFirstChild->toString; l } l $description =~ s/</\</go; l $description =~ s/>/\>/go; l $description =~ s/[\n\r]//go; l push (@results, [$title, $guid, $description]); l } l \@results; l }
57
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 56 The Code – delete.pl l #!/usr/bin/perl l # l # sample adapted from Facebook Perl API example l # hussein suleman l # 31 july 2007 l use strict; l use CGI; l sub main { l my $q = new CGI; l handle_delete ($q->param('position')); l print "Location: http://apps.facebook.com/hussein_testb/\n\n"; l } l sub handle_delete { l my ( $position ) = @_; l open (my $ofile, "data.txt"); l my @lines = ; l close ($ofile); l splice (@lines, $position-1, 1); l open (my $ofile, ">data.txt"); l foreach my $aline (@lines) l { l print $ofile $aline; l } l close ($ofile); l } l main();
58
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 57 References l W3C's homepage for CGI. http://www.w3c.org/CGI/ l Introduction to Common Gateway Interface specifications. NCSA Software Development Group. http://hoohoo.ncsa.uiuc.edu/CGI/overview.html l The WWW Common Gateway Interface Version 1.1 (Internet Draft), David Robinson, October 1995. l ISAPI (Internet Server API). Progress Software and Microsoft. http://www.process.com/news/spec.htp l NSAPI (Netscape Server API). Netscape. http://www.netscape.com/newsref/std/server_api.html http://www.netscape.com/newsref/std/server_api.html l Vaughn Bullard, Smith, Daconta. Essential XUL Programming. New York: John Wiley & Sons, Inc. 2001.
59
http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ 58 謝謝捧場 http://www.csie.nctu.edu.tw/~tsaiwn/introcs/ http://gogle.com/ HTML and Web Programming
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.