plugins/SpecialPageFuncs.php
changeset 117 7cfdbb2fd17a
parent 116 77c75179bb95
child 129 0b5244001799
equal deleted inserted replaced
116:77c75179bb95 117:7cfdbb2fd17a
   204 {
   204 {
   205   global $db, $session, $paths, $template, $plugins; // Common objects
   205   global $db, $session, $paths, $template, $plugins; // Common objects
   206   static $rowtracker = 0;
   206   static $rowtracker = 0;
   207   static $tdclass = 'row2';
   207   static $tdclass = 'row2';
   208   static $per_row = 2;
   208   static $per_row = 2;
       
   209   static $first = true;
   209   $return = '';
   210   $return = '';
   210   if ( $crap === false && $row === false )
   211   if ( $id === false && $row === false )
   211   {
   212   {
   212     $rowtracker = 0;
   213     $rowtracker = 0;
       
   214     $first = true;
   213     return false;
   215     return false;
   214   }
   216   }
   215   $rowtracker++;
   217   $rowtracker++;
   216   if ( $rowtracker == $per_row )
   218   if ( $rowtracker == $per_row || $first )
   217   {
   219   {
   218     $rowtracker = 0;
   220     $rowtracker = 0;
   219     $tdclass = ( $tdclass == 'row2' ) ? 'row1' : 'row2';
   221     $tdclass = ( $tdclass == 'row2' ) ? 'row1' : 'row2';
   220   }
   222   }
       
   223   if ( $rowtracker == 0 && !$first )
       
   224     $return .= "</tr>\n<tr>";
       
   225   
       
   226   $first = false;
   221   
   227   
   222   preg_match('/^ns=(' . implode('|', array_keys($paths->nslist)) . ');pid=(.*?)$/i', $id, $match);
   228   preg_match('/^ns=(' . implode('|', array_keys($paths->nslist)) . ');pid=(.*?)$/i', $id, $match);
   223   $namespace =& $match[1];
   229   $namespace =& $match[1];
   224   $page_id   =& $match[2];
   230   $page_id   =& $match[2];
   225   $page_id   = sanitize_page_id($page_id);
   231   $page_id   = sanitize_page_id($page_id);
   229   
   235   
   230   $link = '<a href="' . $url . '">' . htmlspecialchars($row['name']) . '</a>';
   236   $link = '<a href="' . $url . '">' . htmlspecialchars($row['name']) . '</a>';
   231   $td = '<td class="' . $tdclass . '" style="width: 50%;">' . $link . '</td>';
   237   $td = '<td class="' . $tdclass . '" style="width: 50%;">' . $link . '</td>';
   232   
   238   
   233   $return .= $td;
   239   $return .= $td;
   234   
       
   235   if ( $rowtracker == ($per_row - 1) )
       
   236     $return .= "</tr>\n<tr>";
       
   237   
   240   
   238   return $return;
   241   return $return;
   239 }
   242 }
   240 
   243 
   241 function page_Special_AllPages() 
   244 function page_Special_AllPages() 
   249   $q = $db->sql_query('SELECT COUNT(urlname) FROM '.table_prefix.'pages WHERE visible!=0;');
   252   $q = $db->sql_query('SELECT COUNT(urlname) FROM '.table_prefix.'pages WHERE visible!=0;');
   250   if ( !$q )
   253   if ( !$q )
   251     $db->_die();
   254     $db->_die();
   252   $row = $db->fetchrow_num();
   255   $row = $db->fetchrow_num();
   253   $count = $row[0];
   256   $count = $row[0];
       
   257   
       
   258   switch($count % 4)
       
   259   {
       
   260     case 0:
       
   261     case 2:
       
   262       // even number of results; do nothing
       
   263       $last_cell = '';
       
   264       break;
       
   265     case 1:
       
   266       // odd number of results and odd number of rows, use row1
       
   267       $last_cell = '<td class="row1"></td>';
       
   268       break;
       
   269     case 3:
       
   270       // odd number of results and even number of rows, use row2
       
   271       $last_cell = '<td class="row2"></td>';
       
   272       break;
       
   273   }
       
   274   
   254   $db->free_result();
   275   $db->free_result();
   255   
   276   
   256   $q = $db->sql_unbuffered_query('SELECT CONCAT("ns=",namespace,";pid=",urlname) AS identifier, name FROM '.table_prefix.'pages WHERE visible!=0 ORDER BY name ASC;');
   277   $q = $db->sql_unbuffered_query('SELECT CONCAT("ns=",namespace,";pid=",urlname) AS identifier, name FROM '.table_prefix.'pages WHERE visible!=0 ORDER BY name ASC;');
   257   if ( !$q )
   278   if ( !$q )
   258     $db->_die();
   279     $db->_die();
   271       40,                  // results per page
   292       40,                  // results per page
   272       array( 'identifier' => 'PagelistingFormatter' ), // hooks
   293       array( 'identifier' => 'PagelistingFormatter' ), // hooks
   273       '<div class="tblholder">
   294       '<div class="tblholder">
   274          <table border="0" cellspacing="1" cellpadding="4">
   295          <table border="0" cellspacing="1" cellpadding="4">
   275            <tr>',          // print at start
   296            <tr>',          // print at start
   276       '    </tr>
   297       '    ' . $last_cell . '</tr>
   277          </table>
   298          </table>
   278        </div>'             // print at end
   299        </div>'             // print at end
   279        );
   300        );
   280   
   301   
   281   echo $result;
   302   echo $result;