hawkwang / zhaole365

1 stars 0 forks source link

TBD #2

Open hawkwang opened 9 years ago

hawkwang commented 9 years ago
hawkwang commented 9 years ago

提示信息显示

在PHP中, OW::getFeedback()->info(message);

OW::getFeedback()->error(message);

在js中, OW.error(message);

构造url

1)使用controller、action和参数 $deleteUrl = OW::getRouter()->urlFor('ZLGROUPS_CTRL_Groups', 'delete', array('groupId' => $groupDto->id));

2)route名称和参数 $url = OW::getRouter()->urlForRoute('groups-customize', array('mode' => 'customize', 'groupId' => $groupId))

3)在html中,see admin_additional.htm {capture assign='onclick'}window.location.href='{url_for for="ZLGROUPS_CTRL_Admin:connect_forum"}?isForumConnected=yes'{/capture} {decorator name='button' type='button' id='btn-connect-forum' langLabel='forum+connect_forum_button' class='ow_ic_add' onclick=$onclick }

4)在 action中, see group.php $js = UTIL_JsGenerator::newInstance(); $js->newFunction('window.location.href=url', array('url'), 'redirect'); $js->jQueryEvent('#zlgroups-delete_btn', 'click', UTIL_JsGenerator::composeJsString( 'if( confirm({$lang}) ) redirect({$url});', array('url' => $deleteUrl, 'lang' => $lang))); $js->jQueryEvent('#groups-back_btn', 'click', UTIL_JsGenerator::composeJsString( 'redirect({$url});', array('url' => $viewUrl))); OW::getDocument()->addOnloadScript($js);

创建页面内菜单项 参见ZLGROUPS_CTRL_Groups的getGroupListMenu()方法

hawkwang commented 9 years ago

HOW-TO:如何开发一个插件?

定义plugin.xml

plugin使用顺序:安装(install.php)、激活(activate.php)、初始化(init.php)、应用

(1) 应用的前提: 1)datastore related parts (files under folder bol) 创建entity、entity_dao、service 2)component (files under components, views/components) 3)widget (files under components, views/components) 4)controller, action and view (files under controllers, views/controllers) 5)event hander (event_handler.php under folder classes) 6)console bridge (console_bridge.php under folder classes) 7)etc. (other files under folder classes)

(2) install.php : 1)在install.php中创建表脚本和执行

2)在install.php中添加widget,并指定其在插件place的位置

3)在install.php 中设置语言包 BOL_LanguageService::getInstance()->importPrefixFromZip($plugin->getRootDir() . 'langs.zip', 'zlgroups');

4)设置访问权限 $authorization = OW::getAuthorization(); $groupName = 'zlgroups'; $authorization->addGroup($groupName);

$authorization->addAction($groupName, 'add_comment'); $authorization->addAction($groupName, 'create'); $authorization->addAction($groupName, 'view', true);

5)其他关联配置信息的设置

(3) activate.php : 1)设置插件的菜单入口(可选) 2)添加准备在其他插件页面上显示的本插件widget(如没有则不需要),并将其设置在对应位置上 3)fire install_widget event related to feed, forum或其他插件

(4) init.php 1)在init.php中设置route (admin 和 action) 2)在init.php中设置event handler关联

取消激活调用(deactivate.php)-将activate.php中的操作逆处理

1)删除插件的菜单入口(可选) 2)删除widget位置,删除widget

卸载流程(不仅仅是uninstall.php)

1)用户点击“卸载”则触发admin/plugins/xyzplugin/uninstall,对应route在init.php中调用(相应action - uninstall在admin.php中定义,相应view也需要创建)

2)在uninstall action中设置卸载和系统正在维护标识 $config->saveConfig('zlgroups', 'uninstall_inprogress', 1); OW::getApplication()->setMaintenanceMode(true);

3)定时器任务定时检查并完成删除插件自身相关数据内容,在验证已经完成数据删除后,则调用 BOL_PluginService::getInstance()->uninstall('xyzplugin'); 和去除卸载和系统维护标识 $config->saveConfig('xyzplugin', 'uninstall_inprogress', 0); OW::getApplication()->setMaintenanceMode(false);

4)BOL_PluginService::getInstance()->uninstall('xyzplugin')操作会调用插件的deactivate.php文件

5)BOL_PluginService::getInstance()->uninstall('xyzplugin')操作会调用插件的uninstall.php文件 5.1)删除所有安装的widget place和widget 5.2)相关插件所产生的相关内容,如forum等 5.3)删除base_place表中插件对应项 $dbPrefix = OW_DB_PREFIX; $sql = <<<EOT DELETE FROM {$dbPrefix}base_place WHERE name='zlgroup'; EOT; OW::getDbo()->query($sql);

6)BOL_PluginService::getInstance()->uninstall('xyzplugin')会负责删除 6.1)删除插件相关工作目录 6.2)删除插件相关配置 6.3)删除插件语言prefix 6.4)删除权限相关信息 6.5)删除相关table删除 6.6)删除插件本身(数据库插件表中纪录)

定时器(cron.php)

1)完成定时需要完成的功能 2)完成卸载操作 较好的例子参见photo插件

hawkwang commented 9 years ago

定制每个乐群的布局 http://class1.local/zhaole365/groups/1/customize

hawkwang commented 9 years ago

HOW-TO:newsfeed如何使用?

待完善 相关数据表: wx_newsfeed_action
wx_newsfeed_action_feed
wx_newsfeed_action_set
wx_newsfeed_activity
wx_newsfeed_cron_command
wx_newsfeed_follow
wx_newsfeed_like
wx_newsfeed_status

hawkwang commented 9 years ago

HOW-TO: 事件处理机制

1) fire and get updated data $event = new OW_Event(self::EVENT_USER_BEFORE_ADDED, array( 'groupId' => $groupId, 'userId' => $userId ), $data);

    OW::getEventManager()->trigger($event);
    $data = $event->getData();

2) use event handler to deal with event, and update event data public function onBeforeUserJoin( OW_Event $event ) { $data = $event->getData(); $params = $event->getParams();

    $userId = (int) $params['userId'];
    $privacy = ZLGROUPS_BOL_Service::PRIVACY_EVERYBODY;

    $t = OW::getEventManager()->call('plugin.privacy.get_privacy', array(
        'ownerId' => $params['userId'],
        'action' => ZLGROUPS_BOL_Service::PRIVACY_ACTION_VIEW_MY_GROUPS
    ));

    $data['privacy'] = empty($t) ? $privacy : $t;

    $event->setData($data);
}

trigger()和call()的区别?

trigger 是广而告知 call 是直接调用

hawkwang commented 9 years ago

HOW-TO:flag

用于举报

hawkwang commented 9 years ago

HOW-TO:在php中动态创建js

class UTIL_JsGenerator 参见 ow_utilities/js_generator.php 例子: - 创建实例 $jsResponse = UTIL_JsGenerator::newInstance();

- 创建调用函数的脚本 $jsResponse->callFunction(array('OW', 'info'), array( OW::getLanguage()->text('zlgroups', 'join_complete_message') ));

-创建js新函数,例如,redirect $js->newFunction('window.location.href=url', array('url'), 'redirect');

-创建jquery事件处理绑定代码 $js->jQueryEvent('#zlgroups-delete_btn', 'click', UTIL_JsGenerator::composeJsString( 'if( confirm({$lang}) ) redirect({$url});', array('url' => $deleteUrl, 'lang' => $lang)));

-创建脚本初始化代码 OW::getDocument()->addOnloadScript($js);

-创建脚本并初始化 $js = UTIL_JsGenerator::newInstance(); $js->addScript('OW.Invitation = new OW_Invitation({$key}, {$params});', array( 'key' => $this->getKey(), 'params' => array( 'rsp' => OW::getRouter()->urlFor('BASE_CTRL_Invitation', 'ajax') ) )); OW::getDocument()->addOnloadScript($js);

hawkwang commented 9 years ago

