Jump to content

Is the ipsRegistry.php code only available for use inside the forum software?

Featured Replies

Posted

http://www.invisionpower.com/support/guides/_/advanced-and-developers/miscellaneous/check-if-a-member-is-logged-in-r91

Basically I'm needing a way to check if the user is logged in on the site end outside the forums. MyBB had a way to do this where you looked at a public login string that was cookied and compared it against a private string in the database, but I'm not sure if IPB does things the same way.

I found the above guide, but when I call the ipsRegistry.php bit it automatically redirects me to the forums. Is this by design, i.e. this code is only usable in a plugin?

No. The following is a simple example to list topics:

<?php

    $forum_path = 'forum'; //FORUM FOLDER
    chdir( $forum_path );

    define( 'IPB_THIS_SCRIPT', 'public' );

    require_once( $forum_path . '/initdata.php' );
    require_once( IPS_ROOT_PATH . 'sources/base/ipsRegistry.php' );
    require_once( IPS_ROOT_PATH . 'sources/base/ipsController.php' );

    $ipbRegistry    = ipsRegistry::instance();
    $ipbRegistry->init();

    /* Init */
    if ( ! $ipbRegistry->isClassLoaded('topics') )
    {
        $classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir( 'forums' ) . "/sources/classes/topics.php", 'app_forums_classes_topics', 'forums' );
        $ipbRegistry->setClass( 'topics', new $classToLoad( $ipbRegistry ) );
    }
    
    $topic = $ipbRegistry->getClass('topics')->getTopicById( mt_rand (1, 10000 ) ); //CHANGE THAT NUMBER

    echo '<b>.: A RANDOM TOPIC :.<br /><br />' . $topic['title'] . '</b><br />Created by ' . $topic['starter_name'] . ' at ' . date( 'd/m/Y - H:i', $topic['start_date'] );
    
    echo '<br /><br />';
    echo '<b>.: LATEST 10 TOPICS :.</b><br /><br />';

    $topics = $ipbRegistry->getClass('topics')->getTopics( array(
                                                    'forumId'         => XXX,
                                                    'topicType'        => 'visible',
                                                    'getFirstPost'  => false,
                                                    'sortField'     => 'start_date',
                                                    'sortOrder'        => 'desc',
                                                    'limit'         => 10
    ) );

    foreach( $topics as $pid => $topic )
    {
        echo '<b>' . $topic['title'] . '</b><br />Created by ' . $topic['starter_name'] . ' at ' . date( 'd/m/Y - H:i', $topic['start_date'] ) . '<br />';
    }
?>

Or create a new account on your board:

<?php

    $forum_path = 'forum'; //FORUM FOLDER
    chdir( $forum_path );
    
    define( 'IPB_THIS_SCRIPT', 'public' );
    
    require_once( $forum_path . '/initdata.php' );
    require_once( IPS_ROOT_PATH . 'sources/base/ipsRegistry.php' );
    require_once( IPS_ROOT_PATH . 'sources/base/ipsController.php' );
    
    $ipbRegistry    = ipsRegistry::instance();
    $ipbRegistry->init();
    
    $email = 'testeapi@sosinvision.com.br';
    $name = 'Testing the API';
    $pass = mt_rand();
    
    IPSMember::create( array(
                            'members'            => array(
                                                 'email'                    => $email,
                                                 'name'                        => $name,
                                                 'members_l_username'        => strtolower($name),
                                                 'members_display_name'        => $name,
                                                 'members_l_display_name'    => strtolower($name),
                                                 'joined'                    => time(),
                                                 'password'                    => $pass,
                                                        ),
                            'profile_portal'    => array(
                                                        ),
                            'pfields_content'    => array(
                                                        ),
    ) );
    
    echo "New user added! Password ".$pass;

?>
  • Author

Hmm, the moment that init() code runs is when I get auto-redirected to the forums.

Not sure if it helps, but right now the development site (that's outside the forums) is in a password protected folder. The new forums which we haven't replaced with the old ones is also in a password protected folder.

Basically what happens is that http://dev.testsite.com gets redirected to http://www.testsite.com/forums2 right after the init() call is made.

There's a constant you can set to prevent any redirection, however you should post your inquiry in a peer support forum. This forum is primarily intended for feedback about the software itself. :)

  • 3 months later...

The content of the first post might be no feedback, but he indirectly states that the documentation is insufficient for him. That is for me too.

I'd try to use the example in this guide (and this thread) in order to post content outside the forum, but all I get is error (500/404). It seems to miss a certain wrapper/context which I did not succeed to find.

/* I know the code below is no good and not very smart. I just want to
 * show the lack of documentation for me as a beginner in IPB scripting.
 */


//define('IN_IPB', 1);
define("IPB_THIS_SCRIPT","public");
define("ALLOW_FURLS",FALSE);
define("IPS_ENFORCE_ACCESS",TRUE);
require_once("../../../initdata.php");
require_once(IPS_ROOT_PATH."sources/base/ipsRegistry.php");
require_once(IPS_ROOT_PATH."sources/base/ipsController.php");
//ipsController::run();
$registry = ipsRegistry::instance();
$registry->init();

ipsRegistry::getAppClass('forums');

$classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir('forums') . '/sources/classes/post/classpost.php', 'classPost', 'forums' );
$classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir('forums') . '/sources/classes/post/classpostforms.php', 'classPostForms', 'forums' );
$this->post = new $classToLoad( $this->registry );

try {
    $this->post->setBypassPermissionCheck(true);
    $this->post->setIsAjax(false);
    $this->post->setPublished(true);
    $this->post->setForumID(157);
    $this->post->setAuthor(IPSMember::load(54635));
    $this->post->setPostContentPreFormatted("tekst");
    $this->post->setTopicTitle("Test");
    $this->post->setSettings(array('enableSignature'=>1,'enableEmoticons'=>1,'post_htmlstatus'=>0));
    
    if($this->post->addTopic() === false) {
        print_r($this->post->getPostError());
        return false;
    }
    $topic = $this->post->getTopicData();
} catch (Exception $e) {
    print $e->getMessage();
    return false;
}

Archived

This topic is now archived and is closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.