/** * Load Statics **/ function espiral_statics() { $deps = array(); $version = "2.0.0.8"; $footer = true; $path = get_template_directory_uri(); // Normalize CSS $src = "{$path}/css/normalize.css"; wp_enqueue_style("normalize", $src, $deps, $version); // Hover CSS $src = "{$path}/css/hover-min.css"; wp_enqueue_style("hover", $src, $deps, $version); // Fontawesome wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'); if (is_live()) { $handle = "custom-css"; $src = "{$path}/css/compiled.css"; wp_enqueue_style($handle, $src, $deps, $version); } else { // Less $handle = "custom-style"; $src = "{$path}/less/style.less"; wp_enqueue_style($handle, $src, $deps, $version); } // Script wp_enqueue_script('app', get_template_directory_uri() . '/js/app.js', array(), '1.0.0', true); }
function set_development() { // $_ENV['DEBUG'] = '/tmp/sql.txt'; $_ENV['DEBUG'] = ''; if (!is_live() && isset($_ENV['DEBUG']) && !empty($_ENV['DEBUG'])) { file_put_contents($_ENV['DEBUG'], ''); } }
function callback() { $this->_secure(); $fields_string = ''; $get_params = get_to_assoc(); $auth_code = $get_params['code']; $state = $get_params['state']; $post_data['code'] = $auth_code; $post_data['client_id'] = $this->google_auth->client_id; $post_data['client_secret'] = $this->google_auth->client_key; $post_data['redirect_uri'] = 'http://' . $_SERVER['SERVER_NAME'] . '/googleauth/callback'; $post_data['grant_type'] = 'authorization_code'; // New auth url set after authorization token received and its has to be posted to get the access token $config['auth_url'] = 'https://accounts.google.com/o/oauth2/token'; $this->google_auth->initialize($config); // The following will post the retrived authorization token to get the access token from the google oauth server $response = $this->google_auth->get_access_token($post_data); if (isset($response['error'])) { die($response['error']); } else { $this->load->model('model_google_accounts'); $user = $this->session->all_userdata(); $google_account_id = $state; // Verify that this account is definitely for this user $google_account = $this->model_google_accounts->get_records(array('client_id' => $user['client_id'], 'google_account_id' => $google_account_id)); if (!empty($google_account)) { $google_account_data = array(); $google_account_data['client_id'] = $user['client_id']; $google_account_data['google_account_id'] = $google_account_id; $google_account_data[is_live() ? 'refresh_token' : 'dev_refresh_token'] = $response['refresh_token']; $this->model_google_accounts->save($google_account_data); $this->session->set_userdata('tab_nav_id', 'google_accounts_link'); $this->session->set_flashdata('flash_message', 'Thank you - your Google account has been authorised.'); redirect('/users/admin/google_accounts'); } } }
function get_google_data($url = '', $refresh_token = '', &$access_token = '', $parameters = array()) { $result = array(); if (!empty($url)) { if (!empty($refresh_token) && empty($access_token)) { $CI =& get_instance(); $CI->load->library('google_auth'); $CI->google_auth->auth_url = 'https://accounts.google.com/o/oauth2/token'; $post_data = array(); if (is_live()) { $post_data['client_id'] = get_app_var('GOOGLE_CLIENT_ID'); $post_data['client_secret'] = get_app_var('GOOGLE_CLIENT_KEY'); } else { $post_data['client_id'] = get_app_var('GOOGLE_DEV_CLIENT_ID'); $post_data['client_secret'] = get_app_var('GOOGLE_DEV_CLIENT_KEY'); } $post_data['refresh_token'] = $refresh_token; $post_data['grant_type'] = 'refresh_token'; $response = $CI->google_auth->get_access_token($post_data); if (isset($response['access_token'])) { $access_token = $response['access_token']; } } if (!empty($access_token)) { $url .= '?access_token=' . $access_token; if (!empty($parameters)) { $url .= '&' . implode('&', $parameters); } $result = @file_get_contents($url); if ($result == false) { log_message('error', 'Failed to read URL: ' . $url); } else { $result = json_decode($result, true); if (isset($result['items'])) { $result = $result['items']; } } } } return $result; }
function deauthorise_google_account() { $this->_secure(50); $result = 'Sorry, but there seems to be a problem with your credentials.'; $user = $this->session->all_userdata(); $post_data = $_POST; if (!empty($post_data)) { if (isset($post_data['google_account_id'])) { $this->load->model('model_google_accounts'); $google_account = $this->model_google_accounts->get_records(array('client_id' => $user['client_id'], 'google_account_id' => $post_data['google_account_id'])); if (!empty($google_account)) { $google_account_data = array(); $google_account_data['google_account_id'] = $post_data['google_account_id']; $google_account_data[is_live() ? 'refresh_token' : 'dev_refresh_token'] = ''; $this->model_google_accounts->save($google_account_data); $result = 'Your Google account has been deauthorised.'; } } } $data = array(); $data['any'] = $result; $data['action_view'] = 'misc/any'; $this->load->view('layouts/blank', $data); }
* Enviroment Validator * @return bool **/ function is_live() { $chost = $_SERVER["HTTP_HOST"]; $rhost = "espiralsanadora.cl"; return $chost == $rhost or $chost == "www.{$rhost}"; } // Enviroment Config $env_url = "http://www.dev.espiral.cl"; $env_debug = FALSE; $env_db_name = "espiral"; $env_db_user = "******"; $env_db_pass = ""; if (is_live()) { $env_url = 'http://www.espiralsanadora.cl'; $env_debug = FALSE; $env_db_name = "espirals_sanadora"; $env_db_user = "******"; $env_db_pass = "******"; } // Site Url define('WP_HOME', $site_url); define('WP_SITEURL', $site_url); // SSL define('FORCE_SSL_ADMIN', false); define('FORCE_SSL_LOGIN', false); // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', $env_db_name);
function is_local() { return !is_live(); }
function update_account_data($google_account_id = 0, &$access_token = '') { $result = array(); if (!empty($google_account_id)) { $CI =& get_instance(); $CI->load->model('model_google_sites'); $google_account = $this->get_records(array('google_account_id' => $google_account_id)); $refresh_token = is_live() ? $google_account[0]['refresh_token'] : $google_account[0]['dev_refresh_token']; $accounts = get_google_data('https://www.googleapis.com/analytics/v3/management/accounts', $refresh_token, $access_token); if (!empty($accounts)) { foreach ($accounts as $account) { if (isset($account['childLink']['href'])) { $properties = get_google_data($account['childLink']['href'], $refresh_token, $access_token); if (!empty($properties)) { foreach ($properties as $property) { if (isset($property['childLink']['href'])) { $profiles = get_google_data($property['childLink']['href'], $refresh_token, $access_token); if (!empty($profiles)) { foreach ($profiles as $profile) { $google_site = $CI->model_google_sites->get_records(array('client_id' => $google_account[0]['client_id'], 'profile_id' => $profile['id'])); $google_site_data = array(); if (empty($google_site)) { $google_site_data['client_id'] = $google_account[0]['client_id']; $google_site_data['google_account_id'] = $google_account_id; } else { $google_site_data['google_site_id'] = $google_site[0]['google_site_id']; } $google_site_data['account_id'] = $account['id']; $google_site_data['account_name'] = $account['name']; $google_site_data['web_property_id'] = $property['id']; $google_site_data['web_property_name'] = $property['name']; $google_site_data['website_url'] = $property['websiteUrl']; $google_site_data['profile_id'] = $profile['id']; $google_site_data['profile_name'] = $profile['name']; $google_site_data['currency'] = $profile['currency']; $google_site_data['timezone'] = $profile['timezone']; $google_site_data['last_updated_date'] = strtotime($profile['updated']); $google_site_data['disconnected_flag'] = '0'; $result[] = $CI->model_google_sites->save($google_site_data); } } } } } } } $this->save(array('google_account_id' => $google_account_id, 'last_checked_date' => mktime())); } } return $result; }