Topic: Complete frustration with Random Article script

I was in need of showing a random news article from a single category and found this post in the forum.

I followed the instructions as given, not complicated. Even removed the strange character. It refused to work.

I was running v1.4.5 so I managed to upgrade to v1.5.3

Gave it one more try, it worked.
Since I was only testing with 2 articles I went to add some more.
When I went to see if it was still working I saw it was still just using the first 2 articles.
I noticed in the script it was looking to /cutenews/data/news.txt
so I added a "c" in front of "data" and figured that would be looking at the right news.txt file.
Test it again, nothing, it doesn't show up at all.
Then I deleted the "c", tested again, and it still doesn't work (show up at all)
Now I am completely puzzled, it was just working with the exact same code.
I set all file chmod's to 777, still nothing.

Here is the code I have in the show_random.php file in the root directory with the show_news.php file
<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><?
error_reporting (E_ALL ^ E_NOTICE);
$cutepath = __FILE__;
$cutepath = preg_replace( "'show_random.php'", "", $cutepath);
$cutepath = preg_replace( "'/show_random.php'", "", $cutepath);
$news = file($cutepath."cdata/news.txt");
shuffle($news);
$i = 0;
$newsids = array();
foreach ($news as $news_line) {
$news_arr = explode("|", $news_line);
if (isset($category) && !stristr($category, $news_arr[6])) { continue; }
$newsids[$i] = $news_arr[0];
$i++;
}
$randid = mt_rand(0, count($newsids)-1);
$subaction = "showfull";
$id = $newsids[$randid];
include($cutepath."show_news.php");
?></div>

This is the code I added to the page
Note: everything works fine if the include points to
/home/hsphere/local/home/xxxxxxx/my-site.com/cutenews/show_news.php

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><?php
$category = "2";
$template = "hot_job";
include ("/home/hsphere/local/home/xxxxxxx/my-site.com/cutenews/show_random.php");
?></div>

I checked the error log and this is what I got.
<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>1364972476|2013-04-03 03:01:16|Warning: file(cdata/news.txt): failed to open stream: No such file or directory; /show_random.php:5;
1364972476|2013-04-03 03:01:16|Warning: shuffle() expects parameter 1 to be array, boolean given; /show_random.php:6;
1364972476|2013-04-03 03:01:16|Warning: Invalid argument supplied for foreach(); /show_random.php:9;
1364972476|2013-04-03 03:01:16|Warning: main(show_news.php): failed to open stream: No such file or directory; /show_random.php:18;
1364972476|2013-04-03 03:01:16|Warning: main(): Failed opening 'show_news.php' for inclusion (include_path='.:/hsphere/shared/apache/libexec/php4ext/php/'); /show_random.php:18;</div>

Please, any help or direction would be gratefully accepted.

Re: Complete frustration with Random Article script

I got it to work, I don't know if it was the best solution, but it works.

I removed line 3-5

$cutepath = __FILE__;
$cutepath = preg_replace( "'show_random.php'", "", $cutepath);
$cutepath = preg_replace( "'/show_random.php'", "", $cutepath);

and replaced $cutepath where used with the correct path
example:
("/home/hsphere/local/home/xxxxxxx/my-site.com/cutenews/cdata/news.txt")

Re: Complete frustration with Random Article script

Hi!

I am also looking for the random function and can't get it done.
Can you help me out by showing the correct code?

I am using the latest version of CN.

thnx.

Re: Complete frustration with Random Article script

Oh it is not so good well you can try for it.