Skip to content

Commit d73ef4b

Browse files
committedJul 17, 2009
refs #1300
* line client 의 기본 기능 추가. * 쓰기, 보기가 됩니다. * TODO * 관리하기 * 비공개 line 만들기 * 서비스 단 마무리 * 출력 옵션 더하기 * 다른 line 구독하기 * ATOM 으로 내보내기
1 parent 770657c commit d73ef4b

File tree

17 files changed

+457
-29
lines changed

17 files changed

+457
-29
lines changed
 

‎framework/Dispatcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function URIinterpreter() {
133133
} else {
134134
if (!empty($URLInfo['fragment'])) {
135135
if( in_array($URLInfo['fragment'][0],
136-
array('api','archive','attachment','author','category','checkup','cover','cron','entry','feeder','foaf','guestbook','iMazing','keylog','location','locationSuggest','logout','notice','page','plugin','pluginForOwner','search','suggest','sync','tag','ttxml')))
136+
array('api','archive','attachment','author','category','checkup','cover','cron','entry','feeder','foaf','guestbook','iMazing','keylog','location','locationSuggest','logout','notice','page','plugin','pluginForOwner','search','suggest','sync','tag','ttxml','line')))
137137
{
138138
$pathPart = $URLInfo['fragment'][0];
139139
$interfacePath = 'interface/blog/'.$pathPart.'.php';

‎framework/legacy/Needlworks.Database.php

+21-20
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ public function getQualifier($name) {
134134
}
135135

136136
public function setQualifier($name, $condition, $value = null, $escape = null) {
137-
//OR, setQualifier($name, $value, $escape = null) - Legacy mode
138137
//OR, setQualifier(string(name_condition_value), $escape = null) - Descriptive mode (NOT implemented)
139-
//OR, setQualifier($name, NULL)
140138
if (is_null($condition)) {
141139
$this->_qualifiers[$name] = 'NULL';
142140
} else {
@@ -145,23 +143,26 @@ public function setQualifier($name, $condition, $value = null, $escape = null) {
145143
$value = $condition;
146144
$condition = null;
147145
}*/
148-
if(is_null($condition)) {
149-
$this->_qualifiers[$name] = (is_null($escape) ? $value : ($escape ? '\'' . POD::escapeString($value) . '\'' : "'" . $value . "'"));
150-
$this->_relations[$name] = '=';
151-
} else {
152-
switch(strtolower($condition)) {
153-
case 'equals':
154-
$this->_relations[$name] = '=';
155-
break;
156-
case 'not':
157-
$this->_relations[$name] = 'NOT';
158-
break;
159-
case 'like':
160-
default:
161-
$this->_relations[$name] = 'LIKE';
162-
}
163-
$this->_qualifiers[$name] = (is_null($escape) ? $value : ($escape ? '\'' . POD::escapeString($value) . '\'' : "'" . $value . "'"));
146+
switch(strtolower($condition)) {
147+
case 'equals':
148+
$this->_relations[$name] = '=';
149+
break;
150+
case 'not':
151+
$this->_relations[$name] = 'NOT';
152+
break;
153+
case 'bigger':
154+
case '>':
155+
$this->_relations[$name] = '>';
156+
break;
157+
case 'smaller':
158+
case '<':
159+
$this->_relations[$name] = '<';
160+
break;
161+
case 'like':
162+
default:
163+
$this->_relations[$name] = 'LIKE';
164164
}
165+
$this->_qualifiers[$name] = (is_null($escape) ? $value : ($escape ? '\'' . POD::escapeString($value) . '\'' : "'" . $value . "'"));
165166
}
166167
}
167168

@@ -172,7 +173,7 @@ public function unsetQualifier($name) {
172173

173174
public function setOrder($standard, $order = 'ASC') {
174175
$this->_order['attribute'] = $standard;
175-
if(!in_array(strtoupper($order, array('ASC','DESC')))) $order = 'ASC';
176+
if(!in_array(strtoupper($order), array('ASC','DESC'))) $order = 'ASC';
176177
$this->_order['order'] = $order;
177178
}
178179

@@ -282,7 +283,7 @@ private function _makeWhereClause() {
282283
(array_key_exists($name, $this->_isReserved) ? '"'.$name.'"' : $name) .
283284
' '.$this->_relations[$name] . ' ' . $value;
284285
}
285-
if(!empty($this->_order)) $clause .= ' ORDER BY '._treatReservedFields($this->_order['standard']).' '.$this->_order['order'];
286+
if(!empty($this->_order)) $clause .= ' ORDER BY '.$this->_treatReservedFields($this->_order['attribute']).' '.$this->_order['order'];
286287
if(!empty($this->_limit)) $clause .= ' LIMIT '.$this->_limit['count'].' OFFSET '.$this->_limit['offset'];
287288
return (strlen($clause) ? ' WHERE ' . $clause : '');
288289
}

‎framework/legacy/Needlworks.PHP.Loader.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ class Autoload {
5353
);
5454
private static $base = array(
5555
'Base64Stream','HTTPRequest','OutputWriter','XMLRPC','XMLRPCFault',
56-
'XMLCustomType','XMLTree','Pop3');
56+
'XMLCustomType','XMLTree','Pop3','CommunicationFeed');
5757
private static $function = array(
5858
'Image','Setting','Respond','Misc');
5959
private static $openid = array(
6060
'OpenID', 'OpenIDSession', 'OpenIDConsumer');
6161
private static $control = array(
6262
'Session','RSS');
63+
private static $newmodel = array('Line','OpenSearchProvider');
6364
public static function load($name) {
6465
global $service, $database;
6566
$name = ucfirst($name);
@@ -89,8 +90,9 @@ public static function load($name) {
8990
require_once(ROOT . "/framework/legacy/Eolin.API.Syndication.php");
9091
} else if (in_array($name,array('Locale'))) {
9192
require_once(ROOT . "/framework/legacy/Needlworks.Core.Locale.php");
92-
}
93-
else {
93+
} else if (in_array($name,self::$newmodel)) {
94+
require_once(ROOT . "/framework/model/".$name.'.php');
95+
} else {
9496
if(defined('TCDEBUG')) print "TC: Unregisterred auto load class: $name<br/>\n";
9597
}
9698
}

‎framework/legacy/Needlworks.PHP.XMLTree.php

+83
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,89 @@ function getChildCount($path) {
132132
return count($n['children']);
133133
}
134134

135+
/// Private functions
136+
/// PHP4 does not support private methods. Thus these methods are access-free.
137+
/// We DO NOT recommend to use these methods using direct-access
138+
139+
/// Recursively attach XML Documentation object
140+
function leap(&$cursor) {
141+
if(!is_array($cursor)) { // terminal.
142+
$this->_xmlcontent .= $cursor;
143+
return;
144+
} else { // Non-terminal
145+
$this->_xmlcontent .= '<'.$cursor['name'];
146+
if(isset($cursor['attributes'])) {
147+
foreach($cursor['attributes'] as $type => $value) {
148+
$this->_xmlcontent .= ' '.$type.'="'.$value.'"';
149+
}
150+
}
151+
$this->_xmlcontent .= '>';
152+
if(isset($cursor['children'])) {
153+
if(!is_array($cursor['children'])) {
154+
$this->_xmlcontent .= $cursor['children'];
155+
} else {
156+
for($i = 0; $i < count($cursor['children']); $i++) {
157+
$this->leap(&$cursor['children'][$i]);
158+
}
159+
}
160+
}
161+
$this->_xmlcontent .= '</'.$cursor['name'].'>';
162+
}
163+
}
164+
/// Generate XML contents based on current tree
165+
function generate() {
166+
$this->_cursor = &$this->tree;
167+
$this->_xmlcontent = '<?xml version="1.0" encoding="utf-8"?>';
168+
if(isset($this->_cursor['children'])) {
169+
for($i = 0; $i < count($this->_cursor['children']); $i++) {
170+
$this->leap(&$this->_cursor['children'][$i]);
171+
}
172+
}
173+
}
174+
175+
/// Set the value to specific path.
176+
function setValue($path, $content, $type = null) {
177+
if (!$this->doesExist($path)) {
178+
$this->createNode($path);
179+
}
180+
$n = &$this->selectNode($path);
181+
array_push($n['children'], $content);
182+
if(!is_null($type)) $this->addAttribute($path, 'type', $type);
183+
}
184+
185+
/// Create node to documentation tree
186+
function createNode($path) {
187+
$this->_cursor = &$this->tree;
188+
$branch = explode('/',ltrim($path,'/'));
189+
foreach($branch as &$fork) {
190+
$growth = true;
191+
if(isset($this->_cursor['children'])) {
192+
for($count = 0; $count < count($this->_cursor['children']); $count++) {
193+
if(isset($this->_cursor['children'][$count]['name']) && $this->_cursor['children'][$count]['name'] == $fork) {
194+
$growth = false;
195+
break;
196+
}
197+
}
198+
} else {
199+
$this->_cursor['children'] = array();
200+
}
201+
if($growth) {
202+
array_push($this->_cursor['children'], array('name' => $fork, 'children' => array()));
203+
$this->_cursor = &$this->_cursor['children'][count($this->_cursor['children']) - 1];
204+
} else {
205+
$this->_cursor = &$this->_cursor['children'][$count];
206+
}
207+
}
208+
$this->_cursor = &$this->tree;
209+
}
210+
211+
/// Adds attribute to path.
212+
function addAttribute($path, $name, $value) {
213+
$n = &$this->selectNode($path);
214+
if(!isset($n['attributes'])) $n['attributes'] = array();
215+
$n['attributes'][$name] = $value;
216+
}
217+
135218
function o($p, $n, $a) {
136219
if (empty($a))
137220
array_push($this->_cursor['children'], array('name' => $n, 'children' => array(), '_' => &$this->_cursor));

‎framework/model/Line.php

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/// Copyright (c) 2004-2009, Needlworks / Tatter Network Foundation
3+
/// All rights reserved. Licensed under the GPL.
4+
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)
5+
6+
final class Line extends Singleton {
7+
private $filter = array();
8+
public function __constructor() {
9+
$this->reset();
10+
}
11+
12+
public static function getInstance() {
13+
return self::_getInstance(__CLASS__);
14+
}
15+
16+
public function reset() {
17+
global $database;
18+
$this->id = null;
19+
$this->blogid = getBlogId();
20+
$this->category = 'public';
21+
$this->content = '';
22+
$this->created = null;
23+
$this->filter = array();
24+
$this->_error = array();
25+
$query = new TableQuery($database['prefix'].'Lines');
26+
}
27+
/// Methods for managing
28+
public function add() {
29+
global $database;
30+
if(is_null($this->created)) $this->created = Timestamp::getUNIXTime();
31+
if(!$this->validate()) return false;
32+
$query = new TableQuery($database['prefix'].'Lines');
33+
$query->setAttribute('id',$this->id);
34+
$query->setAttribute('blogid',$this->blogid);
35+
$query->setAttribute('category',$this->category,true);
36+
$query->setAttribute('content',$this->content,true);
37+
$query->setAttribute('created',$this->created);
38+
return $query->insert();
39+
}
40+
41+
public function delete(){
42+
global $database;
43+
if(empty($this->filter)) return $this->error('Filter empty');
44+
$query = new TableQuery($database['prefix'].'Lines');
45+
foreach($this->filter as $filter) {
46+
if(count($filter) == 3) {
47+
$query->setQualifier($filter[0],$filter[1],$filter[2]);
48+
} else {
49+
$query->setQualifier($filter[0],$filter[1],$filter[2],$filter[3]);
50+
}
51+
}
52+
return $query->delete();
53+
}
54+
/// Methods for querying
55+
public function get($fields = '*') {
56+
global $database;
57+
if(empty($this->filter)) return $this->error('Filter empty');
58+
$query = new TableQuery($database['prefix'].'Lines');
59+
foreach($this->filter as $filter) {
60+
if(count($filter) == 3) {
61+
$query->setQualifier($filter[0],$filter[1],$filter[2]);
62+
} else {
63+
$query->setQualifier($filter[0],$filter[1],$filter[2],$filter[3]);
64+
}
65+
}
66+
$query->setOrder('created','desc');
67+
return $query->getAll($fields);
68+
}
69+
70+
/// @input condition<array> [array(name, condition, value, [need_escaping])]
71+
public function setFilter($condition) {
72+
if(!in_array(count($condition),array(3,4))) return $this->error('wrong filter');
73+
array_push($this->filter, $condition);
74+
}
75+
76+
/// Aliases
77+
public function getWithConditions($conditions) {
78+
79+
}
80+
/// Private members
81+
private function validate() {
82+
if(is_null($this->id)) $this->id = $this->getNextId();
83+
$this->category = UTF8::lessenAsByte($this->category, 11);
84+
$this->content = UTF8::lessenAsByte($this->content, 512);
85+
if(!Validator::isInteger($this->blogid, 1)) return $this->error('blogid');
86+
if(!Validator::timestamp($this->created)) return $this->error('created');
87+
return true;
88+
}
89+
90+
private function getNextId() {
91+
global $database;
92+
$query = new TableQuery($database['prefix'].'Lines');
93+
$maxId = $query->getCell('MAX(id)');
94+
if(!empty($maxId)) return $maxId + 1;
95+
else return 1;
96+
}
97+
public function showResult($result) {
98+
echo "<html><head></head><body>";
99+
echo '<script type="text/javascript">alert("';
100+
if($result) {
101+
echo _t('Line이 추가되었습니다.');
102+
} else {
103+
echo _t('Line 추가에 실패했습니다.');
104+
}
105+
echo '");history.back(-1);</script></body></html>';
106+
}
107+
private function error($state) {
108+
$this->_error['message'] = $state;
109+
return false;
110+
}
111+
}
112+
?>
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/// Copyright (c) 2004-2009, Needlworks / Tatter Network Foundation
3+
/// All rights reserved. Licensed under the GPL.
4+
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)
5+
6+
7+
class OpenSearchProvider extends XMLTree {
8+
9+
/// Set the descriptors to DOM tree
10+
function setDescriptor ($name, $content, $type = null) {
11+
return $this->setValue('/OpenSearchDescription/'.$name, $content, $type);
12+
}
13+
}
14+
?>

