Revision [8947]

This is an old revision of AdvancedBacklinksAction made by JavaWoman on 2005-06-08 00:02:23.

 


This is the development page for a "more advanced" version of the BacklinksActionInfo backlinks action. The version presented on this page offers some functionality equivalent to that in the AdvancedCategoryAction advanced category action, specifically the option to present the output either in a columnar format or as a list.
 

Improvements and new functionality


Features


to follow - see docblock for now

Use cases


later


The code


This code completely replaces the current ./actions/backlinks.php file (make a backup if you want to try it out). This uses some parameters to control its behavior while the current (1.1.6.0) version has no such flexibility at all. Where applicable, the action parameters are equivalent to those in the AdvancedCategoryAction advanced category action.

Note that this is still 'somewhat' beta code - note also the 'todo' in the docblock.

  1. <?php
  2. /**
  3.  * Generates a list of pages linking to the current one.
  4.  *
  5.  * Features:
  6.  * - specify whether to format the output as columns or as a "flat" list
  7.  * - specify a class name as 'hook' for styling
  8.  * - a list is generated as type 'menu' so it can be given "menu" styling
  9.  * - specify a (main) heading to override the built-in defaults
  10.  *
  11.  * Note: the list view (type='list' or type='related') is nice for a sidebar while the columnar view
  12.  * (type='cols') is more suited for output within the context of a page.
  13.  *
  14.  * Syntax:
  15.  *  {{backlinks [type="cols|list"] [cols="n"] [class="class"] [head="main heading"]}}
  16.  *
  17.  * @todo        - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
  18.  *
  19.  * @package     Actions
  20.  * @subpackage  SystemContent
  21.  * @name        Backlinks
  22.  *
  23.  * @author      {@link http://wikka.jsnx.com/JavaWoman JavaWoman} (complete rewrite with parameters and table-less columns)
  24.  * @copyright   Copyright © 2005, Marjolein Katsma
  25.  * @license     http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  26.  * @since       Wikka 1.0.0
  27.  * @version     2.0beta
  28.  *
  29.  * @input       string  $type       optional: cols|list; default: cols
  30.  *                                  - cols: multi-column display, list everything. (Useful for page content)
  31.  *                                  - list: single list. (Useful for sidebar)
  32.  * @input       integer $cols       optional: number of columns to use; default: 1 (only relevant for type"cols")
  33.  *
  34.  * @input       integer $class      optional: class(es) to determine styling of the output list or columns
  35.  * @input       string  $head       optional: override of built-in main heading
  36.  *
  37.  * @output      string  list of pages linking to the current one, formatted as a list or columns of items
  38.  *
  39.  * @uses        Link()
  40.  * @uses        makeId()
  41.  * @uses        makeMemberList()
  42.  * @uses        makeMemberCols()
  43.  */
  44.  
  45. // ----------------- constants and variables ------------------
  46.  
  47. // constants
  48. $aType      = array('cols','list');
  49.  
  50. // set defaults
  51. $lCols      = 1;            # one column for columnar layout
  52. $lType      = 'cols';       # default display type
  53. $lClass     = '';           # no class
  54. $lHead      = NULL;         # specified heading (may contain place holder for category)
  55.  
  56.  
  57. // User-interface strings
  58. if (!defined('BL_HD_COL'))          define('BL_HD_COL','Backlinks');
  59. if (!defined('BL_HD_LST'))          define('BL_HD_LST','Backlinks');
  60.  
  61. if (!defined('BL_COL_PAGES_FOUND')) define('BL_COL_PAGES_FOUND','The following %d pages link to this one:');
  62. if (!defined('BL_LST_PAGES_FOUND')) define('BL_LST_PAGES_FOUND','Pages linking here:');
  63. if (!defined('BL_COL_NONE_FOUND'))  define('BL_COL_NONE_FOUND','No pages found linking to this one.');
  64. if (!defined('BL_LST_NONE_FOUND'))  define('BL_LST_NONE_FOUND','None found.');
  65.  
  66. // --------------------------- processsing --------------------------
  67.  
  68. // --------------- get parameters ----------------
  69.  
  70. if (is_array($vars))
  71. {
  72.     foreach ($vars as $param => $value)
  73.     {
  74.         switch ($param)
  75.         {
  76.             case 'type':
  77.                 if (in_array($value,$aType)) $tType = $value;
  78.                 break;
  79.             case 'compact':
  80.                 if ($value === (string)(int)$value) $tCompact = (int)$value;
  81.                 break;
  82.             case 'cols':
  83.                 if ($value === (string)(int)$value) $tCols = abs((int)$value);
  84.                 break;
  85.             case 'col':
  86.                 if ($value === (string)(int)$value) $tCol = abs((int)$value);
  87.                 break;
  88.             case 'class':
  89.                 $tClass = trim(strip_tags($value));
  90.                 break;
  91.             case 'head':
  92.                 $tHead = trim(strip_tags($value));
  93.         }
  94.     }
  95. }
  96.  
  97. // ------------- process parameters --------------
  98.  
  99. // derive display type
  100. if (isset($tType))
  101. {
  102.     $lType = $tType;
  103. }
  104. elseif (isset($tCompact))                                                   # DEPRECATED
  105. {
  106.     if (0 == $tCompact)
  107.     {
  108.         $lType = 'cols';
  109.     }
  110.     elseif (1 == $tCompact)
  111.     {
  112.         $lType = 'list';
  113.     }
  114. }
  115. //else default 'cols'
  116.  
  117. // --- presentation parameters
  118.  
  119. // columns
  120. if (isset($tCols))                                                          # overrides 'col' parameter
  121. {
  122.     $lCols = $tCols;
  123. }
  124. elseif (isset($tCol))
  125. {
  126.     $lCols = $tCol;
  127. }
  128. // class
  129. if (isset($tClass) && '' != $tClass) $lClass = $tClass;
  130. // main heading override
  131. if (isset($tHead) && '' != $tHead)
  132. {
  133.     $lHead = $tHead;
  134. }
  135. else
  136. {
  137.     switch ($lType)
  138.     {
  139.         case 'cols':
  140.             $lHead = BL_HD_COL;
  141.             break;
  142.         case 'list':
  143.             $lHead = BL_HD_LST;
  144.             break;
  145.     }
  146. }
  147.  
  148. // ---------------- gather data ------------------
  149.  
  150. // get the pages linking to this one
  151. $results = $this->LoadPagesLinkingTo($this->getPageTag());                  # result is sorted by page name
  152.  
  153. $links = array();
  154. if ($results)
  155. {
  156.     foreach ($results as $page)
  157.     {
  158.         $links[] = $this->Link($page['tag']);
  159.     }
  160. }
  161.  
  162. // ------------------ output ---------------------
  163.  
  164. // show resulting list of pages linking to this one
  165. $str ='';
  166. switch ($lType)
  167. {
  168.     case 'cols':
  169.         $attrClass = ('' != $lClass) ? ' class="backlinkcols '.$lClass.'"' : ' class="backlinkcols"';
  170.         $head = $lHead;
  171.         // start wrapper
  172.         $str .= '<div'.$attrClass.'>'."\n";
  173.         $str .= '   <h5 id="'.$this->makeId('hn','backlinks').'">'.$head.'</h5>'."\n";
  174.         // data columns
  175.         $hd   = sprintf(BL_COL_PAGES_FOUND,count($links));
  176.         $str .= $this->makeMemberCols($links,$lCols,$hd,'backlinks',BL_COL_NONE_FOUND);
  177.         // end wrapper
  178.         $str .= "</div>\n";
  179.         break;
  180.     case 'list':
  181.         $attrClass = ('' != $lClass) ? ' class="backlinklist '.$lClass.'"' : ' class="backlinklist"';
  182.         $head = $lHead;
  183.         // start wrapper
  184.         $str .= '<div'.$attrClass.'>'."\n";
  185.         $str .= '   <h5 id="'.$this->makeId('hn','backlinks').'">'.$head.'</h5>'."\n";
  186.         // data list
  187.         $hd   = BL_LST_PAGES_FOUND;
  188.         $str .= $this->makeMemberList($links,$hd,'backlinks','pagelist',BL_LST_NONE_FOUND,'menu');
  189.         // end wrapper
  190.         $str .= "</div>\n";
  191.         break;
  192. }
  193.  
  194. echo $str;
  195. ?>



Supporting code


As can be seen from the docblock (and the rest of the code) this new backlinks action requires several bits of supporting code, already posted on other pages:

Constants


The code makes use of a number of constants. See ArrayToList for the code and how to add it where.

makeId()


Used here to generate a unique id for headings; see GenerateUniqueId for the code and where to insert it. See also AdvancedFormatter for a bit of background an context for this method.

makeMemberCols()


Used to build a columnar display of category members - see ArrayToColumns for the code and further details.

makeMemberList()


Used to build a list of category members - see ArrayToList for the code and further details.



CategoryDevelopmentActions
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki