11.30
php
saved
fmic
Note
improved version of Automagic RSS Feed Generator's control file-> more control on each feed.
improved version of Automagic RSS Feed Generator's control file-> more control on each feed.
- <?php
- class RssController extends RssAppController {
- var $name = 'Rss';
- var $uses = '';
- var $model = null;
- function feed() {
- //check that a model is being requested
- //debug('No model was passed. The URL format should be /rss/model');
- //die;
- $this->passed_args[0] = 'bulletins';
- }
- //load the model
- $this->modelName = Inflector::classify($this->passed_args[0]);
- if (!loadModel($this->modelName)) {
- debug('Unable to load the requested model.');
- die;
- }
- $this->model = new $this->modelName();
- //check the model is allowed to be used as rss
- debug('You are not allowed to create a feed from this model.');
- die;
- }
- $conditions = null;
- $conditions = $this->model->feed['conditions'];
- }
- $orderby = 'created DESC';
- $orderby = $this->model->feed['orderby'];
- }
- $limit = '10';
- $limit = $this->model->feed['limit'];
- }
- $data = $this->model->findAll($conditions, null, $orderby, $limit);
- //organize the data
- foreach($data as $i => $item) {
- //set the title
- $temp['title'] = $this->__getValue($item, 'titleField', $this->titleFields);
- //set the desc
- $temp['desc'] = $this->__getValue($item, 'descField', $this->descFields);
- //skip the item if there is no title or desc
- continue;
- }
- //set the link
- $temp['link'] = str_ireplace("[%value]", $item[$this->model->name][$this->model->feed['link']['value']], $this->model->feed['link']['url']);
- //$temp['link'] = sprintf($this->model->feed['link'], $item[$this->model->name][$this->model->primaryKey]);
- } else {
- $temp['link'] = '/' . $this->model->name . '/view/' . $item[$this->model->name][$this->model->primaryKey];
- }
- $temp['created'] = $item[$this->model->name][$this->model->feed['created']];
- }else{
- $temp['created'] = $item[$this->model->name]['created'];
- }
- $rssData[] = $temp;
- }
- $this->set('rssData', $rssData);
- $this->set('feedTitle', Inflector::humanize(env('HTTP_HOST')) . ' Recent ' . Inflector::pluralize($this->model->name));
- $this->set('modelName', $this->model->name);
- $this->layout = '';
- $this->render('rss');
- }
- function __getValue($item, $element, $fields) {
- return $item[$m][$f];
- } else {
- return $item[$this->model->name][$this->model->feed[$element]];
- }
- }
- foreach($fields as $field) {
- $temp['title'] = $item[$this->model->name][$field];
- }
- }
- return '';
- }
- }
- ?>
Parsed in 0.220 seconds, using GeSHi 1.0.7.14