Dotclear

source: plugins/efiMetadatas/_widgets.php @ 3329

Revision 3329, 3.0 KB checked in by brol, 8 years ago (diff)

voir release.txt

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of efiMetadatas, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009-2010 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               __('Entry first image metadatas'),array('efiMetadatasWidget','publicEFIM')
41          );
42          $w->efim->setting('title',
43               __('Title:'),__('Image infos'),'text'
44          );
45          $w->efim->setting('category',
46               __('Category limit:'),'','combo',$categories_combo
47          );
48          $w->efim->setting('thumbsize',
49               __('Thumbnail size:'),'','combo',$thumbnail_combo
50          );
51          $w->efim->setting('showmeta',
52               __('Show empty metadatas'),0,'check'
53          );
54    $w->efim->setting('content_only',__('Content only'),0,'check');
55    $w->efim->setting('class',__('CSS class:'),'');
56          $w->efim->setting('offline',__('Offline'),0,'check');
57     }
58     
59     public static function publicEFIM($w)
60     {
61          global $core, $_ctx;
62
63          if ($w->offline)
64               return;
65         
66          # Not in post context
67          if (!$_ctx->exists('posts') || !$_ctx->posts->post_id) return;
68         
69          # Not supported post type
70          if (!in_array($_ctx->posts->post_type,array('post','gal','galitem'))) return '';
71         
72          # Category limit
73          if ($w->category == 'null' && $_ctx->posts->cat_id !== null) return;
74          if ($w->category != 'null' && $w->category != '' && $w->category != $_ctx->posts->cat_id) return;
75         
76          # Content lookup
77          $text = $_ctx->posts->post_excerpt_xhtml.$_ctx->posts->post_content_xhtml;
78         
79          # Find source image
80          $img = efiMetadatas::imgSource($core,$text,$w->thumbsize);
81         
82          # No image
83          if (!$img['source']) return;
84         
85          # List metas
86          $metas = efiMetadatas::imgMeta($core,$img['source']);
87         
88          $content = '';
89          foreach($metas as $k => $v)
90          {
91               // keep empty meta if wanted
92               if (!$w->showmeta && empty($v[1])) continue;
93               $content .= '<li class="efi-'.$k.'"><strong>'.$v[0].'</strong><br />'.$v[1].'</li>';
94          }
95         
96          # No meta
97          if (empty($content)) return;
98         
99          # thumbnail
100          if ($img['thumb'])
101          {
102               $thumb =
103               '<li><img class="img-thumbnail" alt="'.$img['title'].'" src="'.$img['thumb'].'" /></li>';
104          }
105
106          $res =
107          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
108          '<ul>'.$thumb.$content.'</ul>';
109
110          return $w->renderDiv($w->content_only,'entryFirstImageMetas '.$w->class,'',$res);
111     }
112}
Note: See TracBrowser for help on using the repository browser.

Sites map