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 | |
---|
13 | if (!defined('DC_RC_PATH')){return;} |
---|
14 | |
---|
15 | $core->addBehavior('initWidgets',array('efiMetadatasWidget','adminEFIM')); |
---|
16 | |
---|
17 | class 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 | '-' => '', |
---|
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 | } |
---|
55 | |
---|
56 | public static function publicEFIM($w) |
---|
57 | { |
---|
58 | global $core, $_ctx; |
---|
59 | |
---|
60 | # Not in post context |
---|
61 | if (!$_ctx->exists('posts') || !$_ctx->posts->post_id) return; |
---|
62 | |
---|
63 | # Not supported post type |
---|
64 | if (!in_array($_ctx->posts->post_type,array('post','gal','galitem'))) return ''; |
---|
65 | |
---|
66 | # Category limit |
---|
67 | if ($w->category == 'null' && $_ctx->posts->cat_id !== null) return; |
---|
68 | if ($w->category != 'null' && $w->category != '' && $w->category != $_ctx->posts->cat_id) return; |
---|
69 | |
---|
70 | # Content lookup |
---|
71 | $text = $_ctx->posts->post_excerpt_xhtml.$_ctx->posts->post_content_xhtml; |
---|
72 | |
---|
73 | # Find source image |
---|
74 | $img = efiMetadatas::imgSource($core,$text,$w->thumbsize); |
---|
75 | |
---|
76 | # No image |
---|
77 | if (!$img['source']) return; |
---|
78 | |
---|
79 | # List metas |
---|
80 | $metas = efiMetadatas::imgMeta($core,$img['source']); |
---|
81 | |
---|
82 | $content = ''; |
---|
83 | foreach($metas as $k => $v) |
---|
84 | { |
---|
85 | // keep empty meta if wanted |
---|
86 | if (!$w->showmeta && empty($v[1])) continue; |
---|
87 | $content .= '<li class="efi-'.$k.'"><strong>'.$v[0].':</strong><br />'.$v[1].'</li>'; |
---|
88 | } |
---|
89 | |
---|
90 | # No meta |
---|
91 | if (empty($content)) return; |
---|
92 | |
---|
93 | # thumbnail |
---|
94 | if ($img['thumb']) |
---|
95 | { |
---|
96 | $thumb = |
---|
97 | '<div class="img-box">'. |
---|
98 | '<div class="img-thumbnail">'. |
---|
99 | '<img alt="'.$img['title'].'" src="'.$img['thumb'].'" />'. |
---|
100 | '</div>'. |
---|
101 | "</div>\n"; |
---|
102 | } |
---|
103 | |
---|
104 | return |
---|
105 | '<div class="entryFirstImageMetas">'. |
---|
106 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
107 | $thumb. |
---|
108 | '<ul>'.$content.'</ul>'. |
---|
109 | '</div>'; |
---|
110 | } |
---|
111 | } |
---|
112 | ?> |
---|