Changeset 16455

Show
Ignore:
Timestamp:
05/23/08 14:36:35 (5 months ago)
Author:
bergie
Message:

New safety in tag picker to disable users from adding their own tags

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.helper.datamanager2/widget/tagpicker.php

    r14893 r16455  
    5353 
    5454    /** 
    55      * whether the input should be shown in the widget, or not. 
     55     * Whether the input should be shown in the widget, or not. 
    5656     * 
    5757     * @var boolean 
     
    5959     */ 
    6060    var $hideinput = false; 
     61     
     62    /** 
     63     * Whether to allow users to add tags that are not yet in database 
     64     * 
     65     * @var boolean 
     66     * @access public 
     67     */ 
     68    var $allow_other = false; 
    6169     
    6270    var $_taglist_html = ''; 
     
    125133    function sync_type_with_widget($results) 
    126134    { 
    127         $this->_type->value = $results[$this->name]; 
     135        if (   $this->allow_other 
     136            || empty($results[$this->name])) 
     137        { 
     138            // The simple way, just take what is given 
     139            $this->_type->value = $results[$this->name]; 
     140            return; 
     141        } 
     142         
     143        // Otherwise, validate the results 
     144        $tags_in_db = net_nemein_tag_handler::get_tags(); 
     145         
     146        $tags_from_user = explode(' ', $results[$this->name]); 
     147         
     148        $tags_to_save = array(); 
     149         
     150        foreach ($tags_from_user as $tag) 
     151        { 
     152            if (!isset($tags_in_db[$tag]) 
     153            { 
     154                // We don't have this tag, skip. 
     155                continue; 
     156            } 
     157             
     158            $tags_to_save[] = $tag; 
     159        } 
     160         
     161        $this->_type->value = implode(' ', $tags_to_save); 
    128162    } 
    129163     
     
    132166        $html = ''; 
    133167        $tags = net_nemein_tag_handler::get_tags(); 
    134         $object_tags = explode(" ", $this->_type->value); 
     168        $object_tags = explode(' ', $this->_type->value); 
    135169         
    136170        if (! empty($tags))