.

GsitemapController Class Reference
[GSitemap]

Controls building and rendering of sitemap. More...

Inheritance diagram for GsitemapController:
ControllerBase IController IEventSink

List of all members.

Public Member Functions

  action_gsitemap_index ($page_data)
  Show a sitemap index.
  action_gsitemap_index_html ($page_data)
  Show sitemap index as HTML.
  action_gsitemap_site ($page_data)
  Show a sitemap site.
  action_gsitemap_site_html ($page_data)
  Show sitemap file as HTML.
  before_action ()
  Activates includes before action to reduce cache memory.
  get_routes ()
  Return array of IDispatchToken this controller takes responsability.

Static Public Member Functions

static  build_sitemap ($params, $index, $itemsperfile=self::ITEMS_PER_FILE, $policy=self::USE_TIMESTAMP)
  Build a sitemap file for given model.
static  build_sitemap_for_model (GSiteMapModel $model, $index)
  Build a sitemap file for given sitemap model.
static  build_sitemap_index ($params, $itemsperfile=self::ITEMS_PER_FILE)
  Helper to build sitemap index for given dao class.
static  build_sitemap_index_for_model (GSiteMapModel $model)
  Helper to build sitemap index for given sitemap model.

Public Attributes

const  ITEMS_PER_FILE = 300
const  NO_TIMESTAMP = 0
const  USE_TIMESTAMP = 1

Protected Member Functions

  collect_models ()
  gsitemap_index (PageData $page_data, IView $view)
  Colelct data for index.
  gsitemap_site (PageData $page_data, IView $view)
  Show a sitemap site.

Detailed Description

Controls building and rendering of sitemap.

Author:
Gerd Riesselmann

Definition at line 8 of file gsitemap.controller.php.


Member Function Documentation

GsitemapController::action_gsitemap_index ( page_data  ) 

Show a sitemap index.

Parameters:
PageData  $page_data

Definition at line 42 of file gsitemap.controller.php.

00042                                                           {
00043                 $view = ViewFactory::create_view(IViewFactory::XML, 'core::gsitemap/index', $page_data);
00044                 $this->gsitemap_index($page_data, $view);
00045                 $view->render();
00046         }
GsitemapController::action_gsitemap_index_html ( page_data  ) 

Show sitemap index as HTML.

Parameters:
PageData  $page_data

Definition at line 72 of file gsitemap.controller.php.

00072                                                                {
00073                 $view = ViewFactory::create_view(IViewFactory::CONTENT, 'core::gsitemap/index_html', $page_data);
00074                 $ret = $this->gsitemap_index($page_data, $view);
00075                 $view->render();
00076                 return $ret;
00077         }
GsitemapController::action_gsitemap_site ( page_data  ) 

Show a sitemap site.

Parameters:
PageData  $page_data
Returns:
mixed

Definition at line 54 of file gsitemap.controller.php.

00054                                                          {
00055                 // Somehat hackish. Let two routes work on same path
00056                 if ($page_data->get_get()->count() == 0) {
00057                         return $this->action_gsitemap_index($page_data); 
00058                 }
00059                 $view = ViewFactory::create_view(IViewFactory::XML, 'core::gsitemap/site', $page_data);
00060                 $ret = $this->gsitemap_site($page_data, $view);
00061                 if ($ret === self::OK) {
00062                         $view->render();
00063                 }
00064                 return $ret;
00065         }  
GsitemapController::action_gsitemap_site_html ( page_data  ) 

Show sitemap file as HTML.

Parameters:
PageData  $page_data

Definition at line 84 of file gsitemap.controller.php.

00084                                                               {
00085                 // Somehat hackish. Let two routes work on same path
00086                 if ($page_data->get_get()->count() == 0) {
00087                         return $this->action_gsitemap_index_html($page_data); 
00088                 }
00089                 $view = ViewFactory::create_view(IViewFactory::CONTENT, 'core::gsitemap/site_html', $page_data);
00090                 $ret = $this->gsitemap_site($page_data, $view);
00091                 if ($ret === self::OK) {
00092                         $view->render();
00093                 }
00094                 return $ret;
00095         }
GsitemapController::before_action (  ) 

Activates includes before action to reduce cache memory.

Reimplemented from ControllerBase.

Definition at line 33 of file gsitemap.controller.php.

00033                                         {
00034                 Load::components('gsitemapmodel', 'gsitemapitemformatter');
00035         }               
static GsitemapController::build_sitemap ( params,
index,
itemsperfile = self::ITEMS_PER_FILE,
policy = self::USE_TIMESTAMP  
) [static]

Build a sitemap file for given model.

Parameters:
string|ISearchAdapter  $params If a string, it is interpreted as a model name If ISearchAdapter limit() and execute() are executed upon the instance
string  $index
int  $itemsperfile Number of items per sitemap file
Returns:
array

Definition at line 223 of file gsitemap.controller.php.

00223                                                                                                                                {
00224                 if ($itemsperfile <= 0) {
00225                         $itemsperfile = self::ITEMS_PER_FILE;
00226                 }
00227                 $model = new GSiteMapModel($params, 'view', $policy);
00228                 $model->items_per_file = $itemsperfile;
00229                 return self::build_sitemap_for_model($model, $index); 
00230         }               
static GsitemapController::build_sitemap_for_model ( GSiteMapModel model,
index  
) [static]

Build a sitemap file for given sitemap model.

Parameters:
GSiteMapModel  $model The model rules
string  $index
Returns:
array

Definition at line 240 of file gsitemap.controller.php.

