Changeset 11872

Show
Ignore:
Timestamp:
08/30/07 15:37:53 (1 year ago)
Author:
bergie
Message:

Various urlparser fixes, s/topic/node, refs #1

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.core/midcom.php

    r11859 r11872  
    129129 
    130130// Helpers and First-Generation services 
    131 require('midcom/helper/urlparser.php'); 
    132131require('midcom/helper/_componentloader.php'); 
    133132require('midcom/helper/_styleloader.php'); 
  • trunk/midcom/midcom.core/midcom/application.php

    r11868 r11872  
    405405     * 
    406406     * Initialize the Application class. Sets all private variables to a predefined 
    407      * state. $topic should be set to the midcom root-topic GUID. 
     407     * state. $node should be set to the midcom root-node GUID. 
    408408     * $prefix can be a prefix, which is appended to get_midgard()->self (i.e. the 
    409409     * Midgard Page URL). This may be needed when MidCOM is run by wrapper. 
     
    431431 
    432432        // Initialize Root Topic 
    433         $root_topic = new midcom_db_topic($GLOBALS['midcom_config']['midcom_root_topic_guid']); 
    434         if (   ! $root_topic 
    435             || !$root_topic->guid) 
     433        $root_node = new midcom_db_topic($GLOBALS['midcom_config']['midcom_root_topic_guid']); 
     434        if (   ! $root_node 
     435            || !$root_node->guid) 
    436436        { 
    437437            if (mgd_errno() == MGD_ERR_ACCESS_DENIED) 
     
    443443            { 
    444444                $this->generate_error(MIDCOM_ERRCRIT, 
    445                     "Unable to load root topic with GUID='{$GLOBALS['midcom_config']['midcom_root_topic_guid']}'.<br />" . 
     445                    "Unable to load root node with GUID='{$GLOBALS['midcom_config']['midcom_root_topic_guid']}'.<br />" . 
    446446                    "This is fatal, aborting. See the MidCOM log file for details.<br />" . 
    447447                    'Last Midgard Error was: ' . mgd_errstr()); 
     
    451451         
    452452        // Initialize Context Storage 
    453         $this->_currentcontext = $this->_create_context(0, $root_topic); 
     453        $this->_currentcontext = $this->_create_context(0, $root_node); 
    454454 
    455455        // Populate browser information 
     
    607607     * the URL $url and executes it as if it was used as primary component. 
    608608     * Additional configuration parameters can be appended through the parameter 
    609      * $config. Specifying a topic id will let the parser work on a different topic 
    610      * tree than usual. The default "null" stays within the current topic tree. It 
    611      * will return the Context ID on success, false on failure, generate-error will 
    612      * be used to generate an appropriate error message. 
     609     * $config. 
    613610     * 
    614611     * This is only possible if the system is in the Page-Style output phase. It 
     
    620617     * the following exceptions: 
    621618     * 
    622      * - The Topic with the ID $topicid is used as a root topic instead of the 
    623      *   normal root topic. This is required to be able to administrate another 
    624      *   Topic Tree as the AIS does. 
    625619     * - This function can (and usually will be) called during the content output phase 
    626620     *   of the system. 
    627621     * - A call to generate_error will result in an regular error page output if 
    628622     *   we still are in the code-init phase. 
    629      * - The parameter urlparser_prefix is there to let the parser know that we are 
    630      *   operating under a different environment. $midgard->self is not a good start 
    631      *   anymore. This is needed to provide an accurate anchor prefix in the 
    632      *   component context. If this parameter is omitted, it is set to the 
    633      *   anchor_prefix of the calling component. 
    634623     * 
    635624     * Example code, executed on a sites Homepage, it will load the newsticker from 
    636      * the given URL and display it using a substyle of the topic style that is assinged 
     625     * the given URL and display it using a substyle of the node style that is assinged 
    637626     * to the loaded one: 
    638627     * 
     
    706695 
    707696        // Parser Init: Generate arguments and instantinate it. 
    708         $topic = $this->get_context_data(MIDCOM_CONTEXT_ROOTTOPIC); 
    709697        $this->_parser = $this->serviceloader->load('midcom_core_service_urlparser'); 
    710698        $argv = $this->_parser->tokenize($url); 
     
    793781     * will report an error, depending on the situation. 
    794782     * 
    795      * Details: The logic will traverse the topic tree and for each topic it will load 
     783     * Details: The logic will traverse the node tree and for each node it will load 
    796784     * the component that is responsible for it. This component gets the chance to 
    797785     * acceppt the request (this is encaspulated in the _checkobject call), which is 
     
    803791     * If the parsing process doesn't find any component that declares to be able to 
    804792     * handle the request, an HTTP 404 - Not Found error is triggered. 
    805      * 
    806      * If no topic is found, it tries to serve a topic attachment as a last resort, 
    807      * it uses the last valid topic as container object. 
    808      * 
    809      * This method has legacy ViewerGroups parameter support since version 1.3. If 
    810      * a ViewerGroup parameter domain is detected at a given topic, and the user does 
    811      * not have the appropriate permissions, it will fire an HTTP 401 Unauthorized 
    812      * error. If no ViewerGroups parameter domain is there, no error will be fired. 
    813      * 
    814      * Two types of attachments will be processed and delivered automatically: 
    815      * Topic-Attachments and explicit attachments requested through the 
    816      * midcom-serveattachment... URL methods. 
    817793     * 
    818794     * @access private 
     
    930906            $object = $this->_parser->get_current_object(); 
    931907 
    932             if (!is_a($object,'midcom_db_topic')) 
     908            if (!is_object($object)) 
    933909            { 
    934                 debug_add("Root topic missing.", MIDCOM_LOG_ERROR); 
    935                 $this->generate_error(MIDCOM_ERRCRIT, "Root topic missing."); 
     910                debug_add("Root node missing.", MIDCOM_LOG_ERROR); 
     911                $this->generate_error(MIDCOM_ERRCRIT, "Root node missing."); 
    936912            } 
    937913 
     
    940916            if (!$path)  
    941917            { 
    942                 debug_add("No component defined for this Topic.", MIDCOM_LOG_ERROR); 
    943                 $this->generate_error(MIDCOM_ERRCRIT, "No component defined for this Topic."); 
     918                debug_add("No component defined for this node.", MIDCOM_LOG_ERROR); 
     919                $this->generate_error(MIDCOM_ERRCRIT, "No component defined for this node."); 
    944920            } 
    945921 
     
    949925            // If so, execute it, if not, continue. 
    950926 
    951             if ($this->_checkobject($object)) { 
     927            if ($this->_checkobject($object))  
     928            { 
    952929                $this->_status = MIDCOM_STATUS_HANDLE; 
    953930 
    954                 // Strip all midcom-*-* URL Parameters out of the prefix. 
    955  
    956931                $prefix = $this->_parser->get_url(); 
    957                 $prefix = preg_replace ("|midcom-[^-]*-[^/]*/|i","",$prefix); 
    958  
     932                 
    959933                // Initialize context 
    960934                $this->_context[$this->_currentcontext][MIDCOM_CONTEXT_ANCHORPREFIX] = $prefix; 
     
    975949        if (! $success) 
    976950        { 
    977             // We couldn't fetch a topic due to access restrictions. 
     951            // We couldn't fetch a node due to access restrictions. 
    978952            if (mgd_errno() == MGD_ERR_ACCESS_DENIED) 
    979953            { 
     
    10381012     * according to the error code and -string of the component in question. 
    10391013     * 
    1040      * @param string $path    Override the component set in the topic (used mainly for AIS). 
    1041      * @access private 
    1042      */ 
    1043     private function _handle($path = NULL) 
     1014     * @access private 
     1015     */ 
     1016    private function _handle() 
    10441017    { 
    10451018        debug_push_class(__CLASS__, __FUNCTION__); 
    10461019 
    1047         $opath = $this->get_context_data(MIDCOM_CONTEXT_COMPONENT); 
    1048         if (!isset($path)) $path = $opath; 
     1020        $path = $this->get_context_data(MIDCOM_CONTEXT_COMPONENT); 
    10491021 
    10501022        if ($this->get_context_data(MIDCOM_CONTEXT_REQUESTTYPE) != MIDCOM_REQUEST_CONTENT) 
     
    11221094     * accordingly, both on the configure and on the can_handle run. 
    11231095     * 
    1124      * @param MidgardTopic $object    The topic that is currently being tested. 
     1096     * @param MidgardTopic $object    The node that is currently being tested. 
    11251097     * @return bool                    Indication, wether a component can handle a request. 
    11261098     * @access private 
     
    11771149     * parameter domain has to be used. 
    11781150     * 
    1179      * @param MidgardTopic $object    The topic from which to load the configuration. 
     1151     * @param MidgardObject $object    The node from which to load the configuration. 
    11801152     * @return midcom_helper_configuration    Reference to the newly constructed configuration object. 
    11811153     * @access private 
     
    13921364     * currently uses different context IDs. The problem is, that this is not 100% 
    13931365     * efficient: If you instantinate two different NAP Classes in different contexts 
    1394      * both referring to the same root topic, you will get two different instances. 
     1366     * both referring to the same root node, you will get two different instances. 
    13951367     * 
    13961368     * If the system has not completed the can_handle phase, this method fails and 
     
    14201392 
    14211393        return $this->_context[$contextid][MIDCOM_CONTEXT_NAP]; 
    1422     } 
    1423  
    1424     /** 
    1425      * @deprecated This function is discouraged in favor of the component context since 2.0.0 
    1426      * 
    1427      * Return a copy of the topic that is handling the request. 
    1428      * 
    1429      * If the system is in the output phase (midcom_application::codeinit is false), 
    1430      * this function returns a copy of the topic, that is being output, for example 
    1431      * for the usage of the NAP System. 
    1432      * 
    1433      * If the system is not in the output phase, this method simply returns false. 
    1434      * 
    1435      * <b>Note:</b> This is equivalent to requesting the context key 
    1436      * MIDCOM_CONTEXT_CONTENTTOPIC 
    1437      * 
    1438      * @return MidgardTopic    The topic being output. 
    1439      * @see midcom_application::get_context_data() 
    1440      */ 
    1441     function get_content_topic()  { 
    1442         return $this->get_context_data(MIDCOM_CONTEXT_CONTENTTOPIC); 
    14431394    } 
    14441395 
     
    18771828     * 
    18781829     * @param int id Explicitly specify the ID for context creation (used during construction), this parameter is usually omitted. 
    1879      * @param midcom_db_topic Root topic of the context 
     1830     * @param MidgardObject Root node of the context 
    18801831     * @return int The ID of the newly created component. 
    18811832     * @access private 
    18821833     */ 
    1883     private function _create_context($id = null, $topic = null) 
     1834    private function _create_context($id = null, $node = null) 
    18841835    { 
    18851836        if (is_null($id)) 
     
    18901841        $this->_context[$id][MIDCOM_CONTEXT_ANCHORPREFIX] = ''; 
    18911842        $this->_context[$id][MIDCOM_CONTEXT_REQUESTTYPE] = MIDCOM_REQUEST_CONTENT; 
    1892         $this->_context[$id][MIDCOM_CONTEXT_ROOTTOPIC] = $topic
     1843        $this->_context[$id][MIDCOM_CONTEXT_ROOTTOPIC] = $node
    18931844        $this->_context[$id][MIDCOM_CONTEXT_CONTENTTOPIC] = null; 
    18941845        $this->_context[$id][MIDCOM_CONTEXT_COMPONENT] = null; 
  • trunk/midcom/midcom.core/midcom/core/service/implementation/urlparsertopic.php

    r11868 r11872  
    1919    private $root_topic = null; 
    2020    private $current_object = null; 
     21 
     22    private $url = ''; 
    2123 
    2224    public function __construct() 
     
    8486         
    8587        $this->current_object = $this->root_topic; 
     88        $this->url = ''; 
    8689    } 
    8790 
     
    129132        $this->argc -= 1; 
    130133        array_shift ($this->argv); 
     134 
     135        $this->url .= $this->current_object->name . '/'; 
    131136         
    132137        return $this->current_object; 
     
    183188    public function get_url() 
    184189    { 
    185         return implode('/', $this->argv_original) . '/'
     190        return '/' . $this->url
    186191    } 
    187192} 
  • trunk/midcom/midcom.core/midcom/helper/_styleloader.php

    r11816 r11872  
    744744        debug_add("entering context $context", MIDCOM_LOG_DEBUG); 
    745745 
    746         $this->_topic = $_MIDCOM->get_content_topic(); 
     746        $this->_topic = $_MIDCOM->get_context_data(MIDCOM_CONTEXT_CONTENTTOPIC); 
    747747 
    748748        $_st = $this->_getComponentStyle($this->_topic); 
     
    781781        // get our topic again 
    782782        // FIXME: does this have to be above _getComponentStyle($this->_topic) ?? 
    783         $this->_topic = $_MIDCOM->get_content_topic(); 
     783        $this->_topic = $_MIDCOM->get_context_data(MIDCOM_CONTEXT_CONTENTTOPIC); 
    784784 
    785785        $this->_snippetdir = $this->_getComponentSnippetdir($this->_topic);