updt=ate ollama indocker and add plugins

This commit is contained in:
southseact-3d
2026-02-09 18:09:12 +00:00
parent a52572ede1
commit a546eafc0b
39 changed files with 5239 additions and 0 deletions

View File

@@ -0,0 +1,414 @@
<?php
// File: admin/class-admin.php
if (!defined('ABSPATH')) {
exit;
}
class PC_HFAP_Admin {
private $page_hook;
public function __construct() {
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets'));
add_action('admin_post_pc_hfap_save_snippet', array($this, 'handle_save_snippet'));
}
public function add_admin_menu() {
$this->page_hook = add_menu_page(
__('Headers & Footers Code', 'pc-headers-and-footers-and-ad-pixels-5ake'),
__('Headers & Footers', 'pc-headers-and-footers-and-ad-pixels-5ake'),
'manage_options',
'pc-hfap-snippets',
array($this, 'render_snippets_page'),
'dashicons-code-standards',
30
);
add_submenu_page(
'pc-hfap-snippets',
__('All Snippets', 'pc-headers-and-footers-and-ad-pixels-5ake'),
__('All Snippets', 'pc-headers-and-footers-and-ad-pixels-5ake'),
'manage_options',
'pc-hfap-snippets',
array($this, 'render_snippets_page')
);
add_submenu_page(
'pc-hfap-snippets',
__('Add New Snippet', 'pc-headers-and-footers-and-ad-pixels-5ake'),
__('Add New', 'pc-headers-and-footers-and-ad-pixels-5ake'),
'manage_options',
'pc-hfap-add-snippet',
array($this, 'render_add_snippet_page')
);
add_submenu_page(
'pc-hfap-snippets',
__('Settings', 'pc-headers-and-footers-and-ad-pixels-5ake'),
__('Settings', 'pc-headers-and-footers-and-ad-pixels-5ake'),
'manage_options',
'pc-hfap-settings',
array($this, 'render_settings_page')
);
}
public function handle_save_snippet() {
// Check nonce
if (!isset($_POST['pc_hfap_nonce']) || !wp_verify_nonce($_POST['pc_hfap_nonce'], 'pc_hfap_save_snippet')) {
wp_redirect(admin_url('admin.php?page=pc-hfap-add-snippet&error=nonce'));
exit;
}
// Check permissions
if (!current_user_can('manage_options')) {
wp_redirect(admin_url('admin.php?page=pc-hfap-add-snippet&error=permission'));
exit;
}
// Validate fields
if (empty($_POST['pc_hfap_title']) || empty($_POST['pc_hfap_location']) || empty($_POST['pc_hfap_code'])) {
wp_redirect(admin_url('admin.php?page=pc-hfap-add-snippet&error=validation'));
exit;
}
// Prepare data
$data = array(
'title' => sanitize_text_field($_POST['pc_hfap_title']),
'location' => in_array($_POST['pc_hfap_location'], array('header', 'footer', 'body')) ? $_POST['pc_hfap_location'] : 'header',
'code' => wp_unslash($_POST['pc_hfap_code'])
);
// Check if editing
$is_edit = !empty($_POST['pc_hfap_id']);
if ($is_edit) {
$snippet = PC_HFAP_Snippet::get_by_id(intval($_POST['pc_hfap_id']));
if ($snippet) {
$snippet->set_title($data['title']);
$snippet->set_location($data['location']);
$snippet->set_code($data['code']);
$result = $snippet->save();
if ($result !== false) {
wp_redirect(admin_url('admin.php?page=pc-hfap-snippets&message=updated'));
exit;
}
}
wp_redirect(admin_url('admin.php?page=pc-hfap-add-snippet&id=' . intval($_POST['pc_hfap_id']) . '&error=save'));
exit;
} else {
$snippet = new PC_HFAP_Snippet($data);
$result = $snippet->save();
if ($result) {
wp_redirect(admin_url('admin.php?page=pc-hfap-snippets&message=created'));
exit;
}
wp_redirect(admin_url('admin.php?page=pc-hfap-add-snippet&error=save'));
exit;
}
}
public function enqueue_admin_assets($hook) {
if ($hook !== $this->page_hook && strpos($hook, 'pc-hfap-') === false) {
return;
}
wp_enqueue_style(
'pc-hfap-admin-style',
PC_HFAP_PLUGIN_URL . 'admin/css/admin-style.css',
array(),
PC_HFAP_VERSION
);
wp_enqueue_script(
'pc-hfap-admin-script',
PC_HFAP_PLUGIN_URL . 'admin/js/admin-script.js',
array('jquery'),
PC_HFAP_VERSION,
true
);
wp_localize_script('pc-hfap-admin-script', 'pc_hfap_admin', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('pc_hfap_admin_nonce'),
'confirm_delete' => __('Are you sure you want to delete this snippet?', 'pc-headers-and-footers-and-ad-pixels-5ake')
));
}
public function render_snippets_page() {
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'pc-headers-and-footers-and-ad-pixels-5ake'));
}
// Handle delete BEFORE any HTML output
if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) {
check_admin_referer('delete_snippet_' . intval($_GET['id']));
if (!current_user_can('manage_options')) {
wp_die(__('You do not have permission.', 'pc-headers-and-footers-and-ad-pixels-5ake'));
}
$snippet = PC_HFAP_Snippet::get_by_id(intval($_GET['id']));
if ($snippet) {
$result = $snippet->delete();
if ($result) {
wp_redirect(admin_url('admin.php?page=pc-hfap-snippets&message=deleted'));
exit;
}
}
}
// Show messages
$message = isset($_GET['message']) ? $_GET['message'] : '';
if ($message === 'created') {
echo '<div class="notice notice-success is-dismissible"><p>Snippet created successfully!</p></div>';
} elseif ($message === 'updated') {
echo '<div class="notice notice-success is-dismissible"><p>Snippet updated successfully!</p></div>';
} elseif ($message === 'deleted') {
echo '<div class="notice notice-success is-dismissible"><p>Snippet deleted successfully!</p></div>';
}
$snippets = PC_HFAP_Snippet::get_all();
?>
<div class="wrap pc-hfap-wrap">
<h1 class="wp-heading-inline">
<?php _e('Headers & Footers Code Snippets', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</h1>
<a href="<?php echo admin_url('admin.php?page=pc-hfap-add-snippet'); ?>" class="page-title-action">
<?php _e('Add New', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</a>
<hr class="wp-header-end">
<?php if (empty($snippets)): ?>
<div class="notice notice-info">
<p><?php _e('No snippets found. Add your first header or footer code snippet!', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?></p>
</div>
<?php else: ?>
<div class="pc-hfap-snippets-table">
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th scope="col" class="manage-column column-title"><?php _e('Title', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?></th>
<th scope="col" class="manage-column column-location"><?php _e('Location', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?></th>
<th scope="col" class="manage-column column-code"><?php _e('Code Preview', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?></th>
<th scope="col" class="manage-column column-actions"><?php _e('Actions', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($snippets as $snippet): ?>
<tr>
<td class="column-title">
<strong><?php echo esc_html($snippet->get_title()); ?></strong>
</td>
<td class="column-location">
<?php
$location = $snippet->get_location();
if ($location === 'header') {
$location_label = __('Header', 'pc-headers-and-footers-and-ad-pixels-5ake');
} elseif ($location === 'body') {
$location_label = __('Body', 'pc-headers-and-footers-and-ad-pixels-5ake');
} else {
$location_label = __('Footer', 'pc-headers-and-footers-and-ad-pixels-5ake');
}
?>
<span class="pc-hfap-location-badge pc-hfap-location-<?php echo esc_attr($location); ?>">
<?php echo esc_html($location_label); ?>
</span>
</td>
<td class="column-code">
<code class="pc-hfap-code-preview">
<?php
$code = esc_html($snippet->get_code());
echo strlen($code) > 100 ? substr($code, 0, 100) . '...' : $code;
?>
</code>
</td>
<td class="column-actions">
<a href="<?php echo admin_url('admin.php?page=pc-hfap-add-snippet&id=' . $snippet->get_id()); ?>" class="button button-small">
<?php _e('Edit', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</a>
<a href="<?php echo wp_nonce_url(admin_url('admin.php?page=pc-hfap-snippets&action=delete&id=' . $snippet->get_id()), 'delete_snippet_' . $snippet->get_id()); ?>"
class="button button-small button-link-delete"
onclick="return confirm('<?php esc_attr_e('Are you sure you want to delete this snippet?', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>');">
<?php _e('Delete', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
<?php
}
public function render_add_snippet_page() {
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'pc-headers-and-footers-and-ad-pixels-5ake'));
}
$snippet = null;
$is_edit = false;
// Check if editing existing
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$snippet = PC_HFAP_Snippet::get_by_id(intval($_GET['id']));
$is_edit = true;
}
// Show error messages
if (isset($_GET['error'])) {
if ($_GET['error'] === 'nonce') {
echo '<div class="notice notice-error"><p>Security check failed. Please try again.</p></div>';
} elseif ($_GET['error'] === 'permission') {
echo '<div class="notice notice-error"><p>You do not have permission to perform this action.</p></div>';
} elseif ($_GET['error'] === 'validation') {
echo '<div class="notice notice-error"><p>Please fill in all required fields.</p></div>';
} elseif ($_GET['error'] === 'save') {
echo '<div class="notice notice-error"><p>Failed to save snippet. Please try again.</p></div>';
}
}
// Get form values
$form_title = isset($_POST['pc_hfap_title']) ? $_POST['pc_hfap_title'] : ($snippet ? $snippet->get_title() : '');
$form_location = isset($_POST['pc_hfap_location']) ? $_POST['pc_hfap_location'] : ($snippet ? $snippet->get_location() : 'header');
$form_code = isset($_POST['pc_hfap_code']) ? $_POST['pc_hfap_code'] : ($snippet ? $snippet->get_code() : '');
?>
<div class="wrap pc-hfap-wrap">
<h1>
<?php
if ($is_edit && $snippet) {
echo esc_html__('Edit Snippet: ', 'pc-headers-and-footers-and-ad-pixels-5ake') . esc_html($snippet->get_title());
} else {
_e('Add New Code Snippet', 'pc-headers-and-footers-and-ad-pixels-5ake');
}
?>
</h1>
<hr class="wp-header-end">
<div class="pc-hfap-form-container">
<form method="post" action="<?php echo admin_url('admin-post.php?action=pc_hfap_save_snippet'); ?>" class="pc-hfap-snippet-form">
<?php wp_nonce_field('pc_hfap_save_snippet', 'pc_hfap_nonce'); ?>
<div class="pc-hfap-form-section">
<h2><?php _e('Snippet Details', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?></h2>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label for="pc_hfap_title">
<?php _e('Snippet Title', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
<span class="required">*</span>
</label>
</th>
<td>
<input type="text"
id="pc_hfap_title"
name="pc_hfap_title"
class="regular-text"
value="<?php echo esc_attr($form_title); ?>"
required>
<p class="description">
<?php _e('A descriptive name for this code snippet', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="pc_hfap_location">
<?php _e('Insert Location', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
<span class="required">*</span>
</label>
</th>
<td>
<select id="pc_hfap_location" name="pc_hfap_location" class="regular-text" required>
<option value="header" <?php selected($form_location, 'header'); ?>>
<?php _e('Header - Insert in <head> section', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</option>
<option value="body" <?php selected($form_location, 'body'); ?>>
<?php _e('Body - Insert after <body> tag', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</option>
<option value="footer" <?php selected($form_location, 'footer'); ?>>
<?php _e('Footer - Insert before </body> tag', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</option>
</select>
<p class="description">
<?php _e('Choose where this code should be inserted.', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="pc_hfap_code">
<?php _e('Code Snippet', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
<span class="required">*</span>
</label>
</th>
<td>
<textarea id="pc_hfap_code"
name="pc_hfap_code"
rows="15"
class="large-text code"
placeholder="<?php esc_attr_e('Paste your HTML, JavaScript, or CSS code here...', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>"
required><?php echo esc_textarea($form_code); ?></textarea>
<p class="description">
<?php _e('Enter the code you want to insert.', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="pc-hfap-form-actions">
<?php if ($is_edit && $snippet): ?>
<input type="hidden" name="pc_hfap_id" value="<?php echo esc_attr($snippet->get_id()); ?>">
<?php endif; ?>
<p class="submit">
<button type="submit"
name="submit_snippet"
class="button button-primary button-large">
<?php echo $is_edit ? __('Update Snippet', 'pc-headers-and-footers-and-ad-pixels-5ake') : __('Save Snippet', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</button>
<a href="<?php echo admin_url('admin.php?page=pc-hfap-snippets'); ?>" class="button button-large">
<?php _e('Cancel', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?>
</a>
</p>
</div>
</form>
</div>
</div>
<?php
}
public function render_settings_page() {
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions.', 'pc-headers-and-footers-and-ad-pixels-5ake'));
}
?>
<div class="wrap pc-hfap-wrap">
<h1><?php _e('Headers & Footers Settings', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?></h1>
<hr class="wp-header-end">
<div class="pc-hfap-form-container">
<p><?php _e('Plugin settings and uninstall options coming soon.', 'pc-headers-and-footers-and-ad-pixels-5ake'); ?></p>
</div>
</div>
<?php
}
}

View File

@@ -0,0 +1,363 @@
/* File: admin/css/admin-style.css */
.pc-hfap-wrap {
max-width: 1200px;
margin: 20px auto;
}
.pc-hfap-wrap h1 {
color: #1d2327;
margin-bottom: 20px;
}
.pc-hfap-wrap .wp-heading-inline {
display: inline-block;
margin-right: 10px;
}
.pc-hfap-wrap .page-title-action {
margin-left: 4px;
padding: 4px 8px;
position: relative;
top: -3px;
text-decoration: none;
border: 1px solid #2271b1;
border-radius: 2px;
background: #f6f7f7;
color: #2271b1;
}
.pc-hfap-wrap .page-title-action:hover {
background: #f0f0f1;
border-color: #0a4b78;
color: #0a4b78;
}
/* Table Styles */
.pc-hfap-snippets-table {
margin: 20px 0;
background: #fff;
border: 1px solid #c3c4c7;
box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.pc-hfap-snippets-table table {
border: none;
box-shadow: none;
}
.pc-hfap-snippets-table th {
font-weight: 600;
color: #1d2327;
}
.pc-hfap-snippets-table td {
vertical-align: middle;
}
/* Location Badges */
.pc-hfap-location-badge {
display: inline-block;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.pc-hfap-location-header {
background-color: #e8f4fd;
color: #135e96;
border: 1px solid #a8d4ff;
}
.pc-hfap-location-footer {
background-color: #f0f6fc;
color: #0a4b78;
border: 1px solid #b5d0ff;
}
/* Code Preview */
.pc-hfap-code-preview {
display: block;
background: #f6f7f7;
padding: 4px 8px;
border-radius: 3px;
border-left: 3px solid #72aee6;
font-family: 'Courier New', monospace;
font-size: 12px;
color: #50575e;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 300px;
}
/* Action Buttons */
.pc-hfap-snippets-table .button-small {
padding: 2px 8px;
font-size: 12px;
line-height: 1.5;
margin: 0 2px;
}
.pc-hfap-snippets-table .button-link-delete {
color: #d63638;
border-color: #d63638;
}
.pc-hfap-snippets-table .button-link-delete:hover {
background: #d63638;
color: #fff;
border-color: #d63638;
}
/* Form Container */
.pc-hfap-form-container {
background: #fff;
padding: 25px;
border: 1px solid #c3c4c7;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
border-radius: 4px;
margin: 20px 0;
}
.pc-hfap-snippet-form {
background: #fff;
padding: 25px;
border: 1px solid #c3c4c7;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
border-radius: 4px;
}
/* Form Sections */
.pc-hfap-form-section {
margin-bottom: 30px;
}
.pc-hfap-form-section h2 {
margin-top: 0;
padding-bottom: 10px;
border-bottom: 1px solid #dcdcde;
color: #1d2327;
}
.pc-hfap-form-section .form-table {
margin-top: 0;
}
.pc-hfap-form-section th {
width: 200px;
padding: 20px 10px 20px 0;
font-weight: 600;
color: #1d2327;
}
.pc-hfap-form-section td {
padding: 15px 10px;
}
.pc-hfap-form-section input[type="text"],
.pc-hfap-form-section select,
.pc-hfap-form-section textarea {
width: 100%;
max-width: 600px;
}
.pc-hfap-form-section textarea.code {
font-family: 'Courier New', monospace;
font-size: 13px;
line-height: 1.5;
}
.pc-hfap-form-section .required {
color: #d63638;
}
.pc-hfap-form-section .description {
color: #646970;
font-size: 13px;
margin-top: 4px;
}
/* Form Actions */
.pc-hfap-form-actions {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #dcdcde;
text-align: right;
}
.pc-hfap-form-actions .button-primary {
background: #2271b1;
border-color: #2271b1;
color: #fff;
text-decoration: none;
text-shadow: none;
padding: 8px 20px;
font-size: 14px;
line-height: 1.5;
min-height: 32px;
margin-right: 10px;
}
.pc-hfap-form-actions .button-primary:hover {
background: #135e96;
border-color: #135e96;
}
.pc-hfap-form-actions .button {
padding: 8px 20px;
padding: 0 15px;
font-size: 14px;
line-height: 1.5;
min-height: 32px;
}
/* Info and Help Cards */
.pc-hfap-info-card,
.pc-hfap-help-card {
background: #fff;
padding: 25px;
border: 1px solid #c3c4c7;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
border-radius: 4px;
margin: 20px 0;
border-left: 4px solid #72aee6;
}
.pc-hfap-info-card h2,
.pc-hfap-help-card h2 {
margin-top: 0;
color: #1d2327;
padding-bottom: 10px;
border-bottom: 1px solid #f0f0f0;
}
.pc-hfap-info-card ul,
.pc-hfap-help-card ul {
margin-left: 20px;
padding-left: 0;
}
.pc-hfap-info-card li,
.pc-hfap-help-card li {
margin-bottom: 8px;
line-height: 1.5;
}
/* Code Examples */
.pc-hfap-code-examples {
margin-top: 20px;
}
.pc-hfap-code-examples h4 {
margin: 15px 0 10px 0;
color: #2c3338;
font-size: 14px;
}
.pc-hfap-code-examples pre {
background: #f6f7f7;
border: 1px solid #dcdcde;
border-radius: 4px;
padding: 15px;
overflow-x: auto;
margin: 0 0 20px 0;
}
.pc-hfap-code-examples code {
font-family: 'Consolas', 'Monaco', monospace;
font-size: 12px;
line-height: 1.4;
color: #50575e;
background: transparent;
padding: 0;
}
/* Column widths */
.pc-hfap-snippets-table .column-title {
width: 25%;
}
.pc-hfap-snippets-table .column-location {
width: 15%;
}
.pc-hfap-snippets-table .column-code {
width: 40%;
}
.pc-hfap-snippets-table .column-actions {
width: 20%;
text-align: right;
}
/* Responsive design */
@media screen and (max-width: 782px) {
.pc-hfap-form-section th {
width: 100%;
display: block;
padding: 10px 0 0 0;
}
.pc-hfap-form-section td {
display: block;
padding: 0 0 20px 0;
}
.pc-hfap-snippets-table {
overflow-x: auto;
}
.pc-hfap-snippets-table table {
min-width: 600px;
}
}
/* Animation for success messages */
@keyframes pc-hfap-fade-in {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.notice.pc-hfap-notice {
animation: pc-hfap-fade-in 0.3s ease-out;
}
/* Loading state */
.pc-hfap-loading {
opacity: 0.6;
pointer-events: none;
}
/* Grid layout for form container */
.pc-hfap-form-container {
display: grid;
grid-template-columns: 2fr 1fr;
gap: 30px;
margin-top: 20px;
}
@media (max-width: 1024px) {
.pc-hfap-form-container {
grid-template-columns: 1fr;
}
}
/* Highlight animation for new rows */
@keyframes pc-hfap-highlight {
0% { background-color: #f0f6fc; }
100% { background-color: transparent; }
}
.pc-hfap-snippets-table tr.highlight {
animation: pc-hfap-highlight 2s ease-out;
}

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden

View File

@@ -0,0 +1,99 @@
// File: admin/js/admin-script.js
jQuery(document).ready(function($) {
'use strict';
// Confirm delete actions
$('.pc-hfap-snippets-table .button-link-delete').on('click', function(e) {
if (!confirm(pc_hfap_admin.confirm_delete)) {
e.preventDefault();
return false;
}
});
// Form validation
$('.pc-hfap-snippet-form').on('submit', function(e) {
var title = $('#pc_hfap_title').val().trim();
var code = $('#pc_hfap_code').val().trim();
var location = $('#pc_hfap_location').val();
if (!title) {
alert('Please enter a title for the snippet.');
$('#pc_hfap_title').focus();
e.preventDefault();
return false;
}
if (!location || (location !== 'header' && location !== 'body' && location !== 'footer')) {
alert('Please select a valid location for the snippet.');
$('#pc_hfap_location').focus();
e.preventDefault();
return false;
}
if (!code) {
alert('Please enter the code for the snippet.');
$('#pc_hfap_code').focus();
e.preventDefault();
return false;
}
});
// Code editor enhancement (if CodeMirror is available)
if (typeof wp !== 'undefined' && wp.codeEditor) {
var codeEditorSettings = wp.codeEditor.defaultSettings ? _.clone(wp.codeEditor.defaultSettings) : {};
codeEditorSettings.codemirror = _.extend({}, codeEditorSettings.codemirror, {
lineNumbers: true,
lineWrapping: true,
mode: 'htmlmixed',
indentUnit: 4,
tabSize: 4,
theme: 'default'
});
var editor = wp.codeEditor.initialize($('#pc_hfap_code'), codeEditorSettings);
}
// Character counter for code preview
$('.pc-hfap-code-preview').each(function() {
var text = $(this).text();
var charCount = text.length;
var $counter = $('<span class="pc-hfap-char-count"> (' + charCount + ' chars)</span>');
$(this).after($counter);
});
// Highlight new rows
if (window.location.hash === '#new') {
var $newRow = $('.pc-hfap-snippets-table tbody tr:first-child');
$newRow.addClass('highlight');
// Scroll to the new row
$('html, body').animate({
scrollTop: $newRow.offset().top - 100
}, 500);
// Remove hash without scrolling
history.replaceState(null, null, ' ');
}
// Toggle for code snippet preview
$('.pc-hfap-code-preview').on('click', function() {
var $preview = $(this);
var fullCode = $preview.data('full-code');
if (!fullCode) {
fullCode = $preview.text();
$preview.data('full-code', fullCode);
$preview.data('is-expanded', false);
}
if ($preview.data('is-expanded')) {
// Collapse
$preview.text(fullCode.length > 100 ? fullCode.substring(0, 100) + '...' : fullCode);
$preview.data('is-expanded', false);
} else {
// Expand
$preview.text(fullCode);
$preview.data('is-expanded', true);
}
});
});

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden