Overview
So what is all this. First of all, recall from our earlier presentations, the New Web looks like:
- XHTML and CSS
- PHP and MySql
- Site Management
Textile and Textpattern address the third area.
Installation
- Deannload textpattern
- Create textpattern MySql DB
- Browser setup.php
- Browser admin
- Backspaces Home Page
.. lets take a test drive!
Links
Code Fragments
First, here’s my modified index.php file. This is the index file for anyone beaming into http://backspaces.net/. It uses php to redirect folks to the http://complexityworkshop.com/ site and any other sites I co-host. The last segment is the default php for textpattern itself.
// -------------------------------------------------------------
<?php
$server = $_SERVER['HTTP_HOST'];
if (eregi("complexity", $server)) {
header("Location: /cw/");
} elseif (eregi("wireless", $server)) {
header("Location: /sites/acequia/");
} else {
include 'textpattern/config.php';
include $txpcfg['txpath'].'/publish.php';
textpattern();
}
?>
Next, this is an example of the implementation of a Textpattern tag, in this case the
<txp:linklist category="xxx" />
tag used for displaying links like those in my default sidebars.
// -------------------------------------------------------------
function linklist($atts) // possible atts: form, sort, category, limit, label
{
if(is_array($atts)) extract($atts);
if(!isset($form)) $form = 'plainlinks';
if(!isset($sort)) $sort = 'linksort';
$Form = fetch('Form','txp_form','name',$form);
$wraptag = (empty($wraptag)) ? '' : $wraptag;
$qparts = array(
(!empty($category)) ? "category='$category'" : '1',
"order by",
$sort,
(!empty($limit)) ? "limit $limit" : ''
);
$rs = safe_rows("*","txp_link",join(' ',$qparts));
if ($rs) {
$outlist = (!empty($label)) ? $label : '';
foreach ($rs as $a) {
extract($a);
$linkname = str_replace("& ","& ", $linkname);
$link = '<a href="'.$url.'">'.$linkname.'</a>';
$linkdesctitle = '<a href="'.$url.
'" title="'.$description.'">'.$linkname.'</a>';
$out = str_replace("<txp:link />", $link, $Form);
$out = str_replace("<txp:linkdesctitle />", $linkdesctitle, $out);
$out = str_replace("<txp:link_description />", $description, $out);
$outlist .= $out;
}
return ($wraptag) ? tag($outlist,$wraptag) : $outlist;
}
return false;
}
Here is an example of the Textpattern utilities available to plugin developers.
// -------------------------------------------------------------
function safe_query($q='',$debug='',$unbuf='')
{
global $DB,$txpcfg;
$method = (!$unbuf) ? 'mysql_query' : 'mysql_unbuffered_query';
if (!$q) return false;
if ($debug) {
dmp($q);
dmp(mysql_error());
}
$result = $method($q,$DB->link);
if(!$result) return false;
return $result;
}
// -------------------------------------------------------------