\Gianism\ServiceTwitter

Description of twitter_controller

Summary

Methods
Properties
Constants
is_connected()
disconnect()
send_dm()
tweet()
get_mentions()
call_api()
is_pseudo_mail()
mail_handler()
set_option()
parse_request()
handle_login()
profile_connect()
connection_message()
login_form()
filter_link()
button()
login_button()
connect_button()
disconnect_button()
user_can_register()
__get()
get_instance()
_()
e()
get()
post()
request()
nonce_action()
nonce_create()
nonce_field()
verify_nonce()
is_ssl_required()
is_enabled()
get_meta_owner()
get_service_instance()
$url_prefix
$tw_screen_name
$umeta_id
$umeta_screen_name
$verbose_service_name
$message_key_name
$service_name
$enabled
$dir
$url
$all_services
$nonce_key_name
No constants found
__construct()
handle_default()
get_api_url()
wp_mail()
init_action()
handle_connect()
handle_disconnect()
get_redirect_to()
get_action()
filter_redirect()
get_redirect_endpoint()
is_smartphone()
hook_connect()
hook_disconnect()
user_password_unknown()
valid_username_from_mail()
api_error_string()
duplicate_account_string()
welcome()
auth_fail()
mail_fail_string()
registration_error_string()
kill_wrong_access()
test_user_can_register()
get_response()
add_message()
wp_die()
session_write()
session_get()
session_delete()
$tw_consumer_key
$tw_consumer_secret
$tw_access_token
$tw_access_token_secret
$tw_use_cron
$pseudo_domain
$api_root
$option_keys
$name
$version
$domain
N/A
get_oauth()
validate_token()
follow_me()
$oauth
$instances
$_all_services
N/A

Properties

$url_prefix

$url_prefix : string

URL prefix

If this property is empty, service name will be used. e.g. http://example.jp/facebook/

Type

string

$tw_screen_name

$tw_screen_name : string

Screen name of admin

Type

string

$umeta_id

$umeta_id : string

User's twitter id

Type

string

$umeta_screen_name

$umeta_screen_name : string

User's scrren name

Type

string

$verbose_service_name

$verbose_service_name : string

Verbose service name

If not set, $this->service_name will be used;

Type

string

$message_key_name

$message_key_name : string

Message post type

Type

string

$service_name

$service_name : string

Type

string

$enabled

$enabled : bool

Type

bool

$dir

$dir : string

Type

string

$url

$url : string

Type

string

$all_services

$all_services : array

Type

array

$nonce_key_name

$nonce_key_name : string

Type

string

$tw_consumer_key

$tw_consumer_key : string

Consumer key

Type

string

$tw_consumer_secret

$tw_consumer_secret : string

Consumer secret

Type

string

$tw_access_token

$tw_access_token : string

Access token of admin

Type

string

$tw_access_token_secret

$tw_access_token_secret : string

Access token secret of admin

Type

string

$tw_use_cron

$tw_use_cron : bool

If use cron bot

Type

bool

$pseudo_domain

$pseudo_domain : string

Pseudo domain

Type

string

$api_root

$api_root : string

Endpoint root. Untrailed with slash.

Type

string

$option_keys

$option_keys : array

Option key to retrieve

Type

array

$name

$name : string

Name

Used for option key, nonce, etc.

Type

string

$version

$version : string

Version number

Type

string

$domain

$domain : string

i18n Domain

Type

string

$oauth

$oauth : \TwitterOAuth

Type

\TwitterOAuth

$instances

$instances : \Gianism\Singleton

Instance holder

Type

\Gianism\Singleton

$_all_services

$_all_services : array

All services

Type

array

Methods

is_connected()

is_connected(int $user_id) : bool

Detect if user is connected to this service

Parameters

int $user_id

Returns

bool

disconnect()

disconnect(int $user_id) : mixed

Disconnect user from this service

Parameters

int $user_id

Returns

mixed

send_dm()

send_dm(int $user_id, string $text) : object

Send direct message on twitter.

Parameters

int $user_id
string $text

Returns

object

tweet()

tweet(string $string) : object

Tweet with Owner ID

Parameters

string $string

Returns

object —

Json format object.

get_mentions()

get_mentions(array $args) : object

Get mentions

Parameters

array $args

Returns

object

call_api()

