Author: ornicar2
Date: 2010-01-22 21:24:27 +0100 (Fri, 22 Jan 2010)
New Revision: 27069

Added:
   plugins/dmWidgetFeedReaderPlugin/LICENSE
   plugins/dmWidgetFeedReaderPlugin/README
   plugins/dmWidgetFeedReaderPlugin/config/
   plugins/dmWidgetFeedReaderPlugin/config/dm/
   plugins/dmWidgetFeedReaderPlugin/config/dm/widget_types.yml
   plugins/dmWidgetFeedReaderPlugin/lib/
   plugins/dmWidgetFeedReaderPlugin/lib/dmWidgetFeedReaderShowForm.php
   plugins/dmWidgetFeedReaderPlugin/lib/dmWidgetFeedReaderShowView.php
   plugins/dmWidgetFeedReaderPlugin/modules/
   plugins/dmWidgetFeedReaderPlugin/modules/dmWidget/
   plugins/dmWidgetFeedReaderPlugin/modules/dmWidget/templates/
   
plugins/dmWidgetFeedReaderPlugin/modules/dmWidget/templates/_dmWidgetFeedReaderShow.php
   plugins/dmWidgetFeedReaderPlugin/nbproject/
   plugins/dmWidgetFeedReaderPlugin/nbproject/project.properties
   plugins/dmWidgetFeedReaderPlugin/nbproject/project.xml
Log:
[Diem][dmWidgetFeedReaderPlugin] initial commit

Added: plugins/dmWidgetFeedReaderPlugin/LICENSE
===================================================================
--- plugins/dmWidgetFeedReaderPlugin/LICENSE                            (rev 0)
+++ plugins/dmWidgetFeedReaderPlugin/LICENSE    2010-01-22 20:24:27 UTC (rev 
27069)
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Thibault Duplessis
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file

