public function __construct($post)
 {
     // Set Category ID Values, but First Time Only
     if (Export_ID_XML_Generator::$OPINION_CATEGORY_ID == -1) {
         Export_ID_XML_Generator::$OPINION_CATEGORY_ID = get_cat_ID("Opinion");
         Export_ID_XML_Generator::$COLUMNS_CATEGORY_ID = get_cat_ID("Columns");
     }
     $this->post = $post;
     $this->context = array();
     $this->template = $this->get_template_context();
     $this->meta = get_post_meta($post->ID, Export_ID_XML_Admin_PostMeta::$META_KEY_NAME, true);
     $this->context['url'] = $this->get_permalink();
     $this->context['headline'] = $this->get_title();
     $this->context['author'] = $this->get_author();
     $this->context['rank'] = $this->get_rank();
     $this->context['body'] = $this->get_body();
     $this->context['jumpword'] = $this->get_jumpword();
     $this->context['conthead'] = $this->get_conthead();
     $this->context['hammer'] = $this->get_hammer();
     $this->context['kicker'] = $this->get_kicker();
     $this->context['bio'] = $this->get_bio();
     $this->context['photos'] = $this->get_photos();
     // Optional for Off-the-Hill Context
     $this->context['oth'] = $this->get_oth();
 }
 private function handle_request()
 {
     global $wp;
     $xml_mode = $wp->query_vars['__xml'];
     // Mode 1 = Article Only
     if ($xml_mode == 1) {
         $xml_article = $wp->query_vars['xml_article'];
         // Check Required Params
         if (!$xml_article) {
             $this->send_error("Article ID not provided.");
         }
         // Generate and Output the XML
         $xml = Export_ID_XML_Generator::generate_article($xml_article);
         // In Case of Download, Name After Article ID
         $filename = $xml_article . '.xml';
         // Mode 3 = Date Only
     } else {
         if ($xml_mode == 3) {
             $xml_date = $wp->query_vars['xml_date'];
             // Check Required Params
             if (!$xml_date) {
                 $this->send_error("Date for articles not provided.");
             }
             // Generate and Output the XML
             $xml = Export_ID_XML_Generator::generate_date($xml_date);
             // In Case of Download, Name After Article ID
             $filename = $xml_date . '.xml';
             // Mode 2 = Category and Date
         } else {
             $xml_category = $wp->query_vars['xml_category'];
             $xml_date = $wp->query_vars['xml_date'];
             // Check Required Params
             if (!$xml_category) {
                 $this->send_error("Category for articles not provided.");
             }
             if (!$xml_date) {
                 $this->send_error("Date for articles not provided.");
             }
             // Make Sure Params are Valid
             $cat = get_category_by_slug($xml_category);
             if (!$cat) {
                 $this->send_error("Category not found.");
             }
             $catID = $cat->cat_ID;
             // Check for Proper Date Format: YYYY-MM-DD
             if (!preg_match("/[0-9]{4}-[0-9]{2}-[0-9]{2}/", $xml_date)) {
                 $this->send_error("Invalid date format.");
             }
             // Generate and Output the XML
             $xml = Export_ID_XML_Generator::generate_category($catID, $xml_date);
             // In Case of Download, Name After Section Name
             $filename = $xml_category . '.xml';
         }
     }
     ob_end_clean();
     if (isset($wp->query_vars['xml_option']) && $wp->query_vars['xml_option'] == "download") {
         header('Content-type: binary/text; charset=utf-8');
         header('Content-Disposition: filename=' . $filename);
     } else {
         header('Access-Control-Allow-Origin: *');
         // for remote access
         header("Content-type: text/xml");
     }
     $response = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
     $response .= $xml;
     echo $response;
 }