We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46886
    • 1,154 Posts
    Hi:

    First, I want to let you know I have hired someone to do this for me, and will put his solution here in the forums. I specifically asked him if it is ok to do so, not sure about the rights to the code actually. I planned to do this but didn't want to say until I was pretty sure he would do it, and right now he is just getting started. I told him I needed a flexible tool to grab lots of different info, and he will try to find a solution. I will let you know right away when he finishes, he works quick so it may not be long. Its just so important to make Discuss a viable solution. His idea is to make a plugin rather than just a script, let's see if he can do it...he is a bit of a wiz to be honest, so I am very hopeful.

    Now, for this issue. I went away from this as its not the most urgent for me and I got distracted by other issues. Right now I came back and put all my previous solutions into one page so I could see what was what.

    So, I just threw all my solutions into a page, at the bottom (https://www.rayxilawforums.com/experimental.html) and I don't have this problem of not being available on the front page, for any of them! I did before but not now, pls check for yourself. It works on front page and works without being logged in too. The guy is working now, on the top one, but I think he will leave the bottom two ones alone.

    I was messing with stuff before but couldn't tell you what I did anymore. So here is the solutions I have now:

    Left side [[!Discuss.Data]]

    <?php
    $discuss = $modx->getService('discuss','Discuss',$modx->getOption('discuss.core_path',null,$modx->getOption('core_path').'components/discuss/').'model/discuss/');
    if (!($discuss instanceof Discuss)) return true;
       
    $c = $modx->newQuery('disPost');
    $c->limit(10);
    $c->sortby('createdon', 'DESC');
       
    $posts = $modx->getCollection('disPost', $c);
       
    foreach ($posts as $post) {
        $temp = $post->toArray();
        $temp['url'] = $post->getUrl();
        // call chunks or what you want
        $out[] = $modx->getChunk('rowTpl', $temp);
    }
    return implode("\n", $out);


    Chunk rowTpl
    <li>  
    <em> by [[+name_first]] [[+name_last]] » [[+createdon:ago]]</em></li>
    <li><h3><a href="/forums/thread/[[+thread]]/[[+threadname]]">[[+title]]</a></h3>
    <p style='margin-top:5px'>[[+message:strip:stripTags:ellipsis=`50`]]</p>
                        <div class="clear"></div>
    </li>



    For this one, its looking pretty good, getting lots of data and the links work. I lost the avatars for now, and don't get the author's names, but that might work if changed...the appropriate field in Thread part of DB is author, so [[+author]] should work...gonna try it in a sec.


    Rightside [[!Discuss.Popular]]

    <?php
    $weghalen = array(",", "/", "?", "<", ">", ";", ":", "[", "]", "{", "}", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "=");
    $vervangen = array(" ", ".");
      
    $c = $modx->newQuery('modUser');
    $c->leftJoin('modUserProfile','Profile');
    $c->sortby('id','ASC');
    // add column names that u want to show
    $c->select(array(
        'modUser.*',
        'Profile.fullname',
        'Profile.email',
    ));
       
    $users = $modx->getCollection("modUser",$c);
    $naam[0] = 'Anoniem';
    foreach($users as $user){
        $usr = $user->toArray();
      
    $naam[$usr['id']] = $usr['username'];
    $email[$usr['id']] = $usr['email'];
    }
      
    $tpl = $modx->getOption('tpl',$scriptProperties,'Forumthreads.Popular');
      
    $package_path = $modx->getOption('core_path').'components/discuss/model/';
    $modx->addPackage('discuss', $package_path);
    $vraag = $modx->newQuery('disThread');
    $vraag->sortby('replies','DESC');
    $vraag->where(array(
    ));
    $vraag->limit(6,0);
      
    $regels = $modx->getCollection('disThread',$vraag);
    $output = '';
      
    foreach($regels as $regel){
    $rglArray['post']= $regel->get('id');
    $rglArray['thread']= $regel->get('thread');
    $titel = strtolower($regel->get('title'));
    if(substr($titel, 0,4)=="re: "){$titel = substr($titel,4);}
    $titel= str_replace($vervangen, "-", str_replace($weghalen, "", $titel));
    if(substr($titel,-1)=="-"){$titel = substr($titel,0,-1);}
    $rglArray['threadname'] = $titel;
    //$rglArray['threadname'] = $titel2;
    $rglArray['title']= $regel->get('title');
    $rglArray['message']= $regel->get('message');
    $rglArray['author'] = $naam[$regel->get('author')];
    $rglArray['createdon']= $regel->get('createdon');
    $rglArray['gravatar'] = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email[$regel->get('author')])))."?d=mm&s=50";
    $rglArray['email'] = $email[$regel->get('author')];
    $rglArray['nummer'] =$nummer;
      
    $output .= $modx->getChunk($tpl,$rglArray);
    }
    return $output;


    And chunk Forumthreads.Popular

    <ul>
    <li>
    <h5><a href="/forums/thread/[[+thread]]/[[+threadname]]#dis-post-[[+post]]">[[+title]]</a></h5>
    <p style='margin-top:-15px'>[[+message:strip:stripTags:ellipsis=`50`]]</p>
                        <div class="clear"></div>
    </li>
    </ul>


    For this one, the links don't work, but that's just a problem of the chunk, should be fixable. But what is weird is the data collected, it seems some old test posts we already deleted are still in there...weird. One of those is def mine from a long time ago, long since deleted.

    Ok, tell me where you are on this. I really don't know why I am not having the problem you are, again I remember it from before with one but not both of these tools, but its not there now at all, pls have a try and see if this will work.
      • 46886
      • 1,154 Posts
      Oh yeah, the [[+author]] outputs the ID number of the user...not the name. And the array doesn't call the User part of the DB so I think its impossible to get this data there without doing that...I will try to figure this out but I do believe an additional call to the DB will be needed, as mintnl's script does (at the top of his code).
      • discuss.answer
        • 46220
        • 66 Posts
        Solved! smiley --> http://forums.modx.com/thread/91788/recent-posts-threads-for-discuss-by-rimotevst-kanev#dis-post-501516

        Just the matter of it showing on the main page, but will get that when the server is up and running again.