See also:
works with:
  • Wikka 1.1.6.0 (v0.1)
NOT Included in any Wikka version
Last edited by OnegWR:
Modified links pointing to docs server
Mon, 28 Jan 2008 00:11 UTC [diff]

This is the development page for the addlink action.

Installation


Code Walktrough

add link to array, rebuild the layout, save the page and refresh the current page.
print the html form.
do nothing / print error.

Code

<?php
/**
 * This action will allow you to fast add links in a structured way.
 *
 * @package        Actions
 * @subpackage    Links
 * @name            AddLink
 *
 * @author        {@link http://wikka.jsnx.com/OnegWR OnegWR} (v0.1)
 * @version       0.1
 * @copyright    Copyright © 2005
 * @license        {@link http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License}
 * @since          Wikka 1.1.6.0
 *
 * @input         NONE ( $_POST["category"], $_POST["url"], $_POST["title"] = string )
 * @output       html form
 *
 * @todo         {@link http://wikka.jsnx.com/AddLinkAction AddLinkAction} (list)
 */

$al_key_default = $al_key = "First";    // Default key
$al_category["First"] = "First";        // LookUpTable for 'safe'-key-names
$al_data = array();                     // to store the links in
$al_select = "";                        // $al_category in html-select format
$al_output = $al_last = "";             // rebuild the page for $this->SavePage()
if( $this->HasAccess("write") && $this->HasAccess("read") ){       // Admin only???
        $al_page = $this->LoadPage($this->tag);
        list($al_header,$al_links,$al_footer) = explode("----", $al_page["body"],3);
        preg_match_all("/(==.*?==)|(\[\[.*?\]\])/", $al_links, $matches);
        //print "\n<pre>\n"; print_r($matches); print "\n<pre>\n".count($matches[0])."\n";
        foreach( $matches[0] as $al_n => $al_item ){
                if( preg_match("/==(.*?)==/", $al_item, $match) ){
                        $al_key_tmp = preg_replace("/[^A-Za-z0-9]/","",$match[1]);
                        if($al_key_tmp <> ""){          // This would also ignore 'strange' titles
                                $al_key=$al_key_tmp;
                                $al_category[$al_key]=$match[1];
                        }
                }else{
                        $al_data[$al_key][]=$al_item;
                }
        }
        //print "\n<pre>\n"; print_r($al_data); print_r($al_category); print "\n<pre>\n";

        if( isset($_POST["url"]) && $_POST["url"]<>"" ){        // add the link + save the page
                if( $this->htmlspecialchars_ent($_POST["title"]) == "" ) {
                        $al_newlink = "[[".$this->cleanUrl($_POST["url"])."]]";
                }else{
                        $al_newlink = "[[".$this->cleanUrl($_POST["url"])." ".$this->htmlspecialchars_ent($_POST["title"])."]]";
                }
                if( $this->htmlspecialchars_ent($_POST["category"]) == "" ){
                        $al_key = $al_key_default;
                }else{
                        $al_key = $this->htmlspecialchars_ent($_POST["category"]);
                }
                $al_data[$al_key][] = $al_newlink;              // Goal of this script: Add the link to the array

                if(isset($al_data["First"])){                        // Here the layout is re-build
                        $al_output .= "==First==\n~".implode(" ",$al_data["First"])."\n";
                        unset($al_data["First"]);
                }
                if(isset($al_data["Last"])) {
                        $al_last .= "==Last==\n~".implode(" ",$al_data["Last"])."\n";
                        unset($al_data["Last"]);
                }
                foreach($al_data as $al_k => $al_v){
                        $al_output .= "==".$al_category[$al_k]."==\n~".implode(" ",$al_data[$al_k])."\n";
                }
                $al_output .= $al_last;
                $this->SavePage($this->tag, $al_header."----\n".$al_output."----".$al_footer, "Link added in category $al_key");
                $this->Redirect($this->Href());
                //print "ok";
                //print "\n<pre>\n"; print_r($al_data); print "\n<pre>\n";
        }else{                                                  // print the form
                print $this->FormOpen('',$this->tag);
                foreach($al_category as $al_cat_safe => $al_cat_full){
                        $al_select.="<option value=\"".$al_cat_safe."\">".$al_cat_full."</option>";
                }
                ?>
                <table border="0" cellpadding="3" cellspacing="0">
                <tr>
                        <td rowspan="2" valign="top"><select name="category" size="3"><?php print $al_select; ?></select></td>
                        <td>Url:&nbsp;</td>
                        <td valign="top"><input type="text" size="50" maxlength="255" name="url" value="<?php print $_GET["url"]; ?>"></td>
                        <td rowspan="2" valign="bottom"><input type=submit name=submit value="Add"></td>
                </tr>
                <tr>
                        <td>Title:</td>
                        <td valign="bottom"><input type="text" size="50" maxlength="255" name="title" value="<?php print $_GET["title"]; ?>"></td>
                </tr>
                </table>
                <?php
                print $this->FormClose();
        }
}else{
        //print "\n<!-- ERROR: You don't have the needed rights for accessing the action addlink -->\n";
}
?>

To Do


Beta



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