static function TplForm($type, $tpl_tag = null) { $new = empty($tpl_tag); $cat = $type == 'cat'; $list = $type == 'list'; $code_id = 'tplinp_' . $type; if (!$list) { if ($new) { $tpl_code = empty($_POST['tplcode']) ? '' : $_POST['tplcode']; } else { $tpl_code = WPFB_Core::GetTpls($type, $tpl_tag); if (empty($tpl_code)) { $tpl_code = ''; } } $item = $cat ? self::$sample_cat : self::$sample_file; } else { $tpl = $new ? new WPFB_ListTpl() : WPFB_ListTpl::Get($tpl_tag); } ?> <h2><?php $new ? _e('Add Template', 'wp-filebase') : _e('Edit Template', 'wp-filebase'); if (!empty($tpl_tag)) { echo ' ' . self::TplTitle($tpl_tag); } ?> </h2> <form action="<?php echo remove_query_arg(array('action', 'type', 'tpl')) . '#' . $type; ?> " method="post"> <?php wp_nonce_field(($new ? 'add' : 'update') . '-' . $type, 'wpfb-tpl-nonce'); ?> <input type="hidden" name="action" value="<?php echo $new ? 'add' : 'update'; ?> " /> <input type="hidden" name="type" value="<?php echo $type; ?> " /> <?php if ($new) { ?> <p> <label for="tpltag"><?php _e('Template Tag (a single word to describe the template):', 'wp-filebase'); ?> </label> <input type="text" name="tpltag" value="<?php if (!empty($_POST['tpltag'])) { echo esc_attr($_POST['tpltag']); } ?> " tabindex="1" maxlength="20" /> </p> <?php } else { ?> <input type="hidden" name="tpltag" value="<?php echo esc_attr($tpl_tag); ?> " /><?php } if ($list) { ?> <table class="form-table"> <tr class="form-field"> <th scope="row" valign="top"><label for="tpl-list-header"><?php _e('Header', 'wp-filebase'); ?> </label></th> <td width="100%"> <textarea id="tpl-list-header" name="tpl-list-header" cols="70" rows="<?php echo max(2, count(explode("\n", $tpl->header))) + 3; ?> " wrap="off" class="codepress html wpfilebase-tpledit" onkeyup="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo htmlspecialchars($tpl->header); ?> </textarea><br /> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"><label for="tpl-list-cat-tpl"><?php _e('Category Template', 'wp-filebase'); ?> </label></th> <td width=""> <select id="tpl-list-cat-tpl" name="tpl-list-cat-tpl" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo WPFB_Admin::TplDropDown('cat', $tpl->cat_tpl_tag); ?> </select> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"><label for="tpl-list-file-tpl"><?php _e('File Template', 'wp-filebase'); ?> </label></th> <td> <select id="tpl-list-file-tpl" name="tpl-list-file-tpl" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo WPFB_Admin::TplDropDown('file', $tpl->file_tpl_tag); ?> </select> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"><label for="tpl-list-footer"><?php _e('Footer', 'wp-filebase'); ?> </label></th> <td> <textarea id="tpl-list-footer" name="tpl-list-footer" cols="70" rows="<?php echo max(2, count(explode("\n", $tpl->footer))) + 3; ?> " wrap="off" class="codepress html wpfilebase-tpledit" onkeyup="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo htmlspecialchars($tpl->footer); ?> </textarea><br /> </td> </tr> </table> <?php } else { ?> <p> <?php _e('Template Code:', 'wp-filebase'); ?> <br /> <textarea id="<?php echo $code_id; ?> " cols="70" rows="<?php echo max(2, count(explode("\n", $tpl_code))) + 3; ?> " wrap="off" name="tplcode" class="codepress html wpfilebase-tpledit" onkeyup="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')" onchange="WPFB_PreviewTpl(this, '<?php echo $type; ?> ')"><?php echo htmlspecialchars($tpl_code); ?> </textarea><br /> <?php wpfb_loadclass('Models'); echo WPFB_Models::TplFieldsSelect($code_id, false, $cat); ?> </p> <?php } ?> <p class="submit"><input type="submit" name="submit" class="button-primary" value="<?php echo esc_attr__($new ? 'Add Template' : 'Submit Template Changes', 'wp-filebase'); ?> " /></p> </form> <div class="entry-content wpfilebase-tpl-preview"> <div id="<?php echo $code_id; ?> _preview"><?php if ($list) { echo $tpl->Sample(self::$sample_cat, self::$sample_file); } else { echo empty($tpl_code) ? '<i>' . __('Preview') . '</i>' : $item->GenTpl(WPFB_TplLib::Parse($tpl_code), 'sample'); } ?> </div> <div style="height: 50px; float: left;"></div> <div class="clear"></div> </div> <?php }