We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7923
    • 4,213 Posts
    Events for the document saving is OnBeforeDocFormSave and OnDocFormSave.

    I’m still not quite sure what you mean that when that TV value should be changed.. each time when the document is requested or on save or when? and what’s the use of that TV..?


      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
      • 6316
      • 92 Posts
      I’ll try to explain myself. My plugin should create a topic in phpBB for comments. I’d use Jot, but I don’t want my visitors to have two accounts on one site.

      For example, I write a news item, by creating a document in MODx. After writing the text, under "Template variables" I set "Create a discussion in phpBB?" to "yes". Under it, there is another TV, "The ID of the topic in phpBB", which I shouldn’t fill. When I save the document, the plugin should create a topic in my phpBB forum and write an ID of the newly created topic to "The ID of the topic in phpBB" TV of the document. This is required for creating links in the document to the topic. And that is what I’m asking about.
        • 7923
        • 4,213 Posts
        Ok, then use OnDocFormSave event, so that the document is already saved to the database when your plugin get’s run. Then use the event params to see if it’s a new document. If it’s a new document, create the new topic in the forums and use for example Docmanager to save the topic id to the TV.
        So something like:

        $e = &$modx->Event;
        if ($e->name == ’OnDocFormSave’)
        {
        if($modx->event->params[’mode’] == ’new’) {
        // create the topic to the forums and get the topic id to a $topicId variable
        require_once(’assets/libs/docmanager/document.class.inc.php’);
        $doc = new Document($modx->event->params[’id’]);
        $doc->SetTV(’topicId’, $topicId);
        $doc->Save();
        }
        }


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 6316
          • 92 Posts
          Thanks, this code almost works. "Almost" because it gives me a bunch of errors after posting a new page.

          I tryed to figure out what exactly gives this error. I changed back to my old code, which worked. Here it is
          define ('IN_PHPBB', true);
          define ('IN_MODX', true);
          include_once ('/home/login/public_html/dev/assets/plugins/phpbbcomments.php');
          
          $e = &$modx->Event;
          
          switch($e->name) {
          	case 'OnWebPagePrerender':
          		$postdetails = insert_post("test message", "test subject", 57, 116, "Admin", 1);
          	break;
          	
          	default :
          		return;
          	break;
          }

          but when I change event OnDocFormSave or use your code, it gives me a lot of errors
          Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 86
          Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 89
          Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 102
          Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 122
          Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 132
          Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 144
          Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 160
          Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 180
          Couldn't determine next publish event!
          Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 226
          Couldn't determine next unpublish event!
          Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php on line 236
          Warning: Cannot modify header information - headers already sent by (output started at /home/login/public_html/dev/manager/processors/cache_sync.class.processor.php:86) in /home/login/public_html/dev/manager/processors/save_content.processor.php on line 330
            • 6316
            • 92 Posts
            Also it turns off CSS in my manager, even when I close browser and re-open. CSS turns on when I disable the plugin.

            If I remove that include_once of phpBB file and the insert_post, everything works. So, there is a conflict between phpBB inserting function and MODx undecided
              • 7923
              • 4,213 Posts
              Have you tried what I posted without the docmanager parts of it? Just try to create that new topic first..


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 6316
                • 92 Posts
                The topic creates, but modx shows me these errors after creating a new document and disables CSS in its manager.

                It’s a conflict between two cores of phpBB and modx, I believe

                I wonder is there any way for a plugin to call the script that would add a topic, instead of including the code itself?
                  • 6316
                  • 92 Posts
                  I almost got it working! Ugly way though, but it works! grin
                    • 6316
                    • 92 Posts
                    Could anyone tell me, how do I access [+pagetitle+] there?
                      • 7923
                      • 4,213 Posts
                      $modx->documentObject[’pagetitle’]

                      EDIT: Sorry, that may not work after all, this should work:

                      $modx->getDocument($modx->event->params[’docid’])[’pagetitle’];


                        "He can have a lollipop any time he wants to. That's what it means to be a programmer."