$plugin['name'] = 'spc_section_alias';
$plugin['author'] = 'Stanton Champion';
$plugin['author_uri'] = 'http://www.stantonchampion.com';
$plugin['version'] = '0.5';
$plugin['description'] = 'Section renaming and management plugin.';
$plugin['help'] = '
- spc_section_alias – Defines the information associated with a section.
- section – The section to which you are associating new information. If you do not specify a section, this will modify the data associated with the current section.
- group – This value will allow you to group certain sections together for better handling with the iterate function (see below). If no group is specified, then the group value is set to “default”. This may be a comma delimited list. If no matching section is found in the comma delimited list of groups, then a new entry will be created in the first group listed.
- name – A human readable name for your section.
- title – A title value for links.
- id – An id value for links.
- accesskey – An accesskey value for links.
- description – A description of your section.
- description2 – A second description for your section.
- breakid – A value that will appear as id= in the break tag when calling spc_section_alias_iterate with break=’li’. At the moment, it does not support any other break type.
- inactive – Setting this value to “1” will will make the iterate function ignore this entry. This does not affect any other function.
- namethis, titlethis, idthis, accesskeythis, descriptionthis, description2this, breakidthis – Use these to redefine existing values. They take any occurrence of ”.this.” in the supplied input, and replace it with the already stored value. If there are no existing values to redefine, the ‘this’ functions will store new values.
- spc_section_alias_copy – Copies the section contents from one group to another.
- section – A section to copy. If none is specified, the current section is used.
- srcgroup – A comma delimited list of groups to search for section information. This function takes the information from the first group found.
- destgroup – A comma delimited list of groups. If the function finds a matching section in this group list, it will copy the section information to this group. If it does not find a matching section, it will create a new group using the first entry from the comma delimited list.
- spc_section_alias_section – Given a section, this returns the section. This is useful when combined with other plugins that demand a section variable.
- section – Return information from this particular section. If no section is specified, the current section is used.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_article_section – (Article form tag) Same as above, but this is meant to be used within an article form.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_name – Return the human readable name for a section.
- section – Return information from this particular section. If no section is specified, the current section is used.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_article_name – (Article form tag) Same as above, but this is meant to be used within an article form.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_title – Return the link title for a section.
- section – Return information from this particular section. If no section is specified, the current section is used.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_article_title – (Article form tag) Same as above, but this is meant to be used within an article form.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_id – Return the link id for a section.
- section – Return information from this particular section. If no section is specified, the current section is used.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_article_id – (Article form tag) Same as above, but this is meant to be used within an article form.
- group – The section group.This value will accept a comma delimited list. If no group is specified, the group value is set to “default”.
- spc_section_alias_description – Return the description for a section.
- section – Return information from this particular section. If no section is specified, the current section is used.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_article_description – (Article form tag) Same as above, but this is meant to be used within an article form.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_description2 – Return the second description for a section.
- section – Return information from this particular section. If no section is specified, the current section is used.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_article_description2 – (Article form tag) Same as above, but this is meant to be used within an article form.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_link – Return a working link for a particular section that includes title, id, and human readable name.
- section – Return information from this particular section. If no section is specified, the current section is used.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_article_link – (Article form tag) Same as above, but this is meant to be used within an article form.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- spc_section_alias_iterate – This tag takes a form and a group, and then iterates over all of the sections listed within that group using the form as input. The form tags are the same tags as listed above. This is useful as a means of outputting a list of sections, section links, etc.
- form – The form over which to iterate.
- group – The section group. If no group is specified, the group value is set to “default”. This value will accept a comma delimited list.
- wraptag – A wraptag to put around the output.
- break – A break tag to put around the elements.
';
$plugin['code'] = '
// spc_section_alias - Alias and manage section names
// by: Stanton Champion
// stantonchampion@yahoo.com
// http://www.stantonchampion.com
// The actual hash value
$spc_section_alias_hash = array();
function spc_section_alias($atts)
{
global $spc_section_alias_hash, $s;
if (is_array($atts))
{
extract($atts);
}
// New trick...
// If we don't have a section, redefine the values for
// the current section.
if(!$section || ($section == ""))
{
$section = $s;
}
if(!$group || ($group == ""))
{
$group = "default";
}
/* Search for a group */
$group_array = preg_split("/\s*,\s*/", $group);
/* See if we can find a matching destination group. */
foreach($group_array as $g)
{
if($spc_section_alias_hash[$g][$section]["section"])
{
/* The user wants to change this. */
$final_dest = $g;
break;
}
}
if( !$final_dest || ($final_dest == "") )
{
/* The detination group doesn't exist, so create a new one. */
$final_dest = $group_array[0];
}
$group = $final_dest;
if($name)
{
$spc_section_alias_hash[$group][$section]["name"] = $name;
}
if($namethis)
{
if($spc_section_alias_hash[$group][$section]["name"])
{
$spc_section_alias_hash[$group][$section]["name"] = str_replace(".this.", $spc_section_alias_hash[$group][$section]["name"], $namethis);
}
else
{
$spc_section_alias_hash[$group][$section]["name"] = $namethis;
}
}
if($title)
{
$spc_section_alias_hash[$group][$section]["title"] = $title;
}
if($titlethis)
{
if($spc_section_alias_hash[$group][$section]["title"])
{
$spc_section_alias_hash[$group][$section]["title"] = str_replace(".this.", $spc_section_alias_hash[$group][$section]["title"], $titlethis);
}
else
{
$spc_section_alias_hash[$group][$section]["title"] = $titlethis;
}
}
if($id)
{
$spc_section_alias_hash[$group][$section]["id"] = $id;
}
if($idthis)
{
if($spc_section_alias_hash[$group][$section]["id"])
{
$spc_section_alias_hash[$group][$section]["id"] = str_replace(".this.", $spc_section_alias_hash[$group][$section]["id"], $idthis);
}
else
{
$spc_section_alias_hash[$group][$section]["id"] = $idthis;
}
}
if($accesskey)
{
$spc_section_alias_hash[$group][$section]["accesskey"] = $accesskey;
}
if($accesskeythis)
{
if($spc_section_alias_hash[$group][$section]["accesskey"])
{
$spc_section_alias_hash[$group][$section]["accesskey"] = str_replace(".this.", $spc_section_alias_hash[$group][$section]["accesskey"], $accesskeythis);
}
else
{
$spc_section_alias_hash[$group][$section]["accesskey"] = $accesskeythis;
}
}
if($description)
{
$spc_section_alias_hash[$group][$section]["description"] = $description;
}
if($descriptionthis)
{
if($spc_section_alias_hash[$group][$section]["description"])
{
$spc_section_alias_hash[$group][$section]["description"] = str_replace(".this.", $spc_section_alias_hash[$group][$section]["description"], $descriptionthis);
}
else
{
$spc_section_alias_hash[$group][$section]["description"] = $descriptionthis;
}
}
if($description2)
{
$spc_section_alias_hash[$group][$section]["description2"] = $description2;
}
if($description2this)
{
if($spc_section_alias_hash[$group][$section]["description2"])
{
$spc_section_alias_hash[$group][$section]["description2"] = str_replace(".this.", $spc_section_alias_hash[$group][$section]["description2"], $description2this);
}
else
{
$spc_section_alias_hash[$group][$section]["description2"] = $description2this;
}
}
if($breakid)
{
$spc_section_alias_hash[$group][$section]["breakid"] = $breakid;
}
if($breakidthis)
{
if($spc_section_alias_hash[$group][$section]["breakid"])
{
$spc_section_alias_hash[$group][$section]["breakid"] = str_replace(".this.", $spc_section_alias_hash[$group][$section]["breakid"], $breakidthis);
}
else
{
$spc_section_alias_hash[$group][$section]["breakid"] = $breakidthis;
}
}
if($inactive)
{
$spc_section_alias_hash[$group][$section]["inactive"] = $inactive;
}
else
{
$spc_section_alias_hash[$group][$section]["inactive"] = "0";
}
$spc_section_alias_hash[$group][$section]["section"] = $section;
return;
}
/* Copies the values from one section group to another */
function spc_section_alias_copy($atts)
{
global $spc_section_alias_hash, $s;
if (is_array($atts))
{
extract($atts);
}
if(!$section || ($section == ""))
{
$section=$s;
}
if(!$srcgroup || ($srcgroup == ""))
{
return;
}
if(!$destgroup || ($destgroup == ""))
{
return;
}
$src_array = preg_split("/\s*,\s*/", $srcgroup);
$dest_array = preg_split("/\s*,\s*/", $destgroup);
/* Search the source group we want */
$final_src = "";
foreach($src_array as $src)
{
/* If we find a matching section */
if($spc_section_alias_hash[$src][$section]["section"])
{
$final_src = $src;
break;
}
}
if( !$final_src || ($final_src == "") )
{
/* The source array doesn't exist. */
return;
}
/* See if we can find a matching destination group. */
foreach($dest_array as $dest)
{
if($spc_section_alias_hash[$dest][$section]["section"])
{
/* The user wants this to go here. */
$final_dest = $dest;
break;
}
}
if( !$final_dest || ($final_dest == "") )
{
/* The detination group doesn't exist, so create a new one. */
$final_dest = $dest_array[0];
}
/* Do the copy */
while($field = key($spc_section_alias_hash[$final_src][$section]))
{
$spc_section_alias_hash[$final_dest][$section][$field] = $spc_section_alias_hash[$final_src][$section][$field];
next ($spc_section_alias_hash[$final_src][$section]);
}
}
/* Prints the section */
function spc_section_alias_section($atts)
{
global $spc_section_alias_hash, $s;
if (is_array($atts))
{
extract($atts);
}
if(!$section || ($section == ""))
{
$section=$s;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["section"])
{
return $spc_section_alias_hash[$g][$section]["section"];
}
}
return;
}
/* Article form: prints section */
function spc_section_alias_article_section($atts)
{
global $spc_section_alias_hash, $thisarticle;
if (is_array($atts))
{
extract($atts);
}
$section=$thisarticle['section'];
if(!$section || ($section == ""))
{
return;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["section"])
{
return $spc_section_alias_hash[$g][$section]["section"];
}
}
return;
}
/* Prints the human readable name */
function spc_section_alias_name($atts)
{
global $spc_section_alias_hash, $s;
if (is_array($atts))
{
extract($atts);
}
if(!$section || ($section == ""))
{
$section=$s;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["name"])
{
return $spc_section_alias_hash[$g][$section]["name"];
}
}
return;
}
/* Article form: prints human readable name */
function spc_section_alias_article_name($atts)
{
global $spc_section_alias_hash, $thisarticle;
if (is_array($atts))
{
extract($atts);
}
$section=$thisarticle['section'];
if(!$section || ($section == ""))
{
return;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["name"])
{
return $spc_section_alias_hash[$g][$section]["name"];
}
}
return;
}
/* Prints link title */
function spc_section_alias_title($atts)
{
global $spc_section_alias_hash, $s;
if (is_array($atts))
{
extract($atts);
}
if(!$section || ($section == ""))
{
$section=$s;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["title"])
{
return $spc_section_alias_hash[$g][$section]["title"];
}
}
return;
}
/* Article form: prints link title */
function spc_section_alias_article_title($atts)
{
global $spc_section_alias_hash, $thisarticle;
if (is_array($atts))
{
extract($atts);
}
$section=$thisarticle['section'];
if(!$section || ($section == ""))
{
return;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["title"])
{
return $spc_section_alias_hash[$g][$section]["title"];
}
}
return;
}
/* Prints link id */
function spc_section_alias_id($atts)
{
global $spc_section_alias_hash, $s;
if (is_array($atts))
{
extract($atts);
}
if(!$section || ($section == ""))
{
$section=$s;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["id"])
{
return $spc_section_alias_hash[$g][$section]["id"];
}
}
return;
}
/* Article form: prints link id */
function spc_section_alias_article_id($atts)
{
global $spc_section_alias_hash, $thisarticle;
if (is_array($atts))
{
extract($atts);
}
$section=$thisarticle['section'];
if(!$section || ($section == ""))
{
return;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["id"])
{
return $spc_section_alias_hash[$g][$section]["id"];
}
}
return;
}
/* Prints first description */
function spc_section_alias_description($atts)
{
global $spc_section_alias_hash, $s;
if (is_array($atts))
{
extract($atts);
}
if(!$section || ($section == ""))
{
$section=$s;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["description"])
{
return $spc_section_alias_hash[$g][$section]["description"];
}
}
return;
}
/* Article form: prints first description */
function spc_section_alias_article_description($atts)
{
global $spc_section_alias_hash, $thisarticle;
if (is_array($atts))
{
extract($atts);
}
$section=$thisarticle['section'];
if(!$section || ($section == ""))
{
return;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["description"])
{
return $spc_section_alias_hash[$g][$section]["description"];
}
}
return;
}
/* Prints second description */
function spc_section_alias_description2($atts)
{
global $spc_section_alias_hash, $s;
if (is_array($atts))
{
extract($atts);
}
if(!$section || ($section == ""))
{
$section=$s;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["description2"])
{
return $spc_section_alias_hash[$g][$section]["description2"];
}
}
return;
}
/* Article form: prints second description */
function spc_section_alias_article_description2($atts)
{
global $spc_section_alias_hash, $thisarticle;
if (is_array($atts))
{
extract($atts);
}
$section=$thisarticle['section'];
if(!$section || ($section == ""))
{
return;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["description2"])
{
return $spc_section_alias_hash[$g][$section]["description2"];
}
}
return;
}
/* Prints complete link for section */
function spc_section_alias_link($atts)
{
global $spc_section_alias_hash, $s, $url_mode, $pfr;
if (is_array($atts))
{
extract($atts);
}
if(!$section || ($section == ""))
{
$section=$s;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["section"])
{
$out = "";
$name = $spc_section_alias_hash[$g][$section]["name"];
if(!$name)
{
$name = "";
}
$title = $spc_section_alias_hash[$g][$section]["title"];
if(!$title)
{
$title = "";
}
$id = $spc_section_alias_hash[$g][$section]["id"];
if(!$id)
{
$id = "";
}
$accesskey = $spc_section_alias_hash[$g][$section]["accesskey"];
if(!$accesskey)
{
$accesskey = "";
}
$section_name = $spc_section_alias_hash[$g][$section]["section"];
if(!$section_name)
{
$section_name = "";
}
$out = spc_section_alias_linkencode($section_name, $id, $accesskey, $title, $name, $url_mode, $pfr);
return $out;
}
}
return;
}
/* Article form: prints complete link for section */
function spc_section_alias_article_link($atts)
{
global $spc_section_alias_hash, $thisarticle, $url_mode, $pfr;
if (is_array($atts))
{
extract($atts);
}
$section=$thisarticle['section'];
if(!$section || ($section == ""))
{
return;
}
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
foreach($g_array as $g)
{
if($spc_section_alias_hash[$g][$section]["section"])
{
$out = "";
$name = $spc_section_alias_hash[$g][$section]["name"];
if(!$name)
{
$name = "";
}
$id = $spc_section_alias_hash[$g][$section]["id"];
if(!$id)
{
$id = "";
}
$accesskey = $spc_section_alias_hash[$g][$section]["accesskey"];
if(!$accesskey)
{
$accesskey = "";
}
$title = $spc_section_alias_hash[$g][$section]["title"];
if(!$title)
{
$title = "";
}
$section_name = $spc_section_alias_hash[$g][$section]["section"];
if(!$section_name)
{
$section_name = "";
}
$out = spc_section_alias_linkencode($section_name, $id, $accesskey, $title, $name, $url_mode, $pfr);
return $out;
}
}
return;
}
/* Iterates across known sections */
function spc_section_alias_iterate($atts)
{
global $spc_section_alias_hash, $url_mode, $pfr;
if (is_array($atts))
{
extract($atts);
}
$form_text = fetch('Form','txp_form','name',$form);
if(!$group || ($group == ""))
{
$group = "default";
}
$g_array = preg_split("/\s*,\s*/", $group);
$break = (empty($break)) ? '' : $break;
$wraptag = (empty($wraptag)) ? '' : $wraptag;
foreach($g_array as $g)
{
// Begin iterating
if($spc_section_alias_hash[$g])
{
foreach ($spc_section_alias_hash[$g] as $section)
{
$name = $section["name"];
if(!$name)
{
$name = "";
}
$title = $section["title"];
if(!$title)
{
$title = "";
}
$id = $section["id"];
if(!$id)
{
$id = "";
}
$accesskey = $section["accesskey"];
if(!$accesskey)
{
$accesskey = "";
}
$description = $section["description"];
if(!$description)
{
$description = "";
}
$description2 = $section["description2"];
if(!$description2)
{
$description2 = "";
}
$section_name = $section["section"];
if(!$section_name)
{
$section_name = "";
}
$breakid = $section["breakid"];
if(!$breakid)
{
$breakid = "";
}
$inactive = $section["inactive"];
$link = spc_section_alias_linkencode($section_name, $id, $accesskey, $title, $name, $url_mode, $pfr);
$out_text = str_replace("", $name, $form_text);
$out_text = str_replace("", $title, $out_text);
$out_text = str_replace("", $description, $out_text);
$out_text = str_replace("", $description2, $out_text);
$out_text = str_replace("", $link, $out_text);
$out_text = str_replace("", $section_name, $out_text);
$out_text = parse($out_text);
if($break == 'li')
{
if( $breakid != "" )
{
$out_text = tag($out_text, $break, " id='$breakid'")."\n";
}
else
{
$out_text = tag($out_text, $break)."\n";
}
}
else
{
$out_text = $out_text.$break."\n";
}
if($inactive != "1")
{
$out .= $out_text;
}
}
}
}
if($wraptag)
{
$out = tag($out, $wraptag);
}
return $out;
}
/* Function to simplify encoding links */
function spc_section_alias_linkencode($section_name, $id, $accesskey, $title, $name, $url_mode, $pfr)
{
$link = "";
if($section_name == "default" || $section_name == "/")
{
$url = $pfr;
}
else
{
if($url_mode)
{
$url = $pfr.urlencode($section_name)."/";
}
else
{
$url = $pfr."?s=".urlencode($section_name);
}
}
$link_title = "";
if($title)
{
$link_title = "title=\"".htmlspecialchars($title)."\" ";
}
$link_id = "";
if($id)
{
$link_id = "id=\"".htmlspecialchars($id)."\" ";
}
$link_accesskey = "";
if($accesskey)
{
$link_accesskey = "accesskey=\"".htmlspecialchars($accesskey)."\" ";
}
$link_name = "";
if($name)
{
$link_name = $name;
}
$link = "".$link_name."";
return $link;
}
';
$plugin['md5'] = 'f1c6b7603e0a7672ec65a50df13de273';