-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c87997
commit 5bccf5e
Showing
14 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* CodoLike | ||
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com) | ||
*/ | ||
|
||
class CodoLikeAdapter { | ||
|
||
public function __construct() { | ||
|
||
} | ||
|
||
public function setup_tables() { | ||
|
||
|
||
} | ||
|
||
public function get_user() { | ||
|
||
return \CODOF\User\User::get(); | ||
} | ||
|
||
public function add_js($js) { | ||
|
||
add_js($js, array('type' => 'defer')); | ||
} | ||
|
||
public function add_css($css) { | ||
|
||
add_css($css); | ||
} | ||
|
||
public function get_abs_path() { | ||
|
||
return PLUGIN_PATH . 'codolike/'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* CodoLike | ||
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com) | ||
*/ | ||
|
||
class codolike { | ||
|
||
public static $path = ""; | ||
public static $language = "english"; | ||
public static $like_post_path = ""; | ||
public static $like_update_path = ""; | ||
public static $trans = array(); | ||
public static $db; | ||
public static $db_prefix; | ||
|
||
public static function get_lang() { | ||
|
||
//$codopm_trans is declared in all language files | ||
//For backward compatibility purposes always include english.php | ||
require 'lang/english.php'; | ||
|
||
if (self::$language != "english") { | ||
|
||
//Overwrite english with the new language | ||
require 'lang/' . self::$language . '.php'; | ||
} | ||
|
||
return $codolike_trans; | ||
} | ||
|
||
public static function t($index) { | ||
echo self::s($index); | ||
} | ||
|
||
public static function j($index) { | ||
echo json_encode(self::s($index)); | ||
} | ||
|
||
public static function s($index) { | ||
|
||
if (!self::$trans) self::$trans = self::get_lang(); | ||
|
||
if (isset(self::$trans[$index])) | ||
return self::$trans[$index]; | ||
|
||
return $index; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* CodoLike | ||
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com) | ||
*/ | ||
?> | ||
<script type="text/javascript"> | ||
codo_defs.trans.notify.new_like=<?php codolike::j('New like') ?>; | ||
codo_defs.trans.notify.new_like_action=<?php codolike::j('clicked like in') ?>; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* CodoLike | ||
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com) | ||
*/ | ||
?> | ||
<script type="text/javascript"> | ||
CODOF.hook.add('on_scripts_loaded', function () { | ||
|
||
jQuery('.codo_posts_post_foot').each(function () { | ||
var $me = jQuery(this); | ||
$me.html('<div class="codo_like_users"></div>'+$me.html()); | ||
}); | ||
|
||
jQuery('.codo_posts_post_action').each(function () { | ||
|
||
var $me = jQuery(this); | ||
var html = $me.html(); | ||
|
||
html = '' | ||
+ '<div class="btn-group codo_like_btn_group">' | ||
+ '<div class="codo_btn_def codo_like_btn"><i class="glyphicon glyphicon-thumbs-up"></i></div>' | ||
+ '<div class="codo_btn_def codo_btn codo_like_counter"><img src="<?php echo codolike::$path ?>client/img/ajax-loader.gif" /></div>' | ||
+ '<div class="codo_btn_primary codo_btn codo_like_btn"><?php codolike::t('like') ?></div>' | ||
+ '</div>' | ||
+ html; | ||
|
||
$me.html(html); | ||
|
||
var postId = parseInt($me.parents('article').attr('id').replace('post-', '')); | ||
$me.children('.codo_like_btn_group').click(function () { | ||
jQuery('#post-'+postId+' .codo_like_counter').html('<img src="<?php echo codolike::$path ?>client/img/ajax-loader.gif" />'); | ||
|
||
jQuery.getJSON( "<?php echo codolike::$like_post_path ?>&id="+postId, function(data) { | ||
if (!data.success) | ||
alert(data.message); | ||
|
||
codolike_update_likes(postId); | ||
}); | ||
}); | ||
}); | ||
|
||
var articles = new Array(); | ||
jQuery('article').each(function () { | ||
var $me = jQuery(this); | ||
var postId = parseInt($me.attr('id').replace('post-', '')); | ||
|
||
articles.push(postId); | ||
}); | ||
|
||
codolike_update_likes(articles); | ||
|
||
function codolike_update_likes(ids) | ||
{ | ||
jQuery.getJSON( "<?php echo codolike::$like_update_path ?>&ids="+ids, function( data ) { | ||
jQuery.each(data, function(key, val) { | ||
jQuery('#post-'+key+' .codo_like_counter').html(val.count); | ||
|
||
var l = new Array(); | ||
for (var i=0; i<val.users.length; i++) | ||
l.push('<a href="<?php echo RURI ?>user/profile/'+ val.users[i].id+'">'+val.users[i].name+'</a>') | ||
|
||
if (l.length) | ||
jQuery('#post-'+key+' .codo_like_users').html(<?php echo codolike::j('Likes to: ') ?>+'<span>'+l.join(', ')+'</span>'); | ||
}); | ||
}); | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.codo_posts_post_action .glyphicon { | ||
color: #333333; | ||
} | ||
|
||
.codo_like_counter { | ||
line-height: 20px; | ||
background: #cccccc; | ||
color: #333333; | ||
width: 40px; | ||
border-radius: 0 0 0 0 !important; | ||
} | ||
|
||
.codo_like_users { | ||
float: left; | ||
font-size: 11px; | ||
} | ||
|
||
.codo_like_users span { | ||
color: #dddddd; | ||
font-weight: bold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html><body bgcolor="#FFFFFF"></body></html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* CodoLike | ||
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com) | ||
*/ | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/** | ||
* CodoLike | ||
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com) | ||
*/ | ||
|
||
$info['name'] = 'codoLike'; | ||
$info['description'] = 'Like plugin for codoforum'; | ||
$info['version'] = '2.x'; | ||
$info['author'] = "Riccardo Tempesta"; | ||
$info['author_url'] = 'http://www.riccardotempesta.com'; | ||
$info['license'] = 'GNU GPL V3'; | ||
$info['core'] = '2.x'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* CodoLike | ||
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com) | ||
*/ | ||
|
||
require_once('adapters/Codoforum.php'); | ||
require_once('arg.php'); | ||
require_once('server/codolike.php'); | ||
|
||
$codoLikeAdapter = new CodoLikeAdapter(); | ||
$codoLikeAdapter->setup_tables(); | ||
codolike::$path = $codoLikeAdapter->get_abs_path(); | ||
codolike::$db_prefix = PREFIX . 'codo_'; | ||
codolike::$like_post_path = RURI . 'codolike/like'; | ||
codolike::$like_update_path = RURI . 'codolike/update'; | ||
codolike::$db = \DB::getPDO(); | ||
|
||
function codolike_add_assets() { | ||
|
||
$codoLikeAdapter = new CodoLikeAdapter(); | ||
$codoLikeAdapter->add_css(codolike::$path . "client/css/app.css"); | ||
$codoLikeAdapter->add_js("http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"); | ||
$codoLikeAdapter->add_js(codolike::$path . "client/js/app.js"); | ||
} | ||
|
||
|
||
function codolike_like_js() { | ||
|
||
include("block/like_js.php"); | ||
} | ||
|
||
function codolike_body_start() { | ||
|
||
include('block/body_start.php'); | ||
|
||
} | ||
|
||
function codolike_after_notify_insert() { | ||
$notifier = new \CODOF\Forum\Notification\Notifier(); | ||
|
||
$res = codolike::$db->query( | ||
"SELECT " | ||
."q.id, q.nid, t.data, q.type " | ||
."FROM ".PREFIX."codo_notify_queue as q " | ||
."INNER JOIN codo_notify_text as t on " | ||
."q.nid=t.id " | ||
."where q.type='new_like'"); | ||
|
||
$queue = $res->fetchAll(); | ||
foreach ($queue as $queuedLike) { | ||
$data = json_decode($queuedLike['data'], true); | ||
$notifier->notify(array($data['puid']), $queuedLike['type'], $queuedLike['nid']); | ||
|
||
// Automatically dequeue notification | ||
codolike::$db->query("delete from ".PREFIX."codo_notify_queue where id=".intval($queuedLike['id'])); | ||
} | ||
} | ||
|
||
\CODOF\Hook::add('block_body_start', 'codolike_body_start'); | ||
\CODOF\Hook::add('block_topic_info_after', 'codolike_like_js'); | ||
\CODOF\Hook::add('tpl_before_forum_topic', 'codolike_add_assets'); | ||
\CODOF\Hook::add('after_like_post', 'codolike_after_notify_insert'); // This runs just before item queue deletion | ||
//\CODOF\Hook::add('on_cron_notify_new_like', array(new \CODOF\Forum\Notification\Notifier, 'dequeueNotify')); | ||
|
||
dispatch("codolike/like", function(){ | ||
$codoLikeAdapter = new CodoLikeAdapter(); | ||
echo json_encode(codolike_add_like($codoLikeAdapter->get_user(), $_GET['id'])); | ||
}); | ||
|
||
dispatch("codolike/update", function(){ | ||
$codoLikeAdapter = new CodoLikeAdapter(); | ||
echo json_encode(codolike_get_likes($codoLikeAdapter->get_user()->id, $_GET['ids'])); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html><body bgcolor="#FFFFFF"></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
Schema::create('codolike_likes', function($table) { | ||
$table->increments('id'); | ||
$table->integer('user_id'); | ||
$table->integer('post_id'); | ||
$table->dateTime('created_at')->default('0000-00-00 00:00:00'); | ||
$table->string('ip', 255); | ||
}); | ||
|
||
DB::update('create unique index post_uidx on codolike_likes(user_id, post_id)'); | ||
DB::update('create index post_idx on codolike_likes(post_id)'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
/** | ||
* CodoLike | ||
* @copyright Copyright (c) 2015 Riccardo Tempesta (http://www.riccardotempesta.com) | ||
*/ | ||
|
||
$codolike_trans['like'] = 'like'; |
Oops, something went wrong.