=====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) $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 .= ''."\n"; $str .= '
'.$head.'
'."\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 .= "\n"; break; case 'list': $attrClass = ('' != $lClass) ? ' class="backlinklist '.$lClass.'"' : ' class="backlinklist"'; $head = $lHead; // start wrapper $str .= ''."\n"; $str .= '
'.$head.'
'."\n"; // data list $hd = BL_LST_PAGES_FOUND; $str .= $this->makeMemberList($links,$hd,'backlinks','pagelist',BL_LST_NONE_FOUND,'menu'); // end wrapper $str .= "\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