function showAllLabels() { // Create DOM from URL $html = file_get_html('all.php'); $allPosts = $html->find('.post'); $labelsList = array(); // Go through all posts foreach ($allPosts as $article) { // These 2 variables are used on both cases $labels = trim($article->find('.labels', 0)->plaintext); // transform in lowercase $labels = strtolower($labels); // split labels (in case there're more than one they're comma separated) $labels = explode(",", $labels); // Iterate over the labels foreach ($labels as $label) { $label = trim($label); // Check if the label exists and then add one to that value if (findLabel($label, $labelsList)) { $labelsList[$label] = $labelsList[$label] + 1; // Otherwise add it to the array } else { $labelsList[$label] = 1; } } } $keys = array_keys($labelsList); sort($keys); $labelsToShow; $endString = " - "; $endStringLen = strlen($endString); foreach ($keys as $key) { $labelsToShow .= "<a href='./showLabel.php?label=" . $key . "' target='_blank'>"; $labelsToShow .= $key; // This is to show the number of posts with each label $labelsToShow .= " (" . $labelsList[$key] . ")"; $labelsToShow .= "</a>"; $labelsToShow .= $endString; } $labelsToShow = substr($labelsToShow, 0, $endStringLen * -1); return $labelsToShow; }
$html = file_get_html('all.php'); $allPosts = $html->find('.post'); $fullLength = sizeof($allPosts); $remainingPosts = $fullLength; $requestedLabel = $_GET["label"]; $oldPosts = "<div class='post old'><p> Estos son los posts con la etiqueta \"<span class='labelName'>" . $requestedLabel . "</span>\"</p>"; // Find all posts foreach ($allPosts as $article) { // Get labels $labels = trim($article->find('.labels', 0)->plaintext); // transform in lowercase $labels = strtolower($labels); // split labels (in case there're more than one they're comma separated) $labels = explode(",", $labels); // FIRST OF ALL CHECK IF THE LABEL MATCHES if (findLabel($requestedLabel, $labels)) { // These 2 variables are used on both cases $title = trim($article->find('.title', 0)->plaintext); $shareTitle = "[Japón] " . $title; $postUrl = "http://www.nestoralvaro.com/japon/showPost.php?postId=" . $remainingPosts; $time_day = $article->find('.time-day', 0)->plaintext; $time_month = $article->find('.time-month', 0)->plaintext; $time_year = $article->find('.time-year', 0)->plaintext; $oldPosts .= "<div class='oldPost'>"; $oldPosts .= "<a href='" . $postUrl . "' target='_blank' >"; $oldPosts .= "[" . $time_year . "-" . $time_month . "-" . $time_day . "]"; $oldPosts .= "<span class='oldTitle'>" . $title . "</span>"; $oldPosts .= "</a>"; // invoke "share" function to show all places to share $oldPosts .= share($shareTitle, $postUrl); $oldPosts .= "</div>";