Commit 63fb8cc9 authored by Marcelo Rivera's avatar Marcelo Rivera Committed by Mark Harding
Browse files

(feat): moved blogs to Minds\Core\Blogs

parent a2b5e7a6
<?php
/**
* Blog Lite View
*/
namespace Minds\plugin\blog\Lite;
use Minds\Core\Email;
class View
{
private $blog;
public function setBlog($blog)
{
$this->blog = $blog;
return $this;
}
public function render()
{
//lets use email templates
$template = new Email\Template;
$template->setTemplate('./lite.tpl');
$template->setBody('./view.tpl');
$template->set('title', $this->blog->title);
$description = strip_tags($this->blog->description);
if (strlen($description) > 140) {
$description = substr($description, 0, 139) . '…';
}
$template->set('meta', [
'title' => $this->blog->title,
'description' => $description,
'og:title' => $this->blog->title,
'og:description' => $description,
'og:url' => str_replace('http://', 'https://', $this->blog->getPermaUrl()),
'og:type' => 'article',
'og:image' => $this->blog->getIconUrl(800),
'og:image:width' => 2000,
]);
$template->set('blog', $this->blog);
return $template->render();
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="https://storage.googleapis.com/code.getmdl.io/1.1.2/material.blue_grey-amber.min.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto:400,700'>
<script src="//storage.googleapis.com/code.getmdl.io/1.1.2/material.min.js"></script>
<!-- inject:css -->
<link rel="stylesheet" href="/stylesheets/main.css?v=1500394555112">
<?php
foreach($vars['meta'] as $name => $content){
$name = strip_tags($name);
$content = str_replace(['"'], '\'', $content);
switch($name){
case "title":
echo "<title>$content</title>\n";
break;
case strpos($name, ":") !== FALSE:
echo "<meta property=\"$name\" content=\"$content\">\n";
break;
default:
echo "<meta name=\"$name\" content=\"$content\">\n";
}
}
?>
</head>
<body>
<div class="m-lite--header">
<a href="https://www.minds.com/" style="text-decoration:none;" class="m-lite--logo">
<img src="https://www.minds.com/assets/logos/medium-production.png" alt="Minds"/>
</a>
<a href="https://www.minds.com/login" style="text-decoration:none; padding-right:8px">
<button class="mdl-button mdl-button--raised mdl-color--blue-grey-600 mdl-color-text--white">Signup</button>
</a>
<a href="https://www.minds.com/login" style="text-decoration:none;">
<button class="mdl-button mdl-button--raised mdl-color--blue-grey-600 mdl-color-text--white">Login</button>
</a>
</div>
<div class="m-lite--body">
<?php echo $vars['body'] ?>
</div>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-35146796-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
</body>
</html>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<minds-banner-fat>
<div class="minds-banner">
<img class="minds-banner-img" src="/fs/v1/banners/<?= $vars['blog']->guid ?>/0/1501848604">
</div>
</minds-banner-fat>
<div class="m-blog-lite mdl-card mdl-shadow--4dp">
<?php if ($vars['blog']->monetized) { ?>
<google-ad style="display:block; width:calc(100% + 32px); margin:-16px -16px 16px">
<ins
class="adsbygoogle"
style="display:block; width:100%;"
data-ad-client="ca-pub-9303771378013875"
data-ad-slot="7588308825"
data-ad-format="auto"
></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</google-ad>
<?php } ?>
<div class="m-blog-lite--header">
<h1><?= $vars['blog']->title ?></h1>
</div>
<div class="minds-blog-ownerblock">
<div class="minds-avatar" [hovercard]="blog.ownerObj.guid">
<a href="<?= $vars['blog']->getOwnerEntity()->username ?>">
<img src="/icon/<?= $vars['blog']->getOwnerEntity()->guid?>/small}}" class="mdl-shadow--2dp"/>
</a>
</div>
<div class="minds-body">
<a href="<?= $vars['blog']->getOwnerEntity()->username ?>" class="mdl-color-text--blue-grey-500"><?= $vars['blog']->getOwnerEntity()->name ?></a>
<span><?= date('M d Y', $vars['blog']->getOwnerEntity()->time_created) ?></span>
</div>
</div>
<div class="m-blog-lite--body">
<?php if ($vars['blog']->monetized) { ?>
<google-ad class="m-ad-block m-ad-block-google square m-ad-block-default m-ad-block-square">
<ins
class="adsbygoogle"
style="display:block; width:100%;"
data-ad-client="ca-pub-9303771378013875"
data-ad-slot="7588308825"
data-ad-format="auto"
></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</google-ad>
<?php } ?>
<div class="minds-blog-body">
<?= $vars['blog']->description ?>
</div>
<?php if ($vars['blog']->monetized) { ?>
<google-ad style="display:block; width:calc(100% + 32px);" class="m-ad-block-mobile">
<ins
class="adsbygoogle"
style="display:block; width:100%;"
data-ad-client="ca-pub-9303771378013875"
data-ad-slot="7588308825"
data-ad-format="auto"
></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</google-ad>
<div id="rcjsload_7c87b6"></div>
<script type="text/javascript">
(function() {
var rcel = document.createElement("script");
rcel.id = 'rc_' + Math.floor(Math.random() * 1000);
rcel.type = 'text/javascript';
rcel.src = "https://trends.revcontent.com/serve.js.php?w=11364&t="+rcel.id+"&c="+(new Date()).getTime()+"&width="+(window.outerWidth || document.documentElement.clientWidth);
rcel.async = true;
var rcds = document.getElementById("rcjsload_7c87b6"); rcds.appendChild(rcel);
})();
</script>
<?php } ?>
</div>
<div class="m-blog-lite--full-link mdl-color--blue-grey-200" style="margin: 16px 0">
<a href="<?= $vars['blog']->getUrl() ?>?lite=false" class="mdl-color-text--white">
You are viewing the Lite version of Minds Blogs. Click here to see the full view.
</a>
</div>
</div>
<?php
/**
* Minds Blog API
*
* @version 1
* @author Mark Harding
*/
namespace minds\plugin\blog\api\v1;
use Minds\Core;
use Minds\Entities\Activity;
use minds\plugin\blog\entities;
use Minds\Entities\User;
use Minds\Interfaces;
use Minds\Api\Factory;
use Minds\Helpers;
class blog implements Interfaces\Api
{
/**
* Returns the conversations or conversation
* @param array $pages
*
* API:: /v1/blog/:filter
*/
public function get($pages)
{
$response = array();
if (!isset($pages[0])) {
$pages[0] = "featured";
}
$limit = isset($_GET['limit']) ? $_GET['limit'] : 12;
$offset = isset($_GET['offset']) ? $_GET['offset'] : "";
switch ($pages[0]) {
case "all":
$entities = core\Entities::get(array(
'subtype' => 'blog',
'offset'=> $offset,
'limit'=> $limit
));
$response['blogs'] = Factory::exportable($entities);
$response['load-next'] = (string) end($entities)->guid;
break;
case "featured":
$guids = Core\Data\indexes::fetch('object:blog:featured', array('offset'=> $offset, 'limit'=> $limit ));
if (!$guids) {
break;
}
$entities = core\Entities::get(array('guids'=>$guids));
usort($entities, function ($a, $b) {
if ((int)$a->featured_id == (int) $b->featured_id) {
return 0;
}
return ((int)$a->featured_id < (int)$b->featured_id) ? 1 : -1;
});
$response['blogs'] = Factory::exportable($entities);
$response['load-next'] = (string) end($entities)->featured_id;
break;
case "trending":
//this is temporary until we bring in neo4j sorting
$db = new Core\Data\Call('entities_by_time');
$guids = $db->getRow('trending:week:object:blog', array( 'limit'=> $limit, 'offset'=>$offset, 'reversed' => false ));
if (!$guids) {
break;
}
ksort($guids);
$entities = core\Entities::get(array('guids'=>$guids));
$response['blogs'] = Factory::exportable($entities);
$response['load-next'] = (string) end(array_keys($guids));
break;
case "owner":
if (isset($pages[1]) && !is_numeric($pages[1])) {
$lookup = new Core\Data\lookup();
$pages[1] = key($lookup->get(strtolower($pages[1])));
}
$entities = core\Entities::get(array(
'subtype' => 'blog',
'owner_guid' => isset($pages[1]) ? $pages[1] : \Minds\Core\Session::getLoggedInUser()->guid,
'offset'=> $offset,
'limit'=> $limit
));
$response['blogs'] = Factory::exportable($entities);
$response['load-next'] = $entities ? (string) end($entities)->guid : null;
break;
case "next":
if (!isset($pages[1])) {
return Factory::response([
'status' => 'error',
'message' => 'Not blog reference guid provided'
]);
}
$blog = new entities\Blog($pages[1]);
$db = new Core\Data\Call('entities_by_time');
//try to get same owner first
//$blogs = $db->getRow("object:blog:user:$blog->owner_guid", ['limit'=> 1, 'offset' => $blog->guid-1]);
//if(!$blogs){
$offset = $blog->featured_id ? $blog->featured_id-1: "";
$blogs = $db->getRow("object:blog:featured", ['limit'=>1, 'offset'=>$offset]);
//}
if (!$blogs) {
return Factory::response([]);
}
//$guids = array_keys($blogs);
$guids = array_values($blogs);
$blog = new entities\Blog($guids[0]);
$response['blog'] = $blog->export();
$owner = new user($blog->ownerObj);
$response['blog']['ownerObj'] = $owner->export();
$response['blog']['description'] = (new Core\Security\XSS())->clean($response['blog']['description']);
break;
case is_numeric($pages[0]):
$guid = $pages[0];
if (strlen($guid) < 15) {
$guid = (new \GUID())->migrate($guid);
}
$blog = new entities\Blog($guid);
if (!$blog->title && !$blog->description || Helpers\Flags::shouldFail($blog)) {
break;
}
$blog->fullExport = true;
$response['blog'] = $blog->export();
//provide correct subscribe info for userobj (renormalize)
$owner = new user($blog->ownerObj);
$response['blog']['ownerObj'] = $owner->export();
$response['blog']['description'] = (new Core\Security\XSS())->clean($response['blog']['description']);
break;
case "header":
$blog = new entities\Blog($pages[1]);
$header = new \ElggFile();
$header->owner_guid = $blog->owner_guid;
$header->setFilename("blog/{$blog->guid}.jpg");
$header->open('read');
header('Content-Type: image/jpeg');
header('Expires: ' . date('r', time() + 864000));
header("Pragma: public");
header("Cache-Control: public");
try {
echo $header->read();
} catch (\Exception $e) {
}
exit;
break;
}
return Factory::response($response);
}
public function post($pages)
{
Factory::isLoggedIn();
$response = [];
$newBlog = false;
if (isset($pages[0]) && is_numeric($pages[0])) {
$blog = new entities\Blog($pages[0]);
} else {
$blog = new entities\Blog();
$newBlog = true;
}
$original_access = $blog->access_id;
$allowed = array('title', 'description', 'access_id', 'status', 'license', 'mature', 'monetized');
foreach ($allowed as $v) {
if (isset($_POST[$v])) {
$blog->$v = $_POST[$v];
}
}
if ($blog->monetized && $blog->mature) {
return Factory::response([
'status' => 'error',
'message' => 'Cannot monetize an explicit blog'
]);
}
if ($blog->monetized && !Core\Session::isAdmin()) {
$merchant = Core\Session::getLoggedInUser()->getMerchant();
if (!$merchant || !isset($merchant['id'])) {
return Factory::response([
'status' => 'error',
'message' => 'User is not a merchant'
]);
}
}
if (isset($_POST['mature']) && $_POST['mature']) {
$user = Core\Session::getLoggedInUser();
if (!$user->getMatureContent()) {
$user->setMatureContent(true);
$user->save();
}
}
if (!$blog->canEdit()) {
return Factory::response([
'status' => 'error',
'message' => 'Sorry, you do not have permission'
]);
}
$blog->save();
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
$resized = get_resized_image_from_uploaded_file('file', 2000, 10000);
$file = new \ElggFile();
$file->owner_guid = $blog->owner_guid;
$file->setFilename("blog/{$blog->guid}.jpg");
$file->open('write');
$file->write($resized);
$file->close();
$blog->header_bg = true;
$blog->header_top = $_POST['header_top'] ?: 0;
$blog->last_updated = time();
$blog->save();
}
$response['guid'] = (string) $blog->guid;
if ($blog->monetized) {
(new Core\Payments\Plans\PaywallReview())
->setEntityGuid($blog->guid)
->add();
}
$activity_post = false;
if ((!isset($pages[0]) || $pages[0] == "new") && $blog->access_id == 2) {
$activity_post = true;
} elseif ($original_access != 2 && $blog->access_id == 2) {
$activity_post = true;
}
if ($activity_post) {
(new Activity())
->setTitle($blog->title)
->setBlurb(strip_tags($blog->description))
->setURL($blog->getURL())
->setThumbnail($blog->getIconUrl())
->setFromEntity($blog)
->setMature($blog->getMature())
->save();
}
if ($newBlog) {
Helpers\Wallet::createTransaction($blog->owner_guid, 15, $blog->guid, 'Blog');
}
return Factory::response($response);
}
public function put($pages)
{
Factory::isLoggedIn();
if (isset($pages[0]) && is_numeric($pages[0])) {
$blog = new entities\Blog($pages[0]);
} else {
$blog = new entities\Blog();
}
if (is_uploaded_file($_FILES['header']['tmp_name'])) {
$resized = get_resized_image_from_uploaded_file('header', 2000, 10000);
$file = new \ElggFile();
$file->owner_guid = $blog->owner_guid;
$file->setFilename("blog/{$blog->guid}.jpg");
$file->open('write');
$file->write($resized);
$file->close();
$blog->header_bg = true;
$blog->last_updated = time();
}
$blog->save();
return Factory::response(array());
}
public function delete($pages)
{
$blog = new entities\Blog($pages[0]);
$deleted = $blog->delete();
if ($deleted) {
Helpers\Wallet::createTransaction($blog->owner_guid, -15, $blog->guid, 'Blog Deleted');
}
return Factory::response(array());
}
}
<?php
/**
* Minds Blog API
*
* @version 1
* @author Mark Harding
*/
namespace minds\plugin\blog\api\v1;
use Minds\Core;
use minds\plugin\blog\entities;
use Minds\Interfaces;
use Minds\Api\Factory;
class header implements Interfaces\Api, Interfaces\ApiIgnorePam
{
/**
* Returns the conversations or conversation
* @param array $pages
*
* API:: /v1/blog/:filter
*/
public function get($pages)
{
$blog = new entities\Blog($pages[0]);
$header = new \ElggFile();
$header->owner_guid = $blog->owner_guid;
$header->setFilename("blog/{$blog->guid}.jpg");
$header->open('read');
header('Content-Type: image/jpeg');
header('Expires: ' . date('r', time() + 864000));
header("Pragma: public");
header("Cache-Control: public");
try {
echo $header->read();
} catch (\Exception $e) {
}
exit;
}
public function post($pages)
{
return Factory::response(array());
}
public function put($pages)
{
return Factory::response(array());
}
public function delete($pages)
{
return Factory::response(array());
}
}
import { NgModule } from '@angular/core';
import { CommonModule as NgCommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '../../common/common.module';
import { ModalsModule } from '../../modules/modals/modals.module';
import { AdsModule } from '../../modules/ads/ads.module';
import { LegacyModule } from '../../modules/legacy/legacy.module';
import { PostMenuModule } from '../../common/components/post-menu/post-menu.module';
import { Blog, BlogViewInfinite, BlogEdit } from './blog';
import { BlogCard } from './card/card';
import { BlogView } from './view/view';
const routes: Routes = [
{ path: 'blog/view/:guid/:title', component: BlogViewInfinite },
{ path: 'blog/view/:guid', component: BlogViewInfinite },
{ path: 'blog/edit/:guid', component: BlogEdit },