Archive for the 'Apache' Category

WRITE YOUR OWN BLOG ENGINE Post and comment (Post office web site)

Tuesday, January 29th, 2008

WRITE YOUR OWN BLOG ENGINE Post and comment previews You can provide a preview of a post in your Administration site. To do this, add a Preview button next to Add post or Update post. Use logic, such as case switching, so your script can detect which button has been pressed and then know whether to update the database or display a preview of the form submission on the page. Adding previews for comments is another good idea because it gives your readers a chance to ensure that their comment will look like they expect. If you force readers to preview their post first by showing the Post button only in preview mode, this can help fend off comment spam (in itself, having your own blog engine goes a long way toward preventing comment spam). Advanced formatting of posts As it stands, your posts are only automatically formatted with paragraph and line break tags; any other formatting you require needs to be added as HTML within the post. Luckily, there are some free alternatives available to help speed up your post writing and format your blog more beautifully. Textile is used within TextPattern (see Chapter 5) and is also available as a separate function from www.textism.com/tools/textile/license.html. You can use it to replace the format function in the functions.php include file. Textile automatically adds paragraphs and line breaks, automatically links URLs, and has its own simple language for formatting for example, *this* would place tags around the word this. Markdown, which is similar to Textile, is available as a PHP function from www.michelf.com/ projects/php-markdown/. Markdown has some differences from Textile because it converts e-mail style language into HTML. For more information on Markdown, see daringfireball.net/projects/markdown/. Categorizing your posts A slightly more advanced addition is to add a categorization system for your blog posts, which would involve creating a categories table with the names of your categories and a category_id for each. Then, in the same way in which you included a post_id field in the comments table so that you knew which post each comment referred to, so you could add a category_id field to the posts table so you know which category each post is in. You would probably also want to add a Categories section to your CMS to help add and edit categories, as well as a post archive page for each category. Happy blogging You should now have a fully functioning content management system and blogging engine, complete with comments, search engine, and a whole bunch of ideas for new features. But what your blog really needs is some content, so pick a subject, get writing, and enjoy yourself!

BLOG DESIGN SOLUTIONS Migrating your files Next it s (Hosting your own web site)

Monday, January 28th, 2008

BLOG DESIGN SOLUTIONS Migrating your files Next it s time to copy your files across. Edit db_connect.php so it has the correct username and password for your live database. Now open up your FTP software, connect to your web server, and copy the rest of your files and folders into the public_html folder. Check that your index.xml RSS file is read-writeable, as explained earlier. Finally, you need to password-protect your cms folder. This process will vary from ISP to ISP, but you will usually be provided with an Apache web control panel, which enables you to password-protect directories as well as a whole host of other operations (see Figure 7-26). Figure 7-26. Adding password protection using the Apache console And that s it: you exported and uploaded your entire MySQL blog database, transferred all your files to your public-facing website, and password-protected your CMS. Your blog is now live and awaiting posts and readers. The future The great thing about having your own blog engine is that you can keep improving it as you discover more techniques and cool stuff to add. I ll now discuss a few additions you could make to your blog by using the knowledge you have already gained. Flickr Flickr (www.flickr.com) is a fantastic photo-sharing site in which you can upload and share photographs, and what s more basic registration is free. Flickr provides a number of ways to display your photos on sites other than Flickr, and what better place to show them than your blog? The quickest and easiest way is to use the Flickr badge JavaScript or Flash code. Once you are signed up, you can go to www.flickr.com/badge.gne, follow the instructions, and cut and paste the code into your blog the ideal place is the sidebar of your homepage.

Submit web site - WRITE YOUR OWN BLOG ENGINE Now you re ready

Sunday, January 27th, 2008

WRITE YOUR OWN BLOG ENGINE Now you re ready to copy your database to your live server. Open up your local installation of phpMyAdmin in your browser and select the blog database. Click the Export tab. Now click the Select All link in the Export box so that the posts and comments tables are both selected. Finally select the Save as file option and click Go (see Figure 7-25). A file called blog.sql should be saved to your default download folder (usually your desktop). Figure 7-25. Exporting your database in phpMyAdmin Now you have a complete copy of your database: table structure, indexes, and data. To import this onto your live server, open up the remote installation of phpMyAdmin and create a database called blog. Now click the SQL tab and browse to select your blog.sql file in the Location of the textfile section. Click Go, and your database will be uploaded. Easy as that! 335

