array( 'controller' => 'tinymce4_ui', 'path' => null, 'ui' => 'tinymce4_ui_form', 'uipath' => null ), ); protected $adminMenu = array( 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'), // 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P') ); protected $adminMenuAliases = array( 'main/edit' => 'main/list' ); protected $menuTitle = 'TinyMce'; } class tinymce4_ui extends e_admin_ui { protected $pluginTitle = 'TinyMce4'; protected $pluginName = 'tinymce4'; protected $prefs = array( 'paste_as_text' => array('title'=> 'Paste as text by default', 'type'=>'boolean', 'data' => 'int','help'=> ''), 'browser_spellcheck' => array('title'=> 'Browser spellcheck', 'type'=>'boolean', 'data' => 'int','help'=> 'Enable this if the browser internal spellchecker should be used.'), 'visualblocks' => array('title'=> 'Visual Blocks', 'type'=>'boolean', 'data' => 'int','help'=> 'Enable to make html blocks visible during editing.'), ); public function init() { } } class tinymce4_ui_form extends e_admin_form_ui { } new tinymce4_admin(); require_once(e_ADMIN."auth.php"); e107::getAdminUI()->runPage(); require_once(e_ADMIN."footer.php"); exit; require_once(e_HANDLER."form_handler.php"); require_once (e_HANDLER.'message_handler.php'); $frm = new e_form(true); $ef = new tinymce; //TODO save prefs to separate config row. // List all forms of access, and allow the user to choose between simple/advanced or 'custom' settings. if(varset($_POST['update']) || varset($_POST['create'])) { $id = intval($_POST['record_id']); $ef->submitPage($id); } if(varset($_POST['delete'])) { $id = key($_POST['delete']); $ef->deleteRecord($id); $_GET['mode'] = "list"; } if(isset($_POST['edit']) || $id) // define after db changes and before header loads. { $id = (isset($_POST['edit'])) ? key($_POST['edit']) : $id; define("TINYMCE_CONFIG",$id); } else { define("TINYMCE_CONFIG",FALSE); } require_once(e_ADMIN."auth.php"); if(varset($_GET['mode'])=='create') { $id = varset($_POST['edit']) ? key($_POST['edit']) : ""; if($_POST['record_id']) { $id = $_POST['record_id']; } $ef->createRecord($id); } else { $ef->listRecords(); } if(isset($_POST['etrigger_ecolumns'])) { $user_pref['admin_release_columns'] = $_POST['e-columns']; save_prefs('user'); } require_once(e_ADMIN."footer.php"); class tinymce { var $fields; var $fieldpref; var $listQry; var $table; var $primary; function __construct() { $this->fields = array( 'tinymce_id' => array('title'=> ID, 'width'=>'5%', 'forced'=> TRUE, 'primary'=>TRUE), 'tinymce_name' => array('title'=> 'name', 'width'=>'auto','type'=>'text'), 'tinymce_userclass' => array('title'=> 'class', 'type' => 'array', 'method'=>'tinymce_class', 'width' => 'auto'), 'tinymce_plugins' => array('title'=> 'plugins', 'type' => 'array', 'method'=>'tinymce_plugins', 'width' => 'auto'), 'tinymce_buttons1' => array('title'=> 'buttons1', 'type' => 'text', 'method'=>'tinymce_buttons', 'methodparms'=>1, 'width' => 'auto'), 'tinymce_buttons2' => array('title'=> 'buttons2', 'type' => 'text', 'method'=>'tinymce_buttons', 'methodparms'=>2, 'width' => 'auto'), 'tinymce_buttons3' => array('title'=> 'buttons3', 'type' => 'text', 'method'=>'tinymce_buttons', 'methodparms'=>3, 'width' => 'auto', 'thclass' => 'left first'), 'tinymce_buttons4' => array('title'=> 'buttons4', 'type' => 'text', 'method'=>'tinymce_buttons', 'methodparms'=>4, 'width' => 'auto', 'thclass' => 'left first'), 'tinymce_custom' => array('title'=> 'custom', 'type' => 'text', 'width' => 'auto'), 'tinymce_prefs' => array('title'=> 'prefs', 'type' => 'text', 'width' => '10%', 'thclass' => 'center' ), 'options' => array('title'=> LAN_OPTIONS, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last') ); $this->fieldpref = (varset($user_pref['admin_tinymce_columns'])) ? $user_pref['admin_tinymce_columns'] : array_keys($this->fields); $this->table = "tinymce"; $this->listQry = "SELECT * FROM #tinymce ORDER BY tinymce_id"; $this->editQry = "SELECT * FROM #tinymce WHERE tinymce_id = {ID}"; $this->primary = "tinymce_id"; $this->pluginTitle = "Tinymce"; $this->listCaption = "Tinymce Configs"; $this->createCaption = LAN_CREATE."/".LAN_EDIT; } // -------------------------------------------------------------------------- /** * Generic DB Record Listing Function. * * @param object $mode [optional] - reserved * @return void */ function listRecords($mode = FALSE) { $ns = e107::getRender(); $sql = e107::getDb(); $frm = e107::getForm(); global $pref; $emessage = eMessage::getInstance(); $text = "
".$this->pluginTitle." ". $frm->colGroup($this->fields,$this->fieldpref). $frm->thead($this->fields,$this->fieldpref). ""; if(!$sql->db_Select_gen($this->listQry)) { $text .= "\n\n"; } else { $row = $sql->db_getList('ALL', FALSE, FALSE); foreach($row as $field) { $text .= "\n"; foreach($this->fields as $key=>$att) { $class = vartrue($this->fields[$key]['thclass']) ? "class='".$this->fields[$key]['thclass']."'" : ""; $text .= (in_array($key,$this->fieldpref) || $att['forced']==TRUE) ? "\t\n" : ""; } $text .= "\n"; } } $text .= "
".CUSLAN_42."
".$this->renderValue($key,$field)."
"; $ns->tablerender($this->pluginTitle." :: ".$this->listCaption, $emessage->render().$text); } /** * Render Field value (listing page) * * @param array $key * @param array $row * @return string */ function renderValue($key, $row) { $att = $this->fields[$key]; $frm = e107::getForm(); if($key == "options") { $id = $this->primary; $text = ""; $text .= ""; return $text; } if($key == "tinymce_userclass") { return $frm->uc_label($row[$key]); } if($key == "tinymce_plugins") { return str_replace(",","
",$row[$key]); } switch($att['type']) { case 'url': return "".$row[$key].""; break; default: return $row[$key]; break; } return $row[$key] .$att['type']; } /** * Render Form Element (edit page) * * @param array $key * @param array $row * @return string method's value or HTML input */ function renderElement($key, $row) { $frm = e107::getForm(); $att = $this->fields[$key]; $value = $row[$key]; if($att['method']) { $meth = $att['method']; if(isset($att['methodparms'])) { return $this->$meth($value, $att['methodparms']); } return $this->$meth($value); } return $frm->text($key, $row[$key], 50); } function createRecord($id=FALSE) { global $frm, $e_userclass, $e_event; $tp = e107::getParser(); $ns = e107::getRender(); $sql = e107::getDb(); $mes = eMessage::getInstance(); if($id) { $query = str_replace("{ID}",$id,$this->editQry); $sql->db_Select_gen($query); $row = $sql->db_Fetch(); } else { $row = array(); } $text = "
".$this->pluginTitle." "; foreach($this->fields as $key=>$att) { if($att['forced']!==TRUE) { $text .= " "; } } $text .= "
Preview ".$this->tinymce_preview()."
".$att['title']." ".$this->renderElement($key,$row)."
"; if($id) { $text .= $frm->admin_button('update', LAN_UPDATE, 'update'); $text .= ""; } else { $text .= $frm->admin_button('create', LAN_CREATE, 'create'); } $text .= "
"; $ns->tablerender($this->pluginTitle." :: ".$this->createCaption,$mes->render(). $text); } function tinymce_buttons($curVal,$id) { return "\n"; } function tinymce_preview() { return ""; } function tinymce_plugins($curVal) { $fl = e107::getFile(); $curArray = explode(",",$curVal); if($plug_array = $fl->get_dirs(e_PLUGIN."tinymce/plugins/")) { sort($plug_array); } $text = "
"; foreach($plug_array as $mce_plg) { $checked = (in_array($mce_plg,$curArray)) ? "checked='checked'" : ""; $text .= "
$mce_plg
"; } $text .= "
"; return $text; } function tinymce_class($curVal) { $frm = e107::getForm(); // $cur = explode(",",$curVal); $uc_options = "guest,member,admin,main,classes"; return $frm->uc_checkbox('tinymce_userclass', $curVal, $uc_options); } /** * Generic Save DB Record Function. * Insert or Update a table row. * * @param mixed $id [optional] if set, $id correspond to the primary key of the table * @return void */ function submitPage($id = FALSE) { global $sql, $tp, $e107cache, $admin_log, $e_event; $emessage = eMessage::getInstance(); $insert_array = array(); foreach($this->fields as $key=>$att) { if($att['forced']!=TRUE) { $insert_array[$key] = $_POST[$key]; } if($att['type']=='array') { $insert_array[$key] = implode(",",$_POST[$key]); } } $xml = new SimpleXMLElement(''); $insertXml = array_flip($insert_array); array_walk_recursive($insertXml, array ($xml, 'addChild')); $save = $xml->asXML(); file_put_contents(e_SYSTEM."admin.xml",$save); // echo htmlentities($save); if($id) { $insert_array['WHERE'] = $this->primary." = ".$id; $status = $sql->db_Update($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; $message = LAN_UPDATED; } else { $status = $sql->db_Insert($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; $message = LAN_CREATED; } $emessage->add($message, $status); } function deleteRecord($id) { if(!$id || !$this->primary || !$this->table) { return; } $emessage = eMessage::getInstance(); $sql = e107::getDb(); $query = $this->primary." = ".$id; $status = $sql->db_Delete($this->table,$query) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; $message = LAN_DELETED; $emessage->add($message, $status); } function optionsPage() { global $e107, $pref, $frm, $emessage; if(!isset($pref['pageCookieExpire'])) $pref['pageCookieExpire'] = 84600; //XXX Lan - Options $text = "
".LAN_OPTIONS."
".CUSLAN_29." ".$frm->radio_switch('listPages', $pref['listPages'])."
".CUSLAN_30." ".$frm->text('pageCookieExpire', $pref['pageCookieExpire'], 10)."
".$frm->admin_button('saveOptions', CUSLAN_40, 'submit')."
"; $e107->ns->tablerender(LAN_OPTIONS, $emessage->render().$text); } function saveSettings() { global $pref, $admin_log, $emessage; $temp['listPages'] = $_POST['listPages']; $temp['pageCookieExpire'] = $_POST['pageCookieExpire']; if ($admin_log->logArrayDiffs($temp, $pref, 'CPAGE_04')) { save_prefs(); // Only save if changes $emessage->add(CUSLAN_45, E_MESSAGE_SUCCESS); } else { $emessage->add(CUSLAN_46); } } function show_options($action) { $action = varset($_GET['mode'],'list'); $var['list']['text'] = $this->listCaption; $var['list']['link'] = e_SELF."?mode=list"; $var['list']['perm'] = "0"; $var['create']['text'] = $this->createCaption; $var['create']['link'] = e_SELF."?mode=create"; $var['create']['perm'] = 0; /* $var['options']['text'] = LAN_OPTIONS; $var['options']['link'] = e_SELF."?options"; $var['options']['perm'] = "0";*/ e107::getNav()->admin($this->pluginTitle, $action, $var); } } function admin_config_adminmenu() { global $ef; global $action; $ef->show_options($action); } if($_POST['save_settings']) // Needs to be saved before e_meta.php is loaded by auth.php. { $tpref['customjs'] = $_POST['customjs']; $tpref['theme_advanced_buttons1'] = $_POST['theme_advanced_buttons1']; $tpref['theme_advanced_buttons2'] = $_POST['theme_advanced_buttons2']; $tpref['theme_advanced_buttons3'] = $_POST['theme_advanced_buttons3']; $tpref['theme_advanced_buttons4'] = $_POST['theme_advanced_buttons4']; $tpref['plugins'] = $_POST['mce_plugins']; e107::getPlugConfig('tinymce')->setPref($tpref); e107::getPlugConfig('tinymce')->save(); } $tpref = e107::getPlugConfig('tinymce')->getPref(); if($_POST['save_settings']) // is there an if $emessage? $emessage->hasMessage doesn't return TRUE. { $emessage->add(LAN_UPDATED, E_MESSAGE_SUCCESS); e107::getRender()->tablerender(LAN_UPDATED, $emessage->render()); } if(!$tpref['theme_advanced_buttons1']) { $tpref['theme_advanced_buttons1'] = "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect"; } if(!$tpref['theme_advanced_buttons2']) { $tpref['theme_advanced_buttons2'] = "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor"; } if(!$tpref['theme_advanced_buttons3']) { $tpref['theme_advanced_buttons3'] = "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen,emoticons,ibrowser"; } if(!$tpref['theme_advanced_buttons4']) { $tpref['theme_advanced_buttons4'] = "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage"; } function edit_theme() { $ns = e107::getRender(); $text = "
Preview
Installed Plugins
"; foreach($plug_array as $mce_plg) { $checked = (in_array($mce_plg,$tpref['plugins'])) ? "checked='checked'" : ""; $text .= "
$mce_plg
"; } $text .= "
Button Layout "; for ($i=1; $i<=4; $i++) { $rowNm = "theme_advanced_buttons".$i; $text .= "\t\n"; } $text .= "
Custom TinyMce Javascript
"; $text .= ""; $text .= "
"; $ns -> tablerender("TinyMCE Configuration", $text); } require_once(e_ADMIN."footer.php"); ?>