Backspaces

September 29, 2004

Textile, Textpattern, and the Meaning of Life

Filed under: Hacks — backspaces @ 12:24 pm

Overview

So what is all this. First of all, recall from our earlier presentations, the New Web looks like:

  1. XHTML and CSS
  2. PHP and MySql
  3. Site Management

Textile and Textpattern address the third area.

Installation

.. 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("& ","&#38; ", $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;
    }
// -------------------------------------------------------------

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress