00001 <?php
00002
00016
00017
00018
00019 import('form.Form');
00020
00021 class CmsSettingsForm extends Form {
00023 var $journalId;
00024
00026 var $plugin;
00027
00029 var $contentManager;
00030
00032 var $errors;
00033
00038 function CmsSettingsForm(&$plugin, $journalId) {
00039
00040 parent::Form($plugin->getTemplatePath() . 'settingsForm.tpl');
00041
00042 $this->journalId = $journalId;
00043 $this->plugin =& $plugin;
00044
00045 $plugin->import('ContentManager');
00046 $this->contentManager =& new ContentManager();
00047
00048 $this->addCheck(new FormValidatorCustom($this, 'content', 'required', null, array(&$this, 'checkAndFixContent')));
00049 $this->addCheck(new FormValidatorPost($this));
00050
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060 function checkAndFixContent ( $content ) {
00061
00062 $content = trim($content);
00063
00064 if ( strlen($content) > 0 &&
00065 substr($content, 0, 3) != '<h1' &&
00066 substr($content, 0, 3) != '<h2' &&
00067 substr($content, 0, 3) != '<h3' ) {
00068 $this->setData('content', trim($content));
00069 $this->addError('content', Locale::translate('plugins.generic.cms.error.muststartwithheader'));
00070 return true;
00071 }
00072
00073
00074 preg_match_all('/<h([1-3])>(.*)<\/h[1-3]>/U', $content, $headMatches);
00075 preg_match_all('/<\/h([1-3])>(.*)<(h[1-3]|\/body)>/U', $content.'</body>', $contentMatches);
00076
00077
00078 if ( count($headMatches[0]) != count($contentMatches[0]) ) {
00079 $this->setData('content', $content);
00080 $this->addError('content', Locale::translate('plugins.generic.cms.error.musthavecontent'));
00081 return true;
00082 }
00083
00084
00085 $prev = 1;
00086 for ( $i = 0; $i < count($headMatches[0]); $i++ ) {
00087
00088 if ( $headMatches[1][$i] > $prev + 1 )
00089 $headMatches[1][$i] = $prev + 1;
00090 $prev = $headMatches[1][$i];
00091
00092
00093 $headMatches[2][$i] = preg_replace('/<.*>/','', $headMatches[2][$i]);
00094 $headMatches[2][$i] = str_replace(' ', ' ', $headMatches[2][$i]);
00095 $headMatches[2][$i] = trim($headMatches[2][$i]);
00096
00097 if ( str_replace(' ', '', $headMatches[2][$i]) == '' ) {
00098 $this->setData('content', $content);
00099 $this->addError('content', Locale::translate('plugins.generic.cms.error.headingcannotbeempty'));
00100 return true;
00101 }
00102 }
00103
00104
00105 for ( $i = 0; $i < count($contentMatches[0]); $i++ ) {
00106 if ( strpos($contentMatches[2][$i], '<' ) === false ) {
00107 $this->setData('content', $content);
00108 $this->addError('content', Locale::translate('plugins.generic.cms.error.musthavecontent'));
00109 return true;
00110 }
00111 }
00112
00113
00114 $content = '';
00115 for ( $i = 0; $i < count($headMatches[0]); $i++ ) {
00116 $content .= "<h".$headMatches[1][$i].">".$headMatches[2][$i]."</h".$headMatches[1][$i].">";
00117 $content .= $contentMatches[2][$i];
00118 }
00119
00120 $this->setData('content', $content);
00121 return true;
00122 }
00123
00127 function initData( $args ) {
00128 $journalId = $this->journalId;
00129 $plugin =& $this->plugin;
00130 $contentManager =& $this->contentManager;
00131
00132 $templateMgr = &TemplateManager::getManager();
00133
00134 $headings = array();
00135 $content = array();
00136
00137
00138 if (count($args) > 0 && $args[0] != '') {
00139 $current = $args[0];
00140 } else {
00141 $current = $contentManager->defaultHeading[1];
00142 }
00143
00144
00145 $contentManager->parseContents($headings, $content, $current);
00146
00147
00148 if ( isset($current) && count($content) > 0 ) {
00149 $currentContent = $content[$current];
00150
00151 foreach ( $headings as $heading ) {
00152 if ( $heading[1] == $current ) {
00153 $currentHeading = "<h".$heading[0].">".$heading[2]."</h".$heading[0].">";
00154 break;
00155 }
00156 }
00157
00158 } else {
00159 $currentContent = "";
00160 $currentHeading = "";
00161 }
00162
00163
00164 $this->addTinyMCE();
00165
00166 $templateMgr->assign('cmsPluginToc', $headings);
00167 $templateMgr->assign('currentHeading', $currentHeading );
00168 $templateMgr->assign('currentContent', $currentContent );
00169 $templateMgr->assign('current', $current );
00170 $templateMgr->assign('cmsPluginEdit', true);
00171 }
00172
00173 function addTinyMCE() {
00174 $journalId = $this->journalId;
00175 $plugin =& $this->plugin;
00176 $templateMgr = &TemplateManager::getManager();
00177
00178
00179 $additionalHeadData = $templateMgr->get_template_vars('additionalHeadData');
00180
00181 import('file.JournalFileManager');
00182 $publicFileManager =& new PublicFileManager();
00183 $tinyMCE_script = '
00184 <script language="javascript" type="text/javascript" src="'.Request::getBaseUrl().'/'.TINYMCE_JS_PATH.'/tiny_mce.js"></script>
00185 <script language="javascript" type="text/javascript">
00186 tinyMCE.init({
00187 mode : "textareas",
00188 plugins: "save, table, advimage, -heading",
00189 relative_urls : false,
00190 document_base_url : "'. Request::getBaseUrl() .'/'.$publicFileManager->getJournalFilesPath($journalId) .'/",
00191 theme : "advanced",
00192 theme_advanced_layout_manager : "SimpleLayout",
00193 theme_advanced_buttons1 : "save, bold, italic, underline, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, outdent, indent, code",
00194 theme_advanced_buttons2 : "h1, h2, h3, h4, image, link, unlink",
00195 theme_advanced_buttons3 : "tablecontrols",
00196 extended_valid_elements : "span[*]"
00197 });
00198 </script>';
00199
00200
00201
00202
00203 $tinyMCE_plugins = array( 'heading');
00204
00205 foreach ( $tinyMCE_plugins as $tinyMCEplugin ) {
00206 $tinyMCE_NewPlugin = file_get_contents($plugin->getPluginPath().'/tinyMCEPlugins/'.$tinyMCEplugin.'/editor_plugin.js');
00207 $tinyMCE_NewPlugin = preg_replace('/\{\$pluginurl\}/', Request::getBaseUrl().'/'.$plugin->getPluginPath().'/tinyMCEPlugins/'.$tinyMCEplugin, $tinyMCE_NewPlugin);
00208 $tinyMCE_script .= "\n<script language=\"javascript\" type=\"text/javascript\">\n" .
00209 "/***** $tinyMCEplugin Plugin *****/\n$tinyMCE_NewPlugin\n/*****/\n</script>";
00210 }
00211
00212 $templateMgr->assign('additionalHeadData', $additionalHeadData."\n".$tinyMCE_script);
00213
00214 }
00215
00219 function readInputData() {
00220 $this->readUserVars(array('content', 'current'));
00221 }
00222
00226 function save() {
00227 $plugin =& $this->plugin;
00228 $journalId = $this->journalId;
00229 $contentManager =& $this->contentManager;
00230
00231 $journal = &Request::getJournal();
00232
00233 $content = $this->getData('content');
00234 $current = $this->getData('current');
00235
00236 $contentManager->insertContent($content, $current);
00237 $this->setData('current', $current);
00238
00239 $h = array();
00240 $c = array();
00241
00242 $contentManager->parseContents( $h, $c );
00243
00244 $plugin->updateSetting($journalId, 'toc', $h);
00245 }
00246
00251 function execute() {
00252 $plugin =& $this->plugin;
00253 $journalId = $this->journalId;
00254 $contentManager =& $this->contentManager;
00255
00256 $h = array();
00257 $c = array();
00258
00259
00260 $contentManager->parseContents( $h, $c );
00261
00262
00263 $plugin->updateSetting($journalId, 'toc', $h);
00264 }
00265
00266 }
00267 ?>