Skip to content

Commit

Permalink
1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lianglee committed Feb 5, 2021
1 parent 3399faf commit 067a619
Show file tree
Hide file tree
Showing 7 changed files with 1,847 additions and 0 deletions.
101 changes: 101 additions & 0 deletions ossn_com.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* Open Source Social Network
*
* @package (softlab24.com).ossn
* @author OSSN Core Team <[email protected]>
* @copyright 2014-2018 SOFTLAB24 LIMITED
* @license Open Source Social Network License (OSSN LICENSE) http://www.opensource-socialnetwork.org/licence
* @link http://www.opensource-socialnetwork.org/
*/
define('Mentions', ossn_route()->com . 'Mentions/');
/**
* Mentions Init
*
* @return void
*/
function mentions_init() {
ossn_extend_view('js/opensource.socialnetwork', 'mentions/js');
ossn_extend_view('css/ossn.default', 'mentions/css');

if(ossn_isLoggedin()) {
ossn_load_external_js('jquery.caret.js');
ossn_load_external_js('jquery.atwho.js');
ossn_load_external_css('jquery.atwho.css');

ossn_register_page('mentions_picker', 'mentions_picker');

ossn_add_hook('comment:view', 'template:params', 'mentions_tag_user', 150);

ossn_new_external_js('jquery.caret.js', ossn_add_cache_to_url('components/Mentions/vendors/jquery.caret.js'));
ossn_new_external_js('jquery.atwho.js', ossn_add_cache_to_url('components/Mentions/vendors/jquery.atwho.js'));

ossn_new_external_css('jquery.atwho.css', ossn_add_cache_to_url('components/Mentions/vendors/jquery.atwho.css'));
}
}
/**
* Replace in the comments
*
* @param string $hook comment:view
* @param string $callback template:params
* @param array $params Comment Data
*
* @return array
*/
function mentions_tag_user($hook, $type, $return, $params) {
if(isset($return['comment']['comments:entity'])) {
$return['comment']['comments:entity'] = mentions_replace_usernames($return['comment']['comments:entity']);
}
if(isset($return['comment']['comments:post'])) {
$return['comment']['comments:post'] = mentions_replace_usernames($return['comment']['comments:post']);
}
return $return;
}
/**
* Replace @mention with profile URL
*
* @return string|string
*/
function mentions_replace_usernames($text) {
$url = ossn_site_url('u/');
return preg_replace('/@(\w+)/', " <a class='mentions-user' href='{$url}$1'>$1</a>", $text);
}
/**
* Mentions Picker
* Copied from OssnWall friends picker added username
*
* return void
*/
function mentions_picker() {
header('Content-Type: application/json');
if(!ossn_isLoggedin()) {
exit();
}
$user = new OssnUser();
$friends = $user->getFriends(ossn_loggedin_user()->guid);
if(!$friends) {
return false;
}
$search_for = input('q');
// allow case insensitivity with first typed in char
$fc = mb_strtoupper(mb_substr($search_for, 0, 1, 'UTF-8'), 'UTF-8');
$search_For = $fc . mb_substr($search_for, 1, null, 'UTF-8');
// show all friends with wildcard '*' in first place
if($search_for == '*') {
$search_for = '';
$search_For = '';
}
$search_len = mb_strlen($search_for, 'UTF-8');
foreach ($friends as $users) {
$first_name_start = mb_substr($users->first_name, 0, $search_len, 'UTF-8');
if($first_name_start == $search_for || $first_name_start == $search_For) {
$p['first_name'] = $users->first_name;
$p['last_name'] = $users->last_name;
$p['imageurl'] = $users->iconURL()->smaller;
$p['username'] = $users->username;
$usera[] = $p;
}
}
echo json_encode($usera);
}
ossn_register_callback('ossn', 'init', 'mentions_init');
15 changes: 15 additions & 0 deletions ossn_com.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<component xmlns="http://www.opensource-socialnetwork.org/v/3.0">
<name>Mentions</name>
<id>Mentions</id>
<author>Core Team</author>
<description>Mention users.</description>
<license>Open Source Social Network License (OSSN LICENSE)</license>
<author_url>http://www.opensource-socialnetwork.org</author_url>
<license_url>http://www.opensource-socialnetwork.org/licence/</license_url>
<version>1.0</version>
<requires>
<type>ossn_version</type>
<version>5.6</version>
</requires>
</component>
10 changes: 10 additions & 0 deletions plugins/default/mentions/css.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.mentions {
background:#1877f233;
}
.mentions-user:hover,
.mentions-user {
font-weight: bold;
font-style: italic;
color: #2d89ff;
text-decoration:none;
}
11 changes: 11 additions & 0 deletions plugins/default/mentions/js.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//<script>
$(document).ready(function(){
if(typeof $.fn.atwho !== 'undefined'){
$('.comment-box').atwho({
at: "@",
insertTpl: '<span class="mentions">@${username}</span>',
displayTpl: "<li><img src='${imageurl}' height='20' width='20'/> ${first_name} ${last_name}</li>",
data: Ossn.site_url+"mentions_picker",
});
}
});
75 changes: 75 additions & 0 deletions vendors/jquery.atwho.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
.atwho-view {
position:absolute;
top: 0;
left: 0;
display: none;
margin-top: 18px;
background: white;
color: black;
border: 1px solid #DDD;
border-radius: 3px;
box-shadow: 0 0 5px rgba(0,0,0,0.1);
min-width: 120px;
z-index: 11110 !important;
}

.atwho-view .atwho-header {
padding: 5px;
margin: 5px;
cursor: pointer;
border-bottom: solid 1px #eaeff1;
color: #6f8092;
font-size: 11px;
font-weight: bold;
}

.atwho-view .atwho-header .small {
color: #6f8092;
float: right;
padding-top: 2px;
margin-right: -5px;
font-size: 12px;
font-weight: normal;
}

.atwho-view .atwho-header:hover {
cursor: default;
}

.atwho-view .cur {
background: #3366FF;
color: white;
}
.atwho-view .cur small {
color: white;
}
.atwho-view strong {
color: #3366FF;
}
.atwho-view .cur strong {
color: white;
font:bold;
}
.atwho-view ul {
/* width: 100px; */
list-style:none;
padding:0;
margin:auto;
max-height: 200px;
overflow-y: auto;
}
.atwho-view ul li {
display: block;
padding: 5px 10px;
border-bottom: 1px solid #DDD;
cursor: pointer;
/* border-top: 1px solid #C8C8C8; */
}
.atwho-view small {
font-size: smaller;
color: #777;
font-weight: normal;
}
.mention {

}
Loading

0 comments on commit 067a619

Please sign in to comment.