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