1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # Copyright (c) 2008 Olivier Azeau and contributors. All rights |
---|
4 | # reserved. |
---|
5 | # |
---|
6 | # This is free software; you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation; either version 2 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # This is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with DotClear; if not, write to the Free Software |
---|
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | # |
---|
20 | # ***** END LICENSE BLOCK ***** |
---|
21 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
22 | |
---|
23 | $__autoload['PostMakerSettings'] = dirname(__FILE__).'/PostMakerSettings.php'; |
---|
24 | |
---|
25 | $postMakerSettings = new PostMakerSettings(); |
---|
26 | foreach( $postMakerSettings->values as $name => $entry ) |
---|
27 | { |
---|
28 | $_menu['Blog']->addItem( |
---|
29 | __('New entry').' "'.$name.'"', // title |
---|
30 | 'post.php?customEntry='.urlencode($name), // url |
---|
31 | 'images/menu/edit.png', // img |
---|
32 | preg_match('/post.php(.*)$/',$_SERVER['REQUEST_URI']), // active |
---|
33 | $core->auth->check('usage,contentadmin',$core->blog->id) // show |
---|
34 | ); |
---|
35 | } |
---|
36 | |
---|
37 | $_menu['Plugins']->addItem( |
---|
38 | 'Post Maker', // title |
---|
39 | 'plugin.php?p=postMaker', // url |
---|
40 | 'index.php?pf=postMaker/icon.png', // img |
---|
41 | preg_match('/plugin.php\?p=postMaker/',$_SERVER['REQUEST_URI']), // active |
---|
42 | $core->auth->check('usage,contentadmin',$core->blog->id) // show |
---|
43 | ); |
---|
44 | |
---|
45 | $core->addBehavior('adminPostFormSidebar',array('PostMaker','FillPostContent')); |
---|
46 | |
---|
47 | define('DC_POST_MAKER_TPL_FOLDER',dirname(__FILE__).'/templates'); |
---|
48 | define('DC_POST_MAKER_TPL_CACHE',DC_TPL_CACHE.'/cbtpl/postMaker'); |
---|
49 | |
---|
50 | class PostMaker |
---|
51 | { |
---|
52 | public static function FillPostContent(&$post) |
---|
53 | { |
---|
54 | global $post_content, $post_format, $core; |
---|
55 | if( !empty($post_content ) ) |
---|
56 | return; |
---|
57 | if( !isset($_REQUEST['customEntry']) ) |
---|
58 | return; |
---|
59 | |
---|
60 | if (!is_dir(DC_POST_MAKER_TPL_CACHE)) |
---|
61 | mkdir(DC_POST_MAKER_TPL_CACHE); |
---|
62 | $core->postMakerTpl = new template(DC_POST_MAKER_TPL_CACHE,'$core->postMakerTpl'); |
---|
63 | $core->postMakerTpl->setPath( DC_POST_MAKER_TPL_FOLDER ); |
---|
64 | $core->postMakerTpl->addBlock('EntryTitle',array('PostMaker','EntryTitle')); |
---|
65 | $core->postMakerTpl->addBlock('EntryExcerpt',array('PostMaker','EntryExcerpt')); |
---|
66 | $core->postMakerTpl->addBlock('EntryContent',array('PostMaker','EntryContent')); |
---|
67 | $core->postMakerTpl->addValue('FeedURL',array('PostMaker','FeedURL')); |
---|
68 | $core->postMakerTpl->addValue('FeedProperty',array('PostMaker','FeedProperty')); |
---|
69 | $core->postMakerTpl->addBlock('FeedItems',array('PostMaker','FeedItems')); |
---|
70 | $core->postMakerTpl->addValue('FeedItemProperty',array('PostMaker','FeedItemProperty')); |
---|
71 | $core->postMakerTpl->addValue('FeedItemDate',array('PostMaker','FeedItemDate')); |
---|
72 | $core->postMakerTpl->addValue('FeedItemTime',array('PostMaker','FeedItemTime')); |
---|
73 | |
---|
74 | $templateTypes = array('xhtml'=>'hentry','wiki'=>'wentry'); |
---|
75 | $templateType = $templateTypes[$post_format]; |
---|
76 | |
---|
77 | $settings = new PostMakerSettings(); |
---|
78 | $entry = $settings->values[$_REQUEST['customEntry']]; |
---|
79 | |
---|
80 | global $postMakerHook; |
---|
81 | $postMakerHook = new stdClass(); |
---|
82 | $postMakerHook->url = $entry->feed; |
---|
83 | $postMakerHook->feed = feedReader::quickParse($entry->feed,DC_POST_MAKER_TPL_CACHE); |
---|
84 | |
---|
85 | global $post_title, $post_excerpt, $core; |
---|
86 | ob_start(); |
---|
87 | include $core->postMakerTpl->getFile($entry->TemplateFile()); |
---|
88 | ob_end_clean(); |
---|
89 | } |
---|
90 | |
---|
91 | public static function EntryTitle($attr,$content) |
---|
92 | { |
---|
93 | return '<?php |
---|
94 | ob_start(); |
---|
95 | ?>'. |
---|
96 | $content. |
---|
97 | '<?php $post_title = ob_get_contents(); ob_end_clean(); ?>'; |
---|
98 | } |
---|
99 | |
---|
100 | public static function EntryExcerpt($attr,$content) |
---|
101 | { |
---|
102 | return '<?php |
---|
103 | ob_start(); |
---|
104 | ?>'. |
---|
105 | $content. |
---|
106 | '<?php $post_excerpt = ob_get_contents(); ob_end_clean(); ?>'; |
---|
107 | } |
---|
108 | |
---|
109 | public static function EntryContent($attr,$content) |
---|
110 | { |
---|
111 | return '<?php |
---|
112 | ob_start(); |
---|
113 | ?>'. |
---|
114 | $content. |
---|
115 | '<?php $post_content = ob_get_contents(); ob_end_clean(); ?>'; |
---|
116 | } |
---|
117 | |
---|
118 | public static function FeedURL($attr) |
---|
119 | { |
---|
120 | return '<?php print $postMakerHook->url; ?>'; |
---|
121 | } |
---|
122 | |
---|
123 | public static function FeedProperty($attr) |
---|
124 | { |
---|
125 | if( !isset($attr['name']) ) |
---|
126 | return ''; |
---|
127 | return '<?php print $postMakerHook->feed->'.$attr['name'].'; ?>'; |
---|
128 | } |
---|
129 | |
---|
130 | public static function FeedItems($attr,$content) |
---|
131 | { |
---|
132 | return '<?php |
---|
133 | foreach ($postMakerHook->feed->items as $postMakerHook->item) : |
---|
134 | ?>'. |
---|
135 | $content. |
---|
136 | '<?php endforeach; unset($postMakerHook->item); ?>'; |
---|
137 | } |
---|
138 | |
---|
139 | public static function FeedItemProperty($attr) |
---|
140 | { |
---|
141 | if( !isset($attr['name']) ) |
---|
142 | return ''; |
---|
143 | return '<?php print $postMakerHook->item->'.$attr['name'].'; ?>'; |
---|
144 | } |
---|
145 | |
---|
146 | public static function FeedItemDate($attr) |
---|
147 | { |
---|
148 | return '<?php print dt::str($core->blog->settings->date_format,$postMakerHook->item->TS); ?>'; |
---|
149 | } |
---|
150 | |
---|
151 | public static function FeedItemTime($attr) |
---|
152 | { |
---|
153 | return '<?php print dt::str($core->blog->settings->time_format,$postMakerHook->item->TS); ?>'; |
---|
154 | } |
---|
155 | } |
---|
156 | ?> |
---|