<commit_before><?php

if (!defined('GNUSOCIAL')) { exit(1); }

class QuitimNoticeListItem extends NoticeListItem
{
    // Add changes that might be necessary later on or just keep this as an empty intermediate class

    function showNoticeFooter()
    {
        $this->elementStart('footer');
        $this->showNoticeInfo();
        if ($this->options) { $this->showNoticeOptions(); }
//         if ($this->attachments) { $this->showNoticeAttachments(); }
        $this->elementEnd('footer');
    }

    function showStart()
    {

        // see if this is an "empty" notice with only image attachments
        $attachments = $this->notice->attachments();
        $content_stripped_of_attachments = $this->notice->content;
        $image_attachments_num = 0;
 		foreach($attachments as $attachment) {
 			$attachment_type = substr($attachment->mimetype, 0, strpos($attachment->mimetype,'/'));
 			if(empty($this->notice->reply_to) && $attachment_type == 'image' && $attachment instanceof File) {
                $image_attachments_num++;
                $content_stripped_of_attachments = trim(str_replace(File_redirection::getKV('file_id',$attachment->id)->url,'',$content_stripped_of_attachments));
            }
		}


        if (Event::handle('StartOpenNoticeListItemElement', array($this))) {
            $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id;
            $class = 'h-entry notice';
            if ($this->notice->scope != 0 && $this->notice->scope != 1) {
                $class .= ' limited-scope';
            }
            if (!empty($this->notice->source)) {
                $class .= ' notice-source-'.$this->notice->source;
            }
            if($content_stripped_of_attachments == '') {
                $class .= ' empty-text';
            }
            if(substr($this->notice->rendered,0,27) == '<div class="quitim-notice">') {
                $class .= ' old-quitim-notice';
            }            
            if(isset($this->notice->is_conversation_starter)) {
                $class .= ' conversation-starter';
            }
            if($image_attachments_num == 0) {
                $class .= ' no-images';
            }
            $id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : '');
            $this->out->elementStart($this->item_tag, array('class' => $class,
                                                 'id' => "${id_prefix}notice-${id}",
                                                 'data-local-permalink' => $this->notice->getLocalUrl()));
            Event::handle('EndOpenNoticeListItemElement', array($this));
        }
    }


    function showAuthor()
    {
        $attrs = array('href' => $this->profile->profileurl,
                       'class' => 'h-card p-author',
                       'title' => $this->profile->getStreamName());

        if (Event::handle('StartShowNoticeItemAuthor', array($this->profile, $this->out, &$attrs))) {
            $this->out->elementStart('a', $attrs);
            $this->showAvatar($this->profile);
            $this->out->text($this->profile->getNickname());
            $this->out->elementEnd('a');
            Event::handle('EndShowNoticeItemAuthor', array($this->profile, $this->out));
        }
    }


    function showContent()
    {

        $this->out->elementStart('article', array('class' => 'e-content'));

        $attachments = $this->notice->attachments();

		$image_attachments_num = 0;
 		foreach($attachments as $attachment) {
 			$attachment_type = substr($attachment->mimetype, 0, strpos($attachment->mimetype,'/'));

 			// we only show conversation starting images
 			if(empty($this->notice->reply_to) && $attachment_type == 'image' && $attachment instanceof File) {

 				// show full image if small
 				if($attachment->width < 1000) {
                    $thumb_url = $attachment->url;
				// thumbnail scaled to 1000px wide if big
                } else {
                    $ratio = $attachment->width/$attachment->height;
                    $thumb = $attachment->getThumbnail(1000, 1000/$ratio);
                    $thumb_url = $thumb->url;
                }
                $this->out->raw('<div class="quitim-notice"><a class="link" href="'.$this->notice->getUrl().'"><img src="'.$thumb_url.'" /></a><img class="no-link" src="'.$thumb_url.'" /></div>');
				$image_attachments_num++;
			}
		}
	
		// if this is a root notice but without image, we show the text
		if(empty($this->notice->reply_to) && $image_attachments_num==0) {
			$this->out->raw('<div class="quitim-notice-text-only">'.$this->notice->rendered.'</div>');			
		}

        // don't know why i had to do this, but when QuitimNoticeListItem is used from quitimnewnotice.php it can't find this clas...
        // but we don't need it then, since it's always the question about getting a comment with ajax then.
        if(class_exists('QuitimThreadedNoticeListFavesItem')) {
            $item = new QuitimThreadedNoticeListFavesItem($this->notice, $this->out);
            $hasFaves = $item->show();
        } else {
            $hasFaves = false;
        }

        // add a fav container even if no faves, to load into with ajax when faving
        if(!isset($hasFaves) || !$hasFaves) {
        	$this->element('div',array('class' => 'notice-data notice-faves'));
        	}

        $this->out->elementStart('div', 'first-comment');
        $this->showAuthor();
        $this->out->elementStart('span', 'quitim-notice-text');
        if ($this->maxchars > 0 && mb_strlen($this->notice->content) > $this->maxchars) {
            $this->out->text(mb_substr($this->notice->content, 0, $this->maxchars) . '[…]');
        } elseif ($this->notice->rendered) {
            $this->out->raw($this->notice->rendered);
        }<commit_msg>fixes this bug https://quitter.se/notice/3993742<commit_after><?php

if (!defined('GNUSOCIAL')) { exit(1); }

class QuitimNoticeListItem extends NoticeListItem
{
    // Add changes that might be necessary later on or just keep this as an empty intermediate class

    function showNoticeFooter()
    {
        $this->elementStart('footer');
        $this->showNoticeInfo();
        if ($this->options) { $this->showNoticeOptions(); }
//         if ($this->attachments) { $this->showNoticeAttachments(); }
        $this->elementEnd('footer');
    }

    function showStart()
    {

        // see if this is an "empty" notice with only image attachments
        $attachments = $this->notice->attachments();
        $content_stripped_of_attachments = $this->notice->content;
        $image_attachments_num = 0;
 		foreach($attachments as $attachment) {
 			$attachment_type = substr($attachment->mimetype, 0, strpos($attachment->mimetype,'/'));
 			if(empty($this->notice->reply_to) && $attachment_type == 'image' && $attachment instanceof File) {
                $image_attachments_num++;
                $content_stripped_of_attachments = trim(str_replace(File_redirection::getKV('file_id',$attachment->id)->url,'',$content_stripped_of_attachments));
            }
		}


        if (Event::handle('StartOpenNoticeListItemElement', array($this))) {
            $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id;
            $class = 'h-entry notice';
            if ($this->notice->scope != 0 && $this->notice->scope != 1) {
                $class .= ' limited-scope';
            }
            if (!empty($this->notice->source)) {
                $class .= ' notice-source-'.$this->notice->source;
            }
            if($content_stripped_of_attachments == '') {
                $class .= ' empty-text';
            }
            if(substr($this->notice->rendered,0,27) == '<div class="quitim-notice">') {
                $class .= ' old-quitim-notice';
            }            
            if(isset($this->notice->is_conversation_starter)) {
                $class .= ' conversation-starter';
            }
            if($image_attachments_num == 0) {
                $class .= ' no-images';
            }
            $id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : '');
            $this->out->elementStart($this->item_tag, array('class' => $class,
                                                 'id' => "${id_prefix}notice-${id}",
                                                 'data-local-permalink' => $this->notice->getLocalUrl()));
            Event::handle('EndOpenNoticeListItemElement', array($this));
        }
    }


    function showAuthor()
    {
        $attrs = array('href' => $this->profile->profileurl,
                       'class' => 'h-card p-author',
                       'title' => $this->profile->getStreamName());

        if (Event::handle('StartShowNoticeItemAuthor', array($this->profile, $this->out, &$attrs))) {
            $this->out->elementStart('a', $attrs);
            $this->showAvatar($this->profile);
            $this->out->text($this->profile->getNickname());
            $this->out->elementEnd('a');
            Event::handle('EndShowNoticeItemAuthor', array($this->profile, $this->out));
        }
    }


    function showContent()
    {

        $this->out->elementStart('article', array('class' => 'e-content'));

        $attachments = $this->notice->attachments();

		$is_conversation_root = ($this->notice->id == $this->notice->conversation);

		$image_attachments_num = 0;
 		foreach($attachments as $attachment) {
 			$attachment_type = substr($attachment->mimetype, 0, strpos($attachment->mimetype,'/'));
			
 			// we only show conversation starting images
 			if($is_conversation_root && $attachment_type == 'image' && $attachment instanceof File) {

 				// show full image if small
 				if($attachment->width < 1000) {
                    $thumb_url = $attachment->url;
				// thumbnail scaled to 1000px wide if big
                } else {
                    $ratio = $attachment->width/$attachment->height;
                    $thumb = $attachment->getThumbnail(1000, 1000/$ratio);
                    $thumb_url = $thumb->url;
                }
                $this->out->raw('<div class="quitim-notice"><a class="link" href="'.$this->notice->getUrl().'"><img src="'.$thumb_url.'" /></a><img class="no-link" src="'.$thumb_url.'" /></div>');
				$image_attachments_num++;
			}
		}
	
		// if this is a root notice but without image, we show the text
		if($is_conversation_root && $image_attachments_num==0) {
			$this->out->raw('<div class="quitim-notice-text-only">'.$this->notice->rendered.'</div>');			
		}

        // don't know why i had to do this, but when QuitimNoticeListItem is used from quitimnewnotice.php it can't find this clas...
        // but we don't need it then, since it's always the question about getting a comment with ajax then.
        if(class_exists('QuitimThreadedNoticeListFavesItem')) {
            $item = new QuitimThreadedNoticeListFavesItem($this->notice, $this->out);
            $hasFaves = $item->show();
        } else {
            $hasFaves = false;
        }

        // add a fav container even if no faves, to load into with ajax when faving
        if(!isset($hasFaves) || !$hasFaves) {
        	$this->element('div',array('class' => 'notice-data notice-faves'));
        	}

        $this->out->elementStart('div', 'first-comment');
        $this->showAuthor();
        $this->out->elementStart('span', 'quitim-notice-text');
        if ($this->maxchars > 0 && mb_strlen($this->notice->content) > $this->maxchars) {
            $this->out->text(mb_substr($this->notice->content, 0, $this->maxchars) . '[…]');
        } elseif ($this->notice->rendered) {
            $this->out->raw($this->notice->rendered);
        }
{'fraction_non_alphanumeric': 0.17120054921479447, 'fraction_numerical': 0.005749592379644727, 'mean_word_length': 2.3051616562677255, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 255, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7297877', 'n_tokens_mistral': 3564, 'n_tokens_neox': 3310, 'n_words': 618}