Ejemplo n.º 1
0
/**
 * get_posts 
 *
 * @desc get_posts is used to get content by parameters
 * @access      public
 * @category    posts
 * @author      Microweber 
 * @link        http://microweber.info/documentation/get_posts
 * @param 
   $params = array(); 
   //params for the output
   $params['display'] = 'post_item.php';
   
   //params for the posts
     
  	$params['selected_categories'] = array(1,2); //if false will get the articles from the curent category. use 'all' to get all articles from evrywhere
  	$params['items_per_page'] = 5; //limits the results by paging
	$params['curent_page'] = 1; //curent result page
	$params['without_custom_fields'] = true; //if true it will get only basic posts info. Use this parameter for large queries
    
    
 * 
 * 
*/
function get_posts($params = array())
{
    global $CI;
    if ($params['display']) {
        $list_file = $params['display'];
        unset($params['display']);
    }
    if ($params['file']) {
        $file = $params['file'];
        unset($params['file']);
    }
    if ($params['data']) {
        $data = $params['data'];
        unset($params['data']);
    }
    if (!$params['items_per_page']) {
        $params['items_per_page'] = 30;
    }
    app_var('items_per_page', $params['items_per_page']);
    //var_Dump($params ['selected_categories']);
    if ($params['category']) {
        $params['selected_categories'][] = $params['category'];
    }
    if ($data == false) {
        if (is_array($params['selected_categories'])) {
        } else {
            if ($params['selected_categories'] == 'all') {
                unset($params['selected_categories']);
            } else {
                $params['selected_categories'] = $CI->template['active_categories'];
                if ($params['selected_categories'] == false) {
                    $try_post = $CI->template['post'];
                    if (!empty($try_post)) {
                        $try = CI::model('taxonomy')->getCategoriesForContent($try_post['id'], $return_only_ids = true);
                        if (!empty($try)) {
                        }
                        $params['selected_categories'] = $try;
                    }
                }
            }
        }
    }
    if ($params['without_custom_fields']) {
        $without_custom_fields = $params['without_custom_fields'];
        unset($params['without_custom_fields']);
    }
    if ($data == false) {
        if (!empty($params)) {
            $posts = CI::model('content')->contentGetByParams($params);
            return $posts;
            //p($posts);
            if (!empty($posts)) {
                if ($posts["posts_pages_count"]) {
                    app_var('posts_pages_count', $posts["posts_pages_count"]);
                }
            }
            if (!empty($posts)) {
                if ($posts["posts_pages_curent_page"]) {
                    app_var('posts_pages_curent_page', $posts["posts_pages_curent_page"]);
                }
            }
            if (!empty($posts)) {
                if ($posts["posts_pages_links"]) {
                    app_var('posts_pages_links', $posts["posts_pages_links"]);
                }
            }
            if (!empty($posts)) {
                $posts = $posts['posts'];
            }
        } else {
            $posts = $CI->template['posts'];
        }
    } else {
        $posts = $data;
        //p($data);
    }
    if (!empty($posts)) {
        $posts_cf = array();
        foreach ($posts as $post) {
            //$more = false;
            //$more = CI::model ( 'core' )->getCustomFields ( 'table_content', $post ['id'] );
            //$post ['custom_fields'] = $more;
            $posts_cf[] = $post;
        }
        $posts = $posts_cf;
    }
    if ($file != false) {
        $try_file1 = TEMPLATE_DIR . 'modules/posts/views/' . $file . '.php';
        if (is_file($try_file1)) {
            $CI->template['posts'] = $posts;
            $CI->load->vars($CI->template);
            $content_filename = $CI->load->file($try_file1, true);
            print $content_filename;
        } else {
            $try_file1 = TEMPLATE_DIR . '' . $file . '.php';
            if (is_file($try_file1)) {
                $CI->template['posts'] = $posts;
                $CI->load->vars($CI->template);
                $content_filename = $CI->load->file($try_file1, true);
                print $content_filename;
            }
        }
    } elseif ($list_file != false) {
        if (!empty($posts)) {
            $list_file = trim($list_file);
            if (stristr($list_file, '.php') == false) {
                $try_file_template_dir = TEMPLATE_DIR . $list_file . '.php';
            } else {
                $try_file_template_dir = TEMPLATE_DIR . $list_file . '';
            }
            if (is_file($try_file_template_dir) == false) {
                $try_file1 = TEMPLATE_DIR . 'modules/posts/views/' . $list_file . '.php';
                $try_file = TEMPLATE_DIR . 'modules/posts/views/' . '_default' . '.php';
                if ($list_file == 'default') {
                    $try_file1 = $try_file;
                }
                if (is_file($try_file1) == false) {
                    $dir = dirname($try_file1);
                    if (is_dir($dir) == false) {
                        @mkdir_recursive($dir);
                    }
                    if ($list_file != 'default') {
                        if (!copy($try_file, $try_file1)) {
                            //echo "failed to copy $file...\n";
                        }
                    }
                }
            } else {
                $try_file1 = $try_file_template_dir;
            }
            if (is_file($try_file1)) {
                foreach ($posts as $the_post) {
                    if ($without_custom_fields == false) {
                        $more = false;
                        $more = CI::model('core')->getCustomFields('table_content', $the_post['id']);
                        $the_post['custom_fields'] = $more;
                    }
                    $CI->template['the_post'] = $the_post;
                    $CI->load->vars($CI->template);
                    $content_filename = $CI->load->file($try_file1, true);
                    print $content_filename;
                }
            } else {
                return $posts;
            }
        }
    } else {
        return $posts;
    }
    return $posts;
}
Ejemplo n.º 2
0
 <? if(empty($posts_pages_links)) : ?>
 <? $posts_pages_links = app_var('posts_pages_links'); ?>
 <?php endif ; ?>
 
 
<?php if(!empty($posts_pages_links)): ?>
 

<div class="paging">
  <?php $i = 1; foreach($posts_pages_links as $page_link) : ?>
  <span <?php if($posts_pages_curent_page == $i) : ?>  class="active"  <?php endif; ?>><a  href="<?php print $page_link ;  ?>"><?php print $i ;  ?></a></span>
  <?php $i++; endforeach;  ?>
</div>
<?php endif ; ?>