phpBB.com     phpBB Academy     phpBB Modders     phpBB Weekly     ktuk     phpBB Hacks     Vlad Studio  

[FUNCTION] get_announcements

Pull latest X topic titles from a certain forum and diplay them on any page.

Not enough for a full proper MOD, but too useful not to share
Forum rules
Please read over our forum guidelines

[FUNCTION] get_announcements

Postby Lunatic Zorr » 29 Sep 2008, 20:50

Hi :)

I just got another idea....

This time, it is also about including the news/announcements form various forums, but not all together...

It would be possible to use Tabs, right?

I mean, create with html/javasript a tabbed template... something like:

Code: Select all
echo "<table cellSpacing='1' cellPadding='1' width='100%' border='0' class='tbl-border'><tr>

<td align='center' width='33%' class='tbl2'>
<span id='welcome' onclick=\"return SetBoxText('welcome');\"><a href=\"javascript:show_hide()\"><b>".$locale['AWP018']."</b></a></span></td>

<td align='center' width='33%' class='tbl2'>
<span id='informations' onclick=\"return SetBoxText('informations');\"><a href=\"javascript:show_hide()\"><b>".$locale['AWP019']."</b></a></span></td>

<td align='center' width='33%' class='tbl2'>
<span id='copyrights' onclick=\"return SetBoxText('copyrights');\"><a href=\"javascript:show_hide()\"><b>".$locale['AWP020']."</b></a></span></td>

</tr><tr><td colspan='3' class='tbl1'><div id='box_text' style='overflow: auto; padding: 0px'>&nbsp;</div>";


(Code extracted from a PHP-Fusion panel, witch I was using before, code is not complete)

So when you open your page, the first tab is open (for example, Anime), and shows latest news from Anime forum. If you click on tab 2 (Games) it shows the latest news from (Games forum), and o on...

That should be possible, no?

Like this, each tab could include another annoucements file... :

Tab 1 --> Include: anime_announcements.php
Tab 2 --> Include: games_announcements.php
Tab 3 ---> ...

I mean, like this you would not have the same function more than one time in the same file...


What you think?


P.D, i found a page with something similar: http://www.ddanime.org/ but this page realoads completely... The way I mean would be without reloading the full page...
User avatar
Lunatic Zorr
Registered User
Registered User
 
Posts: 5
Joined: 21 Sep 2008, 17:04

Donate to 6 String MODs
If you like any of the work that I do here, please consider donating.
click the image on the left for a list of some of the advantages of donating



[FUNCTION] get_announcements

Postby kenny » 30 Sep 2008, 00:55

Yes that's certainly doable. I'll have a look this week.
I won't be out much, so I should have some time to come up with something :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

[FUNCTION] get_announcements

Postby kenny » 30 Sep 2008, 15:22

Ok, here's a little extra bit that I just added to the site here. Thought it might be useful for others too. Basically it adds a linked icon before the "Announcements" link that takes you to the new topic posting page for that forum. Like a "quick post" link :) I haven't added it to the main function yet, but here are the changes for anyone wishing to use it. Screenshot added as well.

Note that the link with show up to everyone with admin permissions. You can narrow this down by altering the acl_gets() function. You could even create your own permission to handle this. Feel free to change the image to something else, I just thought it easier to use one that's already there ;)

OPEN: includes/functions_announce.php
FIND:
Code: Select all
* @version $Id: functions_announce.php 0013 17:07 17/08/2008 kenny

REPLACE WITH:
Code: Select all
* @version $Id: functions_announce.php 0014 14:29 17/08/2008 kenny

FIND:
Code: Select all
    global $db, $template;

REPLACE WITH:
Code: Select all
    global $db, $template, $auth;

FIND:
Code: Select all
        'L_TITLE'         => $title)

REPLACE WITH:
Code: Select all
        'L_TITLE'         => $title,
        'S_NEW_ANNOUNCE'    => $auth->acl_gets('a_') ? '<a href="' . append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=post&amp;f=' . $forum_id) . '"><img src="' . $phpbb_root_path . 'adm/images/file_new.gif" alt="New" title="New" /></a>' : '')

OPEN: styles/prosilver/template/announce_body.html
FIND:
Code: Select all
<h3>

IN-LINE AFTER ADD:
Code: Select all
{S_NEW_ANNOUNCE}&nbsp;
quick-announce.png
quick-announce.png (2.92 KiB) Viewed 1040 times
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

[FUNCTION] get_announcements

Postby JohanNL » 17 Nov 2008, 19:26

Getting a blank page. Codes:

