Return only images in News list...

Discussion in 'Coding Help' started by Mole, Dec 15, 2010.

  1. Mole

    Mole New Member

    I am using Concrete5 on a site I'm working on. Below is the News List display view.php file needed in the block to display the content from news pages. The code allows images entered in the WSYIWYG to appear in the RSS list. I want to know how I can edit the code below, so it shows only the these images from the $content not the text. Can anybody help me on this? Thanks

    Code:
    <?php     
    defined('C5_EXECUTE') or die("Access Denied.");
        $html = Loader::helper('html');
        $uh = Loader::helper('concrete/urls');
        $bt = BlockType::getByHandle('news_list');
        global $c;
    
    
       $rss_address = $controller->getRssUrl().'?ctID='.$ctID.'&bID='.$bID ;
    
        if (isset($_GET['pageno'])) {
           $pageno = $_GET['pageno'];
        } else {
           $pageno = 1;
        } // if
        ?>
        
        <div class="newsflash">
        <div class="headtitle">
            <h1><?php echo $rssTitle ?></h1>
            </div>    
        <?php    
    
    
    
        if (!function_exists('newslistParse')) {
        
            function newslistParse($url,$thumbnail,$thumbwidth,$time,$content,$title,$date){
    
        //###################################################################################//
        //here we lay out they way the page looks, html with all our vars fed to it     //
        //this is the content that displays.  it is recommended not to edit anything beyond    //
        //the content parse.  Feel free to structure and re-arrange any element and adjust //
        //CSS as desired.                                    //
        // available vars:  $url,$thumbnail,$thumbwidth,$time,$content,$title,$date          //
        //###################################################################################//
    
            ?>
            <div class="newsflashcontain">    
                  <div class="title">
                      <?php echo $title ; ?>
                  </div>
                  <div class="time">
                      <?php echo $date ; ?><?php echo $time ; ?>
                  </div>
                  <div class="description">
                    <?php echo $content); ?>
                  </div>
            </div>
            <?php    
            
        //#####################################################################################//
        //this is the end of the recommended content area.  please do not edit below this line //
        //#####################################################################################//
            
            }
        }
        
    
            $db = Loader::db();
    
        //go grab the posts, check if they are current, return only current posts
            Loader::model('newzy','simplenews');
            $news = NewsCheck::getCurrentBlocks($ctID,$ordering);
        
        //count the number of current posts returned    
            $pcount = count($news);
    
        //if no events are returned, then we display a user defined message    
            if($pcount==0){
                echo $nonelistmsg;
            }
            
        //now calc the last page    
            $lastpage = ceil($pcount/$num);
            
        
        //set the current page min max keys -1 as array key's start @ 0
            $sKey = $num * ($pageno-1) ;
            $eKey = ($num * ($pageno-1)) + ($num-1) ;
        
            
        //take each current post and treat it like a query, for each one do X
            foreach($news as $key => $row){
        
        //check for external URL, if none, rout to parent page
            if(!empty($row['urlLink'])){
                $url = $row['urlLink'];
            }else{
                $url = $controller->grabURL($row['cParentID']); 
            }
        //check if thumbnail is there, if so get it, if not, null
            if($row['graphic']>0){
                $thumbnail = $controller->getThumbnail($row['graphic']);
            }else{
                $thumbnail = NULL;
            }
        //set vars
            $time = $controller->replaceTimeString($row['nbID']);
            $date = $row['sdt'];
            $title = $row['title'];
            //$content = strip_tags($controller->translateFrom($row['content']));
            $content = $controller->translateFrom($row['content']);
        //if truncation is enabled
            if($truncateSummaries == 1){
                if (strlen($content) >= $truncateChars){
        //truncate to suplied truncation value
                 //$content = substr($content,0,$truncateChars).'.....';
                 $content = wordwrap($content, $truncateChars);
                 $content = substr($content, 0, strpos($content, "\n")).'.....';
                }
            }
        
        
        //check if paging is enabled
                if($isPaged){
    
                //check to make sure the array key is within the range    
                    if($key >= $sKey && $key <= $eKey){
                         newslistParse($url,$thumbnail,$thumbwidth,$time,$content,$title,$date);
                    }
                    
        //if paging is not selected, use number of items designated in the list block
                }else{
                        
                        $i += 1;
    
                        newslistParse($url,$thumbnail,$thumbwidth,$time,$content,$title,$date);
                        
                //once we reach the set number stop the script        
                        if($i >= $num){ break; }    
    
                }
            }
        
        ?>
        </div>
        <?php    
        
        //is iCal feed option is sellected, show it
            if($showfeed==1){    
                ?>
        <div class="rssfeed">
            <img src="<?php echo $uh->getBlockTypeAssetsURL($bt, 'rss.png');?>" width="14" height="14" alt="rss feed" />&nbsp;&nbsp;
            <a href="<?php echo $rss_address ; ?>" id="getFeed">Get this Feed</a>
            <link href="<?php echo $controller->getRssUrl();?>" rel="alternate" type="application/rss+xml" title="<?php      echo t('RSS');?>" />
        </div>
                <?php    
            }    
        
        //$c = Page::getCurrentPage();
        $link = Loader::helper('navigation')->getLinkToCollection($c);
        $link = $controller->URLfix($link);
    
        //if pagination is set, if it is needed, show it    
            if($isPaged==1){
                    
                if ($pcount > $num) {
                    echo '<div id="pagination">';
                    if ($pageno == 1) {
                           echo " FIRST PREV ";
                    } else {
                           echo '<a href="'.$link.'pageno=1">FIRST </a>';
                           $prevpage = $pageno-1;
                           echo '<a href="'.$link.'pageno='.$prevpage.'"> PREV</a>';
                    } // if 
                    echo ' ( Page '.$pageno.' of '.$lastpage.' ) ';
                
                    if ($pageno == $lastpage) {
                           echo " NEXT LAST ";
                    } else {
                           $nextpage = $pageno+1;
                           echo '<a href="'.$link.'pageno='.$nextpage.'">NEXT </a>';
                           echo '<a href="'.$link.'    pageno='.$lastpage.'"> LAST</a>';
                    } // if        
                    echo '</div>';
                }    
            }            
        if (isset($bID)) { echo '<input type="hidden" name="bID" value="'.$bID.'" />';}
    ?>
    
     
  2. Mole

    Mole New Member

    It's really only this section of the PHP I need to edit... Can anyone help? Thanks

    Code:
    ?>
    <div class="newsflashcontain">    
                  <div class="title">
                      <?php echo $title ; ?>
                  </div>
                  <div class="time">
                      <?php echo $date ; ?><?php echo $time ; ?>
                  </div>
                  <div class="description">
                    <?php echo $content); ?>
    </div>
    </div>
    <?php    
    
     
  3. php.allstar

    php.allstar New Member

    I'd love to help, but your description is very vague... can you be a little more descriptive as I'm confused as to what you're looking for...
     
  4. Mole

    Mole New Member

  5. php.allstar

    php.allstar New Member

    Sorry, there is a bit of delay here between you posting and me checking your page so you've obviously made some changes and the red text is gone!

    If you want me to help, you can get me on GoogleTalk all day (php.allstar).
     
  6. php.allstar

    php.allstar New Member

    PHP:
    <?php

        
    foreach($images[0] as $img){

            echo 
    $img '<br />';

        }

    ?>
     
  7. Mole

    Mole New Member

    Thanks php.allstar

    This is the final code that now displays just the images from my $content.

    PHP:
            ?>
            <div class="newsflashcontain">    
                  <div class="title">
                      <?php echo $title ?>
                  </div>
                  <div class="time">
                      <?php echo $date ?>
                  </div>
                  <div class="description">
                            <?php preg_match_all('/<img[^>]+>/i',$content,$images); ?> <?php foreach($images[0] as $img){ echo $img;}?>
                  </div>
            </div>
            <?php    
     

Share This Page