Exemple #1
0
    function parseArticle_03($article)
    {
        global $wgTitle, $wgUser, $wgRequest, $wgServer, $wgLang, $wgArticle, $wgParser, $wgOut, $IP;
        $article = self::mungeSteps($article);
        $sk = $wgUser->getSkin();
        $url = urlencode($wgServer . "/" . $wgTitle->getPrefixedURL());
        $img = urlencode(WikihowShare::getPinterestImage($wgTitle));
        $desc = urlencode(wfMsg('howto', $wgTitle->getText()) . WikihowShare::getPinterestTitleInfo());
        $fb = '<div class="like_button"><fb:like href="' . $url . '" send="false" layout="button_count" width="100" show_faces="false"></fb:like></div>';
        $gp1 = '<div class="gplus1_button"><g:plusone size="medium" callback="plusone_vote"></g:plusone></div>';
        $pinterest = '<div id="pinterest"><a href="http://pinterest.com/pin/create/button/?url=' . $url . '&media=' . $img . '&description=' . $desc . '" class="pin-it-button" count-layout="horizontal">Pin It</a></div>';
        // German includes "how to " in the title text
        $howto = wfMsg('howto', htmlspecialchars($wgTitle->getText()));
        $tb = '<div class="admin_state"><a href="http://twitter.com/share" data-lang="' . $wgLanguageCode . '" style="display:none; background-image: none; color: #ffffff;" class="twitter-share-button" data-count="horizontal" data-via="wikiHow" data-text="' . $howto . '" data-related="JackHerrick:Founder of wikiHow">Tweet</a></div>';
        $article = str_replace('<div class="corner top_right"></div>', '<div class="corner top_right">&nbsp;</div>', $article);
        $article = str_replace('<div class="corner top_left"></div>', '<div class="corner top_left">&nbsp;</div>', $article);
        $article = str_replace('<div class="corner bottom_right"></div>', '<div class="corner bottom_right">&nbsp;</div>', $article);
        $article = str_replace('<div class="corner bottom_left"></div>', '<div class="corner bottom_left">&nbsp;</div>', $article);
        $article = str_replace("<div class='corner top_right'></div>", "<div class='corner top_right'>&nbsp;</div>", $article);
        $article = str_replace("<div class='corner top_left'></div>", "<div class='corner top_left'>&nbsp;</div>", $article);
        $article = str_replace("<div class='corner bottom_right'></div>", "<div class='corner bottom_right'>&nbsp;</div>", $article);
        $article = str_replace("<div class='corner bottom_left'></div>", "<div class='corner bottom_left'>&nbsp;</div>", $article);
        $article = str_replace('<div style="clear:both"></div>', '<div style="clear:both">&nbsp;</div>', $article);
        $article = str_replace("’", "'", $article);
        $introImage = "";
        require_once "{$IP}/extensions/wikihow/mobile/JSLikeHTMLElement.php";
        $doc = new DOMDocument('1.0', 'utf-8');
        $doc->registerNodeClass('DOMElement', 'JSLikeHTMLElement');
        $doc->strictErrorChecking = false;
        $doc->recover = true;
        @$doc->loadHTML($article);
        $doc->normalizeDocument();
        $xpath = new DOMXPath($doc);
        //removing the featured article star
        $nodes = $xpath->query('//div[@id="featurestar"]');
        foreach ($nodes as $node) {
            $node->parentNode->removeChild($node->nextSibling->nextSibling);
            $node->parentNode->removeChild($node);
            break;
        }
        $nodes = $xpath->query('//div[@class="rounders"]');
        foreach ($nodes as $node) {
            $style = $node->getAttribute("style");
            $start = strpos($style, "width:");
            $end = strpos($style, "px", $start);
            $width = intval(substr($style, $start + 6, $start + 6 - $end));
            $newWidth = $width + 21;
            $style = substr($style, 0, $start + 6) . $newWidth . substr($style, $end);
            $start = strpos($style, "height:");
            $end = strpos($style, "px", $start);
            $height = intval(substr($style, $start + 7, $start + 7 - $end));
            $newheight = $height + 19;
            $style = substr($style, 0, $start + 7) . $newHeight . substr($style, $end);
            $node->setAttribute("style", $style);
            $childNode = $node->firstChild;
            $node->removeChild($childNode);
            $newNode = $doc->createElement("div");
            $newNode->setAttribute('class', 'top');
            $node->appendChild($newNode);
            $newNode2 = $doc->createElement("div");
            $newNode2->setAttribute('class', 'bottom');
            $newNode->appendChild($newNode2);
            $newNode3 = $doc->createElement("div");
            $newNode3->setAttribute('class', 'left');
            $newNode2->appendChild($newNode3);
            $newNode4 = $doc->createElement("div");
            $newNode4->setAttribute('class', 'right');
            $newNode3->appendChild($newNode4);
            $newNode4->appendChild($childNode);
        }
        //grabbing the intro image
        /*$nodes = $xpath->query('//div[@class="mwimg"]');
        		foreach ($nodes as $node) {
        			$introImage = "<div class='mwimg'>" . $node->innerHTML . "</div>";
        			$node->parentNode->removeChild($node);
        			break;
        		}*/
        $nodes = $xpath->query('//ol[@class="steps_list_2"]/li/div[@class="mwimg"]');
        foreach ($nodes as $node) {
            $checkNode = $xpath->evaluate($node->parentNode->getNodePath() . '/div[@class="check"]')->item(0);
            $node->parentNode->removeChild($node);
            $checkNode->parentNode->insertBefore($node, $checkNode->nextSibling);
        }
        $article = $doc->saveHTML();
        $article = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>', "", $article);
        $article = str_replace('</body></html>', "", $article);
        //$share =  $fb . $gp1 . $pinterest;
        $mainVars = array('wgTitle' => $wgTitle, 'wgUser' => $wgUser, 'article' => $article, 'sk' => $sk, 'wgRequest' => $wgRequest, 'share' => $share, 'wgLang' => $wgLang, 'wgArticle' => $wgArticle, 'introImage' => $introImage, 'navigation' => self::getNavigation());
        return EasyTemplate::html('main_' . self::ARTICLE_LAYOUT . '.tmpl.php', $mainVars);
    }