配置文件视图OSSN

时间:2018-10-28 16:05:33

标签: php oop pdo

大家好,我目前正在尝试构建OSSN组件“ Profile Views”,因为该组件可以向您显示哪些用户查看了您的个人资料。我正在尝试通过查看个人资料查看器的链接来获取查看者的数量,以查看他们如何显示您的帐户。我绝对不是流利的编码人员,但我将代码分开,发现在显示结果方面可能有用。

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

    <?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');

1 个答案:

答案 0 :(得分:0)

该属性可以传递给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);