Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 General Discussions
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2017, 06:24 AM
userform3 userform3 is offline
 
Join Date: Jul 2010
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default New extension, does not work!

Hi,

In forum, vbulletin version 5.2.5, I would like to create a new extension.

To the facts, the forum is only accessible to registered users, if a user is not registered, he can see the forum, not.
If the user is registered, his real first name and last name should be displayed.
These data are located in a separate table in the forum database and must be read out additionally.

To implement this, we introduced a new product in the area "Products & Hooks" in "Manage Products" with the name "klarnamenIntern".
A new add-on was created in "Manage Hooks". To test with "klarnamen".
In the directory .../forum5/core/packages/klarnamenIntern the following directories with files were created:

HTML Code:
klarnamenIntern/api/site.php
klarnamenIntern/xml/product_klarname.xml
product.php
Unfortunately, I can not access the forum data via the procedure described above.
That is, About the file klarnamenIntern/api/site.php I can not read posts from the forum.

What is the error or the causes why I can not access the data?
How can I access the PHP files klarnamenIntern/api/site.php from the forum or connect?

Example the file klarnamenIntern/api/site.php
PHP Code:
<?php if(!defined('VB_ENTRY')) die('Access denied.');

class Interred_Api_Site extends vB_Api_Extensions 
{
    protected $product = 'klarnamenIntern';
    protected $developer = 'die-user';
    protected $title = 'Global';
    protected $minver = '5.2.0';    
    protected $AutoInstall = 2;
    protected $extensionOrder = 10;
    
    function __construct () {
        $this->fetchThreads();
        
        // Only the default data is taken from the forum
        $forum = $this->do_get_forum();
        echo "<pre>forum:: " .print_r( $forum, true ). "</pre><hr>";        
    }
    
    public static function fetchThreads(){ 
        // Only user data, which is calling the forum!
        $userinfo = vB_Api::instance('user')->fetchUserInfo();
    }
    
    // ##########################################
    // From here, methods taken from another extension.
    
    public static function do_get_forum_data()
    {
        $cleaned = vB::getCleaner()->cleanArray($_REQUEST, array(
            'forumids' => vB_Cleaner::TYPE_STR,
        ));

        if (!isset($cleaned['forumids']) || strlen($cleaned['forumids']) == 0) {
            return array('forums' => array());
        }

        $forumids = explode(',', $cleaned['forumids']);

        $forum_data = array();

        foreach ($forumids AS $forumid) {
            $forum = self::fr_get_and_parse_forum($forumid);
            if($forum != null) {
                $forum_data[] = $forum;
            }
        }

        if(!empty($forum_data)) {
            return array('forums' => $forum_data);
        } else {
            return null;
        }
    }
    
    function fr_get_and_parse_forum($forumid, $foruminfo = false)
    {
        $userinfo = vB_Api::instance('user')->fetchUserInfo();
        $options = vB::get_datastore()->get_value('options');

        if(!$foruminfo) {
            $foruminfo = vB_Api::instance('node')->getFullContentforNodes(array($forumid));
            if (empty($foruminfo)) {
                return null;
            }
            $foruminfo = $foruminfo[0];
        }
        if(!$foruminfo) {
            return null;
        }

        $type = 'old';

        if ($options['threadmarking'] AND $userinfo['userid']) {
            $userlastvisit = (!empty($foruminfo['readtime']) ? $foruminfo['readtime'] : (vB::getRequest()->getTimeNow() - ($options['markinglimit'] * 86400)));
        } else {
            $lastvisit = vB5_Cookie::get('lastvisit', vB5_Cookie::TYPE_UINT);
            $forumview = fr_fetch_bbarray_cookie('channel_view', $foruminfo['nodeid']);

            //use which one produces the highest value, most likely cookie
            $userlastvisit = ($forumview > $lastvisit ? $forumview : $lastvisit);
        }

        if ($foruminfo['lastcontent'] AND $userlastvisit < $foruminfo['lastcontent']) {
            $type = 'new';
        } else {
            $type = 'old';
        }

        $out = array(
            'id' => $foruminfo['nodeid'],
            'new' => $type == 'new' ? true : false,
            'name' => html_entity_decode(strip_tags($foruminfo['title'])),
            'password' => false, // No forum passwords in vB5
        );

        $icon = self::fr_get_forum_icon($foruminfo['nodeid'], $foruminfo == 'new');
        if ($icon) {
            $out['icon'] = $icon;
        }

        if ($foruminfo['description'] != '') {
            $desc = strip_tags($foruminfo['description']);
            if (strlen($desc) > 0) {
                $out['desc'] = $desc;
            }
        }
        return $out;
    }
    
    function fr_get_forum_icon ($forumid, $shownew, $showlink=false)
    {
        $basedir = MCWD . '/icons/';

        $new = $old = $link = null;

        if (@file_exists($basedir . 'forum-default-new.png')) {
        $new = 'forum-default-new.png';
        if (@file_exists($basedir . 'forum-default-old.png')) {
            $old = 'forum-default-old.png';
        } else {
            $old = $new;
        }
        }
        if (@file_exists($basedir . 'forum-default-link.png')) {
        $link = 'forum-default-link.png';
        }

        if (@file_exists($basedir . 'forum-' . $forumid . '-new.png')) {
        $new = 'forum-' . $forumid . '-new.png';
        if (@file_exists($basedir . 'forum-' . $forumid . '-old.png')) {
            $old = 'forum-' . $forumid . '-old.png';
        } else {
            $old = $new;
        }
        }
        if (@file_exists($basedir . 'forum-' . $forumid . '-link.png')) {
        $link = 'forum-' . $forumid . '-link.png';
        }

        return ($showlink ? $link : ($shownew ? $new : $old));
    }
}
?>

greetings
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:50 PM.


Powered by vBulletin® Version 3.9.0 Beta 2
Copyright ©2000 - 2017, vBulletin Solutions Inc.