Changeset 301 in t29-www for lib


Ignore:
Timestamp:
Sep 20, 2012, 12:18:45 AM (12 years ago)
Author:
sven
Message:

Zwei grosse Bugfixes die einige Backendänderungen nach sich zogen:

  • Impressum: Google Maps-Karte lädt wieder. Dafür wurde endlich ein seitenspezifisches Scriptsystem geschrieben, welches im RessourceLoader verankert Scriptfiles direkt einbindet. Das ermöglicht besseres Debugging, bessere Ladezeit und eine Symmetrie zu seitenspezifischen CSS. Insbesondere aber (bislang eher dreckige) Hooks, mit denen externe Scripts eingebunden werden können, was per pagescripts.js nicht geht. pagescripts.js gibts für kleine Scripte immernoch, könnte man dann ggf. auflösen.
  • Relationale Rücklinks für Geräteseiten: Geräteseiten haben nun wie ehemals einen Rücklink auf die verweisende Seite. Dieser wird anhand ihrer Einordnung in der Navigation erlangt. Bei Seiten, die nicht klar einzuordnen waren, könnte dieses Vorgehen ggf. Fehler erzeugen. Das müsste man dann im Einzelfall überprüfen.
Location:
lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • lib/loader.php

    r277 r301  
    2323        'cache_file' => array('compressed.js', 'style.css'),
    2424        'module_dir' => array("$webroot/shared/js-v6/modules", "$webroot/shared/css-v6/modules"),
     25        'page_dir' => array("$webroot/shared/js-v6/pagescripts", "$webroot/shared/css-v6/pagestyles"),
    2526        'glob_pattern' => array('*.js', '*.css'),
    2627        'content_types' => array('application/javascript', 'text/css'),
  • lib/menu.php

    r299 r301  
    55 *
    66 **/
     7
     8require_once dirname(__FILE__).'/messages.php';
     9 
    710class t29Menu {
    811        public $conf;
    912        public $xml;
    1013
     14        // Bevor es eine ordentliche Dev-Moeglichkeit gibt: Der magische
     15        // Schalter zum Ausblenden der Geraeteseiten im Menue
     16        const hide_geraete_seiten = true;
     17
    1118        // jeweils relativ zum lang_path
    1219        const navigation_file = 'navigation.xml';
     
    1926        function __construct($conf_array) {
    2027                $this->conf = $conf_array;
     28               
     29                // create a message object if not given
     30                if(!isset($this->conf['msg']))
     31                        $this->conf['msg'] = new t29Messages($this->conf['lang']);
    2132               
    2233                // libxml: don't raise errors while parsing.
     
    201212                }
    202213                $seiten_id = $this->conf['seiten_id'];
    203 
     214                $_ = $this->conf['msg']->get_shorthand_returner();
     215               
    204216                // find wanted menu
    205217                $xml = $this->xml->xpath($xpath_menu_selection);
     
    216228                        $current_li = $current_a[0]->xpath("parent::li");
    217229                        self::dom_add_class($current_li[0], 'current');
    218                         self::dom_prepend_attribute($current_a, 'title', 'Aktuelle Seite', ': ');
     230                        self::dom_prepend_attribute($current_a, 'title', $_('nav-hierarchy-current'), ': ');
    219231
    220232                        $actives = $current_li[0]->xpath("ancestor-or-self::li");
     
    222234                       
    223235                        $ancestors = $current_li[0]->xpath("ancestor::li");
    224                         array_walk($ancestors, function($i) {
    225                                 t29Menu::dom_prepend_attribute($i->xpath("./a[1]"), 'title', 'Übergeordnete Kategorie der aktuellen Seite' , ': ');
    226                         });
     236                        foreach($ancestors as $i)
     237                                t29Menu::dom_prepend_attribute($i->xpath("./a[1]"), 'title', $_('nav-hierarchy-ancestor'), ': ');
    227238                }
    228239
     
    237248
    238249                // Geraete-Seiten entfernen
    239                 $geraete_uls = $xml->xpath("//ul[contains(@class, 'geraete')]");
    240                 foreach($geraete_uls as $ul) {
    241                         $uld = dom_import_simplexml($ul);
    242                         $uld->parentNode->removeChild($uld);
    243                 }
    244        
     250                if(self::hide_geraete_seiten) {
     251                        $geraete_uls = $xml->xpath("//ul[contains(@class, 'geraete')]");
     252                        foreach($geraete_uls as $ul) {
     253                                $uld = dom_import_simplexml($ul);
     254                                $uld->parentNode->removeChild($uld);
     255                        }
     256                }
    245257       
    246258                if($xpath_menu_selection == self::horizontal_menu) {
     
    283295                        // wenn aktuelle seite eine geraeteseite ist
    284296                        if(in_array('geraete', $this->get_link_ul_classes($seiten_id))) {
    285                                 //$return['next'] = null; // kein Link nach vorne
    286                                 //$return['prev'] = null; // TODO: Da muss der richtige Link auf die Seite, die auf diese Extraseite verweist.
     297                                //  pfad:                        a ->li->ul.geraete->li->li/a
     298                                $geraetelink = $current_a[0]->xpath("../../../a");
     299                                if(count($geraetelink))
     300                                        $return['prev'] = $geraetelink[0];
     301                                $return['next'] = null; // kein Link nach vorne
    287302                        } else {
    288303                                foreach(array(
     
    304319                        $return['start'] = t29Menu::dom_new_link('#', 'bla');
    305320                }
     321               
     322                // Linkliste aufarbeiten: Nullen rausschmeissen (nur deko) und
     323                // Links *klonen*, denn sie werden durch print_menu sonst veraendert
     324                // ("Übergeordnete Kategorie der aktuellen Seite" steht dann drin)
     325                // und wir wollen sie unveraendert haben.
     326                foreach($return as $key => $node) {
     327                        if(!$node) {
     328                                unset($return[$key]);
     329                                continue;
     330                        }
     331                        $dn = dom_import_simplexml($node);
     332                        $dnc = simplexml_import_dom($dn->cloneNode(true));
     333                        $return[$key] = $dnc;
     334                }
     335               
    306336                return $return;
    307337        }
  • lib/messages.php

    r299 r301  
    137137                                                  '&copy; 2003-2012 technikum29. You must not use contents and photographies without the permission of the owner. <a href="/en/contact.php" class="go">Legal Information</a>.'),
    138138               
     139                'nav-hierarchy-current'  => array('Aktuelle Seite', 'Current page'),
     140                'nav-hierarchy-ancestor' => array('Übergeordnete Kategorie der aktuellen Seite', 'Parental category of current page'),
    139141                'nav-rel-prev'           => array('vorherige Seite', 'previous page'),
    140142                'nav-rel-next'           => array('nächste Seite', 'next page'),
  • lib/ressourceloader.php

    r285 r301  
    3232class t29RessourceLoader {
    3333        /**
    34          * expects: type, cache_file, module_dir, glob_pattern, content_types, class, modules, debug
     34         * expects: type, cache_file, module_dir, page_dir, glob_pattern, content_types, class, modules, debug
    3535         **/
    3636        public $conf;
     
    6161               
    6262                return new $conf['class']($conf);
     63        }
     64       
     65        function get_page_specific_urls($seiten_id) {
     66                global $webroot;
     67                $file = sprintf("%s/%s.%s", $this->conf['page_dir'], $seiten_id, $this->conf['type']);
     68                // TODO: This is hacky. Same in get_urls.
     69                $file_rel2webroot = str_replace($webroot, '', $file);
     70                return file_exists($file) ? array($file_rel2webroot) : array();
    6371        }
    6472       
     
    187195                }
    188196        }
     197       
     198        function get_page_specific_urls($seiten_id) {
     199                $urls = parent::get_page_specific_urls($seiten_id);
     200                switch($seiten_id) {
     201                        case 'impressum':
     202                                $urls[] = 'http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAraTKZ5cINardZ8ITNVssKhRcOoEBtCgYLJRQznXYEV8m1M3fRRRT9wMSvFwhyo62fD3KyiwQxe5ruw';
     203                                break;
     204                }
     205                return $urls;
     206        }
    189207
    190208        function print_header($title=null) {
  • lib/template.php

    r299 r301  
    1111 **/
    1212
    13 require dirname(__FILE__) . "/ressourceloader.php";
    14 
    1513class t29Template {
    1614        public $conf, $menu, $msg;
     
    3432                require_once $this->conf['lib'].'/messages.php';
    3533                $this->msg = new t29Messages($this->conf['lang']);
     34               
     35                // create the ressourceloaders:
     36                require_once $this->conf['lib'].'/ressourceloader.php';
     37                $this->rl = array();
     38                foreach(array('js','css') as $type)
     39                        $this->rl[$type] = t29RessourceLoader::create_from_type($type, $this->conf);
    3640
    3741                // fill up configuration
     
    175179  <meta name="viewport" content="width=device-width,initial-scale=1">
    176180  <?php
    177         $csslinktmpl = PHP_EOL.'  <link rel="stylesheet" href="%s">';
    178         foreach($this->get_ressourceloader_links('css') as $css)
    179                 printf($csslinktmpl, $css);
    180  
    181         if($this->conf['has_pagecss'])
    182                 printf($csslinktmpl, $this->conf['pagecss']);
     181        $this->print_ressourceloader_links('css', PHP_EOL . '  <link rel="stylesheet" href="%s">');
    183182  ?>
    184183
     
    309308
    310309  <!-- JavaScript at the bottom for fast page loading -->
    311 
    312   <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
    313   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    314   <script>window.jQuery || document.write('<script src="/shared/js-v6/libs/jquery-1.7.2.min.js"><\/script>')</script>
    315 
     310  <script src="/shared/js-v6/libs/jquery-1.7.2.min.js"></script>
    316311  <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script>
    317312  <?php
    318         foreach($this->get_ressourceloader_links('js') as $js)
    319                 printf('  <script src="%s"></script>'.PHP_EOL, $js);
     313        $this->print_ressourceloader_links('js', '  <script src="%s"></script>'.PHP_EOL);
    320314  ?>
    321315</body>
     
    331325        }
    332326
    333         function get_ressourceloader_links($type) {
    334                 $rl = t29RessourceLoader::create_from_type($type, $this->conf);
    335                 return $rl->get_urls( isset($_GET['rl_debug']) );
    336         }
     327        function print_ressourceloader_links($type, $template='<!-- RL: %s -->') {
     328                $rl = $this->rl[$type];
     329                $rl_links = $rl->get_urls( isset($_GET['rl_debug']) );
     330                $rl_pagespecific_links = $rl->get_page_specific_urls($this->conf['seiten_id']);
     331
     332                foreach(array($rl_links, $rl_pagespecific_links) as $rls)
     333                        foreach($rls as $link)
     334                                printf($template, $link);
     335        }
     336
    337337
    338338} // class t29Template
Note: See TracChangeset for help on using the changeset viewer.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License