1,026

(5 replies, posted in Programming)

Cheers chaps. Greatly appreciated. smile

1,027

(11 replies, posted in PunBB 1.2 show off)

Zimmer92 wrote:

Style doesn't look decent enough, I still think there is a lot of work to be done by me to get it nice. I think the borders are a bit too harsh on the eye and the colours are out of depth, so viewing and scrolling down forums is not the nicest thing to do.

To be totally truthful, I quite like those borders. big_smile One of the problems with a lot of the darker themes tends to be their lack of distinction between sections. I think it works quite well myself. smile


Zimmer92 wrote:

The code SHOULD be written correctly from the start, I agree, but I didn't really get my claws on this till a month or so ago. It died for a while, see, so I didn't really bother with such things.

I wasn't inferring either yourself or Liquidator in that comment. I had occasion to read the other participants website, and when they are stating things such as this as their strongpoints:

Quote:

proper, easy to use/edit Coding, Typography, Accessibility (yes, so that even blind people can easily use my websites), Navigation, Content and Search Engine Optimization.

End quote.

then in my book, that makes any lack of validity, (which by virtue also ruins accessibility), a perfectly good and honest criticism. As the saying goes, if you are going to stand yourself upon a pedestal....... big_smile


Zimmer92 wrote:

style problems - which IE will always be a fucking dick about.

Ain't that the truth. big_smile big_smile As I mentioned, apologies if you thought my comments were a reflection upon yourself or Liquidators efforts. They were not. I was merely pointing out the hypocritical nature of the site against the above quote. smile

1,028

(5 replies, posted in Programming)

Cheers. smile

Edit: Just out of curiosity, does the 'not natively' bit mean there is an alternative way to do it?

1,029

(5 replies, posted in Programming)

Is there any way in PHP to detach a running function so that it will continue in the background, so that the calling script may carry on with its tasks?


Cheers,

Matt

I will stress very highly about this, multi-dimensional arrays *ARE NOT* my strongpoint, big_smile so this script may be completely flawed. I would honestly suggest not testing it until one of the other, more learned ones, have given it a once over at least. But, here is my claim for ridicule, big_smile :

<?php

// Include the SimplePie library 
require_once 'simplepie.inc';
require 'shorten.php';

// Because we're using multiple feeds, let's just set the headers here.
header('Content-type:text/html; charset=utf-8');

// These are the feeds we want to use
mysql_connect(localhost,$db_username,$db_password);
@mysql_select_db($db_name) or die( "Unable to select database");

$query="SELECT id, firstname, username, rssfeed FROM members WHERE rssfeed!=''";
$result=mysql_query($query);

$feeds = array();

$i = 0;
$xf = 0;
$xi = 0;
$xx = 0;

while ($cur_feed = mysql_fetch_assoc($result))
{
    $feeds[$i][uid] = $cur_feed['id'];
    $feeds[$i][feed] = $cur_feed['rssfeed'];
    $feeds[$i][fname] = $cur_feed['firstname'];
    $feeds[$i][uname] = $cur_feed['username'];
    $i++;
}

// This array will hold the items we'll be grabbing.
$first_items = array();
 
// Let's go through the array, feed by feed, and store the items we want.

while ($xi <= $i)
{
    $url = $feeds[$xi][feed];
    
    // Use the long syntax
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->init();

    // How many items per feed should we try to grab?
    $items_per_feed = 1;
 
    // As long as we're not trying to grab more items than the feed has, go through them one by one and add them to the array.
    for ($x = 0; $x < $feed->get_item_quantity($items_per_feed); $x++)
    {
        $first_items[$xx][feed] = $feed->get_item($x);
        $first_items[$xx][uid] = $feeds[$xi][uid];
        $first_items[$xx][fname] = $feeds[$xi][fname];
        $first_items[$xx][uname] = $feeds[$xi][uname];
        $xx++;
    }
    $xi++;
    // We're done with this feed, so let's release some memory.
    unset($feed);
}
 
/*
// We need to sort the items by date with a user-defined sorting function.  Since usort() won't accept "SimplePie::sort_items", we need to wrap it in a new function.
function sort_items($a, $b)
{
    return SimplePie::sort_items($a, $b);
}
 
// Now we can sort $first_items with our custom sorting function.
usort($first_items, "sort_items");
*/

$counter = 0;

