Plugin Directory

Changeset 204285


Ignore:
Timestamp:
02/11/2010 05:57:35 PM (16 years ago)
Author:
zeeg
Message:

Merged in changes to Jaiku from lemonad

Location:
lifestream/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lifestream/trunk/extensions/jaiku/extension.inc.php

    r191677 r204285  
    22class Lifestream_JaikuFeed extends Lifestream_Feed
    33{
    4     const ID            = 'jaiku';
    5     const NAME        = 'Jaiku';
    6     const URL          = 'http://www.jaiku.com/';
     4    const ID          = 'jaiku';
     5    const NAME        = 'Jaiku';
     6    const URL         = 'http://www.jaiku.com/';
    77    const NS_JAIKU    = 'http://jaiku.com/ns';
    8     const LABEL     = 'Lifestream_MessageLabel';
    9     const CAN_GROUP = false;
    10    
     8    const LABEL       = 'Lifestream_MessageLabel';
     9    const DESCRIPTION = 'Hiding or showing comments only affects new comments and not the ones already in your lifestream.';
     10        const AUTHOR      = 'Unknown, Jonas Nockert';
     11    const CAN_GROUP   = false;
     12
    1113    function get_options()
    1214    {       
    1315        return array(
    1416            'username' => array($this->lifestream->__('Username:'), true, '', ''),
     17            'hide_comments' => array($this->lifestream->__('Hide Comments'), false, true, false),
    1518        );
    1619    }
     
    2023        return 'http://'.$this->get_option('username').'.jaiku.com/feed/rss';
    2124    }
    22    
     25
    2326    function get_user_url($user)
    2427    {
    2528        return 'http://'.$user.'.jaiku.com';
    2629    }
    27    
     30
    2831    function get_user_link($user)
    2932    {
    30         return $this->lifestream->get_anchor_html('@'.htmlspecialchars($user), $this->get_user_url($user), array('class'=>'user'));
     33        return $this->lifestream->get_anchor_html('@'.htmlspecialchars($user[1]), $this->get_user_url($user[1]), array('class'=>'user'));
    3134    }
    32    
     35
    3336    function parse_users($text)
    3437    {
    35         return preg_replace_callback('/([^\w]*)@([a-z0-9_\-\/]+)\b/i', array($this, 'get_user_link'), $text);
     38        return preg_replace_callback('/(?<=^|\s)@([a-zA-Z0-9_]+)\b/i', array($this, 'get_user_link'), $text);
    3639    }
    3740
    3841    function render_item($row, $item)
    3942    {
    40         return $this->parse_users($this->parse_urls(htmlspecialchars($item['title']))).' ['.$this->lifestream->get_anchor_html(htmlspecialchars($this->get_option('username')), $item['link']).']';
     43        // Posts do not have URL fragment identifiers
     44        if (strpos($item['guid'], '#') === false)
     45        {
     46            // Render a post using only the feed item title
     47            return $this->parse_users($this->parse_urls(htmlspecialchars($item['title']))).' ['.$this->lifestream->get_anchor_html(htmlspecialchars($this->get_option('username')), $item['link']).']';
     48        }
     49
     50        /* Render a comment using the feed item description. We're rendering the comment
     51           html directly here but given the below it should be safe enough:
     52           1) Jaiku is trying hard to avoid rendering anything malicious anywhere.
     53           2) It can be assumed that the source of the html will be text the user wrote
     54              herself. */
     55
     56                // Remove avatar image
     57        $desc_without_image = preg_replace('/<a.+?$\s+/Amu', '', $item['description']);
     58
     59        // Remove comment author as it's always the stream owner.
     60        $desc_without_author = preg_replace('!^(<p.*?>\s+)(Comment).+(on)$!um', '\\1<i>\\2 \\3', $desc_without_image);
     61
     62        // Remove relative time and location
     63        $desc_without_time = preg_replace('!\s+[^\r\n]+\s+[^\r\n]+\s+</p>$!u', '</i>', $desc_without_author);
     64
     65        /* Line breaks instead of paragraphs. Nested paragraphs and
     66           multiple empty paragraphs in a row should not give additional
     67           line breaks */
     68        $desc_without_p = preg_replace('/<p.*?>/u', '', $desc_without_time);
     69        $desc_without_p = preg_replace('!(\s*</p>\s*){1,}!u', '<br/><br/>', $desc_without_p);
     70
     71        return $desc_without_p . ' ['.$this->lifestream->get_anchor_html(htmlspecialchars($this->get_option('username')), $item['link']).']';
    4172    }
    4273
    4374    function yield($row, $url, $key)
    4475    {
    45         //I don't know what this is for, would not fetch when running
    46         //if (!lifestream_str_startswith($row->get_link(), 'http://'.$this->get_option('username').'.jaiku.com/presence/')) return;
    47        
    4876        $data = parent::yield($row, $url, $key);
    49         //preg_match('|<p>([^<]+)</p>|i', $row->get_title(), $matches);
    50         //$data['title'] = $matches[1];
    51         $data['title'] = $row->get_title();
     77        // Comments have URL fragment identifiers while posts do not
     78        if ($this->get_option('hide_comments') && strpos($data['guid'], '#') !== false)
     79        {
     80            return false;
     81        }
     82        $data['title'] = $this->lifestream->html_entity_decode($row->get_title());
     83        $data['description'] = $row->get_description();
    5284        return $data;
    5385    }
  • lifestream/trunk/inc/core.php

    r202949 r204285  
    17221722            else
    17231723            {
    1724 
    17251724                $post = array(
    17261725                    'post_title' => 'Lifestream',
Note: See TracChangeset for help on using the changeset viewer.