Changeset 12903

Show
Ignore:
Timestamp:
10/19/07 16:58:13 (1 year ago)
Author:
adrenalin
Message:

Added article linking support similar to the one of net.nehmer.blog

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/net.nehmer.static/config/config.inc

    r4443 r12903  
    2727// Set this to true if you want to enable on-site AJAX editing 
    2828'enable_ajax_editing' => false, 
     29 
     30// Page linking system 
     31'enable_article_links' => true, 
     32'enable_editing_of_linked_articles' => false, 
     33'include_linked_articles_to_feeds' => true, 
     34 
     35// Creation callback snippet for defining site-specific function 
     36'callback_snippet' => null, 
     37 
     38// Callback function will be called after creation e.g. to provide interface for page linking system 
     39// $callback_function($article, $topic) 
     40'callback_function' => null, 
  • trunk/midcom/net.nehmer.static/config/manifest.inc

    r5819 r12903  
    1  
    2   'name' => 'net.nehmer.static', 
    3   'version' => '1.0.10beta1', 
    4   'state' => 'beta', 
    5   'package.xml' =>  
    6   array ( 
     1'name' => 'net.nehmer.static', 
     2'version' => '1.0.10beta2', 
     3'state' => 'beta', 
     4'class_definitions' => array 
     5
     6    'midcom_dba_classes.inc', 
     7), 
     8'package.xml' => array 
     9
    710    'summary' => 'Static article content display', 
    811    'description' => 'Static content display component emulating regular directory of HTML files', 
    9     'maintainers' =>  
    10     array
    11       'torben' =>  
    12       array
    13         'name' => 'Torben Nehmer', 
    14         'email' => 'torben@nehmer.net', 
    15         'role' => 'lead', 
    16         'active' => 'no', 
    17       ), 
    18       'bergie' =>  
    19       array
    20         'name' => 'Henri Bergius', 
    21         'email' => 'henri.bergius@iki.fi', 
    22         'role' => 'lead', 
    23         'active' => 'yes', 
    24       ), 
    25       'adrenalin' =>  
    26       array
    27         'name' => 'Arttu Manninen', 
    28         'email' => 'arttu@kaktus.cc', 
    29         'role' => 'lead', 
    30       ), 
     12    'maintainers' => array 
     13   
     14        'torben' => array 
     15     
     16            'name' => 'Torben Nehmer', 
     17            'email' => 'torben@nehmer.net', 
     18            'role' => 'lead', 
     19            'active' => 'no', 
     20        ), 
     21        'bergie' => array 
     22     
     23            'name' => 'Henri Bergius', 
     24            'email' => 'henri.bergius@iki.fi', 
     25            'role' => 'lead', 
     26            'active' => 'yes', 
     27        ), 
     28        'adrenalin' => array 
     29     
     30            'name' => 'Arttu Manninen', 
     31            'email' => 'arttu@kaktus.cc', 
     32            'role' => 'lead', 
     33        ), 
    3134    ), 
    32     'dependencies' =>  
    33     array ( 
    34       'midcom.helper.datamanager2' =>  
    35       array ( 
    36       ), 
    37       'midcom.helper.datamanager' =>  
    38       array ( 
    39       ), 
    40       'midcom' =>  
    41       array ( 
    42       ), 
     35    'dependencies' => array 
     36    ( 
     37        'midcom.helper.datamanager2' => array (), 
     38        'midcom.helper.datamanager' => array (), 
     39        'midcom' => array (), 
    4340    ), 
    44   ), 
     41), 
  • trunk/midcom/net.nehmer.static/documentation/CHANGES

    r5797 r12903  
    88  which might even break existing functionality. 
    99- All items marked with "+" represent completely new features. 
     10 
     112007-10-19 adrenalin 
     12  ! Added article linking support similar to the one of net.nehmer.blog 
    1013 
    11142007-04-24 adrenalin 
  • trunk/midcom/net.nehmer.static/handler/admin.php

    r5857 r12903  
    171171    { 
    172172        $tmp = Array(); 
    173  
    174         $tmp[] = Array 
    175         ( 
    176             MIDCOM_NAV_URL => "{$handler_id}/{$this->_article->guid}.html", 
    177             MIDCOM_NAV_NAME => $this->_l10n_midcom->get($handler_id), 
    178         ); 
    179  
     173         
     174        if ($handler_id !== 'delete_link') 
     175        { 
     176            $tmp[] = Array 
     177            ( 
     178                MIDCOM_NAV_URL => "{$handler_id}/{$this->_article->guid}.html", 
     179                MIDCOM_NAV_NAME => $this->_l10n_midcom->get($handler_id), 
     180            ); 
     181        } 
     182 
     183        switch ($handler_id) 
     184        { 
     185            case 'delete_link': 
     186                $tmp[] = Array 
     187                ( 
     188                    MIDCOM_NAV_URL => "delete/link/{$this->_article->guid}.html", 
     189                    MIDCOM_NAV_NAME => $this->_l10n->get('delete link'), 
     190                ); 
     191                break; 
     192             
     193            default: 
     194                $tmp[] = Array 
     195                ( 
     196                    MIDCOM_NAV_URL => "{$handler_id}/{$this->_article->guid}.html", 
     197                    MIDCOM_NAV_NAME => $this->_l10n_midcom->get($handler_id), 
     198                ); 
     199        } 
     200         
    180201        $_MIDCOM->set_custom_context_data('midcom.helper.nav.breadcrumb', $tmp); 
    181202    } 
     
    193214    { 
    194215        $this->_article = new midcom_db_article($args[0]); 
    195         if (! $this->_article) 
     216        if (!$this->_article) 
    196217        { 
    197218            $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, "The article {$args[0]} was not found."); 
     219            // This will exit. 
     220        } 
     221         
     222        // Relocate for the correct content topic, let the true content topic take care of the ACL 
     223        if ($this->_article->topic !== $this->_content_topic->id) 
     224        { 
     225            $nap = new midcom_helper_nav(); 
     226            $node = $nap->get_node($this->_article->topic); 
     227             
     228            if (   $node 
     229                && isset($node[MIDCOM_NAV_FULLURL])) 
     230            { 
     231                $_MIDCOM->relocate($node[MIDCOM_NAV_FULLURL] . "edit/{$args[0]}.html"); 
     232                // This will exit 
     233            } 
     234            $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, "The article with GUID {$args[0]} was not found."); 
    198235            // This will exit. 
    199236        } 
     
    238275    } 
    239276 
     277     
     278    /** 
     279     * Displays article link delete confirmation 
     280     */ 
     281    function _handler_deletelink($handler_id, $args, &$data) 
     282    { 
     283        $this->_article = new midcom_db_article($args[0]); 
     284         
     285        if (   !$this->_article 
     286            || !isset($this->_article->guid) 
     287            || !$this->_article->guid) 
     288        { 
     289            $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, "The article {$args[0]} was not found."); 
     290            // This will exit. 
     291        } 
     292         
     293        $qb = net_nehmer_static_link_dba::new_query_builder(); 
     294        $qb->add_constraint('topic', '=', $this->_content_topic->id); 
     295        $qb->add_constraint('article', '=', $this->_article->id); 
     296         
     297        // No links were found 
     298        if ($qb->count() === 0) 
     299        { 
     300            return false; 
     301        } 
     302         
     303        // Get the link 
     304        $results = $qb->execute_unchecked(); 
     305        $this->_link =& $results[0]; 
     306        $this->_link->require_do('midgard:delete'); 
     307         
     308        $this->_process_link_delete(); 
     309         
     310        $this->_prepare_request_data(); 
     311        $_MIDCOM->set_26_request_metadata($this->_article->metadata->revised, $this->_article->guid); 
     312        $this->_view_toolbar->bind_to($this->_article); 
     313        $_MIDCOM->set_pagetitle("{$this->_topic->extra}: {$this->_article->title}"); 
     314        $this->_update_breadcrumb_line($handler_id); 
     315         
     316        return true; 
     317    } 
     318     
     319    /** 
     320     * Internal helper method, which will check if the delete request has been 
     321     * confirmed 
     322     *  
     323     * @access private 
     324     */ 
     325    function _process_link_delete() 
     326    { 
     327        if (isset($_POST['f_cancel'])) 
     328        { 
     329            $_MIDCOM->uimessages->add($this->_l10n->get('net.nehmer.static'), $this->_l10n->get('delete cancelled')); 
     330             
     331            // Redirect to view page. 
     332            if ($this->_config->get('view_in_url')) 
     333            { 
     334                $_MIDCOM->relocate("view/{$this->_article->name}.html"); 
     335            } 
     336            else 
     337            { 
     338                $_MIDCOM->relocate("{$this->_article->name}.html"); 
     339            } 
     340            // This will exit 
     341        } 
     342         
     343        if (!isset($_POST['f_delete'])) 
     344        { 
     345            return; 
     346        } 
     347         
     348        // Delete the link 
     349        if ($this->_link->delete()) 
     350        { 
     351            $_MIDCOM->uimessages->add($this->_l10n->get('net.nehmer.static'), $this->_l10n->get('article link deleted')); 
     352            $_MIDCOM->relocate(''); 
     353            // This will exit 
     354        } 
     355        else 
     356        { 
     357            $_MIDCOM->generate_error(MIDCOM_ERRCRIT, $this->_l10n->get('failed to delete the article link, contact the site administrator')); 
     358            // This will exit 
     359        } 
     360    } 
     361     
     362    function _show_deletelink($handler_id, &$data) 
     363    { 
     364        $data['article'] =& $this->_article; 
     365        $nap = new midcom_helper_nav(); 
     366        $node = $nap->get_node($this->_article->topic); 
     367         
     368        $data['topic_url'] = $node[MIDCOM_NAV_FULLURL]; 
     369        $data['topic_name'] = $node[MIDCOM_NAV_NAME]; 
     370        $data['delete_url'] = "{$node[MIDCOM_NAV_FULLURL]}delete/{$this->_article->guid}.html"; 
     371         
     372        midcom_show_style('admin-delete-link'); 
     373    } 
     374 
    240375    /** 
    241376     * Displays an article delete confirmation view. 
     
    249384    { 
    250385        $this->_article = new midcom_db_article($args[0]); 
    251         if (! $this->_article) 
     386        if (   !$this->_article 
     387            || !isset($this->_article->guid) 
     388            || !$this->_article->guid) 
    252389        { 
    253390            $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, "The article {$args[0]} was not found."); 
    254391            // This will exit. 
     392        } 
     393         
     394        // Relocate to delete the link instead of the article itself 
     395        if ($this->_article->topic !== $this->_content_topic->id) 
     396        { 
     397            $_MIDCOM->relocate("delete/link/{$args[0]}.html"); 
     398            // This will exit 
    255399        } 
    256400        $this->_article->require_do('midgard:delete'); 
     
    266410                // This will exit. 
    267411            } 
     412 
     413            // Delete all the links pointing to the article 
     414            $qb = net_nehmer_static_link_dba::new_query_builder(); 
     415            $qb->add_constraint('article', '=', $this->_article->id); 
     416            $links = $qb->execute_unchecked(); 
     417             
     418            $_MIDCOM->auth->request_sudo('net.nehmer.static'); 
     419            foreach ($links as $link) 
     420            { 
     421                $link->delete(); 
     422            } 
     423            $_MIDCOM->auth->drop_sudo(); 
    268424 
    269425            // Update the index 
  • trunk/midcom/net.nehmer.static/handler/create.php

    r12717 r12903  
    173173        } 
    174174 
     175        // Callback possibility 
     176        if ($this->_config->get('callback_function')) 
     177        { 
     178            if ($this->_config->get('callback_snippet')) 
     179            { 
     180                // mgd_include_snippet($this->_config->get('callback_snippet')); 
     181                $eval = midcom_get_snippet_content($this->_config->get('callback_snippet')); 
     182                 
     183                if ($eval) 
     184                { 
     185                    eval($eval); 
     186                } 
     187            } 
     188             
     189            $callback = $this->_config->get('callback_function'); 
     190            $callback($this->_article, $this->_content_topic); 
     191        } 
     192         
    175193        return $this->_article; 
    176194    } 
  • trunk/midcom/net.nehmer.static/handler/view.php

    r12423 r12903  
    102102 
    103103        $qb = midcom_baseclasses_database_article::new_query_builder(); 
    104         $qb->add_constraint('topic', '=', $this->_content_topic->id); 
    105104        $qb->add_constraint('name', '=', $args[0]); 
    106105        $qb->add_constraint('up', '=', 0); 
    107106        $qb->set_limit(1); 
     107         
     108        // Include the article links to the indexes if enabled 
     109        if ($this->_config->get('enable_article_links')) 
     110        { 
     111            $mc = net_nehmer_static_link_dba::new_collector('topic', $this->_content_topic->id); 
     112            $mc->add_value_property('article'); 
     113            $mc->add_constraint('topic', '=', $this->_content_topic->id); 
     114             
     115            // Get the results 
     116            $mc->execute(); 
     117             
     118            $links = $mc->list_keys(); 
     119            $qb->begin_group('OR'); 
     120                foreach ($links as $guid => $link) 
     121                { 
     122                    $article_id = $mc->get_subkey($guid, 'article'); 
     123                    $qb->add_constraint('id', '=', $article_id); 
     124                } 
     125                $qb->add_constraint('topic', '=', $this->_content_topic->id); 
     126            $qb->end_group(); 
     127        } 
     128        else 
     129        { 
     130            $qb->add_constraint('topic', '=', $this->_content_topic->id); 
     131        } 
    108132         
    109133        $result = $qb->execute(); 
     
    135159        { 
    136160            $qb = midcom_db_article::new_query_builder(); 
    137             $qb->add_constraint('topic', '=', $this->_content_topic->id); 
    138161            $qb->add_constraint('name', '=', 'index'); 
    139162            $qb->set_limit(1); 
     163             
     164            // Include the article links to the indexes if enabled 
     165            if ($this->_config->get('enable_article_links')) 
     166            { 
     167                $mc = net_nehmer_static_link_dba::new_collector('topic', $this->_content_topic->id); 
     168                $mc->add_value_property('article'); 
     169                $mc->add_constraint('topic', '=', $this->_content_topic->id); 
     170                 
     171                // Get the results 
     172                $mc->execute(); 
     173                 
     174                $links = $mc->list_keys(); 
     175                $qb->begin_group('OR'); 
     176                    foreach ($links as $guid => $link) 
     177                    { 
     178                        $article_id = $mc->get_subkey($guid, 'article'); 
     179                        $qb->add_constraint('id', '=', $article_id); 
     180                    } 
     181                    $qb->add_constraint('topic', '=', $this->_content_topic->id); 
     182                $qb->end_group(); 
     183            } 
     184            else 
     185            { 
     186                $qb->add_constraint('topic', '=', $this->_content_topic->id); 
     187            } 
     188             
    140189            $result = $qb->execute(); 
    141190 
  • trunk/midcom/net.nehmer.static/locale/default.en.txt

    r11197 r12903  
    148148---STRINGEND 
    149149 
     150---STRING failed to delete the article link, contact the site administrator 
     151Failed to delete the article link, contact the site administrator 
     152---STRINGEND 
     153 
     154---STRING delete cancelled 
     155Delete cancelled 
     156---STRINGEND 
     157 
     158---STRING article link deleted 
     159Article link deleted 
     160---STRINGEND 
     161 
     162---STRING article %s deleted 
     163Article %s deleted 
     164---STRINGEND 
     165 
     166---STRING delete link 
     167Delete link 
     168---STRINGEND 
     169 
     170---STRING delete article link 
     171delete article link 
     172---STRINGEND 
     173 
     174---STRING this article has been linked from <a href="%s">%s</a> and confirming will delete only the link 
     175This article has been linked from <a href="%s">%s</a> and confirming will delete only the link. 
     176---STRINGEND 
     177 
     178---STRING if you want to delete the original article, <a href="%s">click here</a> 
     179If you want to delete the original article, <a href="%s">click here</a>. 
     180---STRINGEND 
     181 
     182---STRING delete article link 
     183Delete article link 
     184---STRINGEND 
     185 
     186---STRING from 
     187From 
     188---STRINGEND 
     189 
     190---STRING delete_link 
     191Delete link 
     192---STRINGEND 
  • trunk/midcom/net.nehmer.static/locale/default.fi.txt

    r11545 r12903  
    148148---STRINGEND 
    149149 
     150---STRING failed to delete the article link, contact the site administrator 
     151Artikkelilinkin poistaminen epÀonnistui, ota yhteys sivuston yllÀpitÀjÀÀn. 
     152---STRINGEND 
     153 
     154---STRING delete cancelled 
     155Poistaminen peruutettu 
     156---STRINGEND 
     157 
     158---STRING article link deleted 
     159Artikkelilinkki poistettu 
     160---STRINGEND 
     161 
     162---STRING article %s deleted 
     163Artikkeli %s poistettu 
     164---STRINGEND 
     165 
     166---STRING delete link 
     167Poista linkki 
     168---STRINGEND 
     169 
     170---STRING delete article link 
     171Poista artikkelilinkki 
     172---STRINGEND 
     173 
     174---STRING this article has been linked from <a href="%s">%s</a> and confirming will delete only the link 
     175TÀmÀ artikkeli on linkitetty osoitteesta <a href="%s">%s</a> ja vahvistaminen poistaa vain linkin. 
     176---STRINGEND 
     177 
     178---STRING if you want to delete the original article, <a href="%s">click here</a> 
     179Jos haluat poistaa alkuperÀisen artikkelin, <a href="%s">klikkaa tÀstÀ</a>. 
     180---STRINGEND 
     181 
     182---STRING delete article link 
     183Poista artikkelilinkki 
     184---STRINGEND 
     185 
     186---STRING delete_link 
     187Poista linkki 
     188---STRINGEND 
  • trunk/midcom/net.nehmer.static/midcom/interfaces.php

    r12014 r12903  
    3838        ( 
    3939            'viewer.php', 
    40             'navigation.php' 
     40            'navigation.php', 
     41            'article_link.php', 
    4142        ); 
    4243        $this->_autoload_libraries = Array 
    4344        ( 
    44             'midcom.helper.datamanager2' 
     45            'midcom.helper.datamanager2', 
    4546        ); 
    4647    } 
  • trunk/midcom/net.nehmer.static/navigation.php

    r11877 r12903  
    4848    { 
    4949        // Get the required information with midgard_collector 
    50         $mc = midcom_db_article::new_collector('topic', $this->_content_topic->id); 
     50        $mc = midcom_db_article::new_collector('up', 0); 
    5151        $mc->set_key_property('topic'); 
    5252        $mc->add_value_property('id'); 
     
    5656         
    5757        $mc->add_constraint('topic', '=', $this->_content_topic->id); 
    58         $mc->add_constraint('up', '=', 0); 
     58        if (!$this->_config->get('enable_article_links')) 
     59        { 
     60            $mc->add_constraint('topic', '=', $this->_content_topic->id); 
     61        } 
     62        else 
     63        { 
     64            // Get the linked articles as well 
     65            $mc_link = net_nehmer_static_link_dba::new_collector('topic', $this->_content_topic->id); 
     66            $mc_link->add_value_property('article'); 
     67            $mc_link->add_constraint('topic', '=', $this->_content_topic->id); 
     68            $mc_link->execute(); 
     69             
     70            $links = $mc_link->list_keys(); 
     71             
     72            $mc->begin_group('OR'); 
     73                $mc->add_constraint('topic', '=', $this->_content_topic->id); 
     74                foreach ($links as $guid => $array) 
     75                { 
     76                    $id = $mc_link->get_subkey($guid, 'id'); 
     77                    $mc->add_constraint('id', '=', $id); 
     78                } 
     79            $mc->end_group(); 
     80        } 
     81         
    5982        $mc->add_constraint('metadata.navnoentry', '=', 0); 
    6083         
  • trunk/midcom/net.nehmer.static/viewer.php

    r11909 r12903  
    5757            'handler' => Array('net_nehmer_static_handler_admin', 'delete'), 
    5858            'fixed_args' => Array('delete'), 
     59            'variable_args' => 1, 
     60        ); 
     61        $this->_request_switch['delete_link'] = array 
     62        ( 
     63            'handler' => array('net_nehmer_static_handler_admin', 'deletelink'), 
     64            'fixed_args' => array('delete', 'link'), 
    5965            'variable_args' => 1, 
    6066        );