【问题标题】:Profile Views OSSN配置文件视图 OSSN
【发布时间】:2019-04-01 16:10:23
【问题描述】:

大家好,我目前正在尝试构建 OSSN 的一个组件,即个人资料视图,因为该组件向您展示了哪些用户查看了您的个人资料。我正在尝试通过指向“个人资料查看者”的链接显示查看您帐户的查看者数量。我绝不是一个流利的编码器,但我已经分解了代码并发现了在显示结果时可能有用的东西。

在一个组件中,需要两个文件才能工作。一是注册语言。

    <?php
/**
 * Open Source Social Network
 *
 * @package   (softlab24.com).ossn
 * @author    OSSN Core Team <info@softlab24.com>
 * @copyright 2014-2017 SOFTLAB24 LIMITED
 * @license   General Public Licence http://www.opensource-socialnetwork.org/licence
 * @link      https://www.opensource-socialnetwork.org/
 */

$en = array(
    'profileviews' => 'Profile Views:' . '<b>&nbsp'. $count . '</b>',
);

ossn_register_languages('en', $en); 

另一个是传递给系统的函数。

<?php
/**
 * Open Source Social Network
 *
 * @packageOpen Source Social Network
 * @author    Open Social Website Core Team <info@informatikon.com>
 * @copyright 2014 iNFORMATIKON TECHNOLOGIES
 * @license   General Public Licence http://www.opensource-socialnetwork.org/licence
 * @link      http://www.opensource-socialnetwork.org/licence
 */

define("__who_view_profile_type__", 'profile:viewed');


function who_viewed_my_profile_init() {
        if(ossn_isLoggedin()) {
                ossn_register_callback('page', 'load:profile', 'who_viewed_my_profile', 'ossn_relationships');
                ossn_register_page('profileviews', 'profileviews');
                ossn_register_sections_menu('newsfeed', array(
                        'name' => 'profileviews' . '<b>&nbsp'. $count . '</b>',
                        'text' => ossn_print('profileviews'), 
                        'url' => ossn_site_url('profileviews'),
                        'parent' => 'links',
                        'icon' => true

                ));

        }

}


function profileviews() {
        $looks = ossn_get_relationships(array(
                'to' => ossn_loggedin_user()->guid,
                'type' => __who_view_profile_type__
        ));

        $count = ossn_get_relationships(array(
                'to' => ossn_loggedin_user()->guid,
                'type' => __who_view_profile_type__,
                'count' => true

        ));

        if($looks) {
                foreach($looks as $item) {
                        $user = ossn_user_by_guid($item->relation_from);
                        if($user) {
                                $users[] = $user;
                        }
                }
        }

        $vars['users']     = $users;
        $vars['icon_size'] = 'small';

        $lists = "<div class='ossn-page-contents'>" .  $count;
        $lists .= "<p><strong>" . ossn_print('profileviews') . "</strong></p> ";
        $lists .= ossn_plugin_view("output/users_list", $vars);
        $lists .= ossn_view_pagination($count);
        $lists .= "</div>";

        $contents = array(
                'content' => $lists
        );
        $content  = ossn_set_page_layout('newsfeed', $contents, $count);
        echo ossn_view_page($title, $content);

}
function who_viewed_my_profile() {
        $profile = ossn_user_by_guid(ossn_get_page_owner_guid());
        $user    = ossn_loggedin_user();
        if(!$profile || !$user) {
                return false;
        }
        if(!ossn_relation_exists($profile->guid, $user->guid, __who_view_profile_type__)) {
                ossn_add_relation($profile->guid, $user->guid, __who_view_profile_type__);
        }
}



ossn_register_callback('ossn', 'init', 'who_viewed_my_profile_init');

据我所知,函数function profileviews() 包含我需要显示的视图数量。该数组说明有多少用户查看了配置文件。

$count = ossn_get_relationships(array(
                'to' => ossn_loggedin_user()->guid,
                'type' => __who_view_profile_type__,
                'count' => true

        ));

我的问题是当我尝试调用函数时,我的主页是空白的。然而它适用于实际的用户页面。空白页显示没有错误。

“发生系统错误。请稍后再试。您可以通过电子邮件将此错误的详细信息通过电子邮件发送给系统管理员”

也许我调用了错误的函数?

ossn_register_callback('ossn', 'init', 'who_viewed_my_profile_init', 'profileviews');

【问题讨论】:

    标签: php oop pdo


    【解决方案1】:

    属性可以传递给ossn_print函数

    function who_viewed_my_profile_init() {
            if(ossn_isLoggedin()) {
                $count = ossn_get_relationships(array(
                    'to' => ossn_loggedin_user()->guid,
                    'type' => __who_view_profile_type__,
                    'count' => true
    
                   ));
                   ........
                   ........
                    ossn_register_sections_menu('newsfeed', array(
                            'name' => 'profileviews',
                            'text' => ossn_print('profileviews', array($count)), 
                            ......
    
                    ));
    
            }
    
    }
    

    然后在语言文件中:

    <?php
    
    /**
     * Open Source Social Network
     *
     * @package   (softlab24.com).ossn
     * @author    OSSN Core Team <info@softlab24.com>
     * @copyright 2014-2017 SOFTLAB24 LIMITED
     * @license   General Public Licence http://www.opensource-socialnetwork.org/licence
     * @link      https://www.opensource-socialnetwork.org/
     */
    
    $en = array(
        'profileviews' => 'Profile Views: <b>%s</b>',
    );
    
    ossn_register_languages('en', $en);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      • 1970-01-01
      • 2018-03-15
      • 2020-07-16
      • 1970-01-01
      相关资源
      最近更新 更多