Adding lazy-load version of feed component to load data using AJAX after page content has been rendered.

This commit is contained in:
Jason Williams
2020-10-23 22:54:30 +00:00
parent 2a8454d197
commit af4f1366a0
71 changed files with 1753 additions and 88 deletions

View File

@@ -0,0 +1,33 @@
<?php namespace jasonwilliams\feed\Models;
use Model;
/**
* Model
*/
class Channels extends Model
{
use \October\Rain\Database\Traits\Validation;
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'jasonwilliams_feed_channels';
/**
* @var array Validation rules
*/
public $rules = [
];
public $hasMany = [
'feeditems' => ['jasonwilliams\feed\Models\FeedItem', 'key' => 'channel_id']
];
}

View File

@@ -0,0 +1,65 @@
<?php namespace jasonwilliams\feed\Models;
use Model;
/**
* Model
*/
class FeedItem extends Model
{
use \October\Rain\Database\Traits\Validation;
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'jasonwilliams_feed_';
/**
* @var array Validation rules
*/
public $rules = [
];
public $hasMany = [
'links' => 'jasonwilliams\feed\Models\Links',
'tags' => 'jasonwilliams\feed\Models\Tags'
];
public $belongsTo = [
'channel' => ['jasonwilliams\feed\Models\Channels', 'key' => 'channel_id']
];
public function afterFetch()
{
// Add clickable hashtags to the title field
$this->title = preg_replace('/#(\w*[a-zA-Z]+\w*)/', '<a href="/feed/all/$1">#$1</a>', $this->title);
// Add a friendlytime field
$this->friendlytime = date('M j, Y', $this->timestamp);
// Expand extras to an object
if ($this->extra) $this->extra = json_decode($this->extra);
// Add twitter user links
if ($this->channel_id == 2) $this->title = preg_replace('/@([a-zA-Z0-9_]+)/', '<a href="http://twitter.com/$1">@$1</a>', $this->title);
// Add instagram user links
if ($this->channel_id == 3) $this->title = preg_replace('/@([a-zA-Z0-9_]+)/', '<a href="https://www.instagram.com/$1">@$1</a>', $this->title);
// Add foursquare user Links
if ($this->channel_id == 6 && !empty($this->body)) $this->body = preg_replace('/@([a-zA-Z0-9_]+)/', '<a href="https://www.foursquare.com/$1">@$1</a>', $this->body);
// Find and replace links
foreach($this->links as $link)
{
$this->title = str_replace($link->addr, "<a href=\"".$link->addr."\">".$link->display."</a>", $this->title);
}
}
}

View File

@@ -0,0 +1,35 @@
<?php namespace jasonwilliams\feed\Models;
use Model;
/**
* Model
*/
class Links extends Model
{
use \October\Rain\Database\Traits\Validation;
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'jasonwilliams_feed_links';
protected $fillable = ['addr', 'display'];
/**
* @var array Validation rules
*/
public $rules = [
];
public $belongsTo = [
'links' => 'jasonwilliams\feed\Models\FeedItem'
];
}

View File

@@ -0,0 +1,14 @@
<?php namespace JasonWilliams\Feed\Models;
use Model;
class Settings extends Model
{
public $implement = ['System.Behaviors.SettingsModel'];
// A unique code
public $settingsCode = 'jasonwilliams_feed_settings';
// Reference to field configuration
public $settingsFields = 'fields.yaml';
}

View File

@@ -0,0 +1,40 @@
<?php namespace jasonwilliams\feed\Models;
use Model;
/**
* Model
*/
class Tags extends Model
{
use \October\Rain\Database\Traits\Validation;
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'jasonwilliams_feed_tags';
protected $fillable = ['tag'];
/**
* @var array Validation rules
*/
public $rules = [
];
public $belongsTo = [
'feeditem' => ['jasonwilliams\feed\Models\FeedItem', 'key' => 'feed_item_id']
];
public function afterFetch()
{
//dd($this->feeditem);
}
}

View File

@@ -0,0 +1,10 @@
columns:
id:
label: 'Channel ID'
type: number
sortable: true
title:
label: Title
type: text
searchable: true
sortable: false

View File

@@ -0,0 +1,21 @@
fields:
title:
label: 'Channel Title'
span: left
type: text
slug:
label: Slug
span: right
preset:
field: title
type: slug
type: text
icon:
label: Icon
span: left
type: text
comment: 'Icon code from FontAwesome'
colour:
label: 'Icon Colour'
span: auto
type: colorpicker

View File

@@ -0,0 +1,9 @@
columns:
title:
label: 'Post Title'
type: text
searchable: true
timestamp:
label: 'UNIX Timestamp'
type: number
sortable: true

View File

@@ -0,0 +1,20 @@
fields:
title:
label: 'Post Title'
span: full
type: text
body:
label: 'Post Body'
size: ''
span: full
type: richeditor
timestamp:
label: 'UNIX Timestamp'
span: auto
type: number
channel:
label: Channel
nameFrom: title
descriptionFrom: description
span: auto
type: relation

View File

@@ -0,0 +1,51 @@
fields:
twitter_section:
label: Twitter API Settings
type: section
twitter_username:
label: Username
description: Your twitter username, excluding the @
span: left
twitter_latest_tweet:
label: Latest Tweet ID
description: The ID of the most recent tweet already fetched and stored
span: right
twitter_consumer_key:
label: Consumer Key
description: Your consumer key for accessing the twitter API
span: left
twitter_consumer_secret:
label: Consumer Key Secret
description: Your consumer key secret for accessing the twitter API
span: right
twitter_access_token:
label: Access Token
description: Your access token for accessing the twitter API
span: left
twitter_access_token_secret:
label: Access Token Secret
description: Your access token secret for accessing the twitter API
span: right
instagram_section:
label: Instagram API Settings
type: section
instagram_access_token:
label: Access Token
description: Your access token for accessing the instagram API
span: full
instagram_latest_post:
label: Latest Post Timestamp
description: The unix timestamp of the most recent post already fetched and stored
span: left
foursquare_section:
label: Foursquare API Settings
type: section
foursquare_access_token:
description: Your access token for accessing the foursquare API
span: full
foursquare_latest_post:
label: Latest Checkin Timestamp
description: The unix timestamp of the most recent checkin already fetched and stored
span: left