Merge branch 'release/0.0.3'

This commit is contained in:
Jonny Barnes 2016-06-09 15:47:17 +01:00
commit 68e11f4331
12 changed files with 571 additions and 275 deletions

View file

@ -11,7 +11,6 @@ DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_CONNECTION=pgsql
CACHE_DRIVER=file
SESSION_DRIVER=file

View file

@ -13,10 +13,12 @@ env:
- setup=basic
php:
- 7.0
- 7.0.6
- 7.0.7
- nightly
matrix:
allow_failures:
- php: 7.0.7 # A known bug in PHP 7.0.7 stops phpdbg producing code coverage reports
- php: nightly
before_install:

View file

@ -3,7 +3,6 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Jonnybarnes\UnicodeTools\UnicodeTools;
use League\CommonMark\CommonMarkConverter;
use MartinBean\Database\Eloquent\Sluggable;
use Illuminate\Database\Eloquent\SoftDeletes;
@ -57,9 +56,8 @@ class Article extends Model
*/
public function getMainAttribute($value)
{
$unicode = new UnicodeTools();
$markdown = new CommonMarkConverter();
$html = $markdown->convertToHtml($unicode->convertUnicodeCodepoints($value));
$html = $markdown->convertToHtml($value);
//change <pre><code>[lang] ~> <pre><code data-language="lang">
$match = '/<pre><code>\[(.*)\]\n/';
$replace = '<pre><code class="language-$1">';

View file

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use App\Client;
use App\MicropubClient;
class ClientsAdminController extends Controller
{
@ -13,7 +13,7 @@ class ClientsAdminController extends Controller
*/
public function listClients()
{
$clients = Client::all();
$clients = MicropubClient::all();
return view('admin.listclients', ['clients' => $clients]);
}
@ -36,7 +36,7 @@ class ClientsAdminController extends Controller
*/
public function postNewClient(Request $request)
{
Client::create([
MicropubClient::create([
'client_url' => $request->input('client_url'),
'client_name' => $request->input('client_name'),
]);
@ -52,7 +52,7 @@ class ClientsAdminController extends Controller
*/
public function editClient($clientId)
{
$client = Client::findOrFail($clientId);
$client = MicropubClient::findOrFail($clientId);
return view('admin.editclient', [
'id' => $clientId,
@ -70,7 +70,7 @@ class ClientsAdminController extends Controller
*/
public function postEditClient($clientId, Request $request)
{
$client = Client::findOrFail($clientId);
$client = MicropubClient::findOrFail($clientId);
if ($request->input('edit')) {
$client->client_url = $request->input('client_url');
$client->client_name = $request->input('client_name');

View file

@ -155,17 +155,9 @@ class NotesController extends Controller
*/
public function taggedNotes($tag)
{
$tag = mb_strtolower(
preg_replace(
'/&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/i',
'$1',
htmlentities($tag)
),
'UTF-8'
);
$tagId = Tag::where('tag', $tag)->pluck('id');
$notes = Tag::find($tagId)->notes()->orderBy('updated_at', 'desc')->get();
$notes = Note::whereHas('tags', function ($query) use ($tag) {
$query->where('tag', $tag);
})->get();
foreach ($notes as $note) {
$note->iso8601_time = $note->updated_at->toISO8601String();
$note->human_time = $note->updated_at->diffForHumans();

View file

@ -4,7 +4,7 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
class Client extends Model
class MicropubClient extends Model
{
/**
* The table associated with the model.

View file

@ -5,7 +5,6 @@ namespace App;
use Normalizer;
use Jonnybarnes\IndieWeb\Numbers;
use Illuminate\Database\Eloquent\Model;
use Jonnybarnes\UnicodeTools\UnicodeTools;
use League\CommonMark\CommonMarkConverter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
@ -98,10 +97,8 @@ class Note extends Model implements HasMedia
*/
public function getNoteAttribute($value)
{
$unicode = new UnicodeTools();
$codepoints = $unicode->convertUnicodeCodepoints($value);
$markdown = new CommonMarkConverter();
$html = $markdown->convertToHtml($codepoints);
$html = $markdown->convertToHtml($value);
$hcards = $this->makeHCards($html);
$hashtags = $this->autoLinkHashtag($hcards);
@ -150,7 +147,7 @@ class Note extends Model implements HasMedia
if ($this->client_id == null) {
return;
}
$name = Client::where('client_url', $this->client_id)->value('client_name');
$name = MicropubClient::where('client_url', $this->client_id)->value('client_name');
if ($name == null) {
$url = parse_url($this->client_id);
if (isset($url['path'])) {
@ -216,7 +213,7 @@ class Note extends Model implements HasMedia
foreach ($matches[0] as $name) {
$name = str_replace('#', '', $name);
$replacements[$name] =
'<a rel="tag" class="p-category" href="/notes/tagged/' . $name . '">#' . $name . '</a>';
'<a rel="tag" class="p-category" href="/notes/tagged/' . Tag::normalizeTag($name) . '">#' . $name . '</a>';
}
// Replace #tags with valid microformat-enabled link

View file

@ -5,7 +5,6 @@ namespace App\Providers;
use App\Tag;
use App\Note;
use Validator;
use Jonnybarnes\IndieWeb\NotePrep;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@ -32,11 +31,14 @@ class AppServiceProvider extends ServiceProvider
//Add tags for notes
Note::created(function ($note) {
$noteprep = new NotePrep();
$tagsToAdd = [];
$tags = $noteprep->getTags($note->note);
foreach ($tags as $text) {
$tag = Tag::firstOrCreate(['tag' => $text]);
preg_match_all('/#([^\s<>]+)\b/', $note, $tags);
foreach ($tags[1] as $tag) {
$tag = Tag::normalizeTag($tag);
}
$tags = array_unique($tags[1]);
foreach ($tags as $tag) {
$tag = Tag::firstOrCreate(['tag' => $tag]);
$tagsToAdd[] = $tag->id;
}
if (count($tagsToAdd > 0)) {

View file

@ -36,4 +36,32 @@ class Tag extends Model
* @var array
*/
protected $guarded = ['id'];
/**
* Normalize tags so theyre lowercase and fancy diatrics are removed.
*
* @param string
*/
public function setTagAttribute($value)
{
$this->attributes['tag'] = $this->normalizeTag($value);
}
/**
* This method actually normalizes a tag. That means lowercase-ing and
* removing fancy diatric characters.
*
* @param string
*/
public static function normalizeTag($tag)
{
return mb_strtolower(
preg_replace(
'/&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/i',
'$1',
htmlentities($tag)
),
'UTF-8'
);
}
}

View file

@ -1,5 +1,9 @@
# Changelog
## Version 0.0.3 (2013-06-09)
- Better tag normalization code organisation
- Remove `jonnybarnes/unicode-tools` dependency and clean up relevant code
## Version 0.0.2 (2016-05-25)
- Fix issue#1: tagged notes page needs the tag from the URL normalizing.

View file

@ -8,7 +8,6 @@
"ext-intl": "*",
"php": ">=7.0.0",
"laravel/framework": "5.2.*",
"jonnybarnes/unicode-tools": "dev-master",
"jonnybarnes/indieweb": "dev-master",
"jonnybarnes/webmentions-parser": "dev-master",
"guzzlehttp/guzzle": "~6.0",
@ -21,24 +20,18 @@
"league/commonmark": "^0.13.0",
"spatie/laravel-medialibrary": "^3.5",
"league/flysystem-aws-s3-v3": "^1.0",
"phaza/laravel-postgis": "dev-master",
"phaza/laravel-postgis": "~3.1",
"lcobucci/jwt": "^3.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpunit/phpunit": "~5.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*",
"barryvdh/laravel-debugbar": "~2.0",
"filp/whoops": "~2.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/njbarrett/laravel-postgis"
}
],
"autoload": {
"classmap": [
"database"

747
composer.lock generated

File diff suppressed because it is too large Load diff