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 / function.image.php
100644 117 lines (106 sloc) 3.655 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
<?php
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#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_image($params, &$smarty)
{
  global $gCms;
 
  $text = '';
  $imgstart = '<img src=';
  $imgend = '/>';
  if( !empty($params['src'] ) )
  {
    $text = $imgstart .= '"'.$gCms->config['image_uploads_url'].'/'.$params['src'].'"';
    $size = @getimagesize($gCms->config['image_uploads_path'].'/'.$params['src']);
 
    if( !empty($params['width'] ) ) {
      $text .= ' width="'.$params['width'].'"';
    } elseif ($size[0] > 0) {
      $text .= ' width="'.$size[0].'"';
    }
 
    if( !empty($params['height'] ) ) {
      $text .= ' height="'.$params['height'].'"';
    } elseif ($size[1] > 0) {
      $text .= ' height="'.$size[1].'"';
    }
    if( !empty($params['alt'] ) )
    {
      $alt = $params['alt'];
    } else {
      $alt = '['.$params['src'].']';
    }
    $text .= ' alt="'.$alt.'"';
    if( !empty($params['title'] ) )
    {
      $text .= ' title="'.$params['title'].'"';
    } else {
      $text .= ' title="'.$alt.'"';
    }
    if( !empty($params['class'] ) )
    {
      $text .= ' class="'.$params['class'].'"';
    }
 
    if( !empty($params['addtext'] ) )
    {
      $text .= ' ' . $params['addtext'];
    }
    $text .= $imgend;
  }
  else
  {
    $text = '<!-- empty results from image plugin -->';
  }
 
  if (array_key_exists('assign', $params))
  {
    $smarty->assign($params['assign'], $text);
  }
  else
  {
    return $text;
  }
}
 
 
function smarty_cms_help_function_image()
{
  ?>
  <h3>What does this do?</h3>
  <p>Creates an image tag to an image stored within your images directory</p>
  <h3>How do I use it?</h3>
  <p>Just insert the tag into your template/page like: <code>{image src="something.jpg"}</code></p>
  <h3>What parameters does it take?</h3>
  <ul>
    <li><em>(required)</em> <tt>src</tt> - Image filename within your images directory.</li>
    <li><em>(optional)</em> <tt>width</tt> - Width of the image within the page. Defaults to true size.</li>
    <li><em>(optional)</em> <tt>height</tt> - Height of the image within the page. Defaults to true size.</li>
    <li><em>(optional)</em> <tt>alt</tt> - Alt text for the image -- needed for xhtml compliance. Defaults to filename.</li>
    <li><em>(optional)</em> <tt>class</tt> - CSS class for the image.</li>
    <li><em>(optional)</em> <tt>title</tt> - Mouse over text for the image. Defaults to Alt text.</li>
    <li><em>(optional)</em> <tt>addtext</tt> - Additional text to put into the tag</li>
    <li><em>(optional)</em> <tt>assign</tt> - Assign the output to a smarty variable named in assign instead of outputting it directly.</li>
  </ul>
  <?php
}
 
 
function smarty_cms_about_function_image()
{
?>
  <p>Author: Robert Campbell &lt;calguy1000@hotmail.com&gt;,</p>
  <p>Version 1.2</p>
  <p>Change History<br/>
    1.2 - Added default width, height and alt <small>(contributed by Walter Wlodarski)</small><br />
    1.1 - Added alt param and removed the </img><br />
    1.0 - Initial release<br/>
  </p>
<?php
}
 
?>