Added: plugins/dmWidgetFeedReaderPlugin/README
===================================================================
--- plugins/dmWidgetFeedReaderPlugin/README                             (rev 0)
+++ plugins/dmWidgetFeedReaderPlugin/README     2010-01-22 20:24:27 UTC (rev 
27069)
@@ -0,0 +1,11 @@
+dmWidgetFeedReaderPlugin
+=================
+
+The `dmWidgetFeedReaderPlugin` allows to load and display feeds on your site.
+It packages a Diem front widget to show feed items from a url.
+The plugin is fully extensible. Only works with [Diem 
5.0](http://diem-project.org/) installed.
+
+Documentation
+-------------
+
+See the online documentation : [Diem Widget Feed Reader plugin 
documentation](http://diem-project.org/plugins/dmwidgetfeedreaderplugin)
\ No newline at end of file

Added: plugins/dmWidgetFeedReaderPlugin/config/dm/widget_types.yml
===================================================================
--- plugins/dmWidgetFeedReaderPlugin/config/dm/widget_types.yml                 
        (rev 0)
+++ plugins/dmWidgetFeedReaderPlugin/config/dm/widget_types.yml 2010-01-22 
20:24:27 UTC (rev 27069)
@@ -0,0 +1,4 @@
+dmWidgetFeedReader:
+
+  show:
+    cache:              false
\ No newline at end of file

Added: plugins/dmWidgetFeedReaderPlugin/lib/dmWidgetFeedReaderShowForm.php
===================================================================
--- plugins/dmWidgetFeedReaderPlugin/lib/dmWidgetFeedReaderShowForm.php         
                (rev 0)
+++ plugins/dmWidgetFeedReaderPlugin/lib/dmWidgetFeedReaderShowForm.php 
2010-01-22 20:24:27 UTC (rev 27069)
@@ -0,0 +1,36 @@
+<?php
+
+class dmWidgetFeedReaderShowForm extends dmWidgetPluginForm
+{
+  public function configure()
+  {
+    $this->widgetSchema['url'] = new sfWidgetFormInputText();
+    $this->validatorSchema['url'] = new dmValidatorLinkUrl(array(
+      'required' => true
+    ));
+
+    $this->widgetSchema['nb_items'] = new sfWidgetFormInputText();
+    $this->validatorSchema['nb_items'] = new sfValidatorInteger(array(
+      'min' => 0,
+      'max' => 100
+    ));
+
+    $this->widgetSchema['life_time'] = new sfWidgetFormInputText();
+    $this->validatorSchema['life_time'] = new sfValidatorInteger(array(
+      'min' => 0
+    ));
+    $this->widgetSchema->setHelp('life_time', 'Cache life time in seconds');
+
+    if(!$this->getDefault('nb_items'))
+    {
+      $this->setDefault('nb_items', 10);
+    }
+
+    if(!$this->getDefault('life_time'))
+    {
+      $this->setDefault('life_time', 86400);
+    }
+    
+    parent::configure();
+  }
+}
\ No newline at end of file

Added: plugins/dmWidgetFeedReaderPlugin/lib/dmWidgetFeedReaderShowView.php
===================================================================
--- plugins/dmWidgetFeedReaderPlugin/lib/dmWidgetFeedReaderShowView.php         
                (rev 0)
+++ plugins/dmWidgetFeedReaderPlugin/lib/dmWidgetFeedReaderShowView.php 
2010-01-22 20:24:27 UTC (rev 27069)
@@ -0,0 +1,90 @@
+<?php
+
+class dmWidgetFeedReaderShowView extends dmWidgetPluginView
+{
+  
+  public function configure()
+  {
+    parent::configure();
+    
+    $this->addRequiredVar(array('url', 'nb_items', 'life_time'));
+  }
+
+  protected function filterViewVars(array $vars = array())
+  {
+    $vars = parent::filterViewVars($vars);
+
+    $vars['items'] = $this->getItems($vars['url'], $vars['nb_items'], 
$vars['life_time']);
+    
+    return $vars;
+  }
+  
+  protected function doRenderForIndex()
+  {
+    $items = array();
+    
+    foreach($this->compiledVars['items'] as $item)
+    {
+      $items[] = $item->__toString();
+    }
+    
+    return implode(', ', $items);
+  }
+
+  protected function getItems($url, $nb, $lifeTime)
+  {
+    $cache = 
$this->getService('cache_manager')->getCache('dm_widget_feed_reader');
+    
+    $cacheKey = md5($url.$nb);
+
+    if ($cache->has($cacheKey))
+    {
+      $items = $cache->get($cacheKey);
+    }
+    else
+    {
+      $items = array();
+    
+      $collection = $this->getItemCollection($url);
+
+      $collection = array_slice($collection, 0, $nb);
+      
+      foreach($collection as $item)
+      {
+        $items[] = $this->feedItemToArray($item);
+      }
+
+      $items = $this->context->getEventDispatcher()->filter(
+        new sfEvent($this, 'dm.widget_twitter_feed_reader_show.items', 
array('url' => $url, 'nb' => $nb)),
+        $items
+      )->getReturnValue();
+      
+      $cache->set($cacheKey, $items, $lifeTime);
+    }
+
+    return $items;
+  }
+
+  protected function getItemCollection($url)
+  {
+    $browser = $this->getService('web_browser');
+
+    if($browser->get($url)->responseIsError())
+    {
+      throw new dmException(sprintf('The given URL (%s) returns an error (%s: 
%s)', $url, $browser->getResponseCode(), $browser->getResponseMessage()));
+    }
+
+    return sfFeedPeer::createFromXml($browser->getResponseText(), 
$url)->getItems();
+  }
+
+  protected function feedItemToArray(sfFeedItem $item)
+  {
+    return array(
+      'title'       => $item->getTitle(),
+      'link'        => $item->getLink(),
+      'content'     => $item->getDescription() ? $item->getDescription() : 
$item->getContent(),
+      'pub_date'    => $item->getPubDate()
+    );
+  }
+  
+}
\ No newline at end of file

Added: 
plugins/dmWidgetFeedReaderPlugin/modules/dmWidget/templates/_dmWidgetFeedReaderShow.php
===================================================================
--- 
plugins/dmWidgetFeedReaderPlugin/modules/dmWidget/templates/_dmWidgetFeedReaderShow.php
                             (rev 0)
+++ 
plugins/dmWidgetFeedReaderPlugin/modules/dmWidget/templates/_dmWidgetFeedReaderShow.php
     2010-01-22 20:24:27 UTC (rev 27069)
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * An $item is an array containing:
+ * - title:       title of the feed item
+ * - link:        url of the feed item
+ * - content:     HTML content
+ * - pub_date:    item publication date
+ */
+
+echo £o('ul');
+
+foreach($items as $item)
+{
+  echo £('li',
+
+    // link to the feed page
+    £link($item['link'])->text($item['title'])->set('.feed_item_link').
+
+    // render truncated feed content
+    £('div.feed_item_content', 
dmString::truncate(strip_tags($item['content']), 100))
+
+  );
+}
+
+echo £c('ul');
\ No newline at end of file


Property changes on: plugins/dmWidgetFeedReaderPlugin/nbproject
___________________________________________________________________
Added: svn:ignore
   + private


Added: plugins/dmWidgetFeedReaderPlugin/nbproject/project.properties
===================================================================
--- plugins/dmWidgetFeedReaderPlugin/nbproject/project.properties               
                (rev 0)
+++ plugins/dmWidgetFeedReaderPlugin/nbproject/project.properties       
2010-01-22 20:24:27 UTC (rev 27069)
@@ -0,0 +1,10 @@
+file.reference.workspace-diem=../diem
+include.path=\
+    ${php.global.include.path}:\
+    ${file.reference.workspace-diem}
+php.version=PHP_5
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=true
+web.root=.

Added: plugins/dmWidgetFeedReaderPlugin/nbproject/project.xml
===================================================================
--- plugins/dmWidgetFeedReaderPlugin/nbproject/project.xml                      
        (rev 0)
+++ plugins/dmWidgetFeedReaderPlugin/nbproject/project.xml      2010-01-22 
20:24:27 UTC (rev 27069)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1";>
+    <type>org.netbeans.modules.php.project</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/php-project/1";>
+            <name>dmWidgetFeedReaderPlugin</name>
+        </data>
+    </configuration>
+</project>

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to