Page 1 of 1

How to check if there is <img> tag in the table?

Posted: Tue Jun 03, 2008 3:18 am
by gosu
The script sniffs the db for the latest news published and puts them in the main page of my webpage. The images are auto resized with scaling but here is the problem: if there is news (short_story) which doesn't contain image is also published on the main page, and im trying to avoild that. I want only news which contain image to be published, i.e if we see such news skip it and go to the next one untill the limit $conf[top_number_mod]"); is reached.
I don't have idea how can i do that, any ideas? :banghead: :|

Code: Select all

 
<?PHP
if ($conf['index_allow_top_read_cat_1'] == "yes"){
$top_read_cat_1 = dle_cache("top_read_cat_1", $conf['skin']);
if (!$top_read_cat_1) {
 
    $this_month = date ('Y-m-d', time()-(3600*24*27));
 
    $db->query("SELECT id, title, date, alt_name, short_story, news_read FROM " . PREFIX . "_post WHERE approve='$conf[allow_index_metka]' AND category regexp '[[:<:]]($conf[cat_num_1])[[:>:]]' ORDER BY  date DESC LIMIT 0,$conf[top_number_mod]");
 
    while($row = $db->get_row()){
   /// How to check if there is no image stored in short_story, if there isn't skip the news and go to the next one untill LIMIT 0,$conf[top_number_mod] is reached.
        $row['date'] = strtotime($row['date']);
        
        if (strlen($row['title']) > 10)
            $title = substr ($row['title'], 0, $conf["index_top_title"])." ...";
        else
            $title = $row['title'];
 
        $go_page = ($config['ajax']) ? "onclick=\"DlePage('newsid=".$row['id']."'); return false;\" " : "";
 
        if ($conf['allow_alt_url'] == "yes")
            $link = "<a {$go_page}href=\"".$config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html\">".stripslashes($title)."</a>";
        else 
            $link = "<a {$go_page}href=\"$PHP_SELF?newsid=".$row['id']."\">".stripslashes($title)."</a>";
            if ($conf['allow_read_num']=="yes")
            $read = "(".$row['news_read'].")";
 
if ($conf['allow_images_catindex'] == "yes")
{
    unset($img);
    $img =  get_img_basic($row['short_story']);
    if ($img =="")
        $images ="";
    else
        if ($conf['img_blank'] == "yes")
        {
            $images_show = "<a href=\"$img\" target=\"_top\">";
            $images_show_a = "</a>";
        }
        else
        {
            $images_show = "<a href=\"$img\" target=\"_blank\">";
            $images_show_a = "</a>";
        };
    if ($conf['img_click_allow'] == "no")
    {
        $images_show = "";
        $images_show_a = "";
    }
    
    //--------------
    define( 'CAT_IMG', ROOT_DIR.'/uploads/cat/' );
    define( 'CAT_HTTP_IMG', $config['http_home_url'].'uploads/cat/' );
    if (!file_exists(CAT_IMG))
    {
        if ( !(@mkdir(CAT_IMG, 0777)) ) { return '<br> RNB: Unable to mkdir: "'.CAT_IMG.'"'; }
        if ( !(@chmod(CAT_IMG, 0777)) ) { return '<br> RNB: Unable to chmod: "'.CAT_IMG.'"'; }
    }
 
    $not_resized_image = $img;
    $resized_image = CAT_IMG.basename($img);
    if ( 
            ( $size_img = @getimagesize($not_resized_image) ) &&
            (
                ( $size_img[0] > (int)$conf[img_catindex_wigth]) || ($size_img[1] > (int)$conf[img_catindex_hieght]) )
            )
    {
        if (!file_exists( $resized_image ))
        { # make resize:
            $cim = new fth_cropImage;
            $cim->cropImage(    
                                intval($conf[img_catindex_wigth]), 
                                intval($conf[img_catindex_hieght]), 
                                $not_resized_image, 
                                $resized_image 
                            );
            if ( !(@chmod ($resized_image, 0666)) ) { return '<br> CAT: Unable to chmod: "'.$resized_image.'"'; }
        }
    }
 
    //--------------
    if ($img)
    $images = $images_show."<img src=\"".CAT_HTTP_IMG.basename($img)."\" align=\"".$conf[img_catindex_align]."\" border=0>".$images_show_a;
}
 
$row['short_story'] = strip_tags( $row['short_story'] );
 
    if ($conf['allow_short_story']=="yes"){ 
        if ($conf['allow_alt_url'] == "yes")
        if ($conf['allow_dalee']=="yes"){
$links = "<a {$go_page} href=\"".$config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html\">"."Read more"."</a>";
}else{
    $links = "<a {$go_page} href=\"".$config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html\">"."</a>";
}
        else 
        if ($conf['allow_dalee']=="yes"){
            $links = "<a {$go_page}href=\"$PHP_SELF?newsid=".$row['id']."\">"."Read more"."</a>";
            }else{
            $links = "<a {$go_page}href=\"$PHP_SELF?newsid=".$row['id']."\">"."</a>";   
            }     
            if (strlen($row['short_story']) > 50)
            $short_story = substr ($row['short_story'],0, $conf["index_top_symbol"])."...$links";
            else
            $short_story = stripslashes($row['short_story']);
 
if ($conf['date_story']=="yes"){
$date_story =langdate($conf['timestamp_active'], $row['date']);
};
      $top_read_cat_1 .= "<td valign=\"top\" width=\"175px\"><table width=\"175px\"><tr><td class=\"ovt\">".$link.$read."</td>
  <td rowspan=\"4\" class=\"sep1\">&nbsp;</td></tr><tr><td>".$images."</td></tr><tr><td class=\"ovm\">".$short_story."</td>
  </tr><tr><td class=\"small_bold_font\">".$date_story."</td></tr></table></td>";  
            }else{
                    $top_read_cat_1 .= "<div class=\"$conf[index_top_css_mod_title]\">&raquo;".$link.$read.$register."</div>";
            }
    } 
    }
 
    $db->free();
    create_cache ("top_read_cat_1", $top_read_cat_1, $conf['skin']);
}
 
?>
 

Re: How to check if there is <img> tag in the table?

Posted: Tue Jun 03, 2008 7:38 am
by vargadanis
Probalby the simplest way of doing it is examining the content which you have recieved from the DB. If it contains an < img > tag, than it will be displayed otherwise not:

Code: Select all

if(strpos($search, "<img>")!==false){ // must use !== instead of !=
//display
}
 
the bests...

Re: How to check if there is <img> tag in the table?

Posted: Tue Jun 03, 2008 10:13 am
by gosu
I'll put temporary solution untill i can make it work fine
path-to-image will be thumbnail something like 'no-preview'..

Code: Select all

 
    //--------------
    if ($img){
    $images = $images_show."<img src=\"".CAT_HTTP_IMG.basename($img)."\" align=\"".$conf[img_catindex_align]."\" border=0>".$images_show_a;}
/// temp
    else    $images = $images_show."<img src=\"path-to-image\" align=\"".$conf[img_catindex_align]."\" border=0>".$images_show_a;
 
}
 

Re: How to check if there is <img> tag in the table?

Posted: Tue Jun 03, 2008 12:29 pm
by vargadanis
That was a possibility too. Just a remark... When you quote a code (PHP, SQL) do it this way:
[ code = php ]code[ / code ]
It will display as

Code: Select all

<?
    print "Hello World!";
?>
instead of

Code: Select all

<?
    print "Hello World!";
?>

Re: How to check if there is <img> tag in the table?

Posted: Tue Jun 03, 2008 2:40 pm
by gosu
Thanks I fixed the upper posts will know in future :)

Re: How to check if there is <img> tag in the table?

Posted: Wed Jun 04, 2008 10:25 am
by vargadanis
Thanks a lot.. A person who cares :)

Re: How to check if there is <img> tag in the table?

Posted: Wed Jun 04, 2008 10:47 am
by gosu
yeah why not, if it looks nice and neat more people will read it and eventually i will find a solution, im a php begginer so if you want to help me, explain me like if you were involved in php for 2 months now... :lol: