<?php

/**
 * 后台专题管理模块 Model
 * ============================================================================
 * zhuna_php 住哪网酒店分销联盟程序php版　BY Tmac PHP MVC framework
 * $Author: zhangwentao $  <zwttmac@qq.com>
 * $Id: special.class.php 8 2011-11-09 12:56:45Z zhangwentao $
 * http://un.zhuna.cn；
 */
class special extends Model
{

    /**
     * 初始化变量　定义私有变量
     */
    public function _init()
    {
        define('SPECIAL_ROOT', WEB_ROOT . 'special/');        
    }

    /**
     * 获取遍历所有专题
     * @param $show_del 是否显示关闭的
     * return article_class,pages
     */
    public function getSpecialList($show_del = 1)
    {
        $filelists = Array();
        $special_dir = SPECIAL_ROOT;
        $dh = dir($special_dir);

        while (($filename = $dh->read()) !== false) {
            if ((is_dir("$special_dir/$filename")) AND ($filename != ".") AND ($filename != "..") AND ($filename != ".svn"))
                $filelists[] = $filename;
        }        
        $dh->close();
        $rs = array();
        $doc = new DOMDocument();
        foreach ($filelists AS $k => $v) {
            $xml = $special_dir . $v . '/set.xml';
            if (!is_file($xml)) {
                continue;
            }
            $doc->load($xml);
            $root = $doc->getElementsByTagName("root");
            foreach ($root as $basexml) {
                $states = $basexml->getElementsByTagName("state");
                $state = $states->item(0)->nodeValue;
                if ($show_del == 0) {
                    if ($state == 0)
                        continue;
                }
                $rs[$k]['state'] = $state;

                $names = $basexml->getElementsByTagName("name");
                $name = $names->item(0)->nodeValue;
                $rs[$k]['name'] = $name;

                $imgs = $basexml->getElementsByTagName("img");
                $img = $imgs->item(0)->nodeValue;
                $rs[$k]['img'] = $img;

                $links = $basexml->getElementsByTagName("link");
                $link = $links->item(0)->nodeValue;
                $rs[$k]['link'] = $link;

                $orders = $basexml->getElementsByTagName("order");
                $order = $orders->item(0)->nodeValue;
                $rs[$k]['order'] = $order;

                $rs[$k]['filename'] = $v;
            }
        }        
        return $rs;
    }

}