<commit_before><?php

namespace App\Http\Controllers;

use Cache;
use Twitter;
use App\Tag;
use App\Note;
use HTMLPurifier;
use HTMLPurifier_Config;
use Jonnybarnes\IndieWeb\Numbers;
use Illuminate\Filesystem\Filesystem;
use Jonnybarnes\WebmentionsParser\Authorship;

// Need to sort out Twitter and webmentions!

class NotesController extends Controller
{
    /**
     * Show all the notes.
     *
     * @return \Illuminte\View\Factory view
     */
    public function showNotes()
    {
        $notes = Note::orderBy('id', 'desc')->with('webmentions', 'place', 'media')->simplePaginate(10);
        foreach ($notes as $note) {
            $replies = 0;
            foreach ($note->webmentions as $webmention) {
                if ($webmention->type == 'in-reply-to') {
                    $replies++;
                }
            }
            $note->replies = $replies;
            $note->twitter = $this->checkTwitterReply($note->in_reply_to);
            $note->iso8601_time = $note->updated_at->toISO8601String();
            $note->human_time = $note->updated_at->diffForHumans();
            if ($note->location && ($note->place === null)) {
                $pieces = explode(':', $note->location);
                $latlng = explode(',', $pieces[0]);
                $note->latitude = trim($latlng[0]);
                $note->longitude = trim($latlng[1]);
                if (count($pieces) == 2) {
                    $note->address = $pieces[1];
                }
            }
            if ($note->place !== null) {
                $lnglat = explode(' ', $note->place->location);
                $note->latitude = $lnglat[1];
                $note->longitude = $lnglat[0];
                $note->address = $note->place->name;
                $note->placeLink = '/places/' . $note->place->slug;
            }
            $photoURLs = [];
            $photos = $note->getMedia();
            foreach ($photos as $photo) {
                $photoURLs[] = $photo->getUrl();
            }
            $note->photoURLs = $photoURLs;
        }

        return view('allnotes', ['notes' => $notes]);
    }

    /**
     * Show a single note.
     *
     * @param  string The id of the note
     * @return \Illuminate\View\Factory view
     */
    public function singleNote($urlId)
    {
        $numbers = new Numbers();
        $authorship = new Authorship();
        $realId = $numbers->b60tonum($urlId);
        $note = Note::find($realId);
        $replies = [];
        $reposts = [];
        $likes = [];
        $carbon = new Carbon\Carbon();
        foreach ($note->webmentions as $webmention) {
            /*<commit_msg>Use correct namespace for Carbon<commit_after><?php

namespace App\Http\Controllers;

use Cache;
use Twitter;
use App\Tag;
use App\Note;
use HTMLPurifier;
use HTMLPurifier_Config;
use Jonnybarnes\IndieWeb\Numbers;
use Illuminate\Filesystem\Filesystem;
use Jonnybarnes\WebmentionsParser\Authorship;

// Need to sort out Twitter and webmentions!

class NotesController extends Controller
{
    /**
     * Show all the notes.
     *
     * @return \Illuminte\View\Factory view
     */
    public function showNotes()
    {
        $notes = Note::orderBy('id', 'desc')->with('webmentions', 'place', 'media')->simplePaginate(10);
        foreach ($notes as $note) {
            $replies = 0;
            foreach ($note->webmentions as $webmention) {
                if ($webmention->type == 'in-reply-to') {
                    $replies++;
                }
            }
            $note->replies = $replies;
            $note->twitter = $this->checkTwitterReply($note->in_reply_to);
            $note->iso8601_time = $note->updated_at->toISO8601String();
            $note->human_time = $note->updated_at->diffForHumans();
            if ($note->location && ($note->place === null)) {
                $pieces = explode(':', $note->location);
                $latlng = explode(',', $pieces[0]);
                $note->latitude = trim($latlng[0]);
                $note->longitude = trim($latlng[1]);
                if (count($pieces) == 2) {
                    $note->address = $pieces[1];
                }
            }
            if ($note->place !== null) {
                $lnglat = explode(' ', $note->place->location);
                $note->latitude = $lnglat[1];
                $note->longitude = $lnglat[0];
                $note->address = $note->place->name;
                $note->placeLink = '/places/' . $note->place->slug;
            }
            $photoURLs = [];
            $photos = $note->getMedia();
            foreach ($photos as $photo) {
                $photoURLs[] = $photo->getUrl();
            }
            $note->photoURLs = $photoURLs;
        }

        return view('allnotes', ['notes' => $notes]);
    }

    /**
     * Show a single note.
     *
     * @param  string The id of the note
     * @return \Illuminate\View\Factory view
     */
    public function singleNote($urlId)
    {
        $numbers = new Numbers();
        $authorship = new Authorship();
        $realId = $numbers->b60tonum($urlId);
        $note = Note::find($realId);
        $replies = [];
        $reposts = [];
        $likes = [];
        $carbon = new \Carbon\Carbon();
        foreach ($note->webmentions as $webmention) {
            /*
{'fraction_non_alphanumeric': 0.15772572723838307, 'fraction_numerical': 0.007555723460521345, 'mean_word_length': 1.7927215189873418, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6802031', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1570, 'n_words': 314}