Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
First zk1.3 code commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilBau committed Jan 3, 2013
1 parent 1a50ba1 commit e0b41c3
Show file tree
Hide file tree
Showing 13 changed files with 721 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// File : $Id$

1.0 - Initial Release
2.x - API compliant Zikula v.1.2.x requires core version 1.2.0 minimum
3.0 - API compliant Zikula v.1.3.x requires core version 1.3.0 minimum
- Zikula 1.3 native refactor
- New features: - Send a message to a specific group only
- Block settings available : length of a message,
number of messages displayed,
refresh rate (common to all Shoutit blocks)
17 changes: 17 additions & 0 deletions docs/credits.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Shoutit 2.x & 3.x:
-------------------
Gabriel Freinbichler
Philippe Baudrion - UniGE/FTI: Zikula 1.3.x refactoring

shoutit 1.x:
--------------

People who support me with code or ideas:
-----------------------------------------

Karl Pütz aka Charlie
Frank Schummertz aka Landseer
Sascha Jost aka Lindbergh
Axel Guckelsberger aka guite
Steffen Voß aka kaffeeringe.de
Yentl K. Langholz aka TheRealOne
13 changes: 13 additions & 0 deletions docs/install.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// File : $Id$
Installation like any other Zikula modules
The "group messages" setting requires permission: ('Groups::', '::', ACCESS_READ)

TO-KNOW

Permission scheme
-----------------
ACCESS_OVERVIEW : minimal access to display the block
ACCESS_COMMENT : minimal access to post
if "Owner and group messages" is checked, users can read and post to restricted groups only
ACCESS_MODERATE : if "Owner and group messages" is checked, no restriction is applied users view all messages and can post in all groups.
ACCESS_DELETE : minimal access to clear the block content
86 changes: 86 additions & 0 deletions javascript/Shoutit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Shoutit module for Zikula Application Framework
* @author Gabriel Freinbichler
* refactored for zk 1.3 by Philippe Baudrion - UniGE/FTI
*/
var shoutit = Class.create({
initialize: function(bid, refRate, msgLength, postPerm, grpMsg) {
this.bid = bid;
this.refRate = refRate;
this.msgLength = msgLength;
this.postPerm = postPerm;
this.grpMsg = grpMsg;

this.getData();

if (this.postPerm == 1) {
$('shoutitsend_' + this.bid).observe('click', function(){this.saveData();}.bindAsEventListener(this));
$('shoutitsend_' + this.bid).observe('keypress', function(){this.saveData();}.bindAsEventListener(this));
}
},

getData: function() {

this.updater = new Ajax.PeriodicalUpdater(
'shoutitcontent_' + this.bid,
Zikula.Config.baseURL + 'ajax.php?module=Shoutit&func=getmessages',
{
method: 'post',
parameters: {bid: this.bid},
frequency: this.refRate
}
);
},

saveData: function() {
this.updater.stop();

if(this.grpMsg) {
var e = $('shoutitgroup_' + this.bid)[$('shoutitgroup_' + this.bid).selectedIndex].value;
}
var m = $('shoutitmessage_' + this.bid).value;

if (((this.grpMsg == '1' && e != '-') && m != '') ||
(this.grpMsg == '0' && m != '')) {
new Zikula.Ajax.Request(
Zikula.Config.baseURL + "ajax.php?module=Shoutit&func=savemessages",
{
method: 'post',
parameters:
{
bid: this.bid,
gid: e,
message: m
},
onComplete: this.updater.start()
}
);

// form reset
$('shoutitmessage_' + this.bid).value = '';
$('shoutitcounter_' + this.bid).value = this.msgLength;
if(this.grpMsg) {
$('shoutitgroup_' + this.bid).value = '-';
}
}
else if (this.grpMsg == '1' && e == '-' || m == '') {
alert("Please select a group and write a message before sending!");
}
else if (this.grpMsg == '0' && m == '') {
alert("Please write a message before sending!");
}

$('shoutitmessage_' + this.bid).focus();
},

textCounter: function() {
// if too long...trim it!
if ($('shoutitmessage_' + this.bid).value.length > this.msgLength) {
$('shoutitmessage_' + this.bid).value = $('shoutitmessage_' + this.bid).value.substring(0, this.msgLength);
$('shoutitmessage_' + this.bid).setSelectionRange(this.msgLength, this.msgLength);
// otherwise, update 'characters left' counter
} else {
$('shoutitcounter_' + this.bid).value = this.msgLength - $('shoutitmessage_' + this.bid).value.length;
}
}
});
123 changes: 123 additions & 0 deletions lib/Shoutit/Api/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/**
* Shoutit module for Zikula Application Framework
*
* @author Gabriel Freinbichler
* refactored for zk 1.3 by Philippe Baudrion - UniGE/FTI
* @link http://www.cmods-dev.de
* @copyright Copyright (C) by Gabriel Freinbichler
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @version $Id$
*/

/**
* User API
*/
class Shoutit_Api_User extends Zikula_AbstractApi
{
/**
* Get all allowed messages from the database
* @param array $args['bid']
* @return array $messages
*/
public function getMessages($args) {

if (!isset($args['bid'])) {
return LogUtil::registerArgsError();
}

$bid = $args['bid'];
$messages = array();

$tables = DBUtil::getTables();
$shColumn = $tables['shoutit_messages_column'];
$orderBy= "ORDER BY $shColumn[cr_date] DESC";
$limitNumRows = ModUtil::getVar('Shoutit', "shoutit_lastx_messages_{$bid}");
$where = '';
$joinInfo[] = array (
'join_table' => 'users', // table for the join
'join_field' => 'uname', // field in the join table that should be in the result with
'object_field_name' => 'uname', // ...this name for the new column
'compare_field_table' => 'cr_uid', // regular table column that should be equal to
'compare_field_join' => 'uid' // ...the table in join_table
);

// Only select user own messages and messages from own registered group(s)
if(ModUtil::getVar('Shoutit', "shoutit_group_messages_{$bid}") == '1' &&
!SecurityUtil::checkPermission('Shoutit::', $bid.'::', ACCESS_MODERATE)) {

$uid = UserUtil::getVar('uid');
$where = "WHERE $shColumn[cr_uid] = $uid";

// Zikula Groups API: get user groups membership
// requires SecurityUtil::checkPermission('Groups::', '::', ACCESS_READ)
$groups = ModUtil::apiFunc('Groups', 'user', 'getusergroups', array('uid' => $uid));

foreach ($groups as $group) {
// remove Users and Administrators groups
if($group['gid'] != '1' && $group['gid'] != '2') {
$where .= " OR {$shColumn['gid']} = {$group['gid']} AND {$shColumn['cr_uid']} <> {$uid}";
}
}
} else {// get last x messages from all for "moderate" users
}

$messages = DBUtil::selectExpandedObjectArray('shoutit_messages', $joinInfo, $where, $orderBy, '', $limitNumRows);

return $messages;
}

/**
* Function to store one message in the database
*
* @param array $args[bid], $args[message], $args[gid]: optional
* @return boolean
*/
public function saveMessages($args)
{
if (!isset($args['bid']) ||
!isset($args['message'])) {
return LogUtil::registerArgsError();
}

$bid = $args['bid'];

$record = array(
'message' => $args['message'],
'bid' => $args['bid'],
'gid' => $args['gid'],
);

$result = DBUtil::insertObject($record, 'shoutit_messages');

return $result;
}

/**
* Function to clear messages out of the database
* @param integer $args['bid']
* @return boolean
*/
public function deleteMessages($args) {

if (!is_numeric($args['bid'])){
return LogUtil::registerArgsError();
}

$this->throwForbiddenUnless(SecurityUtil::checkPermission('Shoutit::', $args['bid'].'::', ACCESS_DELETE), LogUtil::getErrorMsgPermission());

$tables = DBUtil::getTables();
$shColumns = $tables['shoutit_messages_column'];
$where = "WHERE $shColumns[bid] = $args[bid]";

if(!DBUtil::deleteWhere('shoutit_messages', $where)) {
return LogUtil::registerError ($this->__('Error! Update attempt failed.'));
}

LogUtil::registerStatus($this->__f("Done! Messages from block id '%s' deleted.", $args[bid]));

return true;
}
// end of class
}
?>
Loading

0 comments on commit e0b41c3

Please sign in to comment.