Changeset 56

Show
Ignore:
Timestamp:
10/07/07 17:42:00 (6 years ago)
Author:
d0nut
Message:

released wcf::sitemaps 1.2. splittet wcf::sitemaps and wbb::sitemaps.
added sitemaps for tagging

Files:
25 added
1 removed
2 modified

Legend:

Unmodified
Added
Removed
  • sitemaps/files/lib/page/SitemapsPage.class.php

    r41 r56  
    22// wcf imports 
    33require_once(WCF_DIR.'lib/page/AbstractPage.class.php'); 
    4 require_once(WBB_DIR.'lib/data/board/SitemapsBoard.class.php'); 
    5 require_once(WBB_DIR.'lib/data/thread/SitemapsThread.class.php'); 
    64 
    75/** 
     
    97 * 
    108 * @author      Torben Brodt 
    11  * @package     de.easy-coding.wbb.data.page.sitemaps 
     9 * @package     de.easy-coding.wcf.sitemaps 
    1210 * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> 
    1311 */ 
    1412class SitemapsPage extends AbstractPage { 
    15         protected $index = true; 
    16         protected $rewriter = null; 
    17         protected $boardIDs = array(); 
    18         protected $offset = 0; 
    19         protected $limit = 0; 
    20         protected $boards = array(), $threads = array(); 
    21         protected $thread_posts_per_page=0; 
    22         protected $board_threads_per_page=0; 
     13        protected $type; 
    2314 
    24         /** 
    25          * @see Page::readParameters() 
    26          */ 
    27         public function readParameters() { 
    28                 parent::readParameters(); 
     15        public $index = false; 
     16        public $rewriter; 
     17 
     18        /** 
     19         * @see Page::readParameters() 
     20         */ 
     21        public function readParameters() { 
     22                parent::readParameters(); 
     23                 
     24                if (intval(count($_GET)) == intval(1)) { 
     25                        $this->index = true; 
     26                } 
    2927 
    3028                // SEO MOD 
     
    3331                        $this->rewriter = new PublicSEORewriter(); 
    3432                } 
     33        } 
     34         
     35        /** 
     36         * 
     37         * @param type 
     38         */ 
     39        public function setType($type) { 
     40                $this->type = $type; 
     41        } 
     42         
     43        /** 
     44         * @see Page::assignVariables() 
     45         */ 
     46        public function readData() { 
     47                parent::readData(); 
     48                 
     49                // send header 
     50                @header('Content-Type: application/xml; charset='.CHARSET); 
     51                echo '<?xml version="1.0" encoding="'.CHARSET.'"?>'; 
     52                 
     53                switch($this->type) { 
     54                        case 'sitemapindex': 
     55                                echo '<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">'; 
     56                                break; 
     57                        case 'urlset': 
     58                                echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" 
     59                                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     60                                        xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 
     61                                        http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">'; 
     62                                break; 
     63                } 
     64        } 
     65         
     66        /** 
     67         * @see Page::show() 
     68         */ 
     69        public function show() { 
     70                parent::show(); 
    3571 
    36                 if (isset($_REQUEST['boardID']) && $_REQUEST['boardID'] == 0) { 
    37                         $this->index = false; 
    38  
    39                 } else if(isset($_REQUEST['boardID'])) { 
    40                         $this->boardIDs = ArrayUtil::toIntegerArray(explode(',', $_REQUEST['boardID'])); 
    41                 } 
    42         } 
    43          
    44         /** 
    45          * how many posts in one thread 
    46          */ 
    47         protected function threadPostsPerPage() { 
    48                 if($this->thread_posts_per_page > 0) 
    49                         return $this->thread_posts_per_page; 
    50                  
    51                 $sql =  "SELECT         opt.optionValue 
    52                         FROM            wcf".WCF_N."_option opt 
    53                         WHERE           opt.optionName = 'thread_posts_per_page' 
    54                                         LIMIT 1;"; 
    55                 $result = WCF::getDB()->sendQuery($sql); 
    56                 $row = WCF::getDB()->fetchArray($result); 
    57                 $this->thread_posts_per_page = $row['optionValue']; 
    58         } 
    59          
    60         /** 
    61          * how many threads in one forum 
    62          */ 
    63         protected function boardThreadsPerPage() { 
    64                 if($this->board_threads_per_page > 0) 
    65                         return $this->board_threads_per_page; 
    66                  
    67                 $sql =  "SELECT         opt.optionValue 
    68                         FROM            wcf".WCF_N."_option opt 
    69                         WHERE           opt.optionName = 'board_threads_per_page' 
    70                                         LIMIT 1;"; 
    71                 $result = WCF::getDB()->sendQuery($sql); 
    72                 $row = WCF::getDB()->fetchArray($result); 
    73                 $this->board_threads_per_page = $row['optionValue']; 
    74         } 
    75  
    76         /** 
    77          * Gets the threads for the sitemaps. 
    78          */ 
    79         protected function readThreads() { 
    80                 require_once(WBB_DIR.'lib/data/thread/FeedThread.class.php'); 
    81                 // accessible boards 
    82                 require_once(WBB_DIR.'lib/data/board/Board.class.php'); 
    83                 $boardIDs = Board::getAccessibleBoards(array('canViewBoard', 'canEnterBoard', 'canReadThread')); 
    84  
    85                 // get threads 
    86                 if (!empty($boardIDs)) { 
    87                  
    88                         // read count 
    89                         $this->threadPostsPerPage(); 
    90                          
    91                         $sql = "SELECT          post.*, thread.* 
    92                                 FROM            wbb".WBB_N."_thread thread 
    93                                 LEFT            JOIN       wbb".WBB_N."_post post 
    94                                 ON              (post.postID = thread.firstPostID) 
    95                                 WHERE           thread.boardID IN (".$boardIDs.") 
    96                                                 ".(count($this->boardIDs) ? "AND thread.boardID IN (".implode(',', $this->boardIDs).")" : "")." 
    97                                                 AND thread.isDeleted = 0 
    98                                                 AND thread.isDisabled = 0 
    99                                                 AND thread.movedThreadID = 0 
    100                                 ORDER BY        thread.time DESC"; 
    101                         if($this->limit > 0) { 
    102                                $sql .= "        LIMIT      ".$this->limit; 
    103                         } 
    104                         if($this->offset > 0) { 
    105                                $sql .= "        OFFSET      ".$this->offset; 
    106                         } 
    107  
    108                         $i=0; 
    109                         $result = WCF::getDB()->sendQuery($sql); 
    110                         while ($row = WCF::getDB()->fetchArray($result)) { 
    111                                 $pages = ceil($row['replies']/$this->thread_posts_per_page); 
    112                                 $this->threads[$i] = new FeedThread($row); 
    113  
    114                                 if($this->rewriter === null) { 
    115                                         $this->threads[$i]->url = sprintf('index.php?page=Thread&amp;threadID=%d', $row['threadID']); 
    116                                 } else { 
    117                                         $this->rewriter->publicCacheThreads($row['threadID'], $row); 
    118                                         $this->threads[$i]->url = $this->rewriter->publicParseThreadURLs($row['threadID'], ''); 
    119                                 } 
    120  
    121                                 for($j=2; $j<$pages; $j++) { 
    122                                         $i++; 
    123                                         $this->threads[$i] = new FeedThread($row['threadID'], $row); 
    124  
    125                                         if($this->rewriter === null) { 
    126                                                 $this->threads[$i]->url = sprintf('index.php?page=Thread&amp;threadID=%d&amp;pageNo=%d', $row['threadID'], $j); 
    127                                         } else { 
    128                                                 $this->threads[$i]->url = $this->rewriter->publicParseMultipleThreadURLs($row['threadID'], $j, ''); 
    129                                         } 
    130                                 } 
    131                                 $i++; 
    132                                  
    133                                 // titles are not used again.. clear cache 
    134                                 if($this->rewriter !== null) $this->rewriter->clearCache(); 
    135                         } 
    136                 } 
    137         } 
    138  
    139         /** 
    140          * Gets the boards for the sitemaps overview and for the numbered board pages. 
    141          */ 
    142         protected function readBoards() { 
    143                 // accessible boards 
    144                 require_once(WBB_DIR.'lib/data/board/Board.class.php'); 
    145                 $boardIDs = Board::getAccessibleBoards(array('canViewBoard', 'canEnterBoard', 'canReadThread')); 
    146                  
    147                 // get threads 
    148                 if (!empty($boardIDs)) { 
    149                          
    150                         // read count 
    151                         $this->boardThreadsPerPage(); 
    152  
    153                         $sql = "SELECT          board.* 
    154                                 FROM            wbb".WBB_N."_board board 
    155                                 WHERE           board.threads > 0 
    156                                                 AND board.boardID IN (".$boardIDs.") 
    157                                                 ".(count($this->boardIDs) ? "AND board.boardID IN (".implode(',', $this->boardIDs).")" : "")." 
    158                                 ORDER BY        board.time DESC"; 
    159                         if($this->limit > 0) { 
    160                                $sql .= "        LIMIT      ".$this->limit; 
    161                         } 
    162                         if($this->offset > 0) { 
    163                                $sql .= "        OFFSET      ".$this->offset; 
    164                         } 
    165  
    166                         $i=0; 
    167                         $result = WCF::getDB()->sendQuery($sql); 
    168                         while ($row = WCF::getDB()->fetchArray($result)) { 
    169                                 $pages = ceil($row['threads']/$this->board_threads_per_page); 
    170                                 $this->boards[$i] = new SitemapsBoard($row['boardID'], $row); 
    171                                 $this->boards[$i]->full = true; 
    172                                 if(intval($this->boards[$i]->getThreads()) == 0) { 
    173                                         continue; 
    174                                 } 
    175  
    176                                 if($this->rewriter === null) { 
    177                                         $this->boards[$i]->url = sprintf('index.php?page=Board&amp;boardID=%d', $row['boardID']); 
    178                                 } else { 
    179                                         $this->boards[$i]->url = $this->rewriter->publicParseBoardURLs($row['boardID'], ''); 
    180                                 } 
    181  
    182                                 for($j=2; $j<$pages; $j++) { 
    183                                         $i++; 
    184                                         $this->boards[$i] = new Board($row['boardID'], $row); 
    185  
    186                                         if($this->rewriter === null) { 
    187                                                 $this->boards[$i]->url = sprintf('index.php?page=Board&amp;boardID=%d&amp;pageNo=%d', $row['boardID'], $j); 
    188                                         } else { 
    189                                                 $this->boards[$i]->url = $this->rewriter->publicParseMultipleBoardURLs($row['boardID'], $j, ''); 
    190                                         } 
    191                                 } 
    192  
    193                                 $i++; 
    194  
    195                                  
    196                                 // titles are not used again.. clear cache 
    197                                 if($this->rewriter !== null) $this->rewriter->clearCache(); 
    198                         } 
    199                 } 
    200         } 
    201  
    202         /** 
    203          * @see Page::readData() 
    204          */ 
    205         public function readData() { 
    206                 parent::readData(); 
    207  
    208                 // get threads 
    209                 if (count($this->boardIDs)) { 
    210                         $this->readThreads(); 
    211                 } 
    212                 // get board sitemaps/numbers 
    213                 else { 
    214                         $this->readBoards(); 
    215                 } 
    216         } 
    217  
    218         /** 
    219          * @see Page::show() 
    220          */ 
    221         public function show() { 
    222                 parent::show(); 
    223  
    224                 // send header 
    225                 @header('Content-Type: application/xml; charset='.CHARSET); 
    226                 echo '<?xml version="1.0" encoding="'.CHARSET.'"?>'; 
    227  
    228                 // send thread content 
    229                 if (count($this->boardIDs)) { 
    230                         $tpl = '<url><loc>'.PAGE_URL.'/%s</loc><lastmod>%s</lastmod></url>'; 
    231                         echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" 
    232                                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    233                                 xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 
    234                                 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">'; 
    235                         foreach($this->threads as $thread) { 
    236                                 printf($tpl, $thread->url, date('c', $thread->time)); 
    237                         } 
    238                         echo '</urlset>'; 
    239                 } 
    240                 // send overview content (sitemapindex) 
    241                 else if($this->index) { 
    242                         $tpl = '<sitemap><loc>'.PAGE_URL.'/index.php?page=Sitemaps&amp;boardID=%d</loc><lastmod>%s</lastmod></sitemap>'; 
    243                         echo '<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">'; 
    244                         printf($tpl, 0, date('c')); 
    245                         $boards = array_filter($this->boards, create_function('$a','return isset($a->full);')); 
    246                         foreach($boards as $board) { 
    247                                 printf($tpl, $board->boardID, date('c', $board->time)); 
    248                         } 
    249                         echo '</sitemapindex>'; 
    250                 } 
    251                 // send board contents 
    252                 else { 
    253                         $tpl = '<url><loc>'.PAGE_URL.'/%s</loc><lastmod>%s</lastmod></url>'; 
    254                         echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" 
    255                                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    256                                 xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 
    257                                 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">'; 
    258                         foreach($this->boards as $board) { 
    259                                 printf($tpl, $board->url, date('c', $board->time)); 
    260                         } 
    261                         echo '</urlset>'; 
    262                 } 
    263                  
    264                 exit; 
    265         } 
     72                switch($this->type) { 
     73                        case 'sitemapindex': 
     74                                echo '</sitemapindex>'; 
     75                                break; 
     76                        case 'urlset': 
     77                                echo '</urlset>'; 
     78                                break; 
     79                } 
     80        } 
    26681} 
    26782?> 
  • sitemaps/package.xml

    r41 r56  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<!DOCTYPE package SYSTEM "http://www.woltlab.com/DTDs/package.dtd"> 
    3 <package name="de.easy-coding.wcf.data.page.sitemaps"> 
    4         <packageInformation> 
    5                 <packageName>Sitemaps</packageName> 
    6                 <packageDescription><![CDATA[Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling.]]></packageDescription> 
    7                 <packageDescription languagecode="de"><![CDATA[Sitemaps stellen eine einfache Möglichkeit fÃŒr Webmaster dar, Suchmaschinen Seiten auf Ihren Websites zu melden, die zum Durchsuchen verfÃŒgbar sind.]]></packageDescription> 
    8                 <version>1.1.5</version> 
     3<package name="de.easy-coding.wcf.sitemaps"> 
     4        <packageinformation> 
     5                <packagename>Sitemaps</packagename> 
     6                <packagedescription><![CDATA[Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling.]]></packagedescription> 
     7                <packagedescription languagecode="de"><![CDATA[Sitemaps stellen eine einfache Möglichkeit fÃŒr Webmaster dar, Suchmaschinen Seiten auf Ihren Websites zu melden, die zum Durchsuchen verfÃŒgbar sind.]]></packagedescription> 
     8                <version>1.2.0</version> 
    99                <date>DATE</date> 
    10                 <plugin>com.woltlab.wbb</plugin> 
    11         </packageInformation> 
     10                <plugin>com.woltlab.wcf</plugin> 
     11        </packageinformation> 
    1212 
    13         <authorInformation> 
     13        <authorinformation> 
    1414                <author>Torben Brodt</author> 
    1515                <authorURL>http://www.easy-coding.de/trac/wcf</authorURL> 
    16         </authorInformation> 
     16        </authorinformation> 
    1717 
    1818        <requiredpackages> 
    19                 <requiredpackage minversion="3.0.0">com.woltlab.wbb</requiredpackage> 
    2019                <requiredpackage minversion="1.0.0">com.woltlab.wcf</requiredpackage> 
    2120        </requiredpackages> 
    2221         
    2322        <optionalpackages> 
     23                <optionalpackage file="optionals/de.easy-coding.wbb.sitemaps.tar.gz" minversion="1.0.0">de.easy-coding.wbb.sitemaps</optionalpackage> 
    2424                <optionalpackage file="optionals/de.easy-coding.wcf.data.page.publicseorewriter.tar.gz" minversion="1.0.1">de.easy-coding.wcf.data.page.publicseorewriter</optionalpackage> 
    2525        </optionalpackages> 
     
    3232        </instructions> 
    3333         
     34        <instructions type="update" fromversion="1.1.5"> 
     35                <files>files.tar</files> 
     36        </instructions> 
     37         
    3438        <instructions type="update" fromversion="1.1.4"> 
    35                 <templates>files.tar</templates> 
     39                <files>files.tar</files> 
    3640        </instructions> 
    3741         
    3842        <instructions type="update" fromversion="1.1.3"> 
    39                 <templates>files.tar</templates> 
     43                <files>files.tar</files> 
    4044        </instructions> 
    4145         
    4246        <instructions type="update" fromversion="1.1.2"> 
    43                 <templates>files.tar</templates> 
     47                <files>files.tar</files> 
    4448        </instructions> 
    4549         
    4650        <instructions type="update" fromversion="1.1.1"> 
    47                 <templates>files.tar</templates> 
     51                <files>files.tar</files> 
    4852        </instructions> 
    4953         
    5054        <instructions type="update" fromversion="1.1.0"> 
     55                <files>files.tar</files> 
     56        </instructions> 
     57         
     58        <instructions type="update" fromversion="1.0.2"> 
     59                <files>files.tar</files> 
    5160                <templates>templates.tar</templates> 
    5261        </instructions> 
    5362         
    54         <instructions type="update" fromversion="1.0.2"> 
     63        <instructions type="update" fromversion="1.0.1"> 
     64                <files>files.tar</files> 
    5565                <templates>templates.tar</templates> 
    56                 <files>files.tar</files> 
    57         </instructions> 
    58          
    59         <instructions type="update" fromversion="1.0.1"> 
    60                 <templates>templates.tar</templates> 
    61                 <files>files.tar</files> 
    6266        </instructions> 
    6367         
    6468        <instructions type="update" fromversion="1.0.0"> 
     69                <files>files.tar</files> 
    6570                <templates>templates.tar</templates> 
    6671        </instructions>