Browse Source

Initial commit.

Nathaniel van Diepen 9 years ago
parent
commit
fa4e79aa89
6 changed files with 215 additions and 0 deletions
  1. 1 0
      README.md
  2. 21 0
      src/info.xml
  3. 14 0
      src/languages/english-utf8.php
  4. 14 0
      src/languages/english.php
  5. 21 0
      src/source/dp_news.css
  6. 144 0
      src/source/script.php

+ 1 - 0
README.md

@@ -0,0 +1 @@
+Modified version of dreamportal's [http://dream-portal.net/index.php?topic=835.0](Site News) module used on the Omnimaga.org portal page.

+ 21 - 0
src/info.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module>
+	<name>news</name>
+	<version>1.0</version>
+	<icon>cog.png</icon>
+	<file path="source/script.php">
+		<function><main>module_news</main></function>
+		<function>dp_boardNews</function>
+	</file>
+	<file path="source/dp_news.css" type="header" />
+	<target>_blank</target>
+	<url></url>
+	<languages>
+		<english>
+			<main>languages/english.php</main>
+			<utf8>languages/english-utf8.php</utf8>
+		</english>
+	</languages>
+	<param name="board" type="list_boards">1</param>
+	<param name="limit" type="int">5</param>
+</module>

+ 14 - 0
src/languages/english-utf8.php

@@ -0,0 +1,14 @@
+<?php
+
+// Administration Strings
+$txt['dpmod_news'] = 'Site News';
+$txt['dpmodinfo_news'] = 'Grabs Topics from any board you specify in your forum and displays them as News.';
+$txt['dpmoddesc_news'] = 'Allows you to broadcast topics of importance within a module.[hr][size=8pt][color=darkgreen][tt]Created by:  The Dream Portal Team[/tt][/color][/size]';
+
+$txt['dpmod_news_board'] = 'Select Board';
+$txt['dpmod_news_limit'] = 'Limit<div class="smalltext">0 = default value</div>';
+
+$helptxt['dpmod_news_board'] = 'Select the board you\'d like to display topics from within this module for displaying News.';
+$helptxt['dpmod_news_limit'] = 'Limit the amount of recent topics shown for News.';
+
+?>

+ 14 - 0
src/languages/english.php

@@ -0,0 +1,14 @@
+<?php
+
+// Administration Strings
+$txt['dpmod_news'] = 'Site News';
+$txt['dpmodinfo_news'] = 'Grabs Topics from any board you specify in your forum and displays them as News.';
+$txt['dpmoddesc_news'] = 'Allows you to broadcast topics of importance within a module.[hr][size=8pt][color=darkgreen][tt]Created by:  The Dream Portal Team[/tt][/color][/size]';
+
+$txt['dpmod_news_board'] = 'Select Board';
+$txt['dpmod_news_limit'] = 'Limit<div class="smalltext">0 = default value</div>';
+
+$helptxt['dpmod_news_board'] = 'Select the board you\'d like to display topics from within this module for displaying News.';
+$helptxt['dpmod_news_limit'] = 'Limit the amount of recent topics shown for News.';
+
+?>

+ 21 - 0
src/source/dp_news.css

@@ -0,0 +1,21 @@
+/*
+	(c) Site News Module 2011 Dream Portal Team
+*/
+
+.dp_news .dp_dashed
+{
+	margin: 0.5em 0;
+}
+
+.dp_news img
+{
+	float: left;
+	padding-right: 8px;
+}
+
+.dp_news_avatar
+{
+	width: 45px;
+	height: 45px;
+}
+

+ 144 - 0
src/source/script.php

@@ -0,0 +1,144 @@
+<?php
+
+if (!defined('DP'))
+	die('Hacking Attempt...');
+
+/*
+	(c) Site News 1.0 2011 Dream Portal Team
+*/
+
+function module_news($params)
+{
+	global $context, $txt, $settings, $modSettings;
+
+	// Grab the parameters, if they exist.
+	if (is_array($params))
+	{
+		$board = empty($params['board']) ? 1 : $params['board'];
+		$limit = empty($params['limit']) ? 5 : $params['limit'];
+
+		// Store the board news
+		$input = dp_boardNews($board, $limit);
+
+		// Default - Any content?
+		if (empty($input))
+		{
+			module_error('empty');
+			return;
+		}
+		foreach ($input as $news)
+		{
+			echo '
+									<div class="dp_news">
+										<img src="', $settings['images_url'], '/on.png" alt="" />
+										<p>
+											<a href="', $news['href'], '"><strong>', $news['subject'], '</strong></a> ', $txt['by'], ' ', (!empty($modSettings['dp_color_members']) ? $news['color_poster'] : $news['poster']), '<br />
+											<span class="smalltext">', $news['time'], '</span>
+										</p>';
+			echo parse_bbc($news['body']);
+
+			if(!$news['is_last']){
+				echo '
+										<div class="dp_dashed clear"><!-- // --></div>';
+			}else{
+				echo '
+										<div class="clear"><!-- // --></div>';
+			}
+			echo '
+									</div>';
+
+		}
+	}
+	// Throw an error.
+	else
+		module_error();
+}
+
+
+function dp_boardNews($board, $limit)
+{
+	global $scripturl, $smcFunc, $modSettings;
+
+	if (!loadLanguage('Stats'))
+		loadLanguage('Stats');
+
+	$request = $smcFunc['db_query']('', '
+		SELECT b.id_board
+		FROM {db_prefix}boards AS b
+		WHERE b.id_board = {int:current_board}
+			AND {query_see_board}
+		LIMIT 1',
+		array(
+			'current_board' => $board,
+		)
+	);
+
+	if ($smcFunc['db_num_rows']($request) == 0)
+		return array();
+
+	list ($board) = $smcFunc['db_fetch_row']($request);
+	$smcFunc['db_free_result']($request);
+
+	$request = $smcFunc['db_query']('', '
+		SELECT id_first_msg
+		FROM {db_prefix}topics
+		WHERE id_board = {int:current_board}' . ($modSettings['postmod_active'] ? '
+			AND approved = {int:is_approved}' : '') . '
+		ORDER BY id_first_msg DESC
+		LIMIT ' . $limit,
+		array(
+			'current_board' => $board,
+			'is_approved' => 1,
+		)
+	);
+
+	$posts = array();
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+		$posts[] = $row['id_first_msg'];
+	$smcFunc['db_free_result']($request);
+
+	if (empty($posts))
+		return array();
+
+	$request = $smcFunc['db_query']('', '
+		SELECT
+			m.body,m.subject, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
+			t.id_topic, m.id_member, mg.online_color
+		FROM {db_prefix}topics AS t
+			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
+			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
+			LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
+		WHERE t.id_first_msg IN ({array_int:post_list})
+		ORDER BY t.id_first_msg DESC
+		LIMIT ' . count($posts),
+		array(
+			'post_list' => $posts,
+		)
+	);
+
+	$return = array();
+
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+	{
+		$return[] = array(
+			'body'=>$row['body'],
+			'subject' => $row['subject'],
+			'time' => timeformat($row['poster_time']),
+			'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
+			'poster' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'],
+			'color_poster' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '"><span style="color: ' . $row['online_color'] . ';">' . $row['poster_name'] . '</span></a>' : $row['poster_name'],
+			'is_last' => false
+		);
+	}
+
+	$smcFunc['db_free_result']($request);
+
+	if(empty($return)){
+		return $return;
+	}
+	$return[count($return) - 1]['is_last'] = true;
+	return $return;
+}
+
+
+?>