<?php
/**
 * pragmaMx  Content Management System
 * Copyright (c) 2005 pragmaMx Dev Team - http://pragmaMx.org
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * $Source: /home/www/dps3311/home/cvsroot/pragmamx/html/blocks/block-Top10_Downloads.php,v $
 * $Revision: 1.4.4.4 $
 * $Author: tora60 $
 * $Date: 2006/11/18 21:29:31 $
 * 
 * this file based on:
 * php-nuke Web Portal System - http://phpnuke.org/
 * Thatware - http://thatware.org/
 *
 * This file is copy 2007 by Future
 */
if (!defined("mxMainFileLoaded")) die ("You can't access this file directly...");
/**
 * -----------------------------------------------------------------------------
 * Einstellungen fuer den News Block
 */
// die ersten Teile des Artikeltextes anzeigen,
// - 0 fuer nein, oder
// - eine beliebige Zahl, die die Menge der angezeigten Zeichen definiert
// HTML-Tags, ausser <br> werden entfernt und nicht mitgerechnet
$showintro = 0;
// Bilder im Text anzeigen, wenn $showintro angeschaltet ist
$showpics = true;
// Buttonleiste anzeigen
$showbuttons = 1;
// Veroeffentlichungsdatum anzeigen
$showdate = 1;
// Kategorie zusammen mit der Artikelueberschrift anzeigen
$showcattitle = 0;
// Anzahl der Spalten
$showcolumns = 2;
// Anzahl der angezeigten Artikel
// - eine beliebige Zahl, oder
// - die globale Variable $GLOBALS['storyhome']
$storynum = $GLOBALS['storyhome'];
// Links zu Suche etc. anzeigen
$showextendedlinks = 0;
// Blockcache erlauben
$mxblockcache = false;
/**
 * ENDE Einstellungen fuer den News Block 
 * -----------------------------------------------------------------------------
 * Einstellungen fuer den Forum Block
 */
 /// der Modulname (Ordner des Moduls)
$boardname = 'Forum';
/// Anzahl der angezeigten neuesten Threads
$num_threads = 6;
/// Boards die nicht angezeigt werden sollen, als Array
$exclude_boards = null;
/// Thread-Icons in Liste anzeigen
$show_icons   = 1;
/// Anzahl, wie oft gelesen, in Liste anzeigen 
$show_views   = 1;
/// Anzahl der Antworten in Liste anzeigen
$show_replies = 1;
/// Name des Themenstarters in Liste anzeigen
$show_starter = 0;
/// kleine Forumsstatistik anzeigen
$show_stats  = 1;
/// User-Onlinestatistik anzeigen
$show_online = 1;
/// in Onlinestatistik die Buddies extra listen
$show_buddies = 1;
/// Farben des Blocks
global $bgcolor1, $bgcolor2, $bgcolor3, $textcolor1, $textcolor2;
/// Rahmen um die Liste
$color['border']    = $bgcolor2;
/// Hintergrund Überschriften
$color['row1']      = $bgcolor1;
/// Hintergrund normaler Thread
$color['row2']      = $bgcolor3;
/// Textfarbe Überschriften
$color['txtrow1']   = $textcolor1;
/// Textfarbe normaler Thread
$color['txtrow2']   = $textcolor2;
 /**
 * ENDE Einstellungen fuer den Forum Block 
 * -----------------------------------------------------------------------------
 */
global $prefix, $bgcolor1, $bgcolor2, $bgcolor3;

if ($GLOBALS["multilingual"] == 1) {
    if (ereg("german", $GLOBALS["currentlang"])) $thislang = "german";
    else $thislang = $GLOBALS["currentlang"];
    $querylang = "AND (alanguage LIKE '" . $thislang . "%' OR alanguage='')";
} else {
    $querylang = "";
} 

$qry = "SELECT sid, cat.catid, aid, s.title, time, DATE_ADD(time, INTERVAL 2 DAY) AS expire, now() AS jetzt, hometext, bodytext, comments, s.counter, topic, informant, notes, acomm, cat.title AS title1 
        FROM ${prefix}_stories AS s LEFT JOIN ${prefix}_stories_cat AS cat ON s.catid = cat.catid
        WHERE (ihome='0' OR s.catid='0') AND time <= now() $querylang 
        ORDER BY s.time DESC 
        limit 0,$storynum";

