/** * Get current page "type" in the way WordPress handles it * * Concerned page types are: * * - 'default_home': default wordpress: auto-generated homepage => front-page.php * - 'front_page': user defined front page (homepage post) => front-page.php * - 'home': user defined blog page (post) => home.php * - 'search' * - '401' * - '403' * - '404' * - 'attachment': single attachment * - 'page': single post with type "page" * - 'post_sticky': single post with the featured option enabled * - 'post_XXX': single custom post type post * - 'post': single post * - 'tag': one tag archive * - 'category': one category archive * - 'author': single author / archive of author's posts * - 'post_type_archive_XXX': XXX custom post type archive * - 'post_type_archive': post type archive * - 'taxonomy': one taxonomy archive * - 'date': archive by date * - 'archive': global archive page * - 'index': this is the default type when no other one matches * * @return string */ function get_page_type() { global $page_type; if (!isset($page_type)) { $page_type = 'index'; if (is_front_page() && is_home()) { // default wordpress: auto-generated homepage => front-page.php $page_type = 'default_home'; } elseif (is_front_page()) { // user defined front page (homepage post) => front-page.php $page_type = 'front_page'; } elseif (is_home()) { // user defined blog page (post) => home.php $page_type = 'home'; } elseif (is_search()) { $page_type = 'search'; } elseif (is_401()) { $page_type = '401'; } elseif (is_403()) { $page_type = '403'; } elseif (is_404()) { $page_type = '404'; } elseif (is_single() && is_attachment()) { $page_type = 'attachment'; } elseif (is_page()) { $page_type = 'page'; } elseif (is_single() && is_sticky()) { $page_type = 'post_sticky'; } elseif (is_single()) { $post_type = get_post_type(); if ($post_type) { $page_type = 'post_' . $post_type; } else { $page_type = 'post'; } } elseif (is_archive() && is_tag()) { $page_type = 'tag'; } elseif (is_archive() && is_category()) { $page_type = 'category'; } elseif (is_archive() && is_author()) { $page_type = 'author'; } elseif (is_archive() && is_post_type_archive()) { $post_type = get_post_type(); if ($post_type) { $page_type = 'post_type_archive_' . $post_type; } else { $page_type = 'post_type_archive'; } } elseif (is_archive() && is_tax()) { $page_type = 'taxonomy'; } elseif (is_archive() && (is_date() || is_year() || is_month() || is_day() || is_time())) { $page_type = 'date'; } elseif (is_archive()) { $page_type = 'archive'; } } return $page_type; }
public function render() { /* @var $post \WP_Post */ global $post; $this->entries = array(); $this->addHomePage(); if (!is_front_page() && is_home()) { $show_on_front = get_option('show_on_front'); if ($show_on_front == 'page') { $this->addBlogPage(); } } elseif (is_tag()) { $this->addBlogPage(); $tag_id = get_query_var('tag_id'); $this->addTag($tag_id); } elseif (is_category()) { $this->addBlogPage(); $cat_id = get_cat_id(single_cat_title('', false)); $this->addCategory($cat_id); } elseif (is_author()) { $this->addAuthor(get_the_author_meta('ID')); } elseif (is_search()) { $this->addSearch(get_search_query()); } elseif (is_page()) { $this->addPage($post->ID); } elseif (is_single()) { $this->addBlogPage(); $categories = get_the_category(); if (isset($categories[0])) { $this->addCategory($categories[0]->cat_ID); } $this->addPost($post->ID); } elseif (is_401()) { $this->addErrorPage(401); } elseif (is_403()) { $this->addErrorPage(403); } elseif (is_404()) { $this->addErrorPage(); } elseif (is_tax()) { $this->addBlogPage(); $term = get_query_var('term'); $tax = get_query_var('taxonomy'); if ($tax == 'post_format') { $this->addPostFormat($term); } } elseif (is_archive()) { $this->addBlogPage(); $this->addDate(is_year() || is_month() || is_day() ? get_the_time('Y') : false, is_year() || is_month() ? get_the_time('m') : false, is_day() ? get_the_time('d') : false); } return $this->entries; }
/** * Process the body classes of 401 & 403 error pages * * To use this feature, write: * * add_filter('body_class', 'basicbootstrap_error_class'); * * The `body_class` filter is documented in `wp-includes/post-template.php`. * * @param $classes * @return array * @since WP_Basic_Bootstrap 1.0 */ function basicbootstrap_error_class($classes) { if (is_403()) { $classes[] = "error403"; } elseif (is_401()) { $classes[] = "error401"; } return $classes; }
/** * Execute console command. */ public function handle() { $fix = $this->option('fix'); $old = $this->option('old_files'); if ($old) { return $this->move_files(); } $downloaded_card = Law::where('status', Law::UP_TO_DATE)->count(); $downloaded_text = Law::where('status', Law::DOWNLOADED_REVISIONS)->count(); $downloaded_relations = Law::where('status', Law::DOWNLOADED_RELATIONS)->count(); $without_text = Law::where('status', '>', Law::NOT_DOWNLOADED)->where('has_text', Law::NO_TEXT)->count(); $not_downloaded = Law::where('status', Law::NOT_DOWNLOADED)->count(); $law_dir = $this->getDownloadsDir() . '/zakon.rada.gov.ua/laws/show/'; function is_fake($html, $is_text = true) { return downloader()->detectFakeContent($html); } function is_403($html) { return downloader()->detectFakeContent($html, '403'); } function remove_dir($dir) { exec('rm -rf ' . $dir); } $result_count = Law::where('status', '<', Law::SAVED)->count(); $nd_orphaned_dirs = 0; $d_broken_card = 0; $d_no_files = 0; $d_fake_content = 0; $d_unknown_text_true_content = 0; $d_unknown_text_no_text = 0; $i = 1; Law::where('status', '<', Law::SAVED)->orderBy('id')->chunk(200, function ($laws) use($fix, $law_dir, &$i, &$result_count, &$nd_orphaned_dirs, &$d_broken_card, &$d_no_files, &$d_fake_content, &$d_unknown_text_true_content, &$d_unknown_text_no_text) { foreach ($laws as $law) { $law_path = $law_dir . $law->id; $card_path = $law_dir . $law->id . '/card.html'; $text_path = $law_dir . $law->id . '/text.html'; $page_path = $law_dir . $law->id . '/page.html'; if ($law->status == Law::NOT_DOWNLOADED && is_dir($law_path)) { $nd_orphaned_dirs++; if ($fix) { remove_dir($law_path); } continue; } if ($law->status > Law::NOT_DOWNLOADED && (file_exists($card_path) && is_403(file_get_contents($card_path)) || !file_exists($card_path))) { $d_broken_card++; if ($fix) { remove_dir($law_path); $law->update(['status' => Law::NOT_DOWNLOADED]); } } if ($law->status >= Law::DOWNLOADED_REVISIONS && $law->has_text == Law::HAS_TEXT && !file_exists($text_path) && !file_exists($page_path)) { $d_no_files++; if ($fix) { remove_dir($law_path); $law->update(['status' => Law::NOT_DOWNLOADED]); } } if ($law->status >= Law::DOWNLOADED_REVISIONS && $law->has_text == Law::HAS_TEXT && (file_exists($text_path) || file_exists($page_path))) { if (file_exists($text_path) && is_fake(file_get_contents($text_path), 1) || file_exists($page_path) && is_fake(file_get_contents($page_path), 0)) { $d_fake_content++; if ($fix) { remove_dir($law_path); $law->update(['status' => Law::NOT_DOWNLOADED]); } } } if ($law->status > Law::NOT_DOWNLOADED && $law->has_text == Law::UNKNOWN && (file_exists($text_path) || file_exists($page_path))) { if (file_exists($text_path) && is_fake(file_get_contents($text_path), 1) || file_exists($page_path) && is_fake(file_get_contents($page_path), 0)) { $d_fake_content++; if ($fix) { remove_dir($law_path); $law->update(['status' => Law::NOT_DOWNLOADED]); } } } if ($law->status >= Law::DOWNLOADED_REVISIONS && $law->has_text == Law::UNKNOWN && !(file_exists($text_path) || file_exists($page_path)) && file_exists($card_path)) { $html = file_get_contents($card_path); if (strpos($html, 'Текст відсутній') !== false) { $d_unknown_text_no_text++; if ($fix) { $law->update(['status' => Law::UP_TO_DATE, 'has_text' => Law::NO_TEXT]); } } else { $d_no_files++; if ($fix) { $law->update(['status' => Law::NOT_DOWNLOADED]); } } } if ($law->status > Law::NOT_DOWNLOADED && $law->has_text == Law::UNKNOWN && !(file_exists($text_path) || file_exists($page_path)) && !file_exists($card_path)) { if ($fix) { $law->update(['status' => Law::NOT_DOWNLOADED]); } } print "\rChecked " . $i . ' of ' . $result_count . ' (' . floor($i / $result_count * 100) . '%)'; $i++; } }); print "\n" . 'Downloaded card : ' . $downloaded_card; print "\n" . 'Downloaded text : ' . $downloaded_text . ' (without text: ' . $without_text . ')'; print "\n" . 'Downloaded relations : ' . $downloaded_relations; print "\n" . 'Not downloaded : ' . $not_downloaded; print "\n" . '-------------------------------------------------'; print "\n" . 'Junk directories : ' . $nd_orphaned_dirs; print "\n" . 'Broken card page : ' . $d_broken_card; print "\n" . 'Missing files for downloads: ' . $d_no_files; print "\n" . 'Fake content for downloads : ' . $d_fake_content; print "\n" . 'Has text, but not marked : ' . $d_unknown_text_true_content; print "\n" . 'No text, but not marked : ' . $d_unknown_text_no_text; if ($fix) { print "\n" . 'ALL PROBLEMS FIXED'; } print "\n"; return true; }