tags: site


Cautionary Backup Tale

Here is the news:

I thought it would be nice to be able to browse the old posts from work in a sensible way. Rather than having to go back 600 pages on the blog, or browsing through tags. Tags are fine in Drupal if you don't want to navigate to the next / previous node while reading a story, and are really good for quickly getting to content now I've streamlined the web site so much (lots of tagging work still to do, there, though).

So I tried a few solutions...  ...read more »





template.php

For overriding various theme functions.

<?php
/***
* template.php
*
* This file contains functions for over-riding the default theme functions
* in Drupal core and modules (look at the API documentation for more info).
* The functions don't actually _do_ anything, except pass the variables
* available to phptemplate for use in the *.tpl.php files.
*
* Add similar 'stub' functions to override other default theme functions.
*/

  // variables for fixing topics to 'on_topic' only:
function _phptemplate_variables($hook, $vars) {
 
// if ($hook == 'page') {
  // }
 
if ($hook == 'node') {
  }
  if (
module_exist('taxonomy') && $vars['node']->nid) {
    foreach (
taxonomy_node_get_terms($vars['node']->nid) as $term) {

     
// Change '123' with the vocabulary id.
     
if ($term->vid == '1') {
       
$vars['node_terms'] = $vars['node_terms'] . eregi_replace('[^a-z0-9]', '-', $term->name);
      }
    }
  }
 
// enable me to add service links to templates:
 
if (module_exist('service_links')) {
       
$vars['service_links'] = theme('links', service_links_render($vars['node']));
  }
  return
$vars;
}

 
// move rss icon to centre and give it css class:
function skipMain_feed_icon($url) {
  return
_phptemplate_callback('feedicon', array('url' => $url));
}

function
skipMain_xml_icon($url) {
  return
_phptemplate_callback('feedicon', array('url' => $url));
}

// Quotes module formatting:
function skipMain_quotes_quote($node) {
  return
_phptemplate_callback('quotes', array('node' => $node));
}

// Today's Music title
function flexinode_form_alter($form_id, & $form) {
  if (isset (
$form['type']) && $form['type']['#value'] === 'flexinode-4' && $form['type']['#value'] . '_node_form' == $form_id) {
    global
$user;
           
$form['title']['#default_value'] = t('Today\'s Music') . " " . date('d-m-Y');
  }
}

// upcoming event item
function skipMain_event_upcoming_item($node) {
  return
_phptemplate_callback('event-item', array('node' => $node));
}

//next - prev links (for 'listenings' nodes)
function next_prev($current_nid, $type, $button_type, $label, $class) {
  
$tid = db_result(db_query(db_rewrite_sql("SELECT tid FROM {term_node} WHERE nid = $current_nid;")));
   if (empty(
$tid)){
    return
'';
   }

   switch (
$button_type) {
     case
'next':
      
$sort= 'DESC';
      
$case = '< ';
       break;
     case
'prev':
      
$sort = 'ASC';
      
$case = '> ';
       break;
     case
'parent':
      
$name = db_result(db_query(db_rewrite_sql("SELECT name FROM {term_data} WHERE tid = $tid;")));
       return
l($label.'up', "$name", array('title' => $name, 'class' => $class));
       break;
     case
'last':
      
$sql  = "SELECT n.nid, n.title FROM node n INNER JOIN term_node t ON n.nid = t.nid";
      
$sql .= " INNER JOIN term_data r ON t.tid = r.tid WHERE n.type = '". $type ."'";
      
$sql .= " AND r.tid = $tid AND n.status = 1 ORDER BY nid ASC LIMIT 0 , 1";
      
$result = db_fetch_array(db_query(db_rewrite_sql($sql)));
       return
l($label, 'node/'. $result['nid'], array('title' => $result['title'], 'class' => $class));
       break;
     case
'first':
      
$sql  = "SELECT n.nid, n.title FROM node n INNER JOIN term_node t ON n.nid = t.nid";
      
$sql .= " INNER JOIN term_data r ON t.tid = r.tid WHERE n.type = '" .$type. "'";
      
$sql .= " AND r.tid = $tid AND n.status = 1 ORDER BY nid DESC LIMIT 0 , 1";
      
$result = db_fetch_array(db_query(db_rewrite_sql($sql)));
       return
l($label, 'node/'. $result['nid'], array('title' => $result['title'], 'class' => $class));
       break;
     default:
       return
NULL;
       break;
   }
  
$sql = "SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid ";
  
$sql .= "INNER JOIN {term_data} r ON t.tid = r.tid WHERE n.type = '". $type ."' AND n.nid ". $case;
  
$sql .= $current_nid ." AND r.tid = ". $tid ." AND n.status = 1 ORDER BY nid ". $sort;
  
$result = db_fetch_array(db_query(db_rewrite_sql($sql)));
   if (!
$result) {
     return
NULL;
     return
l($label.$name, "$type/tid/$tid", array('title' => $name, 'class' => $class));
   } else {
     return
l($label, 'node/'. $result['nid'], array('title' => $result['title'], 'class' => $class));
   }
}
?>






node-page.tpl.php

Themes 'pages' which are a different sort of node. Bristol Venues is a page.

<div class="cnr-<?php print $node_terms; ?>">
<div class="tax-<?php print $node_terms; ?>">
<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">

  <?php if ($page == 0): ?>
    <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
  <?php endif; ?>

  <div class="content">
  <?php print $content ?>
  </div>
<br class="clear" />

<?php if ($links): ?>
  <div class="links"><?php print $links ?></div>
<?php endif; ?>

</div>
</div>
</div>
<br class="clear" />






admin.tpl.php

this is the page template for all Administration pages. Only I can see this style, basically all the fancy Flickr stuff in the header is removed and I get my blocks on the left.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language ?>" xml:lang="<?php print $language ?>">
<head>
  <title><?php print $head_title ?></title>
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="ICBM" content="51.467046,-2.582910" />
  <meta name="DC.title" content="<?php print($site_name) ?>" />
  <meta name="geo.position" content="51.467046,-2.582910" />
  <meta name="geo.placename" content="Bristol, England" />
  <meta name="geo.region" content="GB-BST" />

<!-- NIFTY CORNERS -->
<link rel="stylesheet" type="text/css" href="/<?php print $directory ?>/niftyCorners.css" />
<link rel="stylesheet" type="text/css" href="/<?php print $directory ?>/niftyPrint.css" media="print" />
<script type="text/javascript" src="/<?php print $directory ?>/nifty.js"></script>
<script type="text/javascript" src="/<?php print $directory ?>/layout.js"></script>
<!-- end nifty -->

  <?php print $head ?>
  <?php $styles .= theme('stylesheet_import', base_path() . path_to_theme() . '/admin.css'); ?>
  <?php print $styles ?>
</head>

<body>
<div id="mainCorners">
<div id="mainContainer">

<div id="header">
<div class="headerBG">
  <?php print $search_box ?>
  <?php if ($site_name) : ?>
<h1 id="site-name"><a href="<?php print url() ?>" title="Index Page"><?php print($site_name) ?></a></h1>
  <?php endif;?>
  <?php print $header ?>
</div>
</div>

<div id="top-nav">
<?php print $breadcrumb ?>
    <ul id="primary">
    <li><?php global $user; if (!$user->uid) {
print
'<a href="/user/login">login</a>';
} elseif (
$user->uid) {
print
'<a href="/logout">logout</a></li><li><a href="/admin">administer</a></li>';
}
?>
</li>
    <?php if (count($primary_links)) : ?>
    <?php foreach ($primary_links as $link): ?>
      <li><?php print $link?></li>
    <?php endforeach; ?>
    </ul>
  <?php endif; ?>
</div>

<table id="content">
  <tr>
    <?php if ($sidebar_left != ""): ?>
      <td class="sidebar" id="sidebar-left">
        <?php print $sidebar_left ?>
      </td>
    <?php endif; ?>   
        <td class="main-content" id="content-<?php print $layout ?>">
        <?php if ($title != ""): ?>
          <h2 class="content-title"><?php print $title ?></h2>
        <?php endif; ?>
        <?php if ($tabs != ""): ?>
          <?php print $tabs ?>
        <?php endif; ?>
       
        <?php if ($help != ""): ?>
          <p id="help"><?php print $help ?></p>
        <?php endif; ?>
       
        <?php if ($messages != ""): ?>
          <div id="message"><?php print $messages ?></div>
        <?php endif; ?>
       
        <!-- start main content -->
        <?php print($content) ?>
        <!-- end main content -->
        </td><!-- mainContent -->
  </tr>
</table>
  <?php if (count($secondary_links)) : ?>
    <ul id="secondary">
    <?php foreach ($secondary_links as $link): ?>
      <li><?php print $link?></li>
    <?php endforeach; ?>
    </ul>
  <?php endif; ?>

<?php print $closure;?>
</div>
</div>
  </body>
</html>






node-book.tpl.php

Defines 'book' pages. My India Diaries are all book Pages.

<div class="cnr-<?php print $node_terms; ?>">
  <div class="tax-<?php print $node_terms; ?>">
<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">

  <?php if ($page == 0): ?>
    <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
  <?php endif; ?>

  <div class="content">
    <?php print $content ?>
  </div>
<br class="clear" />

<?php if ($links): ?>
  <div class="links"><?php print $links ?></div>

<br class="clear" />
  <div class="service-links">
    <?php print $service_links ?>
  </div>
<?php endif; ?>

</div>
  </div>
</div>
<br class="clear" />