emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] Sacha Chua: changes to your php code and website ge


From: Joe Steeve
Subject: [emacs-wiki-discuss] Sacha Chua: changes to your php code and website generation
Date: Thu, 14 Apr 2005 15:14:03 +0530
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Well, a year back I shamelessly stole the PHP + planner
configurations of Sacha Chua to have some nice features such as a
autogenerated calendar and such. Recently I decided to do some
changes to it, to improve it. Herewith I've included the new
code. Please have a look at it, and comment/improve it. :) All
this code is working fine on my site http://joe.bsdnerds.org/ :)

Sorry., this is going to be a looong mail.

Note: you can use the Calendar.php unmodified. And, I'm no
PHP/Elisp programmer, so there is a very good possibility that
I'm doing some big mistakes in the code. So, please use it with
caution. :)

1. File: planner-include.php: This new version does not provide
   support for the today.php or the previous-day, next-day
   links. May be there should be some way of generating this from
   elisp. I'll have to look into it later. However, when there are
   a lot of day-pages, Sacha Chua's original code would overload
   the server by loading the entire file list into an array. Well,
   I guess that was the only way to get a arranged list. Other
   ways are way too complicated. This new code does not do that.,
   so it kinda server friendly :)

<?
$page = "";

/* pad zeros infront of a given string to $n len */
function pad($s, $n)
{
  $r = $s;
  while (strlen($r) < $n)
    {
      $r = "0".$r;
    }
  return $r;
}

function get_day_page($day, $month, $year)
{
  return pad($year, 4) . "." . pad($month, 2) . "." . pad($day, 2) . ".php";
}

class PlannerCalendar extends Calendar
{
    
  function getDateLink($day, $month, $year)
  {
    $dir = get_day_page($day, $month, $year);
    if (file_exists($dir))
      {
        return $dir;
      }
    else
      {
        return "";
      }
  }

  function getCalendarLink($month, $year)
  {
    return pad($year, 4) . "." . pad($month, 2) . ".php";
  }
}

$cal = new PlannerCalendar;
?>

2. File: header.php: This file should made as the emacs-wiki
   header file. i.e. should make emacs-wiki include this file as a
   header in every file it publishes. Please look into the
   code. It is fairly simple. Just some embedded elisp code. I've
   made elisp do most of the junk that originally PHP was trying
   to do.

<?
$msg = "";
$myaddress = "address@hidden";

require_once "src/calendar.php";
require_once "src/planner-include.php";

$page = "<lisp>(emacs-wiki-page-name)</lisp>.php";

$curr_day = "<lisp>
   (if (string-match planner-date-regexp (emacs-wiki-page-name))
       (substring (emacs-wiki-page-name) 8 10)
    "")</lisp>";
$curr_month = "<lisp>
   (if (string-match joe-month-year-regexp (emacs-wiki-page-name))
       (substring (emacs-wiki-page-name) 5 7)
    "")</lisp>";
$curr_year = "<lisp>
   (if (string-match joe-month-year-regexp (emacs-wiki-page-name))
       (substring (emacs-wiki-page-name) 0 4)
    "")</lisp>";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
  <head>
    <title>Joe's homepage :: <lisp>(emacs-wiki-page-title)</lisp></title>
    <meta name="generator" content="emacs-wiki.el">
    <meta http-equiv="<lisp>emacs-wiki-meta-http-equiv</lisp>"
          content="<lisp>emacs-wiki-meta-content</lisp>">
    <link rev="made" href="<lisp>emacs-wiki-maintainer</lisp>">
    <link rel="home" href="<lisp>(emacs-wiki-published-name
                                     emacs-wiki-home-page)</lisp>">
    <link rel="index" href="<lisp>(emacs-wiki-published-name
                                      emacs-wiki-index-page)</lisp>">
    <link rel="stylesheet" type="text/css" 
href="<lisp>emacs-wiki-style-sheet</lisp>">
  </head>
  <body>
  <div id="sidebar">
<?
if ($curr_month && $curr_year)
{
  print $cal->getMonthView($curr_month, $curr_year);
}
else
{
  print $cal->getCurrentMonthView();  
}
?>

</div>
   <div id="banner">
     <h1>Joe Steeve :: <lisp>(emacs-wiki-page-title)</lisp></h1>
     <div id="banner_links">
       <a href="index.php">Home</a> |
       <a href="cgi-bin/blosxom.cgi">Articles</a> <a 
href="cgi-bin/blosxom.cgi/index.rss"><img border="0" src="images/xml.png" 
alt="XML"></a> |
       <a href="RecentPosts.php">Journal</a> <a href="journal.rdf"><img 
border="0" src="images/xml.png" alt="XML"></a> |
       <a href="Bookmarks.php">Bookmarks</a>
     </div><!--banner_links-->
   </div><!--banner-->
   <div id="content">
      <!-- Page published by Emacs Wiki begins here -->

3. File: footer.php : And here is the footer.php which should be
   included as a footer by emacs-lisp.

<html><head><!-- Page published by Emacs Wiki ends here --></head>
<hr size="1">
<table width=100%>
<tr><td=50%>
Updated:  <lisp>(format-time-string emacs-wiki-footer-date-format (nth 5 
(file-attributes buffer-file-name)))</lisp><br>
<a href="http://www.gnu.org/software/emacs/";><img src="images/emacs.png" 
alt="emacs"></a>
</td><td width=50% align="right">
<a href="WikiIndex.php">Index</a>
<a href="#top">Top</a>
</td></tr>
</table>
<hr size="1">

</div>
</body></html>

Thats all folks., have fun :)

-- 
.O. A proud GNU user
..O http://www.joesteeve.tk/
OOO http://joe.bsdnerds.org/

Attachment: pgpVQ8nhXsU5m.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]