modx->getTemplateVar($tvName, '*', $docID); $field_name = isset($tv['id']) ? $tv['id'] : $tv['name']; // Handle default TVs switch ($tvName) { case 'pagetitle' : $tv['type'] = 'text'; $tv['caption'] = $this->getDefaultTvCaption($tvName); $access = TRUE; break; case 'longtitle' : $tv['type'] = 'text'; $tv['caption'] = $this->getDefaultTvCaption($tvName); $access = TRUE; break; case 'description' : $tv['type'] = 'textarea'; $tv['caption'] = $this->getDefaultTvCaption($tvName); $access = TRUE; break; case 'content' : $tv['type'] = getTvType();$tv['caption'] = $this->getDefaultTvCaption($tvName); $access = TRUE; break; case 'menutitle' : $tv['type'] = 'text'; $tv['caption'] = $this->getDefaultTvCaption($tvName); $access = TRUE; break; case 'introtext' : $tv['type'] = 'textarea'; $tv['caption'] = $this->getDefaultTvCaption($tvName); $access = TRUE; break; } // Check TV access if (!$access) { $access = $this->checkTvAccess($tv['id']); } if (!$access) { return 'Error: Access denied.'; } // User can access TV // Show TV form if ($save == 0) { // Check is document locked? Someone else is editing the document... //$_lang['lock_msg'] if ($this->checkLocked()) { $locked = true; } else { $this->setLocked(1); } // Set document locked // Handle RTE if($tv['type'] === 'richtext') { // Invoke OnRichTextEditorInit event $tmp = array('editor'=>$this->modx->config['which_editor'], 'elements'=>array('tv'.$tvName)); $eventOutput = $this->modx->invokeEvent("OnRichTextEditorInit", $tmp); if(is_array($eventOutput)) { $editorHtml = implode("",$eventOutput); } } // Render TV html $tvHtml = $this->modx->renderFormElement($tv['type'], addslashes($field_name), $tv['default_text'], $tv['elements'], $tv['value']); } else { // Save TV $this->setLocked(0); // Remove document locked // Save TV $this->saveTv($tvName); } // Page output: header $theme = $this->modx->config['manager_theme']; $output = <<< EOT EOT; // Page output: TV form if ($save == 0) { $output .= ''; // Document is locked message if ($locked) { $output .= '

'.$_lang['locked'].'

'.$_lang['lock_msg'].'
'; } else { // Normal form // Image preview if ($tv['type'] === 'image') { $imagePreview = $this->get_img_prev_src(); $imagePreview = str_replace('[+site_url+]',$this->modx->config['site_url'],$imagePreview); $imagePreview = str_replace('[+tv_value+]',$tv['value'],$imagePreview); $imagePreview = str_replace('[+tv_name+]',$tvName,$imagePreview); } else $imagePreview = ''; $output .= '

'.$tv['caption'].'

'.$tv['description'].'
'.$tvHtml.'
'.$imagePreview.'
'.$editorHtml.' '; } } // Page output: close modal box and refresh parent frame else { $output .= ''; } // Page output: footer $output .= ' '; return $output; function getTvType() { global $modx; if($modx->config['use_editor']==0 || $modx->documentObject['richtext']==0) { return 'textarea'; } return 'richtext'; }