Author URI: https://www.trustindex.io/ Contributors: trustindex License: GPL2 License URI: https://www.gnu.org/licenses/gpl-2.0.html Text Domain: social-photo-feed-widget Domain Path: /languages/ Donate link: https://www.trustindex.io/prices/ */ /* You should have received a copy of the GNU General Public License along with Review widget addon for Divi. If not, see https://www.gnu.org/licenses/gpl-2.0.html. */ /* Copyright 2019 Trustindex Kft (email: support@trustindex.io) */ defined('ABSPATH') or die('No script kiddies please!'); require_once plugin_dir_path(__FILE__) . 'include' . DIRECTORY_SEPARATOR . 'cache-plugin-filters.php'; require_once plugin_dir_path( __FILE__ ) . 'trustindex-feed-plugin.class.php'; $trustindex_feed_instagram = new TRUSTINDEX_Feed_Instagram("instagram", __FILE__, "1.8.1", "Widgets for Social Photo Feed", "Instagram"); $pluginManagerInstance = $trustindex_feed_instagram; register_activation_hook(__FILE__, [ $pluginManagerInstance, 'activate' ]); register_deactivation_hook(__FILE__, [ $pluginManagerInstance, 'deactivate' ]); add_action('plugins_loaded', [ $pluginManagerInstance, 'load' ]); add_action('admin_menu', [ $pluginManagerInstance, 'addSettingMenu' ], 10); add_filter('plugin_action_links', [ $pluginManagerInstance, 'addPluginActionLinks' ], 10, 2); add_filter('plugin_row_meta', [ $pluginManagerInstance, 'addPluginMetaLinks' ], 10, 2); add_action('init', [ $pluginManagerInstance, 'outputBuffer' ]); add_action('admin_enqueue_scripts', [ $pluginManagerInstance, 'addScripts' ]); if (is_file($pluginManagerInstance->getCssFile())) { add_action('init', function() use ($pluginManagerInstance) { $path = wp_upload_dir()['baseurl'] .'/'. $pluginManagerInstance->getCssFile(true); if (is_ssl()) { $path = str_replace('http://', 'https://', $path); } wp_register_style($pluginManagerInstance->getCssKey(), $path, [], filemtime($pluginManagerInstance->getCssFile())); }); } if (!function_exists('trustindex_esc_css')) { function trustindex_esc_css($css) { $css = wp_strip_all_tags($css); $css = esc_html($css); $css = str_replace(['<','>','"', ''', '&'], ['<', '>', '"', "'", '&'], $css); return $css; } } add_action('init', [ $pluginManagerInstance, 'shortcode' ]); add_filter('script_loader_tag', function($tag, $handle, $src) { if ($handle === 'trustindex-feed-loader-js' && strpos($tag, 'defer async') === false) { $tag = str_replace(' src', ' defer async src', $tag); } return $tag; }, 10, 3); add_action('rest_api_init', function () use ($pluginManagerInstance) { register_rest_route($pluginManagerInstance->getWebhookAction(), '/get-token', [ 'methods' => 'GET', 'callback' => function () { return rest_ensure_response([ 'nonce' => wp_create_nonce('admin_action_nonce'), ]); }, 'permission_callback' => '__return_true', ]); register_rest_route($pluginManagerInstance->getWebhookAction(), '/troubleshooting', [ 'methods' => 'GET', 'callback' => function (WP_REST_Request $request) use ($pluginManagerInstance) { $authError = $pluginManagerInstance->getAuthError($request); if (null !== $authError) { return $authError; } header('Content-Type: text/html; charset=UTF-8'); global $wpdb, $wp_version; echo '
'; include $pluginManagerInstance->getPluginDir() . 'include' . DIRECTORY_SEPARATOR . 'troubleshooting.php'; echo ''; exit; }, 'permission_callback' => '__return_true', ]); register_rest_route($pluginManagerInstance->getWebhookAction(), '/submit-data', [ 'methods' => 'POST', 'callback' => function (WP_REST_Request $request) use ($pluginManagerInstance) { $authError = $pluginManagerInstance->getAuthError($request); if (null !== $authError) { return $authError; } $oldSource = $pluginManagerInstance->getConnectedSource(); /* This function ensures that each element of the JSON object is sanitized individually using standard WordPress sanitization functions */ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $source = $pluginManagerInstance->sanitizeJsonData(wp_unslash($request->get_param('data')), false); $source['feed_data'] = $pluginManagerInstance->getFeedDataFromCdn(); if (empty($source['feed_data']['style']['type'])) { $oldFeedData = $pluginManagerInstance->getFeedDataLocal(); $source['feed_data']['style'] = array_merge($source['feed_data']['style'], $oldFeedData['style'] ?? []); } $source = $pluginManagerInstance->saveConnectedSource($source); if (empty($source['error']) && !$pluginManagerInstance->isDownloadInProgress()) { $lastDownloadChecked = get_option($pluginManagerInstance->getOptionName('feed-data-download-checked'), 0); if ($lastDownloadChecked + $pluginManagerInstance::$downloadCheckSeconds + 1 < time()) { if ($oldSource) { $notificationType = 'post-download-finished'; } else { $notificationType = 'connect-finished'; } $pluginManagerInstance->sendNotificationEmail($notificationType); $pluginManagerInstance->setNotificationParam($notificationType, 'active', true); $pluginManagerInstance->setNotificationParam($notificationType, 'do-check', false); } } return new WP_REST_Response([ 'token' => get_option($pluginManagerInstance->getOptionName('public-id')), ]); }, 'permission_callback' => '__return_true', ]); register_rest_route($pluginManagerInstance->getWebhookAction(), '/refresh-data', [ 'methods' => 'GET', 'callback' => function (WP_REST_Request $request) use ($pluginManagerInstance) { $authError = $pluginManagerInstance->getAuthError($request); if (null !== $authError) { return $authError; } return rest_ensure_response([ 'data' => $pluginManagerInstance->getFeedData(true), ]); }, 'permission_callback' => '__return_true', ]); }); add_action('wp_ajax_download_check', function() use ($pluginManagerInstance) { check_ajax_referer('ti-download-check', 'nonce'); update_option($pluginManagerInstance->getOptionName('feed-data-download-checked'), time(), false); wp_send_json(['downloaded' => !$pluginManagerInstance->isDownloadInProgress()]); }); add_action('admin_notices', function() use ($pluginManagerInstance) { if (!current_user_can($pluginManagerInstance::$permissionNeeded)) { return; } foreach ($pluginManagerInstance->getNotificationOptions() as $type => $options) { if (!$pluginManagerInstance->isNotificationActive($type)) { continue; } echo ''; } }); add_action('elementor/widgets/widgets_registered', function ($widgetsManager) { require_once(__DIR__ . '/include/trustindex-elementor-widgets.php'); $widgetsManager->register(new \Elementor\TrustrindexFeedWidget_Instagram()); }); add_action('elementor/elements/categories_registered', function ($elementsManager) { $elementsManager->add_category( 'trustindex', [ 'title' => __('Trustindex', 'social-photo-feed-widget'), 'icon' => 'fa fa-plug', ] ); }); add_action('wp_enqueue_scripts', function() use ($pluginManagerInstance) { if (!is_user_logged_in() || !current_user_can($pluginManagerInstance::$permissionNeeded)) { return; } foreach ($pluginManagerInstance->getNotificationOptions() as $type => $options) { if (!$pluginManagerInstance->isNotificationActive($type) || !isset($options['short-message'])) { continue; } echo ''; } wp_register_script('trustindex_frontend_notification', $pluginManagerInstance->getPluginFileUrl('assets/js/frontend-notifictions.js'), [], $pluginManagerInstance->getVersion(), ['in_footer' => false]); wp_enqueue_script('trustindex_frontend_notification'); wp_enqueue_style('trustindex_frontend_notification', $pluginManagerInstance->getPluginFileUrl('assets/css/frontend-notifictions.css'), [], $pluginManagerInstance->getVersion()); }); unset($pluginManagerInstance); ?>