Dotclear

source: plugins/postMaker/trunk/_admin.php @ 400

Revision 400, 5.0 KB checked in by Oaz, 16 years ago (diff)

postMaker 1.0 RC

Line 
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
22$__autoload['PostMakerSettings'] = dirname(__FILE__).'/PostMakerSettings.php';
23
24$postMakerSettings = new PostMakerSettings();
25foreach( $postMakerSettings->values as $name => $entry )
26{
27  $_menu['Blog']->addItem(
28    __('New entry').' "'.$name.'"', // title
29    'post.php?customEntry='.urlencode($name), // url
30    'images/menu/edit.png',  // img
31    preg_match('/post.php(.*)$/',$_SERVER['REQUEST_URI']), // active
32    $core->auth->check('usage,contentadmin',$core->blog->id) // show
33  );
34}
35
36$_menu['Plugins']->addItem(
37  'Post Maker', // title
38  'plugin.php?p=postMaker', // url
39  'index.php?pf=postMaker/icon.png',  // img
40  preg_match('/plugin.php\?p=postMaker/',$_SERVER['REQUEST_URI']), // active
41  $core->auth->check('usage,contentadmin',$core->blog->id) // show
42);
43
44$core->addBehavior('adminPostFormSidebar',array('PostMaker','FillPostContent'));
45
46define('DC_POST_MAKER_TPL_FOLDER',dirname(__FILE__).'/templates');
47define('DC_POST_MAKER_TPL_CACHE',DC_TPL_CACHE.'/cbtpl/postMaker');
48
49class PostMaker
50{
51  public static function FillPostContent(&$post)
52  {
53    global $post_content, $post_format, $core;
54    if( !empty($post_content ) )
55      return;
56    if( !isset($_REQUEST['customEntry']) )
57      return;
58     
59    if (!is_dir(DC_POST_MAKER_TPL_CACHE))
60               mkdir(DC_POST_MAKER_TPL_CACHE);
61    $core->postMakerTpl = new template(DC_POST_MAKER_TPL_CACHE,'$core->postMakerTpl');
62    $core->postMakerTpl->setPath( DC_POST_MAKER_TPL_FOLDER );
63    $core->postMakerTpl->addBlock('EntryTitle',array('PostMaker','EntryTitle'));
64    $core->postMakerTpl->addBlock('EntryExcerpt',array('PostMaker','EntryExcerpt'));
65    $core->postMakerTpl->addBlock('EntryContent',array('PostMaker','EntryContent'));
66    $core->postMakerTpl->addValue('FeedURL',array('PostMaker','FeedURL'));
67    $core->postMakerTpl->addValue('FeedProperty',array('PostMaker','FeedProperty'));
68    $core->postMakerTpl->addBlock('FeedItems',array('PostMaker','FeedItems'));
69    $core->postMakerTpl->addValue('FeedItemProperty',array('PostMaker','FeedItemProperty'));
70    $core->postMakerTpl->addValue('FeedItemDate',array('PostMaker','FeedItemDate'));
71    $core->postMakerTpl->addValue('FeedItemTime',array('PostMaker','FeedItemTime'));
72   
73    $templateTypes = array('xhtml'=>'hentry','wiki'=>'wentry');
74    $templateType = $templateTypes[$post_format];
75   
76    $settings = new PostMakerSettings();
77    $entry = $settings->values[$_REQUEST['customEntry']];
78   
79    global $postMakerHook;
80    $postMakerHook = new stdClass();
81          $postMakerHook->url = $entry->feed;
82          $postMakerHook->feed = feedReader::quickParse($entry->feed,DC_POST_MAKER_TPL_CACHE);
83   
84    global $post_title, $post_excerpt, $core;
85    ob_start();
86          include $core->postMakerTpl->getFile($entry->TemplateFile());
87          ob_end_clean();
88  }
89
90  public static function EntryTitle($attr,$content)
91  {
92    return '<?php
93    ob_start();
94    ?>'.
95    $content.
96    '<?php $post_title = ob_get_contents(); ob_end_clean(); ?>';
97  }
98
99  public static function EntryExcerpt($attr,$content)
100  {
101    return '<?php
102    ob_start();
103    ?>'.
104    $content.
105    '<?php $post_excerpt = ob_get_contents(); ob_end_clean(); ?>';
106  }
107
108  public static function EntryContent($attr,$content)
109  {
110    return '<?php
111    ob_start();
112    ?>'.
113    $content.
114    '<?php $post_content = ob_get_contents(); ob_end_clean(); ?>';
115  }
116
117  public static function FeedURL($attr)
118  {
119    return '<?php print $postMakerHook->url; ?>';
120  }
121
122  public static function FeedProperty($attr)
123  {
124    if( !isset($attr['name']) )
125      return '';
126    return '<?php print $postMakerHook->feed->'.$attr['name'].'; ?>';
127  }
128
129  public static function FeedItems($attr,$content)
130  {
131    return '<?php
132    foreach ($postMakerHook->feed->items as $postMakerHook->item) :
133    ?>'.
134    $content.
135    '<?php endforeach; unset($postMakerHook->item); ?>';
136  }
137
138  public static function FeedItemProperty($attr)
139  {
140    if( !isset($attr['name']) )
141      return '';
142    return '<?php print $postMakerHook->item->'.$attr['name'].'; ?>';
143  }
144
145  public static function FeedItemDate($attr)
146  {
147    return '<?php print dt::str($core->blog->settings->date_format,$postMakerHook->item->TS); ?>';
148  }
149
150  public static function FeedItemTime($attr)
151  {
152    return '<?php print dt::str($core->blog->settings->time_format,$postMakerHook->item->TS); ?>';
153  }
154}
155?>
Note: See TracBrowser for help on using the repository browser.

Sites map