• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Custom Widget System (CWS) Alpha 2

No permission to download

guiltar

Well-known member
#1
guiltar submitted a new resource:

Custom Widget System (CWS) - Allows to manage sidebar widgets just like notices

This is ALPHA version of Widget System.
Don't run it on live forums, just test it, please.

Requirements:
  • Template Modification System.
  • Install the addon twice to import widgets.
Features:
  • Conditions same as for notices (user_criteria and page_criteria).
  • Widgets extend ControllerPublic and are return ConrollerResponce_View.
  • Widgets use all methods of controller and template/container params.
  • Using built in user_criteria and page_criteria allowed to make...
Read more about this resource...
 

CFodder

Well-known member
#3
Installed, it appears to overwrite XFRocks Widget Framework, is this deliberate?

Bit more of an explanation of what this does and a basic guide, esp with regards to callbacks etc would be helpful.

Will say that just from the quick look I've had at this it looks very powerful and configurable and looking forward to seeing where this goes :).
 

guiltar

Well-known member
#4
Installed, it appears to overwrite XFRocks Widget Framework, is this deliberate?

Bit more of an explanation of what this does and a basic guide, esp with regards to callbacks etc would be helpful.

Will say that just from the quick look I've had at this it looks very powerful and configurable and looking forward to seeing where this goes :).
I have not tested them together but at least admin route 'widgets' will be rewrited.
There are not much widgets not, but it's enough for testing alpha.


I will add the basic guide and explanation a bit later when api will be stable.
Actually, this it works like notices. But:
  • Widget can belong to some add-on and can be exported/imported with it.
  • Widget has 'position'. For now I created Left and Right sidebars, but its extendable.
  • Widget has callback class and callback method.
A bit more about callback. Callback class extends CWS_ConrollerWidget_Abstract and has internal property _params which is the mix of containerParams and inner template Params. Using this property widgets may exchange by their params since it passed by refference in constructor. For example Online Stuff and Online Users need one parameter 'usersOnline'. One of them calculates it, another borrows it from the first. At home page nobody calculates it since it prepared in the index controller.

Callback method is similar to action in regular controller. Widget should return ResponseView (or Template object, or string).
These are examples of callbacks.

PHP:
<?php
 
class CWS_ControllerWidget_Default extends CWS_ControllerWidget_Abstract
{
    // The default sidebar generated by XenForo. We already have it in container data
    public function actionDefaultSidebar()
    {
        return !empty($this->_params['sidebar']) ? $this->_params['sidebar'] : '';
    }
 
    // Online Users
    public function actionOnlineUsers()
    {
        $visitor = XenForo_Visitor::getInstance();
 
        /* @var $sessionModel XenForo_Model_Session */
        $sessionModel = $this->getModelFromCache('XenForo_Model_Session');
 
        // Check if param is already calculated in controller or other widget
        $this->_params['onlineUsers'] = isset($this->_params['onlineUsers']) ? $this->_params['onlineUsers'] :
            $sessionModel->getSessionActivityQuickList(
                $visitor->toArray(),
                array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
                ($visitor['user_id'] ? $visitor->toArray() : null)
            );
 
        return $this->responseView('CWS_ViewWidget_Default', 'cws_widget_online_users', $this->_params);
    }
}
 

CFodder

Well-known member
#5
Thanks for your post and explanation.

Unfortunately I'm not a developers ... anything really ... so the callback explanation you've put up is waaaay over my head. The reason I asked, is when I tried adding a widget it asked for the callback and method ... so that is my bad, I should've just used the widgets you had already.

I do notice that when editing and then saving a widget it goes back to the home screen in the ACP ... a minor annoyance but thought I'd let you know :).
 

guiltar

Well-known member
#6
Thanks, I'll fix this incorrect redirect.

For now I've added only widgets from the homepage.
It's not enough for full blown widget system but enough for testing.
I will add more widgets later. Actually end-users don't need to create widgets.
They may use existing ones.

BTW, to import current widgets you should install addd-on twice.
 

guiltar

Well-known member
#8
The core seems to be almost done (last version on github).
Now going to start making more widgets.
So what widgets widgets are most necessary?
 

CFodder

Well-known member
#13
Still a conflict with XFRocks widget framework, when both are installed it will only show one set of widgets, even when selecting the different lists.
 

cclaerhout

Well-known member
#14
After a few hours to manipulate the alpha 4 on Github (published a few months ago), this addon should be a very good one. It needs a few patches to make it work on XenForo 1.2, but the possibilities for developers are great. Come back and "finish the job James" ! ;)