<?php
global $post;
$post_id = $post->ID;
$links = (!empty($args['links'])) ? $args['links'] : array();
if (!empty($links)) :
    $new_playbox = array();
    if (!empty($links) && is_array($links)) {
        $s_id = 1;
        foreach ($links as $key => $season) {
            $e_id = 1;
            $items = (!empty($season['items']) && is_array($season['items'])) ? $season['items'] : array();
            $season_name = (!empty($season['season_name'])) ? $season['season_name'] : $key + 1;
            $quality_name = (!empty($season['quality_link'])) ? $season['quality_link'] : 0;
            $type_name = (!empty($season['type_link'])) ? $season['type_link'] : '';
            foreach ($items as $key => $item) {
                $new_playbox[$season_name][$key][$type_name][$quality_name] = $item;
                $e_id++;
            }
            $s_id++;
        }
    }
    $links = $new_playbox;
    if (!empty($links)) : ?>
        <ul class="inside rt">
            <?php
            $s_i = 1;
            foreach ($links as $season_name => $season) :
                $s_name = (!empty($season_name)) ? $season_name : "نامشخص"; ?>
                <li class="season rt rt-blur rt-8px">
                    <div class="link rt rt-pointer rt-14">
                        <span class="titr rt-color rt-fff rt-30px"><?php echo $s_name; ?></span>
                        <span class="count rt-ddd">تعداد قسمت: <?php echo (!empty($season) && is_array($season)) ? count($season) : 0; ?></span> <i class="fa fa-angle-down left rt-19"></i>
                    </div>
                    <div class="submenu rt-0s rt">
                        <ul class="episodes rt">
                            <?php if (!empty($season) && is_array($season)) :
                                $e_i = 1;
                                foreach ($season as $episode_id => $episode) :
                                    $ep_name = "قسمت " . $e_i; ?>
                                    <li class="item rt rt-bg rt-8px">
                                        <div class="info right rt-13">
                                            <span class="inf right">قسمت : <?php echo $ep_name; ?></span>
                                        </div>
                                        <div class="links left rt-13">
                                            <a href="<?php echo get_online_play_link($post_id, null, $s_i, $e_i); ?>" target="_blank" class="right btn rt-30px rt-fff dl"><i class="fa fa-play rt-15 right"></i> پخش آنلاین</a>
                                        </div>
                                    </li>
                            <?php $e_i++;
                                endforeach;
                            endif; ?>
                        </ul>
                    </div>
                </li>
            <?php $s_i++;
            endforeach; ?>
        </ul>
    <?php endif; ?>
<?php endif; ?>