• Resolved beda69

    (@beda69)


    hello guys

    cool theme

    I like it most because of the @mention feature(s)

    Could you indicate me, which files I would have to include into my own (or child) theme, If i would like to include this feature into other themes too?

    Working with bootstrap self-built theme, but I am struggling with finding the files in your theme that implemented this functionality, even if you don’t have so much files in there ??

    appreciate any info!

    thank you

Viewing 7 replies - 1 through 7 (of 7 total)
  • This from the version 1.5.5 functions.php:

    class P2 {
    	/**
    	 * DB version.
    	 *
    	 * @var int
    	 */
    	var $db_version = 3;
    
    	/**
    	 * Options.
    	 *
    	 * @var array
    	 */
    	var $options = array();
    
    	/**
    	 * Option name in DB.
    	 *
    	 * @var string
    	 */
    	var $option_name = 'p2_manager';
    
    	/**
    	 * Components.
    	 *
    	 * @var array
    	 */
    	var $components = array();
    
    	/**
    	 * Includes and instantiates the various P2 components.
    	 */
    	function P2() {
    		// Fetch options
    		$this->options = get_option( $this->option_name );
    		if ( false === $this->options )
    			$this->options = array();
    
    		// Include the P2 components
    		$includes = array( 'compat', 'terms-in-comments', 'js-locale',
    			'mentions', 'search', 'js', 'options-page', 'widgets/recent-tags', 'widgets/recent-comments',
    			'list-creator' );
    
    		require_once( P2_INC_PATH . "/template-tags.php" );
    
    		// Logged-out/unprivileged users use the add_feed() + ::ajax_read() API rather than the /admin-ajax.php API
    		// current_user_can( 'read' ) should be equivalent to is_user_member_of_blog()
    		if ( defined( 'DOING_AJAX' ) && DOING_AJAX && ( p2_user_can_post() || current_user_can( 'read' ) ) )
    			$includes[] = 'ajax';
    
    		foreach ( $includes as $name ) {
    			require_once( P2_INC_PATH . "/$name.php" );
    		}
    
    		// Add the default P2 components
    		$this->add( 'mentions',             'P2_Mentions'             );
    		$this->add( 'search',               'P2_Search'               );
    		$this->add( 'post-list-creator',    'P2_Post_List_Creator'    );
    		$this->add( 'comment-list-creator', 'P2_Comment_List_Creator' );
    
    		// Bind actions
    		add_action( 'init',       array( &$this, 'init'             ) );
    		add_action( 'admin_init', array( &$this, 'maybe_upgrade_db' ), 5 );
    	}

    Thread Starter beda69

    (@beda69)

    thanks

    I saw that, but this is not what I need i guess.

    I see the “mentions” file is included in this, would it mean, I need to integrate ALL those files:
    ( ‘compat’, ‘terms-in-comments’, ‘js-locale’,
    ‘mentions’, ‘search’, ‘js’, ‘options-page’, ‘widgets/recent-tags’, ‘widgets/recent-comments’,
    ‘list-creator’ )
    or could I work just with the Mentions file?

    I will try… ??

    thanks for this (and more) info ??

    In your theme you probably need to create a class, something like class P2()

    And also create a function, something like function P2() but omit all parts except the “mentions” parts.

    You are welcome. please mark the topic resolved?

    Thread Starter beda69

    (@beda69)

    thanks

    I tried a “find by exclude” process, and as far aI see all JS folder files are quiet necessary + ca. 1/2 of the inc folder too.

    I was able to reduce your theme down to the essential functions mention by you above, but still it requires many js files to “work”

    will get there.

    A final one:

    I see it is not supported to “tag” users in POST BODY, even though you include “the_content” in the filter hook.

    Any reasons why only comments have the fancy “pop up” when start typing?

    AND

    Whats about email notifications on tagging?

    I am on MAMP therefore bit difficult to check if it gives me notifications on tag event.

    Perhaps you can enlighten me?

    then I will happily close this one and go ahead ??

    If you’re using p2 as a parent for your child, all the js and inc files will be there and available.

    For a new parent, To begin, I would just keep all of P2/js and all of P2/inc …

    Sorry, I can’t speak at all to the P2 functionality, it’s not mine. P2 is by Automattic, the same folks who operate WordPress.com. I would suspect P2 is authored by @matt himself.

    Anything more should be here I believe: https://www.ads-software.com/tags/p2?forum_id=5

    Thread Starter beda69

    (@beda69)

    OK; i thank you

    very nice your help.

    solved, will eventually present this in a tutorial once done

    Thread Starter beda69

    (@beda69)

    OK, here comes a partial “solution” to this

    I am working with bootstrap therefore some things might change from theme to theme…

    Include in your current themes functions.php at the very top this one:

    require_once( get_template_directory() . '/inc/utils.php' );
    
    p2_maybe_define( 'P2_INC_PATH', get_template_directory()     . '/inc' );
    p2_maybe_define( 'P2_INC_URL',  get_template_directory_uri() . '/inc' );
    p2_maybe_define( 'P2_JS_PATH',  get_template_directory()     . '/js'  );
    p2_maybe_define( 'P2_JS_URL',   get_template_directory_uri() . '/js'  );
    
    class P2 {
        /**
    	 * DB version.
    	 *
    	 * @var int
    	 */
        var $db_version = 3;
    
        /**
    	 * Options.
    	 *
    	 * @var array
    	 */
        var $options = array();
    
        /**
    	 * Option name in DB.
    	 *
    	 * @var string
    	 */
        var $option_name = 'p2_manager';
    
        /**
    	 * Components.
    	 *
    	 * @var array
    	 */
        var $components = array();
    
        /**
    	 * Includes and instantiates the various P2 components.
    	 */
        function P2() {
            // Fetch options
            $this->options = get_option( $this->option_name );
            if ( false === $this->options )
                $this->options = array();
    
            // Include the P2 components
            $includes = array( 'compat', 'terms-in-comments', 'js-locale',
                              'mentions', 'search', 'js', 'options-page', 'widgets/recent-tags', 'widgets/recent-comments',
                              'list-creator' );
    
            require_once( P2_INC_PATH . "/template-tags.php" );
    
            // Logged-out/unprivileged users use the add_feed() + ::ajax_read() API rather than the /admin-ajax.php API
            // current_user_can( 'read' ) should be equivalent to is_user_member_of_blog()
            if ( defined( 'DOING_AJAX' ) && DOING_AJAX && ( p2_user_can_post() || current_user_can( 'read' ) ) )
                $includes[] = 'ajax';
    
            foreach ( $includes as $name ) {
                require_once( P2_INC_PATH . "/$name.php" );
            }
    
            // Add the default P2 components
            $this->add( 'mentions',             'P2_Mentions'             );
            $this->add( 'search',               'P2_Search'               );
            $this->add( 'post-list-creator',    'P2_Post_List_Creator'    );
            $this->add( 'comment-list-creator', 'P2_Comment_List_Creator' );
    
            // Bind actions
            add_action( 'init',       array( &$this, 'init'             ) );
            add_action( 'admin_init', array( &$this, 'maybe_upgrade_db' ), 5 );
        }
    
        function init() {
    
        }
    
        function ajax_read() {
            if ( ! defined( 'DOING_AJAX' ) ) {
                define( 'DOING_AJAX', true );
            }
    
            require_once( P2_INC_PATH . '/ajax-read.php' );
    
            P2Ajax_Read::dispatch();
        }
    
        /**
    	 * Will upgrade the database if necessary.
    	 *
    	 * When upgrading, triggers actions:
    	 *    'p2_upgrade_db_version'
    	 *    'p2_upgrade_db_version_$number'
    	 *
    	 * Flushes rewrite rules automatically on upgrade.
    	 */
        function maybe_upgrade_db() {
            if ( ! isset( $this->options['db_version'] ) || $this->options['db_version'] < $this->db_version ) {
                $current_db_version = isset( $this->options['db_version'] ) ? $this->options['db_version'] : 0;
    
                do_action( 'p2_upgrade_db_version', $current_db_version );
                for ( ; $current_db_version <= $this->db_version; $current_db_version++ ) {
                    do_action( "p2_upgrade_db_version_$current_db_version" );
                }
    
                // Flush rewrite rules once, so callbacks don't have to.
                flush_rewrite_rules();
    
                $this->set_option( 'db_version', $this->db_version );
                $this->save_options();
            }
        }
    
        /**
    	 * COMPONENTS API
    	 */
        function add( $component, $class ) {
            $class = apply_filters( "p2_add_component_$component", $class );
            if ( class_exists( $class ) )
                $this->components[ $component ] = new $class();
        }
        function get( $component ) {
            return $this->components[ $component ];
        }
        function remove( $component ) {
            unset( $this->components[ $component ] );
        }
    
        /**
    	 * OPTIONS API
    	 */
        function get_option( $key ) {
            return isset( $this->options[ $key ] ) ? $this->options[ $key ] : null;
        }
        function set_option( $key, $value ) {
            return $this->options[ $key ] = $value;
        }
        function save_options() {
            update_option( $this->option_name, $this->options );
        }
    }
    
    $GLOBALS['p2'] = new P2;
    
    function p2_get( $component = '' ) {
        global $p2;
        return empty( $component ) ? $p2 : $p2->get( $component );
    }
    function p2_get_option( $key ) {
        return $GLOBALS['p2']->get_option( $key );
    }
    function p2_set_option( $key, $value ) {
        return $GLOBALS['p2']->set_option( $key, $value );
    }
    function p2_save_options() {
        return $GLOBALS['p2']->save_options();
    }

    then include the JS and INC folders in your Theme

    Remove from js/jquery.jeditable.js this one (otherwise your Bootstrap “Submit Comment” button breaks) :

    defaults: {
                    element : function(settings, original) {
                        var input = $('<input type="hidden"></input>');
                        $(this).append(input);
                        return(input);
                    },
                    content : function(string, settings, original) {
                        $(':input:first', this).val(string);
                    },
                    reset : function(settings, original) {
                      original.reset(this);
                    },
                    buttons : function(settings, original) {
                        var form = this;
                        if (settings.submit) {
                            /* if given html string use that */
                            if (settings.submit.match(/>$/)) {
                                var submit = $(settings.submit).click(function() {
                                    if (submit.attr("type") != "submit") {
                                        form.submit();
                                    }
                                });
                            /* otherwise use button with given string as text */
                            } else {
                                var submit = $('<button type="submit" />');
                                submit.html(settings.submit);
                            }
                            $(this).append(submit);
                        }
                        if (settings.cancel) {
                            /* if given html string use that */
                            if (settings.cancel.match(/>$/)) {
                                var cancel = $(settings.cancel);
                            /* otherwise use button with given string as text */
                            } else {
                                var cancel = $('<button type="cancel" />');
                                cancel.html(settings.cancel);
                            }
                            $(this).append(cancel);
    
                            $(cancel).click(function(event) {
                                //original.reset();
                                if ($.isFunction($.editable.types[settings.type].reset)) {
                                    var reset = $.editable.types[settings.type].reset;
                                } else {
                                    var reset = $.editable.types['defaults'].reset;
                                }
                                reset.apply(form, [settings, original]);
                                return false;
                            });
                        }
                    }
                },

    This works with a few glitches, which i’ll post next… just give me some time ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘@mentions – use for child / new theme’ is closed to new replies.