PluginProbe
Gianism / 1.0
Gianism v1.0
4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.4.0 5.0.0 5.0.1 5.0.2 5.1.0 5.2.1 5.2.2 5.3.0 6.0.0 6.0.1 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 65 releases
gianism / sdks / gianism_controller.php

gianism_controller.php in Gianism 1.0, at sdks/gianism_controller.php

136 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common Utility for Social Service
4 *
5 * @package gianism
6 */
7 class Gianism_Controller {
8
9 /**
10 * Print Javascript if true.
11 * @var boolean
12 */
13 protected $js = false;
14
15 /**
16 * Script to print on footer.
17 * @var string
18 */
19 protected $scripts = '';
20
21 /**
22 * Pseudo domain
23 * @var string
24 */
25 protected $pseudo_domain = '';
26
27 /**
28 * Constructor
29 * @param array $option
30 */
31 public function __construct($option) {
32 $this->set_option($option);
33 if(method_exists($this, 'init_action')){
34 $this->init_action();
35 }
36 if(method_exists($this, 'user_profile')){
37 //Add Hook on Profile page
38 add_action('gianism_user_profile', array($this, 'user_profile'));
39 }
40 if(method_exists($this, 'login_form')){
41 //Add Hook on Login Form page
42 add_action('gianism_login_form', array($this, 'login_form'));
43 //Add Hook on Register Form
44 if(!method_exists($this, 'register_form')){
45 add_action('gianism_regsiter_form', array($this, 'login_form'));
46 }
47 }
48 if(method_exists($this, 'register_form')){
49 //Add Hook on Profile page
50 add_action('gianism_regsiter_form', array($this, 'register_form'));
51 }
52 if(method_exists($this, 'print_script')){
53 //Add Hook On footer
54 add_action('admin_print_footer_scripts', array($this, 'print_script'));
55 add_action('wp_footer', array($this, 'print_script'));
56 }
57 if(method_exists($this, 'wp_mail')){
58 add_filter('wp_mail', array($this, '_wp_mail'));
59 }
60 }
61
62 /**
63 * Setup default option
64 * @param array $option
65 * @return null
66 */
67 protected function set_option($option){
68 return;
69 }
70
71 /**
72 * Returns redirect to url if set.
73 * @param string $default
74 * @param array $args
75 * @return string
76 */
77 protected function get_redirect_to($default, $args = array()){
78 if(isset($_REQUEST['redirect_to'])){
79 $domain = $_SERVER['SERVER_NAME'];
80 if(preg_match("/^(https?:\/\/{$domain}|\/)/", $_REQUEST['redirect_to'])){
81 $redirect_to = $_REQUEST['redirect_to'];
82 if(!empty($args)){
83 $redirect_to .= (false !== strpos($redirect_to, '?')) ? '&' : '?';
84 $counter = 0;
85 foreach($args as $key => $val){
86 if($counter == 0){
87 $redirect_to .= '&';
88 }
89 $redirect_to .= $key.'='.rawurlencode($val);
90 $counter++;
91 }
92 }
93 return $redirect_to;
94 }else{
95 return $default;
96 }
97 }else{
98 return $default;
99 }
100 }
101
102 /**
103 * Returns current action name.
104 * @return string
105 */
106 protected function get_action(){
107 if(isset($_REQUEST['wpg'])){
108 return (string)$_REQUEST['wpg'];
109 }else{
110 return '';
111 }
112 }
113
114 /**
115 * Retuns if given mail address is pseudo.
116 * @param string $mail
117 * @return boolean
118 */
119 protected function is_pseudo_mail($mail){
120 return !empty($this->pseudo_domain) && (false !== strpos($mail, "@".$this->pseudo_domain));
121 }
122
123 /**
124 *
125 * @param type $args
126 * @return type
127 */
128 public function _wp_mail($args){
129 extract($args);
130 if(!empty($this->pseudo_domain) && false !== strpos($to, "@".$this->pseudo_domain) && ($user_id = email_exists($to))){
131 $this->wp_mail($user_id, $subject, $message, $headers, $attchment);
132 }
133 return $args;
134 }
135 }
136