Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Dec 14, 2014
1 parent 3c87997 commit 5bccf5e
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 0 deletions.
38 changes: 38 additions & 0 deletions adapters/Codoforum.php
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/';
}

}
49 changes: 49 additions & 0 deletions arg.php
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;
}
}
10 changes: 10 additions & 0 deletions block/body_start.php
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>
69 changes: 69 additions & 0 deletions block/like_js.php
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>
21 changes: 21 additions & 0 deletions client/css/app.css
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;
}
1 change: 1 addition & 0 deletions client/css/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
Binary file added client/img/ajax-loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions client/js/app.js
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)
*/



13 changes: 13 additions & 0 deletions codolike.info.php
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';
74 changes: 74 additions & 0 deletions codolike.php
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']));
});
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
12 changes: 12 additions & 0 deletions install/1.0.php
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)');
7 changes: 7 additions & 0 deletions lang/english.php
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';
Loading

0 comments on commit 5bccf5e

Please sign in to comment.