component( 'friends' ); if ( $friends ) { return $friends->is_blocked( $user_a, $user_b ); } // Fallback: direct DB query if Friends component not loaded. global $wpdb; return (bool) $wpdb->get_var( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT id FROM {$wpdb->prefix}arshid6social_blocks WHERE (blocker_id = %d AND blocked_id = %d) OR (blocker_id = %d AND blocked_id = %d)", $user_a, $user_b, $user_b, $user_a ) ); } /** * Returns the Stories component or null when disabled. * * @return \Arshid6Social\Components\Stories\Stories|null */ function arshid6social_stories(): ?object { return ARSHID6SOCIAL()->component( 'stories' ); } /** * Returns the Blocking component or null when disabled. * * @return \Arshid6Social\Components\Blocking\Blocking|null */ function arshid6social_blocking(): ?object { return ARSHID6SOCIAL()->component( 'blocking' ); } /** * Returns the Verification component or null when disabled. * * @return \Arshid6Social\Components\Verification\Verification|null */ function arshid6social_verification(): ?object { return ARSHID6SOCIAL()->component( 'verification' ); } /** * Returns the Marketplace component or null when disabled. * * @return \Arshid6Social\Components\Marketplace\Marketplace|null */ function arshid6social_marketplace(): ?object { return ARSHID6SOCIAL()->component( 'marketplace' ); } /** * Returns true if user is site-wide blocked/banned by an admin. * * @param int $user_id User ID. * @return bool */ function arshid6social_is_site_blocked( int $user_id ): bool { return (bool) get_user_meta( $user_id, 'arshid6social_site_blocked', true ); } /** * Returns the verified badge HTML for a user, or empty string if not verified. * * @param int $user_id User ID. * @param bool $echo Whether to echo. * @return string */ /** * Returns the Bootstrap Icon SVG for a given page, or empty string if none is set. * * @param int $page_id WordPress page ID (defaults to current post). * @param int $size SVG width/height in pixels. * @return string Safe inline SVG, or empty string. */ function arshid6social_page_icon( int $page_id = 0, int $size = 20 ): string { if ( ! $page_id ) { $page_id = (int) get_the_ID(); } $icon = (string) get_post_meta( $page_id, \Arshid6Social\Admin\Admin_Page_Icons::META_KEY, true ); if ( ! $icon ) { return ''; } $picker = \Arshid6Social\Admin\Admin_Page_Icons::instance(); return $picker->get_icon_svg( $icon, $size ); } function arshid6social_verified_badge( int $user_id, bool $echo = false ): string { $verification = arshid6social_verification(); if ( ! $verification ) { return ''; } $badge = $verification->get_badge_html( $user_id ); if ( $echo ) { echo $badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } return $badge; } /** * Checks a rate limit via transients. * * @param string $key Unique key prefix (e.g. 'arshid6social_rl_stories'). * @param int $user_id User ID. * @param int $max Max calls per hour. * @return bool True if under limit. */ function arshid6social_check_rate_limit( string $key, int $user_id, int $max ): bool { // Ensure the transient key is always prefixed with the plugin slug. $prefixed_key = str_starts_with( $key, 'ARSHID6SOCIAL_' ) ? $key : 'ARSHID6SOCIAL_' . $key; $tk = $prefixed_key . '_' . $user_id; $count = (int) get_transient( $tk ); if ( $count >= $max ) { return false; } set_transient( $tk, $count + 1, HOUR_IN_SECONDS ); return true; } /** * Determines whether the current user is allowed to view a given activity item. * * Rules: * - Public activities are visible to everyone. * - Private activities are visible only to the author or admins. * - Friends-only activities are visible to the author, their friends, or admins. * - Paid (PPV) activities follow the same rules as private for REST permission checks. * * @param int $activity_id Activity ID. * @return bool True if current user may view the activity. */ function arshid6social_current_user_can_view_activity( int $activity_id ): bool { if ( ! $activity_id ) { return false; } $component = ARSHID6SOCIAL()->component( 'activity' ); if ( $component ) { $activity = $component->get_by_id( $activity_id ); } else { global $wpdb; $activity = $wpdb->get_row( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT id, user_id, privacy FROM {$wpdb->prefix}arshid6social_activity WHERE id = %d LIMIT 1", $activity_id ) ); } if ( ! $activity ) { return false; } $privacy = isset( $activity->privacy ) ? (string) $activity->privacy : 'public'; $activity_author = (int) ( $activity->user_id ?? 0 ); $current_user = get_current_user_id(); // Public is visible to all. if ( 'public' === $privacy ) { return true; } // All non-public requires login. if ( ! $current_user ) { return false; } // Admins and the author always have access. if ( $current_user === $activity_author || current_user_can( 'arshid6social_manage_activity' ) ) { return true; } // Friends-only: check friendship. if ( 'friends' === $privacy ) { $friends = ARSHID6SOCIAL()->component( 'friends' ); if ( $friends && method_exists( $friends, 'are_friends' ) ) { return $friends->are_friends( $current_user, $activity_author ); } } return false; } /** * Outputs the report modal HTML used on profile and group pages. * Requires ARSHID6SOCIALConfig.reportReasons to be populated via wp_localize_script. */ function arshid6social_report_modal(): void { ?>
> */ function a6sc_allowed_svg_tags(): array { return array( 'svg' => array( 'xmlns' => true, 'width' => true, 'height' => true, 'viewbox' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, 'aria-hidden' => true, 'role' => true, ), 'path' => array( 'd' => true, 'fill' => true, 'fill-rule' => true, 'clip-rule' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, ), 'circle' => array( 'cx' => true, 'cy' => true, 'r' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, ), 'rect' => array( 'x' => true, 'y' => true, 'width' => true, 'height' => true, 'rx' => true, 'ry' => true, 'fill' => true, ), 'line' => array( 'x1' => true, 'y1' => true, 'x2' => true, 'y2' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, ), 'polyline' => array( 'points' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, ), 'polygon' => array( 'points' => true, 'fill' => true, 'stroke' => true, ), 'g' => array( 'fill' => true ), ); } } if ( ! function_exists( 'a6sc_kses_svg' ) ) { /** * Sanitizes SVG markup through a minimal explicit allowlist. * * @param string $svg Raw SVG string. * @return string Sanitized SVG string. */ function a6sc_kses_svg( string $svg ): string { return wp_kses( $svg, a6sc_allowed_svg_tags() ); } }