Wiki source for AdvancedBacklinksAction


Show raw source

=====Advanced Backlinks Action=====
//Installed as an **[[WikkaBetaFeatures alpha feature]]** on this server as of 2005-06-12.//

>>**See also:**
//official//
~-BacklinksActionInfo
//supporting code//
~-ArrayToList
~-ArrayToColumns
~-GenerateUniqueId
~-CompatibilityCode
~-AdvancedFormatter
//related//
~-AdvancedCategoryAction
>>This is the development page for a "more advanced" version of the [[Docs: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.::c::
====Improvements and new functionality====

===Features===

~-Choose between columnar or list format output with the **##type##** parameter (default cols)
~-For columnar output, set the number of columns with the **##cols##** parameter (default is 1); it will produce columns in the form of left-floated divs
~-In list format output, the list gets an ##id## in group 'menu' so it can be given menu styling (useful for use in a sidebar)
~-Output is wrapped in a ##div## with class "backlinkcols" or "backlinklist" as an easy hook for styling; use the **##class##** parameter to add extra classes
~-The automatically-generated (main) heading (also with an ##id##) can be overridden with the **##head##** parameter

===Syntax===
""{{backlinks [type="cols|list"] [cols="n"] [class="class"] [head="main heading"]}}""

===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.//

%%(php;1)<?php
/**
* Generates a list of pages linking to the current one.
*
* Features:
* - specify whether to format the output as columns or as a "flat" list
* - specify a class name as 'hook' for styling
* - a list is generated as type 'menu' so it can be given "menu" styling
* - specify a (main) heading to override the built-in defaults
*
* Note: the list view (type='list' or type='related') is nice for a sidebar while the columnar view
* (type='cols') is more suited for output within the context of a page.
*
* Syntax:
* {{backlinks [type="cols|list"] [cols="n"] [class="class"] [head="main heading"]}}
*
* @todo - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
*
* @package Actions
* @subpackage SystemContent
* @name Backlinks
*
* @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} (complete rewrite with parameters and table-less columns)
* @copyright Copyright © 2005, Marjolein Katsma
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @since Wikka 1.0.0
* @version 2.0beta
*
* @input string $type optional: cols|list; default: cols
* - cols: multi-column display, list everything. (Useful for page content)
* - list: single list. (Useful for sidebar)
* @input integer $cols optional: number of columns to use; default: 1 (only relevant for type"cols")
*
* @input integer $class optional: class(es) to determine styling of the output list or columns
* @input string $head optional: override of built-in main heading
*
* @output string list of pages linking to the current one, formatted as a list or columns of items
*
* @uses Link()
* @uses makeId()
* @uses makeMemberList()
* @uses makeMemberCols()
*/

// ----------------- constants and variables ------------------

// constants
$aType = array('cols','list');

// set defaults
$lCols = 1; # one column for columnar layout
$lType = 'cols'; # default display type
$lClass = ''; # no class
$lHead = NULL; # specified heading (may contain place holder for category)


// User-interface strings
if (!defined('BL_HD_COL')) define('BL_HD_COL','Backlinks');
if (!defined('BL_HD_LST')) define('BL_HD_LST','Backlinks');

if (!defined('BL_COL_PAGES_FOUND')) define('BL_COL_PAGES_FOUND','The following %d pages link to this one:');
if (!defined('BL_LST_PAGES_FOUND')) define('BL_LST_PAGES_FOUND','Pages linking here:');
if (!defined('BL_COL_NONE_FOUND')) define('BL_COL_NONE_FOUND','No pages found linking to this one.');
if (!defined('BL_LST_NONE_FOUND')) define('BL_LST_NONE_FOUND','None found.');

// --------------------------- processsing --------------------------

// --------------- get parameters ----------------

if (is_array($vars))
{
foreach ($vars as $param => $value)
{
switch ($param)
{
case 'type':
if (in_array($value,$aType)) $tType = $value;
break;
case 'compact':
if ($value === (string)(int)$value) $tCompact = (int)$value;
break;
case 'cols':
if ($value === (string)(int)$value) $tCols = abs((int)$value);
break;
case 'col':
if ($value === (string)(int)$value) $tCol = abs((int)$value);
break;
case 'class':
$tClass = trim(strip_tags($value));
break;
case 'head':
$tHead = trim(strip_tags($value));
}
}
}

// ------------- process parameters --------------

// derive display type
if (isset($tType))
{
$lType = $tType;
}
elseif (isset($tCompact)) # DEPRECATED
{
if (0 == $tCompact)
{
$lType = 'cols';
}
elseif (1 == $tCompact)
{
$lType = 'list';
}
}
//else default 'cols'

// --- presentation parameters

// columns
if (isset($tCols)) # overrides 'col' parameter
{
$lCols = $tCols;
}
elseif (isset($tCol))
{
$lCols = $tCol;
}
// class
if (isset($tClass) && '' != $tClass) $lClass = $tClass;
// main heading override
if (isset($tHead) && '' != $tHead)
{
$lHead = $tHead;
}
else
{
switch ($lType)
{
case 'cols':
$lHead = BL_HD_COL;
break;
case 'list':
$lHead = BL_HD_LST;
break;
}
}

// ---------------- gather data ------------------

// get the pages linking to this one
$results = $this->LoadPagesLinkingTo($this->getPageTag()); # result is sorted by page name

$links = array();
if ($results)
{
foreach ($results as $page)
{
$links[] = $this->Link($page['tag']);
}
}

// ------------------ output ---------------------

// show resulting list of pages linking to this one
$str ='';
switch ($lType)
{
case 'cols':
$attrClass = ('' != $lClass) ? ' class="backlinkcols '.$lClass.'"' : ' class="backlinkcols"';
$head = $lHead;
// start wrapper
$str .= '<div'.$attrClass.'>'."\n";
$str .= ' <h5 id="'.$this->makeId('hn','backlinks').'">'.$head.'</h5>'."\n";
// data columns
$hd = sprintf(BL_COL_PAGES_FOUND,count($links));
$str .= $this->makeMemberCols($links,$lCols,$hd,'backlinks',BL_COL_NONE_FOUND);
// end wrapper
$str .= "</div>\n";
break;
case 'list':
$attrClass = ('' != $lClass) ? ' class="backlinklist '.$lClass.'"' : ' class="backlinklist"';
$head = $lHead;
// start wrapper
$str .= '<div'.$attrClass.'>'."\n";
$str .= ' <h5 id="'.$this->makeId('hn','backlinks').'">'.$head.'</h5>'."\n";
// data list
$hd = BL_LST_PAGES_FOUND;
$str .= $this->makeMemberList($links,$hd,'backlinks','pagelist',BL_LST_NONE_FOUND,'menu');
// end wrapper
$str .= "</div>\n";
break;
}

echo $str;
?>
%%


====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
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki