Sams Teach Yourself Web Publishing with HTML and CSS in One Hour a Day (5th Edition) P75 doc

10 130 0
Sams Teach Yourself Web Publishing with HTML and CSS in One Hour a Day (5th Edition) P75 doc

Đang tải... (xem toàn văn)

Thông tin tài liệu

Workshop Workshop The following workshop includes questions you might ask about server-side development, quizzes to test your knowledge, and two quick exercises. Q&A Q At work, all of our applications are written using Active Server Pages. Why didn't you write about that? A There are a number of popular platforms for writing web applications. PHP has the advantage of running on a number of operating systems, including Windows, Mac OS X, and Linux. Furthermore, support for PHP is offered by many web hosting providers. Finally, as you'll learn in the next lesson, there are many applications already written in PHP that you can take advantage of. Knowledge of PHP can be helpful in working with them. Q Do I need a special application to edit PHP files? A Just as with HTML, PHP files are normal text documents. Some text editors have specialized features that make working with PHP easier, just as there are for HTML. If you're just starting out, using Notepad or any other regular text editor will work fine, but you'll probably want to find a more powerful tool for writing PHP if you find yourself programming in PHP a lot. Q How do I deploy PHP files to a server? A There are no special requirements for deploying PHP files. You can just transfer them to the server as you would regular HTML files. As long as the server is configured to handle PHP, you should be fine. The one thing you do need to be careful to do is to make sure your directory structure is the same on the server and on your local computer. If you are using includes and directory paths change, your includes will break. Q Are PHP scripts browser-dependent in any way? A All of the processing in PHP scripts takes place on the server. They can be used to produce HTML or JavaScript that won't work with your browser, but there's nothing in PHP that will prevent it from working with a browser. file:///G|/1/0672328860/ch20lev1sec11.html (1 von 3) [19.12.2006 13:50:18] Workshop Quiz 1. What is the difference between double and single quotes in PHP? 2. How do the include_once and require_once functions differ? 3. Which functions can be used to help avoid cross-site scripting attacks? 4. How do you declare an associative array in PHP? Quiz Answers 1. In PHP, strings in double quotes are parsed for variable references and special characters before they are presented. Strings in single quotes are presented as is. 2. The include_once function does not return a fatal error if the file being included is not found. With require_once, if the file is not found, a fatal error occurs and the rest of the page is not processed. 3. You can use htmlspecialchars() to escape the characters used to generate HTML tags for a page. You can use strip_tags() to remove any HTML tags from a string. Either approach should prevent users from using malicious input to attempt a cross-site scripting attack. 4. Associative arrays are declared as follows: $array = ('key' => 'value, 'key2' => 'value2'); Exercises 1. Get PHP up and running on your own computer. file:///G|/1/0672328860/ch20lev1sec11.html (2 von 3) [19.12.2006 13:50:18] Workshop 2. Write a script that enables a user to show the current date and time on a web page. 3. Go to the PHP manual online and find a built-in function that wasn't introduced in this lesson. Use it in a script of your own. file:///G|/1/0672328860/ch20lev1sec11.html (3 von 3) [19.12.2006 13:50:18] Lesson 21. Using Tools to Make Publishing Easier Lesson 21. Using Tools to Make Publishing Easier Throughout the course of this book, you've learned how to build websites by hand, creating HTML pages one by one. In this lesson, you'll learn how to use applications to manage aspects of your website. These types of applications are generally called content management systems, and I'll explain how to install them and use them to keep track of your content so that it's easier to publish and maintain. In this Lesson ● How content management systems came into being ● How to decide whether to use a content management system for your website ● What the common types of content management systems are ● How to work with packaged web applications in general ● How to install and use four popular content management applicationsTypePad, WordPress, MediaWiki, and Coppermine file:///G|/1/0672328860/ch21.html [19.12.2006 13:50:19] The Rise of Content Management The Rise of Content Management Content management systems were invented to deal with the complexity and tedium of managing large collections of HTML documents by hand. A content management system is an application that manages website content in a form that's convenient for editing and maintenance and publishes the content as HTML. Some content management systems generate HTML programmatically on the fly, whereas others generate static files and publish them. Most content management systems are web applications themselves. Users enter and manage content via HTML forms, and the content management system takes care of storing the content in a database of some kind. Generally content management systems provide some kind of facility for creating templates and then merge the content entered by users with the templates to produce a finished website. When templates are updated, all the pages that use those templates automatically have the changes applied to them. Content management systems were initially deployed at the largest sites, such as online news sites, online catalogs, and technical sites that published lots of data. These systems were generally custom built and rather complicated. Content management eventually became an industry unto itself, with many companies producing large, expensive systems aimed at publishers, large corporate websites, and other customers who had lots of web content and a few hundred thousand dollars to spend to deploy a system to manage that content. At the same time, content management systems aimed at individuals also became increasingly popular, except that they weren't called content management tools. Instead, they were called weblogging tools, wikis, photo gallery scripts, and so on. These days, most websites are built using content management systems of some kind, and some of the largest and busiest websites utilize content management tools that were originally aimed at individuals running small sites. For example, one of the busiest sites on the Web, Wikipedia.org, is an encyclopedia written and edited by volunteers that was built using a content management system called a wiki. Wikis started out as a way to make it easy for individuals to quickly publish content on the Web without any knowledge of HTML. Now you can download and use MediaWiki, the tool behind Wikipedia, free of charge. You'll learn more about it later in this lesson. file:///G|/1/0672328860/ch21lev1sec1.html [19.12.2006 13:50:19] Is a Content Management System Right for You? Is a Content Management System Right for You? It may seem odd to talk about using an application to manage your content now after you've worked through 20 lessons explaining how to build web pages from scratch. However, those skills will serve you well whether you use a content management system or not. Content management systems can take a lot of drudgery out of web publishing without limiting the amount of creativity you can apply in designing your web pages. Some work is involved in learning, setting up, and customizing a content management system. When you're creating a website, it's probably easier to start with just a few static files and leave aside the content management system. As your site gets bigger, though, at some point the work involved with dealing with static files offsets the initial investment required to start working with a content management system. You have to figure out whether that initial time investment will pay off in the end. Another common tradeoff with content management systems is that they vary in flexibility. Some, such as photo galleries, are built to handle very specific kinds of content. You wouldn't use photo gallery software to manage an online news site, for example. Others are more flexible. For example, the Mambo content management system is designed as a generic content management system for any type of content. Generally speaking, the more flexible a content management system is, the more work it is to set up. So if you know you're publishing a photo gallery, setting up a photo gallery package probably makes more sense than setting up a general-purpose content management system and customizing it to present photos. In Lesson 18, "Putting Your Site Online," I talked about the various options for web hosting. A similar set of options is available when it comes to content management systems. You can write your own. This provides the most flexibility, but it can be a huge amount of work. You can install and manage an application that someone else wrote and customize it for your own needs. Generally to go this route you'll need your own server or at least an account with a web hosting provider. The final option is to subscribe to a hosted application. For many kinds of web applications, you can pay to subscribe to an application that's hosted by someone else. They make sure that the servers stay up and that the application is running properly, and you just focus on entering your content and making whatever customizations are available. Hosted applications are generally the least flexible, but they're also the easiest to get started with. file:///G|/1/0672328860/ch21lev1sec2.html [19.12.2006 13:50:19] Types of Content Management Systems Types of Content Management Systems Content management systems can be sorted into rough categories. As you've probably figured out, there's more to it than just deciding to use a content management system. You have to figure out what type of content you have and which content management system makes the most sense for you. In some cases, multiple content management systems may be the answer. You may prefer to publish your writing using a weblogging tool and to publish your photos using a photo gallery application. Here's a discussion of some common types of content management systems. Weblogging Tools It seems you can't escape the term weblog (or more commonly, blog) these days. A weblog is just a website where new items are published in reverse chronological order. The items can be articles, links, recipes, photos, or anything else. Generally the most recent items are displayed on the front page, the site maintains an archive of earlier material, and in many cases the site allows users to publish comments of their own. You can find weblogs on just about any topic of interest, and increasingly weblogs are integrated into other types of websites. For example, many magazines and newspapers publish weblogs as part of their sites. Companies are using weblogs to communicate directly with their customers. Political campaigns are using them to get their message out. In large part, the reason weblogs have taken off is that the format is easy to work with. You can publish short items as frequently as you like, and users know that when they visit the site they'll always see the latest and greatest information right up front. In this lesson, I'm going to discuss a weblogging package you can install yourself called WordPress as well as a hosted weblog tool called TypePad. Google also offers a hosted solution that's free to use called Blogger, which you can find at http://www.blogger.com. You may want to check that out as well. Community Publishing Applications Community publishing applications are similar to weblog tools in that they are usually built around publishing items by date right up front. They differ from weblogging tools in that they are more centered around providing features for all of the site's users, not just the site's author or authors. Generally these applications provide the ability for users to register as members of the site, submit stories, and engage in discussions among themselves. Sites that incorporate this kind of functionality include http://slashdot. org/ and http://digg.com/. Some other popular community publishing applications include the following: ● Slash (http://www.slashcode.com/) The software behind the popular website Slashdot.org, written in Perl. ● Scoop (http://scoop.kuro5hin.org/) The software behind Kuro5hin. Scoop is similar to Slash and also written in Perl. ● Drupal (http://drupal.org) A community publishing system written in PHP. The application is written in a modular fashion so that you can include only the features you want. ● PostNuke (http://www.postnuke.com) Another community publishing system written in PHP. Wikis Wiki-style systems take the most radical and counterintuitive approach to content management. Most wikis not only allow anyone to view articles but also to edit them. Some wikis require users to register before they can view or edit articles, but the wiki philosophy is that every user is an editor. When most people hear about this concept, they imagine that the result will be anarchy, but as long as there is a file:///G|/1/0672328860/ch21lev1sec3.html (1 von 3) [19.12.2006 13:50:20] Types of Content Management Systems critical mass of users who want the wiki to be useful, this type of system is resistant to attempted defacement. Wikis generally keep a history of changes made to every article, so it's easy to go back to an older version of a page if someone deletes things they shouldn't or otherwise submits unwanted changes. The most famous wiki is Wikipedia ( http://wikipedia.org), an online encyclopedia written and edited by volunteers. Not only can anyone view the articles in the encyclopedia, but they can also edit them. If you know something about Fargo, North Dakota that's not already in Wikipedia, you can look it up there and add your own information. Attempted vandalism is taken care of by volunteers who keep an eye out for it, and volunteers handle disputes over controversial content as well. The name wiki comes from the name of the original wiki software, which was called WikiWikiWeb, taken from an airport bus route in Honolulu, Hawaii. To read more about the nature of wikis and their history, why not read about them in Wikipedia? The URL is http://en.wikipedia.org/wiki/Wiki. Aside from the fact that everyone can edit the pages in a wiki, the other distinguishing feature of wikis is that they generally provide their own markup language instead of HTML. Generally wiki markup is less flexible than HTML, but also a bit easier to get the hang of. Unfortunately, wiki markup usually differs between wiki software packages, so learning MediaWiki's markup language won't help you out a whole lot if you start using TWiki, for example. Wikis aren't right for every project. If you want to publish your poetry online, putting it up on a page where anyone can edit it probably isn't a good idea. On the other hand, if you need a site where a group can collaboratively write documentation for a project, a wiki can be a great choice. Here's a list of other popular wiki applications and hosts: ● WikiWikiWeb (http://c2.com/cgi/wiki) The original wiki. ● MediaWiki (http://www.mediawiki.org/) The software behind Wikipedia. I'll discuss it more later in this lesson. ● TWiki (http://twiki.org/) A popular wiki package aimed at people who want to support collaboration on a project. ● DokuWiki (http://wiki.splitbrain.org/wiki:dokuwiki) Another wiki designed for project collaboration. Unlike some other wikis, it does not require you to install a relational database such as MySQL to store its data. You can find a comparison of various wiki software packages at http://en.wikipedia.org/wiki/ Comparison_of_wiki_software. There's also a list of hosted wikis that you can use at http://c2.com/cgi/wiki?WikiFarms. Image Galleries As digital cameras have grown more popular, so too has sharing photos online. There are many photo- sharing sites online that you can use to host your photos. Some popular choices include Flickr ( http:// flickr.com/), Kodak EashShare Gallery (http://kodakgallery.com/), Snapfish (http://snapfish.com/), and Fotki ( http://fotki.com/). If you just want to upload pictures and share them with your friends and family members, these sites provide an easy way to do that. In some cases, however, you may want to host your own image galleries. A number of popular image gallery applications are available that vary in terms of complexity and the extent to which they can be customized. The good ones take care of creating thumbnails of your images for you so that you can just upload your photos without dealing with image-editing programs yourself. file:///G|/1/0672328860/ch21lev1sec3.html (2 von 3) [19.12.2006 13:50:20] Types of Content Management Systems In this lesson, I'm going to discuss Coppermine, a popular image gallery application written in PHP. General-Purpose Content Management Systems There are far too many general-purpose content management systems to list here. Some content management systems are really just toolkits that enable you to build something on your own. Others are highly structured with tons of features that you control via configuration, rather than by writing code on your own. Here are some features that these general-purpose content management systems tend to have in common: ● A templating system All content management systems provide some way for you to specify how your content will be laid out on the page, and how the pages containing the content will look. Most templates take the form of HTML files with special markers that indicate where each piece of content goes. In many cases, the templates are just regular PHP, JSP, or ASP pages. In other cases, the content management system will provide its own template language. ● A data repository Content management systems produce web pages, but they usually store the data in some structured format, whether it's in a relational database or in XML files. When users enter data, it is stored so that the system can merge the data with the templates to generate HTML when the documents are published. ● A workflow system Controlling who gets to edit which content as well as managing processes for moving content from draft to published status are big parts of many content management systems. Some provide very rigid systems that you have to work within; others let you modify the workflow to suit your own organization. Generally complex workflow features are part of larger content management systems. They're not very useful for individuals or small groups. ● A system for writing and editing content All content management systems provide some way for you to get your content into the system. Some enable you to enter it using HTML forms; others provide integration with external tools such as Microsoft Word. ● A system for publishing content Once content is in the repository and has been approved for publishing, a content management system has to merge that content with a template and publish it on a web page. Some content management systems produce actual HTML files; others generate the HTML on the fly for every request. Which approach is used usually depends on how much dynamic content appears on the page. Most content management systems that don't publish static files provide some mechanism for caching so that data that hasn't changed can be read from the cache rather than being generated dynamically. file:///G|/1/0672328860/ch21lev1sec3.html (3 von 3) [19.12.2006 13:50:20] Working with Packaged Software Working with Packaged Software So far, this book has been about building things from scratch. This lesson, on the other hand, is about applying tools to make building things a bit easier. However, as I've mentioned, using existing tools can be a job unto itself. Before you can start using MediaWiki to manage your content, you have to download it and get it installed on a server and configured properly. The same is true with any software package. Even if you go with a hosted solution, you still have to set things up so that the software enables you to accomplish your goals. You may also be wondering at this point why you bothered to learn HTML, CSS, JavaScript, and everything else in between if you're going to let an application do your work for you. This is one of the most common misconceptions about this kind of software. Content management systems make some things more convenient, but you'll still apply all of the skills you learned over the course of the book to make your pages look the way you like. Before discussing specific applications, I'm going to discuss some topics that pertain to nearly all applications of this kindrelational databases and deployment issues. Relational Databases In Lesson 20, "Understanding Server-Side Processing," and today, I've brought up the subject of relational databases more than once, but I haven't really explained what they are or how they work. Relational databases are by far the most popular data repository for web applications. There are a number of reasons for that: ● They can scale from the smallest to the largest of applications. You can start a website on a web hosting account on a server that's shared with 50 other people, and eventually wind up running 50 servers of your own and use a relational database to store your data the entire way. ● They are very flexible when it comes to the types of data they can store. All relational databases store their data in tabular format. Each record is a row in a table, and the columns describe the properties of each record. In other words, if you have a table to store information about people, every person will have the same properties. The actual structure of your tables can be customized to suit just about any task. You can create a table of links that has names, URLs, and descriptions for each link, or a table of invoices that lists the customer, amount, shipping address, and item ordered for each invoice. The columns in the table can be configured to hold numbers, dates, short strings, large bodies of text, or even binary files. ● You can create relationships between tables. That's where the "relational" in relational database comes from. You can relate articles to authors, invoices to customers, or even people to other people within the same table. The relational model is very, very powerful. ● Relational databases use a standard query language called SQL (Structured Query Language). Although some differences exist between database vendors, by and large if you know SQL you can work with just about any relational database. ● Relational databases are popular. The basic technology behind relational databases hasn't changed very much in the last 20 years, and they are the foundation of many business applications. What has changed is the fact that now several relational databases are freely available, providing powerful features once only associated with the most expensive software targeted at large corporations. Relational databases are so popular and common that using them for data storage for an application is often an easy decision. Relational databases are usually deployed as a service that is accessible over the network, much like an HTTP server. The difference is that rather than using HTTP to communicate, the database will use its own proprietary protocol. Generally to communicate with a database, you will need some kind of client or library provided by the database vendor. PHP has clients for most popular relational databases built file:///G|/1/0672328860/ch21lev1sec4.html (1 von 2) [19.12.2006 13:50:21] . corporations. Relational databases are so popular and common that using them for data storage for an application is often an easy decision. Relational databases are usually deployed as a service. Relational databases are popular. The basic technology behind relational databases hasn't changed very much in the last 20 years, and they are the foundation of many business applications of HTML documents by hand. A content management system is an application that manages website content in a form that's convenient for editing and maintenance and publishes the content as

Ngày đăng: 07/07/2014, 09:20

Tài liệu cùng người dùng

Tài liệu liên quan