All posts by chen

WordPressの添付ファイルの差替え

国際会議のサイト構築の担当になり、WordPressで構築した。

CFPなど、いくつPDFの添付ファイルがありました。そのPDFファイルは結構頻繁に更新する。

更新するファイルをもう一度添付すると、URLが変わり、本文からのリンクも直す必要。手続き面倒な上、そもそもURL変わる自体も好ましくない。

たまたまEnable Media Replaceというプラグインに出会った。

https://wordpress.org/plugins/enable-media-replace/

ファイルをアップロードするだけで差替えるので、簡単そう。

Enhanced photoblog

Project Title. Enhanced Photo Blog publisher

Elevator Pitch. “Easy Photo Blog publisher” is easy way to make a photo blog to own WordPress site, this cloud app enhanced with addtional post viewer, custom Auth UI with base64 encode implement.

Description.
The Easy Photo Blog publisher is a mobile app that make easy to publish a post with photo to self hosted WordPress site.  Enhanced Photo Blog publisher was enhanced with following funtions:

  1. A post viewer for you browse recent posts.
  2. A custom Auth UI let you manage a WordPress REST API service lists.

The app’s social benefit comes from its ability to make a quick post, and improve later, give a motivation to help user more publish. Also this a good example to use WordPress REST API.

2015-12-11 13.51.55

Download and Test. Because this is a app using WordPress REST API, the only way to fully test its functionality would require using the WordPress REST API powered Blog site. You can feel free to use my test site. To download the app, scan the QR code to the left with the MIT AI2 Companion app or some other Scanner or click on this download link.

PhotoBlog2_V2-download

a screen shot show a post on WordPress REST API powered Blog site.

2015-12-11 13.54.22
Technical Description. As shown in this screenshot, the app exceeds the project’s minimum technical requirements. It contains 2 global variables, 4 list data, 2 procedures or functions, and 2 if/else structure.

PhotoBlog2-blocks2

Appendix.

WP REST API web service

The WP REST API is a WordPress plugin that intends to be eventually integrated into WordPress’ core as another (big) step towards transforming WordPress from a blogging platform/CMS into a fully fledged application framework.

To start a service, you have own a own WordPress site, and use 2 plugins:

  1. WP REST API plugin, install and active (schedule uptake to core WP 4.4 and WP 4.5)
  2. BASIC Auth plugin, git clone https://github.com/WP-API/Basic-Auth basicAuth,  and active.

 

tinywebdb-base64 web service

WP REST API provide OAuth 1.0a and Basic Auth algorithm. Currently it is no way to use OAuth 1.0a on App Inventor, so I use Basic Auth on this app. Because , I create a tinywebdb-base64 program, which use App Inventor Tinywebdb feature to get value = base64_encode(tag) . You need install tinywebdb-base64 program on your server and set URL to program. You can feel free to use my tinywebdb-base64 web service.

Photoblog

Project Title. Easy Photo Blog publisher

Elevator Pitch. This cloud app pickup a photo from device’s image gallay, save the photo on self hosted WordPress site as a media file,and create a post with the media file attachement.

Description.
The Easy Photo Blog publisher is a mobile app that make easy to publish a post with photo to self hosted WordPress site. To make a post, user could follow steps:

  1. Type the post title
  2. Pickup a photo from device’s image gallay.
  3. Press “Post to madia” button to save the photo on WordPress site as a media file
  4. Type the post main content
  5. Press “Post Blog” to create a post with the media file attachement.

the app is easy way to make a photo blog to own WordPress site.

The app’s social benefit comes from its ability to make a quick post, and improve later, give a motivation to help user more publish. Also this a good example to use WordPress REST API.

screen1

Download and Test. Because this is a app using WordPress REST API, the only way to fully test its functionality would require using the WordPress REST API powered Blog site. You can feel free to use my test site. To download the app, scan the QR code to the left with the MIT AI2 Companion app or some other Scanner or click on this download link.

apk-download

a screen shot show a post on WordPress REST API powered Blog site.

2015-12-10 07.51.15
Technical Description. As shown in this screenshot, the app exceeds the project’s minimum technical requirements. It contains 2 global variables, 4 list data, 2 procedures or functions, and 2 if/else structure.

blocks2

Appendix.

The WP REST API is a WordPress plugin that intends to be eventually integrated into WordPress’ core as another (big) step towards transforming WordPress from a blogging platform/CMS into a fully fledged application framework.

WP REST API provide OAuth 1.0a and Basic Auth algorithm. it is no way to use OAuth 1.0a on App Inventor, so I use Basic Auth on this app. Basic Auth use base64 encode and not way to do on App Inventor, so on this app, just use a global variable to store a text which already encoded auth text.

Windows Live WrightがWordPressに接続できない。

かなり前からWLWでWordPress書く習慣があるが,最近一部のWordPressサイトはwlwに接続できない問題発生,サーバー側に接続しようとすると以下のようなメッセージが表示され接続(投稿)出来ない。
———————————————————————————————————————

ログイン中に予期しないエラーが発生しました。
サーバーの応答が無効ですーブログサーバーから受信した
blogger.getUsersBlogsメソッドへの応答が無効です。
invalid response document returned from XmlrRpc server

———————————————————————————————————————

原因はXML-RPC戻るXMLテキストの最后は破损。なんどもGoogleしたが、対策が見つからなかった。今天は遂に解决した。

オリジナルの対策は以下リンクにあるようです:

https://www.corelan.be/index.php/2008/10/14/windows-live-writer-unable-to-connect-to-wordpress-blog/