call_api(string $endpoint, array $data, string $method, \TwitterOAuth $oauth) : object

Returns GET api request.

You should know what kind of APIs are available.

Parameters

string $endpoint

API URL. Must not be started with slash. i.e. 'statuses/user_timeline'

array $data
string $method

GET or POST. Default GET

\TwitterOAuth $oauth

If not set, create own.

Returns

object —

Maybe JSON object.

is_pseudo_mail()

is_pseudo_mail(string $mail) : bool

This controller reutrn always false

Parameters

string $mail

Returns

bool

mail_handler()

mail_handler(array $args) : array

Override default wp_mai

Parameters

array $args

Returns

array

set_option()

set_option() : void

Setup default option

parse_request()

parse_request(string $action, \WP_Query $wp_query) : void

Called on redirect endpoint

Parameters

string $action
\WP_Query $wp_query

handle_login()

handle_login(\WP_Query $wp_query)

Make user login

Parameters

\WP_Query $wp_query

profile_connect()

profile_connect(\WP_User $user) : void

Show connect button on profile page

Parameters

\WP_User $user

connection_message()

connection_message(string $context) : string

Connection message

Overriding this function, you can customize connection message

Parameters

string $context

Returns

string

login_form()

login_form(boolean $is_register) : void

Display login buttons

Parameters

boolean $is_register

filter_link()

filter_link(string $markup, string $href, string $text, bool $is_register) : string

Resturns link to filter

Parameters

string $markup
string $href
string $text
bool $is_register

Returns

string

button()

button(string $text, string $href, bool $icon_name, array $class_names, array $attributes) : string

Create common button

Parameters

string $text
string $href
bool $icon_name
array $class_names
array $attributes

Returns

string

login_button()

login_button(string $redirect, bool $register) : string

Show login button

Parameters

string $redirect
bool $register

Returns

string

connect_button()

connect_button(string $redirect_to) : string

Get connect button

Parameters

string $redirect_to

If not set, profile page's URL

Returns

string

disconnect_button()

disconnect_button(string $redirect_to) : string

Get disconnect button

Parameters

string $redirect_to

If not set, profile page's URL

Returns

string

user_can_register()

user_can_register() : bool

Detect if user can register

Returns

bool

__get()

__get(string $name) : mixed

Getter

Parameters

string $name

Returns

mixed

get_instance()

get_instance(array $argument) : self

Get instance

Parameters

array $argument

Returns

self

_()

_(string $string) : string

Alias of __

Parameters

string $string

Returns

string

e()

e(string $string)

Alias of _e

Parameters

string $string

get()

get(string $key) : mixed

Return $_GET

Parameters

string $key

Returns

mixed

post()

post(string $key) : mixed

Return $_POST

Parameters

string $key

Returns

mixed

request()

request(string $key) : mixed

return $_REQUEST

Parameters

string $key

Returns

mixed

nonce_action()

nonce_action(string $action) : string

Return nonce name with prefix

Parameters

string $action

Returns

string

nonce_create()

nonce_create(string $action) : string

Parameters

string $action

Returns

string

nonce_field()

nonce_field(string $action, bool $referrer)

Alias of wp_nonce_field

Parameters

string $action
bool $referrer

Default false.

verify_nonce()

verify_nonce(string $action, string $referrer) : boolean

Check nonce

Parameters

string $action
string $referrer

Returns

boolean

is_ssl_required()

is_ssl_required() : boolean

Returns if login is forced to use SSL.

To override it, use filter gianism_force_ssl_login

Returns

boolean

is_enabled()

is_enabled(string $service) : bool

Determine if service is enabled.

Parameters

string $service

If not specified, one of the services are enabled, return true.

Returns

bool

get_meta_owner()

get_meta_owner(string $key, string $value) : int

Retrieve user meta's owner ID

Parameters

string $key
string $value

Returns

int —

User ID. If not exists, return 0

get_service_instance()

get_service_instance(string $service) : null|\Gianism\Service\Common\Mail

Get service instance

Parameters

string $service

Returns

null|\Gianism\Service\Common\Mail

__construct()

__construct(array $argument)

Constructor

Parameters

array $argument

handle_default()

handle_default(string $action) : void

Handle callback request

This function must exit at last.

Parameters

string $action

get_api_url()

get_api_url(string $action) : string|false

