Dotclear

source: plugins/efiMetadatas/_widgets.php @ 3360

Revision 3360, 3.1 KB checked in by brol, 8 years ago (diff)

voir changelog

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of efiMetadatas, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009-2015 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13if (!defined('DC_RC_PATH')){return;}
14
15$core->addBehavior('initWidgets',array('efiMetadatasWidget','adminEFIM'));
16
17class efiMetadatasWidget
18{
19     public static function adminEFIM($w)
20     {
21          global $core;
22         
23          $categories_combo = array('-' => '', __('Uncategorized') => 'null');
24          $categories = $core->blog->getCategories();
25          while($categories->fetch())
26          {
27               $cat_title = html::escapeHTML($categories->cat_title);
28               $categories_combo[$cat_title] = $categories->cat_id;
29          }
30         
31          $thumbnail_combo = array(
32      __('None') => '',
33               __('square') => 'sq',
34               __('thumbnail') => 't',
35               __('small') => 's',
36               __('medium') => 'm'
37          );
38         
39          $w->create('efim',
40               __('EfiMetadatas'),array('efiMetadatasWidget','publicEFIM'),
41               null,
42               __('Entry first image metadatas'));
43          $w->efim->setting('title',
44               __('Title:'),__('Image infos'),'text'
45          );
46          $w->efim->setting('category',
47               __('Category limit:'),'','combo',$categories_combo
48          );
49          $w->efim->setting('thumbsize',
50               __('Thumbnail size:'),'','combo',$thumbnail_combo
51          );
52          $w->efim->setting('showmeta',
53               __('Show empty metadatas'),0,'check'
54          );
55    $w->efim->setting('content_only',__('Content only'),0,'check');
56    $w->efim->setting('class',__('CSS class:'),'');
57          $w->efim->setting('offline',__('Offline'),0,'check');
58     }
59     
60     public static function publicEFIM($w)
61     {
62          global $core, $_ctx;
63
64          if ($w->offline)
65               return;
66         
67          # Not in post context
68          if (!$_ctx->exists('posts') || !$_ctx->posts->post_id) return;
69         
70          # Not supported post type
71          if (!in_array($_ctx->posts->post_type,array('post','gal','galitem'))) return '';
72         
73          # Category limit
74          if ($w->category == 'null' && $_ctx->posts->cat_id !== null) return;
75          if ($w->category != 'null' && $w->category != '' && $w->category != $_ctx->posts->cat_id) return;
76         
77          # Content lookup
78          $text = $_ctx->posts->post_excerpt_xhtml.$_ctx->posts->post_content_xhtml;
79         
80          # Find source image
81          $img = efiMetadatas::imgSource($core,$text,$w->thumbsize);
82         
83          # No image
84          if (!$img['source']) return;
85         
86          # List metas
87          $metas = efiMetadatas::imgMeta($core,$img['source']);
88         
89          $content = '';
90          foreach($metas as $k => $v)
91          {
92               // keep empty meta if wanted
93               if (!$w->showmeta && empty($v[1])) continue;
94               $content .= '<li class="efi-'.$k.'"><strong>'.$v[0].'</strong><br />'.$v[1].'</li>';
95          }
96         
97          # No meta
98          if (empty($content)) return;
99         
100          # thumbnail
101          $thumb = '';
102          if ($img['thumb'])
103          {
104               $thumb =
105               '<li><img class="img-thumbnail" alt="'.$img['title'].'" src="'.$img['thumb'].'" /></li>';
106          }
107
108          $res =
109          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
110          '<ul>'.$thumb.$content.'</ul>';
111
112          return $w->renderDiv($w->content_only,'entryFirstImageMetas '.$w->class,'',$res);
113     }
114}
Note: See TracBrowser for help on using the repository browser.

Sites map