<commit_before><?php

/**
 * @file WidgetCommon.php
 * This file is part of MOVIM.
 *
 * @brief The widgets commons methods.
 *
 * @author <NAME> <<EMAIL>>
 *
 * @date 08 march 2012
 *
 * Copyright (C)2010 MOVIM Project
 *
 * See COPYING for licensing information.
 *
 */

use \Rain\Tpl;
use \Michelf\Markdown;

use Moxl\Xec\Action\Pubsub\PostPublish;
use Moxl\Xec\Action\Pubsub\PostDelete;
use Moxl\Xec\Action\Microblog\CommentPublish;
use Moxl\Xec\Action\Microblog\CommentsGet;

class WidgetCommon extends WidgetBase {
    private function loadTemplate() {
        $config = array(
            'tpl_dir'       => APP_PATH.'widgets/WidgetCommon/',
            'cache_dir'     => CACHE_PATH,
            'tpl_ext'       => 'tpl',
            'auto_escape'   => false
        );

        // We load the template engine
        $view = new Tpl;
        $view->objectConfigure($config);
        $view->assign('c', $this);
        
        return $view;
    }
    
    protected function printPost($post, $comments = false, $public = false) {
        // Initialize the variables
        $class = $title = $access = $flagcolor = $group = $c = 
        $tags = $toolbox = $place = $recycle = '';

        if($post->title)
            $title = $post->title;
            
        $spoiler = false;
            
        if(current(explode('.', $post->jid)) == 'nsfw')
            $spoiler = ' movim_toggle_class(this, \'show\')';
            
        if($this->user->getLogin() == $post->aid) {
            $class = 'me ';

            if($post->privacy == 1){
                $flagcolor='black';
                $access .= 'protect black';
            }
            else{
                $flagcolor='orange';
                $access .= 'protect orange';
            }

            $avatar = $post->getContact()->getPhoto('m');
        } elseif(isset($post->aid)) {
            $avatar = $post->getContact()->getPhoto('m', $post->aid);
        // A little hack which display a colored avatar for the Groups
        } elseif(!filter_var($post->jid, FILTER_VALIDATE_EMAIL) && $post->node != '') {
            $avatar = $post->getContact()->getPhoto('m', $post->node);
        } else
            $avatar = $post->getContact()->getPhoto('m');
            
        if(!filter_var($post->jid, FILTER_VALIDATE_EMAIL) && $post->node != '')
            $group = '
                <span class="group">
                    <a href="'.Route::urlize('node', array($post->jid, $post->node)).'">'.$post->node.' ('.$post->jid.')</a>
                </span>';
        elseif($post->jid != $post->aid)
            $recycle .= '
                <span class="recycle">
                    <a href="'.Route::urlize('friend', $post->jid).'">'.$post->jid.'</a>
                 </span>';

        if($post->getPlace() != false)
            $place .= '
                <span class="place">
                    <a 
                        target="_blank" 
                        href="http://www.openstreetmap.org/?lat='.$post->lat.'&lon='.$post->lon.'&zoom=10"
                    >'.__('post.place').'</a>
                </span>';

        if(filter_var($post->jid, FILTER_VALIDATE_EMAIL) && $post->jid != '')
            $c = '
                <span>
                    <a href="'.Route::urlize('friend', $post->jid).'">'.$post->getContact()->getTrueName().'</a>
                </span>';
        elseif($post->getContact()->getTrueName() != '' && filter_var($post->aid, FILTER_VALIDATE_EMAIL))
            $c = '
                <span>
                    <a href="'.Route::urlize('friend', $post->aid).'">'.$post->getContact()->getTrueName().'</a>
                </span>';
        elseif($post->aid != '' && filter_var($post->aid, FILTER_VALIDATE_EMAIL))
            $c = '
                <span>
                    <a href="'.Route::urlize('friend', $post->aid).'">'.$post->aid.'</a>
                </span>';
                
        if($post->links)
            $enc = $this->printEnclosures($post->links);
           
        if($post->tags)
            $tags = $this->printTags($post->tags);
                
        if(isset($enc) && $enc != '') {
            $enc = '
                <div class="enclosures">'.
                    $enc.
                '
                    <div class="clear"></div>
                </div>';
        } else
            $enc = '';

        $author = $this->prepareAuthor($post);

        $content = $post->contentcleaned;
        
        if($post->node == 'urn:xmpp:microblog:0')
            $comments = $this->printComments($post, $comments, $public);
        else
            $comments = '';
        
        if($this->user->getLogin() == $post->aid) 
            $toolbox = $this->getToolbox($post);
            
        $view = $this->loadTemplate();
        $view->assign('idhash',     md5($post->nodeid));
        $view->assign('id',         $post->nodeid);
        $view->assign('class',      $class);
        $view->assign('access',     $access);
        $view->assign('spoiler',    $spoiler);
        $view->assign('flagtitle',  getFlagTitle($flagcolor));
        if(filter_var($post->jid, FILTER_VALIDATE_EMAIL))
            $view->assign('friend',     Route::urlize('friend', $post->jid));
        elseif(!filter_var($post->jid, FILTER_VALIDATE_EMAIL) && $post->node != '')
            $view->assign('friend',     Route::urlize('node', array($post->jid, $post->node)));
        else<commit_msg>- Little fix for retrocompatibility<commit_after><?php

/**
 * @file WidgetCommon.php
 * This file is part of MOVIM.
 *
 * @brief The widgets commons methods.
 *
 * @author <NAME> <<EMAIL>>
 *
 * @date 08 march 2012
 *
 * Copyright (C)2010 MOVIM Project
 *
 * See COPYING for licensing information.
 *
 */

use \Rain\Tpl;
use \Michelf\Markdown;

use Moxl\Xec\Action\Pubsub\PostPublish;
use Moxl\Xec\Action\Pubsub\PostDelete;
use Moxl\Xec\Action\Microblog\CommentPublish;
use Moxl\Xec\Action\Microblog\CommentsGet;

class WidgetCommon extends WidgetBase {
    private function loadTemplate() {
        $config = array(
            'tpl_dir'       => APP_PATH.'widgets/WidgetCommon/',
            'cache_dir'     => CACHE_PATH,
            'tpl_ext'       => 'tpl',
            'auto_escape'   => false
        );

        // We load the template engine
        $view = new Tpl;
        $view->objectConfigure($config);
        $view->assign('c', $this);
        
        return $view;
    }
    
    protected function printPost($post, $comments = false, $public = false) {
        // Initialize the variables
        $class = $title = $access = $flagcolor = $group = $c = 
        $tags = $toolbox = $place = $recycle = '';

        if($post->title)
            $title = $post->title;
            
        $spoiler = false;
            
        if(current(explode('.', $post->jid)) == 'nsfw')
            $spoiler = ' movim_toggle_class(this, \'show\')';
            
        if($this->user->getLogin() == $post->aid) {
            $class = 'me ';

            if($post->privacy == 1){
                $flagcolor='black';
                $access .= 'protect black';
            }
            else{
                $flagcolor='orange';
                $access .= 'protect orange';
            }

            $avatar = $post->getContact()->getPhoto('m');
        } elseif(isset($post->aid)) {
            $avatar = $post->getContact()->getPhoto('m', $post->aid);
        // A little hack which display a colored avatar for the Groups
        } elseif(!filter_var($post->jid, FILTER_VALIDATE_EMAIL) && $post->node != '') {
            $avatar = $post->getContact()->getPhoto('m', $post->node);
        } else
            $avatar = $post->getContact()->getPhoto('m');
            
        if(!filter_var($post->jid, FILTER_VALIDATE_EMAIL) && $post->node != '')
            $group = '
                <span class="group">
                    <a href="'.Route::urlize('node', array($post->jid, $post->node)).'">'.$post->node.' ('.$post->jid.')</a>
                </span>';
        elseif($post->jid != $post->aid)
            $recycle .= '
                <span class="recycle">
                    <a href="'.Route::urlize('friend', $post->jid).'">'.$post->jid.'</a>
                 </span>';

        if($post->getPlace() != false)
            $place .= '
                <span class="place">
                    <a 
                        target="_blank" 
                        href="http://www.openstreetmap.org/?lat='.$post->lat.'&lon='.$post->lon.'&zoom=10"
                    >'.__('post.place').'</a>
                </span>';

        if(filter_var($post->jid, FILTER_VALIDATE_EMAIL) && $post->jid != '')
            $c = '
                <span>
                    <a href="'.Route::urlize('friend', $post->jid).'">'.$post->getContact()->getTrueName().'</a>
                </span>';
        elseif($post->getContact()->getTrueName() != '' && filter_var($post->aid, FILTER_VALIDATE_EMAIL))
            $c = '
                <span>
                    <a href="'.Route::urlize('friend', $post->aid).'">'.$post->getContact()->getTrueName().'</a>
                </span>';
        elseif($post->aid != '' && filter_var($post->aid, FILTER_VALIDATE_EMAIL))
            $c = '
                <span>
                    <a href="'.Route::urlize('friend', $post->aid).'">'.$post->aid.'</a>
                </span>';
                
        if($post->links)
            $enc = $this->printEnclosures($post->links);
           
        if($post->tags)
            $tags = $this->printTags($post->tags);
                
        if(isset($enc) && $enc != '') {
            $enc = '
                <div class="enclosures">'.
                    $enc.
                '
                    <div class="clear"></div>
                </div>';
        } else
            $enc = '';

        $author = $this->prepareAuthor($post);

        $content = $post->contentcleaned;
        if(!isset($content))
            $content = $post->content;
        
        if($post->node == 'urn:xmpp:microblog:0')
            $comments = $this->printComments($post, $comments, $public);
        else
            $comments = '';
        
        if($this->user->getLogin() == $post->aid) 
            $toolbox = $this->getToolbox($post);
            
        $view = $this->loadTemplate();
        $view->assign('idhash',     md5($post->nodeid));
        $view->assign('id',         $post->nodeid);
        $view->assign('class',      $class);
        $view->assign('access',     $access);
        $view->assign('spoiler',    $spoiler);
        $view->assign('flagtitle',  getFlagTitle($flagcolor));
        if(filter_var($post->jid, FILTER_VALIDATE_EMAIL))
            $view->assign('friend',     Route::urlize('friend', $post->jid));
        elseif(!filter_var($post->jid, FILTER_VALIDATE_EMAIL) && $post->node != '')
            $view->assign('friend',     Route::urlize('node', array($post->jid, $post->node)));
        else
{'fraction_non_alphanumeric': 0.18886043533930857, 'fraction_numerical': 0.0027437351381013352, 'mean_word_length': 1.679490320999755, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 236, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5438309', 'n_tokens_mistral': 3395, 'n_tokens_neox': 3261, 'n_words': 530}