Return api URL to authenticate

If you need additional information (ex. token), use $this->session_write inside.

$this->session_write('token', $token); return $url;

Parameters

string $action

'connect', 'login'

Throws

\Exception

Returns

string|false —

URL to redirect

wp_mail()

wp_mail(int $user_id, string $subject, string $message, array|string $headers, string $attachment) : void

Alternative wp_mail

Parameters

int $user_id
string $subject
string $message
array|string $headers
string $attachment

init_action()

init_action() : void

Initialize

If some stuff is required, override this.

handle_connect()

handle_connect(\WP_Query $wp_query)

Handle connect

Parameters

\WP_Query $wp_query

handle_disconnect()

handle_disconnect(\WP_Query $wp_query)

Handle disconnect

Parameters

\WP_Query $wp_query

get_redirect_to()

get_redirect_to(string $default, array $args) : string

Returns redirect to url if set.

Parameters

string $default
array $args

Returns

string

get_action()

get_action() : string

Returns current action name.

Returns

string

filter_redirect()

filter_redirect(string $url, string $context) : string

Filter redirect URL

Parameters

string $url
string $context

login, connect, disconnect

Returns

string

get_redirect_endpoint()

get_redirect_endpoint(string $action, string $nonce_key, array $args) : string

Get URL for immediate endpoint.

Parameters

string $action

'connect', 'disconnect', 'login' or else.

string $nonce_key

If empty, nonce won't be set.

array $args

Returns

string

is_smartphone()

is_smartphone() : boolean

Detect if current client is smartphone.

Returns

boolean

hook_connect()

hook_connect(int $user_id, mixed $data, bool $on_creation)

Fires connect hook

Parameters

int $user_id
mixed $data
bool $on_creation

hook_disconnect()

hook_disconnect(mixed $user_id)

Fires disconnect hook

Parameters

mixed $user_id

user_password_unknown()

user_password_unknown(int $user_id)

Use's password is automatically generated

Parameters

int $user_id

valid_username_from_mail()

valid_username_from_mail(string $email) : string

Create valid username from email address

Parameters

string $email

Throws

\Exception

Returns

string

api_error_string()

api_error_string() : string

Returns API error string

Returns

string

duplicate_account_string()

duplicate_account_string() : string

Message account duplication

Returns

string

welcome()

welcome(string $who)

Add welcome message

Parameters

string $who

auth_fail()

auth_fail(string $message)

Add error message

Parameters

string $message

mail_fail_string()

mail_fail_string() : string

Add error message

Returns

string

registration_error_string()

registration_error_string() : string

Registration error string

Returns

string

kill_wrong_access()

kill_wrong_access()

Kill wrong access

test_user_can_register()

test_user_can_register() : bool

Test if can register.

Throws

\Exception

Returns

bool

get_response()

get_response(string $endpoint, string|array $request, string $method, bool $json, array $additional_headers) : array|\stdClass|bool|null

Get Request

Parameters

string $endpoint
string|array $request
string $method

If x-www-form-urlencoded required, pass array or else, pass query string.

bool $json

if this request is JSON

array $additional_headers

Additional headers.

Returns

array|\stdClass|bool|null

add_message()

add_message(string $string, bool $error)

Add message to show

Parameters

string $string
bool $error

wp_die()

wp_die(string $message, int $status_code, bool $return)

Short hand for wp_die

Parameters

string $message
int $status_code
bool $return

session_write()

session_write(string $key, mixed $value)

Write session

Parameters

string $key
mixed $value

session_get()

session_get(string $key) : bool

Get session

After get, session key will be deleted.

Parameters

string $key

Returns

bool

session_delete()

session_delete(string $key)

Delete session

Parameters

string $key

get_oauth()

get_oauth(string $oauth_token, string $oauth_token_secret) : \TwitterOAuth

Get API wrapper

Parameters

string $oauth_token
string $oauth_token_secret

Returns

\TwitterOAuth

validate_token()

validate_token(mixed $token, bool $url_confirmed) : bool

Validate token

Parameters

mixed $token
bool $url_confirmed

If redirect URL must be validated

Returns

bool

follow_me()

follow_me(\TwitterOAuth $oauth) : object

Force authenticated user to follow me

Parameters

\TwitterOAuth $oauth

Returns

object —

Json format object.