Changeset 11684

Show
Ignore:
Timestamp:
08/22/07 18:25:42 (1 year ago)
Author:
adrenalin
Message:

Moved creating and editing folders to use midcom.helper.datamanager2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/branch-2_6/src/midcom.admin.folder/config/config.inc

    r5150 r11684  
    11'schemadb' => 'file:/midcom/config/metadata_dm2_default.inc', 
     2'schemadbs_folder' => array 
     3( 
     4    'default' => 'file:/midcom/admin/folder/config/schemadb_folder.inc', 
     5), 
     6 
  • branches/branch-2_6/src/midcom.admin.folder/config/manifest.inc

    r5772 r11684  
    11'name' => 'midcom.admin.folder', 
    22'purecode' => true, 
    3 'version' => '1.1.4', 
    4 'state' => 'stable', 
    5 'privileges' => Array 
     3'version' => '1.1.5', 
     4'state' => 'beta', 
     5'privileges' => array 
    66( 
    77    'topic_management' => MIDCOM_PRIVILEGE_DENY, 
     8    'template_management' => MIDCOM_PRIVILEGE_DENY, 
    89), 
    9 'package.xml' => Array 
     10'package.xml' => array 
    1011( 
    1112    'summary' => 'Folder management', 
    1213    'description' => 'Management of MidCOM site folders', 
    13     'maintainers' => Array 
     14    'maintainers' => array  
    1415    ( 
    15         'bergie' => Array 
     16        'bergie' => array 
    1617        ( 
    1718            'name' => 'Henri Bergius', 
     
    1920            'role' => 'lead', 
    2021        ), 
    21         'adrenalin' => Array 
     22        'adrenalin' => array 
    2223        ( 
    2324            'name' => 'Arttu Manninen', 
     
    2526            'role' => 'lead', 
    2627        ), 
    27         'torben' => Array 
     28        'torben' => array 
    2829        ( 
    2930            'name' => 'Torben Nehmer', 
     
    3334        ), 
    3435    ), 
    35     'dependencies' => Array 
     36    'dependencies' => array 
    3637    ( 
    37         'midcom.helper.datamanager2' => Array(), 
     38        'midcom.helper.datamanager2' => array (), 
     39        'midcom' => array (), 
    3840    ), 
    3941), 
  • branches/branch-2_6/src/midcom.admin.folder/documentation/CHANGES

    r5768 r11684  
    66  which might even break existing functionality. 
    77- All items marked with "+" represent completly new features. 
     8 
     92007-06-07 adrenalin 
     10  - Masked PHP notices on component listings for possible missing 'state' keys in manifests 
     11 
     122007-06-03 
     13  - Added component state display 
    814 
    9152007-04-20 adrenalin 
  • branches/branch-2_6/src/midcom.admin.folder/folder_management.php

    r5150 r11684  
    7979         
    8080        $this->_request_data['folder'] = $this->_topic; 
    81          
    82 //        if (!array_key_exists($this->_topic->get_parameter('midcom', 'component'), $_MIDCOM->componentloader->manifests)) 
    83 //        { 
    84 //            $this->_topic->set_parameter('midcom', 'component', 'midcom.core.nullcomponent'); 
    85 //        } 
    8681    } 
    8782     
     
    108103            'create' => array 
    109104            ( 
    110                 'handler' => array('midcom_admin_folder_handler_create', 'create'), 
    111                 'fixed_args' => 'create'
     105                'handler' => array('midcom_admin_folder_handler_edit', 'edit'), 
     106                'fixed_args' => array ('create')
    112107            ), 
    113108             
     
    120115            ( 
    121116                'handler' => array('midcom_admin_folder_handler_edit', 'edit'), 
    122                 'fixed_args' => 'edit'
     117                'fixed_args' => array ('edit')
    123118            ), 
    124119             
     
    131126            ( 
    132127                'handler' => array('midcom_admin_folder_handler_delete', 'delete'), 
    133                 'fixed_args' => 'delete'
     128                'fixed_args' => array ('delete')
    134129            ), 
    135130             
     
    146141            ( 
    147142                'handler' => array('midcom_admin_folder_handler_approvals', 'approval'), 
    148                 'fixed_args' => 'approve'
     143                'fixed_args' => array ('approve')
    149144            ), 
    150145             
     
    157152            ( 
    158153                'handler' => array('midcom_admin_folder_handler_approvals', 'approval'), 
    159                 'fixed_args' => 'unapprove'
     154                'fixed_args' => array ('unapprove')
    160155            ), 
    161156             
     
    171166            ( 
    172167                'handler' => array('midcom_admin_folder_handler_metadata', 'metadata'), 
    173                 'fixed_args' => 'metadata', 
     168                'fixed_args' => array ('metadata'), 
     169                'variable_args' => 1, 
     170            ), 
     171 
     172            /** 
     173             * Object moving 
     174             *  
     175             * Match /move/<object guid>/ 
     176             */ 
     177            'move' => array 
     178            ( 
     179                'handler' => array('midcom_admin_folder_handler_move', 'move'), 
     180                'fixed_args' => array ('move'), 
    174181                'variable_args' => 1, 
    175182            ), 
     
    179186            ( 
    180187                'handler' => array('midcom_admin_folder_handler_order', 'order'), 
    181                 'fixed_args' => 'order'
     188                'fixed_args' => array ('order')
    182189            ), 
    183190        ); 
     
    205212             
    206213            // Skip components beginning with midcom or midgard 
    207             if (ereg('^(midcom|midgard)\.', $manifest->name)) 
     214            if (   ereg('^(midcom|midgard)\.', $manifest->name) 
     215                && $manifest->name != 'midcom.helper.search') 
    208216            { 
    209217                continue; 
     
    225233                $description = ''; 
    226234            } 
    227              
     235 
    228236            $components[$manifest->name] = array 
    229237            ( 
    230                 'name' => $manifest->get_name_translated(), 
     238                'name'        => $manifest->get_name_translated(), 
    231239                'description' => $description, 
     240                'state'       => @$manifest->state, 
     241                'version'     => $manifest->version, 
    232242            ); 
    233243        } 
     
    251261     
    252262    /** 
     263     * Static method for populating user interface for editing and creating topics 
     264     *  
     265     * @access static public 
     266     * @return Array Containing a list of components 
     267     */ 
     268    function list_components($parent_component = '', $all = false) 
     269    { 
     270        $list = array(); 
     271         
     272        foreach (midcom_admin_folder_folder_management::get_component_list() as $component => $details) 
     273        { 
     274            // TODO: configuration options for either excluding or including components to the list 
     275            if (   isset($GLOBALS['midcom_config']['component_listing_allowed']) 
     276                && is_array($GLOBALS['midcom_config']['component_listing_allowed']) 
     277                && !in_array($component, $GLOBALS['midcom_config']['component_listing_allowed']) 
     278                && $component !== $parent_component 
     279                && !$all) 
     280            { 
     281                continue; 
     282            } 
     283             
     284            if (   isset($GLOBALS['midcom_config']['component_listing_excluded']) 
     285                && is_array($GLOBALS['midcom_config']['component_listing_excluded']) 
     286                && in_array($component, $GLOBALS['midcom_config']['component_listing_excluded']) 
     287                && $component !== $parent_component 
     288                && !$all) 
     289            { 
     290                continue; 
     291            } 
     292             
     293            $list[$component] = "{$details['name']} ({$component} {$details['version']})"; 
     294        } 
     295         
     296        return $list; 
     297    } 
     298     
     299    /** 
    253300     * Static method for listing available style templates 
    254301     *  
     
    258305    { 
    259306        static $style_array = array(); 
     307         
     308        $style_array[''] = $_MIDCOM->i18n->get_string('default', 'midcom.admin.folder'); 
    260309         
    261310        $qb = midcom_db_style::new_query_builder(); 
     
    266315        { 
    267316            $style_string = "{$prefix}{$style->name}"; 
     317             
     318            // Hide common unwanted material with heuristics 
     319            if (preg_match('/(asgard|aegir|empty|spider|admin site)/i', $style_string)) 
     320            { 
     321                continue; 
     322            } 
     323             
    268324            $style_array[$style_string] = "{$spacer}{$style->name}"; 
    269325            midcom_admin_folder_folder_management::list_styles($style->id, $style_string . '/', $spacer . '&nbsp;&nbsp;'); 
  • branches/branch-2_6/src/midcom.admin.folder/handler/edit.php

    r5150 r11684  
    1616{ 
    1717    /** 
     18     * DM2 schema 
     19     *  
     20     * @access private 
     21     * @var midcom_helper_datamanager2_schema $_schema 
     22     */ 
     23    var $_schemadb; 
     24     
     25    /** 
     26     * DM2 controller instance 
     27     *  
     28     * @access private 
     29     * @var midcom_helper_datamanager2_controller $_controller 
     30     */ 
     31    var $_controller; 
     32     
     33    /** 
     34     * ID of the handler 
     35     *  
     36     * @access private 
     37     */ 
     38    var $_handler_id; 
     39     
     40    /** 
    1841     * Constructor method 
    1942     *  
     
    2447        parent::midcom_baseclasses_components_handler(); 
    2548    } 
    26  
     49     
     50    /** 
     51     * Load the schemadb and other midcom.admin.folder specific stuff 
     52     *  
     53     * @access public 
     54     */ 
     55    function _on_initialize() 
     56    { 
     57        // Load the configuration 
     58        $_MIDCOM->componentloader->load('midcom.admin.folder'); 
     59        $this->_config =& $GLOBALS['midcom_component_data']['midcom.admin.folder']['config']; 
     60    } 
     61     
     62    /** 
     63     * Load either a create controller or an edit (simple) controller or trigger an error message 
     64     *  
     65     * @access private 
     66     */ 
     67    function _load_controller() 
     68    { 
     69        // Get the configured schemas 
     70        $schemadbs = $this->_config->get('schemadbs_folder'); 
     71         
     72        // Check if a custom schema exists 
     73        if (array_key_exists($this->_topic->get_parameter('midcom', 'component'), $schemadbs)) 
     74        { 
     75            $schemadb = $schemadbs[$this->_topic->get_parameter('midcom', 'component')]; 
     76        } 
     77        else 
     78        { 
     79            if (!array_key_exists('default', $schemadbs)) 
     80            { 
     81                $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Configuration error. No default schema for topic has been defined!'); 
     82                // This will exit 
     83            } 
     84             
     85            $schemadb = $schemadbs['default']; 
     86        } 
     87         
     88        $GLOBALS['midcom_admin_folder_mode'] = $this->_handler_id; 
     89         
     90        // Create the schema instance 
     91        $this->_schemadb = midcom_helper_datamanager2_schema::load_database($schemadb); 
     92         
     93        switch ($this->_handler_id) 
     94        { 
     95            case 'edit': 
     96                $this->_controller =& midcom_helper_datamanager2_controller::create('simple'); 
     97                $this->_controller->schemadb =& $this->_schemadb; 
     98                $this->_controller->set_storage($this->_topic); 
     99                break; 
     100             
     101            case 'create': 
     102                $this->_schemadb->default->fields['name']['required'] = 0; 
     103                $this->_controller =& midcom_helper_datamanager2_controller::create('create'); 
     104                $this->_controller->schemadb =& $this->_schemadb; 
     105                $this->_controller->schemaname = 'default'; 
     106                $this->_controller->callback_object =& $this; 
     107                 
     108                // Suggest to create the same type of a folder as the parent is 
     109                $this->_controller->defaults = array 
     110                ( 
     111                    'component' => $this->_topic->get_parameter('midcom', 'component'), 
     112                ); 
     113                break; 
     114             
     115            default: 
     116                $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Unable to process the request, unknown handler id'); 
     117                // This will exit 
     118        } 
     119         
     120        if (! $this->_controller->initialize()) 
     121        { 
     122            $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Failed to initialize a DM2 controller instance for article {$this->_event->id}."); 
     123            // This will exit. 
     124        } 
     125         
     126    } 
     127     
     128    /** 
     129     * DM2 creation callback, binds to the current content topic. 
     130     */ 
     131    function & dm2_create_callback (&$controller) 
     132    { 
     133        $this->_new_topic = new midcom_db_topic(); 
     134        $this->_new_topic->up = $this->_topic->id; 
     135         
     136        if (! $this->_new_topic->create()) 
     137        { 
     138            debug_push_class(__CLASS__, __FUNCTION__); 
     139            debug_print_r('We operated on this object:', $this->_new_topic); 
     140            debug_pop(); 
     141            $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 
     142                'Failed to create a new article, cannot continue. Last Midgard error was: '. mgd_errstr()); 
     143            // This will exit. 
     144        } 
     145 
     146        return $this->_new_topic; 
     147    } 
     148 
     149     
    27150    /** 
    28151     * Handler for folder editing. Checks for the permissions and folder integrity. 
     
    36159        $this->_topic->require_do('midcom.admin.folder:topic_management'); 
    37160         
    38         if (array_key_exists('f_cancel', $_REQUEST)) 
    39         { 
    40             $_MIDCOM->relocate(''); 
    41             // This will exit. 
    42         } 
    43  
    44         if (array_key_exists('f_submit', $_REQUEST)) 
    45         { 
    46             if ($this->_process_edit_form()) 
    47             { 
    48                 // Relocate to the renamed topic 
    49                 $_MIDCOM->relocate($_MIDCOM->permalinks->create_permalink($this->_topic->guid)); 
    50                 // This will exit. 
    51             } 
     161        $this->_handler_id = str_replace('____ais-folder-', '', $handler_id); 
     162         
     163        // Load the DM2 controller 
     164        $this->_load_controller(); 
     165         
     166        // Get the content topic prefix 
     167        $prefix = $_MIDCOM->get_context_data(MIDCOM_CONTEXT_ANCHORPREFIX); 
     168         
     169        // Store the old name before editing 
     170        $old_name = $this->_topic->name; 
     171         
     172        switch ($this->_controller->process_form()) 
     173        { 
     174            case 'cancel': 
     175                $_MIDCOM->uimessages->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('cancelled')); 
     176                $_MIDCOM->relocate($prefix); 
     177                break; 
     178             
     179            case 'save': 
     180                if ($this->_handler_id === 'edit') 
     181                { 
     182                    $_MIDCOM->uimessages->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('folder saved')); 
     183                     
     184                    // Get the relocation url 
     185                    $url = preg_replace("/{$old_name}\/\$/", "{$this->_topic->name}/", $prefix); 
     186                } 
     187                else 
     188                { 
     189                    $_MIDCOM->uimessages->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('folder created')); 
     190                     
     191                    // Generate name if it is missing 
     192                    if (!$this->_new_topic->name) 
     193                    { 
     194                        $this->_new_topic->name = midcom_generate_urlname_from_string($this->_new_topic->extra); 
     195                        $this->_new_topic->update(); 
     196                    } 
     197                     
     198                    // Get the relocation url 
     199                    $url = "{$prefix}/{$this->_new_topic->name}/"; 
     200                } 
     201                 
     202                $_MIDCOM->relocate($url); 
     203                // This will exit 
    52204        } 
    53205         
     
    65217        $this->_node_toolbar->hide_item('__ais/folder/edit.html'); 
    66218 
     219        $data['topic'] =& $this->_topic; 
     220        $data['controller'] =& $this->_controller; 
     221         
    67222        // Set page title 
    68         $this->_request_data['topic'] = $this->_topic; 
    69         $this->_request_data['title'] = sprintf($_MIDCOM->i18n->get_string('edit folder %s', 'midcom.admin.folder'), $this->_request_data['topic']->extra); 
    70         $_MIDCOM->set_pagetitle($this->_request_data['title']); 
     223        $data['title'] = sprintf($_MIDCOM->i18n->get_string('edit folder %s', 'midcom.admin.folder'), $data['topic']->extra); 
     224        $_MIDCOM->set_pagetitle($data['title']); 
    71225 
    72226        // Set the help object in the toolbar 
     
    75229        // Ensure we get the correct styles 
    76230        $_MIDCOM->style->prepend_component_styledir('midcom.admin.folder'); 
     231         
     232        // Serve the correct localization 
     233        $data['l10n'] =& $this->_l10n; 
    77234         
    78235        // Add style sheet 
     
    91248     
    92249    /** 
    93      * Processes the _Edit folder_ page form and updates the folder. 
    94      *  
    95      * @access private 
    96      * @return boolean Indicating success 
    97      */ 
    98     function _process_edit_form() 
    99     { 
    100         if (trim($_REQUEST['f_name']) == '') 
    101         { 
    102             $this->_processing_msg = 'Error: URL name was empty.'; 
    103             return false; 
    104         } 
    105         if (trim($_REQUEST['f_title']) == '') 
    106         { 
    107             $this->_processing_msg = 'Error: Title was empty.'; 
    108             return false; 
    109         } 
    110         if (mgd_get_topic_by_name($this->_topic->id, $_REQUEST['f_name'])) 
    111         { 
    112             $this->_processing_msg = 'Error: a Folder with this name already exists.'; 
    113             return false; 
    114         } 
    115  
    116         // store form data in topic object 
    117         $this->_topic->name = midcom_generate_urlname_from_string($_REQUEST['f_name']); 
    118         $this->_topic->extra = $_REQUEST['f_title']; 
    119         //$this->_topic->score = $_REQUEST['f_score']; 
    120         //$this->_topic->owner = $_REQUEST['f_owner']; 
    121         $this->_topic->set_parameter('midcom', 'style', $_REQUEST['f_style']); 
    122          
    123         // TODO: Move to metadata 
    124         $this->_topic->set_parameter('midcom.helper.nav', 'navorder', $_REQUEST['f_navorder']); 
    125          
    126         if (   array_key_exists('f_style_inherit', $_REQUEST) 
    127             && $_REQUEST['f_style_inherit'] == 'on') 
    128         { 
    129             $this->_topic->set_parameter('midcom', 'style_inherit', true); 
     250     * Create a new style for the topic 
     251     *  
     252     * @access private 
     253     * @param string $name Name of the style 
     254     * @return string Style path 
     255     */ 
     256    function _create_style($style_name) 
     257    { 
     258        debug_push_class(__CLASS__, __FUNCTION__); 
     259         
     260        if (isset($GLOBALS['midcom_style_inherited'])) 
     261        { 
     262            $up = $_MIDCOM->style->get_style_id_from_path($GLOBALS['midcom_style_inherited']); 
     263            debug_add("Style inherited from {$GLOBALS['midcom_style_inherited']}"); 
    130264        } 
    131265        else 
    132266        { 
    133             $this->_topic->set_parameter('midcom', 'style_inherit', false); 
    134         } 
    135  
    136         if (   trim($_REQUEST['f_type']) !== $this->_topic->get_parameter('midcom', 'component') 
    137             && $_MIDCOM->auth->admin 
    138             && $_REQUEST['f_type'] !== '') 
    139         { 
    140              $this->_topic->set_parameter('midcom', 'component', $_REQUEST['f_type']); 
    141         } 
    142  
    143  
    144         if (! $this->_topic->update()) 
    145         { 
    146             $this->_processing_msg = 'Could not save Folder: ' . mgd_errstr(); 
    147             return false; 
    148         } 
    149  
    150         $_MIDCOM->cache->invalidate($this->_topic->guid()); 
    151  
    152         return true; 
     267            $up = $_MIDGARD['style']; 
     268            debug_add("No inherited style found, placing the new style under host style (ID: {$_MIDGARD['style']}"); 
     269        } 
     270         
     271        $style = new midcom_db_style(); 
     272        $style->name = $style_name; 
     273        $style->up = $up; 
     274         
     275        if (!$style->create()) 
     276        { 
     277            debug_print_r('Failed to create a new style due to ' . mgd_errstr(), $style, MIDCOM_LOG_WARN); 
     278            debug_pop(); 
     279             
     280            $_MIDCOM->uimessages->add('edit folder', sprintf($_MIDCOM->i18n->get_string('failed to create a new style template: %s', 'midcom.admin.folder'), mgd_errstr()), 'error'); 
     281            return ''; 
     282        } 
     283         
     284        debug_print_r('New style created', $style); 
     285        debug_pop(); 
     286         
     287        return $_MIDCOM->style->get_style_path_from_id($style->id); 
    153288    } 
    154289     
     
    160295    function _show_edit($handler_id, &$data) 
    161296    { 
    162         // Get parent component and navorder 
    163         $this->_request_data['parent_topic'] = $this->_topic->get_parameter('midcom', 'component'); 
    164                 
    165         $this->_request_data['view'] =& $this->_topic; 
    166         $this->_request_data['style_inherit'] = $this->_topic->get_parameter('midcom', 'style_inherit'); 
    167         $this->_request_data['style'] = $this->_topic->get_parameter('midcom', 'style'); 
    168         $this->_request_data['folder'] =& $this->_topic; 
    169          
    170         // TODO: Move to metadata 
    171         $this->_request_data['navorder'] = $this->_topic->parameter('midcom.helper.nav', 'navorder'); 
    172          
    173         $this->_request_data['navorder_list'] = array 
    174         ( 
    175             MIDCOM_NAVORDER_DEFAULT => $_MIDCOM->i18n->get_string('default sort order', 'midcom.admin.folder'), 
    176             MIDCOM_NAVORDER_TOPICSFIRST => $_MIDCOM->i18n->get_string('folders first', 'midcom.admin.folder'), 
    177             MIDCOM_NAVORDER_ARTICLESFIRST => $_MIDCOM->i18n->get_string('pages first', 'midcom.admin.folder'), 
    178             MIDCOM_NAVORDER_SCORE => $_MIDCOM->i18n->get_string('by score', 'midcom.admin.folder'), 
    179         ); 
    180          
    181         $style_default = array 
    182         ( 
    183             '' => $_MIDCOM->i18n->get_string('default', 'midcom.admin.folder'), 
    184         ); 
    185          
    186297        $styles_all = midcom_admin_folder_folder_management::list_styles(); 
    187298         
    188         $this->_request_data['styles'] = array_merge($style_default, $styles_all); 
    189          
    190         // Place $view as a super global for the style checker function 
    191         // midcom_admin_content_list_styles_selector2 
    192         $GLOBALS['view'] =& $this->_topic; 
    193          
    194299        // Show the style element 
    195         midcom_show_style('midcom-admin-show-edit-folder'); 
     300        if ($this->_handler_id === 'create') 
     301        { 
     302            $data['page_title'] = sprintf($this->_i18n->get_string("create folder", 'midcom.admin.folder')); 
     303        } 
     304        else 
     305        { 
     306            $data['page_title'] = sprintf($this->_i18n->get_string("{$this->_handler_id} folder %s", 'midcom.admin.folder'), $this->_topic->extra); 
     307        } 
     308         
     309        midcom_show_style('midcom-admin-show-folder-actions'); 
    196310    } 
    197311}