Пример #1
0
    public static function createTemplate(&$template, $form)
    {
        if (!class_exists('JHtmlBehavior')) {
            jimport('joomla.html.html.behavior');
        }
        $tagjs = "function insertTag(tag){ try{if(jInsertEditorText(tag,'template_body')){ return true;}else{jInsertEditorText(tag,'alt_body'); return true}} catch(err){alert('Your editor does not enable jNews to automatically insert the tag, please copy/paste it manually in your Newsletter'); return false;}}";
        if (!isset($template)) {
            $template = new stdClass();
        }
        //we change the permission of the template
        //if we not change the permission to writable(755) the images won't show
        @($mediacomjNewsTemplatesdir = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS . $template->namekey);
        @chmod(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS . $template->namekey, 0755);
        $template->name = isset($template->name) ? $template->name : '';
        $template->namekey = isset($template->namekey) ? $template->namekey : '';
        $template->published = isset($template->published) ? $template->published : 0;
        $template->premium = isset($template->premium) ? $template->premium : 0;
        $template->thumbnail = isset($template->thumbnail) ? $template->thumbnail : '';
        $template->description = isset($template->description) ? $template->description : '';
        $template->availability = isset($template->availability) ? $template->availability : '1';
        $template->body = isset($template->body) ? $template->body : '';
        $template->altbody = isset($template->altbody) ? $template->altbody : '';
        $template->styles = isset($template->styles) ? $template->styles : '';
        $template->csstyle = isset($template->csstyle) ? $template->csstyle : '';
        $editor = JFactory::getEditor();
        //		if(!$GLOBALS[JNEWS.'disabletooltip']){
        if (version_compare(JVERSION, '3.0.0', '<')) {
            JHTML::_('behavior.tooltip');
        } else {
            JHtml::_('behavior.tooltip');
        }
        $text = str_replace('"', '&quot;', $template->name);
        $namekey = str_replace('"', '&quot;', $template->namekey);
        if (function_exists('htmlspecialchars_decode')) {
            $text = htmlspecialchars_decode($text, ENT_NOQUOTES);
            $namekey = htmlspecialchars_decode($namekey, ENT_NOQUOTES);
        } elseif (function_exists('html_entity_decode')) {
            $text = html_entity_decode($text, ENT_NOQUOTES);
            $namekey = html_entity_decode($namekey, ENT_NOQUOTES);
        }
        $readOnlyNamekey = !empty($namekey) ? 'READONLY' : '';
        $styles = $template->styles;
        $styles['color_bg'] = !empty($styles) && isset($styles['color_bg']) ? $styles['color_bg'] : '#FFFFFF';
        $styles['cssfile'] = !empty($styles) && isset($styles['cssfile']) ? $styles['cssfile'] : '';
        $templateHTML['name'] = '<input type="text" name="template_name" class="inputbox" size="40" maxlength="64" value="' . $text . '" />';
        $templateHTML['namekey'] = '<input type="text" name="template_namekey" class="inputbox" size="40" maxlength="64" value="' . $namekey . '" ' . $readOnlyNamekey . ' />';
        $templateHTML['publish'] = jnews::HTML_BooleanList('confirmed', 'class="inputbox"', $template->published);
        $templateHTML['premium'] = jnews::HTML_BooleanList('premium', 'class="inputbox"', $template->premium);
        $templateHTML['bgcolor'] = jnews::colorPicker('styles[color_bg]', 15, $styles['color_bg']);
        $templateHTML['thumbnail'] = jNews_TemplatesHTML::_attachment($template->thumbnail);
        $templateHTML['description'] = '<br/><textarea rows="5" cols="45" name="description">' . $template->description . '</textarea><br/>';
        unset($styles['cssfile']);
        $templateHTML['cssfile'] = '<div id="cssfile" style="display:none;"><input type="text" name="styles[cssfile]" style="margin: 2px 0 2px 2px;" class="inputbox" size="45" value="' . jNews_Templates::escapeVal(@$styles['cssfile']) . '" />';
        $templateHTML['cssfile'] .= '<input type="button" onclick="javascript:hideMainMenu(); submitbutton(\'apply\')" style="margin: 2px 0 2px 2px;" name="Process External CSS" class="button" value="' . _JNEWS_EXTERNALCSS_PROCESS . '"></div>';
        //		}
        //remove empty classname
        unset($styles['']);
        echo $form['main'];
        ?>
			<table cellpadding="1" cellspacing="0" border="0" width="99%">
				<tbody>
					<tr>
						<td width="20%" valign="top">
							<fieldset style="margin-top:7px;">
								<?php 
        echo jnews::beginingOfTable('jnewstable');
        echo jnews::miseEnHTML(_JNEWS_TEMPLATE_NAME, _JNEWS_TEMPLATE_NAME_T, $templateHTML['name']);
        echo jnews::miseEnHTML(_JNEWS_TEMPLATE_ALIAS, _JNEWS_TEMPLATE_NAMEKEY_T, $templateHTML['namekey']);
        echo jnews::miseEnHTML(_JNEWS_TEMPLATE_PUBLISH, _JNEWS_TEMPLATE_PUBLISH_T, $templateHTML['publish']);
        echo jnews::miseEnHTML(_JNEWS_TEMPLATE_DEFAULT, _JNEWS_TEMPLATE_DEFAULT_T, $templateHTML['premium']);
        echo jnews::miseEnHTML(_JNEWS_TEMPLATE_BG, _JNEWS_TEMPLATE_BG_T, $templateHTML['bgcolor']);
        echo jnews::miseEnHTML(_JNEWS_TEMPLATE_UPLOAD, _JNEWS_TEMPLATE_UPLOAD_T, $templateHTML['thumbnail']);
        echo jnews::miseEnHTML(_JNEWS_TEMPLATE_DESC, _JNEWS_TEMPLATE_DESC_T, $templateHTML['description']);
        echo jnews::endOfTable();
        ?>
							</fieldset>
						</td>
						<td width="49%" valign="top">
								<?php 
        $switchjs = 'function switchContent() {
										        	var option=[\'jNewsStyles\',\'jNewsCSSTextbox\'];
										        	for(var i=0; i<option.length; i++){
											        	obj=document.getElementById(option[i]);
											        	obj.className=(obj.className=="visible")? "hidden" : "visible";
											       	}
											       	var form = document.adminForm;
											       	if(form.stylechosen.value == \'0\'){form.stylechosen.value = 1}else{form.stylechosen.value = 0}
										       	 }
										        function showInput() {
													var el = document.getElementById(\'cssfile\');
													if ( el.style.display != \'none\' ) {
														el.style.display = \'none\';
													}
													else {
														el.style.display = \'\';
														el.focus();
													}
												}';
        $jnewscss = '.visible {display:block;}
											     .hidden {display:none;}';
        $doc = JFactory::getDocument();
        $doc->addScriptDeclaration($switchjs . $tagjs);
        $doc->addStyleDeclaration($jnewscss);
        //echo '<a name="cssfileindex">';
        jNews_TemplatesHTML::_styles($styles);
        //add the specific style
        //echo '</a>';
        echo '<div id="jNewsCSSTextbox" style="padding: 4px;" class="hidden">' . jNews_TemplatesHTML::_csstextbox($template->csstyle) . '</div>';
        echo '<div class="button2-left">';
        echo '<div class="blank"><a href="#" style="cursor: hand;" onclick="switchContent()" title="Toggle Template Styling" >' . _JNEWS_CSS_TOGGLESTYLE . '</a></div>';
        echo '</div>';
        //									echo '<div class="button2-left">';
        //									echo '<div class="blank"><a href="#cssfileindex" style="cursor: hand;" onclick="showInput()" title="Click to Input External CSS" >'._JNEWS_EXTERNALCSS_LINK.'</a></div>';
        //									echo '</div>';
        echo $templateHTML['cssfile'];
        ?>
						</td>
					</tr>
					<tr>
						<td colspan="2" width="100%">
							<fieldset class="jnewscss">
								<legend>
									<?php 
        echo _JNEWS_HTML_VERSION;
        ?>
								</legend>
								<?php 
        echo $editor->display('template_body', $template->body, '99%', '800', '75', '50', true);
        ?>
							</fieldset>
							<fieldset class="jnewscss">
								<legend><?php 
        echo _JNEWS_NONHTML_VERSION;
        ?>
</legend>
								<textarea name="alt_body" rows="20" cols="70" style="width: 100%; height: 400px;"><?php 
        echo $template->altbody;
        ?>
</textarea>
							</fieldset>
						</td>
					</tr>
				</tbody>
			</table>
		<?php 
        echo JHTML::_('behavior.keepalive');
    }