This is caused because something (a plugin ? my webserver (IIS) ? something else ?) decided to add UTF-8 BOM to the XML-RPC response. Result : the xml response is 3 bytes longer than expected, which causes the xml response to be truncated.

原因はIISの问题らしい。しかしこちら使うのはLAMP,でも対策は有効だ。

解決策:
(1)wp-includesパスにclass.IXR.phpファイルをみつけ,
(2) $length = strlen($xml);  を $length = strlen($xml)+3 に書換え

TinyWebDB for App Inventor Sample Project

App Inventor Sample Project

New Project

Start a new project from Project menu.

Put TinyWebDB component on screen and set ServiceURL to your WordPress Server with TinyWebDB API available.

Behavior Design

Put TinyWebDB component on screen and set ServiceURL to http://tinywebdb.ml/api

(or your WordPress Server with TinyWebDB API available)

スクリーンショット 2016-11-02 15.19.36

  • GetValue : get TinyWebDB value from WordPress server and set to TextBox.
  • StoreValue : Store TextBox  value to WordPress Server TinyWebDB plugin.

 

Programming

  • GetValue : get TinyWebDB value from WordPress server and set to TextBox.
  • StoreValue : Store TextBox  value to WordPress Server TinyWebDB plugin.

スクリーンショット 2016-11-02 15.19.11

Download

Download TinyWebDB Demo Code available on github.

下記のDownloadから、App Inventorで作ったAndroid test app サンプル を参考に、 ご自分のappを作る.

https://github.com/edu2web/TinyWebDB_Tester

tinywebdbdemo.aia is a minimal App Inventor project for WordPress TinyWebDB API Test.

注意点として、APIのURLは、最後の”/” を削除しでください。

Refer to Plugin URI to get sample Android test app which make by App Inventor, to create your own app.

Be sure to remove “/” on the tail of URL.

You need a WordPress Server with TinyWebDB API available, you can use my test server http://tinywebdb.ml/api , or install and setup your server follow steps on https://wp-api.net/tinywebdb-api/ .

Related links

WP- REST-API Setup

To Preparation WordPress wp-api,  you have three setup steps:

  1. JSON REST API
  2. Authenticate
  3. Permalink

JSON REST API

Grab the latest version of JSON REST API on WordPress plugin directory. Install and activate it.

Authenticate

There are three ways you can authenticate.

Using the cookies

This is one method not widely used when working with APIs. When a user navigates on the web, pages tend to store data on users side. The cookie method here is a bit different by using the nonces method.

OAuth

This plugin implements the version 1.0a of OAuth. This method is widely used. Google, Facebook, Twitter and Flickr use OAuth for third party authentication.

Basic Authentication

Using this method you have to send your username and password each time you make a request. Client tools for REST testing usually have this method implemented themselves. This method is mainly used when developing. Is rarely used on production. On production consider using OAuth.

the Basic Authentication plugin only on it’s GitHub repository.

git clone https://github.com/WP-API/Basic-Auth basicAuth

Permalink

Change the permalink configuration to any other that not default.

WP- REST-API with AppInventor

AppInventorはAndoridのApp作りに簡単な環境です。WordPressはWebコンテンツを作るに最適な環境。

AppInventor is a easy way to creating an Android app from web browser.  WordPress is a best web content management tool.

WP- REST-APIは、両者の長所を連携し、WordPressをAppInventorのWebサービスとして利用するためのAPIとして利用する。

WP- REST-API use you WordPress as a web service for AppInventor App.

API endpoint

 

Posts

Get

Post

Firefox_Screenshot_2015-09-05T10-22-07.193Z

Delete

Media

Post

Firefox_Screenshot_2015-09-05T10-24-14.020Z

Users

Get

WP- REST-API with Python

API endpoint

import http.client
 
def main():
    conn = http.client.HTTPConnection("wp-api.pw")
    
    conn.request("GET", "/wp-json/")
    res = conn.getresponse()
    print(res.status, res.reason)
    print(res.read())
    conn.close()
 
if __name__ == "__main__":
    main()

Posts

Get

Post

Delete

Media

Post

Users

Get

WP- REST-API with cURL

API endpoint

[chen@luna ~]$ curl -l http://wp-api.pw/wp-json/

Posts

Get

The Posts endpoint returns a Post Collection containing a subset of the site’s posts.

[chen@luna ~]$ curl -l http://wp-api.pw/wp-json/posts

Post

Create a Post Requires authentication

[chen@luna ~]$ cat data.json
{
    "title": "This is a post",
    "content_raw": "This is some content"
}
[chen@luna ~]$ curl --user test:password -X POST http://wp-api.pw/wp-json/posts --data @data.json

Delete

Delete a Post Requires authentication

[chen@luna ~]$ curl --user test:password -X DELETE http://wp-api.pw/wp-json/posts/229
{"message":"Deleted post"}

Media

Post

To create the raw data for an attachment. This is a binary object (blob), such as image data or a video.

[chen@luna ~]$ curl --user test:password -H 'Content-Type:image/jpeg' -H 'Content-Disposition: attachment; filename="test1551.jpg"' -X POST http://wp-api.pw/wp-json/media --data-binary @/home/chen/IMG_1551.jpg

Users

Get

This endpoint offers a permalink to get the current user, without needing to know the user’s ID.

get user self

[chen@luna ~]$ curl --user test:password http://wp-api.pw/wp-json/users/me

get user list

[chen@luna ~]$ curl --user test:password http://wp-api.pw/wp-json/users