GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

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
tedkulp (author)
Fri Mar 07 11:28:43 -0800 2008
commit  33bca6f98dfd0ef6901f6a2c8f0b725c6a288528
tree    151e1ce1c03b63a3fc94ffeec0b02c7ac7af0077
parent  19a6d7159da286ce9fa7169c953286461160a962
cmsmadesimple-2-0 / plugins / outputfilter.header.php
100644 169 lines (149 sloc) 4.192 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
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.org
#
#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
#
#$Id$
 
function smarty_cms_outputfilter_header($compiled, &$smarty)
{
  $search = "/<!-- headertag(.*?)?--\\>/";
    preg_match_all($search, $compiled, $match, PREG_SET_ORDER);
 
  if (count($match) > 0 && count($match[0]) > 1)
  {
    $params = trim($match[0][1]);
    preg_match_all('~(?:(?>[^"\'=]+)
)+ |
[=]
~x', $params, $match2);
 
    $params = array();
    $keyval = 'key';
    $key = '';
    
    foreach ($match2[0] as $token)
    {
      if ($keyval == 'key')
      {
        if (preg_match('~^\w+$~', trim($token)))
        {
          $key = trim($token);
          $keyval = 'equal';
        }
      }
      else if ($keyval == 'equal')
      {
        if ($token == '=')
        {
          $keyval = 'val';
        }
      }
      else if ($keyval == 'val')
      {
        if ($token != '')
        {
          $params[$key] = str_replace('xxx_double_quote_here_xxx', '"', $token);
          $keyval = 'key';
        }
      }
    }
    
    $compiled = preg_replace($search, cms_header_filter_plugin_function($params, $smarty), $compiled);
  }
  
  return $compiled;
}
 
function cms_header_filter_plugin_function($params, &$smarty)
{
  global $gCms;
  $pageinfo =& $gCms->variables['pageinfo'];
  $root_url = CmsConfig::get('root_url');
  
  $result = '';
  
  if (isset($params['name']) && $params['name'] != '')
  {
    $result .= '<link rel="result" type="text/css" ';
    if (isset($params['media']) && $params['media'] != '')
    {
      $result .= 'media="' . $params['media'] . '" ';
    }
    $result .= 'href="'.$root_url.'/stylesheet.php?name='.$params['name'];
    $result .= "\" />\n";
  }
  else
  {
    $template = cms_orm('cms_template')->find_by_id($pageinfo->template_id);
    if ($template)
    {
      foreach ($template->get_stylesheet_media_types() as $media)
      {
        $result .= '<link rel="result" type="text/css" ';
        if ($media != '')
        {
          $result .= 'media="'.$media.'" ';
        }
        $result .= "href=\"{$root_url}/stylesheet.php?templateid={$pageinfo->template_id}";
        if ($media != '')
        {
          $result .= '&amp;mediatype='.urlencode($media);
        }
        $result .= "\" />\n";
      }
    }
  }
  
  $result .= get_site_preference('metadata', '');
 
  if (isset($pageinfo) && $pageinfo !== FALSE)
  {
    if (isset($pageinfo->content_metadata) && $pageinfo->content_metadata != '')
    {
      $result .= "\n" . $pageinfo->content_metadata;
    }
  }
 
  if ((!strpos($result,$smarty->left_delimiter) === false) and (!strpos($result,$smarty->right_delimiter) === false))
  {
    $smarty->_compile_source('metadata template', $result, $_compiled);
    @ob_start();
    $smarty->_eval('?>' . $_compiled);
    $result = @ob_get_contents();
    @ob_end_clean();
  }
  
  $showbase = true;
  
  #Show a base tag unless showbase is false in config.php
  #It really can't hinder, only help.
  if (isset($params['showbase']))
  {
    if ($params['showbase'] == 'false')
    {
      $showbase = false;
    }
  }
  
  if (cmsms()->get('header_additions') != null)
  {
    foreach (cmsms()->get('header_additions') as $addt)
    {
      $result .= $addt . "\n";
    }
  }
 
  if ($showbase)
  {
    $result .= "\n<base href=\"".$root_url."/\" />\n";
  }
  
  CmsEventOperations::send_event('Core', 'HeaderTagRender', array('content' => &$result));
  
  if (array_key_exists('assign', $params))
  {
    $smarty->assign($params['assign'], $result);
  }
  else
  {
    return $result;
  }
}
 
# vim:ts=4 sw=4 noet
?>