Plugin Directory

Changeset 3268778


Ignore:
Timestamp:
04/08/2025 12:27:36 PM (12 months ago)
Author:
topirank
Message:

Init version 1.1.4

Location:
topirank-integration
Files:
32 added
10 edited

Legend:

Unmodified
Added
Removed
  • topirank-integration/trunk/assets/css/topirank-normalize.css

    r3266247 r3268778  
    1212  width: 100%;
    1313  left: 0;
    14   z-index: 9;
    1514}
    1615
    17 .contact-item a{
    18     color:unset;
     16.contact-item a {
     17  color: unset;
    1918}
    2019
  • topirank-integration/trunk/assets/js/topirank-normalize.js

    r3220350 r3268778  
    1616        resizeObserver.observe(nextElement);
    1717    }
     18
    1819});
     20
     21document.addEventListener("DOMContentLoaded", function () {
     22    const progressBar = document.querySelector(".first-progress-bar-default");
     23    const body = document.body;
     24
     25    if (progressBar && body) {
     26        body.insertBefore(progressBar, body.firstChild);
     27    }
     28});
     29
     30
     31window.addEventListener("load", () => {
     32    const content = document.querySelector(".optimized-topirank-template");
     33    if (!content) return;
     34
     35    const headerRoot = document.querySelector("header") || document.querySelector('[data-elementor-type="header"]');
     36    if (!headerRoot) return;
     37
     38    const allHeaderElements = [headerRoot, ...headerRoot.querySelectorAll("*")];
     39    const fixedEl = allHeaderElements.find(el => getComputedStyle(el).position === "fixed");
     40
     41    if (!fixedEl) return;
     42
     43    requestAnimationFrame(() => {
     44        const headerOffsetTop = fixedEl.getBoundingClientRect().top + window.scrollY;
     45        const headerHeight = fixedEl.offsetHeight;
     46        const progressBar = document.querySelector(".first-progress-bar-default");
     47        const progressBarHeight = progressBar ? progressBar.offsetHeight : 0;
     48
     49        const totalOffset = headerOffsetTop + headerHeight - progressBarHeight;
     50
     51        const contentTop = content.getBoundingClientRect().top + window.scrollY;
     52
     53        if (contentTop < totalOffset + 10) {
     54            content.style.paddingTop = `${totalOffset}px`;
     55        }
     56    });
     57});
     58
     59
     60
     61
  • topirank-integration/trunk/includes/api-integration.php

    r3266247 r3268778  
    105105    $replace = isset($request['replace']) && $request['replace'] === 'true';
    106106    $selected_style = isset($request['style']) ? sanitize_text_field($request['style']) : 'not set';
     107    $selected_type = isset($request['type']) ? sanitize_key($request['type']) : 'page';
    107108
    108109    if (!$file || $file['error'] !== UPLOAD_ERR_OK) {
  • topirank-integration/trunk/includes/extract-and-create.php

    r3266247 r3268778  
    6464        topirank_search_files($extracted_path, 'js'),
    6565        $js_destination,
    66         $selected_style,
    67         function ($file_name) {
    68             $sanitized = strtolower(str_replace([' ', '_'], '-', $file_name));
    69             return preg_replace('/-+/', '-', $sanitized);
    70         }
     66        $selected_style
    7167    );
    7268
     
    183179    $wp_filesystem = topirank_get_filesystem();
    184180
     181    $page_js_dir = $destination . '/page-js';
     182    if (strpos($destination, '/js/') !== false && !$wp_filesystem->is_dir($page_js_dir)) {
     183        $wp_filesystem->mkdir($page_js_dir, FS_CHMOD_DIR);
     184    }
     185
    185186    foreach ($files as $file) {
    186187        $file_name = basename($file);
     
    188189            $file_name = $name_transform($file_name);
    189190        }
    190         $target = trailingslashit($destination) . $file_name;
     191
     192        if (
     193            pathinfo($file, PATHINFO_EXTENSION) === 'js' &&
     194            strpos($file, '/js/') !== false
     195        ) {
     196            $target = trailingslashit($page_js_dir) . $file_name;
     197        } else {
     198            $target = trailingslashit($destination) . $file_name;
     199        }
    191200
    192201        if ($selected_style === 'wp' && pathinfo($file, PATHINFO_EXTENSION) === 'js') {
  • topirank-integration/trunk/includes/file-upload.php

    r3234611 r3268778  
    66{
    77?>
    8     <div class="topirank_container">
    9         <div class="topirank_wrap">
    10             <div class="topirank_main_content_line">
    11                 <button onclick="window.location.href='<?php echo esc_url(admin_url('admin.php?page=topirank_plugin')); ?>'" class="topirank_solid_button">
    12                     <?php esc_html_e('Go Back to Main Page', 'topirank-integration'); ?>
    13                 </button>
    14             </div>
    15             <?php
    16             topirank_handle_file_upload();
    17             ?>
    18         </div>
     8  <div class="topirank_container">
     9    <div class="topirank_wrap">
     10      <div class="topirank_main_content_line">
     11        <button onclick="window.location.href='<?php echo esc_url(admin_url('admin.php?page=topirank_plugin')); ?>'" class="topirank_solid_button">
     12          <?php esc_html_e('Go Back to Main Page', 'topirank-integration'); ?>
     13        </button>
     14      </div>
     15      <?php
     16      topirank_handle_file_upload();
     17      ?>
    1918    </div>
     19  </div>
    2020
    2121<?php
     
    2424function topirank_handle_file_upload()
    2525{
    26     if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
    27         if (!isset($_FILES['html_archive']) || empty($_FILES['html_archive']['tmp_name'])) {
    28             echo '<div class="topirank_main_content_line without_space_between">
     26  if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
     27    if (!isset($_FILES['html_archive']) || empty($_FILES['html_archive']['tmp_name'])) {
     28      echo '<div class="topirank_main_content_line without_space_between">
    2929        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    3030<path d="M12 22C17.523 22 22 17.523 22 12C22 6.477 17.523 2 12 2C6.477 2 2 6.477 2 12C2 17.523 6.477 22 12 22Z" stroke="#CF2323" stroke-width="1.5" stroke-linejoin="round"/>
     
    3232</svg>
    3333<div class="topirank_line_title">';
    34             esc_html_e('Invalid file upload.', 'topirank-integration');
    35             echo '</div>
     34      esc_html_e('Invalid file upload.', 'topirank-integration');
     35      echo '</div>
    3636</div>';
    37             return;
     37      return;
     38    }
     39
     40    $file = isset($_FILES['html_archive']) && is_array($_FILES['html_archive'])
     41      ? array_map('sanitize_text_field', $_FILES['html_archive'])
     42      : null;
     43
     44    if (is_array($file) && isset($file['name'], $file['tmp_name'])) {
     45      $upload_dir   = wp_upload_dir();
     46      $topirank_dir = $upload_dir['basedir'] . '/topirank-import-files';
     47      topirank_recursive_delete($topirank_dir);
     48
     49      $selected_style = isset($_POST['style']) ? sanitize_text_field(wp_unslash($_POST['style'])) : '';
     50      $selected_type = isset($_POST['type']) ? sanitize_text_field(wp_unslash($_POST['type'])) : 'page';
     51      $replace = '';
     52
     53      $file_extension = pathinfo($file['name'], PATHINFO_EXTENSION);
     54
     55      if (strtolower($file_extension) !== 'zip') {
     56        echo '<div class="error notice"><p>';
     57        esc_html_e('Please upload a ZIP archive.', 'topirank-integration');
     58        echo '</p></div>';
     59        return;
     60      }
     61
     62      if (!file_exists($topirank_dir)) {
     63        wp_mkdir_p($topirank_dir);
     64      }
     65
     66      $uploaded_file = wp_handle_upload($file, array('test_form' => false));
     67
     68      if (isset($uploaded_file['file']) && ! isset($uploaded_file['error'])) {
     69        $original_path = $uploaded_file['file'];
     70        $zip_path      = $topirank_dir . '/' . basename($original_path);
     71
     72        $wp_filesystem = topirank_get_filesystem();
     73
     74        if ($wp_filesystem->move($original_path, $zip_path, true)) {
     75          $extracted_path = $topirank_dir . '/' . basename($file['name'], '.zip');
     76          topirank_extract_and_create_posts($zip_path, $extracted_path, $replace, $selected_style, $selected_type);
     77
     78          if ($wp_filesystem->exists($zip_path)) {
     79            $wp_filesystem->delete($zip_path);
     80          }
     81        } else {
     82          echo '<div class="topirank_main_content_line">';
     83          echo '<div class="topirank_line_title">';
     84          esc_html_e('Could not move the uploaded file.', 'topirank-integration');
     85          echo '</div>';
     86          echo '</div>';
    3887        }
    39 
    40         $file = isset($_FILES['html_archive']) && is_array($_FILES['html_archive'])
    41             ? array_map('sanitize_text_field', $_FILES['html_archive'])
    42             : null;
    43 
    44         if (is_array($file) && isset($file['name'], $file['tmp_name'])) {
    45             $upload_dir   = wp_upload_dir();
    46             $topirank_dir = $upload_dir['basedir'] . '/topirank-import-files';
    47             topirank_recursive_delete($topirank_dir);
    48 
    49             $selected_style = isset($_POST['style']) ? sanitize_text_field(wp_unslash($_POST['style'])) : '';
    50             $replace = '';
    51 
    52             $file_extension = pathinfo($file['name'], PATHINFO_EXTENSION);
    53 
    54             if (strtolower($file_extension) !== 'zip') {
    55                 echo '<div class="error notice"><p>';
    56                 esc_html_e('Please upload a ZIP archive.', 'topirank-integration');
    57                 echo '</p></div>';
    58                 return;
    59             }
    60 
    61             if (!file_exists($topirank_dir)) {
    62                 wp_mkdir_p($topirank_dir);
    63             }
    64 
    65             $uploaded_file = wp_handle_upload($file, array('test_form' => false));
    66 
    67             if (isset($uploaded_file['file']) && ! isset($uploaded_file['error'])) {
    68                 $original_path = $uploaded_file['file'];
    69                 $zip_path      = $topirank_dir . '/' . basename($original_path);
    70 
    71                 $wp_filesystem = topirank_get_filesystem();
    72 
    73                 if ($wp_filesystem->move($original_path, $zip_path, true)) {
    74                     $extracted_path = $topirank_dir . '/' . basename($file['name'], '.zip');
    75                     topirank_extract_and_create_posts($zip_path, $extracted_path, $replace, $selected_style);
    76 
    77                     if ($wp_filesystem->exists($zip_path)) {
    78                         $wp_filesystem->delete($zip_path);
    79                     }
    80                 } else {
    81                     echo '<div class="topirank_main_content_line">';
    82                     echo '<div class="topirank_line_title">';
    83                     esc_html_e('Could not move the uploaded file.', 'topirank-integration');
    84                     echo '</div>';
    85                     echo '</div>';
    86                 }
    87             } else {
    88                 echo '<div class="topirank_main_content_line">';
    89                 echo '<div class="topirank_line_title">';
    90                 if (isset($uploaded_file['error'])) {
    91                     echo esc_html($uploaded_file['error']);
    92                 } else {
    93                     esc_html_e('Upload failed. Please try again.', 'topirank-integration');
    94                 }
    95                 echo '</div>';
    96                 echo '</div>';
    97             }
     88      } else {
     89        echo '<div class="topirank_main_content_line">';
     90        echo '<div class="topirank_line_title">';
     91        if (isset($uploaded_file['error'])) {
     92          echo esc_html($uploaded_file['error']);
    9893        } else {
    99             esc_html_e('Invalid file upload.', 'topirank-integration');
     94          esc_html_e('Upload failed. Please try again.', 'topirank-integration');
    10095        }
     96        echo '</div>';
     97        echo '</div>';
     98      }
     99    } else {
     100      esc_html_e('Invalid file upload.', 'topirank-integration');
    101101    }
     102  }
    102103}
  • topirank-integration/trunk/includes/register-files.php

    r3255204 r3268778  
    11<?php
    22if (! defined('ABSPATH')) exit;
     3
     4function is_valid_post()
     5{
     6    global $post;
     7    return is_object($post);
     8}
    39
    410function topirank_enqueue_admin_assets($hook_suffix)
     
    5157
    5258add_action('template_redirect', function () {
     59    if (!is_valid_post()) {
     60        return;
     61    }
    5362
    5463    global $post;
     
    7685function topirank_enqueue_archive_files()
    7786{
     87    if (!is_valid_post()) {
     88        return;
     89    }
     90
    7891    global $post;
    7992
     
    117130    if (is_dir($js_path)) {
    118131        $js_files = glob($js_path . '/*.js');
    119         $current_slug = sanitize_title($post->post_name);
    120         $clean_archive_name = preg_replace('/--\d+$/', '', $archive_name);
    121 
    122132        foreach ($js_files as $js_file) {
    123 
    124             $file_name = basename($js_file, '.js');
    125             $file_name = preg_replace('/-script$/', '', $file_name);
    126 
    127             if (strpos($file_name, '-page-') === false) {
    128                 wp_enqueue_script(
    129                     'topirank-archive-js-' . sanitize_title($file_name),
    130                     $js_url . '/' . basename($js_file),
    131                     [],
    132                     time(),
    133                     true
    134                 );
    135                 continue;
    136             }
    137 
    138             $file_name = preg_replace('/^' . preg_quote($clean_archive_name, '/') . '/', '', $file_name);
    139             $file_name = preg_replace('/^-page-/', '', $file_name);
    140 
    141 
    142             if (strpos($file_name, $current_slug) === false) {
    143                 continue;
    144             }
    145 
    146133            wp_enqueue_script(
    147                 'topirank-archive-js-' . sanitize_title($file_name),
     134                'topirank-archive-js-' . sanitize_title(basename($js_file, '.js')),
    148135                $js_url . '/' . basename($js_file),
    149136                [],
     
    152139            );
    153140        }
    154     }
    155 }
    156 
     141
     142        $page_js_path = $js_path . '/page-js';
     143        if (is_dir($page_js_path)) {
     144            $page_js_files = glob($page_js_path . '/*.js');
     145            $data_id_title = get_post_meta($post->ID, 'data_id_title', true);
     146
     147            foreach ($page_js_files as $js_file) {
     148                $file_name = basename($js_file, '.js');
     149
     150                if ($file_name === $data_id_title) {
     151                    wp_enqueue_script(
     152                        'topirank-archive-page-js-' . sanitize_title($file_name),
     153                        $js_url . '/page-js/' . basename($js_file),
     154                        [],
     155                        time(),
     156                        true
     157                    );
     158                }
     159            }
     160        }
     161    }
     162}
    157163
    158164
    159165function topirank_admin_styles_for_special_template($hook)
    160166{
     167    if (!is_valid_post()) {
     168        return;
     169    }
     170
    161171    global $post;
    162172
  • topirank-integration/trunk/includes/topirank-template.php

    r3220350 r3268778  
    44/* Template Name: Topirank Post Template */
    55/* Template Post Type: post */
     6if (is_user_logged_in()) {
     7    show_admin_bar(false);
     8    add_action('get_header', function () {
     9        remove_action('wp_head', '_admin_bar_bump_cb');
     10    });
     11}
    612get_header();
    713$choose_styles = get_post_meta($post->ID, 'choose_styles', true);
  • topirank-integration/trunk/includes/update-content-and-seo.php

    r3249873 r3268778  
    1818  if (preg_match('/<title>(.*?)<\/title>/is', $content, $title_match)) {
    1919    $title = wp_strip_all_tags($title_match[1]);
    20     update_post_meta($post_id, '_yoast_wpseo_title', $title);
    2120  } else {
    2221    $title = '';
     
    2524  if (preg_match('/<meta\s+name=["\']description["\']\s+content=["\'](.*?)["\']/is', $content, $description_match)) {
    2625    $description = wp_strip_all_tags($description_match[1]);
    27     update_post_meta($post_id, '_yoast_wpseo_metadesc', $description);
    2826  } else {
    2927    $description = '';
     
    4038
    4139  $xpath = new DOMXPath($dom);
     40
     41  $elements_with_data_id = $xpath->query('//*[@data-id-title]');
     42  if ($elements_with_data_id->length > 0) {
     43    $element = $elements_with_data_id->item(0);
     44    if ($element instanceof DOMElement) {
     45      $data_id_title = $element->getAttribute('data-id-title');
     46      update_post_meta($post_id, 'data_id_title', $data_id_title);
     47    }
     48  }
    4249
    4350  $fonts_script = $dom->getElementById('fonts-with-script-integrate');
     
    152159    $image_srcs = $image_matches[1];
    153160    $upload_dir = wp_upload_dir();
     161    $special_attachment_id = null;
     162
     163    $matched_src = null;
     164    if (preg_match('/<img[^>]*data-image-position=["\']main["\'][^>]*src=["\']([^"\']+)["\']/i', $content, $special_img_match)) {
     165      $matched_src = $special_img_match[1];
     166    }
    154167
    155168    foreach ($image_srcs as $image_src) {
     
    181194      $new_url = wp_get_attachment_url($attachment_id);
    182195      $content = str_replace($image_src, $new_url, $content);
    183     }
    184   }
     196
     197      if ($image_src === $matched_src) {
     198        $special_attachment_id = $attachment_id;
     199      }
     200    }
     201
     202    if ($special_attachment_id) {
     203      set_post_thumbnail($post_id, $special_attachment_id);
     204      $img_url = wp_get_attachment_url($special_attachment_id);
     205
     206      if (class_exists('WPSEO_Meta')) {
     207        WPSEO_Meta::set_value('opengraph-image', $img_url, $post_id);
     208        WPSEO_Meta::set_value('twitter-image', $img_url, $post_id);
     209      }
     210    }
     211  }
     212
    185213
    186214  wp_update_post([
     
    190218  ]);
    191219
    192   $post_title = get_the_title($post_id);
    193   $post_title_slug = sanitize_title($post_title);
    194 
    195   $thumbnail_query = new WP_Query([
    196     'title'  => $post_title_slug,
    197     'post_type' => 'attachment',
    198     'post_status' => 'inherit',
    199     'fields' => 'ids',
    200     'posts_per_page' => 1,
    201   ]);
    202   $thumbnail_id = !empty($thumbnail_query->posts) ? $thumbnail_query->posts[0] : null;
    203220  wp_reset_postdata();
    204221
    205222  if (class_exists('WPSEO_Meta')) {
    206     if ($thumbnail_id) {
    207       set_post_thumbnail($post_id, $thumbnail_id);
    208       $thumbnail_url = wp_get_attachment_url($thumbnail_id);
    209       WPSEO_Meta::set_value('opengraph-image', $thumbnail_url, $post_id);
    210     }
    211223
    212224    if ($title) {
    213225      WPSEO_Meta::set_value('opengraph-title', $title, $post_id);
     226      WPSEO_Meta::set_value('twitter-title', $title, $post_id);
     227      update_post_meta($post_id, '_yoast_wpseo_title', $title);
    214228    }
    215229
    216230    if ($description) {
    217231      WPSEO_Meta::set_value('opengraph-description', $description, $post_id);
     232      WPSEO_Meta::set_value('twitter-description', $description, $post_id);
     233      update_post_meta($post_id, '_yoast_wpseo_metadesc', $description);
    218234    }
    219235  }
  • topirank-integration/trunk/readme.txt

    r3266247 r3268778  
    44Requires at least: 6.0
    55Tested up to: 6.7.2
    6 Stable tag: 1.1.3
     6Stable tag: 1.1.4
    77Requires PHP: 7.3
    88License: GPLv2 or later
     
    5757
    5858== Changelog ==
     59
     60= 1.1.4 =
     61* Fixed an issue with the progress bar display.
     62* Fixed SEO image rendering.
     63* Fixed JS file loading.
     64* Improved support for two page types.
     65* Improved rendering of new widgets on pages.
    5966
    6067= 1.1.3 =
  • topirank-integration/trunk/topirank-integration.php

    r3266247 r3268778  
    33Plugin Name: Topirank Integration
    44Description: Plugin for parsing pages
    5 Version: 1.1.3
     5Version: 1.1.4
    66Author: Topirank
    77License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.