=====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: ">
FormClose(); } }else{ //print "\n\n"; } ?> %% === To Do === - Test: how is this script behaving with an German, Chinese,... char set? - Layout: How to structure the links? - Code: is there an easy way to add 2 or 3 levels in the titles (like when you save your bookmark as an html file). - CSS: convert the 'table'-form into pure css layout. - HTML: What is the max length of an "option" in a "select"? - Add a switch: "Last added", FIFO with the last ?10? added links... - Add more checks: is the link or refer in the blacklist?,... === Beta === - I'm experimenting with javascript code to auto add the url and tilte into the form via $_GET variables. So adding a link would only take two mouse-clicks... - javascript:void(window.location.href='http://server.com/TestAddLink?url='+escape(window.location.href)+'&title='+escape(document.title)) - I don't think it's possible to make this link browser independent, so we'll end up with a few links like this... ---- CategoryUserContributions