author | Dan |
Sun, 09 Dec 2007 20:27:16 -0500 | |
changeset 2 | b0e58c67304b |
parent 1 | 7785b3e99977 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/* |
|
3 |
Plugin Name: AjIM Enano Module |
|
4 |
Plugin URI: http://enanocms.org/AjIM |
|
5 |
Description: AjIM is an AJAX-based chatroom system which was designed to be integrated with other web apps like Enano and phpBB. It's very simple to write bindings for AjIM and it doesn't use that much code which makes it pretty fast. |
|
6 |
Author: Dan Fuhry |
|
7 |
Version: 1.0 |
|
8 |
Author URI: http://enanocms.org/ |
|
9 |
*/ |
|
10 |
||
11 |
if(!defined('_AJIM_INCLUDED')) |
|
12 |
{ |
|
13 |
define('_AJIM_INCLUDED', ''); |
|
14 |
||
15 |
// Change this line to wherever your AjIM installation is |
|
16 |
||
17 |
if(defined('scriptPath')) |
|
18 |
define('ajimClientPath', scriptPath.'/ajim'); |
|
19 |
||
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
20 |
// if(!defined('ENANO_ROOT')) |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
21 |
// define('ENANO_ROOT', dirname(dirname(__FILE__))); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
22 |
|
0 | 23 |
global $db, $session, $paths, $template, $plugins; // Common objects |
24 |
$__ajim_config = Array( |
|
25 |
'sb_color_background'=>'#FFF', |
|
26 |
'sb_color_foreground'=>'#000', |
|
27 |
); |
|
28 |
if(defined('ENANO_INSTALLED') || defined('MIDGET_INSTALLED')) |
|
29 |
{ |
|
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
30 |
define('ajimServerPath', ENANO_ROOT.'/ajim'); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
31 |
|
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
32 |
$plugins->attachHook('compile_template', 'AjIM_SideBar();'); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
33 |
$plugins->attachHook('acl_rule_init', 'global $session; $session->register_acl_type(\'ajim_post\', AUTH_ALLOW, \'Submit AjIM posts\');'); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
34 |
require_once(ajimServerPath . '/ajim.php'); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
35 |
|
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
36 |
function AjIM_SideBar() |
0 | 37 |
{ |
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
38 |
global $db, $session, $paths, $template, $plugins; // Common objects |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
39 |
global $__ajim_config; |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
40 |
$paths->addAdminNode('Plugin configuration', 'AjIM configuration', 'AjIM_Config'); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
41 |
$dir = getcwd(); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
42 |
chdir(ENANO_ROOT); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
43 |
include('config.php'); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
44 |
chdir($dir); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
45 |
unset($dir); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
46 |
if($session->user_level >= USER_LEVEL_ADMIN) |
0 | 47 |
{ |
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
48 |
$r = $db->sql_query('SELECT password FROM '.table_prefix.'users WHERE username=\''.$session->username.'\''); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
49 |
$p = $db->fetchrow_num($r); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
50 |
$admin = $p[0]; |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
51 |
} |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
52 |
else |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
53 |
{ |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
54 |
$admin = false; |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
55 |
} |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
56 |
$__ajim_config['db_connection_handle'] = $db->_conn; |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
57 |
if(!$session->user_logged_in) |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
58 |
{ |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
59 |
$__ajim_config['cant_post_notice'] = 'The administrator requires that you <a href="'.makeUrlNS('Special', 'Login/'.$paths->page, null, true).'">log in</a> to post messages.'; |
0 | 60 |
} |
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
61 |
else |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
62 |
{ |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
63 |
$__ajim_config['cant_post_notice'] = 'The administrator has disallowed message posting for your user account.'; |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
64 |
} |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
65 |
$canpost = ( $session->get_permissions('ajim_post') ) ? true : false; |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
66 |
$ajim = new ajim($__ajim_config, table_prefix, scriptPath.'/plugins/ajim.php', $admin, false, $canpost, array('RenderMan', 'render')); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
67 |
$template->sidebar_widget('Shoutbox', $ajim->html(ajimClientPath)); |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
68 |
$template->additional_headers .= '<link rel="stylesheet" type="text/css" href="'.ajimClientPath.'/ajim.php?css&id='.$ajim->id.'&pfx='.table_prefix.'&path='.scriptPath.'/plugins/ajim.php" />'; |
0 | 69 |
} |
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
70 |
} |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
71 |
elseif ( isset($_GET['ajimmode']) ) |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
72 |
{ |
0 | 73 |
global $db, $session, $paths, $template, $plugins, $dbhost, $dbname, $dbuser, $dbpasswd; |
74 |
require_once('../includes/common.php'); |
|
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
75 |
define('ajimServerPath', ENANO_ROOT.'/ajim'); |
0 | 76 |
require_once(ajimServerPath . '/ajim.php'); |
77 |
header('HTTP/1.1 200 OK'); |
|
78 |
define('ajimClientPath', scriptPath.'/ajim'); |
|
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
79 |
if ( $session->user_level >= USER_LEVEL_ADMIN ) |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
80 |
{ |
0 | 81 |
$admin = $session->grab_password_hash(); |
1
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
82 |
} |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
83 |
else |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
84 |
{ |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
85 |
$admin = false; |
7785b3e99977
Updated for compatibility with newer Enano releases. Oops.
Dan
parents:
0
diff
changeset
|
86 |
} |
0 | 87 |
require('../config.php'); |
88 |
$canpost = (getConfig('ajim_require_login') != '1' || $session->user_logged_in) ? true : false; |
|
89 |
$__ajim_config['db_connection_handle'] = $db->_conn; |
|
90 |
$__ajim_config['cant_post_notice'] = 'The administrator requires that you <a href="'.makeUrlNS('Special', 'Login/'.$paths->page, null, true).'">log in</a> to post messages.'; |
|
91 |
$__ajim_config['allow_looping'] = true; |
|
92 |
$ajim = new ajim($__ajim_config, table_prefix, scriptPath.'/plugins/ajim.php', $admin, $_GET['id'], $canpost, array('RenderMan', 'render')); |
|
93 |
$db->close(); |
|
94 |
exit; |
|
95 |
} |
|
96 |
||
97 |
function page_Admin_AjIM_Config() |
|
98 |
{ |
|
99 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
100 |
if(isset($_POST['_save'])) |
|
101 |
{ |
|
102 |
setConfig('ajim_require_login', ( isset($_POST['ajim_require_login']) ) ? '1' : '0'); |
|
103 |
} |
|
104 |
echo '<form name="main" action="'.makeUrl($paths->nslist['Special'].'Administration?module='.$paths->cpage['module']).'" method="post">'; |
|
105 |
?> |
|
106 |
<h3>Configure AjIM, the Asynchronous Javascript Instant Messenger</h3> |
|
107 |
<p>Only one option right now...</p> |
|
108 |
<p><label><input type="checkbox" name="ajim_require_login" <?php if(getConfig('ajim_require_login')=='1') echo 'checked="checked" '; ?>/>Only logged-in users can post</label></p> |
|
109 |
<p><input type="submit" name="_save" value="Save changes" /> |
|
110 |
<?php |
|
111 |
echo '</form>'; |
|
112 |
} |
|
113 |
} |
|
114 |
?> |