public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / plugins / function.content.php
100644 177 lines (165 sloc) 5.873 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
function smarty_cms_function_content($params, &$smarty)
{
  global $gCms;
  $pageinfo =& $gCms->variables['pageinfo'];
  if (isset($pageinfo) && $pageinfo !== FALSE && isset($pageinfo->content_id) )
  {
    $id = '';
    $modulename = '';
    $action = '';
    $inline = false;
    if (isset($_REQUEST['module'])) $modulename = $_REQUEST['module'];
    if (isset($_REQUEST['id']))
    {
      $id = $_REQUEST['id'];
    }
    elseif (isset($_REQUEST['mact']))
    {
      $ary = explode(',', cms_htmlentities($_REQUEST['mact']), 4);
      $modulename = (isset($ary[0])?$ary[0]:'');
      $id = (isset($ary[1])?$ary[1]:'');
      $action = (isset($ary[2])?$ary[2]:'');
      $inline = (isset($ary[3]) && $ary[3] == 1?true:false);
    }
    if (isset($_REQUEST[$id.'action'])) $action = $_REQUEST[$id.'action'];
    else if (isset($_REQUEST['action'])) $action = $_REQUEST['action'];
    
    $block_name = 'default';
    if (isset($params['block']))
      $block_name = $params['block'];
    else if (isset($params['name']))
      $block_name = $params['name'];
 
    $block_name = strtolower(str_replace(' ', '_', $block_name));
 
    //Only consider doing module processing if
    //a. There is no block parameter
    //b. then
    // 1. $id is cntnt01
    // 2. or inline is false
    if ($block_name == 'default' && ($id == 'cntnt01' || ($id != '' && $inline == false)))
    {
      $cmsmodules = &$gCms->modules;
    
      if (isset($cmsmodules))
      {
        foreach ($cmsmodules as $key=>$value)
        {
          if (strtolower($modulename) == strtolower($key))
          {
            $modulename = $key;
          }
        }
    
        if (isset($modulename))
        {
          if (isset($cmsmodules[$modulename]))
          {
            if (isset($cmsmodules[$modulename]['object'])
              && $cmsmodules[$modulename]['installed'] == true
              && $cmsmodules[$modulename]['active'] == true
              && $cmsmodules[$modulename]['object']->IsPluginModule())
            {
              @ob_start();
              $params = array_merge($params, GetModuleParameters($id));
 
              $returnid = '';
              if (isset($params['returnid']))
              {
                $returnid = $params['returnid'];
              }
              else
              {
                $returnid = $pageinfo->content_id;
              }
              $result = $cmsmodules[$modulename]['object']->DoActionBase($action, $id, $params, $returnid);
              if ($result !== FALSE)
              {
                echo $result;
              }
              $modresult = @ob_get_contents();
              @ob_end_clean();
              return _smarty_cms_function_content_return($modresult, $params, $smarty);
            }
            else
            {
             return _smarty_cms_function_content_return("<!-- Not a tag module -->\n", $params, $smarty);
            }
          }
        }
      }
    }
    else
    {
      $result = $smarty->fetch(str_replace(' ', '_', 'content:' . $block_name), '', $pageinfo->content_id);
      if (isset($_REQUEST['tmpfile']))
      {
        $smarty->clear_compiled_tpl(str_replace(' ', '_', 'content:' . $block_name), $pageinfo->content_id);
      }
      return _smarty_cms_function_content_return($result, $params, $smarty);
    }
  }
  return _smarty_cms_function_content_return('', $params, $smarty);
}
 
function _smarty_cms_function_content_return($result, &$params, &$smarty)
{
  if ( empty($params['assign']) )
  {
    return $result;
  }
  else
  {
    $smarty->assign($params['assign'], $result);
    return '';
  }
}
 
function smarty_cms_help_function_content()
{
  ?>
  <h3>What does this do?</h3>
  <p>This is where the content for your page will be displayed. It's inserted into the template and changed based on the current page being displayed.</p>
  <h3>How do I use it?</h3>
  <p>Just insert the tag into your template like: <code>{content}</code>.</p>
  <h3>What parameters does it take?</h3>
  <ul>
    <li><em>(optional)</em>block - Allows you to have more than one content block per page. When multiple content tags are put on a template, that number of edit boxes will be displayed when the page is edited.
<p>Example:</p>
<pre>{content block="Second Content Block"}</pre>
<p>Now, when you edit a page there will a textarea called "Second Content Block".</li>
    <li><em>(optional)</em>wysiwyg (true/false) - If set to false, then a wysiwyg will never be used while editing this block. If true, then it acts as normal. Only works when block parameter is used.</li>
    <li><em>(optional)</em>oneline (true/false) - If set to true, then only one edit line will be shown while editing this block. If false, then it acts as normal. Only works when block parameter is used.</li>
    <li><em>(optional)</em>assign - Assigns the content to a smarty parameter, which you can then use in other areas of the page, or use to test whether content exists in it or not.
<p>Example of passing page content to a User Defined Tag as a parameter:</p>
<pre>
{content assign=pagecontent}
{table_of_contents thepagecontent="$pagecontent"}
</pre>
</li>
  </ul>
  <?php
}
 
function smarty_cms_about_function_content()
{
  ?>
  <p>Author: Ted Kulp&lt;tedkulp@users.sf.net&gt;</p>
  <p>Version: 1.1</p>
  <p>
  Change History:<br/>
  1.1 - Added assign parameter from djnz's patch in the forge<br />
  1.0 - Initial version
  </p>
  <?php
}
 
# vim:ts=4 sw=4 noet
?>