BLOG DESIGN SOLUTIONS Mon, 28 Mar 2005 22:15:00 (Web site design and hosting)

Sunday, January 27th, 2008

BLOG DESIGN SOLUTIONS
Mon, 28 Mar 2005 22:15:00 GMT http://your-domain-name.com/post.php?post_id=4 Paying my debts and thence to . Covent Garden and an Italian puppet play.

]]> .
Sat, 01 May 2004 23:10:00 GMT http://your-domain-name.com/post.php?post_id=3 My arme not being well, . I staid within all the morning.

]]> Finally, you need to tell the world that you have an RSS feed. Many indexers will automatically look for an index.xml file, but you should also add this line just after the in your blog homepage to make sure:<br /> <link rel="alternate" type="application/rss+xml" . title="RSS 2.0 feed" . href="http://your-domain-name.com/index.xml" /> Once your RSS feed is up and running on your live site, I recommend submitting it to pingomatic.com, which will automatically notify all the web-based RSS news readers that your RSS feed exists. Making it live And so your blog engine is complete. You now have an administration site to add and edit blog posts and a blog site with a homepage listing your latest entries, a page for each post allowing comments, an archive of all past entries, search functionality, and an RSS feed. All that remains is to move the whole lot onto a live web server. Migrating your database I assume that your Internet Service Provider has provided you with FTP access, PHP, and MySQL. If so, it probably provided you with phpMyAdmin as well. If phpMyAdmin is not installed, you can use FTP software to copy your phpMyAdmin files to your live server. In this case, you will probably have to edit the username and password in the config.inc.php file, as explained in Chapter 2. </p> </div> </div> <div class="post"> <h3 id="post-404"><a href="http://apache.armadillowebhosting.com/apache/web-space-write-your-own-blog-engine-message-rss/" rel="bookmark" title="Permanent Link to Web space - WRITE YOUR OWN BLOG ENGINE $message = “RSS">Web space - WRITE YOUR OWN BLOG ENGINE $message = “RSS</a></h3> <small>Saturday, January 26th, 2008</small> <div class="entry"> <p>WRITE YOUR OWN BLOG ENGINE $message = “RSS file updated.”; } // close file fclose($fh); The script uses the fwrite function to write the contents of $rssfile to the $fh file handler created at the beginning of the script. As with fopen, fwrite returns false if the writing process fails. Finally, the fclose function is used to release the index.xml file, and your RSS feed has been updated. But all you have at the moment is a function that can update your RSS feed. That function is not actually called from anywhere. Your RSS feed will need updating on three occasions: when you add a new blog post, when you update a post, and when you delete a post. The first two instances happen in the addpost.php file. So open that file. Just after the opening <?php delimiter, add this code to bring in the functions.php: include($_SERVER["DOCUMENT_ROOT"] . "/functions.php"); Now find the line that says the following: $message = "Successfully inserted post '$title'."; Following that line, add this call to the makerssfeed function: $message .= "<br />” . makerssfeed(); Now find this line: $message = “Successfully update post ‘$title’.”; After that line, add the same call to makerssfeed. The delete blog function is on the index.php page in your CMS, so add the functions.php include to that file in the same way and add the same call to makerssfeed after this line: $message = “Post $delete deleted.”; Now try making a change to one of your blog posts using your CMS, which will force the RSS file to be created. Once you have received the message RSS file updated in your CMS, open up index.xml in your text editor and you should see something like this: <rss version="2.0"> <channel><br /> <link>http://your-domain-name.com</link> <description>A blog by Samuel Pepys</description> <language>en-gb</language> <item><br /> <pubDate>Sun, 03 Apr 2005 15:30:00 GMT</pubDate> <link>http://your-domain-name.com/post.php?post_id=2</link> <description><![CDATA[ <p>News of the fleet and an . afternoon with Mrs. Turner to see a dreadful play.</p> <p>]]> . 333 </p> </div> </div> <div class="post"> <h3 id="post-403"><a href="http://apache.armadillowebhosting.com/apache/blog-design-solutions-blog-more-information-on-the-kids-web-site/" rel="bookmark" title="Permanent Link to BLOG DESIGN SOLUTIONS blog). More information on the (Kids web site)">BLOG DESIGN SOLUTIONS blog). More information on the (Kids web site)</a></h3> <small>Friday, January 25th, 2008</small> <div class="entry"> <p>BLOG DESIGN SOLUTIONS blog). More information on the RSS 2.0 syntax can be found at feedvalidator. org/docs/rss2.html. // pull blogs from database $sql = “SELECT post_id, title, summary, . DATE_FORMAT(postdate, ‘%a, %d %b %Y %T GMT’) as pubdate . FROM posts ORDER BY postdate DESC LIMIT 10″; $result = mysql_query($sql); The script now performs the familiar SELECT query in which it grabs the latest ten blog post titles and summaries. The postdate is formatted in a special way for RSS feeds and includes the time zone (in this case, GMT), which you may have to change according to where your live website is hosted. if ($mypost = mysql_fetch_array($result)) { do { $post_id = $mypost[”post_id”]; $pubdate = $mypost[”pubdate”]; $summary = format($mypost[”summary”]); $title = $mypost[”title”]; $title = strip_tags($title); $title = htmlentities($title); $rssfile .= ” <item>\n”; $rssfile .= ”<br /> <pubDate>$pubdate</pubDate>\n”; $rssfile .= ” \n”; $rssfile .= ”<br /> <link>http://your-domain-name.com/ . post.php?post_id=$post_id</link>\n”; $rssfile .= ” <description><![CDATA[$summary]]> . </description>\n”; $rssfile .= ” </item>\n”; } while ($mypost = mysql_fetch_array($result)); } This code should again look familiar as the script loops through the posts and writes them to the $rssfile variable. Because you are writing RSS instead of HTML, the mark-up will look different, but it is still structured in a similar manner. $rssfile .=” </channel> </rss>“; Here, the final closing tags are added to the RSS feed. It is now ready for writing to your index.xml file. // write to file $fw = @fwrite($fh, $rssfile); if (!$fw) { $message = “Could not write to the file $filename”; } else { </p> </div> </div> <div class="post"> <h3 id="post-402"><a href="http://apache.armadillowebhosting.com/apache/web-server-on-xp-write-your-own-blog-engine-if-fw/" rel="bookmark" title="Permanent Link to Web server on xp - WRITE YOUR OWN BLOG ENGINE if (!$fw) {">Web server on xp - WRITE YOUR OWN BLOG ENGINE if (!$fw) {</a></h3> <small>Friday, January 25th, 2008</small> <div class="entry"> <p>WRITE YOUR OWN BLOG ENGINE if (!$fw) { $message = “Could not write to the file $filename”; } else { $message = “RSS file updated.”; } // close file fclose($fh); } else { $message = “Could not open file $filename”; } return $message; } Your code will be calling the function from more than one place, so the ideal place to add it is in the functions.php include you made earlier. Make sure that the makerssfeed function is placed before the closing ?> delimiter. I will now step through the function. It is really just a simplified version of your blog home- page: It grabs the ten most recent blog entries from the database and writes them to a file. The main differences will be the RSS file syntax (which is similar to but different from HTML) and some new functions for file handling, which is what we kick off with: function makerssfeed() { // set file to write $filename = $_SERVER[”DOCUMENT_ROOT”] . “/index.xml”; // open file $fh = @fopen($filename, “w”); if($fh) { Here, the full server path of the RSS file is written to the $filename variable. Next, the fopen function is used to open the file for writing (that s what the w means). As mentioned earlier in the chapter, the @ before the function call prevents any ugly errors being written to the screen. I m writing the fopen function to the $fh variable. If the fopen function failed (perhaps the index.xml file doesn t exist or it is read-only), the value of $fh is false, and there s no point continuing with the function. $rssfile = “<rss version=\"2.0\"> <channel><br /> <link>http://your-domain-name.com</link> <description>A blog by Samuel Pepys</description> <language>en-gb</language>“; The script has verified that your RSS file has been opened for writing, so it now starts to piece together the contents of the file. The script will compile the entire file in a variable called $rssfile and then write it to index.xml. Here the script has begun with the opening elements required by RSS (make sure that you change these details to match your 331 </p> </div> </div> <div class="post"> <h3 id="post-401"><a href="http://apache.armadillowebhosting.com/apache/blog-design-solutions-here-is-free-web-hosting-with-ftp-the-function-that/" rel="bookmark" title="Permanent Link to BLOG DESIGN SOLUTIONS Here is (Free web hosting with ftp) the function that">BLOG DESIGN SOLUTIONS Here is (Free web hosting with ftp) the function that</a></h3> <small>Thursday, January 24th, 2008</small> <div class="entry"> <p>BLOG DESIGN SOLUTIONS Here is the function that will write your RSS file: function makerssfeed() { // set file to write $filename = $_SERVER[”DOCUMENT_ROOT”] . “/index.xml”; // open file $fh = @fopen($filename, “w”); if($fh) { $rssfile = “<rss version=\"2.0\"> <channel><br /> <link>http://your-domain-name.com</link> <description>A blog by Samuel Pepys</description> <language>en-gb</language>“; // pull blogs from database $sql = “SELECT post_id, title, summary, . DATE_FORMAT(postdate, ‘%a, %d %b %Y %T GMT’) as pubdate . FROM posts ORDER BY postdate DESC LIMIT 10″; $result = mysql_query($sql); if ($mypost = mysql_fetch_array($result)) { do { $post_id = $mypost[”post_id”]; $pubdate = $mypost[”pubdate”]; $summary = format($mypost[”summary”]); $title = $mypost[”title”]; $title = strip_tags($title); $title = htmlentities($title); $rssfile .= ” <item>\n”; $rssfile .= ”<br /> <pubDate>$pubdate</pubDate>\n”; $rssfile .= ” \n”; $rssfile .= ”<br /> <link>http://your-domain-name.com/ . post.php?post_id=$post_id</link>\n”; $rssfile .= ” <description><![CDATA[$summary]]> . </description>\n”; $rssfile .= ” </item>\n”; } while ($mypost = mysql_fetch_array($result)); } $rssfile .=” </channel> </rss>“; // write to file $fw = @fwrite($fh, $rssfile); </p> </div> </div> <div class="post"> <h3 id="post-400"><a href="http://apache.armadillowebhosting.com/apache/write-your-own-blog-engine-my-web-site-figure-7-23-adding/" rel="bookmark" title="Permanent Link to WRITE YOUR OWN BLOG ENGINE (My web site) Figure 7-23. Adding">WRITE YOUR OWN BLOG ENGINE (My web site) Figure 7-23. Adding</a></h3> <small>Wednesday, January 23rd, 2008</small> <div class="entry"> <p>WRITE YOUR OWN BLOG ENGINE Figure 7-23. Adding an index to the postdate field in phpMyAdmin Now do the same for the post_id field in the comments table, and your blog database will be fully optimized. Creating an RSS feed The final thing every blog should have is an RSS feed, which is a web content syndication format. (RSS stands for Really Simple Syndication.) An RSS feed is an XML file that tells the outside world when you have updated your blog so your readers don t have to keep com ing back to your website to find out whether you made any changes. RSS feeds can be read online, through websites such as Bloglines (www.bloglines.com), or by using news reader software. There are many different news readers available for all operating systems. Your RSS feed might well end up being the most frequently downloaded file on your website. Many robots, indexers, and software will come and grab it so they can keep their users up to date with when your blog has been updated. Assuming that you want your blog to be read (and who doesn t), this is a good thing. However, it also means that your database server could end up fairly stressed if a database query were required every time the RSS file is requested. For this reason, I will show you how to create a static file that is updated only when you make a change to your blog. Because, by definition, static files do not require a database connection, your site will be more easily able to handle lots of nosy RSS software. Traditionally, the main RSS feed for a site is named index.xml. The first step is to create an empty index.xml file just create a new document in your text editor and save it to your root directory as index.xml. Because your code will eventually be rewriting this document, it needs to have read-write privileges. On Windows machines that should already be the case, but on Mac OS X machines you need to change the file properties. To do so, locate your index.xml file in Finder and select File . Get Info. Open the Details area of Ownership & Permissions and Figure 7-24. Changing file permissions select Read & Write access for Owner, Group, and Others; then close of index.xml on Mac OS X the Info window (see Figure 7-24). 329 </p> </div> </div> <div class="post"> <h3 id="post-399"><a href="http://apache.armadillowebhosting.com/apache/web-page-design-blog-design-solutions-the-code-should-be-somewhat/" rel="bookmark" title="Permanent Link to Web page design - BLOG DESIGN SOLUTIONS The code should be somewhat">Web page design - BLOG DESIGN SOLUTIONS The code should be somewhat</a></h3> <small>Wednesday, January 23rd, 2008</small> <div class="entry"> <p>BLOG DESIGN SOLUTIONS<br /> <div id="sidebar"> <?php include("searchform.php"); ?> </div> <p> <!-- sidebar ends --> </div> <p> <!-- maincontent ends --> <?php include("footer.php"); ?> </body> </html> The code should be somewhat familiar by now, with a database query first, followed by a do-while loop in the body of your page. However the SELECT statement in the database query warrants further investigation: SELECT post_id, title, summary, DATE_FORMAT(postdate, ‘%e %b %Y . at %H:%i’) . AS dateattime FROM posts WHERE . MATCH (title,summary,post) AGAINST (’$q’) LIMIT 50 MySQL text searching is performed by combing the MATCH and AGAINST functions. The arguments passed to the MATCH function should be a comma-separated list of the columns you used to create the fulltext index, and the argument to the AGAINST function should be the search term. MySQL automatically returns the results in order of relevance. Because you have only a few posts in your database, the fulltext searching can produce some unexpected results, particularly if you search for a word you know to be repeated in all your posts. In this instance, MySQL will deem the word as common, and you might receive no results for the search. However, as you write more and more, the search results become increasingly accurate. Indexing your blog database MySQL fulltext searching is extremely quick because it uses an index. If you were trying to find a topic in a reference book, you would most likely look at the index first, rather than leafing through the book page by page. In essence, this is how database indexes work, too. Every time you have a WHERE clause in a SELECT query you should ensure that you have an index on each field mentioned in the clause, which can increase speed by an order of magnitude or more (especially for tables with large amounts of data). When you created the posts table, you set the Primary Key option. When this was done, an index was automatically created for the post_id field. However, some queries are being performed on fields that are not indexed: archive.php also queries the postdate field, and post.php queries the post_id field in the comments table. To add indexes to these fields, open up phpMyAdmin in your browser, select the blog database, and click the posts link in the left frame. In the Indexes box, type 1 in the Create an index on n columns box and click Go. Now name the index as idx_postdate, select Index as the Index type (it is probably already selected) and select postdate as the Fields, then press Save (see Figure 7-23). </p> </div> </div> <div class="navigation"> <div class="alignleft"><a href="http://apache.armadillowebhosting.com/category/apache/page/2/">« Previous Entries</a></div> <div class="alignright"></div> </div> </div> <div id="sidebar"> <ul> <li> <form method="get" id="searchform" action="http://apache.armadillowebhosting.com/"> <div><input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form> </li> <!-- Author information is disabled per default. Uncomment and fill in your details if you want to use it. <li><h2>Author</h2> <p>A little something about you, the author. Nothing lengthy, just an overview.</p> </li> --> <li> <p>You are currently browsing the archives for the Apache category.</p> </li> <li><h2>Archives</h2> <ul> <li><a href='http://apache.armadillowebhosting.com/2008/01/' title='January 2008'>January 2008</a></li> <li><a href='http://apache.armadillowebhosting.com/2007/12/' title='December 2007'>December 2007</a></li> <li><a href='http://apache.armadillowebhosting.com/2007/11/' title='November 2007'>November 2007</a></li> <li><a href='http://apache.armadillowebhosting.com/2007/10/' title='October 2007'>October 2007</a></li> <li><a href='http://apache.armadillowebhosting.com/2007/09/' title='September 2007'>September 2007</a></li> <li><a href='http://apache.armadillowebhosting.com/2007/08/' title='August 2007'>August 2007</a></li> <li><a href='http://apache.armadillowebhosting.com/2007/07/' title='July 2007'>July 2007</a></li> <li><a href='http://apache.armadillowebhosting.com/2007/05/' title='May 2007'>May 2007</a></li> <li><a href='http://apache.armadillowebhosting.com/2007/04/' title='April 2007'>April 2007</a></li> </ul> </li> <li><h2>Categories</h2> <ul> <li class="current-cat"><a href="http://apache.armadillowebhosting.com/category/apache/" title="View all posts filed under Apache">Apache</a> (407) </li> </ul> </li> </ul> </div> <hr /> <div id="footer"> <!-- If you'd like to support WordPress, having the "powered by" link someone on your blog is the best way, it's our only promotion or advertising. --> <p> Apache Web Hosting Php - Php4, Php5 Programming Blog is proudly powered by <a href="http://www.visionwebhosting.net/">cheap hosting</a> <br /><a href="feed:http://apache.armadillowebhosting.com/feed/">Entries (RSS)</a> and <a href="feed:http://apache.armadillowebhosting.com/comments/feed/">Comments (RSS)</a>. <!-- 17 queries. 0.099 seconds. --> </p> </div> </div> <!-- Gorgeous design by Michael Heilemann - http://binarybonsai.com/kubrick/ --> </body> </html>