'ansico', 'title' => __( 'Ansico Blocks', 'ansico-some-plugin' ), 'icon' => null, ) ); return $categories; } function ansico_get_micropost_max_chars() { $value = get_option( 'ansico_micropost_max_chars', 500 ); $value = intval( $value ); return $value > 0 ? $value : 500; } add_action( 'admin_menu', 'ansico_register_settings_page' ); function ansico_register_settings_page() { add_options_page( 'Ansico SoMe Plugin', 'Ansico SoMe Plugin', 'manage_options', 'ansico-some-plugin-settings', 'ansico_render_settings_page' ); } add_action( 'admin_init', 'ansico_register_settings' ); function ansico_register_settings() { register_setting( 'ansico_some_plugin_settings', 'ansico_micropost_max_chars', array( 'type' => 'integer', 'sanitize_callback' => 'ansico_sanitize_micropost_max_chars', 'default' => 500, ) ); register_setting( 'ansico_some_plugin_settings', 'ansico_clean_up_profile_settings', array( 'type' => 'boolean', 'sanitize_callback' => 'ansico_sanitize_checkbox_setting', 'default' => false, ) ); add_settings_section( 'ansico_some_plugin_main', __( 'Micropost settings', 'ansico-some-plugin' ), function() { echo '
' . esc_html__( 'Settings for Ansico SoMe Plugin.', 'ansico-some-plugin' ) . '
'; }, 'ansico-some-plugin-settings' ); add_settings_field( 'ansico_micropost_max_chars', __( 'Maximum characters in Micropost Form', 'ansico-some-plugin' ), 'ansico_render_micropost_max_chars_field', 'ansico-some-plugin-settings', 'ansico_some_plugin_main' ); add_settings_field( 'ansico_clean_up_profile_settings', __( 'Clean up profile settings', 'ansico-some-plugin' ), 'ansico_render_clean_up_profile_settings_field', 'ansico-some-plugin-settings', 'ansico_some_plugin_main' ); } function ansico_sanitize_checkbox_setting( $value ) { return ! empty( $value ) ? '1' : ''; } function ansico_sanitize_micropost_max_chars( $value ) { $value = intval( $value ); if ( $value < 1 ) { $value = 500; } return $value; } function ansico_render_micropost_max_chars_field() { $value = ansico_get_micropost_max_chars(); echo ''; echo '' . esc_html__( 'Default is 500 characters.', 'ansico-some-plugin' ) . '
'; } function ansico_render_clean_up_profile_settings_field() { $enabled = ! empty( get_option( 'ansico_clean_up_profile_settings', '' ) ); echo ''; } function ansico_render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } ?>$1', $text);
$text = preg_replace('/^>\s+(.*)/m', '$1', $text); return $text; } function ansico_get_formatted_comment_html( $comment, $already_filtered = false ) { if ( ! is_object( $comment ) ) { return ''; } $raw_text = isset( $comment->comment_content ) ? (string) $comment->comment_content : ''; if ( $raw_text === '' ) { return ''; } preg_match( '/(https?:\/\/[^\s()<>{}\[\]]+)/i', $raw_text, $url_matches ); $first_url = ! empty( $url_matches[1] ) ? $url_matches[1] : ''; $text = esc_html( $raw_text ); $text = ansico_apply_micropost_text_formatting( $text ); $text = wpautop( $text ); if ( $first_url ) { $embed_data = ansico_fetch_metadata_internal( $first_url ); if ( $embed_data && ! empty( $embed_data['title'] ) ) { $img_html = ! empty( $embed_data['image'] ) ? '
\s*(
)\s*#i', '#\s*(]*>\s*]*class="ansico-tweet-embed-image"[^>]*>\s*)\s*
\s*(]*class="ansico-tweet-embed-image"[^>]*>)\s*
\s*(
]*>.*?)\s*#is', '#
\s*
#i', ); $replacements = array('$1', '$1', '$1', '$1', '$1', ''); $html = preg_replace( $patterns, $replacements, $html ); return trim( $html ); } /* ========================================================================== 1.8. CUSTOM COMMENT MARKUP (Design uden "siger" og med ny opstilling) ========================================================================== */ function ansico_custom_comment_markup($comment, $args, $depth) { $GLOBALS['comment'] = $comment; $avatar = get_avatar($comment, 40, '', '', array('class' => 'ansico-tweet-avatar')); $author_link = get_comment_author_link($comment); $author_url = ''; if ( is_object( $comment ) && ! empty( $comment->user_id ) ) { $author_url = get_author_posts_url( (int) $comment->user_id ); } elseif ( is_object( $comment ) && ! empty( $comment->comment_author_url ) ) { $author_url = $comment->comment_author_url; } $avatar_html = $author_url ? '' . $avatar . '' : $avatar; $time_display = get_comment_date( get_option('date_format'), $comment ) . ' · ' . get_comment_time( get_option('time_format'), false, false, $comment ); $like_button = ansico_render_like_button( 'comment', $comment->comment_ID ); ?>ID ) && get_post_type( $wp_object->ID ) === 'micropost' ) { update_post_meta( intval( $wp_object->ID ), '_ansico_has_been_federated', '1' ); } } add_action( 'activitypub_mark_wp_object_as_federated', 'ansico_mark_micropost_as_federated' ); /* ========================================================================== 3. RENDERING ENGINE ========================================================================== */ function ansico_get_like_count( $object_type, $object_id ) { $object_id = intval( $object_id ); if ( $object_id < 1 ) { return 0; } if ( $object_type === 'comment' ) { return max( 0, intval( get_comment_meta( $object_id, '_ansico_like_count', true ) ) ); } return max( 0, intval( get_post_meta( $object_id, '_ansico_like_count', true ) ) ); } function ansico_get_user_liked_items( $user_id, $object_type ) { $meta_key = $object_type === 'comment' ? '_ansico_liked_comments' : '_ansico_liked_posts'; $liked = get_user_meta( intval( $user_id ), $meta_key, true ); return is_array( $liked ) ? array_values( array_unique( array_map( 'intval', $liked ) ) ) : array(); } function ansico_user_has_liked( $object_type, $object_id, $user_id = 0 ) { $user_id = $user_id ? intval( $user_id ) : get_current_user_id(); $object_id = intval( $object_id ); if ( $user_id < 1 || $object_id < 1 ) { return false; } return in_array( $object_id, ansico_get_user_liked_items( $user_id, $object_type ), true ); } function ansico_toggle_like( $object_type, $object_id, $user_id = 0 ) { $user_id = $user_id ? intval( $user_id ) : get_current_user_id(); $object_id = intval( $object_id ); if ( $user_id < 1 || $object_id < 1 ) { return new WP_Error( 'ansico_like_forbidden', 'Kun loggede brugere kan like.', array( 'status' => 403 ) ); } if ( $object_type === 'comment' ) { $comment = get_comment( $object_id ); if ( ! $comment || intval( $comment->comment_approved ) !== 1 ) { return new WP_Error( 'ansico_like_invalid_comment', 'Kommentaren findes ikke.', array( 'status' => 404 ) ); } $liked = ansico_get_user_liked_items( $user_id, 'comment' ); $has_liked = in_array( $object_id, $liked, true ); if ( $has_liked ) { $liked = array_values( array_diff( $liked, array( $object_id ) ) ); update_user_meta( $user_id, '_ansico_liked_comments', $liked ); $count = max( 0, ansico_get_like_count( 'comment', $object_id ) - 1 ); update_comment_meta( $object_id, '_ansico_like_count', $count ); return array( 'liked' => false, 'count' => $count ); } $liked[] = $object_id; update_user_meta( $user_id, '_ansico_liked_comments', array_values( array_unique( array_map( 'intval', $liked ) ) ) ); $count = ansico_get_like_count( 'comment', $object_id ) + 1; update_comment_meta( $object_id, '_ansico_like_count', $count ); return array( 'liked' => true, 'count' => $count ); } $post = get_post( $object_id ); if ( ! $post || $post->post_status !== 'publish' || $post->post_type !== 'micropost' ) { return new WP_Error( 'ansico_like_invalid_post', 'Microposten findes ikke.', array( 'status' => 404 ) ); } $liked = ansico_get_user_liked_items( $user_id, 'post' ); $has_liked = in_array( $object_id, $liked, true ); if ( $has_liked ) { $liked = array_values( array_diff( $liked, array( $object_id ) ) ); update_user_meta( $user_id, '_ansico_liked_posts', $liked ); $count = max( 0, ansico_get_like_count( 'post', $object_id ) - 1 ); update_post_meta( $object_id, '_ansico_like_count', $count ); return array( 'liked' => false, 'count' => $count ); } $liked[] = $object_id; update_user_meta( $user_id, '_ansico_liked_posts', array_values( array_unique( array_map( 'intval', $liked ) ) ) ); $count = ansico_get_like_count( 'post', $object_id ) + 1; update_post_meta( $object_id, '_ansico_like_count', $count ); return array( 'liked' => true, 'count' => $count ); } function ansico_render_like_button( $object_type, $object_id, $extra_classes = '' ) { $object_id = intval( $object_id ); if ( $object_id < 1 ) { return ''; } $count = ansico_get_like_count( $object_type, $object_id ); $is_logged_in = is_user_logged_in(); $has_liked = $is_logged_in ? ansico_user_has_liked( $object_type, $object_id ) : false; $classes = trim( 'ansico-action-btn ansico-like-btn ' . $extra_classes . ( $has_liked ? ' is-liked' : '' ) ); $disabled_attr = $is_logged_in ? '' : ' disabled aria-disabled="true" tabindex="-1"'; $title = $is_logged_in ? ( $has_liked ? 'Fjern like' : 'Like' ) : 'Log ind for at like'; return ''; } function ansico_get_tweet_html($author_id, $text, $time_str, $source_url, $embed_data = null, $post_id = 0) { $name = get_the_author_meta( 'display_name', $author_id ); $avatar = get_avatar_url( $author_id, array( 'size' => 50 ) ); if (!$embed_data) { preg_match('/(?{}\[\]]+))/i', $text, $matches); if ($matches) { $embed_data = ansico_fetch_metadata_internal($matches[0]); } } $time_display = $time_str; if ( strtotime($time_str) ) { $ts = strtotime($time_str); $time_display = wp_date(get_option('date_format'), $ts) . ' · ' . wp_date(get_option('time_format'), $ts); } $text = ansico_apply_micropost_text_formatting( $text ); $comment_count = $post_id ? get_comments_number($post_id) : 0; $permalink = $post_id ? get_permalink($post_id) : $source_url; $like_button = $post_id ? ansico_render_like_button( 'post', $post_id ) : ''; $is_federated = $post_id ? ansico_is_micropost_federated( $post_id ) : false; ob_start(); ?>
| Profilbillede |
|---|
| '; echo ' | ';
echo ' ';
echo '';
echo '';
echo ' ';
echo ' | ';
echo '
|---|