Permalink
Browse files

refactoring: server-slim replaces server

  • Loading branch information...
1 parent 09fcaef commit b148501788d8adc18deea26fffa8385ba3de948d @kerphi committed Aug 18, 2012
View
@@ -1,30 +1,29 @@
path = $(shell pwd)
TESTS=$(wildcard $(path)/server/tests/*.js)
-TESTSSLIM=$(wildcard $(path)/server-slim/tests/*.js)
dummy:
# run all tests
test: test-server test-client
-# run server-slim tests
+# run server tests
test-server: dummy
- @touch $(path)/server-slim/config.local.php
- @mv -f $(path)/server-slim/config.local.php $(path)/server-slim/config.local.php.tmp
- @cp -f $(path)/server-slim/tests/config.local.php $(path)/server-slim/config.local.php
- @rm -rf server-slim/data/*
- @vows $(TESTSSLIM) --spec
- @mv -f $(path)/server-slim/config.local.php.tmp $(path)/server-slim/config.local.php
+ @touch $(path)/server/config.local.php
+ @mv -f $(path)/server/config.local.php $(path)/server/config.local.php.tmp
+ @cp -f $(path)/server/tests/config.local.php $(path)/server/config.local.php
+ @rm -rf server/data/*
+ @vows $(TESTS) --spec
+ @mv -f $(path)/server/config.local.php.tmp $(path)/server/config.local.php
# run client tests
test-client: dummy
@./phantomjs/bin/phantomjs ./phantomjs/examples/run-qunit.js http://127.0.0.1:32773/client/tests/test1.html
setup: dummy
- @cd $(path)/server-slim/lib/ && curl -L https://nodeload.github.com/codeguy/Slim/tarball/1.6.5 > slim.tar.gz && pwd && tar -ztf slim.tar.gz 2>/dev/null | head -1 > /tmp/slimname
- @cd $(path)/server-slim/lib/ && tar xzf slim.tar.gz
- @rm -rf $(path)/server-slim/lib/Slim && mv $(path)/server-slim/lib/`cat /tmp/slimname` $(path)/server-slim/lib/Slim
- @rm -f /tmp/slimname && rm -f $(path)/server-slim/lib/slim.tar.gz
+ @cd $(path)/server/lib/ && curl -L https://nodeload.github.com/codeguy/Slim/tarball/1.6.5 > slim.tar.gz && pwd && tar -ztf slim.tar.gz 2>/dev/null | head -1 > /tmp/slimname
+ @cd $(path)/server/lib/ && tar xzf slim.tar.gz
+ @rm -rf $(path)/server/lib/Slim && mv $(path)/server/lib/`cat /tmp/slimname` $(path)/server/lib/Slim
+ @rm -f /tmp/slimname && rm -f $(path)/server/lib/slim.tar.gz
# install needed packages for tests run
setup-server-test:
@@ -35,7 +35,9 @@
<div class="pfc-hook"><a href="http://www.phpfreechat.net">phpFreeChat: simple Web chat</a></div>
<script>
- $('.pfc-hook').phpfreechat();
+ $('.pfc-hook').phpfreechat({
+ refresh_delay: 2000,
+ });
</script>
<p>Bla bla bla</p>
@@ -1,9 +0,0 @@
-<IfModule mod_rewrite.c>
- Options -MultiViews
-
- RewriteEngine On
- #RewriteBase /path/to/app
- RewriteRule ^(.*)$ index.php [QSA,L]
-</IfModule>
-
-
@@ -1,62 +0,0 @@
-<?php
-
-include_once 'container/indexes.php';
-include_once 'container/users.php';
-
-class Container_channels {
-
- static public function getChannelsDir() {
- $datadir = __DIR__.'/../data';
- $cdir = $datadir.'/channels';
- return $cdir;
- }
-
- static public function generateCid() {
- $cdir = self::getChannelsDir();
- do {
- $cid = sha1(uniqid('', true));
- $cpath = $cdir.'/'.$cid.'/';
- } while (file_exists($cpath));
- @mkdir($cpath, 0777, true);
- @mkdir($cpath.'/users', 0777, true);
- return $cid;
- }
-
-
- static public function getChannelMsgPath($cid, $mid) {
- $cdir = self::getChannelsDir();
- $mpath = $cdir.'/'.$cid.'/msg/'.$mid.'.json';
- return $mpath;
- }
-
- static public function getChannelUserPath($cid, $uid) {
- $cdir = self::getChannelsDir();
- $cupath = $cdir.'/'.$cid.'/users/'.$uid;
- return $cupath;
- }
-
- static public function getChannelUsers($cid, $withudata = false) {
- $cdir = self::getChannelsDir();
- $cupath = $cdir.'/'.$cid.'/users/';
- $subscribers = array();
- foreach(scandir($cupath) as $value) {
- if($value === '.' || $value === '..') {continue;}
- if ($withudata) {
- $subscribers[$value] = Container_users::getUserData($value);
- } else {
- $subscribers[] = $value;
- }
- }
- return $subscribers;
- }
-
- /**
- * Check if a user is on the given channel
- */
- static public function checkChannelUser($cid, $uid) {
- $cdir = self::getChannelsDir();
- $cupath = $cdir.'/'.$cid.'/users/'.$uid;
- return file_exists($cupath);
- }
-}
-
@@ -1,42 +0,0 @@
-<?php
-
-class Container_indexes {
-
- static public function getIndexDir() {
- return __DIR__ . '/../data/indexes';
- }
-
- /**
- * setIndex('users/name', 'kerphi', 'xxxxx-uid-xxxxx')
- */
- static public function setIndex($path, $key, $value) {
- $path = self::getIndexDir().'/'.$path;
- $file = $path.'/'.urlencode($key);
- @mkdir($path, 0777, true);
- file_put_contents($file, $value);
- }
-
- /**
- * getIndex('users/name', 'kerphi')
- */
- static public function getIndex($path, $key) {
- $path = self::getIndexDir().'/'.$path;
- $file = $path.'/'.urlencode($key);
- if (!file_exists($file)) {
- return null;
- } else {
- return file_get_contents($file);
- }
- }
-
- /**
- * rmIndex('users/name', 'kerphi')
- */
- static public function rmIndex($path, $key) {
- $path = self::getIndexDir().'/'.$path;
- $file = $path.'/'.urlencode($key);
- @unlink($file);
- }
-}
-
-
@@ -1,55 +0,0 @@
-<?php
-
-include_once 'container/channels.php';
-include_once 'container/users.php';
-
-class Container_messages {
-
- /**
- * cid : recipient
- * uid : sender
- * msg : message to send
- */
- static public function postMsgToChannel($cid, $uid, $body, $type = 'msg') {
-
- $mid = self::generateMid($cid);
- $msg = array(
- 'id' => $mid,
- 'sender' => $uid,
- 'recipient' => 'channel|'.$cid,
- 'type' => $type,
- 'body' => $body,
- 'timestamp' => time(),
- );
-
- // when a join message is sent, body contains user's data
- if ($type == 'join') {
- $msg['body'] = Container_users::getUserData($uid);
- }
-
- // json encode msg before storing
- $msg = json_encode($msg);
-
- // search users subscribed to the channel
- foreach(Container_channels::getChannelUsers($cid) as $subuid) {
- // post this message on each users subscribed on the channel
- // /users/:uid/msg/
- if ($subuid != $uid) { // don't post message to the current connected user
- $umdir = Container_users::getDir().'/'.$subuid.'/messages';
- file_put_contents($umdir.'/'.$mid, $msg);
- }
- }
-
- return $msg;
- }
-
- /**
- * Generates a unique message id
- */
- static public function generateMid($cid) {
- $mid = sha1(uniqid('', true));
- return $mid;
- }
-
-}
-
Oops, something went wrong.

0 comments on commit b148501

Please sign in to comment.