• Resolved xforce

    (@xforce)


    One of the problem I face when using this plugin is that if the links ends with a ‘/’ at the end then wordpress redirects to 404. So I was checking the code shorten-url.php -> redirect_404() [line number 845].

    I have added a fix for the backslash, let me know if its correct.
    What I am doing is checking if the last element is blank then remove it from the array ‘param’.

    function redirect_404() {
    		global $post;
    		global $wpdb;
    		$table_name = $this->table_name;
    
    		if(is_404()) {
    			$param = explode("/", $_SERVER['REQUEST_URI']) ; 
    
    			// Fixed by Ahmed, if there is a slash at the end.
    			if( count( $param ) > 2 ) {
    				$last_elem = array_pop( $param );
    				if( $last_elem != '' )
    					$param[] = $last_elem;
    			}
    			// End fix
    			if (preg_match("/^([a-zA-Z0-9_.-])*$/",$param[count($param)-1],$matches)==1) {
    				$select = "SELECT id_post FROM {$table_name} WHERE short_url='".$param[count($param)-1]."'" ;
    				$temp_id = $wpdb->get_var( $select ) ;
    				if (($temp_id==null)||($temp_id===false)) {
    					return ;
    				} else if (is_numeric($temp_id)) {
    					if ($temp_id==0) {
    						$select = "SELECT url_externe FROM {$table_name} WHERE short_url='".$param[count($param)-1]."'" ;
    						$temp_url = $wpdb->get_var( $select ) ;
    						$wpdb->query("UPDATE {$table_name} SET nb_hits = IFNULL(nb_hits, 0) + 1 WHERE short_url='".$param[count($param)-1]."'") ;
    						header("HTTP/1.1 301 Moved Permanently");
    						$temp_url = str_replace("&", "&", $temp_url);
    						header("Location: ".$temp_url );
    						exit();
    					} else {
    						$wpdb->query("UPDATE {$table_name} SET nb_hits = IFNULL(nb_hits, 0) + 1 WHERE id_post=".$temp_id) ;
    						header("HTTP/1.1 301 Moved Permanently");
    						//$temp_url = str_replace("&", "&", $temp_url); -- Why is this line added ? -Ahmed
    						header("Location: ".get_permalink($temp_id));
    						exit();
    					}
    				}
    			}
    		}
    	}

    What I am not trying to understand is this piece of code,
    preg_match("/^([a-zA-Z0-9_.-])*$/",$param[count($param)-1],$matches)

    When a blank is passed as the second argument, then it return 1, I think it should return FALSE.

    Thanks

    https://wordpress.org/plugins/shorten-url/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Few things I noticed in the code’ is closed to new replies.