while ($xf <= $xx)
{
    $item = $first_items[$xf][feed];
    $user_id = $first_items[$xf][uid];
    $firstname = $first_items[$xf][fname];
    $username = $first_items[$xf][uname];

    $feed = $item->get_feed();

    $counter++;
    $xf++;

    if ($counter >= 10)
    {
        break;
    }

    if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$user_id.'.jpg'))
    {
        $avatar_field = '<img src="'.$pun_config['o_avatars_dir'].'/'.$user_id.'.jpg" alt="" />';
    }
    else
    {
        $avatar_field = '<img src="'.$pun_config['o_avatars_dir'].'/nopicture.png" alt="" />';
    }

    $picture = '<div id="feedpicture"><a href="member.php?id='.$user_id.'" title="'.$firstname.'\'s Member Page">'.$avatar_field.'</a></div>';

// Begin the (X)HTML page.
?>

<h3><?php echo $picture; ?><a href="<?php echo $item->get_permalink(); ?>" target="_blank"><?php echo html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8'); ?></a></h3>

<!-- get_content() prefers full content over summaries -->
<? echo trim(substr((str_replace("\n", ' ', str_replace("\r", ' ', strip_tags($item->get_description())))),0,300)); ?>
... <i>more</i></a><br />

<p class="footnote"><a href="member.php?id=<?php echo $user_id; ?>" title="<?php echo $firstname.'\'s Member Page'; ?>"><?php echo $username; ?></a> | <a href="<?php echo $feed->get_permalink(); ?>" target="_blank"><?php echo $feed->get_title(); ?></a> | <?php echo $item->get_date('M j, Y | g:i a'); ?></p><br />

<?php

}

?>

Seriously though, regarding the caution. I would wait until it's been checked over first. It could do anything from literally nothing, upto going into a constant while loop. big_smile


Edit: The sorting is also disabled, as that would have reset all the keys.

Post the complete script you're using.

Peter wrote:
    for ($x = 0; $x < $feed->get_item_quantity($items_per_feed); $x++)
    {
        $first_items[] = $feed->get_item($x);

    $user_id = $id_array[$x];
    $firstname = $first[$x];
    $x++;

    }

You have already set user_id and firstname at the top of the loop. You shouldn't have them in that loop too. All you are achieving there is running through the array without doing anything with the info. They're already set. Echo the output where you need it.

Peter wrote:

I give up for now.

Well stop stripping parts off the code you're given then. smile

$query="SELECT id, firstname, username, rssfeed FROM members WHERE rssfeed!=''";
$result=mysql_query($query);

$feeds = array();
$id_array = array();
$first = array();

while ($cur_feed = mysql_fetch_assoc($result))
{
    $feeds[] = $cur_feed['rssfeed'];
    $id_array[] = $cur_feed['id'];
    $first[] = $cur_feed['firstname'];
}

// This array will hold the items we'll be grabbing.
$first_items = array();
 
// Let's go through the array, feed by feed, and store the items we want.

$ix = 0;

