/** * Returns the translations array * * @return array */ private function get_translations() { $categories = isset($_POST['ai1ec_categories']) ? $_POST['ai1ec_categories'] : array(); foreach ($categories as &$cat) { $term = get_term($cat, 'events_categories'); $cat = $term->name; } $translations = array('[feed_url]' => $_POST['ai1ec_calendar_url'], '[categories]' => implode(', ', $categories), '[user_email]' => $_POST['ai1ec_submitter_email'], '[site_title]' => get_bloginfo('name'), '[site_url]' => ai1ec_site_url(), '[feeds_url]' => ai1ec_admin_url(AI1EC_FEED_SETTINGS_BASE_URL . '#ics')); return $translations; }
/** * Returns path for cookies. * * @return string */ public function get_path_for_cookie() { $parsed = parse_url(ai1ec_site_url()); return isset($parsed['path']) ? $parsed['path'] : '/'; }
/** * Create a calendar when the user is signup */ protected function _create_calendar() { $body = array('title' => get_bloginfo('name'), 'url' => ai1ec_site_url(), 'timezone' => $this->_settings->get('timezone_string')); $request = array('headers' => $this->_get_headers(), 'body' => json_encode($body), 'timeout' => self::DEFAULT_TIMEOUT); $response = wp_remote_post(AI1EC_API_URL . 'calendars', $request); $response_code = wp_remote_retrieve_response_code($response); $response_body = json_decode($response['body']); if (200 === $response_code) { return $response_body->id; } else { return 0; } }
/** * Get base URL of WP installation * * @return string URL where WP is installed */ public function get_site_url() { if (null === $this->_site_url) { $this->_site_url = ai1ec_site_url(); } return $this->_site_url; }
/** * _safe_file_name method * * Generate safe file name for any storage case. * * @param string $file File name currently supplied * * @return string Sanitized file name */ protected function _safe_file_name($file) { static $prefix = null; $extension = $this->_get_extension_for_file($file); if (null === $prefix) { // always include site_url when there is more than one $pref_string = ai1ec_site_url(); if (!AI1EC_DEBUG) { // address multiple re-saves for a single version // i.e. when theme settings are being edited $pref_string .= mt_rand(); } $prefix = substr(md5($pref_string), 0, 8); } $length = strlen($file); if (!ctype_alnum($file)) { $file = preg_replace('|_+|', '_', preg_replace('|[^a-z0-9\\-,_]|', '_', $file)); } if (0 !== strncmp($file, $prefix, 8)) { $file = $prefix . '_' . $file; } return $file . $extension; }
/** * Create a calendar when the user is signup */ protected function _create_calendar() { $body = array('title' => get_bloginfo('name'), 'url' => ai1ec_site_url(), 'timezone' => $this->_settings->get('timezone_string')); $response = $this->request_api('POST', AI1EC_API_URL . 'calendars', json_encode($body)); if ($this->is_response_success($response)) { return $response->body->id; } else { $this->log_error($response, 'Created calendar'); return 0; } }