00240                                                                                      {
00241                 $ret = array();
00242                 $chunk = $model->extract_chunk($index);
00243                 if ($chunk !== false) {
00244                         $dao = $model->create_adapter();
00245                         $model->select_chunk($dao, $chunk);
00246                 
00247                         $dao->find();
00248                         while($dao->fetch()) {
00249                                 $ret[] = $model->create_formatter($dao);
00250                         }
00251                 }
00252                 return $ret;
00253         }               
static GsitemapController::build_sitemap_index ( params,
itemsperfile = self::ITEMS_PER_FILE  
) [static]

Helper to build sitemap index for given dao class.

Parameters:
string|ISearchAdapter  $params If a string, it is interpreted as a model name If ISearchAdapter limit() and execute() are executed uipen the insance
integer  $itemsperfile Number of items per sitemap file
Returns:
array

Definition at line 187 of file gsitemap.controller.php.

00187                                                                                                 {
00188                 if ($itemsperfile <= 0) {
00189                         $itemsperfile = self::ITEMS_PER_FILE;
00190                 }
00191                 $model = new GSiteMapModel($params);
00192                 $model->items_per_file = $itemsperfile;
00193                 return self::build_sitemap_index_for_model($model);             
00194         }
static GsitemapController::build_sitemap_index_for_model ( GSiteMapModel model  )  [static]

Helper to build sitemap index for given sitemap model.

Parameters:
GSiteMapModel  $model
Returns:
array

Definition at line 203 of file gsitemap.controller.php.

00203                                                                                    {
00204                 $ret = array();
00205                 $c = $model->get_number_of_chunks();
00206                 for($i = 0; $i < $c; $i++) {
00207                         $ret[] = $model->build_index_name($i);
00208                 }
00209                 return $ret;            
00210         }       
GsitemapController::collect_models (  )  [protected]

Definition at line 97 of file gsitemap.controller.php.

00097                                             {
00098                 $ret = array();
00099                 $models = array();
00100                 EventSource::Instance()->invoke_event('gsitemap_models', null, $models);
00101                 foreach($models as $model) {
00102                         if ($model instanceof GSiteMapModel) {
00103                                 $ret[] = $model;
00104                         }
00105                         else {
00106                                 $ret[] = new GSiteMapModel($model);
00107                         }
00108                 }
00109                 return $ret;
00110         }
GsitemapController::get_routes (  ) 

Return array of IDispatchToken this controller takes responsability.

Reimplemented from ControllerBase.

Definition at line 16 of file gsitemap.controller.php.

00016                                      {
00017                 $ret = array(
00018                         new ExactMatchRoute('sitemap.xml', $this, 'gsitemap_site', new SimpleCacheManager()),
00019                         new ExactMatchRoute('sitemap.xml', $this, 'gsitemap_index', new SimpleCacheManager()),
00020                         new ExactMatchRoute('sitemapindex.xml', $this, '', new RedirectRenderDecorator('sitemap.xml')),
00021                 );
00022                 if (Config::has_feature(ConfigGSitemap::GSITEMAP_HTML_SITEMAP)) {
00023                         $ret[] = new ExactMatchRoute('sitemap.html', $this, 'gsitemap_site_html', new SimpleCacheManager());                            
00024                         $ret[] = new ExactMatchRoute('sitemap.html', $this, 'gsitemap_index_html', new SimpleCacheManager());
00025                         $ret[] = new ExactMatchRoute('sitemapindex.html', $this, '', new RedirectRenderDecorator('sitemap.html'));
00026                 }
00027                 return $ret;            
00028         }
GsitemapController::gsitemap_index ( PageData page_data,
IView view  
) [protected]

Colelct data for index.

Definition at line 115 of file gsitemap.controller.php.

00115                                                                             {
00116                 $arrret = array('main');
00117                 $models = $this->collect_models();
00118                 foreach($models as $model) {
00119                         $arrret = array_merge($arrret, self::build_sitemap_index_for_model($model));
00120                 }
00121                 EventSource::Instance()->invoke_event('gsitemap_index', null, $arrret);
00122                 $view->assign('files', $arrret); 
00123         }
GsitemapController::gsitemap_site ( PageData page_data,
IView view  
) [protected]

Show a sitemap site.

Parameters:
PageData  $page_data
Returns:
mixed

Definition at line 131 of file gsitemap.controller.php.

00131                                                                            {
00132                 $p = $page_data->get_get()->get_item('i');
00133                 if (empty($p)) {
00134                         return self::NOT_FOUND;
00135                 }
00136                 $arrret = array();
00137                 if ($p == 'main') {
00138                         $arrret[] = new GSiteMapItemFormatter(Config::get_url(Config::URL_BASEURL), array());
00139                 }
00140                 else {
00141                         $models = $this->collect_models();
00142                         foreach($models as $model) {
00143                                 $arrret = array_merge($arrret, self::build_sitemap_for_model($model, $p));
00144                         }
00145                 }
00146                 EventSource::Instance()->invoke_event('gsitemap_site', $p, $arrret);
00147                 if (count($arrret) == 0) {
00148                         return self::NOT_FOUND;
00149                 }
00150                 $formatters = array();
00151                 foreach($arrret as $item) {
00152                         if ($item instanceof GSiteMapItemFormatter) {
00153                                 $formatters[] = $item;
00154                         } else if (is_array($item)) {
00155                                 $formatters[] = new GSiteMapItemFormatter($item['url'], $item);
00156                         } else {
00157                                 $formatters[] = new GSiteMapItemFormatter($item, array());
00158                         }
00159                 }
00160                 $view->assign('items', $formatters);
00161                 return self::OK;
00162         }  

Member Data Documentation

Definition at line 9 of file gsitemap.controller.php.

Definition at line 11 of file gsitemap.controller.php.

Definition at line 10 of file gsitemap.controller.php.


The documentation for this class was generated from the following file: