コード例 #1
0
ファイル: model.php プロジェクト: coolswitcher/rm_anonses
 public function getPrograms()
 {
     if (!$this->init) {
         return FALSE;
     }
     $categories = (array) Arr::get($this->options->category_options, 'categories');
     if (empty($categories)) {
         return FALSE;
     }
     $posts = get_posts(array('category__in' => $categories, 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'desc'));
     $programs_array = array();
     foreach ($posts as &$post) {
         if (empty($post->post_title)) {
             continue;
         }
         $program_title = $post->post_title;
         $program_title = trim($program_title);
         $program_title = strip_tags($program_title);
         $program_title = htmlspecialchars($program_title, ENT_QUOTES);
         $program_title = preg_replace('#\\&\\w{3,7};#iu', '', $program_title);
         $program_title = Model::cleanName($program_title);
         $programs_array[] = $program_title;
     }
     return $programs_array;
 }
コード例 #2
0
ファイル: widget.php プロジェクト: coolswitcher/rm_anonses
    public function widget($args, $instance)
    {
        if (!$instance) {
            return;
        }
        global $rm_anonses_options, $post;
        $template = array('before_title' => '<div class="head"><h3>', 'after_title' => '</h3></div>', 'before_widget' => '<div class="rm_anonses_block">', 'after_widget' => '</div>');
        $template = wp_parse_args($args, $template);
        $title = Arr::get($instance, 'title', 'Анонсы');
        $text = Arr::get($instance, 'text', 0);
        $model = new Model(isset($_GET['anonses_debug']));
        $programs = $model->getTVprograms();
        if (!$programs) {
            return;
        }
        $programs = array_slice($programs, 0, Arr::get($rm_anonses_options->time_options, 'max_show_count', 6), TRUE);
        $posts_ids = array_keys($programs);
        $_posts = get_posts(array('post__in' => $posts_ids, 'posts_per_page' => -1));
        $posts = array();
        foreach ($_posts as $post) {
            setup_postdata($post);
            $program_name = Arr::path($programs, get_the_ID() . '.name');
            $posts[] = array('id' => get_the_ID(), 'title' => (Arr::get($rm_anonses_options->category_options, 'tv_title') and $program_name) ? $program_name : get_the_title(), 'time' => Arr::path($programs, get_the_ID() . '.time_readable'), 'ts' => Arr::path($programs, get_the_ID() . '.time'), 'url' => get_permalink(get_the_ID()), 'text' => strip_tags(get_the_excerpt()));
        }
        wp_reset_postdata();
        usort($posts, function ($a, $b) {
            return $a['ts'] > $b['ts'];
        });
        $top_posts = array_splice($posts, 0, 2);
        $i = 0;
        echo $template['before_widget'];
        echo $template['before_title'] . $title . $template['after_title'];
        ?>
        <div class="anonses-holder">
        <div class="anonces-top">
        <?php 
        foreach ($top_posts as $pid => $p) {
            $i++;
            ?>
        <div class="aplayer-<?php 
            echo $i;
            ?>
">
            <div class="player">
                <a href="<?php 
            echo $p['url'];
            ?>
">
                <?php 
            if (function_exists('render_overlay_image')) {
                render_overlay_image(array(Arr::get($rm_anonses_options->image_options, 'width_big', 290), Arr::get($rm_anonses_options->image_options, 'height_big', 217)), 'overlay-image-anonse-big', NULL, $p['id']);
            } else {
                echo get_the_post_thumbnail($p['id'], array(Arr::get($rm_anonses_options->image_options, 'width_big', 290), Arr::get($rm_anonses_options->image_options, 'height_big', 217)));
            }
            ?>
                </a>
            </div>
            <div class="text">
                <h4>
                <a href="<?php 
            echo $p['url'];
            ?>
">
                  <?php 
            echo $p['title'];
            ?>
                </a>
                </h4>
                <div class="anonse-period<?php 
            echo !$text ? 'anonse-period-compact' : '';
            ?>
">
                    <?php 
            echo '<span>' . $p['time'] . '</span>';
            ?>
                </div>
                <?php 
            if ($text) {
                ?>
                <p><?php 
                echo $p['text'];
                ?>
</p>            
                <?php 
            }
            ?>
            </div>      
      </div>          
    <?php 
        }
        ?>
    </div>    
    <div class="anonses-sidebottom">
      <ul>
        <?php 
        foreach ($posts as $p) {
            setup_postdata($post);
            ?>
      
        <li>              
          <a href="<?php 
            echo $p['url'];
            ?>
">
            <?php 
            if (function_exists('render_overlay_image')) {
                render_overlay_image(array(Arr::get($rm_anonses_options->image_options, 'width', 128), Arr::get($rm_anonses_options->image_options, 'height', 96)), 'overlay-image-anonse-small', NULL, $p['id']);
            } else {
                echo get_the_post_thumbnail($p['id'], array(Arr::get($rm_anonses_options->image_options, 'width', 128), Arr::get($rm_anonses_options->image_options, 'height', 96)));
            }
            ?>
            <?php 
            echo $p['title'];
            ?>
          </a>
            <div class="anonse-period-small">
                <?php 
            echo '<span>' . $p['time'] . '</span>';
            ?>
            </div>          
        </li>        
      <?php 
        }
        ?>
      </ul>
    </div>
  </div>
    <?php 
        echo $template['after_widget'];
        ?>
    <?php 
    }