]> git.quilime.com - plog_bk.git/commitdiff
template editing, major editing to index file
authorGabriel Dunne <gdunne@quilime.com>
Fri, 2 Jul 2010 02:01:24 +0000 (19:01 -0700)
committerGabriel Dunne <gdunne@quilime.com>
Fri, 2 Jul 2010 02:01:24 +0000 (19:01 -0700)
12 files changed:
index.php
lib/data.php
lib/output.php
lib/template.php
templates/about.html.tpl
templates/code.html.tpl
templates/default.html.tpl [moved from templates/index.html.tpl with 67% similarity]
templates/default.json.tpl [moved from templates/index.json.tpl with 100% similarity]
templates/entry.html.tpl
templates/index.html [deleted file]
templates/links.html.tpl
templates/log.html.tpl

index 7df8b0b6946c5831de74768773dc3ddc9ba0d7c0..905854903adb9b488bf713f2601780553b3d0693 100644 (file)
--- a/index.php
+++ b/index.php
@@ -4,55 +4,56 @@
 
     $url_parts = get_url();
 
-//     print_r($url_parts);
-       
-//     echo "<br/><br/>";
-
        list($response_format, $response_mime_type) = parse_format($url_parts['extension'], 'html');    
        
        $t = get_template_instance();   
-       
-       $view = isset($_GET['v']) ? $_GET['v'] : 'inline';
-
-    if (is_string($url_parts['basename'])) 
-       {
-
-               # base content folder
-               if (is_dir  ( CONTENT_DIR . DIRECTORY_SEPARATOR . $url_parts['basename'])) {
-                       
-                       list($items, $total) = get_data(array($url_parts['basename']));                 
-                       $t->assign('items', $items);
-                       $t->assign('total', $total);
-                       $t->assign('view', $view);
-                       $t->render($url_parts['basename'] . '.' . $response_format . '.tpl');
-            exit;
-        }
+       $t->response_format = $response_format;
 
-               # single entry
-        else if ($url_parts['dirname'] != '.' && is_dir(CONTENT_DIR . $url_parts['dirname'])) {
+       $t->assign('view', $_GET['v']);
+       
+       
+       # content folder
+       if (is_dir(CONTENT_DIR . DIRECTORY_SEPARATOR . $url_parts['url']) && $url_parts['basename']) {
+               list($data, $total) = get_data(array($url_parts['basename']));                  
+               $t->assign('data', $data);                              
+               $template = $url_parts['basename'] . '.' . $response_format . '.tpl';
+       }
        
-                       $t->assign('single', true);
-                       $t->assign('item', parse_config(CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename']));
-                       $t->assign('content', $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename']);
-                       
-                       $t->render($url_parts['dirname'] . '.' . $response_format . '.tpl');    
-            exit;
-        }
+       
+       # single file
+       else if (is_file( CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename'])) {
+               $t->assign('single', true);
+               $t->assign('data', parse_config(CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename']));
+               $t->assign('content', $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename']);    
+               $template = $url_parts['dirname'] . '.' . $response_format . '.tpl';    
+       }
+       
+               
+       # direct template
+       else if (is_file( TEMPLATE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'] .'.'. $response_format . '.tpl'))
+       {
+               $template = $url_parts['filename'] . '.' . $response_format . '.tpl';
+       }
 
-               # not found
-        else  {
-                       $t->render('404.'.$response_format.'.tpl');
-            exit;
-        }
 
-    }
+       # 404
+       else if ($url_parts['basename']) {      
+               $template = '404.'.$response_format.'.tpl';
+       }
 
 
-       # render all entries inline
-       list($entries, $total) = get_inline_entries(array('log', 'code'));      
+       # default (index)
+       else {
+               list($data, $total) = get_data();
+               $t->assign('data', $data);
+               $template = 'default.'.$response_format.'.tpl';
+       }
        
-       $t->assign('entries', $entries);
-       $t->assign('total', $total);
-       $t->render('index.'.$response_format.'.tpl');
-
+       
+       
+       
+       # render template
+       $t->assign('total', $total);    
+    header("Content-Type: {$response_mime_type}; charset=UTF-8");
+       $t->render($template);
 ?>
index 20ecec107e42c443608cc1021b5f3cb063ec6a49..bd8d3d3b8431d249657df49fd7f8f28178668194 100644 (file)
@@ -1,15 +1,24 @@
 <?php
 
-
-# parse inline content
-function get_data( $sources,  $params = array() )
+// parse inline content
+function get_data( $sources = array(),  $params  = array())
 {
+       // if no set sources, grab everything in content folder
+       if (sizeof($sources) == 0)
+               $sources = glob(LOCAL_ROOT . CONTENT_DIR . DIRECTORY_SEPARATOR . '/*');
+       
        $result = array();
        $result_total = 0;
        foreach ($sources as $dir) {
+               
+               $dir = basename($dir);
+               
                $contents = glob(LOCAL_ROOT . CONTENT_DIR . DIRECTORY_SEPARATOR . $dir . '/*');
+               
+               if (sizeof($contents) <= 0) continue;
+                               
                foreach ($contents as $f) {
-                       if (!is_dir($f)) {
+                       if (is_file($f)) {
                                
                                if ($params['name']) {                                  
                                        if (basename($f) != $params['name'])
@@ -30,9 +39,12 @@ function get_data( $sources,  $params = array() )
                                }
                                
                                $config = parse_ini_string($cc);
+                                                               
+                               if ($config['draft'])
+                                       continue;
                                
                                $config['url'] = WEB_ROOT . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . basename($f);
-                               $config['timestamp'] = mktime($config['date']);
+                               $config['timestamp'] = $config['date'] ? mktime($config['date']) : mktime(filemtime($f));
                                $config['category'] = $dir;
                                $config['content'] = $content;
                                $config['tags'] = explode(' ', $config['tags']);
@@ -45,16 +57,16 @@ function get_data( $sources,  $params = array() )
        
        // order by date
        foreach ($result as $key => $row) {
-           $time[$key]  = $row['date'];
+           $time[$key] = $row['timestamp'];
        }
-       array_multisort($time, SORT_DESC, $result);
+       if ($time)
+               array_multisort($time, SORT_DESC, $result);
        
        return array($result, $result_total);
 }
 
 
 
-
 function list_content($path, $args="")
 {
     list($list, $total) = get_content($path, $args);
@@ -105,7 +117,7 @@ function parse_config ($config_file)
         }
         
         if ($break) {
-            $config['inline_content'] .= $c;                
+            $config['inline_content'] .= $c . "\n";                
         }
         else {
             $conf = explode("=", $c);
index 112c083382d4c01932bddfc18eb2468b0f03ff02..caf3ce1728b68fcc48484b0fd958ca7e4054a363 100644 (file)
@@ -61,7 +61,9 @@
     
     function get_url()
     {
-        return pathinfo($_SERVER['SCRIPT_URL']); //substr($_SERVER['SCRIPT_URL'], strlen(get_base_dir() . '/'));
+               $path_info = pathinfo($_SERVER['SCRIPT_URL']);
+               $path_info['url'] = $_SERVER['SCRIPT_URL'];
+        return $path_info; //substr($_SERVER['SCRIPT_URL'], strlen(get_base_dir() . '/'));
     }
     
     
index 5be035b33b59cba3eff4fcae8e0b8ccaaa0148fe..31598dac2131632cd25d4f39140d8404d82733d8 100644 (file)
@@ -3,6 +3,7 @@
 class Template
 {
        var $template_dir = 'templates';
+       var $response_format = 'html';
        
        var $_tpl_vars = array();
 
@@ -35,8 +36,13 @@ class Template
 
        public function render( $template )
        {
-               extract( $this->_tpl_vars );    
-               include( $this->template_dir . DIRECTORY_SEPARATOR  . $template );
+               extract( $this->_tpl_vars );
+               
+               if (is_file($this->template_dir . DIRECTORY_SEPARATOR . $template))
+                       include( $this->template_dir . DIRECTORY_SEPARATOR . $template );
+               else
+                       include( $this->template_dir . DIRECTORY_SEPARATOR . 'default.'.$this->response_format.'.tpl' );                
+                       
        }
 }
 
index 21784ec2fe3c7d50ff10cc42dc6817a55df99378..341913c487c235e25265f2e5013f59f2de885f2f 100644 (file)
@@ -2,7 +2,7 @@
 
 <head>
 
-    <?php include_template( 'header-src.html' ); ?>
+    <?php $this->include_template( 'head-inc.html.tpl' ); ?>
         
     <title><?php echo SITE_TITLE ?> - about</title>
     
index 2502d790eaa10c692c8288c50f0090942b098c35..852a18a03c68282aa50ed4c3ee8891473ca07026 100644 (file)
@@ -1,33 +1,19 @@
-<?php
-
-
-    $items = array();
-    $single = false;
-    
-    if (is_dir(CONTENT_DIR . $url_string) && !is_file(CONTENT_DIR . $url_string . '/config') ) {
-               list($items, $total) = get_inline_entries(array('code'));       
-    //    list($items_list, $total) = get_content(basename($url_string));
-    }
-    else {
-               list($items, $total) = get_inline_entries(array('code'), array('name'=>basename($url_string)));         
-               $items = $items[0];
-        $single = true;
-    }
-
-       $inline = isset($_GET['inline']) ? true : false;
-       
-       $page = "code";
-
-
-?>
 <html>
 
 <head>
-    <?php include_template('header-src.html'); ?>
-    <script src="/js/jquery-1.3.2.min.js"></script>
-    
-    <title><?php echo SITE_TITLE; ?> - code<?php if (sizeof($items) > 0 ) : ?>: <?echo strtolower($items['title']); ?> [<?php echo $items['medium']; ?>]<?php endif; ?></title>
+       
+    <? $this->include_template('head-inc.html.tpl') ?>
         
+    <title>
+        <?=SITE_TITLE; ?>
+        <? if ($single): ?> 
+                       - code: <?= $data['title']; ?> 
+                       [<?=date("Y M d", strtotime($data['date']));?>]
+               <? else: ?>
+                       - code
+               <? endif; ?>
+       </title>
+
 </head>
 
 <body>
        
         <?php if ($single) : ?>
 
-                       <h2><?=$items['title']?> [<?=$items['date']?>]</h2>
+                       <h2><?=$data['title']?> [<?=$data['date']?>]</h2>
 
             <div class="content">
                 <?php 
-                    print ($items['content']);
+                    echo ($data['inline_content']);
                 ?>
             </div>
        
@@ -53,7 +39,7 @@
 <div class="func"><a href="/code/">list</a></div>              
        
             <ul class="inline_content">
-            <?php foreach($items_list as $items): ?>
+            <?php foreach($data as $items): ?>
                    <li>
                        <h3>
                            <a href="<?php echo $items['href']?>"><?php echo $items['title']; ?></a>
@@ -85,7 +71,7 @@
 
                 <?php
                 $c = 1; 
-                foreach($items as $item): 
+                foreach($data as $item): 
                                
 //                             print_r($item);
 
similarity index 67%
rename from templates/index.html.tpl
rename to templates/default.html.tpl
index 0342c64dc2079c852af86f0d3fe5e156c51f4bd1..698ed55c3741e196878d44a3c5a0dbd59799c0ae 100644 (file)
     
 <div id="content">
 
-       <? foreach($entries as $entry): ?>
+       <? foreach($data as $entry): ?>
        <? $this->include_template('entry.html.tpl', array('entry' => $entry)); ?>
        <? endforeach; ?>
        
+       <? if ($view == "archive") : ?>
+               <a href="<?=$list_url?>">view list</a>
+       <? else : ?>
+               <a href="<?=$archive_url?>">view archive</a>
+       <? endif; ?>    
+       
 </div>
 
+
        <? $this->include_template('footer.html.tpl') ?>
 
 </body>
index d60ee659f9e1252606342ee6c1dc7cf354fa9a38..168b73004f7a179b205b45668b51000e9624311a 100644 (file)
@@ -1,4 +1,3 @@
-
 <div class="entry">
        
        <h2>
@@ -10,4 +9,5 @@
        <?=$entry['content']?>
        
        </div>
+       
 </div>
diff --git a/templates/index.html b/templates/index.html
deleted file mode 100644 (file)
index 07d581d..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<html>
-
-<head>
-    
-    <?php include_template('header-src.html'); ?>
-    
-    <title><?php echo SITE_TITLE; ?></title>
-    
-</head>
-
-<body>
-    
-    <? include_template('nav.html'); ?>
-    
-<div id="content">
-<--- nav    
-</body>
-</html>
index ef7e0dd69a9597340898870fe3190d20fdd21af7..112ef3d1bd652e6885b32a30d5f1760aaf9a7dcf 100644 (file)
@@ -6,7 +6,7 @@
 
 <head>
 
-    <?php include_template('header-src.html'); ?>
+    <?php $this->include_template('header-src.html'); ?>
 
     <title><?php echo SITE_TITLE ?> - links</title>
 
@@ -25,7 +25,7 @@
             function linklist($links)
             { ?>
                 <?php foreach($links as $l) : ?>
-                <li><a href="http://<?php echo $l[0];?>"><?php echo $l[1];?></a></li>
+                <li><a href="http://<?php echo $l[0];?>"><?php echo $l[1];?></a> &rarr;</li>
                 <?php endforeach; ?>
             <?php
             }
@@ -49,8 +49,8 @@
                     array('digitanalog.net', 'marc nimoy'),
                     array('makaga.com', 'matthew gale'),
                     array('fredericeyl.de', 'frédéric eyl'),
-                    array('thegreeneyl.com', 'the green eyl'),
-                                       array('local.wasp.uwa.edu.au/~pbourke/', '')
+                    array('thegreeneyl.com', 'the green eyl')
+//                                     array('local.wasp.uwa.edu.au/~pbourke/', '')
                     );
         ?>
 
index aea4be93009e42e87110c63c93d47ffbc6e4afcd..02ebf5fab61b87e7323a4ca4afd348bf481768f8 100644 (file)
@@ -1,24 +1,3 @@
-<?php
-/*
-    $items = array();
-    $single = false;
-    
-    if (is_dir(CONTENT_DIR . $url_string) && !is_file(CONTENT_DIR . $url_string . '/config') ) {
-        list($items, $total) = get_inline_entries(array('log'));
-        //list($log_list, $total) = get_content(basename($url_string), "type=flat");
-    }
-    else {
-        $config = parse_config(CONTENT_DIR . $url_string);
-        $log = $config;
-        $base_dir = $log['base_dir'];        
-        $single = true;        
-    }
-    
-    $list = isset($_GET['list']) ? $_GET['list'] : false;
-
-       $page = "/log";
-*/
-?>
 <html>
 
 <head>
@@ -28,8 +7,8 @@
     <title>
         <?=SITE_TITLE; ?>
         <? if ($single): ?> 
-                       - log: <?= $entry['title']; ?> 
-                       [<?=date("Y M d", strtotime($entry['date']));?>]
+                       - log: <?= $data['title']; ?> 
+                       [<?=date("Y M d", strtotime($data['date']));?>]
                <? else: ?>
                        - log
                <? endif; ?>
 
 <body>
     
-    <?php include('nav.html'); ?>
+    <?php $this->include_template('nav.html'); ?>
 
     <div id="content">
 
         <?php if ($single) : ?>
+       
+                       <? //$this->include_template('entry.html.tpl', array('entry' => $item)); ?>             
 
                <h2>
-                   <a title="posted <?php echo get_relative_time($item['timestamp']); ?>" href="<?php echo $item['url'];?>">
-                       <?php echo $item['title']; ?>
-                               </a><small>[<?php echo date("Y M d", strtotime($item['date']));?>]</small>
-               </h2>
-       
-                       
+                   <a title="posted <?php echo get_relative_time($data['timestamp']); ?>" href="<?php echo $data['url'];?>">
+                       <?php echo $data['title']; ?>
+                               </a><small>[<?php echo date("Y M d", strtotime($data['date']));?>]</small>
+               </h2>           
        
             <div class="content">
-            <?=$item['inline_content'];?>
-            </div>
-                                
+            <?=$data['inline_content'];?>
+            </div>                     
+
         <?php elseif ($view == 'archive'): ?>
         
            <table class="archive" cellspacing="0" cellpadding="0">
@@ -68,7 +47,7 @@
                 </td>
                 <?php 
                     $c = 1; 
-                    foreach($items as $log): 
+                    foreach($data as $log): 
                 ?>
                 <tr>
                 <td style="text-align:right; padding-right:1em;">
@@ -76,7 +55,7 @@
                 </td>
                 <td>
                     <strong>
-                                   <a onmouseout="$('.c_pop').hide();" onmouseover="$('.c_pop').hide(); $('#c_<?php echo $c; ?>').show();" href="<?php echo $log['href']?>"><?php echo $log['title']; ?></a>
+                                   <a onmouseout="$('.c_pop').hide();" onmouseover="$('.c_pop').hide(); $('#c_<?php echo $c; ?>').show();" href="<?php echo $log['url']?>"><?php echo $log['title']; ?></a>
                                </strong>
                     <div id="c_<?php echo $c; ?>" class="c_pop">
                     <?=$log['content']; ?>
@@ -97,7 +76,7 @@
         <?php else: ?>
        
             <ul class="inline_content log">
-            <?php foreach($items as $log): ?>
+            <?php foreach($data as $log): ?>
                    <li>
                        <h3>