Skip to content

Commit

Permalink
Tell EE about widgets' package paths before calling their index() fun…
Browse files Browse the repository at this point in the history
…ction, so $EE->load->view(), et al. work from within widgets, and move the RSS widget’s view code to views/widgets/feed_reader.php to celebrate!
  • Loading branch information
Brandon Kelly committed Sep 11, 2011
1 parent 1f40e08 commit beaca17
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
21 changes: 21 additions & 0 deletions third_party/dashee/mcp.dashee.php
Expand Up @@ -146,6 +146,25 @@ public function get_widget_listing()
exit();
}

/**
* Add Widget's Package Path
*
* Makes it possible for widgets to use $EE->load->view(), etc
*
* Should be called right before calling a widget's index() funciton
*/
private function _add_widget_package_path($name)
{
$path = PATH_THIRD . $name . '/';
$this->_EE->load->add_package_path($path);

// manually add the view path if this is less than EE 2.1.5
if (version_compare(APP_VER, '2.1.5', '<'))
{
$this->_EE->load->_ci_view_path = $path . 'views/';
}
}

/**
* Add selected widget to users dashboard and update config.
*
Expand Down Expand Up @@ -290,6 +309,7 @@ public function update_settings()
$this->_update_member(FALSE);

$obj = $this->_get_widget_object($widget['mod'],$widget['wgt']);
$this->_add_widget_package_path($widget['mod']);
$content = $obj->index(json_decode($settings_json));
$result = array(
'title' => $obj->title,
Expand Down Expand Up @@ -393,6 +413,7 @@ private function _widget_loader(array $widgets)
}
else
{
$this->_add_widget_package_path($params['mod']);
$content = $obj->index(@json_decode($params['stng']));
}

Expand Down
16 changes: 16 additions & 0 deletions third_party/dashee/views/widgets/feed_reader.php
@@ -0,0 +1,16 @@
<ul>
<?php
$i = 0;

foreach ($rss->channel->item as $key => $item):
if ($i++ >= $num) break;
$title = trim($item->title);
$link = trim($item->link);
?>
<li class="item" title="<?=str_replace('"', '&quot;"', $title)?>">
<a href="<?=$link?>" target="_blank"><?=$title?></a>
</li>
<?php
endforeach
?>
</ul>
29 changes: 8 additions & 21 deletions third_party/dashee/widgets/wgt.feed_reader.php
Expand Up @@ -43,27 +43,14 @@ public function index($settings = NULL)
$EE = get_instance();
$EE->load->helper('text');

$rss = simplexml_load_file($settings->url);

$display = '';
$i = 0;
foreach($rss->channel->item as $key => $item)
{
if($i >= $settings->num) { break; }

$link = trim($item->link);
$title = trim($item->title);

$display .= '<li class="item" title="'.str_replace('"', '&quot;"', $title).'">'.anchor($link, $title, 'target="_blank"').'</li>';

++$i;
}

$this->title = ellipsize($rss->channel->title, 19, 1);

return '
<ul>'.$display.'</ul>
';
$rss = simplexml_load_file($settings->url);

$this->title = (string) $rss->channel->title;

$vars['rss'] = $rss;
$vars['num'] = $settings->num;

return $EE->load->view('widgets/feed_reader', $vars, TRUE);
}

/**
Expand Down

0 comments on commit beaca17

Please sign in to comment.