- Posts: 4
- Thank you received: 0
Get Image and text from Content
-
jianhui0215
Inactive member - Topic Author
- New Member
Less
More
13 years 6 months ago - 13 years 6 months ago #8534
by jianhui0215
Get Image and text from Content was created by jianhui0215
I Like Hot News flash very much ,but it only supports static image from module setting page,so I do some work to let that get images and text from content items .
all is bellow:
first : modify mod xml file
I add some param, special is the category ID.
mod_hot_newsflash.xml
second ,change the default image folder to ""
third, modify the php code, add some functions ,let it get image,title,text from content items
mod_hot_newsflash.php
1.change the default image folder
2.the php code
I'm Chinese, now I'm living in Jiangsu Province, my email is 26365685@qq.com
If you have some problem , Maybe I can give some help.
all is bellow:
first : modify mod xml file
I add some param, special is the category ID.
mod_hot_newsflash.xml
Code:
<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="limittitle" type="text" default="" label="Title Chars Limit" description="Article's Title Characters Limit" />
<param name="contentLength" type="text" default="150" label="Content Lenght" description="DESC CONTENT LENGTH" />
second ,change the default image folder to ""
Code:
<param name="imageFolder" type="text" default="" label="LABEL FOLDER" description="DESC FOLDER" />
third, modify the php code, add some functions ,let it get image,title,text from content items
mod_hot_newsflash.php
1.change the default image folder
Code:
line 35: $imageFolder = $params->get('imageFolder','');
2.the php code
Code:
/* cancel the original method
for ($loop = 1; $loop <= 5; $loop += 1) {
$heading[$loop] = $params->get('heading'.$loop,'Lorem Ipsum');
}
for ($loop = 1; $loop <= 5; $loop += 1) {
$link[$loop] = $params->get('link'.$loop,'#');
}
for ($loop = 1; $loop <= 5; $loop += 1) {
$info[$loop] = $params->get('info'.$loop,'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam.');
}
for ($loop = 1; $loop <= 5; $loop += 1) {
$image[$loop] = $params->get('image'.$loop,'image'.$loop.'.jpg');
}
*/
$cs=get_ArticalList($params);
//print_r($cs);
$loop=1;
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;
$c=JString::substr(html2txt($text) ,0,$params->get(contentLength));
$info[$loop]=$c.' ...';
///grep images
$regex = "/<img[^>]+src\s*=\s*[\"']\/?([^\"']+)[\"'][^>]*\>/";
$search = $row->introtext . $row->fulltext;
preg_match ($regex, $search, $matches);
$images = (count($matches)) ? $matches : array();
$image[$loop]=$images[1];
//print_r($images);
$loop++;
}
$speed = $params->get('speed','5000');
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;
}
function html2txt($str) {
$search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 javascript
"'<[\/\!]*?[^<>]*?>'si", // 去掉 HTML 标记
"'([\r\n])[\s]+'", // 去掉空白字符
"'&(quot|#34);'i", // 替换 HTML 实体
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // 作为 PHP 代码运行
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$text = preg_replace ($search, $replace, $str);
return $text;
}
I'm Chinese, now I'm living in Jiangsu Province, my email is 26365685@qq.com
If you have some problem , Maybe I can give some help.
Last edit: 13 years 6 months ago by jianhui0215.
Please Log in to join the conversation.
-
milos
Support Staff - Moderator
Less
More
- Posts: 6742
- Thank you received: 715
13 years 6 months ago #8535
by milos
Replied by milos on topic Re: Get Image and text from Content
Great, but before we test it please tell us is it for Joomla 1.5 or Joomla 1.6 version of the Hot Newsflash module?
Please Log in to join the conversation.
-
jianhui0215
Inactive member - Topic Author
- New Member
Less
More
- Posts: 4
- Thank you received: 0
13 years 6 months ago #8555
by jianhui0215
Replied by jianhui0215 on topic Re: Get Image and text from Content
I run it on joomla 1.5, so the modified version runs under joomla 1.5 too.
Please Log in to join the conversation.
-
jianhui0215
Inactive member - Topic Author
- New Member
Less
More
- Posts: 4
- Thank you received: 0
13 years 6 months ago - 13 years 6 months ago #8596
by jianhui0215
Replied by jianhui0215 on topic Re: Get Image and text from Content
Version 2:
now ,you can switch images from content items or from you typed as before .
Under joomla 1.5
Firest : change the xml file
1:change imageFolder the default to ""
2: add some params
2nd, modify mod_hot_newsflash.php file
1:Change the $imageFolder 's default value
2:add the code, the file is long ,so I give all the php code of the file
Have funs, the Attachments is all the module
now ,you can switch images from content items or from you typed as before .
Under joomla 1.5
Firest : change the xml file
1:change imageFolder the default to ""
Code:
<param name="imageFolder" type="text" default="" label="LABEL FOLDER" description="DESC FOLDER" />
2: add some params
Code:
<param type="spacer" default="Images and Contents Source Properties" />
<param name="sourceFrom" type="list" default="sql" label="LABEL Images and Contents Source From" description="DESC Images and Contents Source From">
<option value="db">Content Item in the DB</option>
<option value="typed">bellow typed</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>
<param name="contentSource" type="list" default="all" label="LABEL Content Source" description="DESC Content Source">
<option value="all">Intro Text + Full Text</option>
<option value="intro">Intro Text</option>
<option value="full">Full Text</option>
</param>
<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="contentLength" type="text" default="150" label="Content Lenght" description="DESC CONTENT LENGTH" />
2nd, modify mod_hot_newsflash.php file
1:Change the $imageFolder 's default value
Code:
$imageFolder = $params->get('imageFolder','');
2:add the code, the file is long ,so I give all the php code of the file
Code:
<?php
//no direct access
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
// Path assignments
$mosConfig_absolute_path = JPATH_SITE;
$mosConfig_live_site = JURI :: base();
if(substr($mosConfig_live_site, -1)=="/") { $mosConfig_live_site = substr($mosConfig_live_site, 0, -1); }
// get parameters from the module's configuration
$enablejQuery = $params->get('enablejQuery','1');
$noConflictMode = $params->get('noConflictMode','0');
$moduleWidth = $params->get('moduleWidth','600');
$moduleBackground = $params->get('moduleBackground','ffffff');
$borderWidth = $params->get('borderWidth','0');
$borderColor = $params->get('borderColor','000000');
$readMore = $params->get('readMore','1');
$readMoreText = $params->get('readMoreText','Full story');
$headingTextColor = $params->get('headingTextColor','000000');
$mainTextColor = $params->get('mainTextColor','000000');
$tabNumber = $params->get('tabNumber','4');
$tabWidth = $params->get('tabWidth','150');
$tabBgColor = $params->get('tabBgColor','ffffff');
$tabBgColorHover = $params->get('tabBgColorHover','f2f2f2');
$tabBgColorActive = $params->get('tabBgColorActive','000000');
$tabFontColor = $params->get('tabFontColor','000000');
$tabFontColorHover = $params->get('tabFontColorHover','000000');
$tabFontColorActive = $params->get('tabFontColorActive','ffffff');
$tabDelimiterColor = $params->get('tabDelimiterColor','cccccc');
$tabMultiline = $params->get('tabMultiline','0');
$imageFolder = $params->get('imageFolder','');
$imageWidth = $params->get('imageWidth','256');
$imageHeight = $params->get('imageHeight','169');
$imageLink = $params->get('imageLink','1');
$imageSource= $params->get('imageSource','all');
$contentSource= $params->get('contentSource','full');
$sourceFrom = $params->get('sourceFrom','db');
switch ($sourceFrom )
{
case 'typed':
for ($loop = 1; $loop <= 5; $loop += 1) {
$heading[$loop] = $params->get('heading'.$loop,'Lorem Ipsum');
}
for ($loop = 1; $loop <= 5; $loop += 1) {
$link[$loop] = $params->get('link'.$loop,'#');
}
for ($loop = 1; $loop <= 5; $loop += 1) {
$info[$loop] = $params->get('info'.$loop,'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam.');
}
for ($loop = 1; $loop <= 5; $loop += 1) {
$image[$loop] = $params->get('image'.$loop,'image'.$loop.'.jpg');
}
break;
case 'db':
default:
$cs=get_ArticalList($params);
//print_r($cs);
$loop=1;
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='';
switch ($contentSource) {
case 'intro':
$text=$row->introtext;
break;
case 'full':
$text= $row->fulltext;
break;
case 'all':
default:
$text=$row->introtext . $row->fulltext;
}
//echo $params->get(contentLength).$text;
//$text=$row->introtext . $row->fulltext;
$c=JString::substr(txt2html(html2txt($text)) ,0,$params->get(contentLength));
$info[$loop]=$c.' ...';
///这里是查找照片
$regex = "/<img[^>]+src\s*=\s*[\"']\/?([^\"']+)[\"'][^>]*\>/";
$search ='';//.$row->introtext . $row->fulltext;
switch ($imageSource) {
case 'intro':
$search=$row->introtext;
break;
case 'full':
$search= $row->fulltext;
break;
case 'all':
default:
$search=$row->introtext . $row->fulltext;
}
preg_match ($regex, $search, $matches);
$images = (count($matches)) ? $matches : array();
$image[$loop]=$images[1];
//print_r($images);
$loop++;
}
$speed = $params->get('speed','5000');
break;
}
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;
}
function html2txt($str) {
$search = array ("'<script[^>]*?>.*?</script>'si", // del javascript
"'<[\/\!]*?[^<>]*?>'si", // del the HTML tag
"'([\r\n])[\s]+'", // del spac
"'&(quot|#34);'i",
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // 作为 PHP 代码运行
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$text = preg_replace ($search, $replace, $str);
return $text;
}
/**
* txt 2 HTML
*
* @param string $txt;
* return string;
*/
function txt2html($txt){
$txt = str_replace(" "," ",$txt);
$txt = str_replace("<","<",$txt);
$txt = str_replace(">",">",$txt);
$txt = preg_replace("/[\r\n]{1,}/isU","<br/>\r\n",$txt);
return $txt;
}
require(JModuleHelper::getLayoutPath('mod_hot_newsflash'));
Have funs, the Attachments is all the module
Last edit: 13 years 6 months ago by jianhui0215.
Please Log in to join the conversation.
-
Yowsa
Inactive member - New Member
Less
More
- Posts: 2
- Thank you received: 0
13 years 5 months ago #8927
by Yowsa
Replied by Yowsa on topic Re: Get Image and text from Content
Any way you could help out and move the tab-links to the left instead of the right? I am loving your version of hot newsflash, perfect for what I want except for the tab-positions
Thanks in advance
Thanks in advance
Please Log in to join the conversation.
-
Alimoso
Inactive member - New Member
Less
More
- Posts: 1
- Thank you received: 0
13 years 4 months ago #9656
by Alimoso
Replied by Alimoso on topic Re: Get Image and text from Content
Hiya all!
Do you think it's worth trying the code out on the Joomla 1.6 version of the Hot Newsflash module?
Sounds exactly like what I've been looking for! :laugh:
Do you think it's worth trying the code out on the Joomla 1.6 version of the Hot Newsflash module?
Sounds exactly like what I've been looking for! :laugh:
Please Log in to join the conversation.
Time to create page: 0.143 seconds