requireComponent('Tattertools.Data.Post');
requireComponent('Tattertools.Data.Attachment');
requireComponent('Tattertools.Data.Category');
requireComponent('Eolin.PHP.XMLTree');
function doesHaveOwnership(){
global $owner;
if(empty($_SESSION['userid'])||($_SESSION['userid']!=$owner))
return false;
return true;
}
function requireLogin(){
global $service,$hostURL,$blogURL;
if(!empty($service['loginURL']))
header("Location: {$service['loginURL']}?requestURI=".rawurlencode("$hostURL{$_SERVER['REQUEST_URI']}"));
else{
{
header("Location: $blogURL/login?requestURI=".rawurlencode("{$_SERVER['REQUEST_URI']}"));
}
}
exit;
}
function requireOwnership(){
if(doesHaveOwnership())
return true;
requireLogin();
return false;
}
function fetchQueryAll($query,$type=MYSQL_BOTH){
$rows=array();
if($result=mysql_query($query)){
while($row=mysql_fetch_array($result,$type))
array_push($rows,$row);
}
return $rows;
}
function check() {
global $hostURL,$blogURL,$owner,$database;
requireOwnership();
if(!file_exists(ROOT."/attach/$owner")){
mkdir(ROOT."/attach/$owner",0777);
}
$tempid=uniqid(rand());
while(file_exists(ROOT."/attach/$owner/__DEL$tempid.txt")) {
$tempid=uniqid(rand());
}
$fp=fopen(ROOT."/attach/$owner/__DEL".$tempid.".txt","w");
fwrite($fp,"hello");
fclose($fp);
@chmod(ROOT."/attach/$owner/__DEL".$tempid.".txt",0777);
mysql_query("insert into {$database['prefix']}Attachments values ($owner, -1, '__DEL$tempid.txt', '__DEL$tempid.txt', 'text/plain', 0, 0, 0, UNIX_TIMESTAMP(), 0,0)");
$fsn_indexurl=$hostURL.$blogURL;
echo "
$fsn_indexurl 의 동작여부를 확인중입니다....잠시만기다려 주세요.
";
}
function checkdone(){
global $owner;
$_GET[checkdone]= preg_replace ("/[ #\&\+\-%@=\/\\\:;,\.'\"\^`~|\!\?\*$#<>()\[\]\{\}]/i", "", $_GET[checkdone]);
if(substr ($_GET[checkdone], 0, 5)=="__DEL") {
unlink(ROOT."/attach/$owner/".$_GET[checkdone].".txt");
mysql_query("delete from {$database['prefix']}Attachments where owner=$owner and label='{$_GET[checkdone]}'");
}
}
function printpassform(){
global $hostURL,$blogURL,$owner,$database,$fsn,$service;
echo "
설정
_
}
function setpass($v){
global $hostURL,$blogURL,$owner,$database,$fsn;
$category=$_POST[category];
$fp=fopen(ROOT."/attach/$owner/FSNconfig.php","w+");
if ($fp) {
$pass=$v;
fwrite($fp," \$fsn['pass'] = '$pass'; " );
fwrite($fp," \$fsn['category'] = '$category'; ?>" );
fclose($fp);
@chmod(ROOT."/attach/$owner/FSNconfig.php", 0666);
}
$fsn['pass']=$v;
$fsn['category']=$category;
echo "_";
printpassform();
}
function postMoblog(){
global $owner,$database,$hostURL,$blogURL,$skinSetting,$service;
if (file_exists(ROOT."/attach/$owner/FSNconfig.php")){
include(ROOT."/attach/$owner/FSNconfig.php");
}
$pass=($_POST['pass']);
$subject=($_POST['subject']);
$memo=($_POST['memo']);
$fileurl=$_POST['fileurl'];
if($fsn['pass']!=$pass) exit("wrong password");
$entry = new Post();
if( substr($subject,0,1)=='#') {
$subject= substr($subject,1);
$open='private';
}
else {
$open='syndicated';
}
$entry->visibility = $open;
$entry->title = $subject;
$entry->content =$memo;
$entry->category=(empty($fsn['category'])||$fsn['category']==0)?null:$fsn['category'];
if (!$entry->add()) exit($entry->error."add fail1");
$pid=$entry->id;
if(count($_FILES)>0){
$file=array_pop($_FILES);
$skinName=$skinSetting[skin];
$xml=file_get_contents(ROOT."/skin/$skinName/index.xml");
$xmls=new XMLTree();
if($xmls->open($xml,$service['encoding']))
$contentWidth=$xmls->getValue('/skin/default/contentWidth');
if(!$contentWidth) $contentWidth=300;
$path=ROOT."/attach/$owner";
$att=new Attachment();
$att->label=$att->name=$file['name'];
$att->width=$contentWidth;
$att->parent=$pid;
//$att->label =
$att->size =$file['size'];
if($imageAttributes=@getimagesize($file['tmp_name'])){
$att->mime =$imageAttributes['mime'];
$att->width =$imageAttributes[0];
$att->height =$imageAttributes[1];
}
if(!$att->add()){ echo "attache fail";} else{
move_uploaded_file($file['tmp_name'], $path."/".$att->name);}
if($att->width > $contentWidth )
{
$w=$contentWidth;
$h=$contentWidth/$att->width*$att->height;
}else {
$w=$att->width;
$h=$att->height;
}
$fname=$att->name;
$text= "[##_1C|$fname|width=\"$w\" height=\"$h\" alt=\"\"|_##]";
$entry->content=$text.$memo;
$entry->update();
}
$fsn_indexurl=$hostURL.$blogURL;
echo "OK|$fsn_indexurl/".$pid;
}
function take() {
global $hostURL,$blogURL,$owner,$database,$fsn;
if (file_exists(ROOT."/attach/$owner/FSNconfig.php")){
include(ROOT."/attach/$owner/FSNconfig.php");
}
if($_GET[check]) {
check();
}
else if($_GET[checkdone]){
checkdone();
}else if($_GET[setpass]==1){
requireOwnership();
printpassform();
}else if($_POST[moblogpass]){
requireOwnership();
setpass($_POST[moblogpass]);
}else if($_POST['subject']){
postMoblog();
}
}
?>