403Webshell
Server IP : 89.108.64.180  /  Your IP : 216.73.216.61
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux 89-108-64-180.cloudvps.regruhosting.ru 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User : www-root ( 1010)
PHP Version : 8.0.30
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/жемчужина.online/wp-content/plugins/mphb-reviews/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/жемчужина.online/wp-content/plugins/mphb-reviews/includes//importer.php
<?php

namespace MPHBR;

class Importer
{
    /**
     * @var array|null
     * @since 1.2.3
     */
    protected $importedTerms = null;

    public function __construct()
    {
        add_action('import_start', [$this, 'startImport']);

        // OCDI - add term meta "_mphb_import_id"
        add_action('wxr_importer.processed.term', [$this, 'addTermImportId'], 10, 2);
        // WPI - add term meta "_mphb_import_id"
        add_filter('wp_import_term_meta', [$this, 'filterTermMeta'], 10, 3);

        // WPI & OCDI - replace rating IDs in comment meta
        add_filter('wp_import_post_comments', [$this, 'filterCommentMeta']);

        // WPI & OCDI - replace reting IDs in port meta
        add_filter('import_post_meta_key', [$this, 'filterPostMetaKey'], 10, 3);

        // Use later priority than the main plugin (20) to check did_action("mphb_import_end")
        add_action('import_end', [$this, 'endImport'], 25);
    }

    /**
     * @param bool $force Optional. FALSE by default.
     * @return array [Old term ID => New term ID]
     *
     * @since 1.2.3
     */
    public function getImportedTerms($force = false)
    {
        if (is_null($this->importedTerms) || $force) {
            $this->importedTerms = [];

            $ratingTypes = MPHBR()->getRatingTypeTaxonomy()->getAll();

            foreach ($ratingTypes as $ratingId) {
                $importId = get_term_meta($ratingId, '_mphb_import_id', true);

                if (is_numeric($importId)) {
                    $this->importedTerms[(int)$importId] = $ratingId;
                }
            }
        }

        return $this->importedTerms;
    }

    /**
     * @since 1.2.3
     */
    public function startImport()
    {
        // Disable updating average ratings while import
        add_filter('mphbr_update_average_ratings_on_save_review', '__return_false');
    }

    /**
     * @param int $newTermId
     * @param array $term
     *
     * @since 1.2.3
     */
    public function addTermImportId($newTermId, $term)
    {
        add_term_meta($newTermId, '_mphb_import_id', (int)$term['id']);
    }

    /**
     * @param array $termmeta Array of [key, value].
     * @param int $newTermId
     * @param array $term
     * @return array
     *
     * @since 1.2.3
     */
    public function filterTermMeta($termmeta, $newTermId, $term)
    {
        if (isset($term['term_id'], $term['term_taxonomy']) && $term['term_taxonomy'] == 'mphbr_ratings') {
            $termmeta[] = [
                'key'   => '_mphb_import_id',
                'value' => (int)$term['term_id']
            ];
        }

        return $termmeta;
    }

    /**
     * @param array $comments
     * @return array
     *
     * @since 1.2.3
     */
    public function filterCommentMeta($comments)
    {
        $importedTerms = $this->getImportedTerms();

        foreach ($comments as &$comment) {
            if (!isset($comment['comment_id'], $comment['comment_type'], $comment['commentmeta'])) {
                continue;
            }

            if ($comment['comment_type'] != 'mphbr_review') {
                continue;
            }

            // Replace old rating type IDs with the new ones
            foreach ($comment['commentmeta'] as &$commentmeta) {
                $isRating = preg_match('/^mphbr_rating_(?<id>\d+)$/', $commentmeta['key'], $matches);
                $oldTermId = $isRating ? (int)$matches['id'] : 0;

                if (isset($importedTerms[$oldTermId])) {
                    $newTermId = $importedTerms[$oldTermId];
                    $commentmeta['key'] = 'mphbr_rating_' . $newTermId;
                }
            }

            unset($commentmeta);
        }

        unset($comment);

        return $comments;
    }

    /**
     * @param string $metaKey
     * @param int $newPostId
     * @param array $post
     * @return string
     *
     * @since 1.2.3
     */
    public function filterPostMetaKey($metaKey, $newPostId, $post)
    {
        if (isset($post['post_type']) && $post['post_type'] == MPHB()->postTypes()->roomType()->getPostType()) {
            $importedTerms = $this->getImportedTerms();

            $isRating = (bool)preg_match('/^mphbr_rating_(?<id>\d+)(?<count>_count)?$/', $metaKey, $matches);
            $oldTermId = $isRating ? (int)$matches['id'] : 0;
            $suffix = isset($matches['count']) ? $matches['count'] : '';

            if (isset($importedTerms[$oldTermId])) {
                $newTermId = $importedTerms[$oldTermId];
                $metaKey = 'mphbr_rating_' . $newTermId . $suffix;
            }
        }

        return $metaKey;
    }

    /**
     * @since 1.2.3
     */
    public function endImport()
    {
        if (!did_action('mphb_import_end')) {
            do_action('mphb_import_end');
        }

        remove_filter('mphbr_update_average_ratings_on_save_review', '__return_false');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit