przewiń do treści

PHP, MySQL i MVC. Tworzenie witryn WWW opartych na bazie danych

Włodzimierz Gajda

class HTMLArticle
{
    private $art;
    public  $pages;
    public  $html;
    public  $singlepagearticle;
    public  $pagedarticle;

    public function __construct($filename)
    {
        $this->art = new XMLArticle($filename);

        $this->setUrl();

        $this->html = array(
            'figures' => array(),
            'listings' => array(),
            'tables' => array(),
            'frames' => array(),
        );

        $this->processFLFTHTML();
        $this->processEDANumbering();
        $this->processHTML();
        $this->processSinglepage();
        $this->processPages();
    }


    public function processFLFTHTML()
    {
        for ($i = 1; $i <= $this->art->getFiguresCount(); $i++) {
            $this->html['figures'][$i] = $this->getHTMLFigure($i);
        }

        for ($i = 1; $i <= $this->art->getListingsCount(); $i++) {
            $this->html['listings'][$i] = $this->getHTMLListing($i);
        }

        for ($i = 1; $i <= $this->art->getFramesCount(); $i++) {
            $this->html['frames'][$i] = $this->getHTMLFrame($i);
        }

        for ($i = 1; $i <= $this->art->getTablesCount(); $i++) {
            $this->html['tables'][$i] = $this->getHTMLTable($i);
        }
    }


    public function processHTML()
    {
        $tmps = new SmartyString();
        $tmp = $this->art->getArticle();

        $tmps->addTemplate('content.tpl', $tmp);
        $tmps->assign('figures', $this->html['figures']);
        $tmps->assign('listings', $this->html['listings']);
        $tmps->assign('frames', $this->html['frames']);
        $tmps->assign('tables', $this->html['tables']);
        $tmps->left_delimiter = '#####{';
        $tmps->right_delimiter = '}#####';

        $this->html['article'] = $tmps->fetch('str:content.tpl');
    }

    public function processSinglepage()
    {
        $this->singlepagearticle = array();

        $toc_array = getTableOfContents($this->html['article']);
        $this->singlepagearticle['toc'] = getTableOfContentsAsString($toc_array);
        $this->singlepagearticle['text'] = replaceChapters($toc_array, $this->html['article']);

        $this->singlepagearticle['title']        = $this->art->getTitle();
        $this->singlepagearticle['introduction'] = $this->art->getIntroduction();
        $this->singlepagearticle['date']         = $this->art->getDate();
        $this->singlepagearticle['examples']     = $this->html['examples'];
        $this->singlepagearticle['addresses']    = $this->html['addresses'];
        $this->singlepagearticle['download']     = $this->html['download'];
    }

    public function getHTMLFigure($ANo)
    {
        $z = new Smarty();
        $z->assign('figure', $this->art->getFigure($ANo));
        return $z->fetch('figure.tpl');
    }

    public function getHTMLListing($ANo)
    {
        $z = new Smarty();
        $z->assign('listing', $this->art->getListing($ANo));
        return $z->fetch('listing.tpl');
    }

    public function processPages()
    {
        $this->paged = array();
        $this->pages = array();

        $this->paged['title']        = $this->art->getTitle();
        $this->paged['introduction'] = $this->art->getIntroduction();
        $this->paged['date']         = $this->art->getDate();
        $this->paged['examples']     = $this->html['examples'];
        $this->paged['addresses']    = $this->html['addresses'];
        $this->paged['download']     = $this->html['download'];

        $tablicaTOC  = getTableOfContents($this->html['article']);

        $this->paged['toc'] = getTableOfContentsAsStringPages($tablicaTOC, $this->url);

        $newContents = replaceChaptersPages($tablicaTOC, $this->html['article']);

        $podziel = preg_split(
            "/<h3>(.*)<\/h3>/Uis",
            $newContents
        );

        $this->pages_count = count($tablicaTOC);
        for ($i = 1; $i <= $this->pages_count; $i++) {

            $r_tekst = trim($podziel[$i]);
            $r_tytul = $tablicaTOC[$i]['title'];
            $r_numer = $i;
            $r_tekst = "<h3>{$r_numer}. {$r_tytul}</h3>" . $r_tekst;

            $this->pages[$i] = trim($r_tekst);
        }
    }

    public function setUrl()
    {
    }

}

Listing 31.8. Zarys klasy HTMLArticle

Rozdział 31. Skompresowane dokumenty XML zawierające dane binarne

listing-31-08.txt

Reklama

Szkolenia z Symfony 2.0