HOW-TO:notification机制?

    $notificationParams = array(
        'pluginKey' => 'zlgroups',
        'action' => 'zlgroups-add_comment',
        'entityType' => $params['entityType'],
        'entityId' => $params['entityId'],
        'userId' => null,
        'time' => time()
    );

    $notificationData = array(
        'string' => array(
            'key' => 'zlgroups+email_notification_comment',
            'vars' => array(
                'userName' => $avatar['title'],
                'userUrl' => $avatar['url'],
                'url' => $groupUrl,
                'title' => $groupTitle
            )
        ),
        'avatar' => $avatar,
        'content' => $comment->getMessage(),
        'contentImage' => $groupImage
    );
    $userIds = ZLGROUPS_BOL_Service::getInstance()->findGroupUserIdList($group->id);

    foreach ( $userIds as $uid )
    {
        if ( $uid == $userId )
        {
            continue;
        }

        $notificationParams['userId'] = $uid;

        $event = new OW_Event('notifications.add', $notificationParams, $notificationData);
        OW::getEventManager()->trigger($event);
    }
hawkwang commented 9 years ago

HOW-TO: OW_Authorization 机制

// 设置访问权限
$authorization = OW::getAuthorization();
$groupName = 'zlgroups';
$authorization->addGroup($groupName);

$authorization->addAction($groupName, 'add_comment');
$authorization->addAction($groupName, 'create');
$authorization->addAction($groupName, 'view', true);
hawkwang commented 9 years ago

HOW-TO: 如何controller Class命名? 如何给其文件命名?

class naming rule: CTRL file naming rule: controllername.php 如果Controllername中含有大写,如HelloHawk,则文件名为hello_hawk.php

HOW-TO: 如何component、widget Class命名? 如何给其文件命名?

与controller类似

HOW-TO: 如何显示地设置view template?

在action代码前部写入: $templatePath = OW::getPluginManager()->getPlugin('zlgroups')->getCtrlViewDir() . 'groups_list.html'; $this->setTemplate($templatePath);

HOW-TO: 如何给controller的action设置缺省的view file name?

1)view文件前缀:取controller class最后一个“”后的字串取出,如其中有大写字母,则小写并在其前加一个“”. 例如: ZLGROUPS_CTRLGroups 得到前缀为 groups 2)后缀:取action字串,如其中有大写字母,则小写并在其前加一个“”. 例如:ZLGROUPS_CTRL_Groups中的create和userList action,则后缀分别为create和userlist。 3)将前缀和后缀用“”连接,以“.html”结尾形成对应的view的文件名 例如,这里对应的view文件名为 groups_create.html 和 groups_user_list.html。

HOW-TO: 如何给component、widget设置缺省的view file name?

将相应的类文件后缀换为.html即可。

hawkwang commented 9 years ago

HOW-TO: 如何动态创建并添加stye

例如,如何将下面的style添加到当前的action view中? .ow_searchbar_btn { background-position: right 5px; background-repeat: no-repeat; display: inline-block; height: 24px; vertical-align: middle; width: 24px; }

    $style = ".ow_searchbar_btn {
                    background-position: right 5px;
                    background-repeat: no-repeat;
                    display: inline-block;
                    height: 24px;
                    vertical-align: middle;
                    width: 24px;
                }

              .ow_searchbar_input {
                    margin-right: -30px; 
                    width:100%;
               }
            ";
    OW::getDocument()->addStyleDeclaration($style);
hawkwang commented 9 years ago

add_content - 提供了一种hook机制(显示扩展机制),允许响应add_content指定的事件以扩展显示内容

1)用在view中提供: {add_content key='zlevents.content.view.top' eventId=$info.id}

2)任何希望在此部分提供内容显示的插件都可以绑定事件zlevents.content.view.top的event handler;在其中构造显示内容,并更新event的数据,参见:HOW-TO: 事件处理机制

hawkwang commented 9 years ago

HOW-TO: block_decorator 机制

1)在view中提供: {block_decorator name='box' type='empty' iconClass='ow_ic_picture' langLabel='zlevent+view_page_image_block_cap_label' addClass="ow_std_margin clearfix"} {if !empty($info.image)}{/if}{$info.desc} {/block_decorator} 可以看出,有几个参数: name, type等;之间为content,此处为 {if !empty($info.image)}{/if}{$info.desc}