foreach ($feeds as $url)
{
    $user_id = $id_array[$ix];
    $firstname = $first[$ix];
    $ix++;

    // Use the long syntax
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->init();
elbekko wrote:

The while is still wrong.

I'd never noticed that. big_smile

Thanks for what?

Peter wrote:
$query="SELECT id, firstname, username, rssfeed FROM members WHERE rssfeed!=''";
$result=mysql_query($query);

$feeds = array();
$id_array = array();
$first = array();

while ($cur_feed = mysql_fetch_assoc($result))
    $feeds[] = $cur_feed['rssfeed'];
    $id_array[] = $cur_feed['id'];
    $first[] = $cur_feed['firstname'];

// This array will hold the items we'll be grabbing.
$first_items = array();
 
// Let's go through the array, feed by feed, and store the items we want.

$ix = 0;

foreach ($feeds as $url)
{
    $user_id = $id_array[$ix];
    $firstname = $first[$ix];
    $ix++;

    // Use the long syntax
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->init();
Peter wrote:

I had already tried that one, Elbekko. Thanks though.

Just post the code you already have to hand. It'll be far less painful that way. big_smile

elbekko wrote:
foreach ($feeds as $url)
{
    $user_id = $id_array[$ix];
    $ix++;

    $firstname = $first[$ix];
    $ix++;
...

That last bit only needs one increment, to keep the relationship intact:

foreach ($feeds as $url)
{
    $user_id = $id_array[$ix];
    $firstname = $first[$ix];
    $ix++;
Peter wrote:

I've also tried this:

    for ($x = 0; $x < $feed->get_item_quantity($items_per_feed); $x++)
    {
        $first_items[] = $feed->get_item($x);

        $user_id = $id_array[$ix];
        $firstname = $first[$ix];
        $ix++;
    }

Should I use mysql_fetch_row or another variation?

You only want that var incremented once inside the loop, btw, as above.

Edit: In fact, if you're only wanting that info inside of the same loops as the $x count, you can ditch the $ix altogether and just use the $x var.

If I remember correctly offhand, fetch_assoc should be fine. I forgot to mention, btw, remember to set

$ix = 0;

initially outside of the foreach loop. big_smile

Simplest way, I believe, is to create arrays for each item, i.e:

$feeds = array();
$id_array = array();

while ($cur_feed = mysql_fetch_assoc($result))
{
        $feeds[] = $cur_feed['rssfeed'];
        $id_array[] = $cur_feed['id'];
  .....................etc, etc

then in the foreach loop do along the lines of:

$user_id = $id_array[$ix];
$ix++;

or echo or whatever you want to do with it.

Smartys wrote:

Matt: I think you confused implode with explode wink

Possibly. smile It's not an error I'll make a second time though, thanks to your correction. They will go giving these functions similar names and confusing people. big_smile

1,043

(13 replies, posted in General discussion)

Rickard wrote:

Indeed. Happy New Year folks! Give us a few more days and we should have 1.3 beta up for grabs.

Just to be an awkward git and go against the flow, big_smile are you sure you're not rushing a beta out just to placate people? big_smile big_smile

Smartys wrote:

That's a numerically indexed array with one element. So key 0 points to a comma delineated list of URLs.

The two are NOT equivalent.

My apologies. I never realised until you just explained it that implode doesn't actually split them. That's one I'll remember for future reference. Explains why that code I posted was buggered too. big_smile Thanks for the explanation. smile

Smartys wrote:

Matt:
1. That is a numerically indexed array, not an comma delineated list of URLs, which is what you are proposing.

The Simplepie array or the one we've created? Judging by their docs, the code for creating that array I posted earlier and then using the implode inside their array should give output which is similar to that in their documentation for the set_feed_url.

smartys wrote:

2. I wasn't saying that it doesn't allow you to use multiple URLs. We know that works since Peter has done it in this topic already. I was saying that I don't think it allows you to get the most recent post from each URL in the array. That example doesn't seem to do that.

My apologies. I misinterpreted that one. smile

Smartys wrote:

If so, I don't believe SimplePie allows you to do that just using its functions. Doing that involves doing what you were doing (calling each feed URL one by one), storing the results for each feed together in an array, and then sorting those results.

It would appear it does, by the looks of it. From the Simplepie docs:

// Multiple feeds
$feed = new SimplePie();
$feed->set_feed_url(array(
    'http://simplepie.org/blog/feed/',
    'http://digg.com'
));
$feed->enable_order_by_date(false);
$feed->cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache');
$feed->init();
echo $feed->get_title();

Just out of curiosity, change this line:

$feed->set_feed_url(implode(', ', $rss_feeds));

to:

$feed->set_feed_url(array("'".implode("', '", $rss_feeds)."'"));

or:

$feed->set_feed_url(array(implode(', ', $rss_feeds)));

I believe that first syntax should be correct for creating/keeping the single-quotes, but may be wrong.

Edit: I've just edited that code above for the array bit. Hadn't noticed the lack of it until Smartys mentioned. big_smile

The question you keep repeating is moot. You have all the info you need in this thread to do exactly what you require. Note my last post, regarding the array and a foreach loop. And if Simplepie was not the point of this thread, then why mention this:

With your array solutions the SimplePie scripts behaves very different than when I put in a regular list of feeds. They're not the same thing. I don't know how to work with arrays, so I'm at a new dead end if I have to start editing how SimplePie code handles arrays.

Seriously, the problem is not with any of the code which has been supplied to you, but with something else. However, if you wish to prove the point, use that first array code I posted, and then use this to echo each line individually, (providing that rssfeed is the only content being put into each line in the array):

foreach ($feed_array as $value)
{
    echo $value."\n";
}

The problem is that you have your mind set upon a specific answer you want, rather than the possibility of a better solution.

1,049

(11 replies, posted in PunBB 1.2 show off)

Style looks decent enough. The tabs are screwed in the Moz class browsers too, however.

However, just one slight nitpick. What is so hard about developing a compliant and valid site with regards to Xhtml/html? It's even more ironic when one of your designers professes to be something akin to the bees knees with regards to design, accessibility, usability and so on. Before you point out the fact, I know the site is still being worked upon, but the code should be written correctly from day one, not hacked together and then cleaned up as an after thought.

Peter wrote:

Smartys, my original question was about inserting output from one part of a PHP script elsewhere in the same script, instead of echo-ing it. I should never have brought up SimplePie! I've been saying all along that I don't want to go into SimplePie, which works fine elsewhere in my site.

No, your original question was regarding Simplepie and RSS feeds.

Just look at the code you've already been given. With the array you create, you can do what the chuff you like with it later, whether that's using it in a foreach loop and echoing the content, sorting, splitting or whatever else takes your fancy.