<?php
public function init($context) {
switch ($context) {
case 'mgr':
break;
case 'web':
default:
$language = !empty($this->props['language'])
? $this->props['language'] . ':' : '';
$this->modx->lexicon->load($language . 'newspublisher:default');
break;
}
$this->prefix = empty($this->props['prefix']) ? 'np' : $this->props['prefix'];
/* see if we're editing an existing doc */
$this->existing = false;
if (isset($_POST['np_existing']) && $_POST['np_existing'] == 'true') {
$this->existing = is_numeric($_POST['np_doc_id'])
? $_POST['np_doc_id'] : false;
}
/* see if it's a repost */
$this->setPostback(isset($_POST['hidSubmit']) && $_POST['hidSubmit'] == 'true');
if($this->existing) {
$this->resource = $this->modx->getObject('modResource', $this->existing);
if ($this->resource) {
if (!$this->modx->hasPermission('view_document') || !$this->resource->checkPolicy('view') ) {
$this->setError($this->modx->lexicon('np_view_permission_denied'));
}
if ($this->isPostBack) {
/* str_replace to prevent rendering of placeholders */
$fs = array();
foreach($_POST as $k=>$v) {
$fs[$k] = str_replace(array('[',']'),array('[',']'),$v);
}
$this->modx->toPlaceholders($fs,$this->prefix);
} else {
$ph = $this->resource->toArray();
$tags = false;
foreach($ph as $k=>$v) {
if (strstr($v, '[[')) {
$tags = true;
}
if ($tags && ! $this->modx->hasPermission('allow_modx_tags')) {
$this->setError($this->modx->lexicon('np_no_modx_tags'));
return;
}
$fs[$k] = str_replace(array('[',']'),array('[',']'),$v);
}
$ph = $fs;
$this->modx->toPlaceholders($ph,$this->prefix);
unset($ph);
}
} else {
$this->setError($this->modx->lexicon('np_no_resource') . $this->existing);
return;
}
/* need to forward this from $_POST so we know it's an existing doc */
$stuff = '<input type="hidden" name="np_existing" value="true" />' . "\n" .
'<input type="hidden" name="np_doc_id" value="' . $this->resource->get('id') . '" />';
$this->modx->toPlaceholder('post_stuff',$stuff,$this->prefix);
} else {
/* new document */
if (!$this->modx->hasPermission('new_document')) {
$this->setError($this->modx->lexicon('np_create_permission_denied'));
}
$this->resource = $this->modx->newObject('modResource');
/* get folder id where we should store articles
else store under current document */
$this->parentId = !empty($this->props['parent']) ? intval($this->props['parent']):$this->modx->resource->get('id');
/* str_replace to prevent rendering of placeholders */
$fs = array();
foreach($_POST as $k=>$v) {
$fs[$k] = str_replace(array('[',']'),array('[',']'),$v);
}
$this->modx->toPlaceholders($fs,$this->prefix);
$this->aliasTitle = $this->props['aliastitle']? true : false;
$this->clearcache = isset($_POST['clearcache'])? $_POST['clearcache'] : $this->props['clearcache'] ? true: false;
$this->hideMenu = isset($_POST['hidemenu'])? $_POST['hidemenu'] : $this->_setDefault('hidemenu',$this->parentId);
$this->resource->set('hidemenu', $this->hideMenu);
$this->cacheable = isset($_POST['cacheable'])? $_POST['cacheable'] : $this->_setDefault('cacheable',$this->parentId);
$this->resource->set('cacheable', $this->cacheable);
$this->searchable = isset($_POST['searchable'])? $_POST['searchable'] : $this->_setDefault('searchable',$this->parentId);
$this->resource->set('searchable', $this->searchable);
$this->published = isset($_POST['published'])? $_POST['published'] : $this->_setDefault('published',$this->parentId);
$this->resource->set('published', $this->published);
$this->richtext = isset($_POST['richtext'])? $_POST['richtext'] : $this->_setDefault('richtext',$this->parentId);
$this->resource->set('richtext', $this->richtext);
if (! empty($this->props['groups'])) {
$this->groups = $this->_setDefault('groups',$this->parentId);
}
$this->header = !empty($this->props['headertpl']) ? $this->modx->getChunk($this->props['headertpl']) : '';
$this->footer = !empty($this->props['footertpl']) ? $this->modx->getChunk($this->props['footertpl']):'';
$this->intMaxlength = !empty($this->props['intmaxlength'])? $this->props['intmaxlength'] : 10;
$this->textMaxlength = !empty($this->props['textmaxlength'])? $this->props['textmaxlength'] : 60;
}
if( !empty($this->props['badwords'])) {
$this->badwords = str_replace(' ','', $this->props['badwords']);
$this->badwords = "/".str_replace(',','|', $this->badwords)."/i";
}
$this->modx->lexicon->load('core:resource');
$this->template = $this->_getTemplate();
if($this->props['initdatepicker']) {
$this->modx->regClientCSS($this->assetsUrl . 'datepicker/css/datepicker.css');
$this->modx->regClientStartupScript($this->assetsUrl . 'datepicker/js/datepicker.js');
}
/* inject NP CSS file */
/* Empty but sent parameter means use no CSS file at all */
if (empty($this->props['cssfile'])) { /* nothing sent - use default */
$css = $this->assetsUrl . 'css/newspublisher.css';
} elseif (empty($this->props['cssfile']) ) { /* empty param -- no css file */
$css = false;
} else { /* set but not empty -- use it */
$css = $this->assetsUrl . 'components/newspublisher/css/' . $this->props['cssfile'];
}
if ($css !== false) {
$this->modx->regClientCSS($css);
}
$this->listboxMax = $this->props['listboxmax']? $this->props['listboxmax'] : 8;
$this->MultipleListboxMax = $this->props['multiplelistboxmax']? $this->props['multiplelistboxmax'] : 8;
$ph = ! empty($this->props['contentrows'])? $this->props['contentrows'] : '10';
$this->modx->toPlaceholder('contentrows',$ph,$this->prefix);
$ph = ! empty($this->props['contentcols'])? $this->props['contentcols'] : '60';
$this->modx->toPlaceholder('contentcols',$ph, $this->prefix);
$ph = ! empty($this->props['summaryrows'])? $this->props['summaryrows'] : '10';
$this->modx->toPlaceholder('summaryrows',$ph, $this->prefix);
$ph = ! empty($this->props['summarycols'])? $this->props['summarycols'] : '60';
$this->modx->toPlaceholder('summarycols',$ph, $this->prefix);
/* do rich text stuff */
//$ph = ! empty($this->props['rtcontent']) ? 'MODX_RichTextWidget':'content';
$ph = ! empty($this->props['rtcontent']) ? 'modx-richtext':'content';
$this->modx->toPlaceholder('rt_content_1', $ph, $this->prefix );
$ph = ! empty($this->props['rtcontent']) ? 'modx-richtext':'content';
$this->modx->toPlaceholder('rt_content_2', $ph, $this->prefix );
/* set rich text summary field */
$ph = ! empty($this->props['rtsummary']) ? 'modx-richtext':'introtext';
$this->modx->toPlaceholder('rt_summary_1', $ph, $this->prefix );
$ph = ! empty($this->props['rtsummary']) ? 'modx-richtext':'introtext';
$this->modx->toPlaceholder('rt_summary_2', $ph, $this->prefix );
unset($ph);
if ($this->props['initrte']) {
/* set rich text content placeholders and includes necessary js files */
$tinyPath = $this->modx->getOption('core_path').'components/tinymce/';
$this->modx->regClientStartupScript($this->modx->getOption('manager_url').'assets/ext3/adapter/ext/ext-base.js');
$this->modx->regClientStartupScript($this->modx->getOption('manager_url').'assets/ext3/ext-all.js');
$this->modx->regClientStartupScript($this->modx->getOption('manager_url').'assets/modext/core/modx.js');
$whichEditor = $this->modx->getOption('which_editor',null,'');
$plugin=$this->modx->getObject('modPlugin',array('name'=>$whichEditor));
if ($whichEditor == 'TinyMCE' ) {
//$tinyUrl = $this->modx->getOption('assets_url').'components/tinymcefe/';
$tinyUrl = $this->modx->getOption('assets_url').'components/tinymce/';
/* OnRichTextEditorInit */
$tinyproperties=$plugin->getProperties();
require_once $tinyPath.'tinymce.class.php';
$tiny = new TinyMCE($this->modx,$tinyproperties,$tinyUrl);
if (isset($this->props['forfrontend']) || $this->modx->isFrontend()) {
$def = $this->modx->getOption('cultureKey',null,$this->modx->getOption('manager_language',null,'en'));
$tinyproperties['language'] = $this->modx->getOption('fe_editor_lang',array(),$def);
$tinyproperties['frontend'] = true;
//$tinyproperties['selector'] = 'modx-richtext';
//$tinyproperties['selector'] = 'modx-richtext';//alternative to 'frontend = true' you can use a selector for texareas
unset($def);
}
$tinyproperties['cleanup'] = true; /* prevents "bogus" bug */
$tinyproperties['width'] = empty ($this->props['tinywidth'] )? '95%' : $this->props['tinywidth'];
$tinyproperties['height'] = empty ($this->props['tinyheight'])? '400px' : $this->props['tinyheight'];
//$tinyproperties['tiny.custom_buttons1'] = 'image';
//$tinyproperties['tiny.custom_buttons2'] = '';
$tiny->setProperties($tinyproperties);
$html = $tiny->initialize();
$this->modx->regClientStartupScript($tiny->config['assetsUrl'].'jscripts/tiny_mce/langs/'.$tiny->properties['language'].'.js');
$this->modx->regClientStartupScript($tiny->config['assetsUrl'].'tiny.browser.js');
//mod by Bruno
//Todo: new NP-scriptProperty: rt_configs
$rt_configs='[{"selector":"rt_imagetv", "buttons1":"image", "buttons2":"", "theme_advanced_buttons1":"image", "theme_advanced_buttons2":""}]';
$rt_configs=$this->modx->fromJson($rt_configs);
foreach($rt_configs as $rt_config){
$cfg = '';
foreach ($rt_config as $cf_key => $cf_value){
$cfg.='Tiny.config.'.$cf_key.' = "'.$cf_value.'";';
}
$js.=$cfg.' MODx.loadRTE();';
}
$this->modx->regClientStartupHTMLBlock('<script type="text/javascript">
Ext.onReady(function() {
MODx.loadRTE();
'.$js.'
});
</script>');
} /* end if ($whichEditor == 'TinyMCE') */
} /* end if ($richtext) */
} /* end init */