$result = sql_query($qry);
if (!$result) {
    return;
} 
// $empty = "<img src=\"images/menu/empty.gif\" border=0 >";
$count = 0;
$out = '';
$width = ceil(100 / $showcolumns);
while ($story = sql_fetch_assoc($result)) {
    // Textlaengen
    // $introcount = strlen(strip_tags($story['hometext']));
    // $fullcount = strlen(strip_tags($story['bodytext']));
    $totalcount = strlen(strip_tags($story['hometext'])) + strlen(strip_tags($story['bodytext']));

    $introtext = '';
    if ($showintro) {
        if ($showpics) {
            // Alle Tags ausser <br> & <img> entfernen
            $introtext = trim(strip_tags($story['hometext'], '<br><img>')); 
            // <br> am Textbeginn entfernen
            $introtext = preg_replace('#^(?:<br\s*/*>\s*)*#is', '', $introtext); 
            // array zuruecksetzen
            $replaces = array();
            $textlentemp = $showintro; 
            // alle Imagetags suchen und zwischenspeichern
            if (preg_match_all('#<img[^>]*>#si', $introtext, $images)) {
                foreach($images[0] as $i => $img) {
                    // einen alternativen String zum Ersetzen erstellen
                    $alternate = md5($img); 
                    // die gewuenschte Textlaenge um die Textlaenge des alternativen String erweitern
                    $textlentemp = $showintro + strlen($alternate); 
                    // den gefundenen Imagetag in das array stellen
                    $replaces[$alternate] = $img; 
                    // den gefundenen Imagetag aus dem Text entfernen und dafuer den alternativen String einsetzen
                    $introtext = trim(str_replace($img, $alternate, $introtext));
                } 
            } 
            // Text auf die gewuenschte Laenge kuerzen
            $introtext = mxCutString($introtext, $textlentemp, "&nbsp;...", " "); 
            // wenn imagetags gefunden wurden, die alternativen Textteile wieder
            // durch die im Array zwischengespeicherten Imagetags ersetzen
            if (count($replaces)) {
                $introtext = str_replace(array_keys($replaces), array_values($replaces), $introtext);
            } 
            // Text auf die gewuenschte Laenge kuerzen
            $introtext = trim(mxCutString($introtext, $showintro, "&nbsp;...", " "));
        } else {
            // Alle Tags ausser <br> entfernen
            $introtext = trim(strip_tags($story['hometext'], '<br>')); 
            // <br> am Textbeginn entfernen
            $introtext = preg_replace('#^(?:<br\s*/*>\s*)*#is', '', $introtext); 
            // Text auf die gewuenschte Laenge kuerzen
            $introtext = trim(mxCutString($introtext, $showintro, "&nbsp;...", " "));
        } 
        if ($introtext) {
            $introtext = '<div class="content">' . $introtext . '</div>';
        } 
    } 
    // das formatierte Datum
    $datetime = '';
    if ($showdate) {
        $datetime = '<td width="96%">' . mx_strftime(_SHORTDATESTRING, mxSqlDate2UnixTime($story['time'])) . '</td>';
    } 
    // die Buttons
    $buttons = array();
    if ($showbuttons) {
        $buttons[] = '<a href="modules.php?name=News&amp;file=print&amp;sid=' . $story['sid'] . '"><img src="images/menu/print.gif" width=12 height=13 border=0 alt="' . _BMXPRINTER . '"  title="' . _BMXPRINTER . '" ></a>';
        if (mxModuleAllowed('Recommend_Us')) {
            $buttons[] = '<a href="modules.php?name=News&amp;file=friend&amp;sid=' . $story['sid'] . '"><img src="images/menu/friend.gif" width=12 height=13 border=0 alt="' . _BMXFRIEND . '" title="' . _BMXFRIEND . '" ></a>';
        } 
        $buttons[] = '<a href="modules.php?name=News&amp;file=article&amp;sid=' . $story['sid'] . '"><img src="images/menu/bytesmore.gif" border=0 width=12 height=13 alt="' . _BMXBYTESMORE . ' ' . $totalcount . '" title="' . _BMXBYTESMORE . ' ' . $totalcount . '" ></a>';
        $buttons[] = '<a href="modules.php?name=News&amp;file=article&amp;sid=' . $story['sid'] . '#comments"><img src="images/menu/comments2.gif" width=12 height=13 border=0  alt="' . _COMMENTS . ' ' . $story['comments'] . '"  title="' . _COMMENTS . ' ' . $story['comments'] . '" ></a>';
        if (mxModuleAllowed('Userinfo')) {
            $buttons[] = '<a href="modules.php?name=Userinfo&amp;uname=' . $story['informant'] . '"><img src="images/menu/informant.gif" width=12 height=13 border=0 alt="' . $story['informant'] . '" title="' . _UNICKNAME . ': ' . $story['informant'] . '" ></a>';
        } 
        $buttons[] = '<img src="images/menu/counter.gif" width=12 height=13 border=0 alt="' . $story['counter'] . ' ' . _READS . '" title="' . $story['counter'] . ' ' . _READS . '" >';
    } 
    $colspan = count($buttons) + 1; 
    // $buttons = '<table border="0" cellspacing="1" cellpadding="1" align="right"><tr><td>'.implode('</td><td>', $button).'</td></tr></table>';
    $buttons = '<td>' . implode('</td><td>', $buttons) . '</td>'; 
    // der Titel des Artikels
    $story['title'] = '<a href="modules.php?name=News&amp;file=article&amp;sid=' . $story['sid'] . '">' . $story['title'] . '</a>'; 
    // den Kategoriename mit anzeigen
    if ($showcattitle && $story['catid']) {
        $story['title'] = $story['title'] . '&nbsp; [<a href="modules.php?name=News&amp;file=categories&amp;op=newindex&catid=' . $story['catid'] . '">' . $story['title1'] . '</a>]';
    } 
	$image = ($story['jetzt'] > $story['expire']) ? 'sign' : 'new';
	//   $out .= '<td colspan="'.$colspan.'"><img src="images/menu/' . $image . '.gif" align="middle" alt=""></td>';
    if ($count == 0) {
        $out .= '<tr valign="top">';
    } 
    $out .= '
    <td width="' . $width . '%" valign="top" style="border: 1px solid ' . $bgcolor2 . ';">
        <table border="0" cellspacing="0" cellpadding="2" width="100%">';
    if ($datetime || $buttons) {
        $out .= '
            <tr valign="top" style="height: 10px;">
                ' . $datetime . $buttons . '
            </tr>
            ';
    } 
    $out .= '
            <tr valign="top" style="height: 35px;">
                <td colspan="' . $colspan . '"><img src="images/menu/' . $image . '.gif" align="middle" alt=""><p><b>' . $story['title'] . '</b></p>' . $introtext . '</td>
            </tr>
        </table>
    </td>
    ';

    $count++;
    if ($count * $width == 100) {
        $out .= '</tr>';
        $count = 0;
    } 
} 
// falls nicht alle Tabellenspalten am Ende gefuellt sind, eine zus. anfuegen
if ($count && $out) {
    $out .= '<td colspan="' . ($showcolumns - $count) . '">&nbsp;</td>';
} 
// die Links zu anderen Modulen
if ($showextendedlinks) {
    if (mxModuleAllowed('Stories_Archive')) {
        $links[] = '<a href="modules.php?name=Stories_Archive">' . _STORIEARCHIVE . '</a>';
    } 
    if (mxModuleAllowed('Submit_News')) {
        $links[] = '<a href="modules.php?name=Submit_News">' . _SUBMITNEWS . '</a>';
    } 
    if (mxModuleAllowed('Search')) {
        $links[] = '<a href="modules.php?name=Search">' . _SEARCH . '</a>';
    } 
    if (isset($links)) {
        $out .= '<tr><td align="center" colspan="' . $showcolumns . '" style="border: 1px solid ' . $bgcolor2 . ';">';
        $out .= '[&nbsp;' . implode('&nbsp;|&nbsp;', $links) . '&nbsp;]';
        $out .= '</td></tr>';
    } 
} 
// content-tabelle, nur wenn ueberhaupt was zum anzeigen da ist...
if ($out) {
    $news_raus = '<table width="100%" border="0" cellspacing="2" cellpadding="5" align="center">' . $out . '</table>';
} 
##################################################################################################################################################
//Forum Start
/// versch. globale Variablen vorher initialisieren, weil in Funktionen aufgerufen
global $db_prefix, $settings, $context, $scripturl, $mxsmf;
/// die SSI-Datei includen
include(dirname(dirname(__FILE__)) . '/modules/'.$boardname.'/mx_SSI.php');
/// Boardstatistik
$boardstats  = ssi_boardStats('array');
$boardstats = '
'. $txt[330]. ': '. $boardstats['topics']. ' |
'. $txt[95]. ': '. $boardstats['posts']. ' |
'. $txt[331]. ': <a href="modules.php?name='. $boardname. '&amp;action=mlist" title="'.$txt['332'].'">'. $boardstats['members']. '</a>
';
/// Wer ist Online?
if ($show_online) {
	$whoonline = ssi_whosOnline('array');
	$whoonline_out = ''. $whoonline['guests']. ' '. (($whoonline['guests'] == 1) ? $txt['guest'] : $txt['guests']). ', '. $whoonline['num_users']. ' '. (($whoonline['num_users'] == 1) ? $txt['user'] : $txt['users']);
	// Hidden users. or buddies?
	if ($whoonline['hidden'] > 0 || $show_buddies)
		$whoonline_out .= ' (' . ($show_buddies ? ($whoonline['buddies'] . ' ' . (($whoonline['buddies'] == 1) ? $txt['buddy'] : $txt['buddies'])) : '') . ($show_buddies && $whoonline['hidden'] ? ', ' : '') . (!$whoonline['hidden'] ? '' : $whoonline['hidden'] . ' ' . $txt['hidden']) . ')';
	if (count($whoonline['users'])) {
		$whoonline_list = '';
		foreach ($whoonline['users'] as $user)
			$whoonline_list .= (($user['hidden']) ? '<i>' . $user['link'] . '</i>' : $user['link']). (($user['is_last']) ? '' : '. ');
	}
	#mxDebugFuncVars($whoonline_out);
}
/// die Threads und Posts 
$posts = ssi_recentTopics(intval($num_threads), $exclude_boards, 'array');
if ($show_starter || $show_replies || $show_views) {
	/// alle Thread-ID's vorher auslesen, für Datenbankbedingung
	foreach ($posts as $post) {
		$topics[$post['topic']] = $post['topic'];
	}
	if (isset($topics)) {
		/// zusätzliche Daten, die nicht von SSI bereitgestellt werden ermitteln
		$qry = "SELECT DISTINCT m.ID_MEMBER, m.posterName, t.numReplies, t.numViews, t.ID_TOPIC
				FROM {$db_prefix}topics AS t
				LEFT JOIN {$db_prefix}messages AS m ON ( m.ID_MSG = t.ID_FIRST_MSG )
				WHERE t.ID_TOPIC IN (".implode(',',$topics).")
				LIMIT ".intval($num_threads)."";
		$result = sql_query($qry);
		/// die zusätzlichen Daten sind dann über den Index des Arrays ansprechbar, dieser index entspricht der Thread-ID
		while ($row = sql_fetch_assoc($result)) {
			$row['link'] = (empty($row['ID_MEMBER'])) ? $row['posterName'] : '<a href="modules.php?name='. $boardname. '&amp;action=profile;u=' . $row['ID_MEMBER'] . '" title="'. $txt[92]. ' ' . $row['posterName'] . '">' . $row['posterName'] . '</a>';
			$posts_more[$row['ID_TOPIC']] = $row;
		}
	}
}
#mxDebugFuncVars($topics, $posts_more);
/// Der Tabellenkopf für die Threads und Posts 
$show = '<table width="100%" border="0" cellspacing="1" cellpadding="2" style="background: '.$color['border'].';">
<tr style="background: '.$color['row1'].'; color: '.$color['txtrow1'].';">';
$show .= '<th colspan="'.(($show_icons) ? 2 : 1).'">'.$txt['319'].'</th>';		# Thema
if ($show_starter)
	$show .= '<th>'.$txt['109'].'</th>';		# Themenstarter
if ($show_replies)
	$show .= '<th>'.$txt['110'].'</th>';		# Antworten
if ($show_views)
	$show .= '<th>'.$txt['301'].'</th>';		# Aufrufe
$show .= '<th>'.$txt['111'].'</th>';			# Letzter Beitrag
$show .= '
</tr>
';
/// die Hauptliste der einzelnen Threads
foreach ($posts as $post) {
	#mxDebugFuncVars($post);
	$new = (!$post['new']) ? ' <a href="modules.php?name='. $boardname. '&amp;topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" align="right"></a> ': '';
	$show .= '<tr style="background: '.$color['row2'].'; color: '.$color['txtrow2'].';">';
	if ($show_icons)
		$show .= '<td width="1%" align="center" style="background: '.$color['row1'].';">'.$post['icon'].'</td>';
	$show .= '<td>'.$new.'<a href="'. $post['href']. '">'. $post['subject']. '</a><br /><em>'. $txt['smf88']. ' '. $post['board']['link']. '</em></td>';
	if ($show_starter)
		$show .= '<td width="1%" style="white-space: nowrap;">'.((isset($posts_more[$post['topic']]['link'])) ? $posts_more[$post['topic']]['link'] : '').'</td>';
	if ($show_replies)
		$show .= '<td width="1%" align="center">'.((isset($posts_more[$post['topic']]['numReplies'])) ? $posts_more[$post['topic']]['numReplies'] : 0).'</td>';
	if ($show_views)
		$show .= '<td width="1%" align="center">'.((isset($posts_more[$post['topic']]['numViews'])) ? $posts_more[$post['topic']]['numViews'] : 0).'</td>';
	$show .= '<td>'. $post['time']. '<br />'. $txt[525]. ' '. $post['poster']['link']. '</td>';
	$show .= '</tr>';
}
/// Boardstatistik anzeigen
if ($show_stats)
	$show .= '
		<tr style="background: '.$color['row1'].'; color: '.$color['txtrow1'].';">
		<td colspan="6" align="center"><div class="content">'.$boardstats.'</div></td>
		</tr>';
