public function render(array $params) { $this->_dump_buffers(); header('Content-type: text/calendar; charset=utf-8'); echo $params['data']; return Ai1ec_Http_Response_Helper::stop(0); }
/** * Renders the css for our frontend. * * Sets etags to avoid sending not needed data */ public function render_css() { header('HTTP/1.1 200 OK'); header('Content-Type: text/css', true, 200); // Aggressive caching to save future requests from the same client. $etag = '"' . md5(__FILE__ . $_GET[self::QUERY_STRING_PARAM]) . '"'; header('ETag: ' . $etag); $max_age = 31536000; $time_sys = $this->_registry->get('date.system'); header('Expires: ' . gmdate('D, d M Y H:i:s', $time_sys->current_time() + $max_age) . ' GMT'); header('Cache-Control: public, max-age=' . $max_age); if (empty($_SERVER['HTTP_IF_NONE_MATCH']) || $etag !== stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) { // compress data if possible $compatibility_ob = $this->_registry->get('compatibility.ob'); if ($this->_registry->get('http.request')->client_use_gzip()) { $compatibility_ob->start('ob_gzhandler'); header('Content-Encoding: gzip'); } else { $compatibility_ob->start(); } $content = $this->get_compiled_css(); echo $content; $compatibility_ob->end_flush(); } else { // Not modified! status_header(304); } // We're done! Ai1ec_Http_Response_Helper::stop(0); }
public function render(array $params) { $this->_dump_buffers(); header('HTTP/1.1 200 OK'); header('Content-Type: text/xml; charset=UTF-8'); $data = Ai1ec_Http_Response_Helper::utf8($params['data']); $output = Ai1ec_XML_Builder::serialize_to_xml($data); echo $output; return Ai1ec_Http_Response_Helper::stop(0); }
public function render(array $params) { $this->_dump_buffers(); header('HTTP/1.1 200 OK'); header('Content-Type: application/json; charset=UTF-8'); $data = Ai1ec_Http_Response_Helper::utf8($params['data']); $output = json_encode($data); if (!empty($params['callback'])) { $output = $params['callback'] . '(' . $output . ')'; } echo $output; return Ai1ec_Http_Response_Helper::stop(0); }
public function render(array $params) { $this->_dump_buffers(); header('Content-Type: application/force-download; name="calendar.xml"'); header('Content-type: text/xml'); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="calendar.xml"'); header('Expires: 0'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); echo $params['data']; return Ai1ec_Http_Response_Helper::stop(0); }
/** * Checks if current request is direct for Events cats/tags and redirects * to filtered calendar. * * @param WP $wpobj WP object. * * @return void Method does not return. */ public function handle_categories_and_tags(WP $wpobj) { $cats = Ai1ec_Event_Taxonomy::CATEGORIES; $tags = Ai1ec_Event_Taxonomy::TAGS; if (!isset($wpobj->query_vars) || !isset($wpobj->query_vars[$cats]) && !isset($wpobj->query_vars[$tags])) { return; } $is_cat = isset($wpobj->query_vars[$cats]); $is_tag = isset($wpobj->query_vars[$tags]); if ($is_cat) { $query_ident = $cats; $url_ident = 'cat_ids'; } if ($is_tag) { $query_ident = $tags; $url_ident = 'tag_ids'; } $term = get_term_by('slug', $wpobj->query_vars[$query_ident], $query_ident); if (!$term) { return; } $href = $this->_registry->get('html.element.href', array($url_ident => $term->term_id)); return Ai1ec_Http_Response_Helper::redirect($href->generate_href(), 301); }
public function render(array $params) { $this->_dump_buffers(); $now = gmdate('D, d M Y H:i:s'); $filename = $params['filename']; header('Expires: Tue, 03 Jul 2001 06:00:00 GMT'); header('Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate'); header('Last-Modified: ' . $now . ' GMT'); // force download header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream'); header('Content-Type: application/download'); // disposition / encoding on response body header('Content-Disposition: attachment;filename="' . addcslashes($filename, '"') . '"'); header('Content-Transfer-Encoding: binary'); $columns = $params['columns']; for ($i = 0; $i < count($columns); $i++) { if ($i > 0) { echo ','; } echo $columns[$i]; } echo "\n"; $data = $params['data']; for ($i = 0; $i < count($data); $i++) { $row = $data[$i]; for ($j = 0; $j < count($row); $j++) { if ($j > 0) { echo ','; } echo $row[$j]; } echo "\n"; } return Ai1ec_Http_Response_Helper::stop(0); }
/** * Parse all the less files resolving the dependencies. * * @param array $variables * @param bool $compile_core If set to true, it forces compilation of core CSS only, suitable for shipping. * @throws Ai1ec_File_Not_Found_Exception|Exception * @throws Exception * @return string */ public function parse_less_files(array $variables = null, $compile_core = false) { // If no variables are passed, initialize from DB, config file, and // extension injections in one call. if (empty($variables)) { $variables = $this->get_saved_variables(false); } // convert the variables to key / value $variables = $this->convert_less_variables_for_parsing($variables); // Inject additional constants from extensions $variables = apply_filters('ai1ec_less_constants', $variables); // Use this variables for hashmap purposes. $this->variables = $variables; // Load the static variables defined in the theme's variables.less file. $this->load_static_theme_variables(); $loader = $this->_registry->get('theme.loader'); //Allow extensions to add their own LESS files. $this->files = apply_filters('ai1ec_less_files', $this->files); $this->files[] = 'override.less'; // Find out the active theme URL. $option = $this->_registry->get('model.option'); $theme = $option->get('ai1ec_current_theme'); $this->lessc->addImportDir($theme['theme_dir'] . DIRECTORY_SEPARATOR . 'less'); $import_dirs = array(); foreach ($this->files as $file) { $file_to_parse = null; try { // Get the filename following our fallback convention $file_to_parse = $loader->get_file($file); } catch (Ai1ec_Exception $e) { // We let child themes override styles of Vortex. // So there is no fallback for override and we can continue. if ($file !== 'override.less') { throw $e; } else { // It's an override, skip it. continue; } } // We prepend the unparsed variables.less file we got earlier. // We do this as we do not import that anymore in the less files. $this->unparsed_variable_file .= $file_to_parse->get_content(); // Set the import directories for the file. Includes current directory of // file as well as theme directory in core. This is important for // dependencies to be resolved correctly. $dir = dirname($file_to_parse->get_name()); if (!isset($import_dirs[$dir])) { $import_dirs[$dir] = true; $this->lessc->addImportDir($dir); } } $variables['fontdir'] = '~"' . Ai1ec_Http_Response_Helper::remove_protocols($theme['theme_url']) . '/font"'; $variables['fontdir_default'] = '~"' . Ai1ec_Http_Response_Helper::remove_protocols($this->default_theme_url) . 'font"'; $variables['imgdir'] = '~"' . Ai1ec_Http_Response_Helper::remove_protocols($theme['theme_url']) . '/img"'; $variables['imgdir_default'] = '~"' . Ai1ec_Http_Response_Helper::remove_protocols($this->default_theme_url) . 'img"'; if (true === $compile_core) { $variables['fontdir'] = '~"../font"'; $variables['fontdir_default'] = '~"../font"'; $variables['imgdir'] = '~"../img"'; $variables['imgdir_default'] = '~"../img"'; } try { $this->parsed_css = $this->lessc->parse($this->unparsed_variable_file, $variables); } catch (Exception $e) { throw $e; } // Replace font placeholders $this->parsed_css = preg_replace_callback('/__BASE64_FONT_([a-zA-Z0-9]+)_(\\S+)__/m', array($this, 'load_font_base64'), $this->parsed_css); return $this->parsed_css; }
public function do_execute() { $this->_registry->get('theme.compiler')->generate(); return Ai1ec_Http_Response_Helper::stop(0); }
/** * Echoes the Javascript if not cached. * * Echoes the javascript with the correct content. * Since the content is dinamic, i use the hash function. * * @param string $javascript * * @return void */ private function _echo_javascript($javascript) { $conditional_get = new HTTP_ConditionalGet(array('contentHash' => md5($javascript))); $conditional_get->sendHeaders(); if (!$conditional_get->cacheIsValid) { $http_encoder = $this->_registry->get('http.encoder', array('content' => $javascript, 'type' => 'text/javascript')); $compression_level = null; if ($this->_registry->get('model.settings')->get('disable_gzip_compression')) { // set the compression level to 0 to disable it. $compression_level = 0; } $http_encoder->encode($compression_level); $http_encoder->sendAll(); } Ai1ec_Http_Response_Helper::stop(0); }
public function do_execute() { $message = $this->_process_files(); echo $message; return Ai1ec_Http_Response_Helper::stop(0); }
/** * Install robotx.txt into current Wordpress instance * * @return void */ public function install() { $option = $this->_registry->get('model.option'); $settings = $this->_registry->get('model.settings'); $robots = $option->get('ai1ec_robots_txt'); if (isset($robots['page_id']) && $robots['page_id'] == $settings->get('calendar_page_id')) { return; } $ftp_base_dir = defined('FTP_BASE') ? FTP_BASE . DIRECTORY_SEPARATOR : ''; // we can't use ABSPATH for ftp, if ftp user is not chrooted they need // to define FTP_BASE in wp-config.php $robots_file = $ftp_base_dir . 'robots.txt'; $robots_txt = array(); $is_installed = false; $current_rules = null; $custom_rules = $this->rules('', false); $url = wp_nonce_url('edit.php?post_type=ai1ec_event&page=all-in-one-event-calendar-settings', 'ai1ec-nonce'); $redirect_url = ai1ec_admin_url('edit.php?post_type=ai1ec_event&page=all-in-one-event-calendar-settings&noredirect=1'); if (!function_exists('request_filesystem_credentials')) { return; } $type = get_filesystem_method(); if ('direct' === $type) { // we have to use ABSPATH for direct $robots_file = ABSPATH . 'robots.txt'; } $creds = request_filesystem_credentials($url, $type, false, false, null); if (!WP_Filesystem($creds)) { $error_v = isset($_POST['hostname']) || isset($_POST['username']) || isset($_POST['password']) || isset($_POST['connection_type']); if ($error_v) { // if credentials are given and we don't have access to // wp filesystem show notice to user // we could use request_filesystem_credentials with true error // parameter but in this case second ftp credentials screen // would appear $notification = $this->_registry->get('notification.admin'); $err_msg = Ai1ec_I18n::__('<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.'); $notification->store($err_msg, 'error', 1); // we need to avoid infinity loop if FS_METHOD direct // and robots.txt is not writable if (!isset($_REQUEST['noredirect'])) { Ai1ec_Http_Response_Helper::redirect($redirect_url); } } return; } global $wp_filesystem; // sometimes $wp_filesystem could be null if (null === $wp_filesystem) { return; } $redirect = false; if ($wp_filesystem->exists($robots_file) && $wp_filesystem->is_readable($robots_file) && $wp_filesystem->is_writable($robots_file)) { // Get current robots txt content $current_rules = $wp_filesystem->get_contents($robots_file); // Update robots.txt $custom_rules = $this->rules($current_rules, false); } $robots_txt['is_installed'] = $wp_filesystem->put_contents($robots_file, $custom_rules, FS_CHMOD_FILE); if (false === $robots_txt['is_installed']) { $err_msg = Ai1ec_I18n::__('<strong>ERROR:</strong> There was an error storing <strong>robots.txt</strong> to the server, the file could not be written.'); $this->_registry->get('notification.admin')->store($err_msg, 'error'); $redirect = true; } // Set Page ID $robots_txt['page_id'] = $settings->get('calendar_page_id'); // Update Robots Txt $option->set('ai1ec_robots_txt', $robots_txt); // Update settings textarea $settings->set('edit_robots_txt', $custom_rules); // we need to avoid infinity loop if FS_METHOD direct // and robots.txt is not writable if ($redirect && !isset($_REQUEST['noredirect'])) { Ai1ec_Http_Response_Helper::redirect($redirect_url); } }
/** * Redirect the user either to the front page or the dashbord page * * @return void Method does not return */ protected function redirect($suggested_url = null) { $url = ai1ec_get_site_url(); if (is_admin()) { $url = null !== $suggested_url ? $suggested_url : ai1ec_get_admin_url(); } Ai1ec_Http_Response_Helper::redirect($url); }
/** * Get the parameters for the view from the request object * * @param Ai1ec_Abstract_Query $request * * @return array */ protected function get_view_args_for_view(Ai1ec_Abstract_Query $request) { $settings = $this->_registry->get('model.settings'); // Define arguments for specific calendar sub-view (month, agenda, etc.) // Preprocess action. // Allow action w/ or w/o ai1ec_ prefix. Remove ai1ec_ if provided. $action = $request->get('action'); if (0 === strncmp($action, 'ai1ec_', 6)) { $action = substr($action, 6); } $view_args = $request->get_dict(apply_filters('ai1ec_view_args_for_view', array('post_ids', 'auth_ids', 'cat_ids', 'tag_ids', 'events_limit'))); $add_defaults = array('cat_ids' => 'categories', 'tag_ids' => 'tags'); foreach ($add_defaults as $query => $default) { if (empty($view_args[$query])) { $setting = $settings->get('default_tags_categories'); if (isset($setting[$default])) { $view_args[$query] = $setting[$default]; } } } $type = $request->get('request_type'); $view_args['data_type'] = $this->return_data_type_for_request_type($type); $view_args['request_format'] = $request->get('request_format'); $exact_date = $this->get_exact_date($request); $view_args['no_navigation'] = $request->get('no_navigation') === 'true'; // Find out which view of the calendar page was requested, and render it // accordingly. $view_args['action'] = $action; $view_args['request'] = $request; $view_args = apply_filters('ai1ec_view_args_array', $view_args); if (null === $exact_date) { $href = $this->_registry->get('html.element.href', $view_args)->generate_href(); return Ai1ec_Http_Response_Helper::redirect($href, 307); } return $view_args; }
/** * Get the url to retrieve the css * * @return string */ public function get_css_url() { // get what's saved. I t could be false, a int or a string. // if it's false or a int, use PHP to render CSS $saved_par = $this->db_adapter->get(self::QUERY_STRING_PARAM); // if it's empty it's a new install probably. Return static css. // if it's numeric, just consider it a new install if (empty($saved_par)) { $theme = $this->_registry->get('model.option')->get('ai1ec_current_theme'); return Ai1ec_Http_Response_Helper::remove_protocols(apply_filters('ai1ec_frontend_standard_css_url', $theme['theme_url'] . '/css/ai1ec_parsed_css.css')); } if (is_numeric($saved_par)) { if ($this->_registry->get('model.settings')->get('render_css_as_link')) { $time = (int) $saved_par; $template_helper = $this->_registry->get('template.link.helper'); return Ai1ec_Http_Response_Helper::remove_protocols(add_query_arg(array(self::QUERY_STRING_PARAM => $time), trailingslashit(ai1ec_get_site_url()))); } else { add_action('wp_head', array($this, 'echo_css')); return ''; } } // otherwise return the string return Ai1ec_Http_Response_Helper::remove_protocols($saved_par); }
/** * Redirect the user either to the front page or the dashbord page * * @return void Method does not return */ protected function redirect() { if (is_admin()) { Ai1ec_Http_Response_Helper::redirect(get_admin_url()); } else { Ai1ec_Http_Response_Helper::redirect(get_site_url()); } }