Metadot6  4.5.4
About: MetaDot Open Source Portal Server is a point & click website builder that includes features such as: Discussion Forum, File and Content Management, Task / To-Do List, Calendar, Poll, FAQs, End-User Personal Website, Group- and user-based access control, My News Page - like My Yahoo, Content Syndication with XML/RSS feeds, Email Notifications, Bookmarking, WYSIWYG HTML Editor (from interactivetools.com), Site themes and templates.
  Fossies Dox: Metadot6.4.5.4.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

 All Files
JavascriptHTML.pm
Go to the documentation of this file.
1 ###########################################################################
2 # <LICENSEINFO>
3 # Copyright (C) Daniel Guermeur - 1999-2001
4 # Copyright (C) Metadot Corporation - 2001-2005
5 #
6 # This file is part of Metadot Portal Server software $Name: Release_6_4_5_4 $
7 #
8 # Metadot Portal Server software is free software; you can
9 # redistribute it and/or modify it under the terms of the GNU General Public
10 # License as published by the Free Software Foundation; either version 2 of
11 # the License, or (at your option) any later version.
12 #
13 # Metadot Portal Server software is distributed in the hope that it
14 # will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 # Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Metadot Portal Server; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #
22 # For more information, please contact info@metadot.com.
23 #</LICENSEINFO>
24 #
25 #
26 ############################################################################
27 package JavascriptHTML;
28 
29 use strict;
30 use GizmoBuilder;
31 use vars qw(@ISA);
32 use CGI qw/escapeHTML unescapeHTML/;
33 
34 my $version = "1.0";
35 
36 sub get_version {
37  return $version;
38 }
39 
40 use Metadot qw($USER %FORM $SESSION $HTTP_HEADER_SENT $PARAMS);
41 
42 use constant NOTE=>'<ul><li><b><i>Name</i></b> and <b><i>description</i></b> fields will not appear in normal viewing mode</li>'
43  .'<li>The script code will only be executed in normal viewing mode, or by clicking on the "Run" button,<br />'
44  .'and not in editing mode, therefore, you must disable editing to see the result of the code</li></ul>';
45 
46 use constant SAMPLE=>'<b>The following example code displays an alert box when the page loads:<br /><br /></b>'
47  . '&lt;script language="JavaScript"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;alert("I am alive!");<br />'
48  . '&lt;/script&gt;<br />';
49 
50 @ISA=qw(GizmoBuilder);
51 
52 
53 sub customize_permissions {
54  my $class = shift;
55  my $AC = shift;
56 
57  $class->SUPER::customize_permissions($AC);
58 
59  $AC->add_op('MOD', 'run_it');
60 }
61 
62 
63 sub get_gizmo_name {
64  return "HTML/Javascript";
65 }
66 
67 sub gizmo_list_decorator {
68  return 'HTML::Decorator::NullDecorator';
69 }
70 
71 sub initialize {
72  my $self = shift;
73  my $args = Utility->coerce_hashref(@_);
74  $self->SUPER::initialize(@_);
75 
76  $self->set_field_info (
77  'name', NOTE.'<br /><b>Name</b>', 1,
78  'description', '<b>Description</b>', 0,
79  't1', SAMPLE.'<br /><b>Code</b>', 1,
80  );
81 
82  $self->set_field_type( 't1', 'variabletext', {rows=>35, cols=>120, html_only=>1} );
83 }
84 
85 
86 sub get_script_code {
87  my $self = shift;
88  return $self->get_t1();
89 }
90 
91 sub show_summary {
92  my $self = shift;
93  my $iid = $self->get_iid();
94  my $name = $self->get_name();
95  my $description = $self->get_description();
96  my $script = $self->get_script_code();
97  my $buttons = $self->get_buttons();
98  my $run_it = $FORM{'run_it'};
99  my $html = "\n";
100 
101  ## Only show name and description when in edit mode
102  if ($USER->is_logged_in() && ($SESSION->admin_mode()) && $self->is_allowed_to_do('run_it', $USER)) {
103  $html = "<p><b>$buttons <b><font size=\"3\">&lt; &gt;</font></b> $name</b>\n";
104  $html .= "<br />$description\n" if ($description);
105  $html .= "</p>\n";
106 
107  unless( $run_it ){
108  my $script_size = length $script;
109 
110  $script = escapeHTML($script);
111 
112  if( $script_size > 100 ){
113  $script = substr($script,0,100);
114  $script .= "<br />...\n";
115  }
116 
117  $script =~ s/\n/<br \/>/g;
118 
119  }
120 
121  $html .= "<pre><i><font face=\"courier\">$script</font></i></pre>";
122 
123  }
124  else{
125 
126  $html .= "$script\n";
127  }
128  return $html;
129 }
130 
131 sub show {
132  return show_summary;
133 }
134 
135 sub exec_show {
136  my $self = shift;
137  my $context = shift;
138  return $self->show();
139 }
140 
141 sub exec_show_summary {
142  my $self = shift;
143  my $context = shift;
144  return $self->show_summary();
145 }
146 
147 
148 # add a 'run code' button.
149 sub get_buttons {
150  my $self = shift;
151  my $id = $self->get_id();
152  my $buttons;
153 
154  if (defined $id) {
155  $buttons .= $self->SUPER::get_buttons( {add_panel=>$self->get_run_button()});
156  } else {
157  $buttons = $self->SUPER::get_buttons();
158  }
159  return $buttons;
160 }
161 
162 sub get_run_button {
163  my $self = shift;
164  my $parent = $self->get_navigation_parent();
165  return unless defined($parent);
166 
167  my $parent_id = $parent->get_id();
168  my $parent_isa = $parent->get_is_a();
169 
170  my $id = $self->get_id();
171  my $isa = $self->get_is_a();
172 
173  my $result;
174  my $run_it = $FORM{'run_it'};
175  my $flag = 1;
176  my $image = "run.jpg";
177 
178  my $win = "";
179  my $href;
180 
181  $href = "?id=$parent_id&isa=$parent_isa&op=show&run_it=$flag";
182  $win = "target=\"_blank\"";
183 
184  if( $run_it ){
185  $flag = 0;
186  }
187 
188  if ($SESSION->admin_mode()) {
189  if ($href) {
190  my $img_src = "$PARAMS->{'imageslocation'}/obj/$image";
191  $result = "<a href=\"$href\" $win><img src=\"$img_src\" class=\"icon\" border=\"0\" /></a>";
192  }
193  }
194 
195  return $result;
196 }
197 
198 1;