Dotclear

source: plugins/typo/_admin.php @ 655

Revision 655, 4.3 KB checked in by franck, 15 years ago (diff)

Hyphenation feature removed
Draft code for action on selected entries in admin

Line 
1<?php 
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of Typo plugin for Dotclear 2.
5#
6# Copyright (c) 2008 Franck Paul and contributors
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK ------------------------------------
12
13require_once dirname(__FILE__).'/inc/smartypants.php';
14
15/* Add behavior callback, will be used for all types of posts (standard, page, galery item, ...) */
16$core->addBehavior('coreAfterPostContentFormat',array('adminTypo','updateTypoEntries'));
17
18/* Add behavior callbacks, will be used for all comments (not trackbacks) */
19$core->addBehavior('coreBeforeCommentCreate',array('adminTypo','updateTypoComments'));
20$core->addBehavior('coreBeforeCommentUpdate',array('adminTypo','updateTypoComments'));
21
22/* Add menu item in extension list */
23$_menu['Plugins']->addItem(__('Typo'),'plugin.php?p=typo','index.php?pf=typo/icon.png',
24          preg_match('/plugin.php\?p=typo(&.*)?$/',$_SERVER['REQUEST_URI']),
25          $core->auth->check('contentadmin',$core->blog->id));
26         
27/* Add behavior callbacks for posts actions */
28$core->addBehavior('adminPostsActionsCombo',array('adminTypo','adminPostsActionsCombo'));
29$core->addBehavior('adminPostsActions',array('adminTypo','adminPostsActions'));
30$core->addBehavior('adminPostsActionsContent',array('adminTypo','adminPostsActionsContent'));
31
32class adminTypo
33{
34     public static function adminPostsActionsCombo(&$args)
35     {
36          global $core;
37          // Add menuitem in actions dropdown list
38          if ($core->auth->check('contentadmin',$core->blog->id))
39               $args[0][__('typographic features')] = 'typo';
40     }
41
42     public static function adminPostsActionsContent($core,$action,$hidden_fields)
43     {
44          if ($action == 'typo')
45          {
46               echo
47               '<h2>'.__('Apply typographic features to entries').'</h2>'.
48
49               '<form action="posts_actions.php" method="post">'.
50
51               '<p><label class="classic">'.
52               form::checkbox('set_typo','1',$core->blog->settings->typo_active).
53               ' '.__('Apply typographic replacements for selected entries').'</label></p>'.
54               
55               '<p>'.__('Warning! These replacements will not be undoable.').'</p>'.
56               
57               $hidden_fields.
58               $core->formNonce().
59               form::hidden(array('action'),'typo').
60               '<p><input type="submit" value="'.__('save').'" /></p>'.
61               '</form>';
62          }
63     }
64     
65     public static function adminPostsActions(&$core,$posts,$action,$redir)
66     {
67          if ($action == 'typo' && !empty($_POST['set_typo'])
68          && $core->auth->check('contentadmin',$core->blog->id))
69          {
70               try
71               {
72                    if ((boolean)$_POST['set_typo']) {
73                         while ($posts->fetch())
74                         {
75                              # Apply typo features to entry
76                              $cur = $core->con->openCursor($core->prefix.'post');
77                             
78                              if ((boolean)$_POST['set_typo']) {
79                                   if ($cur->excerpt_xhtml)
80                                        $cur->excerpt_xhtml = SmartyPants($cur->excerpt_xhtml);
81                                   if ($cur->content_xhtml)
82                                        $cur->content_xhtml = SmartyPants($cur->content_xhtml);
83                              }
84
85//                            echo '<p>request : “'.$cur->getUpdate('WHERE post_id = '.(integer) $posts->post_id).'”</p>';
86//                            $cur->update('WHERE post_id = '.(integer) $posts->post_id);
87                         }
88                    }
89                   
90                    http::redirect($redir);
91               }
92               catch (Exception $e)
93               {
94                    $core->error->add($e->getMessage());
95               }
96          }
97     }
98
99     public static function updateTypoEntries($ref)
100     {
101          global $core;
102          if ($core->blog->settings->typo_active) {
103               if (@is_array($ref)) {
104                    /* Transform typo for excerpt (XHTML) */
105                    if (isset($ref['excerpt_xhtml'])) {
106                         $excerpt = &$ref['excerpt_xhtml'];
107                         if ($excerpt) {
108                              if ($core->blog->settings->typo_entries) {
109                                   $excerpt = SmartyPants($excerpt);
110                              }
111                         }
112                    }
113                    /* Transform typo for content (XHTML) */
114                    if (isset($ref['content_xhtml'])) {
115                         $content = &$ref['content_xhtml'];
116                         if ($content) {
117                              if ($core->blog->settings->typo_entries) {
118                                   $content = SmartyPants($content);
119                              }
120                         }
121                    }
122               }
123          }
124     }
125     
126     public static function updateTypoComments(&$blog,&$cur)
127     {
128          global $core;
129          if ($core->blog->settings->typo_active && $core->blog->settings->typo_comments)
130          {
131               /* Transform typo for comment content (XHTML) */
132               if (!(boolean)$cur->comment_trackback) {
133                    if ($cur->comment_content != null) {
134                         if ($core->blog->settings->typo_comments)
135                              $cur->comment_content = SmartyPants($cur->comment_content);
136                    }
137               }
138          }
139     }
140}
141?>
Note: See TracBrowser for help on using the repository browser.

Sites map