1
chefry
Article... Spotlight
  • 2009/3/24 11:08

  • chefry

  • Home away from home

  • Posts: 1005

  • Since: 2006/10/14


Can someone help me with a bit of coding?

Article 1.00 and 2.0RC both sanitize text in the spotlight. It won't accept XOOPS Codes for text size or HTML <br>

In the style.css the only code relating to Spotlight is
Quote:

.article-spotlight .article-header-image img{
width: 100px;


In the template Article_Block_Spotlight.html the code is

Quote:

<h3><{$block.title}></h3>

<div style="clear: both;">
<{if $block.image.url}>
<div style="float: left; padding: 5px;">
<img src="<{$block.image.url}>" alt="<{$block.image.caption}>" />
</div>
<{/if}>
<div style="padding: 5px 0px;">
<span><{$block.lang_author}>: <{$block.writer|default:$block.author}></span>
<span><{$block.lang_time}>: <{$block.time}></span>
<br />
<{if $block.sp_note}>
<span style="font-weight: bold;"><{$block.sp_note}></span>
<br />
<{/if}>
<{if $block.summary}>
<span><{$block.summary}></span>
<{/if}>
</div>

<div>
<a href="<{$block.url}>" title="<{$smarty.const._MORE}>"><{$smarty.const._MORE}></a>
</div>
<br style="clear: both;" />
</div>


In the file class>spotlight.php the code is
Quote:

if (!defined("XOOPS_ROOT_PATH")) {
exit();
}
include_once dirname(dirname(__FILE__))."/include/vars.php";
mod_loadFunctions("parse", $GLOBALS["artdirname"]);

if(!class_exists("Spotlight")){
class Spotlight extends ArtObject
{
function Spotlight($id = null)
{
$this->ArtObject();
$this->table = art_DB_prefix("spotlight");
$this->initVar("sp_id", XOBJ_DTYPE_INT, 0);
$this->initVar("art_id", XOBJ_DTYPE_INT, 0);
$this->initVar("uid", XOBJ_DTYPE_INT, 0);
$this->initVar("sp_time", XOBJ_DTYPE_INT);
$this->initVar("sp_image", XOBJ_DTYPE_ARRAY, array());
$this->initVar("sp_categories", XOBJ_DTYPE_ARRAY, array());
$this->initVar("sp_note", XOBJ_DTYPE_TXTAREA, "");

$this->initVar("dohtml", XOBJ_DTYPE_INT, 1);
$this->initVar("dosmiley", XOBJ_DTYPE_INT, 1);
$this->initVar("doxcode", XOBJ_DTYPE_INT, 1);
$this->initVar("doimage", XOBJ_DTYPE_INT, 1);
$this->initVar("dobr", XOBJ_DTYPE_INT, 1);
}

function getImage()
{
$image = $this->getVar("sp_image");
if(!empty($image["file"])){
mod_loadFunctions("url", $GLOBALS["artdirname"]);
$image["url"] = art_getImageUrl($image["file"]);
}else{
$image = array();
}
return $image;
}

function getTime($format = "")
{
if(empty($format)){
if (!is_object($GLOBALS["xoopsModule"]) || $GLOBALS["xoopsModule"]->getVar("dirname") !=$GLOBALS["artdirname"]) {
$module_handler =& xoops_gethandler("module");
$artModule =& $module_handler->getByDirname($GLOBALS["artdirname"]);
$config_handler =& xoops_gethandler("config");
$artConfig =& $config_handler->getConfigsByCat(0, $artModule->getVar("mid"));
$format = $artConfig["timeformat"];
}else{
$format =$GLOBALS["xoopsModuleConfig"]["timeformat"];
}
}
mod_loadFunctions("time", $GLOBALS["artdirname"]);
$time = art_formatTimestamp($this->getVar("sp_time"), $format);
return $time;
}
}
}

art_parse_class('
class [CLASS_PREFIX]SpotlightHandler extends ArtObjectHandler
{
function [CLASS_PREFIX]SpotlightHandler(&$db) {
$this->ArtObjectHandler($db, art_DB_prefix("spotlight", true), "Spotlight", "sp_id");
}

function &get()
{
$Spotlight =& $this->create();
$sql = "SELECT * FROM " . art_DB_prefix("spotlight")." ORDER BY sp_id DESC LIMIT 1";
if(!$result = $this->db->query($sql)) {
return $Spotlight;
}
$array = $this->db->fetchArray($result);
if(empty($array)){
return $Spotlight;
}
$Spotlight->assignVars($array);
$Spotlight->unsetNew();

return $Spotlight;
}

/**
* Get spotlight article
*
* {@link ArtObjectHandler}
*
* @param bool $asArticleId retrun article ID
* @param bool $specifiedOnly only return article market as spotlight by editors; in this case, null is returned if "recent article" is selected in spotlight admin
* @return array spotlight content
*/
function &getContent($asArticleId = true, $specifiedOnly = false)
{
$content = array();
$spotlight =& $this->get();
if(!is_object($spotlight) || !$spotlight->getVar("art_id")){
$content["sp_note"] = "";
$content["image"] = null;
$art_id = 0;
$categories = null;
}else{
$content["sp_note"] = $spotlight->getVar("sp_note");
$content["image"] = $spotlight->getImage();
$art_id = $spotlight->getVar("art_id");
$categories = $spotlight->getVar("sp_categories");
}
if(empty($art_id) && !empty($specifiedOnly)) {
return $content;
}

$article_handler =& xoops_getmodulehandler("article", $GLOBALS["artdirname"]);
if(empty($art_id)) {
$criteria = new CriteriaCompo(new Criteria("ac.ac_publish", 0, ">"));
$arts =& $article_handler->getIdsByCategory($categories, 1, 0, $criteria);
$art_id = empty($arts[0])?0:$arts[0];
}

$content["art_id"] = $art_id;
if($asArticleId){
}elseif($art_id>0){
$article_obj =& $article_handler->get($art_id);
if(!is_object($article_obj)){
unset($content["art_id"]);
return $content;
}
$content["image"] = empty($content["image"])?$article_obj->getImage():$content["image"];
$content["title"] = $article_obj->getVar("art_title");
$content["uid"] = $article_obj->getVar("uid") ;
$content["writer_id"] = $article_obj->getVar("writer_id") ;
$content["time"] = $article_obj->getTime();
$content["views"] = $article_obj->getVar("art_counter") ;
$content["comments"]= $article_obj->getVar("art_comments") + $article_obj->getVar("art_trackbacks");
$content["summary"] = $article_obj->getSummary(true);
}else{
$content["summary"] = "";
}
return $content;
}

/**
* clean orphan items from database
*
* @return bool true on success
*/
function cleanOrphan()
{
return true; // skip this step since it will remove all spotlight with "art_id = 0";

//return parent::cleanOrphan(art_DB_prefix("article"), "art_id");


There is no other mention of Spotlight in any other files.

Can someone tell me what code to change to stop the sanitizing so that the spotlight presents the text the same was as the original Article?

TIA

2
trabis
Re: Article... Spotlight
  • 2009/3/24 14:14

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


$content["summary"] = $article_obj->getSummary(true);

Try change this to

$content["summary"] = $article_obj->getSummary();

3
chefry
Re: Article... Spotlight
  • 2009/3/25 7:33

  • chefry

  • Home away from home

  • Posts: 1005

  • Since: 2006/10/14


Nope... It didn't make a difference.

I think that refers to the summary area of the article template. If there's a summary, get it...

But the way it works is, if there isn't a summary, get X number of characters from the article body... and in preferences I have X number of characters set high enough to get that entire article body.

4
trabis
Re: Article... Spotlight
  • 2009/3/25 13:59

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


You must look into database to see what are the values for dohtml, dosmiley etc for your articles. Maybe they are set to 0 instead of 1.

EDIT: Or maybe not, if text is rendered well in article page then I suppose value is 1.

5
chefry
Re: Article... Spotlight
  • 2009/3/25 20:30

  • chefry

  • Home away from home

  • Posts: 1005

  • Since: 2006/10/14


$this->initVar("dohtml", XOBJ_DTYPE_INT, 1);

6
trabis
Re: Article... Spotlight
  • 2009/3/25 21:21

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Got it, edit class/article.php around line 192(function getSummary())

Replace by this
function getSummary($actionOnEmpty false$dohtml true)
    {
        
$myts =& MyTextSanitizer::getInstance();
        
$summary $this->getVar("art_summary""n");
        if (empty(
$summary) && !empty($actionOnEmpty)) {
            
$pages $this->getPages();
            
$text_handler =& xoops_getmodulehandler("text"$GLOBALS["artdirname"]);
            if (
count($pages) > 1) {
                
$texts =array_filter($text_handler->getList(new Criteria("text_id""(" implode(","$pages) . ")""IN")), "trim"); // fixed by Steven Chu
                
$summary implode$dohtml "<br />" ". "$texts);
            } else {
                
$text_obj =& $text_handler->get($pages[0]);
                
$summary $text_obj->getVar("text_body");
                
mod_loadFunctions("render"$GLOBALS["artdirname"]);
                
//$summary = art_html2text($summary);
                
$length = empty($GLOBALS["xoopsModuleConfig"]["length_excerpt"]) ? 255 $GLOBALS["xoopsModuleConfig"]["length_excerpt"];
                
//$summary = $myts->displayTarea( xoops_substr($summary, 0, $length), 1);
                
$summary art_truncateTagSafe($summary$length'...'false);
            }
        } else {
            
$summary $myts->displayTarea($summary1);
            if (!
$dohtml) {
                
mod_loadFunctions("render"$GLOBALS["artdirname"]);
                
$summary art_html2text($summary);
            }
        }
        return 
$summary;
    }


Now edit include/functions.render.php and add this 2 functions:

function &art_truncateTagSafe($string$length 80$etc '...'$break_words false)
{
    if (
$length == 0) return '';

    if (
strlen($string) > $length) {
        
$length -= strlen($etc);
        if (!
$break_words) {
            
$string preg_replace('/s+?(S+)?$/'''substr($string0$length+1));
            
$string preg_replace('/<[^>]*$/'''$string);
            
$string art_closeTags($string);
        }
        return 
$string $etc;
    } else {
        return 
$string;
    }
}

function &
art_closeTags($string)
{
    
// match opened tags
    
if(preg_match_all('/<([a-z:-]+)[^/]>/'$string$start_tags)) {
        
$start_tags $start_tags[1];
        
// match closed tags
        
if(preg_match_all('/</([a-z]+)>/'$string$end_tags)) {
            
$complete_tags = array();
               
$end_tags $end_tags[1];

               foreach(
$start_tags as $key => $val) {
                
$posb array_search($val$end_tags);
                   if(
is_integer($posb)) {
                      unset(
$end_tags[$posb]);
                   } else {
                    
$complete_tags[] = $val;
                }
            }
        } else {
            
$complete_tags $start_tags;
        }

        
$complete_tags array_reverse($complete_tags);
        for(
$i 0$i count($complete_tags); $i++) {
            
$string .= '</' $complete_tags[$i] . '>';
        }
    }
    return 
$string;
}

7
chefry
Re: Article... Spotlight
  • 2009/3/25 22:02

  • chefry

  • Home away from home

  • Posts: 1005

  • Since: 2006/10/14


HOORAY!!! That did it!!!!

Thanks Trabis, your a PRINCE


Login

Who's Online

186 user(s) are online (129 user(s) are browsing Support Forums)


Members: 0


Guests: 186


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits