晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/rainic/www/oldTZh/wp-content/plugins/elementor-pro/modules/notes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/rainic/www/oldTZh/wp-content/plugins/elementor-pro/modules/notes/usage.php
<?php

namespace ElementorPro\Modules\Notes;

use Elementor\Core\Base\Document;
use ElementorPro\Core\Database\Join_Clause;
use ElementorPro\Core\Database\Query_Builder;
use ElementorPro\Core\Utils\Collection;
use ElementorPro\Modules\Notes\Database\Models\Note;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

class Usage {

	const THREADS = 'threads';
	const REPLIES = 'replies';

	/**
	 * Register hooks.
	 *
	 * @return void
	 */
	public function register() {
		add_filter( 'elementor/tracker/send_tracking_data_params', function ( array $params ) {
			$params['usages']['notes_feature'] = $this->get_usage_data();

			return $params;
		} );
	}

	/**
	 * Get the Notes feature usage data.
	 *
	 * @return array
	 */
	private function get_usage_data() {
		return [
			'threads' => $this->get_threads_usage(),
			'replies' => $this->get_replies_usage(),
			'mentions' => $this->get_mentions_usage(),
			'first_interaction' => $this->get_first_interaction(),
			'last_interaction' => $this->get_last_interaction(),
		];
	}

	/**
	 * Get the Threads' usage data.
	 *
	 * @return array
	 */
	private function get_threads_usage() {
		return [
			'total' => Note::query()
				->only_threads()
				->count(),

			'resolved' => Note::query()
				->only_threads()
				->where( 'is_resolved', '=', true )
				->count(),

			'trashed' => Note::query()
				->only_threads()
				->only_trashed()
				->count(),

			'users_used' => $this->get_notes_users_used( static::THREADS ),

			'document_type' => $this->get_notes_document_types( static::THREADS ),
		];
	}

	/**
	 * Get the replies' usage data.
	 *
	 * @return array
	 */
	private function get_replies_usage() {
		return [
			'total' => Note::query()
				->only_replies()
				->count(),

			'trashed' => Note::query()
				->only_replies()
				->only_trashed()
				->count(),

			'replied_threads' => (int) Note::query()
				->disable_model_initiation()
				->only_replies()
				->select_raw( [ 'COUNT(DISTINCT `parent_id`) AS `count`' ] )
				->first()['count'],

			'users_used' => $this->get_notes_users_used( static::REPLIES ),

			'document_type' => $this->get_notes_document_types( static::REPLIES ),
		];
	}

	/**
	 * Get the mentions' usage data.
	 *
	 * @return array
	 */
	private function get_mentions_usage() {
		return [
			'total' => ( new Query_Builder() )
				->table( Module::TABLE_NOTES_USERS_RELATIONS, 'e_notes_relations' )
				->join( function ( Join_Clause $j ) {
					$j->table( Module::TABLE_NOTES, 'e_notes' )
						->on_column( 'e_notes.id', '=', 'e_notes_relations.note_id' );
				} )
				->where( 'type', '=', Note::USER_RELATION_MENTION )
				->where( 'e_notes.status', '!=', Note::STATUS_TRASH )
				->count(),

			'users_used' => $this->get_mentions_users_used(),

			'document_type' => ( new Query_Builder() )
				->select( [ 'type' => 'postmeta.meta_value' ] )
				->add_count_select( '*', 'count' )
				->from( Module::TABLE_NOTES_USERS_RELATIONS, 'e_notes_relations' )
				->join( function ( Join_Clause $j ) {
					$j->table( Module::TABLE_NOTES, 'e_notes' )
						->on_column( 'e_notes.id', '=', 'e_notes_relations.note_id' );
				} )
				->join( function ( Join_Clause $j ) {
					$j->table( 'posts' )
						->on_column( 'posts.ID', '=', 'e_notes.post_id' );
				} )
				->join( function ( Join_Clause $j ) {
					$j->table( 'postmeta' )
						->on_column( 'posts.ID', '=', 'postmeta.post_id' )
						->on( 'postmeta.meta_key', '=', Document::TYPE_META_KEY );
				} )
				->where( 'e_notes.status', '!=', Note::STATUS_TRASH )
				->group_by( 'postmeta.meta_value' )
				->get()
				->map_with_keys( function ( $row ) {
					return [ $row['type'] => (int) $row['count'] ];
				} )
				->all(),
		];
	}

	/**
	 * Get the first user interaction with the Notes feature.
	 *
	 * @return string|null
	 */
	private function get_first_interaction() {
		$note = Note::query()
			->with_trashed()
			->select( [ 'created_at' ] )
			->order_by( 'created_at' )
			->first();

		return $note && $note->created_at
			? $note->created_at->format( 'Y-m-d\TH:i:sO' )
			: null;
	}

	/**
	 * Get the last user interaction with the Notes feature.
	 *
	 * @return string|null
	 */
	private function get_last_interaction() {
		$note = Note::query()
			->with_trashed()
			->select( [ 'last_activity_at' ] )
			->order_by( 'last_activity_at', 'desc' )
			->first();

		return $note && $note->last_activity_at
			? $note->last_activity_at->format( 'Y-m-d\TH:i:sO' )
			: null;
	}

	/**
	 * Get the count of `$type` usages grouped by user role.
	 *
	 * e.g. for 10 replies it can be something like: `{ admin: 7, subscriber: 3 }`
	 *
	 * @param string $type - Threads or replies.
	 *
	 * @return array
	 */
	private function get_notes_users_used( $type ) {
		$query = Note::query()
			->disable_model_initiation()
			->select( [ 'user_used_id' => Module::TABLE_NOTES . '.author_id' ] )
			->add_count_select( Module::TABLE_NOTES . '.id', 'count' )
			->group_by( 'user_used_id' );

		switch ( $type ) {
			case static::THREADS:
				$query->only_threads();
				break;

			case static::REPLIES:
				$query->only_replies();
				break;
		}

		return $this->normalize_users_used( $query->get() );
	}

	/**
	 * Get the count of mentions usages grouped by user role.
	 *
	 * e.g. for 10 mentions it can be something like: `{ admin: 7, subscriber: 3 }`
	 *
	 * @return array
	 */
	private function get_mentions_users_used() {
		$query = ( new Query_Builder() )
			->from( Module::TABLE_NOTES_USERS_RELATIONS, 'e_notes_relations' )
			->select( [ 'user_used_id' => 'e_notes.author_id' ] )
			->add_count_select( 'e_notes_relations.id', 'count' )
			->join( function ( Join_Clause $j ) {
				$j->table( Module::TABLE_NOTES, 'e_notes' )
					->on_column( 'e_notes_relations.note_id', '=', 'e_notes.id' );
			} )
			->where( 'e_notes_relations.type', '=', Note::USER_RELATION_MENTION )
			->where( 'e_notes.status', '!=', Note::STATUS_TRASH )
			->group_by( 'e_notes.author_id' );

		return $this->normalize_users_used( $query->get() );
	}

	/**
	 * Normalize `users_used` query results into counts array grouped by user role.
	 *
	 * @param Collection $query_results
	 *
	 * @return array
	 */
	private function normalize_users_used( Collection $query_results ) {
		if ( $query_results->is_empty() ) {
			return [];
		}

		$results = $query_results->map_with_keys( function ( $row ) {
			return [ $row['user_used_id'] => (int) $row['count'] ];
		} );

		/**
		 * @type \WP_User[] $users
		 */
		$users = get_users( [
			'include' => $results->keys()->all(),
		] );

		$counts = [];

		foreach ( $users as $user ) {
			/**
			 * WordPress also uses the first role.
			 *
			 * @see https://github.com/WordPress/WordPress/blob/57039311720709d55e96e1a074414ebadba64e00/wp-admin/user-edit.php#L419-L435
			 */
			$role = reset( $user->roles );

			if ( ! isset( $counts[ $role ] ) ) {
				$counts[ $role ] = 0;
			}

			$counts[ $role ] += $results->get( $user->ID );
		}

		return $counts;
	}

	/**
	 * Get the count of `$type` usages grouped by document type.
	 *
	 * @param string $type - Threads or replies.
	 *
	 * @return array
	 */
	private function get_notes_document_types( $type ) {
		$query = Note::query()
			->disable_model_initiation()
			->select( [ 'type' => 'postmeta.meta_value' ] )
			->add_count_select( '*', 'count' )
			->join( function ( Join_Clause $j ) {
				$j->table( 'posts' )
					->on_column( 'posts.ID', '=', Module::TABLE_NOTES . '.post_id' );
			} )
			->join( function ( Join_Clause $j ) {
				$j->table( 'postmeta' )
					->on_column( 'posts.ID', '=', 'postmeta.post_id' )
					->on( 'postmeta.meta_key', '=', Document::TYPE_META_KEY );
			} )
			->group_by( 'postmeta.meta_value' );

		switch ( $type ) {
			case static::THREADS:
				$query->only_threads();
				break;

			case static::REPLIES:
				$query->only_replies();
				break;
		}

		return $query->get()
			->map_with_keys( function ( $row ) {
				return [ $row['type'] => (int) $row['count'] ];
			} )
			->all();
	}
}

haha - 2025