2)系统提供的decorator可以在如下目录下找到: ow_system_plugins/base/decorators/ 以box.html为例,

{if $data.capEnabled}
<div class="ow_box_cap{$data.capAddClass}">
    <div class="ow_box_cap_right">
        <div class="ow_box_cap_body">
            <h3 class="{$data.iconClass}">{$data.label}</h3>{$data.capContent}
        </div>
    </div>
</div>
{/if}
<div class="ow_box{$data.addClass} ow_break_word"{if !empty($data.style)} style="{$data.style}"{/if}>
{$data.content}
{if !empty($data.toolbar)}
    <div class="ow_box_toolbar_cont clearfix">
    {decorator name='box_toolbar' itemList=$data.toolbar}
    </div>
{/if}
{if empty( $data.type )}
    <div class="ow_box_bottom_left"></div>
    <div class="ow_box_bottom_right"></div>
    <div class="ow_box_bottom_body"></div>
    <div class="ow_box_bottom_shadow"></div>
{/if}
</div>

可以看出,参数以$data.xyz形式出现;

3)用户可以定义自己的decorator模板,放置在自定义theme/decorators/目录下

hawkwang commented 9 years ago

HOW-TO: 菜单机制

激活菜单项显示 OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'zlevent', 'main_menu_item');

NikolasViv commented 9 years ago

好了,不好意思汪老师,打扰了,我继续看。

在 2014-11-14 11:03:31,"lixiaodong" helloing_world@163.com 写道: 汪老师,目前遇到一点问题,,经过install的plugin,经language机制,定义的key,可以显示,但是经controller和view写的页面不能显示,查了一天没整出来,controller和view的名字好像没有错误,我再看看。

在 2014-11-14 10:53:56,"Hawk" notifications@github.com 写道:

HOW-TO: 菜单机制

激活菜单项显示 OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'zlevent', 'main_menu_item');

— Reply to this email directly or view it on GitHub.

hawkwang commented 9 years ago

HOW-TO: 创建toolbar按钮

- 创建toolbar按钮,使用js相应。 $userId = (int) $params['userId'];

    $callbackUrl = OW::getRouter()->urlFor('BASE_CTRL_User', 'userDeleted');

    $linkId = 'ud' . rand(10, 1000000);
    $script = UTIL_JsGenerator::newInstance()->jQueryEvent('#' . $linkId, 'click', 'OW.Users.deleteUser(e.data.userId, e.data.callbackUrl, false);'
        , array('e'), array('userId' => $userId, 'callbackUrl' => $callbackUrl));

    OW::getDocument()->addOnloadScript($script);

    $resultArray = array(
        BASE_CMP_ProfileActionToolbar::DATA_KEY_LABEL => OW::getLanguage()->text('base', 'profile_toolbar_user_delete_label'),
        BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_CLASS => 'ow_mild_red',
        BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_HREF => 'javascript://',
        BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_ID => $linkId,
        BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_GROUP_KEY => 'base.moderation',
        BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_GROUP_LABEL => OW::getLanguage()->text('base', 'profile_toolbar_group_moderation'),
        BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_ORDER => 5,
        BASE_CMP_ProfileActionToolbar::DATA_KEY_ITEM_KEY => "base.delete_user"
    );

    $event->add($resultArray);

- 创建toolbar按钮,使用url相应。 $action = array( BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_GROUP_KEY => 'base.moderation', BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_GROUP_LABEL => OW::getLanguage()->text('base', 'profile_toolbar_group_moderation'), BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_HREF => OW::getRouter()->urlFor('BASE_CTRL_User', 'approve', array('userId' => $userId)), BASE_CMP_ProfileActionToolbar::DATA_KEY_LABEL => OW::getLanguage()->text('base', 'profile_toolbar_user_approve_label'), BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_CLASS => 'ow_mild_green', BASE_CMP_ProfileActionToolbar::DATA_KEY_ITEM_KEY => "base.approve_user" );

    $event->add($action);