index.php
(note: this file isn't in the phpBB root, but in my website root! (created it with topic in Chit-Chat)
Code: Select all
<?php
    define
('IN_PHPBB', true);
    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
    include($phpbb_root_path . 'includes/functions_announce.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    page_header('Homepage');

    $template->set_filenames(array(
        'body' => 'site/homepage_body.html',
    ));
    $template->assign_vars(array(       
   
'ANNOUNCEMENT'    => get_announcements('2', '5', 'laatste<span style=\"color: red;\">mededelingen</span>'),
    ))
    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
    page_footer();
?>



homepage_body.html

Code: Select all
<!-- INCLUDE overall_header.html -->
    <div class="panel">
       <div class="inner"><span class="corners-top"><span></span></span>

       <div class="content">
      <h2>beta-garden<span style="color: red;">.com</span></h2>
      <p>Beta-Garden.com is een jonge &amp; groeiende community, die discussies voert over o.a. games, software, hardware, internet, grafisch design, computers en meer.
     Daarnaast is op Beta-Garden ook plek om even gewoon, gezellig over niks te praten, te lachen, leuke filmpjes te delen etc.
     Je kan je geheel vrijblijvend &amp; kostenloos op Beta-Garden aanmelden, zonder enige verplichtingen te hebben.
     Toch zouden we het wel leuk vinden als je je op onze nieuwsbrief inschrijft, zo nu en dan op het forum komt en gezellig mee praat!<br />
     </p><br />
      <p>Beta-Garden is gebasseerd op het concept van een forum, met de voordelen van dien. Het forum is dan ook het centrale punt van Beta-Garden.
     Echter hebben we, naast het forum, nog meer leuke onderdelen! Zo kan je onze eigen RPG spelen, gezellig chatten met anderen, informatie zoeken, bijwerken of plaatsen op de Wiki, en nog meer!</p>
       </div>

       <span class="corners-bottom"><span></span></span></div>
    </div>
   
          <div class="navbar">
             <div class="inner"><span class="corners-top"><span></span></span>
          <h3><a href="{U_FORUM}" title="{L_TITLE}">{L_TITLE}</a></h3>
          <span style="font-size: 1.1em;">
             <!-- BEGIN announce_row -->
                   <a href="{announce_row.U_ANNOUNCE}" title="{announce_row.POST_SUBJECT}" style="font-size: 1.1em;">{announce_row.TOPIC_TITLE}</a><br />
             <!-- END announce_row -->
          </span>
             <span class="corners-bottom"><span></span></span></div>
       </div>
       <br />

<!-- INCLUDE overall_footer.html -->



functions_announce.php

Code: Select all
<?php
   
/**
    *
    * @package phpBB3
    * @version $Id: functions_announce.php 0013 17:07 17/08/2008 kenny
    * @copyright (c) 2005 phpBB Group
    * @license http://opensource.org/licenses/gpl-license.php GNU Public License
    *
    */

    /**
    * @ignore
    */
    if (!defined('IN_PHPBB'))
    {
        exit;
    }

    /**
    * Pull info for latest announcements // cherokee red - 08/13/2008
    *
    * $forum_id is the forum you want to pull info from
    * $topic_limit is the amount of topics to display
    * $title is the name you want to give to the block i.e. Announcements, or Latest Posts
    *
    */
    function get_announcements($forum_id, $topic_limit, $title)
    {

        global $db, $template;
        global $phpbb_root_path, $phpEx;

        $an_sql = 'SELECT topic_id, forum_id, topic_title
            FROM '
. TOPICS_TABLE . '
            WHERE forum_id = '
. $forum_id . '       
            ORDER BY topic_id DESC'
;
           
       
//query the db
        $result = $db->sql_query_limit($an_sql, $topic_limit);

        $db->sql_freeresult($result);

        // Lets build a page ...
        $template->assign_vars(array(
            'U_FORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
            'L_TITLE'         => $title)
        );

        while ($announce = $db->sql_fetchrow($result))
       
{
            $template->assign_block_vars('announce_row', array(
                'TOPIC_TITLE'         => $announce['topic_title'],
                'U_ANNOUNCE'         => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $announce['forum_id'] . '&amp;' . 't=' . $announce['topic_id']),
            ));   

       
}

        $template->set_filenames(array(
            'content' => 'announce_body.html',
        ));

        // Thanks Vic ^_^
        $content = $template->assign_display('content', '', true);

        return $content;
    }
?>



It worked before making the edits..
Last edited by kenny on 18 Nov 2008, 09:41, edited 1 time in total.
Reason: php tags :P
Image
User avatar
JohanNL JohanNL is my name
V.I.P
V.I.P
 
Posts: 148
Joined: 27 Sep 2008, 07:24

[FUNCTION] get_announcements

Postby kenny » 18 Nov 2008, 09:40

There's a few errors in your code.
1st, there is whitespace at the start of both php file which you need to delete.
You are missing a semi-colon after this code:
Code: Select all
'ANNOUNCEMENT'    => get_announcements('2', '5', 'laatste<span style="color: red;\">mededelingen</span>'),
   )) 

You are also missing a backslash "\" in the style there ;)
In homepage body, you don't need the code from announce_body.html. Instead just use {ANNOUNCEMENT} :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

[FUNCTION] get_announcements

Postby JohanNL » 18 Nov 2008, 15:50

semi-colon? :?: Thought I'd already fixed that backslash.. :?

I was thinking I could use the announce_body.html code, and then don't use the file.. Think it won't work. If I use '{ANNOUNCEMENT}', do I get all the 5 announcements? :D
Image
User avatar
JohanNL JohanNL is my name
V.I.P
V.I.P
 
Posts: 148
Joined: 27 Sep 2008, 07:24

[FUNCTION] get_announcements

Postby JohanNL » 18 Nov 2008, 17:26

Hmm, it actually shows up now, but it has no content (And my Block Name doesn't work, it shows:
mededelingen">laatstemededelingen
--> announcements">lastannouncements).. :o If I hover I get
laatste <span style=\
(laatste=last).



Edit: Works OK now.
Image
User avatar
JohanNL JohanNL is my name
V.I.P
V.I.P
 
Posts: 148
Joined: 27 Sep 2008, 07:24

[FUNCTION] get_announcements

Postby kenny » 19 Nov 2008, 13:29

Hi Johan, just to make sure - you have solved the problem? :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

[FUNCTION] get_announcements

Postby JohanNL » 19 Nov 2008, 13:59

Yes. :mrgreen: It works nice! :)
Image
User avatar
JohanNL JohanNL is my name
V.I.P
V.I.P
 
Posts: 148
Joined: 27 Sep 2008, 07:24

[FUNCTION] get_announcements

Postby kenny » 19 Nov 2008, 14:05

Excellent, good to heard :D
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

PreviousNext



Return to Code Snippets

Who is online

Yahoo [Bot]


cron