Initial commit: igny8 project

This commit is contained in:
igny8
2025-11-09 10:27:02 +00:00
commit 60b8188111
27265 changed files with 4360521 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
<?php
/**
* ==============================
* 🔐 IGNY8 FILE RULE HEADER
* ==============================
* @file : ai-shortcodes.php
* @location : shortcodes/
* @type : Shortcode Handler
* @scope : Global
* @allowed : Shortcode registration and handling only
* @reusability : Global
* @notes : Main IGNY8 shortcode for content personalization
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* Register shortcode [igny8]
*/
add_shortcode('igny8', 'igny8_shortcode_handler');
/**
* Main Shortcode Handler Function
*/
function igny8_shortcode_handler($atts) {
// Normalize 'form-fields' → 'form_fields'
if (isset($atts['form-fields'])) {
$atts['form_fields'] = $atts['form-fields'];
unset($atts['form-fields']);
}
// Enable nested shortcodes in all attribute values
foreach ($atts as $key => $value) {
$atts[$key] = do_shortcode($value);
}
// Store normalized field list
$form_fields_value = $atts['form_fields'] ?? '';
// Generate inline JavaScript for personalization functionality
$ajax_url = admin_url('admin-ajax.php');
$nonce = wp_create_nonce('igny8_ajax_nonce');
// Fetch context values
$post_id = get_queried_object_id();
// Debug: Log PHP variables
error_log('IGNY8 Debug - PHP Variables:');
error_log('ajax_url: ' . $ajax_url);
error_log('nonce: ' . $nonce);
error_log('post_id: ' . $post_id);
// Check if Content Engine is enabled
$content_engine_status = get_option('igny8_content_engine_global_status', 'enabled');
$post_type = get_post_type();
$enabled_post_types = get_option('igny8_content_engine_enabled_post_types', []);
if ($content_engine_status === 'enabled' && in_array($post_type, $enabled_post_types)) {
$teaser = esc_html(get_option('igny8_content_engine_teaser_text', 'Want to read this as if it was written exclusively about you?'));
$display_mode = get_option('igny8_content_engine_display_mode', 'button');
} else {
$teaser = esc_html(get_option('igny8_teaser_text', 'Want to read this as if it was written exclusively about you?'));
$display_mode = 'button';
}
// Start output buffering
ob_start();
?>
<?php if ($display_mode === 'auto'): ?>
<!-- Auto Mode: Generate content immediately -->
<div id="igny8-auto-content"
data-ajax-url="<?php echo $ajax_url; ?>"
data-post-id="<?php echo $post_id; ?>"
data-form-fields="<?php echo esc_attr($form_fields_value); ?>"
<?php
foreach ($atts as $key => $val) {
if (!in_array($key, ['form_fields', 'form-fields'])) {
echo ' data-' . esc_attr($key) . '="' . esc_attr($val) . '"';
}
}
?>
>
<p class="igny8-teaser"><?php echo $teaser; ?></p>
<div class="igny8-loading">Generating personalized content...</div>
<div id="igny8-generated-content"></div>
</div>
<?php elseif ($display_mode === 'inline'): ?>
<!-- Inline Mode: Show personalization form directly -->
<div id="igny8-inline-form">
<p class="igny8-teaser"><?php echo $teaser; ?></p>
<div id="igny8-form-container"></div>
<div id="igny8-generated-content"></div>
</div>
<?php else: ?>
<!-- Button Mode: Show teaser text + personalization button (default) -->
<div id="igny8-trigger">
<p class="igny8-teaser"><?php echo $teaser; ?></p>
<button class="button" id="igny8-launch"
data-ajax-url="<?php echo $ajax_url; ?>"
data-post-id="<?php echo $post_id; ?>"
data-form-fields="<?php echo esc_attr($form_fields_value); ?>"
<?php
foreach ($atts as $key => $val) {
if (!in_array($key, ['form_fields', 'form-fields'])) {
echo ' data-' . esc_attr($key) . '="' . esc_attr($val) . '"';
}
}
?>
>Personalize</button>
</div>
<?php endif; ?>
<!-- Inject admin-defined context (hidden) -->
<?php
if ($content_engine_status === 'enabled' && in_array($post_type, $enabled_post_types)) {
$context_raw = get_option('igny8_content_engine_context_source', '');
} else {
$context_raw = get_option('igny8_context_source', '');
}
if (!empty($context_raw)) {
echo '<div id="igny8-context-source" style="display:none;">' . esc_html($context_raw) . '</div>';
}
?>
<script>
// Inject JavaScript variables
window.igny8_ajax_url = '<?php echo $ajax_url; ?>';
window.igny8_nonce = '<?php echo $nonce; ?>';
window.igny8_post_id = <?php echo $post_id; ?>;
window.igny8_form_fields = '<?php echo esc_js($form_fields_value); ?>';
// Debug: Log JavaScript variables
console.log('IGNY8 Debug - JavaScript Variables:');
console.log('ajax_url:', window.igny8_ajax_url);
console.log('nonce:', window.igny8_nonce);
console.log('post_id:', window.igny8_post_id);
console.log('form_fields:', window.igny8_form_fields);
</script>
<?php
return ob_get_clean();
}

View File

@@ -0,0 +1,278 @@
<?php
/**
* ==========================
* 🔐 IGNY8 FILE RULE HEADER
* ==========================
* @file : writer-shortcodes.php
* @location : /shortcodes/writer-shortcodes.php
* @type : Shortcode
* @scope : Global
* @allowed : Shortcode registration, frontend rendering
* @reusability : Globally Reusable
* @notes : Writer-related shortcodes for frontend display
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* Display specific in-article image by ID
*
* Usage: [igny8-image id="desktop-1"]
*
* @param array $atts Shortcode attributes
* @return string HTML output
*/
add_shortcode('igny8-image', function($atts) {
$atts = shortcode_atts(['id' => ''], $atts);
$post_id = get_the_ID();
if (empty($post_id)) {
return '';
}
$images = get_post_meta($post_id, '_igny8_inarticle_images', true);
if (!is_array($images)) {
return '';
}
// Display specific image by ID
if (!empty($atts['id']) && isset($images[$atts['id']])) {
$image_data = $images[$atts['id']];
// Device detection - only show if device matches
$is_mobile = wp_is_mobile();
$is_desktop = !$is_mobile;
// Check if image should be displayed based on device
$should_display = false;
if (strpos($atts['id'], 'desktop-') === 0 && $is_desktop) {
$should_display = true;
} elseif (strpos($atts['id'], 'mobile-') === 0 && $is_mobile) {
$should_display = true;
}
if (!$should_display) {
return '';
}
$attachment_id = intval($image_data['attachment_id']);
if ($attachment_id > 0) {
return wp_get_attachment_image($attachment_id, 'large', false, [
'class' => 'igny8-inarticle-image',
'data-image-id' => esc_attr($atts['id']),
'data-device' => esc_attr($image_data['device']),
'alt' => esc_attr($image_data['label'])
]);
}
}
return '';
});
/**
* Display all in-article images
*
* Usage: [igny8-images]
*
* @param array $atts Shortcode attributes
* @return string HTML output
*/
add_shortcode('igny8-images', function($atts) {
$atts = shortcode_atts([
'device' => '', // Filter by device type (desktop/mobile)
'size' => 'large', // Image size
'class' => 'igny8-image-gallery' // CSS class
], $atts);
$post_id = get_the_ID();
if (empty($post_id)) {
return '';
}
$images = get_post_meta($post_id, '_igny8_inarticle_images', true);
if (!is_array($images) || empty($images)) {
return '';
}
$output = '<div class="' . esc_attr($atts['class']) . '">';
$output .= '<p style="background: #f0f0f0; padding: 10px; border-left: 4px solid #0073aa; margin: 10px 0; font-weight: bold;">This is coming from shortcode</p>';
foreach ($images as $label => $image_data) {
// Filter by device if specified
if (!empty($atts['device']) && $image_data['device'] !== $atts['device']) {
continue;
}
$attachment_id = intval($image_data['attachment_id']);
if ($attachment_id > 0) {
$output .= wp_get_attachment_image($attachment_id, $atts['size'], false, [
'class' => 'igny8-inarticle-image',
'data-image-id' => esc_attr($label),
'data-device' => esc_attr($image_data['device']),
'alt' => esc_attr($image_data['label'])
]);
}
}
$output .= '</div>';
return $output;
});
/**
* Display desktop images only
*
* Usage: [igny8-desktop-images]
*
* @param array $atts Shortcode attributes
* @return string HTML output
*/
add_shortcode('igny8-desktop-images', function($atts) {
$atts = shortcode_atts([
'size' => 'large',
'class' => 'igny8-desktop-gallery'
], $atts);
return do_shortcode('[igny8-images device="desktop" size="' . $atts['size'] . '" class="' . $atts['class'] . '"]');
});
/**
* Display mobile images only
*
* Usage: [igny8-mobile-images]
*
* @param array $atts Shortcode attributes
* @return string HTML output
*/
add_shortcode('igny8-mobile-images', function($atts) {
$atts = shortcode_atts([
'size' => 'large',
'class' => 'igny8-mobile-gallery'
], $atts);
return do_shortcode('[igny8-images device="mobile" size="' . $atts['size'] . '" class="' . $atts['class'] . '"]');
});
/**
* Display image count
*
* Usage: [igny8-image-count]
*
* @param array $atts Shortcode attributes
* @return string HTML output
*/
add_shortcode('igny8-image-count', function($atts) {
$atts = shortcode_atts(['device' => ''], $atts);
$post_id = get_the_ID();
if (empty($post_id)) {
return '0';
}
$images = get_post_meta($post_id, '_igny8_inarticle_images', true);
if (!is_array($images)) {
return '0';
}
if (!empty($atts['device'])) {
$count = 0;
foreach ($images as $image_data) {
if ($image_data['device'] === $atts['device']) {
$count++;
}
}
return (string) $count;
}
return (string) count($images);
});
/**
* Display image gallery with responsive design
*
* Usage: [igny8-responsive-gallery]
*
* @param array $atts Shortcode attributes
* @return string HTML output
*/
add_shortcode('igny8-responsive-gallery', function($atts) {
$atts = shortcode_atts([
'desktop_size' => 'large',
'mobile_size' => 'medium',
'class' => 'igny8-responsive-gallery'
], $atts);
$post_id = get_the_ID();
if (empty($post_id)) {
return '';
}
$images = get_post_meta($post_id, '_igny8_inarticle_images', true);
if (!is_array($images) || empty($images)) {
return '';
}
$output = '<div class="' . esc_attr($atts['class']) . '">';
// Desktop images
$desktop_images = array_filter($images, function($img) {
return $img['device'] === 'desktop';
});
if (!empty($desktop_images)) {
$output .= '<div class="igny8-desktop-images" style="display: block;">';
foreach ($desktop_images as $label => $image_data) {
$attachment_id = intval($image_data['attachment_id']);
if ($attachment_id > 0) {
$output .= wp_get_attachment_image($attachment_id, $atts['desktop_size'], false, [
'class' => 'igny8-desktop-image',
'data-image-id' => esc_attr($label)
]);
}
}
$output .= '</div>';
}
// Mobile images
$mobile_images = array_filter($images, function($img) {
return $img['device'] === 'mobile';
});
if (!empty($mobile_images)) {
$output .= '<div class="igny8-mobile-images" style="display: none;">';
foreach ($mobile_images as $label => $image_data) {
$attachment_id = intval($image_data['attachment_id']);
if ($attachment_id > 0) {
$output .= wp_get_attachment_image($attachment_id, $atts['mobile_size'], false, [
'class' => 'igny8-mobile-image',
'data-image-id' => esc_attr($label)
]);
}
}
$output .= '</div>';
}
$output .= '</div>';
// Add responsive CSS
$output .= '<style>
@media (max-width: 768px) {
.igny8-desktop-images { display: none !important; }
.igny8-mobile-images { display: block !important; }
}
@media (min-width: 769px) {
.igny8-desktop-images { display: block !important; }
.igny8-mobile-images { display: none !important; }
}
</style>';
return $output;
});