Mostly bug fixes
Showing
4 changed files
with
45 additions
and
35 deletions
| 1 | <?php | 1 | <?php |
| 2 | namespace Tz\WordPress\Tools\Analytics; | 2 | namespace Tz\WordPress\Tools\Analytics; |
| 3 | 3 | ||
| 4 | use Tz; | ||
| 4 | use Tz\WordPress\Tools; | 5 | use Tz\WordPress\Tools; |
| 5 | 6 | ||
| 6 | const OPTION_NAME = 'tz_analytics'; | 7 | const OPTION_NAME = 'tz_analytics'; |
| ... | @@ -21,17 +22,18 @@ class Actions { | ... | @@ -21,17 +22,18 @@ class Actions { |
| 21 | return; | 22 | return; |
| 22 | } | 23 | } |
| 23 | ?> | 24 | ?> |
| 24 | <script type="text/javascript"> | 25 | <script type="text/javascript"> |
| 25 | var _gaq = _gaq || []; | 26 | var _gaq = _gaq || []; |
| 26 | _gaq.push(['_setAccount', '<?php echo Vars::$options['api_key']; ?>']); | 27 | _gaq.push(['_setAccount', '<?php echo Vars::$options['api_key']; ?>']); |
| 27 | _gaq.push(['_trackPageview']); | 28 | _gaq.push(['_trackPageview']); |
| 28 | 29 | ||
| 29 | (function() { | 30 | (function() { |
| 30 | var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | 31 | var ga = document.createElement('script'); ga.type = 'text/javascript'; |
| 31 | ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | 32 | ga.async = true; |
| 32 | var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | 33 | ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| 34 | var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | ||
| 33 | })(); | 35 | })(); |
| 34 | </script> | 36 | </script> |
| 35 | <?php | 37 | <?php |
| 36 | } | 38 | } |
| 37 | } | 39 | } | ... | ... |
| ... | @@ -40,7 +40,7 @@ class Actions { | ... | @@ -40,7 +40,7 @@ class Actions { |
| 40 | 40 | ||
| 41 | class Fields { | 41 | class Fields { |
| 42 | public static function api_key() { | 42 | public static function api_key() { |
| 43 | echo '<input tpe="text" name="' . Analytics\OPTION_NAME . '[' . __FUNCTION__ . ']" id="' . __FUNCTION__ . '" value="' . Analytics\Vars::$options[__FUNCTION__] . '" />'; | 43 | echo '<input type="text" name="' . Analytics\OPTION_NAME . '[' . __FUNCTION__ . ']" id="' . __FUNCTION__ . '" value="' . Analytics\Vars::$options[__FUNCTION__] . '" />'; |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | ?> | 46 | ?> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -28,6 +28,8 @@ namespace Tz\WordPress\Tools\Auth\Facebook; | ... | @@ -28,6 +28,8 @@ namespace Tz\WordPress\Tools\Auth\Facebook; |
| 28 | use Tz\WordPress\Tools; | 28 | use Tz\WordPress\Tools; |
| 29 | use Tz\WordPress\Tools\Auth; | 29 | use Tz\WordPress\Tools\Auth; |
| 30 | 30 | ||
| 31 | use FB; | ||
| 32 | |||
| 31 | use InvalidArgumentException; | 33 | use InvalidArgumentException; |
| 32 | 34 | ||
| 33 | const OPTION_NAME = 'tz_auth_fb'; | 35 | const OPTION_NAME = 'tz_auth_fb'; |
| ... | @@ -49,7 +51,8 @@ const OPTION_NAME = 'tz_auth_fb'; | ... | @@ -49,7 +51,8 @@ const OPTION_NAME = 'tz_auth_fb'; |
| 49 | * @returns NULL|String | 51 | * @returns NULL|String |
| 50 | */ | 52 | */ |
| 51 | function drawLoginButton($echo = true) { | 53 | function drawLoginButton($echo = true) { |
| 52 | $btn = '<a id="TzFB" class="fb_button fb_button_medium"><span class="fb_button_text">' . Vars::$options['button_title'] ?: 'Login' . '</span></a>'; | 54 | $title = Vars::$options['button_title'] ?: 'Login'; |
| 55 | $btn = '<a id="TzFB" class="fb_button fb_button_medium"><span class="fb_button_text">' . $title . '</span></a>'; | ||
| 53 | 56 | ||
| 54 | if (!$echo) { | 57 | if (!$echo) { |
| 55 | return $btn; | 58 | return $btn; |
| ... | @@ -58,21 +61,28 @@ function drawLoginButton($echo = true) { | ... | @@ -58,21 +61,28 @@ function drawLoginButton($echo = true) { |
| 58 | echo $btn; | 61 | echo $btn; |
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | function loadSDK() { | 64 | // This might need some work...what happens if the object fails? |
| 62 | static $loaded = false; | 65 | function getSDK() { |
| 63 | if ($loaded) { | 66 | static $instance = false; |
| 64 | return; | 67 | if (false === $instance) { |
| 68 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'facebook-sdk.php'); | ||
| 69 | $instance = new FB\Facebook(Array( | ||
| 70 | 'appId' => Vars::$options['application_id'] | ||
| 71 | , 'secret' => Vars::$options['application_secret'] | ||
| 72 | , 'cookie' => true | ||
| 73 | )); | ||
| 65 | } | 74 | } |
| 66 | $loaded = true; | 75 | |
| 67 | 76 | return $instance; | |
| 68 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'facebook-sdk.php'); | ||
| 69 | Vars::$sdk = new \FB\Facebook(Array( | ||
| 70 | 'appId' => Vars::$options['application_id'] | ||
| 71 | , 'secret' => Vars::$options['application_secret'] | ||
| 72 | , 'cookie' => true | ||
| 73 | )); | ||
| 74 | } | 77 | } |
| 75 | 78 | ||
| 79 | /* | ||
| 80 | * Logic for all these methods needs to be re-thought out | ||
| 81 | * Should only load FB stuff when something happens (decide) | ||
| 82 | * 1) drawLoginButton() has been called | ||
| 83 | * 2) User is on the login_page | ||
| 84 | * 3) Some other clever way of deciding if FB stuff should load | ||
| 85 | */ | ||
| 76 | class Actions { | 86 | class Actions { |
| 77 | /** | 87 | /** |
| 78 | * Logs the user in to WP if they logged into FB | 88 | * Logs the user in to WP if they logged into FB |
| ... | @@ -82,10 +92,10 @@ class Actions { | ... | @@ -82,10 +92,10 @@ class Actions { |
| 82 | global $post; // I want a better way to do this | 92 | global $post; // I want a better way to do this |
| 83 | 93 | ||
| 84 | if ($post->ID == Auth\Vars::$options['login_page'] && !is_user_logged_in()) { | 94 | if ($post->ID == Auth\Vars::$options['login_page'] && !is_user_logged_in()) { |
| 85 | loadSDK(); | 95 | $sdk = getSDK(); |
| 86 | 96 | ||
| 87 | if (Vars::$sdk->getSession()) { | 97 | if ($sdk->getSession()) { |
| 88 | $info = Vars::$sdk->api('/me'); | 98 | $info = $sdk->api('/me'); |
| 89 | // get email, verify vs database | 99 | // get email, verify vs database |
| 90 | // register and/or login | 100 | // register and/or login |
| 91 | } | 101 | } |
| ... | @@ -117,16 +127,21 @@ class Actions { | ... | @@ -117,16 +127,21 @@ class Actions { |
| 117 | * Destroy Facebook session data on site if the log out of WordPress | 127 | * Destroy Facebook session data on site if the log out of WordPress |
| 118 | */ | 128 | */ |
| 119 | public static function wp_logout() { | 129 | public static function wp_logout() { |
| 120 | loadSDK(); | 130 | $sdk = getSDK(); |
| 121 | Vars::$sdk->setSession(); // I think this is how you log them out of Facebook | 131 | $sdk->setSession(); // I think this is how you log them out of Facebook |
| 122 | } | 132 | } |
| 123 | } | 133 | } |
| 124 | 134 | ||
| 125 | class ShortCodes { | 135 | class ShortCodes { |
| 126 | public static function fb_login_button() { | 136 | public static function fb_login_button() { |
| 127 | if (Vars::$sdk->getSession()) { | 137 | if (is_user_logged_in()) { |
| 138 | return ''; | ||
| 139 | } | ||
| 140 | |||
| 141 | $sdk = getSDK(); | ||
| 142 | if ($sdk->getSession()) { | ||
| 128 | ob_start(); | 143 | ob_start(); |
| 129 | print_r(Vars::$sdk->api('/me')); | 144 | print_r($sdk->api('/me')); |
| 130 | $data = '<pre>' . ob_get_contents() . '</pre>'; | 145 | $data = '<pre>' . ob_get_contents() . '</pre>'; |
| 131 | ob_end_clean(); | 146 | ob_end_clean(); |
| 132 | 147 | ||
| ... | @@ -143,11 +158,5 @@ class Vars { | ... | @@ -143,11 +158,5 @@ class Vars { |
| 143 | * @type WP_Option | 158 | * @type WP_Option |
| 144 | */ | 159 | */ |
| 145 | public static $options; | 160 | public static $options; |
| 146 | |||
| 147 | /** | ||
| 148 | * An instance of Facebook's PHP SDK | ||
| 149 | * @type Facebook | ||
| 150 | */ | ||
| 151 | public static $sdk; | ||
| 152 | } | 161 | } |
| 153 | ?> | 162 | ?> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -10,8 +10,8 @@ namespace Tz\WordPress\Tools; | ... | @@ -10,8 +10,8 @@ namespace Tz\WordPress\Tools; |
| 10 | 10 | ||
| 11 | use Tz\WordPress\Tools\ShortCodes; | 11 | use Tz\WordPress\Tools\ShortCodes; |
| 12 | 12 | ||
| 13 | use \ReflectionClass, \ReflectionMethod; | 13 | use ReflectionClass, ReflectionMethod; |
| 14 | use \Exception; | 14 | use Exception; |
| 15 | 15 | ||
| 16 | spl_autoload_register(__NAMESPACE__ . '\autoloader'); | 16 | spl_autoload_register(__NAMESPACE__ . '\autoloader'); |
| 17 | 17 | ||
| ... | @@ -36,7 +36,6 @@ function import($com) { | ... | @@ -36,7 +36,6 @@ function import($com) { |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | function autoloader($class) { | 38 | function autoloader($class) { |
| 39 | |||
| 40 | $a = explode('\\', $class); | 39 | $a = explode('\\', $class); |
| 41 | $class = array_pop($a); | 40 | $class = array_pop($a); |
| 42 | 41 | ... | ... |
-
Please register or sign in to post a comment