‎interface/blog/checkup.php

+22
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,28 @@ function clearCache() {
651651
showCheckupMessage(false);
652652
}
653653
}
654+
655+
if (!doesExistTable($database['prefix'] . 'Lines')) {
656+
$changed = true;
657+
echo '<li>', _text('라인 기능을 위한 테이블을 만듭니다'), ': ';
658+
$query = "
659+
CREATE TABLE {$database['prefix']}Lines (
660+
id int(11) NOT NULL default 0,
661+
blogid int(11) NOT NULL default 0,
662+
category varchar(11) NOT NULL default 'public',
663+
content varchar(512) NOT NULL default '',
664+
created int(11) NOT NULL default 0,
665+
PRIMARY KEY (id),
666+
UNIQUE KEY (blogid, created),
667+
KEY (blogid, category, created)
668+
) TYPE=MyISAM
669+
";
670+
if (POD::execute($query . ' DEFAULT CHARSET=utf8') || POD::execute($query))
671+
showCheckupMessage(true);
672+
else {
673+
showCheckupMessage(false);
674+
}
675+
}
654676
}
655677

656678
/***** Common parts. *****/

‎interface/blog/line.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/// Copyright (c) 2004-2009, Needlworks / Tatter Network Foundation
3+
/// All rights reserved. Licensed under the GPL.
4+
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)
5+
require ROOT . '/library/preprocessor.php';
6+
7+
$lineobj = Line::getInstance();
8+
$lineobj->reset();
9+
// If line comes.
10+
if(isset($_GET['key']) && isset($_GET['content'])) {
11+
$password = Setting::getBlogSetting('LinePassword', null, true);
12+
if($password == $_GET['key']) {
13+
$lineobj->content = $_GET['content'];
14+
$lineobj->showResult($lineobj->add());
15+
}
16+
} else {
17+
/// Prints public lines
18+
$lineobj->setFilter(array('created','bigger',(Timestamp::getUNIXTime()-86400)));
19+
$lineobj->setFilter(array('category','equals','public',true));
20+
21+
$lines = $lineobj->get();
22+
23+
fireEvent('OBStart');
24+
require ROOT . '/interface/common/blog/begin.php';
25+
require ROOT . '/interface/common/blog/line.php';
26+
require ROOT . '/interface/common/blog/end.php';
27+
fireEvent('OBEnd');
28+
}
29+
?>

‎interface/blog/notice.php

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
/// All rights reserved. Licensed under the GPL.
44
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)
55
require ROOT . '/library/preprocessor.php';
6-
if (false) {
7-
fetchConfigVal();
8-
}
96

107
if (isset($suri['id']) || (isset($suri['value']) && strlen($suri['value']) > 0)) {
118
if (!isset($suri['id']) || (getBlogSetting('useSloganOnPost',1) == 1)) {

0 commit comments

Comments
 (0)