Commit 8c94d970 authored by thomas craipeau's avatar thomas craipeau
Browse files

fix merge master

parents 29648200 91b57f1d
......@@ -1068,6 +1068,7 @@ function getNewsObject(formId, actionType){
newNews = {
text : $(formId+" .get_url_input").val(),
scope : $(formId+" input[name='scope']").val(),
markdownActive: $("#fcn-active-markdown").is(':checked')
};
var actionType=(notNull(actionType))? actionType : "save";
......@@ -1439,4 +1440,36 @@ function deleteImage(id,name,hideMsg,communevent){
);
}
function showNewLinkPreview(newsItem){
//extract all link from news text
var links = newsItem.text.match(/(https?:\/\/[^\s]+)/g)
if(links){
links.forEach(function(link){
$.post("/api/news/getpagecontent",{url:link}, function(data){
var title = $(data).filter('title').text(),
description = $(data).filter('meta[name="description"]').attr("content"),
ogDescription = $(data).filter('meta[property="og:description"]').attr("content"),
image = $(data).filter('meta[property="og:image"]').attr("content"),
url = new URL(link);
var preview = `
<div class="link-preview">
<div class="link-preview-header">
<img class="link-preview-img" src="${image}" alt="">
</div>
<div class="link-preview-body">
<p class="link-preview-domain"><a href="${url.origin}" target="_blank">${url.host}</a></p>
<h4 class="link-preview-title"><a href="${link}" target="_blank">${title}</a></h4>
<p class="link-preview-description">${
description?description:(ogDescription?ogDescription:"")
}</p>
</div>
</div>
`;
$(`#news${newsItem._id.$id} .timeline-body`).append(preview)
})
})
}
}
......@@ -143,6 +143,9 @@ class News {
*/
public static function getNewsForObjectId($param,$sort=array("created"=>-1),$type, $limit=6, $followsArrayIds=null ) {
//$param=array();
$param['type'] = [
'$ne' => ActivityStream::COLLECTION
];
$res = PHDB::findAndSort(self::COLLECTION, $param,$sort,$limit);
return $res;
}
......@@ -222,7 +225,8 @@ class News {
'id'=>@$params["parentId"],
'type'=>@$params["parentType"]
),
"created"=>new MongoDate(time())
"created"=>new MongoDate(time()),
"markdownActive" => isset($params["markdownActive"]) && $params["markdownActive"]
);
if(isset($params["targetIsAuthor"]) && $params["targetIsAuthor"]==true){
......
......@@ -153,6 +153,11 @@ if(isset(Yii::app()->session['userId'])){ ?>
</div>
<?php } ?>
<div style="display: flex; align-items:center; height:32px; padding: 0px 10px;">
<div class="checkbox" style="margin: 0;">
<label><input type="checkbox" value="" id="fcn-active-markdown"><?= Yii::t("news", "Use markdown syntax") ?></label>
</div>
</div>
</div>
<div id='form-news' class="col-xs-12 no-padding">
......@@ -315,4 +320,30 @@ if(isset(Yii::app()->session['userId'])){ ?>
<?php } } ?>
<script type="text/javascript">
var contextScopeNews = <?php echo json_encode($contextScopeNews) ?>;
var tagsManuelSelect = [];
$("textarea#get_url").keyup(function(){
var tagsAuto = $(this).val().match(/#[A-Za-zÀ-ÖØ-öø-ÿ-\d]+/g),
tags = JSON.parse(JSON.stringify(tagsManuelSelect));
if(tagsAuto){
tagsAuto.forEach(function(tag){
tag = tag.replace("#", "")
tags.push({
id: tag,
text: tag
});
})
}
$("#tags").select2("data", tags)
})
$("#tags").on("select2-selecting", function(e){
tagsManuelSelect.push({id:e.val, text:e.val})
}).on("select2-removing", function(e){
$("textarea#get_url").val($("textarea#get_url").val().replaceAll("#"+e.val, ""));
tagsManuelSelect = tagsManuelSelect.filter(function(v){
return v.id !== e.val
})
})
</script>
......@@ -68,12 +68,11 @@ HtmlHelper::registerCssAndScriptsFiles($cssAnsScriptFiles, Yii::app()->request->
<div class="col-xs-12 margin-top-70">
<!-- <h3 class="text-center"><i class="fa fa-newspaper-o"></i> Message</h3><hr> -->
</div>
<div class="container">
<ul class="timeline inline-block" id="news-list">
<?php if(!empty($element)){
$this->renderPartial('news.views.co.timelineTree',
array("news"=>array($element),
array("news"=>array( @(string)$element["_id"] => $element),
"nbCol"=> 1,
"endStream"=>true,
"inline"=>true) );
......@@ -99,7 +98,7 @@ HtmlHelper::registerCssAndScriptsFiles($cssAnsScriptFiles, Yii::app()->request->
var inline=true;
var news=<?php echo json_encode($element); ?>;
jQuery(document).ready(function() {
if(news){
/* if(news){
if(typeof news.text != "undefined"){
var text = news.text.substr(0,30);
if(news.text.length>30) text+="...";
......@@ -116,7 +115,7 @@ HtmlHelper::registerCssAndScriptsFiles($cssAnsScriptFiles, Yii::app()->request->
$(".timeline_text").html(linkify(text));
//showCommentsTools(news["_id"]['$id']);
}
} */
});
</script>
\ No newline at end of file
......@@ -40,6 +40,49 @@ li.timeline-inverted .timeline-panel#nbAbuse4::before{
border-left:0px!important;
}
.link-preview{
width: 100%;
display: flex;
align-items: flex-start;
padding: 15px 5px;
border-bottom: 2px solid rgb(240, 240, 240);
}
.link-preview-img{
width: 120px;
max-height: 100%;
object-fit: cover;
}
.link-preview-body{
padding-left: 15px;
}
.link-preview-title{
margin: 0;
padding: 0;
}
.link-preview-title a{
text-decoration: none;
color: black;
}
.link-preview-description{
margin: 0;
padding: 0;
margin-top: 10px;
color: #555;
}
.link-preview-domain{
margin: 0;
margin-bottom: 5px;
}
.link-preview-domain a{
text-decoration: none;
color: #777;
transition: .3s;
}
.link-preview-domain a:hover{
color: black;
}
</style>
......@@ -206,6 +249,7 @@ foreach($news as $key => $media){
scopes = "",
tagsClass = "",
scopeClass = "";
markdownActive = v.markdownActive;
if(actionController=="save"){
if(nbCol>1)
......@@ -236,7 +280,8 @@ foreach($news as $key => $media){
//Check if @mentions return text with link
if(typeof(v.mentions) != "undefined")
textNews = mentionsInit.addMentionInText(textNews,v.mentions);
textHtml='<span class="timeline_text no-padding text-black" >'+linkify(textNews)+'</span>';
textHtml = `<span class="timeline_text no-padding text-black ${markdownActive?"markdown-body":""}">${markdownActive?linkify(dataHelper.markdownToHtml(textNews)):linkify(textNews)}</span>`;
$("#newsContent"+e).html(textHtml);
$(".btn-showmorenews").off().click(function(){
......@@ -267,6 +312,8 @@ foreach($news as $key => $media){
newsObj.createAndInsertMediaRender(e, v, "file");
}
showNewLinkPreview(v);
coInterface.bindLBHLinks();
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment