- Posts: 4
- Thank you received: 0
Add the functions to get Image from Content
-
jianhui0215
Inactive member - Topic Author
- New Member
Less
More
13 years 6 months ago - 13 years 6 months ago #8597
by jianhui0215
Add the functions to get Image from Content was created by jianhui0215
I Modify the file, Now that can get Images from content items,
1.modify mod_hot_joomla_carousel.xml
add these params
2.add a helper.php file
3.modify the tmpl/default.php file ,del the original code between <ul style="margin:0; padding:0"> ..... to </ul> ,and add the new code as bellow
1.modify mod_hot_joomla_carousel.xml
add these params
Code:
<param type="spacer" default="Images and Contents Source Properties" />
<param name="secid" type="text" default="" label="Section ID" description="PARAMSECTIONID" />
<param name="catid" type="text" default="" label="Category ID" description="PARAMCATEGORYID" />
<param name="count" type="text" default="5" label="Count" description="The number of items to display (default 5)" />
<param name="ordering" type="list" default="c_dsc" label="Ordering" description="Ordering options">
<option value="c_dsc">Recently Added First</option>
<option value="m_dsc">Recently Modified First</option>
</param>
<param name="picSource" type="list" default="content" label="LABEL Images and Contents Source From" description="DESC Images and Contents Source From">
<option value="content">Get Pictures from Content Items</option>
<option value="folder">Get Picture from folder</option>
</param>
<param name="imageSource" type="list" default="all" label="LABEL IMAGE Source" description="DESC IMAGE Source">
<option value="all">Intro Text + Full Text</option>
<option value="intro">Intro Text</option>
<option value="full">Full Text</option>
</param>
2.add a helper.php file
Code:
<?php
class modHotJoomlaCarouselHelper
{
function get_ArticalList(&$params)
{
//global $mainframe;
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$userId = (int) $user->get('id');
$count =5;// (int) $params->get('count', 5);
$catid = trim( $params->get('catid') );
$secid = trim( $params->get('secid') );
$show_front = $params->get('show_front', 1);
$aid = $user->get('aid', 0);
$contentConfig = &JComponentHelper::getParams( 'com_content' );
$access = !$contentConfig->get('show_noauth');
$nullDate = $db->getNullDate();
$date =& JFactory::getDate();
$now = $date->toMySQL();
$where = 'a.state = 1'
. ' AND ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )'
. ' AND ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )'
;
// User Filter
switch ($params->get( 'user_id' ))
{
case 'by_me':
$where .= ' AND (created_by = ' . (int) $userId . ' OR modified_by = ' . (int) $userId . ')';
break;
case 'not_me':
$where .= ' AND (created_by <> ' . (int) $userId . ' AND modified_by <> ' . (int) $userId . ')';
break;
}
// Ordering
switch ($params->get( 'ordering' ))
{
case 'm_dsc':
$ordering = 'a.modified DESC, a.created DESC';
break;
case 'c_dsc':
default:
$ordering = 'a.created DESC';
break;
}
if ($catid)
{
$ids = explode( ',', $catid );
JArrayHelper::toInteger( $ids );
$catCondition = ' AND (cc.id=' . implode( ' OR cc.id=', $ids ) . ')';
}
if ($secid)
{
$ids = explode( ',', $secid );
JArrayHelper::toInteger( $ids );
$secCondition = ' AND (s.id=' . implode( ' OR s.id=', $ids ) . ')';
}
// Content Items only
$query = 'SELECT a.*, ' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'.
' FROM #__content AS a' .
($show_front == '0' ? ' LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id' : '') .
' INNER JOIN #__categories AS cc ON cc.id = a.catid' .
' INNER JOIN #__sections AS s ON s.id = a.sectionid' .
' WHERE '. $where .' AND s.id > 0' .
($access ? ' AND a.access <= ' .(int) $aid. ' AND cc.access <= ' .(int) $aid. ' AND s.access <= ' .(int) $aid : '').
($catid ? $catCondition : '').
($secid ? $secCondition : '').
($show_front == '0' ? ' AND f.content_id IS NULL ' : '').
' AND s.published = 1' .
' AND cc.published = 1' .
' ORDER BY '. $ordering;
$db->setQuery($query, 0, $count);
$rows = $db->loadObjectList();
$i = 0;
$lists = array();
foreach ( $rows as $row )
{
if($row->access <= $aid)
{
$lists[$i]->link = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid));
} else {
$lists[$i]->link = JRoute::_('index.php?option=com_user&view=login');
}
$lists[$i]->title = htmlspecialchars( $row->title );
$lists[$i]->introtext= ( $row->introtext );
$lists[$i]->fulltext= ( $row->fulltext );
$i++;
}
//print_r($rows);
return $lists;
}
}
?>
3.modify the tmpl/default.php file ,del the original code between <ul style="margin:0; padding:0"> ..... to </ul> ,and add the new code as bellow
Code:
<?php
$count=$params->get('count',15);
$picSource=$params->get('picSource','content');
switch($picSource)
{
case 'folder':
$carouselPath = $_SERVER['SCRIPT_FILENAME'];
$carouselRealPath = substr_replace($carouselPath ,"",-9);
$carouselFullPath = $carouselRealPath.$carouselImagesPath;
if ($handle = opendir($carouselFullPath))
{
$infinite_pics_number = 0;
$infinite_list = "";
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if($infinite_list !== "")
{ $infinite_list = $infinite_list."||"."$file";}
else
{ $infinite_list = "$file";}
$infinite_pics_number = $infinite_pics_number + 1;
}
}
closedir($handle);
$infinite_pic = explode("||", $infinite_list);
//$infinite_pics_number = count($infinite_pic) - 2;
for ($loop = 0; $loop < $infinite_pics_number; $loop += 1) {
sort($infinite_pic);
$pic_type = explode(".", $infinite_pic[$loop]);
if ((($pic_type[1]=="jpg")or($pic_type[1]=="gif"))or(($pic_type[1]=="jpeg")or($pic_type[1]=="png"))) {
echo '<li><img src="'.$carouselImagesPath.'/'.$infinite_pic[$loop].'" alt="" width="'.$imageWidth.'" height="'.$imageHeight.'" /></li>';
echo "\n";
} elseif ((($pic_type[1]=="JPG")or($pic_type[1]=="GIF"))or(($pic_type[1]=="JPEG")or($pic_type[1]=="PNG"))) {
echo '<li><img src="'.$carouselImagesPath.'/'.$infinite_pic[$loop].'" alt="" width="'.$imageWidth.'" height="'.$imageHeight.'" /></li>';
echo "\n";
}
}
}
break;
case 'content':
default:
$cs=modHotJoomlaCarouselHelper::get_ArticalList($params);
//$heading=array();
//$link=array();
//$images=array();
$loop=1;
//print_r($cs);
foreach ( $cs as $row ) {
///if you title is long, you may using $heading[$loop]=JString::substr($row->title,0,$params->get(limittitle));
$heading[$loop]=$row->title;
$link[$loop] = $row->link;
$text=$row->introtext .$row->fulltext;
///search the images
$regex = "/<img[^>]+src\s*=\s*[\"']\/?([^\"']+)[\"'][^>]*\>/";
$search = $text;
preg_match ($regex, $search, $matches);
$images = (count($matches)) ? $matches : array();
$image[$loop]=$images[1];
//print_r($images);
echo '<li><a href="'.$link[$loop].'"><img src="'.$image[$loop].'" alt="" width="'.$imageWidth.'" height="'.$imageHeight.'" /></a></li>';
echo "\n";
$loop++;
}
break;
}
?>
Last edit: 13 years 6 months ago by jianhui0215.
Please Log in to join the conversation.
-
ivan.milic
Support Staff - Moderator
Less
More
- Posts: 14116
- Thank you received: 1639
13 years 6 months ago #8609
by ivan.milic
Replied by ivan.milic on topic Re: Does someone need get Image from Content ?
You are welcome to post your work here if you want. People often search this forum and eventually and I'am sure you will make quite of them happy.
Best Regards,
Best Regards,
Please Log in to join the conversation.
Time to create page: 0.153 seconds