plugins/ajim.php
author Dan
Sat, 08 Dec 2007 13:25:13 -0500
changeset 1 7785b3e99977
parent 0 2f9b67edc9b1
permissions -rw-r--r--
Updated for compatibility with newer Enano releases. Oops.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     1
<?php
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     2
/*
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     3
Plugin Name: AjIM Enano Module
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     4
Plugin URI: http://enanocms.org/AjIM
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     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.
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     6
Author: Dan Fuhry
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     7
Version: 1.0
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     8
Author URI: http://enanocms.org/
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
     9
*/
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    10
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    11
if(!defined('_AJIM_INCLUDED'))
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    12
{
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    13
  define('_AJIM_INCLUDED', '');
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    14
  
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    15
  // Change this line to wherever your AjIM installation is
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    16
  
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    17
  if(defined('scriptPath'))
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    18
    define('ajimClientPath', scriptPath.'/ajim');
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    23
  global $db, $session, $paths, $template, $plugins; // Common objects
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    24
  $__ajim_config = Array(
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    25
    'sb_color_background'=>'#FFF',
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    26
    'sb_color_foreground'=>'#000',
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    27
    );
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    28
  if(defined('ENANO_INSTALLED') || defined('MIDGET_INSTALLED'))
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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&amp;id='.$ajim->id.'&amp;pfx='.table_prefix.'&amp;path='.scriptPath.'/plugins/ajim.php" />';
0
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    73
    global $db, $session, $paths, $template, $plugins, $dbhost, $dbname, $dbuser, $dbpasswd;
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    76
    require_once(ajimServerPath . '/ajim.php');
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    77
    header('HTTP/1.1 200 OK');
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    87
    require('../config.php');
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    88
    $canpost = (getConfig('ajim_require_login') != '1' || $session->user_logged_in) ? true : false;
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    89
    $__ajim_config['db_connection_handle'] = $db->_conn;
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    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.';
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    91
    $__ajim_config['allow_looping'] = true;
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    92
    $ajim = new ajim($__ajim_config, table_prefix, scriptPath.'/plugins/ajim.php', $admin, $_GET['id'], $canpost, array('RenderMan', 'render'));
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    93
    $db->close();
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    94
    exit;
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    95
  }
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    96
  
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    97
  function page_Admin_AjIM_Config()
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    98
  {
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
    99
    global $db, $session, $paths, $template, $plugins; // Common objects
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   100
    if(isset($_POST['_save']))
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   101
    {
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   102
      setConfig('ajim_require_login', ( isset($_POST['ajim_require_login']) ) ? '1' : '0');
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   103
    }
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   104
    echo '<form name="main" action="'.makeUrl($paths->nslist['Special'].'Administration?module='.$paths->cpage['module']).'" method="post">';
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   105
    ?>
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   106
    <h3>Configure AjIM, the Asynchronous Javascript Instant Messenger</h3>
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   107
     <p>Only one option right now...</p>
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   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>
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   109
     <p><input type="submit" name="_save" value="Save changes" />
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   110
    <?php
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   111
    echo '</form>';
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   112
  }
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   113
}
2f9b67edc9b1 Initial repository population
dan@fuhry
parents:
diff changeset
   114
?>