=====Addlink Action===== >>==See also:== - Documentation: AddLinkActionInfo. ==works with:== - Wikka 1.1.6.0 (v0.1) >>//NOT Included in any Wikka version//{{lastedit show="3"}} This is the development page for the addlink action. ===Installation=== - Save the code below as ##action/addpage.php## - Give it the same file permissions as the other php files in that directory. ===Code Walktrough=== - If you have write and read access: - Read the current links and build arrays $al_data and $al_category. - if $_POST["url"] is set: add link to array, rebuild the layout, save the page and refresh the current page. - if $_POST["url"] is NOT set: print the html form. - If you have DON'T write and read access: do nothing / print error. === Code === %%(php)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
\n"; print_r($matches); print "\n\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\n"; print_r($al_data); print_r($al_category); print "\n\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\n"; print_r($al_data); print "\n\n"; }else{ // print the form print $this->FormOpen('',$this->tag); foreach($al_category as $al_cat_safe => $al_cat_full){ $al_select.=""; } ?>
Url: | "> | ||
Title: | "> |