Commit: fba9c506710f5461e4e6b6da03c88f851cfb8e51
Author: gwoo | Date: 2009-11-25 20:25:13 -0800
diff --git a/models/Log.php b/models/Log.php
index 79815b9..cbbc872 100644
--- a/models/Log.php
+++ b/models/Log.php
@@ -20,8 +20,8 @@ class Log extends \lithium\core\StaticObject {
if (!is_dir($dir)) {
mkdir($dir);
}
+ $fp = !file_exists($path) ? fopen($path, 'x+') : fopen($path, 'a+');
- $fp = !file_exists($path) ? fopen($path, 'x+') : fopen($file, 'a+');
if (!is_resource($fp)) {
return false;
}
@@ -38,13 +38,14 @@ class Log extends \lithium\core\StaticObject {
if (!static::exists($channel, $date)) {
return array();
}
-
- $fp = fopen($path, 'r+');
$log = array();
+ $fp = @fopen($path, 'r+');
- while (!feof($fp)) {
- $line = fgets($fp);
+ if (!is_resource($fp)) {
+ return $log;
+ }
+ while ($line = fgets($fp)) {
if (preg_match(static::$_pattern, $line, $matches)) {
$log[] = $matches;
}
@@ -88,12 +89,11 @@ class Log extends \lithium\core\StaticObject {
}
public static function path($channel, $date = null) {
- $path = static::$path.'#'.$channel;
+ $path = static::$path . '#' . $channel;
if (!is_null($date)) {
- $path .= '/'.$date;
+ $path .= '/' . $date;
}
-
return $path;
}
}
diff --git a/tests/cases/models/LogTest.php b/tests/cases/models/LogTest.php
index 0a3cd00..51ba387 100644
--- a/tests/cases/models/LogTest.php
+++ b/tests/cases/models/LogTest.php
@@ -32,12 +32,12 @@ class LogTest extends \lithium\test\Unit {
));
$this->assertEqual($expected, $result);
- $expected = array('li3');
+ $expected = array('#li3');
$result = MockLog::find('first');
$this->assertEqual($expected, $result);
-
+
$expected = array(date('Y-m-d'));
- $result = MockLog::find('all', array('channel' => 'li3'));
+ $result = MockLog::find('all', array('channel' => '#li3'));
$this->assertEqual($expected, $result);
}
diff --git a/views/layouts/default.html.php b/views/layouts/default.html.php
index 3e160a0..2c83ae0 100644
--- a/views/layouts/default.html.php
+++ b/views/layouts/default.html.php
@@ -4,44 +4,55 @@
<title><?php echo $this->title(); ?></title>
<?php echo $this->scripts(); ?>
<style type='text/css'>
- a { color: blue; text-decoration: none; }
- a:hover { text-decoration: underline; }
- .breadcrumb { list-style: none; background: #e9e9e9; margin: .5em 0; padding: .25em; border: 1px solid #999; }
- .breadcrumb li { display: inline; }
- .breadcrumb li + li:before { content: ' > '; }
- .channels { float: left; list-style: none; background: #e9e9e9; width: 100px; margin: 0; padding: 0; border: 1px solid #999; }
- .channels a { display: block; margin-top: -1px; padding: .25em; border-top: 1px solid #999; }
- .channels a:hover { background: #e0e0e0; }
- .nav { margin-bottom: .5em; text-align: center; height: 1em; }
- .nav a.prev { float: left; }
- .nav a.next { float: right; margin-top: 0; }
- .content { margin-left: 120px; }
- .messages p { border: 1px solid #999; margin: -1px 0 0; padding: 2px; font-family: monospace; }
- .messages p.odd { background-color: #f6f6f6; }
- .messages p.even { background-color: #f0f0f0; }
- .messages p:hover { background: #e6e6e6; }
- .messages p em { font-style: normal; }
- .messages p strong:before { content: '<'; }
- .messages p strong:after { content: '>'; }
+ body {margin: 0; font-family: 'Trebuchet MS', sans-serif;}
+ a { color: blue; text-decoration: none; }
+ a:hover { text-decoration: underline; }
+ h1 {margin: .5em 0 0 14px; font-weight: normal;}
+ .breadcrumb {
+ list-style: none; background: #e9e9e9; margin: 0; padding: .5em 15px;
+ border: solid #999; border-width: 1px 0;
+ }
+ .breadcrumb li { display: inline; }
+ .breadcrumb li + li:before { content: ' > '; }
+ .channels {
+ float: left; list-style: none; background: #e9e9e9; width: 100px; margin: 0 .5em;
+ padding: 0; border: solid #999; border-width: 0px 1px 1px 1px;
+ }
+ .channels a {
+ display: block; margin-top: -1px; padding: .5em .5em; border-top: 1px solid #999;
+ font-size: 90%;
+ }
+ .channels a:hover { background: #e0e0e0; }
+ .nav { margin: .5em 0; text-align: center; height: 1em; }
+ .nav a.prev { float: left; }
+ .nav a.next { float: right; margin-top: 0; }
+ .content { margin-left: 120px; }
+ .messages p { border: 1px solid #999; margin: -1px 0 0; padding: 2px; font-family: monospace; }
+ .messages p.odd { background-color: #f6f6f6; }
+ .messages p.even { background-color: #f0f0f0; }
+ .messages p:hover { background: #e6e6e6; }
+ .messages p em { font-style: normal; }
+ .messages p strong:before { content: '<'; }
+ .messages p strong:after { content: '>'; }
</style>
</head>
<body>
<h1>Lithium Bot</h1>
<ul class="breadcrumb">
-<?php foreach ($breadcrumbs as $link => $title): ?>
- <li><?php echo ($link != '#') ? $this->html->link($title, $link) : $title; ?></li>
-<?php endforeach; ?>
+ <?php foreach ($breadcrumbs as $link => $title): ?>
+ <li><?php echo ($link != '#') ? $this->html->link($title, $link) : $title; ?></li>
+ <?php endforeach; ?>
</ul>
<ul class="channels">
-<?php foreach ((array)$channels as $channel): ?>
- <li><?=$this->html->link('#'.$channel, 'bot/'.$channel); ?></li>
-<?php endforeach;?>
+ <?php foreach ((array)$channels as $channel): ?>
+ <li><?=$this->html->link('#'.$channel, 'bot/'.$channel); ?></li>
+ <?php endforeach;?>
</ul>
<div class="content">
-<?=$this->content(); ?>
+ <?php echo $this->content(); ?>
</div>
</body>
</html>
diff --git a/views/logs/index.html.php b/views/logs/index.html.php
index 26b5574..badf2cf 100644
--- a/views/logs/index.html.php
+++ b/views/logs/index.html.php
@@ -4,9 +4,10 @@
<ul>
<?php foreach ((array)$logs as $date): ?>
<li>
- <a href="/bot/view/<?=$channel; ?>/<?=$date; ?>">
- <?=$date; ?>
- </a>
+ <?php echo $this->html->link($date, array(
+ 'plugin' => 'li3_bot', 'controller' => 'logs', 'action' => 'view',
+ 'args' => array($channel, $date)
+ ));?>
</li>
<?php endforeach;?>
</ul>
diff --git a/views/logs/view.html.php b/views/logs/view.html.php
index 43761d5..f53fe71 100644
--- a/views/logs/view.html.php
+++ b/views/logs/view.html.php
@@ -1,11 +1,25 @@
<div class="nav">
- <?php if ($previous) echo $this->html->link($previous, 'bot/view/'.$channel.'/'.$previous, array('class' => 'prev')); ?>
- <strong><?=$date?></strong>
- <?php if ($next) echo $this->html->link($next, 'bot/view/'.$channel.'/'.$next, array('class' => 'next')); ?>
+ <?php if ($previous)
+ echo $this->html->link($previous, array(
+ 'plugin' => 'li3_bot', 'controller' => 'logs', 'action' => 'view',
+ 'args' => array($channel, $previous)
+ ), array('class' => 'prev'));
+ ?>
+ <strong><?=$date?></strong>
+ <?php if ($next)
+ echo $this->html->link($next, array(
+ 'plugin' => 'li3_bot', 'controller' => 'logs', 'action' => 'view',
+ 'args' => array($channel, $next)
+ ), array('class' => 'next'));
+ ?>
</div>
<div class="messages">
<?php foreach ($log as $i => $line): $class = ($i % 2) ? 'even' : 'odd'; ?>
- <p class='<?=$class?>'><em><?=$line['time'];?></em> <strong><?=$line['user']?></strong> <?=$line['message']?></p>
+ <p class='<?=$class?>'>
+ <em><?=$line['time'];?></em>
+ <strong><?=$line['user']?></strong>
+ <?=$line['message']?>
+ </p>
<?php endforeach; ?>
</div>