/// Wer ist Online anzeigen
if ($show_online)
	$show .= '
		<tr style="background: '.$color['row2'].'; color: '.$color['txtrow2'].';">
		<td colspan="6" align="center"><div class="content">'.$txt['who_title'].':&nbsp;&nbsp;'.$whoonline_out.'</div></td>
		</tr>';
/// Wer ist Online anzeigen, die Liste der einzelnen User
if ($show_online && !empty($whoonline_list))
	$show .= '
		<tr style="background: '.$color['row1'].'; color: '.$color['txtrow1'].';">
		<td colspan="6"><div class="content">'.$whoonline_list.'</div></td>
		</tr>';
/// Der Tabellenfuss für die Threads und Posts 
$show .= '</table>';
/// Den Output für pragmaMx aufbereiten (links usw. anpassen)
$smf_raus = mxSmfPrepareOutput($show);
//Forum ende
#########################################################################################################################################
?>
<link rel="stylesheet" type="text/css" href="includes/ajax_tabs/ajax_smf_news.css" />
<script type="text/javascript" src="includes/ajax_tabs/ajax_smf_news.js">
/***********************************************
* Tab Content script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
/***********************************************
* Vielen Dank an Dynamicdrive.com für dieses   
* tolle Script
***********************************************/
</script>
<!-- Die Links für die Tabs -->
<ul id="maintab" class="shadetabs">
<li class="selected"><a href="#" rel="tcontent1">News</a></li>
<li><a href="#" rel="tcontent2">Forum</a></li>
</ul>
<!-- Die Container für die Ausgaben -->
<div class="tabcontentstyle">
	<!-- Aufrufen des Containers für die News -->
	<div id="tcontent1" class="tabcontent">
	<?php echo "$news_raus"; // Ausgabe der News ?>
	</div>
	<!-- Aufrufen des Containers für das Forum -->
	<div id="tcontent2" class="tabcontent">
	<?php echo "$smf_raus"; // Ausgabe des SMF Forums ?>
	</div>
</div>
<!-- Alles an das Script übergeben -->
<script type="text/javascript"> initializetabcontent("maintab") </script>