vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.5 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=113)
-   -   Import Unread News from a Forum (https://vborg.vbsupport.ru/showthread.php?t=115179)

antialiasis 05-08-2006 10:00 PM

Import Unread News from a Forum
 
This hack will allow you to specify one or more forum IDs in your Admin CP as "news forums". Every time a thread is created in these forums, all users will see an "Unread news" notification at the top of every page of the forum until they view the unread news thread. If many news threads are unread, they will all be shown in the notification and removed one by one as each thread is viewed.

This hack both serves to make sure all users are aware of posted news and to give users who return after a long absence a quick rundown of what has been going on in the forums since they last were there.

As of version 2.0, it is possible to specify:

- Time cutoff: all news older than x days will count as read
- Only check for read status on latest x threads: only the latest x news will be shown if unread; all older news will always be treated as read
- Maximum number of news to display at one time: if a user has more unread news (after the time cutoff and latest x filter) than the number specfied, only that number will actually be displayed on the page
- Whether to make users see news created before they joined as unread
- Whether to show the date and time when each news thread was made or just the date

Please note that you must have Paul_M's Display who has read a thread hack installed for this to function correctly! You don't need to actually have the people who have read the thread shown for anybody at all (heck, if you're completely uninterested in what that hack does, you don't even need to make the template edit for it), but as long as it's installed, this hack will work.

Version 3.0 adds the ability to have more than one news forum and to set a PHP condition for each forum which must be met in order for news from that forum to be imported.

Installation

Simply download the product attached to this post and import it via the Admin CP Product Manager. Then make one template edit: add

Code:

$unreadnews
to the bottom of the header template.

------------------------------------

If using PHP version 4.x (or if you are getting an error message that looks something like Fatal error: Call to undefined function: array_combine() in /public_html/global.php(359) : eval()'d code on line 139), you additionally need to find this line in the Import News plugin on the hook global_start:

PHP Code:

   $newsarray array_combine($newsids$newsinfo); 

Replace it with

PHP Code:

   $newsarray = array();
foreach (
$newsids AS $key => $id)
{
   
$newsarray["$id"] = $newsinfo["$key"];


If using PHP 5 or later (which is the case if you don't get that error message), you will not need to make this edit.

------------------------------------

Afterwards, go to your vBulletin options, find the News Import System setting group, specify your news forum(s), set the other settings if you want, and turn the system on.

Don't forget to click Install if it's working for you. Enjoy!

Version 3.0: Added ability to have multiple news forums and use conditionals.
Version 2.23: Important bugfix from version 2.22
Version 2.22: Bugfixes
Version 2.21: Cutting off on the user's join date has been made an optional feature specified in the admin CP, and some unnecessary code has been removed. Also added alternative templates for no particular reason.
Version 2.2: Fixed uncached template, added "More..." link that links to the news forum when unread news are cut off by "Maximum number of news to display at one time" option, and all news created before the user registered will now count as read for that user. (Imagine registering and having twenty "unread news" notifications you have to plough through...)
Version 2.01: Added template edit information (I'm an official idiot for forgetting that) and fixed table prefixes.
Version 2.0: Added functionality (see above)

----------------------------

EXTRA: Alternative templates

If you don't like the way the current unread news box looks, I've got some more standard-looking templates you can use instead if you want. This also allows you to collapse the unread news, which might be useful. Just replace the templates, see how it looks, and revert the templates again if you liked the other look better.

Alternative custom_unreadnews template:

Code:

<if condition="$show['unreadnews']">
<br />
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
  <thead>
      <tr>
        <td class="tcat"><a href="#top" style="float:$stylevar[right]" onclick="return toggle_collapse('unreadnews')"><img id="collapseimg_unreadnews" src="$stylevar[imgdir_button]/collapse_tcat$vbcollapse[collapseimg_unreadnews].gif" alt="" border="0" /></a> Unread News</td>
      </tr>
  </thead>
  <tbody id="collapseobj_unreadnews" style="$vbcollapse[collapseobj_unreadnews]">
      $newsitems
      <if condition="$show['importnewscutoff']">
      <tr>
        <td class="alt1"><a href="forumdisplay.php?$session[sessionurl]f={$vbulletin->options['importnewsforum']}" class="smallfont">More...</a></td>
      </tr>
      </if>
  </tbody>
</table>
</if>

Alternative custom_newsbit template:

Code:

      <tr>
        <td class="alt1">$timestamp: <strong><a href="showthread.php?$session[sessionurl]t=$id">$info[title]</a></strong></td>
      </tr>


username12 05-09-2006 09:54 PM

Quote:

Database error in vBulletin 3.5.3:

Invalid SQL:

SELECT threadid, title, dateline
FROM thread
WHERE forumid =;

MySQL Error : You have an error in your SQL syntax near '' at line 5
Error Number : 1064
Sticks around when I disable and uninstall the hack as well.

Edit: got my forums back online by disabling plugin accelerator, though I can't seem to get this to work with or without that.

antialiasis 05-09-2006 10:14 PM

It looks like you haven't set the News forum option. Can you make sure it's set?

Although of course, I should update the hack to make sure it doesn't try to do anything unless it's set to something...

DrewM 05-09-2006 10:24 PM

look at the xml there is no vb options!

antialiasis 05-09-2006 10:25 PM

Hmm, that is odd... I'll fix it. Just a moment. Sorry about that.

DrewM 05-09-2006 10:27 PM

Quote:

Originally Posted by antialiasis
Hmm, that is odd... I'll fix it. Just a moment. Sorry about that.

it's fine I've done stuff like that before but worse..

antialiasis 05-09-2006 10:34 PM

Okay, it should be functional now. Sorry again. (Just import the new product instead of the old one.)

FleaBag 05-10-2006 12:18 AM

Can I set this so it shows a maz amount of recent items? I know a lot of my users won't read the news and don't want them mounting up for them forcing them to read.

antialiasis 05-10-2006 12:57 AM

Hm, yes, that should be possible. Just open the plugin "Import news" on the hook global_start and find:

PHP Code:

$newsthreads $db->query_read("
   SELECT threadid, title, dateline
   FROM thread
   WHERE forumid = 
$newsforum
"
); 

Replace that with

PHP Code:

$newsthreads $db->query_read("
   SELECT threadid, title, dateline
   FROM thread
   WHERE forumid = 
$newsforum
   ORDER BY dateline DESC
"
); 

Then find this:

PHP Code:

while ($news $db->fetch_array($newsthreads))
{
   
$newsinfo[] = array('title' => $news['title'], 'date' => $news['dateline']);
   
$newsids[] = $news['threadid'];  


Below that, add this bit:

PHP Code:

array_splice($newsinfoMAX_NUMBER_HERE);
array_splice($newsidsMAX_NUMBER_HERE); 

Obviously, replace MAX_NUMBER_HERE with your maximum number of unread news items that should be shown. This should take only the latest x threads from the news forum and check if they are unread, which I believe is what you were asking for.

(If you'd rather have it cut off all news older than x or simply display only the latest x unread news so a new one is added to the list if one of them is read, just ask.)

Skaterscafe.com 05-10-2006 01:34 AM

I get this when I install, happens during the install:

Database error in vBulletin 3.5.2:

Invalid SQL:

INSERT INTO setting
(varname, grouptitle, value, defaultvalue, datatype, optioncode, displayorder, advanced, volatile, product)
VALUES
(
'importnews',
'newsimporting',
'',
'',
'boolean',
'yesno',
1,
0,
1,
'import_news'
),
(
'newsforum',
'newsimporting',
'5,197,39',
'1',
'numeric',
'',
2,
0,
1,
'import_news'
);

MySQL Error : Duplicate entry 'newsforum' for key 1
Error Number : 1062
Date : Tuesday, May 9th 2006 @ 10:33:04 PM
Script : ......./admincp/plugin.php
Referrer : /admincp/plugin.php?do=productadd
IP Address : ********
Username : *******
Classname : vb_database

antialiasis 05-10-2006 11:13 AM

This must be some sort of clash with another product. Do you already have something installed that could have a setting called "newsforum"?

reteep 05-10-2006 11:36 AM

Cool idea but doesn't work here:

Quote:

Invalid SQL:

INSERT INTO vb3_setting
(varname, grouptitle, value, defaultvalue, datatype, optioncode, displayorder, advanced, volatile, product)
VALUES
(
'importnews',
'newsimporting',
'',
'',
'boolean',
'yesno',
1,
0,
1,
'import_news'
),
(
'newsforum',
'newsimporting',
'86',
'1',
'numeric',
'',
2,
0,
1,
'import_news'
);

MySQL-Fehler : Duplicate entry 'newsforum' for key 1
Fehler-Nr. : 1062
Datum : Wednesday, May 10th 2006 @ 02:33:14 PM
Skript : /vb/admincp/plugin.php
Referrer : /vb/admincp/plugin.php?do=productadd


Klassenname : vB_Database
vbAdvanced is using that name, you should use another table name!

antialiasis 05-10-2006 11:59 AM

Ah, okay, had to be something like that. The product has been updated to use 'importnewsforum' instead.

EDIT: One more fix... and a note of the updates in the first post.

I think I'll make a version 2.0 soon where the functionality that FleaBag requested will be automatically in and controllable through the Admin CP...

rmxs 05-10-2006 04:21 PM

Database error in vBulletin 3.5.4:

Invalid SQL:

SELECT threadid
FROM +++++ad
WHERE userid = 450 AND threadid IN ();

MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3
Error Number : 1064
Date : Wednesday, May 10th 2006 @ 11:22:45 AM
Script : http://www.*****r/**/showthread.php?t=1174
Referrer : http://www.****r/**/forumdisplay.php?f=26
IP Address : 1****
Username : ***
Classname : ****


Onother error here??there is fix??

TomasDR 05-10-2006 05:03 PM

rmxs your answer is in the first bug I found.

First bug: I had to add " . TABLE_PREFIX . " to your two select statements.
Code:

$newsthreads = $db->query_read("
  SELECT threadid, title, dateline
  FROM " . TABLE_PREFIX . "thread
  WHERE forumid = $newsforum
  $queryaddition
  ORDER BY dateline DESC
");

$readnews = $db->query_read("
  SELECT threadid
  FROM " . TABLE_PREFIX . "+++++ad
  WHERE userid = " . $vbulletin->userinfo['userid'] . " AND threadid IN (" . implode(',', $newsids) . ")
");

As for another bug, for the life of me I cannot figure out how you are displaying the news on the forumhome without adding a variable to the either the Header template or even the Navbar template.

I tried the variables $newsitems & $unreadnews without success, the $newsitems variable works but it isn't defined in a nice colored box like in your screenshot. It just puts the latest news right above the navbar but again not formatted to a template.

antialiasis 05-10-2006 05:32 PM

Oh, crap... more screw-ups...

What you're supposed to do is add $unreadnews to the bottom of the header template. It sounds odd that $unreadnews wouldn't be working, though. (You were testing it as logged in, right? And enabled the hack in the Admin CP, specified a news forum and all that?)

rmxs 05-10-2006 05:38 PM

If i set news forum to 0 its OK :)

If i set forum news to exaple 1 i get this error line Fatal error: Call to undefined function: array_combine() in /home/rmxs/domains/rmxs.gr/public_html/Vb/global.php(349) : eval()'d code on line 301

antialiasis 05-10-2006 05:47 PM

Ah, you must be using PHP 4 or earlier, then. array_combine() was apparently introduced in PHP 5...

A workaround for that should be fairly simple... find the line

Code:

  $newsarray = array_combine($newsids, $newsinfo);
in the Import News plugin on global_start, and replace it with

Code:

  $newsarray = array();
  for ($i = 0; i < count($newsids); i++)
  {
      $newsarray["$newsids[$i]"] = $newsinfo[$i];
  }

That should work basically the same as that built-in function.

rmxs 05-10-2006 05:53 PM

Ok now it works with no error byt im not get any message on the header and im lose the global attachment Block

im use PHP Version 4.4.2

antialiasis 05-10-2006 06:07 PM

Quote:

Originally Posted by rmxs
Ok now it works with no error byt im not get any message on the header and im lose the global attachment Block

im use PHP Version 4.4.2

You won't get a message unless you actually have unread news. That's how it's supposed to work.

What do you mean, you lost the global attachment block?

rmxs 05-10-2006 06:11 PM

DISAPEARD..
i make this change byt if i refresh my page i dont see the block like the attach file,also the global attachment block missing

Snake 05-10-2006 06:21 PM

This is very nice!

rmxs 05-10-2006 06:31 PM

I try many times and i cannot make the news appeard on the header..
Also take a look maybe there is a bug with the Global Announcement 1.2 Displays an announcement of choice on the index page of your forum.

Because after install its GONE

DJ XtAzY 05-10-2006 06:38 PM

i got this error

Code:

Database error in vBulletin 3.5.4:

Invalid SQL:

      SELECT threadid
      FROM +++++ad
      WHERE userid = 1 AND threadid IN (12778,12574,11841,11611,11289,11192,10878,10713,10361,9777,9576,9319,8612,8448,8282,8252,7909,7908,7830,7637,6856,6750,6590,6476,5666,5576,4546,4413,3878,3771,3720,3453,3381,3338,3275,3248,3100,2882,2717,2714,2550,2494,2452,2317,2291,2036,1923,1778,1673,1668,1550,1409,1397,1363,939,933,755,745,735,655,650,595,568,567,541,538,537,529,520,486,478,460,429,406,399,398,374,372,348,317,281,218,183,177,176,175,174,173,157,134,130,122,113,107,99,95,94,78,74,57,55,25,10,2);

MySQL Error  : Table 'forums.+++++ad' doesn't exist
Error Number : 1146
Date        : Wednesday, May 10th 2006 @ 03:36:53 PM


antialiasis 05-10-2006 06:57 PM

Quote:

Originally Posted by rmxs
I try many times and i cannot make the news appeard on the header..
Also take a look maybe there is a bug with the Global Announcement 1.2 Displays an announcement of choice on the index page of your forum.

Because after install its GONE

I still don't get it... do you mean the global announcement block is gone, not attachment? In that case, this hack can't have anything to do with it - I just skimmed the global announcement product file and there don't seem to be any clashing settings or variables or anything, and the template edits don't even edit the same template.

And do you definitely have some unread news (remember, any news that *you* create are read, so you either need to make a test account or get somebody else to create a new news item), are you logged in, have you made the template edit I added to the first post a while ago, and have you turned the system on in the Admin CP?

XtAsY, it looks like you haven't installed Paul_M's 'Display who has read a thread' hack (linked to in the first post).

monkeywarplane 05-10-2006 07:02 PM

Would love this plugin, will check this out later when the bugs are fixed.

Good luck

Stuart

rmxs 05-10-2006 07:09 PM

Quote:

Originally Posted by antialiasis
I still don't get it... do you mean the global announcement block is gone, not attachment? In that case, this hack can't have anything to do with it - I just skimmed the global announcement product file and there don't seem to be any clashing settings or variables or anything, and the template edits don't even edit the same template.

And do you definitely have some unread news (remember, any news that *you* create are read, so you either need to make a test account or get somebody else to create a new news item), are you logged in, have you made the template edit I added to the first post a while ago, and have you turned the system on in the Admin CP?


Everything look correct byt the BLOCK OF GLOBAL ANNOUCEMENT GONE if i unistall your Plugin appeard again...

(remember, any news that *you* create are read, so you either need to make a test account or get somebody else to create a new news item)

I forget that :)

EDIT: i check again byt nothing happent with new user(No Block)


i make again the install byt still THE BLOCK GONE


Try plz to install to your system to check this out

antialiasis 05-10-2006 07:23 PM

monkeywarplane: Oh, it DOES work if you do everything correctly. I now installed the exact product that's attached to the first post on a test forum, making exactly that template edit exactly as said, and it worked fine. XtAsY was having problems due to not having installed the plugin you need to have first, and rmxs's problem was that he didn't have any unread news. You're safe installing it as it is now.

rmxs: I installed Global Announcements on my test forum with this hack and it worked fine... =/ I don't know what's different on your forum, but it's clearly not a problem with the hack itself.

TomasDR 05-10-2006 10:34 PM

Quote:

Originally Posted by antialiasis
Oh, crap... more screw-ups...

What you're supposed to do is add $unreadnews to the bottom of the header template. It sounds odd that $unreadnews wouldn't be working, though. (You were testing it as logged in, right? And enabled the hack in the Admin CP, specified a news forum and all that?)

Maybe I had only tried $newsitems in the header template, it is working now.

Don't forget to add the " . TABLE_PREFIX . " to your select statements.

antialiasis 05-10-2006 10:39 PM

I did, unless something screwed up in attaching the new XML file.

But it's a good thing that it's working for somebody other than me at last. I can breathe now.

VTXCafe.com 05-11-2006 07:15 AM

Well, I tried again:

Fatal error: Call to undefined function: array_combine() in /public_html/global.php(359) : eval()'d code on line 139

Still not working.

antialiasis 05-11-2006 09:50 AM

You're using PHP 4.x. Follow the special instructions in the first post about editing the Import News plugin on global_start.

(I added information about that error message, too, for others who don't know what PHP version they're using - better play it safe.)

reteep 05-11-2006 10:50 AM

This mod is great, works here!

rmxs 05-11-2006 11:24 AM

FINALY i unistall the global anouchements i install you hack and i unstall again tha GLOBAN anouch...

And everything Work Fine ;)

antialiasis 05-11-2006 12:47 PM

Quote:

Originally Posted by rmxs
FINALY i unistall the global anouchements i install you hack and i unstall again tha GLOBAN anouch...

And everything Work Fine ;)

I'm glad it's working for you now.

Incidentally, thank you for posting that. It made me realize why I was having problems with something else: the order in which plugins are loaded depends on the time of installation. There must have been some plugins in Global Announcements that had to be loaded after some in my hack for some reason, which is why you were having those problems.

Another thing to know for future hacks...

rmxs 05-11-2006 02:35 PM

can you tell me now how i fix this :)

Uncached templates: custom_newsbit (3)

The number (3) change if there is more news now there is 3

antialiasis 05-11-2006 02:59 PM

Oh, right, I forgot to cache that one.

Just add

PHP Code:

$globaltemplates[] = 'custom_newsbit'

to the bottom of the Cache import news template plugin on cache_templates.

Updated XML will be up soon; I'm going to add a couple of hack features anyway so I'll let it wait until I'm done with that.

rmxs 05-11-2006 03:05 PM

I have already add this i fount a tutorial about I waitng for more Features :)

antialiasis 05-11-2006 03:56 PM

Version 2.2 up, with a couple of additions and the template cache fix.

Any feature suggestions would be very much appreciated. I like working on this thing.

rmxs 05-11-2006 04:37 PM

nice.. :)

Suggestion : in new version you add all news created before the user registered will now count as read for that user..

byt now with this all new users dont know the news about forum...

i install it for that reason NEW Members READ THE NEWS :)

I thing it better to cutoff more than 5 and with More Link the BLOCK LOAD THE REST (if there is more news..)

I keep for the time the old Version new users must read the NEWS... ;)

Keep going


All times are GMT. The time now is 07:04 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01635 seconds
  • Memory Usage 1,872KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_code_printable
  • (7)bbcode_php_printable
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete