|
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 |
|
20 if(!defined('ENANO_ROOT')) |
|
21 define('ENANO_ROOT', dirname(dirname(__FILE__))); |
|
22 define('ajimServerPath', ENANO_ROOT.'/ajim'); |
|
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 { |
|
30 if(!isset($_GET['admin'])) |
|
31 { |
|
32 $plugins->attachHook('compile_template', 'AjIM_SideBar();'); |
|
33 $plugins->attachHook('acl_rule_init', 'global $session; $session->register_acl_type(\'ajim_post\', AUTH_ALLOW, \'Submit AjIM posts\');'); |
|
34 include(ajimServerPath . '/ajim.php'); |
|
35 |
|
36 function AjIM_SideBar() |
|
37 { |
|
38 global $db, $session, $paths, $template, $plugins; // Common objects |
|
39 global $__ajim_config; |
|
40 $paths->addAdminNode('Plugin configuration', 'AjIM configuration', 'AjIM_Config'); |
|
41 $dir = getcwd(); |
|
42 chdir(ENANO_ROOT); |
|
43 include('config.php'); |
|
44 chdir($dir); |
|
45 unset($dir); |
|
46 if($session->user_level >= USER_LEVEL_ADMIN) |
|
47 { |
|
48 $r = $db->sql_query('SELECT password FROM '.table_prefix.'users WHERE username=\''.$session->username.'\''); |
|
49 $p = $db->fetchrow_num($r); |
|
50 $admin = $p[0]; |
|
51 } |
|
52 else |
|
53 { |
|
54 $admin = false; |
|
55 } |
|
56 $__ajim_config['db_connection_handle'] = $db->_conn; |
|
57 if(!$session->user_logged_in) |
|
58 { |
|
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.'; |
|
60 } |
|
61 else |
|
62 { |
|
63 $__ajim_config['cant_post_notice'] = 'The administrator has disallowed message posting for your user account.'; |
|
64 } |
|
65 $canpost = ( $session->get_permissions('ajim_post') ) ? true : false; |
|
66 $ajim = new ajim($__ajim_config, table_prefix, scriptPath.'/plugins/ajim.php', $admin, false, $canpost, array('RenderMan', 'render')); |
|
67 $template->sidebar_widget('Shoutbox', $ajim->html(ajimClientPath)); |
|
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" />'; |
|
69 } |
|
70 } |
|
71 } elseif(isset($_GET['ajimmode'])) { |
|
72 global $db, $session, $paths, $template, $plugins, $dbhost, $dbname, $dbuser, $dbpasswd; |
|
73 require_once('../includes/common.php'); |
|
74 require_once(ajimServerPath . '/ajim.php'); |
|
75 header('HTTP/1.1 200 OK'); |
|
76 define('ajimClientPath', scriptPath.'/ajim'); |
|
77 if($session->user_level >= USER_LEVEL_ADMIN) { |
|
78 $admin = $session->grab_password_hash(); |
|
79 } else $admin = false; |
|
80 require('../config.php'); |
|
81 $canpost = (getConfig('ajim_require_login') != '1' || $session->user_logged_in) ? true : false; |
|
82 $__ajim_config['db_connection_handle'] = $db->_conn; |
|
83 $__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.'; |
|
84 $__ajim_config['allow_looping'] = true; |
|
85 $ajim = new ajim($__ajim_config, table_prefix, scriptPath.'/plugins/ajim.php', $admin, $_GET['id'], $canpost, array('RenderMan', 'render')); |
|
86 $db->close(); |
|
87 exit; |
|
88 } |
|
89 |
|
90 function page_Admin_AjIM_Config() |
|
91 { |
|
92 global $db, $session, $paths, $template, $plugins; // Common objects |
|
93 if(isset($_POST['_save'])) |
|
94 { |
|
95 setConfig('ajim_require_login', ( isset($_POST['ajim_require_login']) ) ? '1' : '0'); |
|
96 } |
|
97 echo '<form name="main" action="'.makeUrl($paths->nslist['Special'].'Administration?module='.$paths->cpage['module']).'" method="post">'; |
|
98 ?> |
|
99 <h3>Configure AjIM, the Asynchronous Javascript Instant Messenger</h3> |
|
100 <p>Only one option right now...</p> |
|
101 <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> |
|
102 <p><input type="submit" name="_save" value="Save changes" /> |
|
103 <?php |
|
104 echo '</form>'; |
|
105 } |
|
106 } |
|
107 ?> |