Dotclear

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

Revision 400, 3.8 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
22class PostMakerEntry
23{
24  static private $templatesList = null;
25  public $name;
26  public $template;
27  public $feed;
28 
29  public function __construct($name,$template,$feed)
30  {
31    $this->name = $name;
32    $this->template = $template;
33    $this->feed = $feed;
34  }
35 
36  public function TemplateFile()
37  {
38    return $this->template.'.'.self::GetTemplateType();
39  }
40 
41  public function Display()
42  {
43    self::DisplayRow($this->name,$this->template,$this->feed);
44  }
45 
46  static public function GetTemplatesList()
47  {
48    $templateList = array();
49    $extension = '.'.self::GetTemplateType();
50    $templateFileList = @glob(DC_POST_MAKER_TPL_FOLDER.'/*'.$extension);
51    if (!is_array($templateFileList))
52      return $templateList;
53    foreach ($templateFileList as $templateFile) {
54      $templateName = basename($templateFile,$extension);
55      if (!isset($templateList[$templateName]))
56        $templateList[$templateName] = $templateName;
57    }
58    return $templateList;
59  }
60 
61  static public function DisplayEmptyRow()
62  {
63    self::DisplayRow('','','');
64  }
65 
66  static public function DisplayRow($name,$template,$feed)
67  {
68    if(self::$templatesList == null)
69      self::$templatesList = self::GetTemplatesList();
70    print
71      '<p><label class="classic">'.
72      ' '.form::field(array('pmEntries_names[]'), 25, 25, html::escapeHTML($name)).
73      ' '.form::combo(array('pmEntries_templates[]'), self::$templatesList, $template).
74      ' '.form::field(array('pmEntries_feeds[]'), 50, 250, html::escapeHTML($feed)).
75      '</label></p>';
76  }
77 
78  static public function GetTemplateType()
79  {
80    global $core;
81    $templateTypes = array('xhtml'=>'hentry','wiki'=>'wentry');
82    return $templateTypes[$core->auth->getOption('post_format')];
83  }
84
85}
86
87class PostMakerSettings
88{
89  public $values;
90 
91  public function __construct()
92  {
93    global $core;
94    $core->blog->settings->setNameSpace('postmaker');
95    if( $core->blog->settings->entries === null ) {
96      $this->values = array();
97    } else {
98      $this->values = @unserialize($core->blog->settings->entries);
99    }
100  }
101 
102  public function Display()
103  {
104    foreach( $this->values as $entry )
105      $entry->Display();
106    PostMakerEntry::DisplayEmptyRow();
107  }
108   
109  public function LoadFromHTTP() {
110    if( !isset($_POST['pmEntries_names']) )
111      return false;
112    $names = is_array($_POST['pmEntries_names']) ? $_POST['pmEntries_names'] : array();
113    $templates = is_array($_POST['pmEntries_templates']) ? $_POST['pmEntries_templates'] : array();
114    $feeds = is_array($_POST['pmEntries_feeds']) ? $_POST['pmEntries_feeds'] : array();
115   
116    $this->values = array();
117    foreach( $names as $pos => $name ) {
118      $name = trim($name);
119      $template = trim($templates[$pos]);
120      $feed = trim($feeds[$pos]);
121      if ($name && $template)
122        $this->values[$name] = new PostMakerEntry($name,$template,$feed);
123    }
124    global $core;
125    $core->blog->settings->setNameSpace('postmaker');
126    $core->blog->settings->put('entries',@serialize($this->values)); // put in blog local settings
127    return true;
128  }
129 
130}
131?>
Note: See TracBrowser for help on using the repository browser.

Sites map