Skip to content
Extraits de code Groupes Projets
Valider 8f4dc7fc rédigé par Fabian Becker's avatar Fabian Becker
Parcourir les fichiers

Split up classes to separate files.

This is an example plugin and it should serve as a good example :)
parent f56c9d65
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package Piwik_ExampleRssWidget
*/
/**
*
* @package Piwik_ExampleRssWidget
*/
class Piwik_ExampleRssWidget_Controller extends Piwik_Controller
{
function rssPiwik()
{
try {
$rss = new Piwik_ExampleRssWidget_Rss('http://feeds.feedburner.com/Piwik');
$rss->showDescription(true);
echo $rss->get();
} catch(Exception $e) {
$this->error($e);
}
}
function rssChangelog()
{
try {
$rss = new Piwik_ExampleRssWidget_Rss('http://feeds.feedburner.com/PiwikReleases');
$rss->setCountPosts(1);
$rss->showDescription(false);
$rss->showContent(true);
echo $rss->get();
} catch(Exception $e) {
$this->error($e);
}
}
protected function error($e)
{
echo '<div class="pk-emptyDataTable">'
. Piwik_Translate('General_ErrorRequest')
. ' - ' . $e->getMessage() . '</div>';
}
}
......@@ -55,103 +55,4 @@ class Piwik_ExampleRssWidget extends Piwik_Plugin
Piwik_AddWidget('Example Widgets', 'Piwik.org Blog', 'ExampleRssWidget', 'rssPiwik');
Piwik_AddWidget('Example Widgets', 'Piwik Changelog', 'ExampleRssWidget', 'rssChangelog');
}
}
/**
*
* @package Piwik_ExampleRssWidget
*/
class Piwik_ExampleRssWidget_Controller extends Piwik_Controller
{
function rssPiwik()
{
try {
$rss = new Piwik_ExampleRssWidget_Rss('http://feeds.feedburner.com/Piwik');
$rss->showDescription(true);
echo $rss->get();
} catch(Exception $e) {
$this->error($e);
}
}
function rssChangelog()
{
try {
$rss = new Piwik_ExampleRssWidget_Rss('http://feeds.feedburner.com/PiwikReleases');
$rss->setCountPosts(1);
$rss->showDescription(false);
$rss->showContent(true);
echo $rss->get();
} catch(Exception $e) {
$this->error($e);
}
}
protected function error($e)
{
echo '<div class="pk-emptyDataTable">'
. Piwik_Translate('General_ErrorRequest')
. ' - ' . $e->getMessage() . '</div>';
}
}
/**
*
* @package Piwik_ExampleRssWidget
*/
class Piwik_ExampleRssWidget_Rss
{
protected $url = null;
protected $count = 3;
protected $showDescription = false;
protected $showContent = false;
function __construct($url)
{
$this->url = $url;
}
function showDescription($bool)
{
$this->showDescription = $bool;
}
function showContent($bool)
{
$this->showContent = $bool;
}
function setCountPosts($count)
{
$this->count = $count;
}
function get()
{
try {
$rss = Zend_Feed::import($this->url);
} catch (Zend_Feed_Exception $e) {
echo "Error while importing feed: {$e->getMessage()}\n";
exit;
}
$output = '<div style="padding:10px 15px;"><ul class="rss">';
$i = 0;
foreach($rss as $post)
{
$title = $post->title();
$date = @strftime("%B %e, %Y", strtotime($post->pubDate()));
$link = $post->link();
$output .= '<li><a class="rss-title" title="" target="_blank" href="?module=Proxy&action=redirect&url='.$link.'">'.$title.'</a>'.
'<span class="rss-date">'.$date.'</span>';
if($this->showDescription)
{
$output .= '<div class="rss-description">'.$post->description().'</div>';
}
if($this->showContent)
{
$output .= '<div class="rss-content">'.$post->content().'</div>';
}
$output .= '</li>';
if(++$i == $this->count) break;
}
$output .= '</ul></div>';
return $output;
}
}
}
\ No newline at end of file
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package Piwik_ExampleRssWidget
*/
/**
*
* @package Piwik_ExampleRssWidget
*/
class Piwik_ExampleRssWidget_Rss
{
protected $url = null;
protected $count = 3;
protected $showDescription = false;
protected $showContent = false;
function __construct($url)
{
$this->url = $url;
}
function showDescription($bool)
{
$this->showDescription = $bool;
}
function showContent($bool)
{
$this->showContent = $bool;
}
function setCountPosts($count)
{
$this->count = $count;
}
function get()
{
try {
$rss = Zend_Feed::import($this->url);
} catch (Zend_Feed_Exception $e) {
echo "Error while importing feed: {$e->getMessage()}\n";
exit;
}
$output = '<div style="padding:10px 15px;"><ul class="rss">';
$i = 0;
foreach($rss as $post)
{
$title = $post->title();
$date = @strftime("%B %e, %Y", strtotime($post->pubDate()));
$link = $post->link();
$output .= '<li><a class="rss-title" title="" target="_blank" href="?module=Proxy&action=redirect&url='.$link.'">'.$title.'</a>'.
'<span class="rss-date">'.$date.'</span>';
if($this->showDescription)
{
$output .= '<div class="rss-description">'.$post->description().'</div>';
}
if($this->showContent)
{
$output .= '<div class="rss-content">'.$post->content().'</div>';
}
$output .= '</li>';
if(++$i == $this->count) break;
}
$output .= '</ul></div>';
return $output;
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter