diff --git a/assets/img/demo-post-thumbnails/demo-post-thumbnail-1.jpg b/assets/img/demo-post-thumbnails/demo-post-thumbnail-1.jpg new file mode 100644 index 0000000..f1d6d9e Binary files /dev/null and b/assets/img/demo-post-thumbnails/demo-post-thumbnail-1.jpg differ diff --git a/assets/img/demo-post-thumbnails/demo-post-thumbnail-2.jpg b/assets/img/demo-post-thumbnails/demo-post-thumbnail-2.jpg new file mode 100644 index 0000000..30132f4 Binary files /dev/null and b/assets/img/demo-post-thumbnails/demo-post-thumbnail-2.jpg differ diff --git a/assets/img/demo-post-thumbnails/demo-post-thumbnail-3.jpg b/assets/img/demo-post-thumbnails/demo-post-thumbnail-3.jpg new file mode 100644 index 0000000..44ce517 Binary files /dev/null and b/assets/img/demo-post-thumbnails/demo-post-thumbnail-3.jpg differ diff --git a/assets/js/demo-posts-import.js b/assets/js/demo-posts-import.js new file mode 100644 index 0000000..859f1dd --- /dev/null +++ b/assets/js/demo-posts-import.js @@ -0,0 +1,33 @@ +document.addEventListener('DOMContentLoaded', function () { + // Check if the button exists before adding the event listener + const importButton = document.getElementById('import-demo-posts'); + if (importButton) { + importButton.addEventListener('click', function () { + const formData = new FormData(); + + // Append action and nonce to the form data + formData.append('action', 'lcp_import_demo_posts'); + formData.append('lcp_import_nonce', lcp_ajax_obj.nonce); // Add the nonce passed by wp_localize_script + + // Send the AJAX request + fetch(lcp_ajax_obj.ajax_url, { + method: 'POST', + body: formData + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + alert(data.data); // Success message + } else { + alert('Error: ' + (data.data || 'Unknown error')); // Error message + } + }) + .catch(error => { + console.error('Error:', error); + alert('An error occurred while processing your request.'); + }); + }); + } else { + console.warn('Import button not found.'); + } +}); diff --git a/assets/json/alphabetize.php b/assets/json/alphabetize.php deleted file mode 100644 index 52a999a..0000000 --- a/assets/json/alphabetize.php +++ /dev/null @@ -1,57 +0,0 @@ - diff --git a/assets/json/converter.php b/assets/json/converter.php deleted file mode 100644 index 5410ff2..0000000 --- a/assets/json/converter.php +++ /dev/null @@ -1,61 +0,0 @@ - elements and extract them - preg_match_all('/]*>[\s\S]*?<\/symbol>/', $svgContent, $matches); - - $jsonData = []; - - foreach ($matches[0] as $symbol) { - // Extract 'id', 'viewBox', and 'path' attributes - preg_match('/id="([^"]+)"/', $symbol, $idMatches); - preg_match('/viewBox="([^"]+)"/', $symbol, $viewBoxMatches); - preg_match('/]*d="([^"]+)"/', $symbol, $pathMatches); - - // If we have a valid symbol, process it - if (isset($idMatches[1]) && isset($viewBoxMatches[1]) && isset($pathMatches[1])) { - // Generate a UUID for the symbol - $uniqueId = generateUUID(); - - // Capitalize the name by replacing hyphens with spaces and capitalizing each word - $name = ucwords(str_replace('-', ' ', $idMatches[1])); - - // Build the symbol JSON object - $symbolJSON = [ - "id" => $uniqueId, - "name" => $name, - "viewBox" => $viewBoxMatches[1], - "path" => "" - ]; - - // Add the symbol JSON to the data array - $jsonData[] = $symbolJSON; - } - } - - return $jsonData; -} - -// Read the SVG file (assumes it's in the same directory) -$svgFilePath = 'input.svg'; // The input SVG file -if (file_exists($svgFilePath)) { - $svgContent = file_get_contents($svgFilePath); - - // Convert symbols to JSON - $symbolsJson = convertSymbolsToJSON($svgContent); - - // Output the JSON data to a file - $outputFilePath = 'output.json'; - file_put_contents($outputFilePath, json_encode($symbolsJson, JSON_PRETTY_PRINT)); - - echo "JSON file has been created successfully: $outputFilePath\n"; -} else { - echo "Error: SVG file not found.\n"; -} -?> diff --git a/assets/json/demo-posts.json b/assets/json/demo-posts.json new file mode 100644 index 0000000..8958d22 --- /dev/null +++ b/assets/json/demo-posts.json @@ -0,0 +1,57 @@ +{ + "posts": [ + { + "title": "Mysterious Weather Patterns Reported in Faketown", + "content": "Faketown, USA — In what can only be described as a strange turn of events, Faketown residents have been experiencing unpredictable weather patterns. Local meteorologists have been baffled as sudden temperature shifts have been occurring at all hours of the day. One moment, the sun is shining brightly, and the next, it's snowing. This bizarre occurrence is leaving many questioning whether this is a sign of something more ominous. 'I’ve lived here my entire life, and I’ve never seen anything like this,' said local resident Jane Doe.", + "excerpt": "Faketown residents have been experiencing unpredictable weather patterns, baffling local meteorologists.", + "category": "Local News", + "tags": ["weather", "Faketown", "mystery"], + "date": "2025-01-01", + "status": "publish", + "thumbnail": "demo-post-thumbnail-1.jpg" + }, + { + "title": "Faketown Mayor Announces New Green Initiative", + "content": "In a recent press conference, Faketown’s mayor, John Smith, unveiled an ambitious plan to tackle climate change within the city. The initiative aims to reduce carbon emissions by 40% over the next 10 years, primarily by encouraging the use of electric vehicles and expanding the city's public transportation system. 'We are committed to making Faketown a greener place,' said Mayor Smith. 'Our children and grandchildren deserve a sustainable future.' The plan includes installing charging stations for electric cars across the city and offering tax incentives for green energy solutions.", + "excerpt": "Faketown’s mayor unveils a new green initiative to reduce carbon emissions by 40%.", + "category": "Politics", + "tags": ["green", "climate change", "Faketown"], + "date": "2025-01-02", + "status": "publish", + "thumbnail": "demo-post-thumbnail-2.jpg" + }, + { + "title": "Local Chef Opens Revolutionary Restaurant in Faketown", + "content": "Faketown, USA — In a culinary first for Faketown, renowned chef Sarah Bellamy has opened a new restaurant that combines traditional American cuisine with exotic flavors from around the world. Located in the heart of Faketown, Bellamy’s restaurant has already become the talk of the town. The menu features a variety of dishes, including 'Fusion Fries' and 'Sushi Burger.' 'I wanted to create something completely unique, a blend of cultures,' said Bellamy. The restaurant offers both dine-in and delivery services, with plans to expand its menu soon.", + "excerpt": "Faketown's new restaurant is offering a fusion of global flavors with a local twist.", + "category": "Food & Drink", + "tags": ["restaurant", "food", "Faketown"], + "date": "2025-01-03", + "status": "publish", + "thumbnail": "demo-post-thumbnail-3.jpg" + }, + { + "title": "Strange Creatures Spotted in Faketown's Forests", + "content": "In the deep forests surrounding Faketown, local hikers have begun reporting sightings of strange creatures. Descriptions vary, but many claim to have seen large, mysterious beings with glowing eyes. Some hikers have even reported hearing unusual sounds that have no obvious explanation. 'I was out for a hike last week when I saw something huge moving through the trees,' said Greg Johnson, a local resident. 'I don’t know what it was, but it wasn’t a bear.' Authorities are urging hikers to stay on well-trodden paths and report any strange occurrences.", + "excerpt": "Faketown residents report strange creatures spotted in nearby forests, baffling experts.", + "category": "Strange Happenings", + "tags": ["mystery", "Faketown", "creatures"], + "date": "2025-01-04", + "status": "publish", + "thumbnail": "demo-post-thumbnail-1.jpg" + + }, + { + "title": "Faketown's Annual Festival Breaks Attendance Records", + "content": "This year's annual Faketown Festival was a resounding success, breaking all previous attendance records. Held in the town square, the festival featured local bands, food trucks, and street performances. The highlight of the event was the traditional 'Faketown Parade,' which saw thousands of people lining the streets. 'We’ve never seen this many people come out,' said event coordinator Lisa Thompson. The festival’s success has sparked excitement about next year’s event, with many suggesting that Faketown could become a regional hub for arts and culture.", + "excerpt": "Faketown’s annual festival saw record-breaking attendance, with thousands of people participating.", + "category": "Community Events", + "tags": ["festival", "community", "Faketown"], + "date": "2025-01-05", + "status": "publish", + "thumbnail": "demo-post-thumbnail-2.jpg" + + } + ] + } + \ No newline at end of file diff --git a/assets/json/fixpaths.php b/assets/json/fixpaths.php deleted file mode 100644 index 85222b0..0000000 --- a/assets/json/fixpaths.php +++ /dev/null @@ -1,57 +0,0 @@ - $iconSet) { - if (isset($iconSet['svgs']) && is_array($iconSet['svgs'])) { - foreach ($iconSet['svgs'] as $svgIndex => $svg) { - // Check if 'path' exists - if (isset($svg['path'])) { - // Extract the 'd' attribute value from the nested path string - preg_match('/d=[\'"]([^\'"]+)[\'"]/i', $svg['path'], $matches); - - // If we found the 'd' value, format the paths correctly - if (isset($matches[1])) { - $dValue = $matches[1]; // Get the actual 'd' value from the path - - // Escape the 'd' value for JSON format (escape double quotes inside the string) - $escapedDValue = str_replace('"', '\\"', $dValue); - - // Now, add the proper tag to the 'paths' field - $svg['paths'] = ""; - } - - unset($svg['path']); // Optionally remove the original 'path' key - } - // Save the modified svg back to the array - $data[$index]['svgs'][$svgIndex] = $svg; - } - } -} - -// Optional: Save the modified JSON to a new file -$outputFile = 'solid-fixed-paths.json'; -file_put_contents($outputFile, json_encode($data, JSON_PRETTY_PRINT)); - -// Output the success message -echo "Successfully modified and saved the JSON file with 'path' converted to 'paths'.\n"; - -?> diff --git a/assets/json/icons/fix.php b/assets/json/icons/fix.php deleted file mode 100644 index e58ecc8..0000000 --- a/assets/json/icons/fix.php +++ /dev/null @@ -1,63 +0,0 @@ - diff --git a/assets/json/icons/material-icons/v1.0.32/caps.php b/assets/json/icons/material-icons/v1.0.32/caps.php deleted file mode 100644 index 67eafd8..0000000 --- a/assets/json/icons/material-icons/v1.0.32/caps.php +++ /dev/null @@ -1,86 +0,0 @@ - diff --git a/functions.php b/functions.php index 11017f2..35dab69 100644 --- a/functions.php +++ b/functions.php @@ -4,7 +4,7 @@ include get_template_directory() . '/includes/classes/wp-hooks.php'; -include get_template_directory() . '/includes/classes/lcp-newsletters.php'; + //include get_template_directory(). '/includes/blocks/lcp-gallery/lcp-gallery.php'; include get_template_directory() . '/includes/classes/blocks.php'; @@ -49,10 +49,19 @@ function lcp_backend_enqueue() { // Enqueue the theme's main stylesheet (style.css) wp_enqueue_style('lcp-style', get_stylesheet_uri()); wp_enqueue_script('lcp-script', get_template_directory_uri() . '/script.js'); + wp_enqueue_script('lcp-ui', get_template_directory_uri() . '/assets/js/lcp-ui.js'); + // Enqueue custom script to handle the Demo post import AJAX request + wp_enqueue_script('lcp-import-demo-posts-ajax', get_template_directory_uri() . '/assets/js/demo-posts-import.js', array(), null, true); + + // Add the AJAX URL and nonce as JavaScript variables + wp_localize_script('lcp-import-demo-posts-ajax', 'lcp_ajax_obj', array( + 'ajax_url' => admin_url('admin-ajax.php'), // This is the URL that we’ll send the AJAX request to + 'nonce' => wp_create_nonce('lcp_import_demo_posts_nonce') // Security nonce for validation + )); } -add_action('admin_enqueue_scripts', 'lcp_enqueue'); +add_action('admin_enqueue_scripts', 'lcp_backend_enqueue'); /* KEY POINTS */ @@ -180,26 +189,26 @@ function drop_lcp_icons_table() { /* BACKEND ICON ADDER */ // Register the dashboard page in the admin menu -function mytheme_register_dashboard_page() { +function lcp_register_dashboard_page() { add_menu_page( 'Icon Management', // Page Title 'Icon Management', // Menu Title 'manage_options', // Capability 'icon-management', // Menu Slug - 'mytheme_dashboard_page', // Callback function + 'lcp_dashboard_page', // Callback function 'dashicons-images-alt2', // Icon for the menu item 60 // Position ); } -add_action('admin_menu', 'mytheme_register_dashboard_page'); +add_action('admin_menu', 'lcp_register_dashboard_page'); // Callback function to display the dashboard page content -function mytheme_dashboard_page() { +function lcp_dashboard_page() { ?>
-

+

- +
prefix . 'lcp_icons'; @@ -409,7 +418,7 @@ function mytheme_create_icons_table() { } -function mytheme_enqueue_dashboard_scripts($hook) { +function lcp_enqueue_dashboard_scripts($hook) { // Only load the script on the icon-management page @@ -423,15 +432,15 @@ function mytheme_enqueue_dashboard_scripts($hook) { ); // Pass the AJAX URL to the script - wp_localize_script('icon-import-script', 'mytheme_ajax', array( + wp_localize_script('icon-import-script', 'lcp_ajax', array( 'ajax_url' => admin_url('admin-ajax.php') )); } -add_action('admin_enqueue_scripts', 'mytheme_enqueue_dashboard_scripts'); +add_action('admin_enqueue_scripts', 'lcp_enqueue_dashboard_scripts'); // Handle the AJAX request for uninstalling icon sets -function mytheme_uninstall_icon_set() { +function lcp_uninstall_icon_set() { // Ensure icon set ID is passed in the request if (!isset($_POST['icon_set_id'])) { wp_send_json_error(array('message' => 'Invalid icon set ID.')); @@ -460,6 +469,151 @@ function mytheme_uninstall_icon_set() { } } -add_action('wp_ajax_uninstall_icon_set', 'mytheme_uninstall_icon_set'); +add_action('wp_ajax_uninstall_icon_set', 'lcp_uninstall_icon_set'); + +/* Import Demo Posts */ +function lcp_import_demo_posts() { + $json_data = file_get_contents(get_template_directory() . '/assets/json/demo-posts.json'); + + // Check if the JSON data is successfully fetched and decoded + if (empty($json_data)) { + return; + } + + $posts = json_decode($json_data, true)['posts']; + + if (empty($posts)) { + return; + } + + // Arrays to store post IDs and media (thumbnail) IDs + $post_ids = []; + $media_ids = []; + + foreach ($posts as $post) { + // Prepare post data + $post_data = array( + 'post_title' => wp_strip_all_tags($post['title']), + 'post_content' => $post['content'], + 'post_excerpt' => isset($post['excerpt']) ? $post['excerpt'] : '', + 'post_status' => isset($post['status']) ? $post['status'] : 'draft', // Default to 'draft' if no status + 'post_date' => isset($post['date']) ? $post['date'] : current_time('mysql'), + 'post_type' => 'post', + 'post_author' => 1, // Change if you have specific user IDs + ); + + // Insert the post into the database + $post_id = wp_insert_post($post_data); + + // If there was an issue inserting the post, skip this one + if (is_wp_error($post_id)) { + continue; + } + + // Store the post ID in the array + $post_ids[] = $post_id; + + // Assign categories (if they exist) + if (!empty($post['category'])) { + $category = term_exists($post['category'], 'category'); + if ($category) { + wp_set_post_terms($post_id, array($category['term_id']), 'category'); + } else { + // If category doesn't exist, create it + $category_id = wp_create_term($post['category'], 'category'); + wp_set_post_terms($post_id, array($category_id['term_id']), 'category'); + } + } + + // Assign tags (if they exist) + if (!empty($post['tags'])) { + wp_set_post_terms($post_id, $post['tags'], 'post_tag'); + } + + // Handle thumbnail (featured image) + if (!empty($post['thumbnail'])) { + $thumbnail_url = get_template_directory_uri() . '/assets/img/demo-post-thumbnails/' . $post['thumbnail']; + + // Download the image and add it to the media library + $thumbnail_id = media_handle_sideload( + array( + 'name' => basename($thumbnail_url), + 'tmp_name' => download_url($thumbnail_url) + ), + $post_id + ); + + // If the image was uploaded successfully, set it as the post's featured image + if (!is_wp_error($thumbnail_id)) { + set_post_thumbnail($post_id, $thumbnail_id); + // Store the media ID in the array + $media_ids[] = $thumbnail_id; + } + } + + // You can add additional meta fields if necessary + // Example: + // update_post_meta($post_id, 'some_meta_key', 'some_value'); + } + + // After all posts are imported, update the 'lcp_demo_posts' option + $demo_posts_data = array( + 'post_ids' => $post_ids, + 'media_ids' => $media_ids, + ); + update_option('lcp_demo_posts', $demo_posts_data); + + // Optionally, you can log the post and media IDs + // var_dump($post_ids, $media_ids); // Uncomment this line if you need to inspect the result +} +/* Delete the Demo Posts */ + // Get the lcp_demo_posts option and delete all the posts from there +function lcp_delete_demo_posts() { + // Get the lcp_demo_posts option + $demo_posts_data = get_option('lcp_demo_posts'); + + // Check if the option exists and contains data + if (!empty($demo_posts_data) && isset($demo_posts_data['post_ids']) && isset($demo_posts_data['media_ids'])) { + // Loop through and delete posts + foreach ($demo_posts_data['post_ids'] as $post_id) { + // Delete post, force delete if necessary (set true for delete permanently) + wp_delete_post($post_id, true); // true will permanently delete + } + + // Loop through and delete media (attachments) + foreach ($demo_posts_data['media_ids'] as $media_id) { + // Delete attachment (media file) + wp_delete_attachment($media_id, true); // true will permanently delete + } + + // After deletion, remove the option from wp_options table + delete_option('lcp_demo_posts'); + + // Optionally, you can log the deletion for confirmation + // error_log('Demo posts and media have been deleted.'); + } else { + // If the option doesn't exist, or it's empty + error_log('No demo posts data found or already deleted.'); + } +} + + +/* Localize */ +add_action('wp_ajax_lcp_import_demo_posts', 'lcp_import_demo_posts_ajax_handler'); + +// Define the function to handle the AJAX request +function lcp_import_demo_posts_ajax_handler() { + // Check for permissions (optional: can be used to ensure only admins can trigger this) + if (!current_user_can('manage_options')) { + wp_send_json_error('You do not have sufficient permissions to perform this action.'); + } + + // Call the existing function that imports the demo posts + lcp_import_demo_posts(); + + // Send a success response back to the browser + wp_send_json_success('Demo posts imported successfully.'); +} + diff --git a/includes/classes/backend.php b/includes/classes/backend.php index 31409ff..3355425 100644 --- a/includes/classes/backend.php +++ b/includes/classes/backend.php @@ -247,6 +247,7 @@ function render_lcp_theme_settings_page() { + @@ -258,7 +259,7 @@ function render_lcp_theme_settings_page() { @@ -300,6 +301,14 @@ function render_lcp_theme_settings_page() { + +
+ +

Miscellaneous Settings

+ + + +
diff --git a/parts/footer.html b/parts/footer.html new file mode 100644 index 0000000..c2ea07c --- /dev/null +++ b/parts/footer.html @@ -0,0 +1 @@ + diff --git a/parts/header.html b/parts/header.html new file mode 100644 index 0000000..7e3e990 --- /dev/null +++ b/parts/header.html @@ -0,0 +1 @@ + diff --git a/patterns/viewport-with-sidecontent.php b/patterns/viewport-with-sidecontent.php deleted file mode 100644 index 1885f4e..0000000 --- a/patterns/viewport-with-sidecontent.php +++ /dev/null @@ -1,14 +0,0 @@ - - diff --git a/style.css b/style.css index 2461977..dcf13c5 100644 --- a/style.css +++ b/style.css @@ -2,7 +2,7 @@ Theme Name: Local Content Pro Theme URI: https://localcontentpro.com Description: A simple Block Theme for local content publishers. -Version: 1.0 +Version: 0.0.1 */ /* Main viewport container */ diff --git a/theme.zip b/theme.zip new file mode 100644 index 0000000..c61c35e Binary files /dev/null and b/theme.zip differ diff --git a/zip-theme.js b/zip-theme.js index edfb5b1..ef6e73a 100644 --- a/zip-theme.js +++ b/zip-theme.js @@ -14,7 +14,8 @@ const excludedDirs = [ 'package-lock.json', 'theme.zip', '.git', - 'react' + 'react', + 'zip-theme.js' ]; // Helper function to check if a file or directory should be excluded