25 use \Gino\App\Module\ModuleInstance;
27 require_once(
'class.Article.php');
28 require_once(
'class.Category.php');
46 class news extends \Gino\Controller {
96 parent::__construct($mdlId);
98 $this->_tbl_opt =
'news_opt';
100 $this->_optionsValue = array(
101 'last_news_number'=>3,
103 'showcase_news_number'=>5,
104 'showcase_auto_start'=>0,
105 'showcase_auto_interval'=>5000,
107 'newsletter_news_number'=>10,
110 $this->_last_news_number = $this->setOption(
'last_news_number', array(
'value'=>$this->_optionsValue[
'last_news_number']));
111 $this->_list_nfp = $this->setOption(
'list_nfp', array(
'value'=>$this->_optionsValue[
'list_nfp']));
112 $this->_showcase_news_number = $this->setOption(
'showcase_news_number', array(
'value'=>$this->_optionsValue[
'showcase_news_number']));
113 $this->_showcase_auto_start = $this->setOption(
'showcase_auto_start', array(
'value'=>$this->_optionsValue[
'showcase_auto_start']));
114 $this->_showcase_auto_interval = $this->setOption(
'showcase_auto_interval', array(
'value'=>$this->_optionsValue[
'showcase_auto_interval']));
115 $this->_image_width = $this->setOption(
'image_width', array(
'value'=>$this->_optionsValue[
'image_width']));
116 $this->_newsletter_news_number = $this->setOption(
'newsletter_news_number', array(
'value'=>$this->_optionsValue[
'newsletter_news_number']));
118 $this->_options =
new Options($this);
119 $this->_optionsLabels = array(
120 "last_news_number"=>array(
121 'label'=>_(
"Numero ultime news"),
122 'value'=>$this->_optionsValue[
'last_news_number'],
124 'section_title'=>_(
'Ultime news')
127 'label'=>_(
"Numero news per pagina"),
128 'value'=>$this->_optionsValue[
'list_nfp'],
130 'section_title'=>_(
'Archivio news')
132 "showcase_news_number"=>array(
133 'label'=>_(
"Numero news"),
134 'value'=>$this->_optionsValue[
'showcase_news_number'],
136 'section_title'=>_(
'Vetrina news')
138 "showcase_auto_start"=>array(
139 'label'=>_(
"Animazione automatica"),
140 'value'=>$this->_optionsValue[
'showcase_auto_start']
142 "showcase_auto_interval"=>array(
143 'label'=>_(
"Intervallo animazione automatica (ms)"),
144 'value'=>$this->_optionsValue[
'showcase_auto_start']
146 "image_width"=>array(
147 'label'=>_(
"Larghezza massima immagini"),
148 'value'=>$this->_optionsValue[
'image_width'],
150 'section_title'=>_(
'Media')
152 "newsletter_news_number"=>array(
153 'label'=>_(
"Numero news esportate nella lista"),
154 'value'=>$this->_optionsValue[
'newsletter_news_number'],
156 'section_title'=>_(
'Newsletter')
171 'news_article_category',
179 'archive.php' => _(
'Archivio news'),
180 'detail.php' => _(
'Dettaglio news'),
181 'last.php' => _(
'Lista ultime news'),
182 'showcase.php' => _(
'Vetrina news'),
183 'feed_rss.php' => _(
'Feed RSS'),
184 'newsletter.php' => _(
'News esportate in newsletter')
186 "folderStructure"=>array (
187 CONTENT_DIR.OS.
'news'=> array(
205 $this->requirePerm(
'can_admin');
208 Article::deleteInstance($this);
210 Category::deleteInstance($this);
213 $opt_id = $this->_db->getFieldFromId($this->_tbl_opt,
"id",
"instance", $this->_instance);
214 \Gino\Translation::deleteTranslations($this->_tbl_opt, $opt_id);
215 $result = $this->_db->delete($this->_tbl_opt,
"instance=".$this->_instance);
219 foreach($classElements[
'css'] as $css) {
220 unlink(APP_DIR.OS.$this->_class_name.OS.\Gino\baseFileName($css).
"_".$this->_instance_name.
".css");
224 foreach($classElements[
'views'] as $k => $v) {
225 unlink($this->_view_dir.OS.\Gino\baseFileName($k).
"_".$this->_instance_name.
".php");
229 foreach($classElements[
'folderStructure'] as $fld=>$fldStructure) {
230 \Gino\deleteFileDir($fld.OS.$this->_instance_name,
true);
247 "last" => array(
"label"=>_(
"Lista utime news"),
"permissions"=>array()),
248 "archive" => array(
"label"=>_(
"Lista news paginata"),
"permissions"=>array()),
249 "showcase" => array(
"label"=>_(
"Vetrina"),
"permissions"=>array()),
250 "feedRSS" => array(
"label"=>_(
"Feed RSS"),
"permissions"=>array())
273 $doc_id = cleanVar($request->GET,
'id',
'int');
275 $n =
new Article($doc_id, $this);
277 throw new \Gino\Exception\Exception404();
279 if($n->private && !$this->userHasPerm(
'can_view_private')) {
280 throw new \Gino\Exception\Exception403();
282 $attachment = $n->attachment;
284 $full_path = $this->getBaseAbsPath().OS.
'attachment'.OS.$attachment;
285 return \Gino\download($full_path);
288 throw new \Gino\Exception\Exception404();
292 throw new \Gino\Exception\Exception404();
302 if($this->userHasPerm(
'can_view_private')) {
309 $this->_registry->addCss($this->_class_www.
"/news_".$this->_instance_name.
".css");
310 $this->_registry->addJs($this->_class_www.
"/news.js");
312 $where_arr = array(
"instance='".$this->_instance.
"' AND published='1'");
314 $where_arr[] =
"private='0'";
317 $news = Article::objects($this, array(
'where' => implode(
' AND ', $where_arr),
'order'=>
'date DESC, insertion_date DESC',
'limit'=>array(0, $this->_showcase_news_number)));
319 $view =
new View($this->_view_dir);
321 $view->setViewTpl(
'showcase_'.$this->_instance_name);
323 'instance_name' => $this->_instance_name,
324 'feed_url' => $this->link($this->_instance_name,
'feedRSS'),
326 'autostart' => $this->_showcase_auto_start,
327 'autointerval' => $this->_showcase_auto_interval
330 return $view->render($dict);
339 $request = \Gino\Http\Request::instance();
341 $private = $this->userHasPerm(
'can_view_private') ? TRUE : FALSE;
343 $title_site = $this->_registry->sysconf->head_title;
344 $module =
new ModuleInstance($this->_instance);
345 $title = $module->label.
' | '.$title_site;
347 $this->_registry->addCss($this->_class_www.
"/news_".$this->_instance_name.
".css");
348 $this->_registry->addHeadLink(array(
349 'rel' =>
'alternate',
350 'type' =>
'application/rss+xml',
351 'title' => \
Gino\jsVar($title),
352 'href' => $request->root_absolute_url.$this->link($this->_instance_name,
'feedRSS')
355 $where_arr = array(
"published='1'");
357 $where_arr[] =
"private='0'";
360 $news = Article::objects($this, array(
'where' => implode(
' AND ', $where_arr),
'order'=>
'date DESC, insertion_date DESC',
'limit'=>array(0, $this->_last_news_number)));
362 $view =
new View($this->_view_dir,
'last_'.$this->_instance_name);
365 'instance_name' => $this->_instance_name,
367 'feed_url' => $this->link($this->_instance_name,
'feedRSS'),
368 'archive_url' => $this->link($this->_instance_name,
'archive')
371 return $view->render($dict);
384 $slug = \Gino\cleanVar($request->GET,
'id',
'string');
386 $item = Article::getFromSlug($slug, $this);
388 if(!$item || !$item->id || !$item->published) {
389 throw new \Gino\Exception\Exception404();
391 if($item->private && !$this->userHasPerm(
'can_view_private')) {
392 throw new \Gino\Exception\Exception403();
395 $this->_registry->addCss($this->_class_www.
"/news_".$this->_instance_name.
".css");
397 $view =
new view($this->_view_dir,
'detail_'.$this->_instance_name);
400 'instance_name' => $this->_instance_name,
403 'social' => \
Gino\shareAll(
'st_all_large', $this->link($this->_instance_name,
'detail', array(
'id' => $item->slug))),
406 $document = new \Gino\Document($view->render($dict));
418 $related_contents = GTag::getRelatedContents(
'Article', $item->id);
419 if(count($related_contents)) {
420 $view =
new View(null,
'related_contents_list');
421 return $view->render(array(
'related_contents' => $related_contents));
433 $this->_registry->addCss($this->_class_www.
"/news_".$this->_instance_name.
".css");
435 $ctgslug = \Gino\cleanVar($request->GET,
'ctg',
'string');
437 if($this->userHasPerm(
'can_view_private')) {
445 $ctg = Category::getFromSlug($ctgslug, $this);
446 $ctg_id = $ctg ? $ctg->id : 0;
453 $news_number =
Article::getCount($this, array(
'published' => TRUE,
'private'=>$private,
'ctg'=>$ctg_id));
455 $paginator = Loader::load(
'Paginator', array($news_number, $this->_list_nfp));
456 $limit = $paginator->limitQuery();
458 $where_arr = array(
"instance='".$this->_instance.
"' AND published='1'");
460 $where_arr[] =
"id IN (SELECT article_id FROM ".Article::$table_ctgs.
" WHERE category_id='".$ctg_id.
"')";
463 $where_arr[] =
"private='0'";
466 $news = Article::objects($this, array(
'where'=>implode(
' AND ', $where_arr),
'order'=>
'date DESC, insertion_date DESC',
'limit'=>$limit));
468 $view =
new View($this->_view_dir);
469 $view->setViewTpl(
'archive_'.$this->_instance_name);
471 'instance_name' => $this->_instance_name,
472 'feed_url' => $this->link($this->_instance_name,
'feedRSS'),
475 'pagination' => $paginator->pagination()
478 $document = new \Gino\Document($view->render($dict));
490 $this->requirePerm(array(
'can_admin',
'can_publish',
'can_write'));
492 $block = \Gino\cleanVar($request->GET,
'block',
'string');
494 $link_frontend = sprintf(
'<a href="%s">%s</a>', $this->linkAdmin(array(),
'block=frontend'), _(
'Frontend'));
495 $link_options = sprintf(
'<a href="%s">%s</a>', $this->linkAdmin(array(),
'block=options'), _(
'Opzioni'));
496 $link_ctg = sprintf(
'<a href="%s">%s</a>', $this->linkAdmin(array(),
'block=ctg'), _(
'Categorie'));
497 $link_dft = sprintf(
'<a href="%s">%s</a>', $this->linkAdmin(), _(
'Contenuti'));
498 $sel_link = $link_dft;
500 if($block ==
'frontend' && $this->userHasPerm(
'can_admin')) {
501 $backend = $this->manageFrontend();
502 $sel_link = $link_frontend;
504 elseif($block ==
'options' && $this->userHasPerm(
'can_admin')) {
505 $backend = $this->manageOptions();
506 $sel_link = $link_options;
508 elseif($block ==
'ctg') {
510 $sel_link = $link_ctg;
516 if(is_a($backend,
'\Gino\Http\Response')) {
521 if($this->userHasPerm(
'can_admin')) {
522 $links_array = array($link_frontend, $link_options, $link_ctg, $link_dft);
525 $links_array = array($link_ctg, $link_dft);
528 $module = ModuleInstance::getFromName($this->_instance_name);
530 $view =
new View(null,
'tab');
532 'title' => \
Gino\htmlChars($module->label),
533 'links' => $links_array,
534 'selected_link' => $sel_link,
535 'content' => $backend
538 $document = new \Gino\Document($view->render($dict));
550 $admin_table =
new AdminTable($this, array());
552 $backend = $admin_table->backOffice(
555 'list_display' => array(
'id',
'name',
'slug'),
556 'list_title' => _(
"Elenco categorie"),
557 'list_description' =>
"<p>"._(
'Ciascuna news inserita potrà essere associata ad una o più categorie qui definite.').
"</p>",
561 'description' => array(
562 'widget' =>
'editor',
564 'img_preview' => TRUE,
582 if(!$this->userHasPerm(
'can_admin') and !$this->userHasPerm(
'can_publish')) {
583 $remove_fields = array(
'published');
584 $delete_deny =
'all';
587 $remove_fields = array();
588 $delete_deny = array();
591 $admin_table =
new AdminTable($this, array(
'delete_deny'=>$delete_deny));
593 $backend = $admin_table->backOffice(
596 'list_display' => array(
'id',
'date',
'categories',
'title',
'published',
'private'),
597 'list_title' => _(
"Elenco news"),
598 'filter_fields' => array(
'categories',
'title',
'published')
601 'removeFields' => $remove_fields
605 'widget' =>
'editor',
607 'img_preview' => FALSE,
628 $private = $this->userHasPerm(
'can_view_private') ? TRUE : FALSE;
632 "selected_fields"=>array(
"id",
"slug",
"date", array(
"highlight"=>
true,
"field"=>
"title"), array(
"highlight"=>
true,
"field"=>
"text")),
633 "required_clauses"=>$private ? array(
"instance"=>$this->_instance,
'published'=>1) : array(
"instance"=>$this->_instance,
'private'=>0,
'published'=>1),
634 "weight_clauses"=>array(
"title"=>array(
"weight"=>3),
"text"=>array(
"weight"=>1))
646 $obj =
new Article($results[
'id'], $this);
648 $buffer =
"<div>".\Gino\dbDatetimeToDate($results[
'date'],
"/").
" <a href=\"".$this->link($this->_instance_name,
'detail', array(
'id'=>$results[
'slug'])).
"\">";
649 $buffer .= $results[
'title'] ? \Gino\htmlChars($results[
'title']) : \Gino\htmlChars($obj->ml(
'title'));
650 $buffer .=
"</a></div>";
652 if($results[
'text']) {
653 $buffer .=
"<div class=\"search_text_result\">...".\Gino\htmlChars($results[
'text']).
"...</div>";
656 $buffer .=
"<div class=\"search_text_result\">".\Gino\htmlChars(\
Gino\cutHtmlText($obj->ml(
'text'), 120,
'...',
false,
false,
false, array(
'endingPosition'=>
'in'))).
"</div>";
669 $news = Article::objects($this, array(
'where' =>
"instance='".$this->_instance.
"'",
'order'=>
'date DESC, insertion_date DESC',
'limit'=>array(0, $this->_newsletter_news_number)));
672 foreach($news as $n) {
675 _(
'titolo') => \
Gino\htmlChars($n->ml(
'title')),
676 _(
'privata') => $n->private ? _(
'si') : _(
'no'),
677 _(
'pubblicata') => $n->published ? _(
'si') : _(
'no'),
678 _(
'data') => \Gino\dbDateToDate($n->date),
694 $view =
new View($this->_view_dir,
'newsletter_'.$this->_instance_name);
699 return $view->render($dict);
710 $title_site = $this->_registry->sysconf->head_title;
711 $module =
new ModuleInstance($this->_instance);
712 $title = $module->label.
' | '.$title_site;
713 $description = $module->description;
715 $news = Article::objects($this, array(
'where' =>
"instance='".$this->_instance.
"' AND private='0' AND published='1'",
'order'=>
'date DESC, insertion_date DESC',
'limit'=>array(0, 50)));
717 $view = new \Gino\View($this->_view_dir,
'feed_rss_'.$this->_instance_name);
720 'description' => $description,
721 'request' => $request,
725 $response = new \Gino\Http\Response($view->render($dict));
726 $response->setContentType(
'text/xml');
searchSiteResult($results)
Definisce la presentazione del singolo item trovato a seguito di ricerca (modulo "Ricerca nel sito") ...
showcase()
Frontend vetrina news.
detail(\Gino\Http\Request $request)
Front end dettaglio news.
$_tbl_opt
Tabella di opzioni.
$_list_nfp
numero di news per pagina nella vista elenco news
archive(\Gino\Http\Request $request)
Frontend archivio news.
$_last_news_number
numero di ultime news
$_showcase_auto_interval
animazione vetrina intervallo animazione
getImageWidth()
Getter larghezza di ridimensionamenteo delle immagini.
systemNewsletterRender($id)
Contenuto di una news quanto inserita in una newsletter.
feedRSS(\Gino\Http\Request $request)
Genera un feed RSS standard che presenta le ultime 50 news pubblicate.
download(\Gino\Http\Request $request)
Esegue il download clientside del documento indicato da url ($doc_id)
searchSite()
Metodo per la definizione di parametri da utilizzare per il modulo "Ricerca nel sito".
static getCount($controller, $options=null)
Restituisce il numero di news che soddisfano le condizioni date.
manageCategory(\Gino\Http\Request $request)
Interfaccia di amministrazione delle categorie.
$_showcase_news_number
numero di news nella vetrina
static getClassElements()
Restituisce alcune proprietà della classe utili per la generazione di nuove istanze.
Classe tipo Gino.Model che rappresenta una singola news.
__construct($mdlId)
Costruisce un'istanza di tipo news.
relatedContentsList($item)
Lista di contenuti correlati per tag.
$_newsletter_news_number
Numero ultime news esportate in lista newsletter.
deleteInstance()
Eliminazione istanza.
manageNews(\Gino\Http\Request $request)
Interfaccia di amministrazione delle news.
Classe di tipo Gino.Controller per la gestione di news categorizzate.
last()
Front end ultime news.
static outputFunctions()
Definizione dei metodi pubblici che forniscono un output per il front-end.
$_showcase_auto_start
animazione vetrina start automatico
$_image_width
Massima larghezza immagini.
systemNewsletterList()
Adattatore per la classe newsletter.
manageDoc(\Gino\Http\Request $request)
Interfaccia di amministrazione del modulo.
Namespace dell'applicazione News