Created
November 24, 2016 06:23
-
-
Save emanh1/f8b1e5da679e25e56749e16553a24316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* MetaWeblogAPI - A API for Bo-Blog | |
| Coded & License : emanh | |
| */ | |
| function blogger_getUsersBlogs ($values) { | |
| global $config; | |
| $userdetail=check_user ($values['username'], $values['password']); | |
| $value_body=array('url'=>$config['blogurl'], 'blogid'=>$values['appkey'], 'blogName'=>$config['blogname']); | |
| $array_body[0]=make_xml_piece ("struct", $value_body); | |
| $xml_content=make_xml_piece("array", $array_body); | |
| $body_xml=xml_generate($xml_content); | |
| send_response ($body_xml); | |
| } | |
| function metaWeblog_newPost ($values) { | |
| global $config, $defualtcategoryid, $db_prefix, $mbconfig; | |
| $struct=$values['struct']; | |
| $userdetail=check_user ($values['username'], $values['password']); | |
| if (!$struct['title']) $title="Untitled MetaWeblogAPI Entry"; | |
| else $title=safe_convert($struct['title']); | |
| if (!$struct['description']) xml_error("You MUST provide a decription element in your post."); | |
| else $content=reduce_entities($struct['description']); | |
| if ($struct['pubDate']) $struct['dateCreated']=$struct['pubDate']; | |
| if ($struct['dateCreated']) $time=get_time_unix($struct['dateCreated']); | |
| else $time=time(); | |
| $blog=new boblog; | |
| //writetofile ('text5.php', $struct['categories']); //For debug only | |
| if ($struct['categories']!='') { | |
| $c_tmp=$blog->getgroupbyquery("SELECT cateid FROM `{$db_prefix}categories` WHERE `catename`='{$struct['categories']}'"); | |
| $category=$c_tmp[0]['cateid']; | |
| if ($category=='') $category=$defualtcategoryid; | |
| } | |
| else $category=$defualtcategoryid; | |
| $html=1; | |
| if ($struct['flNotOnHomePage']==1) $property=3; | |
| else $property=0; | |
| $maxrecord=$blog->getsinglevalue("{$db_prefix}maxrec"); | |
| $currentid=$maxrecord['maxblogid']+1; | |
| $query="INSERT INTO `{$db_prefix}blogs` VALUES ('{$currentid}', '{$title}','{$time}','{$userdetail['userid']}', 0, 0, 0, '{$property}','{$category}','','0','{$html}', '1', '1', '{$content}', '0', '0', 'blank', '0', '', '', '0', '', '0', '', '', '', '')"; | |
| $blog->query($query); | |
| $newcym=gmdate("Ym", $time+$config['timezone']*3600); | |
| $newcd=gmdate("d", $time+$config['timezone']*3600); | |
| $blog->query("INSERT INTO `{$db_prefix}calendar` VALUES ('{$newcym}', '{$newcd}', '{$currentid}', '')"); | |
| recache_latestentries (); | |
| recache_currentmonthentries(); | |
| recache_categories(); //Update Category counter | |
| $blog->query("UPDATE `{$db_prefix}maxrec` SET maxblogid={$currentid}"); | |
| $blog->query("UPDATE `{$db_prefix}counter` SET entries=entries+1"); | |
| plugin_runphp('metaweblogadd'); | |
| $xml_content=make_xml_piece("string", $currentid); | |
| $body_xml=xml_generate($xml_content); | |
| send_response ($body_xml); | |
| } | |
| function metaWeblog_editPost ($values) { | |
| global $config, $defualtcategoryid, $db_prefix, $mbconfig; | |
| $struct=$values['struct']; | |
| $userdetail=check_user ($values['username'], $values['password']); | |
| $blog=new boblog; | |
| $values['postid']=floor($values['postid']); | |
| $records=$blog->getgroupbyquery("SELECT * FROM `{$db_prefix}blogs` WHERE `blogid`='{$values['postid']}'"); | |
| if ($records[0]['blogid']=='') xml_error ("Entry does not exist."); | |
| if (!$struct['title']) $title="Untitled MetaWeblogAPI Entry"; | |
| else $title=safe_convert($struct['title']); | |
| if (!$struct['description']) xml_error("You MUST provide a decription element in your post."); | |
| else $content=reduce_entities($struct['description']); | |
| $nowtime=time(); | |
| if ($struct['pubDate']) $struct['dateCreated']=$struct['pubDate']; | |
| if ($struct['dateCreated']) $time=get_time_unix($struct['dateCreated'])+3600*$config['timezone']; | |
| else $time=$records[0]['pubtime']; | |
| $newcym=date("Ym", $time); | |
| $newcd=date("d", $time); | |
| $blog->query("UPDATE `{$db_prefix}calendar` SET cyearmonth='{$newcym}', cday='{$newcd}' WHERE `cid`='{$values['postid']}'"); | |
| //writetofile ('text5.php', $struct['categories']); //For debug only | |
| if ($struct['categories']!='') { | |
| $c_tmp=$blog->getgroupbyquery("SELECT cateid FROM `{$db_prefix}categories` WHERE `catename`='{$struct['categories']}'"); | |
| $category=$c_tmp[0]['cateid']; | |
| if ($category=='') $category=$defualtcategoryid; | |
| } | |
| else $category=$records[0]['category']; | |
| if ($values['publish']==1 && $struct['flNotOnHomePage']!=1) $property=0; | |
| else $property=3; | |
| $query="UPDATE `{$db_prefix}blogs` SET `title`='{$title}', `pubtime`='{$time}', `property`='{$property}', `category`='{$category}', `content`='{$content}', `editorid`='{$userdetail['userid']}', `edittime`='{$nowtime}' WHERE `blogid`='{$values['postid']}'"; | |
| recache_latestentries (); | |
| recache_currentmonthentries(); | |
| recache_categories(); //Update Category counter | |
| $blog->query($query); | |
| plugin_runphp('metaweblogedit'); | |
| $xml_content=make_xml_piece("boolean", '1'); | |
| $body_xml=xml_generate($xml_content); | |
| send_response ($body_xml); | |
| } | |
| function metaWeblog_getPost ($values) { | |
| global $config, $db_prefix; | |
| $userdetail=check_user ($values['username'], $values['password']); | |
| $blog=new boblog; | |
| $values['postid']=floor($values['postid']); | |
| $records=$blog->getgroupbyquery("SELECT * FROM `{$db_prefix}blogs` WHERE `blogid`='{$values['postid']}'"); | |
| if ($records[0]['blogid']=='') xml_error ("Entry does not exist."); | |
| else { | |
| $record=$records[0]; | |
| $time=get_time_unix($record['pubtime'], 'iso'); | |
| $value_body=array('dateCreated'=>$time, 'userid'=>$userdetail['userid'], 'postid'=>$record['blogid'], 'description'=>htmlspecialchars($record['content']), 'title'=>htmlspecialchars($record['title']), 'link'=>"{$config['blogurl']}/read.php?{$record['blogid']}", 'categories'=>make_xml_piece('array', array("Category {$record['category']}"))); | |
| $body=make_xml_piece ("struct", $value_body); | |
| $body_xml=xml_generate($body); | |
| send_response ($body_xml); | |
| } | |
| } | |
| function metaWeblog_getRecentPosts ($values) { | |
| global $config, $db_prefix; | |
| $userdetail=check_user ($values['username'], $values['password']); | |
| $blog=new boblog; | |
| $values['numberOfPosts']=floor($values['numberOfPosts']); | |
| $records=$blog->getgroupbyquery("SELECT * FROM `{$db_prefix}blogs` ORDER BY `pubtime` DESC LIMIT 0, {$values['numberOfPosts']}"); | |
| if ($records[0]['blogid']=='') xml_error ("Entry does not exist."); | |
| else { | |
| for ($i=0; $i<count($records); $i++) { | |
| $record=$records[$i]; | |
| $time=get_time_unix($record['pubtime'], 'iso'); | |
| $value_body=array('dateCreated'=>$time, 'userid'=>$userdetail['userid'], 'postid'=>$record['blogid'], 'description'=>htmlspecialchars($record['content']), 'title'=>htmlspecialchars($record['title']), 'link'=>"{$config['blogurl']}/read.php?{$record['blogid']}", 'categories'=>make_xml_piece('array', array("Category {$record['category']}"))); | |
| $value_bodys[]=make_xml_piece ("struct", $value_body); | |
| } | |
| $body=make_xml_piece ("array", $value_bodys); | |
| $body_xml=xml_generate($body); | |
| send_response ($body_xml); | |
| } | |
| } | |
| function metaWeblog_getCategories ($values) { | |
| global $config, $db_prefix; | |
| $userdetail=check_user ($values['username'], $values['password']); | |
| //Get Categories | |
| $result=db_query("SELECT * FROM `{$db_prefix}categories` ORDER BY `cateorder`"); | |
| while ($row=db_fetch_array($result)) { | |
| $struct_body[]=make_xml_piece ("struct", array('description'=>"{$row['catename']}", 'htmlUrl'=>"{$config['blogurl']}/index.php?go=category_{$row['cateid']}", 'rssUrl'=>"{$config['blogurl']}/feed.php?go=category_{$row['cateid']}")); | |
| } | |
| $xml_content.=make_xml_piece ("array", $struct_body); | |
| $body_xml=xml_generate($xml_content); | |
| send_response ($body_xml); | |
| } | |
| function blogger_getUserInfo ($values) { | |
| global $config, $db_prefix; | |
| $userdetail=check_user ($values['username'], $values['password']); | |
| $xml_content=make_xml_piece ("struct", array('nickname'=>$values['username'], 'userid'=>$userdetail['userid'], 'url'=>$config['blogurl'], 'email'=>$userdetail['email'])); | |
| $body_xml=xml_generate($xml_content); | |
| send_response ($body_xml); | |
| } | |
| function metaWeblog_newMediaObject ($values) { //2006-12-2 add support for uploading files | |
| global $config, $defualtcategoryid, $db_prefix, $mbcon, $nowtime; | |
| $userdetail=check_user ($values['username'], $values['password']); | |
| $struct=$values['struct']; | |
| //writetofile ('text1.php', $struct['bits']); //debug only | |
| if ($struct['bits'] && $struct['name']) { | |
| $writefilecontent=base64_decode($struct['bits']); | |
| $ext=strtolower(strrchr($struct['name'],'.')); | |
| $ext=str_replace(".", '', $ext); | |
| $upload_filename=time().'_'.rand(1000, 9999).substr(md5($struct['name']), 0, 4).'.'.$ext; | |
| if ($mbcon['uploadfolders']=='1') { | |
| $targetfolder_ym=date("Ym").'/'; | |
| $targetfolder="attachment/{$targetfolder_ym}"; | |
| if (!is_dir ($targetfolder)) { | |
| $mktargetfolder=@mkdir($targetfolder, 0777); | |
| if (!$mktargetfolder) xml_error ("Sorry, uploading file ({$struct['name']}) failed because PHP was unable to create a new directory."); | |
| } | |
| } else { | |
| $targetfolder_ym=''; | |
| $targetfolder='attachment'; | |
| } | |
| $filenum=@fopen("{$targetfolder}/{$upload_filename}","wb"); | |
| if (!$filenum) { | |
| xml_error ("Sorry, uploading file ({$struct['name']}) failed."); | |
| } | |
| flock($filenum,LOCK_EX); | |
| fwrite($filenum,$writefilecontent); | |
| fclose($filenum); | |
| //DB updating, new function in 2.1.0 | |
| $blog=new boblog; | |
| $blog->query("INSERT INTO `{$db_prefix}upload` (fid,filepath,originalname,uploadtime,uploaduser) VALUES (null, \"attachment/{$targetfolder_ym}{$upload_filename}\", \"{$struct['name']}\", {$nowtime['timestamp']}, {$userdetail['userid']})"); | |
| $currentid=db_insert_id(); | |
| if ($mbcon['wmenable']=='1') { //Add watermark | |
| $imgext_watermark=array('jpg', 'gif', 'png'); | |
| if (in_array($ext, $imgext_watermark)) { | |
| create_watermark("attachment/{$targetfolder_ym}{$upload_filename}"); | |
| } | |
| } | |
| } | |
| $xml_content=make_xml_piece ("struct", array('url'=>"{$config['blogurl']}/attachment.php?fid={$currentid}")); | |
| $body_xml=xml_generate($xml_content); | |
| send_response ($body_xml); | |
| } | |
| //Give an error code for bloggerAPI aliases | |
| function blogger_newPost ($values) { | |
| xml_error ("Sorry, this method is no longer supported. Please use metaWeblog.newPost instead."); | |
| } | |
| function blogger_editPost ($values) { | |
| xml_error ("Sorry, this method is no longer supported. Please use metaWeblog.editPost instead."); | |
| } | |
| //Give an error code for unsupported methods, like template | |
| function blogger_getTemplate ($values) { | |
| xml_error ("Sorry, this method is not supported yet."); | |
| } | |
| function blogger_setTemplate ($values) { | |
| xml_error ("Sorry, this method is not supported yet."); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment