diff --git a/.github/workflows/build-dev-artifacts.yml b/.github/workflows/build-dev-artifacts.yml index 9997bce1..b13dae1b 100755 --- a/.github/workflows/build-dev-artifacts.yml +++ b/.github/workflows/build-dev-artifacts.yml @@ -17,18 +17,11 @@ jobs: git-sha-8: ${{ steps.retrieve-git-sha-8.outputs.sha8 }} steps: - name: Check out source files - uses: actions/checkout@v2 - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Configure Composer cache - uses: actions/cache@v1 + uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- + node-version: 18 + cache: "npm" - name: Install composer deps env: GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} @@ -99,4 +92,4 @@ jobs: comment-id: ${{ steps.find-comment.outputs.comment-id }} token: ${{ secrets.BOT_TOKEN }} edit-mode: replace - body: ${{ steps.get-comment-body.outputs.body }} \ No newline at end of file + body: ${{ steps.get-comment-body.outputs.body }} diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index e2cec0db..af53b54f 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -15,9 +15,10 @@ jobs: with: persist-credentials: false - name: Build files using ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} + cache: "npm" - name: Release new version id: release run: | @@ -31,4 +32,4 @@ jobs: SEMANTIC_RELEASE_PACKAGE: Visualizer(free) GIT_AUTHOR_EMAIL: ${{ secrets.BOT_EMAIL }} GIT_COMMITTER_NAME: themeisle[bot] - GIT_COMMITTER_EMAIL: ${{ secrets.BOT_EMAIL }} \ No newline at end of file + GIT_COMMITTER_EMAIL: ${{ secrets.BOT_EMAIL }} diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index a50a3364..c44e03ab 100755 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -16,19 +16,11 @@ jobs: fail-fast: false runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: "18" - - uses: actions/cache@v2 - id: npm-and-build-cache - with: - path: | - ~/.cache/Cypress - node_modules - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- + cache: "npm" - name: Install npm deps run: | npm ci diff --git a/.github/workflows/test-php.yml b/.github/workflows/test-php.yml index 595a1850..fc7ffecd 100755 --- a/.github/workflows/test-php.yml +++ b/.github/workflows/test-php.yml @@ -3,7 +3,7 @@ name: PHP Tests on: push: branches-ignore: - - 'master' + - "master" jobs: phplint: @@ -13,21 +13,10 @@ jobs: - name: Setup PHP version uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: "7.4" extensions: simplexml - name: Checkout source code - uses: actions/checkout@v2 - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Setup Composer cache - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- + uses: actions/checkout@v4 - name: Install composer run: | composer install --prefer-dist --no-progress @@ -49,25 +38,14 @@ jobs: - name: Setup PHP version uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: "7.4" extensions: simplexml, mysql tools: phpunit-polyfills - name: Checkout source code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install WordPress Test Suite run: | bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:${{ job.services.mysql.ports['3306'] }} - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Setup Composer cache - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - name: Install composer run: | composer install --prefer-dist --no-progress --no-dev diff --git a/classes/Visualizer/Module/Admin.php b/classes/Visualizer/Module/Admin.php index 2bc81b5c..d2b62f74 100644 --- a/classes/Visualizer/Module/Admin.php +++ b/classes/Visualizer/Module/Admin.php @@ -79,6 +79,10 @@ public function __construct( Visualizer_Plugin $plugin ) { $this->_addFilter( 'admin_footer_text', 'render_review_notice' ); + if ( ! defined( 'TI_CYPRESS_TESTING' ) ) { + $this->_addFilter( 'themeisle-sdk/survey/' . VISUALIZER_DIRNAME, 'get_survey_metadata', 10, 2 ); + } + if ( defined( 'TI_CYPRESS_TESTING' ) ) { $this->load_cypress_hooks(); } @@ -934,7 +938,7 @@ private function getQuery() { */ public function renderSupportPage() { wp_enqueue_style( 'visualizer-upsell', VISUALIZER_ABSURL . 'css/upsell.css', array(), Visualizer_Plugin::VERSION ); - $this->load_survey(); + do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'support' ); include_once VISUALIZER_ABSPATH . '/templates/support.php'; } @@ -1091,7 +1095,7 @@ public function renderLibraryPage() { ) ); - $this->load_survey(); + do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'library' ); if ( ! apply_filters( 'visualizer_is_business', false ) ) { do_action( 'themeisle_sdk_load_banner', 'visualizer' ); @@ -1230,71 +1234,74 @@ public static function checkChartStatus( $type ) { /** * Get the survey metadata. * + * @param array $data The data for survey in Formbricks format. + * @param string $page_slug The slug of the loaded page. + * * @return array The survey metadata. */ - private function get_survey_metadata() { - $install_date = get_option( 'visualizer_install', false ); - $install_category = 0; - - if ( false !== $install_date ) { - $days_since_install = round( ( time() - $install_date ) / DAY_IN_SECONDS ); - - if ( 0 === $days_since_install || 1 === $days_since_install ) { - $install_category = 0; - } elseif ( 1 < $days_since_install && 8 > $days_since_install ) { - $install_category = 7; - } elseif ( 8 <= $days_since_install && 31 > $days_since_install ) { - $install_category = 30; - } elseif ( 30 < $days_since_install && 90 > $days_since_install ) { - $install_category = 90; - } elseif ( 90 <= $days_since_install ) { - $install_category = 91; - } - } + public function get_survey_metadata( $data, $page_slug ) { + $install_date = get_option( 'visualizer_install', time() ); + $install_days_number = intval( ( time() - $install_date ) / DAY_IN_SECONDS ); + + $license_status = apply_filters( 'product_visualizer_license_status', 'invalid' ); + $license_plan = apply_filters( 'product_visualizer_license_plan', false ); + $license_key = apply_filters( 'product_visualizer_license_key', false ); $plugin_data = get_plugin_data( VISUALIZER_BASEFILE, false, false ); $plugin_version = ''; + if ( ! empty( $plugin_data['Version'] ) ) { $plugin_version = $plugin_data['Version']; } - $user_id = 'visualizer_' . preg_replace( '/[^\w\d]*/', '', get_site_url() ); // Use a normalized version of the site URL as a user ID. + $count_charts_cache_key = 'visualizer_count_charts'; + $charts_number = get_transient( $count_charts_cache_key ); - $license_data = get_option( 'visualizer_pro_license_data', false ); - if ( false !== $license_data && isset( $license_data->key ) ) { - $user_id = 'visualizer_' . $license_data->key; + if ( false === $charts_number ) { + $charts_number = $this->count_charts( 100 ); + set_transient( $count_charts_cache_key, $charts_number, 100 === $charts_number ? WEEK_IN_SECONDS : 6 * HOUR_IN_SECONDS ); + } else { + $charts_number = strval( $charts_number ); } - return array( - 'userId' => $user_id, + $data = array( + 'environmentId' => 'cltef8cut1s7wyyfxy3rlxzs5', 'attributes' => array( - 'days_since_install' => strval( $install_category ), - 'free_version' => $plugin_version, - 'pro_version' => defined( 'VISUALIZER_PRO_VERSION' ) ? VISUALIZER_PRO_VERSION : '', - 'license_status' => apply_filters( 'product_visualizer_license_status', 'invalid' ), + 'free_version' => $plugin_version, + 'pro_version' => defined( 'VISUALIZER_PRO_VERSION' ) ? VISUALIZER_PRO_VERSION : '', + 'license_status' => $license_status, + 'install_days_number' => $install_days_number, + 'charts_number' => $charts_number, ), ); - } - - /** - * Load the survey. - */ - private function load_survey() { - if ( defined( 'TI_CYPRESS_TESTING' ) ) { - return; + if ( ! empty( $license_plan ) ) { + $data['attributes']['plan'] = $license_plan; } - $survey_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'survey' ); - - if ( empty( $survey_handler ) ) { - return; + if ( ! empty( $license_key ) ) { + $data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', $license_key ); } - $metadata = $this->get_survey_metadata(); + return $data; + } + + /** + * Count the charts. + * + * @param int $limit The count limit (optional). + * + * @return int The number of charts. + */ + public function count_charts( $limit = -1 ) { + $args = array( + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, + 'post_status' => 'publish', + 'posts_per_page' => $limit, + 'fields' => 'ids', + ); - do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' ); - wp_enqueue_script( 'visualizer_chart_survey', VISUALIZER_ABSURL . 'js/survey.js', array( $survey_handler ), $metadata['attributes']['free_version'], true ); - wp_localize_script( 'visualizer_chart_survey', 'visualizerSurveyData', $metadata ); + $query = new WP_Query( $args); + return $query->post_count; } } diff --git a/classes/Visualizer/Source.php b/classes/Visualizer/Source.php index 03e7c99a..7b3d6b59 100644 --- a/classes/Visualizer/Source.php +++ b/classes/Visualizer/Source.php @@ -429,7 +429,7 @@ private function _fetchSeriesFromEditableTable() { foreach ( $headers as $header ) { if ( ! empty( $types[ $header ] ) ) { $this->_series[] = array( - 'label' => esc_html( wp_strip_all_tags( $header ) ), + 'label' => sanitize_text_field( wp_strip_all_tags( $header ) ), 'type' => $types[ $header ], ); } diff --git a/classes/Visualizer/Source/Csv.php b/classes/Visualizer/Source/Csv.php index 461fd8db..79665864 100644 --- a/classes/Visualizer/Source/Csv.php +++ b/classes/Visualizer/Source/Csv.php @@ -97,7 +97,7 @@ private function _fetchSeries( &$handle ) { $labels[ $i ] = $this->toUTF8( $labels[ $i ] ); $this->_series[] = array( - 'label' => esc_html( wp_strip_all_tags( $labels[ $i ] ) ), + 'label' => sanitize_text_field( wp_strip_all_tags( $labels[ $i ] ) ), 'type' => isset( $types[ $i ] ) ? $types[ $i ] : $default_type, ); } diff --git a/composer.lock b/composer.lock index 142f29d1..8546d89e 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "codeinwp/themeisle-sdk", - "version": "3.3.41", + "version": "3.3.44", "source": { "type": "git", "url": "https://github.com/Codeinwp/themeisle-sdk.git", - "reference": "b194c872933882f4e5780eae56c59698d01623fc" + "reference": "fed444b52ebf1f689ec2434df177926bf8f238c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/b194c872933882f4e5780eae56c59698d01623fc", - "reference": "b194c872933882f4e5780eae56c59698d01623fc", + "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/fed444b52ebf1f689ec2434df177926bf8f238c4", + "reference": "fed444b52ebf1f689ec2434df177926bf8f238c4", "shasum": "" }, "require-dev": { @@ -43,9 +43,9 @@ ], "support": { "issues": "https://github.com/Codeinwp/themeisle-sdk/issues", - "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.41" + "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.44" }, - "time": "2025-02-05T10:30:34+00:00" + "time": "2025-02-18T21:31:30+00:00" }, { "name": "neitanod/forceutf8", diff --git a/js/survey.js b/js/survey.js deleted file mode 100644 index 6e29d56b..00000000 --- a/js/survey.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Initialize the formbricks survey. - * - * @see https://github.com/formbricks/setup-examples/tree/main/html - */ -window.addEventListener('themeisle:survey:loaded', function () { - window?.tsdk_formbricks?.init?.({ - environmentId: "cltef8cut1s7wyyfxy3rlxzs5", - apiHost: "https://app.formbricks.com", - ...(window?.visualizerSurveyData ?? {}), - }); -}); \ No newline at end of file