1
lukeon
xlanguage: more content in one language than other
  • 2008/6/2 14:46

  • lukeon

  • Just popping in

  • Posts: 17

  • Since: 2008/4/2 6


Hi!

I installed xlanguage 3.01 on my Xoops
it works fine.

I have 2 languages english and swedish

The only problem I have that sometime I want to post news (or anything) only in one of this languages. When I do so in the other language only things like " Posted by: " "Read more" etc.

How do I do to hide all this texts if the content of a news / article in a certain language is empty?

2
kerkyra
Re: xlanguage: more content in one language than other
  • 2008/6/2 18:56

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


you could add the content without the language tag! this way both languages will show the same content.
www.guidemap.gr - Beta is out...

3
lukeon
Re: xlanguage: more content in one language than other
  • 2008/6/9 10:06

  • lukeon

  • Just popping in

  • Posts: 17

  • Since: 2008/4/2 6


Yes I thought about that.

It solves the problem when I have a basic language (english) and some articles translated (swedish)

so i tag only the swedish text and put it on the top.


But I was wondering if there is something I can do when the article is only in swedish (for swedish readers only)

Thanks kerkyra!

4
kerkyra
Re: xlanguage: more content in one language than other
  • 2008/6/9 10:17

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


hmm i dont know about that! perhaps you could check in the db string if the swidish tag text equals the other language text show an icon swidish only for example! But i'm not sure how you could do that :) you'll have to do some research...
www.guidemap.gr - Beta is out...

5
kerkyra
Re: xlanguage: more content in one language than other
  • 2008/6/10 13:15

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


i had to research a lil bit cause i needed something similar to what you want so here is what i have found.

in your include folder, make a file with the following code and include it.

Quote:
function ExtractString($str, $start, $end)
{
$str_low = strtolower($str);
$pos_start = strpos($str_low, $start);
$pos_end = strpos($str_low, $end, ($pos_start + strlen($start)));
if ( ($pos_start !== false) && ($pos_end !== false) )
{
$pos1 = $pos_start + strlen($start);
$pos2 = $pos_end - $pos1;
return substr($str, $pos1, $pos2);
}
}


in order to check if you have a 2nd language all you have to do is query the db and hold the content in a variable without sanitising it.
you will get something like this

Quote:
[en]english text[/en][sw]swidish text[/sw]


now you can check the string between the tags calling that function like this

Quote:
$swidishdata= ExtractString($data, '[sw]','[/sw]');
$englishdata = ExtractString($data, '[en]','[/en]');
if ($swidishdata==$englishdata || $englishdata ==null)
{
echo "swidish only";
}


I hope it helps...
www.guidemap.gr - Beta is out...

6
lukeon
Re: xlanguage: more content in one language than other
  • 2008/6/11 8:51

  • lukeon

  • Just popping in

  • Posts: 17

  • Since: 2008/4/2 6


Hej kerkyra!

Thank you for your help. But I'm sort of beginer with all this. Can you explain it more in "for a dummy" style;)

to create a file in include folder, that I can do (lets tell it will have name: langcheck.php)

to include it, i should have a line like this:
include "langcheck.php";

right?
But where should I cinclude this?

Ant the hardest part: Quote:
all you have to do is query the db and hold the content in a variable without sanitising it

this I don't know how to do :(

Where do i insert the code you have provided? in witch file?
how do i call it (execute the querry)

please give me some more advice:)

Thank you for your support.

Just so you know I was experimenting with user groups (ex. swedish users) and view permission settings, but they seem not to work:( I want to try your idea (will reduce the administration fuss with more user groups)

7
kerkyra
Re: xlanguage: more content in one language than other
  • 2008/6/11 11:54

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


you have to edit the php file which runs when u see the news for example. you can see which one it is from the url (www.mysite.com/modules/news/view.php?something) for example.

in the above case you would have to edit the view.php file.

include the file with the function on top of the code where the other include statements are.

then you need to find the sql statement which gets the data from the db. Run through the file code to find it.
it should look like this...
Quote:

$result = $xoopsDB->query("select ... from ".$xoopsDB->prefix("...")." where ...");


bellow that code it should be a while statement or a list of variables that hold the data from the db.

spot the one that holds the multilanguage data you want to check.

this variable is the one you need.

run it through the function to seperate the 2 languages like i wrote you in the post. you have to do that BEFORE that variable is sanitized... that means before the line which should look like this

Quote:

$variablename=myts->makeTboxData4Show($variablename);



i have used the above code and is working fine so if done correctly you shouldnt have any probs

have a shot and if you find any more probs we are here to help
www.guidemap.gr - Beta is out...

8
lukeon
Re: xlanguage: more content in one language than other
  • 2008/6/12 11:54

  • lukeon

  • Just popping in

  • Posts: 17

  • Since: 2008/4/2 6


I use AMS for news section, and the query you were talking about is in the file
.....modules\AMS\class\class.newsstory.php

below is a part of its code which i guess I need to modifiy (i copied it from line 32 to line 213)

The columns that contain language tags in DB are 'hometext' and 'bodytext' from table xoops_ams_text
and 'title' from table xoops_ams_article

I think i need to modify the function getAllPublished (line 166) the way you told me, but i cant find variables that hold my data.

please give me some hint:)

include_once XOOPS_ROOT_PATH."/class/xoopsstory.php";
include_once 
XOOPS_ROOT_PATH."/modules/AMS/class/class.newstopic.php";
include_once 
XOOPS_ROOT_PATH.'/include/comment_constants.php';


class 
AmsStory extends XoopsStory
{
    var 
$newstopic;   // XoopsTopic object
    
var $change;
    var 
$version;
    var 
$revision;
    var 
$revisionminor;
    var 
$current;
    var 
$texttable;
    var 
$ratings//individual ratings
    
var $rating//average rating
    
var $updated//Last update
    
var $_errors=array(); //errors encountered
    
var $isNew false;
    var 
$versionConflict false;
    var 
$banner;
    var 
$VersionNo;
    var 
$audienceid;
    var 
$audience;
    var 
$audiencetable;
    var 
$_hasVersions = -1;
    var 
$uname "";

    function 
AmsStory($storyid=-1$getRating false)
    {
        
$this->db =& Database::getInstance();
        
$this->table $this->db->prefix("ams_article");
        
$this->texttable $this->db->prefix("ams_text");
        
$this->topicstable $this->db->prefix("ams_topics");
        
$this->audiencetable $this->db->prefix("ams_audience");
        if (
is_array($storyid)) {
            
$this->makeStory($storyid);
            
$this->newstopic $this->topic();
        } elseif(
$storyid != -1) {
            
$this->getStory(intval($storyid));
            
$this->newstopic $this->topic(true);
            if (
$getRating != false) {
                
$this->getRatings();
            }
        }
        else {
            
$this->isNew true;
        }
    }

    function 
topic($single_topic false)
    {
        if (!
$this->newstopic) {
            if (
false == $single_topic) {
                
$topics AmsTopic::getAllTopics();
                
$this->newstopic $topics[$this->topicid()];
            }
            else {
                
$this->newstopic = new AmsTopic($this->topicstable$this->topicid());
            }
        }
        return 
$this->newstopic;
    }

    function 
getStory($storyid)
    {
        
$sql "SELECT * FROM ".$this->table." n, ".$this->texttable." t, ".$this->audiencetable." a WHERE n.storyid=t.storyid AND n.audienceid=a.audienceid AND t.current=1 AND n.storyid=".$storyid."";
        
$array $this->db->fetchArray($this->db->query($sql));
        
$this->makeStory($array);
    }

    function 
hometext($format="Show")
    {
        
$myts =& MyTextSanitizer::getInstance();
        
$html 1;
        
$smiley 1;
        
$xcodes 1;
        if ( 
$this->nohtml() ) {
            
$html 0;
        }
        if ( 
$this->nosmiley() ) {
            
$smiley 0;
        }
        switch ( 
$format ) {
            case 
"Show":
            
$hometext $myts->displayTarea($this->hometext,$html,$smiley,$xcodes);
            break;
            case 
"Edit":
            
$hometext $myts->htmlSpecialChars($this->hometext);
            break;
            case 
"Preview":
            
$hometext $myts->previewTarea($this->hometext,$html,$smiley,$xcodes);
            break;
            case 
"InForm":
            
$hometext $myts->htmlSpecialChars$myts->stripSlashesGPC($this->hometext));
            break;
            case 
"N":
            
$hometext stripslashes($this->hometext);
            break;
        }
        return 
$hometext;
    }

    function 
bodytext($format="Show")
    {
        
$myts =& MyTextSanitizer::getInstance();
        
$html 1;
        
$smiley 1;
        
$xcodes 1;
        if ( 
$this->nohtml() ) {
            
$html 0;
        }
        if ( 
$this->nosmiley() ) {
            
$smiley 0;
        }
        switch ( 
$format ) {
            case 
"Show":
            
$bodytext $myts->displayTarea($this->bodytext,$html,$smiley,$xcodes);
            break;
            case 
"Edit":
            
$bodytext $myts->htmlSpecialChars($this->bodytext);
            break;
            case 
"Preview":
            
$bodytext $myts->previewTarea($this->bodytext,$html,$smiley$xcodes);
            break;
            case 
"InForm":
            
$bodytext $myts->htmlSpecialChars($myts->stripSlashesGPC($this->bodytext));
            break;
            case 
"N":
            
$bodytext stripslashes($this->bodytext);
            break;
        }
        return 
$bodytext;
    }

    function 
getAllPublished($limit=0$start=0$checkRight false$topic=0$ihome=0$asobject=true$order 'published'$ids false)
    {
        
$db =& Database::getInstance();
        
$myts =& MyTextSanitizer::getInstance();
        
$ret = array();
        
$sql "SELECT * FROM ".$db->prefix("ams_article")." n, ".$db->prefix("ams_text")." t, ".$db->prefix("ams_audience")." a WHERE t.storyid=n.storyid AND n.audienceid=a.audienceid AND published > 0 AND published <= ".time()." AND (expired = 0 OR expired > ".time().")";
        if ( 
$topic != ) {
            if (!
is_array($topic)) {
                
$sql .= " AND topicid=".intval($topic)." AND (ihome=1 OR ihome=0)";
            }
            else {
                
$sql .= " AND topicid IN (".implode(','$topic).")";
            }
        } else {
            if (
$checkRight) {
                global 
$xoopsUser$xoopsModule;
                if (!isset(
$xoopsModule) || $xoopsModule->getVar('dirname') != "AMS") {
                    
$module_handler =& xoops_gethandler('module');
                    
$newsModule =& $module_handler->getByDirname('AMS');
                }
                else {
                    
$newsModule =& $xoopsModule;
                }
                
$groups $xoopsUser $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
                
$gperm_handler =& xoops_gethandler('groupperm');
                
$topics $gperm_handler->getItemIds('ams_view'$groups$newsModule->getVar('mid'));
                
$topics implode(','$topics);
                
$sql .= " AND topicid IN (".$topics.")";
            }
            if ( 
$ihome == ) {
                
$sql .= " AND ihome=0";
            }
        }
        if (
$ids != false) {
            
$sql .= " AND n.storyid NOT IN (".implode(','$ids).")";
        }
        
$sql .= " AND t.current=1";
        
$sql .= " ORDER BY $order DESC";
        
$result $db->query($sql,intval($limit),intval($start));
        while ( 
$myrow $db->fetchArray($result) ) {
            if ( 
$asobject ) {
                
$ret[] = new AmsStory($myrow);
            } else {
                
$ret[$myrow['storyid']] = $myts->makeTboxData4Show($myrow['title']);
            }
        }
        return 
$ret;
    }

9
kerkyra
Re: xlanguage: more content in one language than other
  • 2008/6/12 13:10

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


can you post the file which call this class and shows your data??? what php file is on the url in which you get the content of your articles?
www.guidemap.gr - Beta is out...

10
lukeon
Re: xlanguage: more content in one language than other
  • 2008/6/12 14:48

  • lukeon

  • Just popping in

  • Posts: 17

  • Since: 2008/4/2 6


i have just folder in the url, so i guess it will be index.php, here it is:

<?php
// $Id: index.php,v 1.15 2004/05/25 10:53:08 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <https://xoops.org/>                             //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
include '../../mainfile.php';

include_once 
XOOPS_ROOT_PATH.'/modules/AMS/class/class.newsstory.php';

if (isset(
$_GET['storytopic'])) {
    
$xoopsOption['storytopic'] = intval($_GET['storytopic']);
} else {
    
$xoopsOption['storytopic'] = 0;
}
if ( isset(
$_GET['storynum']) ) {
    
$xoopsOption['storynum'] = intval($_GET['storynum']);
    if (
$xoopsOption['storynum'] > $xoopsModuleConfig['max_items']) {
        
$xoopsOption['storynum'] = $xoopsModuleConfig['max_items'];
    }
} elseif (
$xoopsOption['storytopic'] > 0) {
    
$xoopsOption['storynum'] = $xoopsModuleConfig['storyhome_topic'];
}
else {
    
$xoopsOption['storynum'] = $xoopsModuleConfig['storyhome'];
}

if ( isset(
$_GET['start']) ) {
    
$start intval($_GET['start']);
} else {
    
$start 0;
}
if (empty(
$xoopsModuleConfig['newsdisplay']) || $xoopsModuleConfig['newsdisplay'] == 'Classic' || $xoopsOption['storytopic'] > 0) {
    
$showclassic 1;
}
else {
    
$showclassic 0;
}

$myts =& MyTextSanitizer::getInstance();
$pagetitle $myts->makeTboxData4Show($xoopsModule->name());
$column_count $xoopsModuleConfig['columnmode'];
if (
$showclassic) {
    
$xoopsOption['template_main'] = 'ams_index.html';
}
else {
     
$xoopsOption['template_main'] = 'ams_by_topic.html';
}
include 
XOOPS_ROOT_PATH.'/header.php';
$xoopsTpl->assign('columnwidth'intval(1/$column_count*100));
if (
$xoopsModuleConfig['displaynav'] == ) {
    
$xoopsTpl->assign('displaynav'true);
    
$xt = new AmsTopic($xoopsDB->prefix('ams_topics'));
    
$allTopics $xt->getAllTopics(true);
    include_once(
XOOPS_ROOT_PATH."/class/tree.php");
    include_once(
XOOPS_ROOT_PATH."/class/xoopsformloader.php");
    
$topic_tree = new XoopsObjectTree($allTopics'topic_id''topic_pid');
    
$topic_select_code $topic_tree->makeSelBox('storytopic''topic_title''-'$xoopsOption['storytopic'], true);
    
$topic_form = new XoopsThemeForm(''"topic_form""index.php""get");
    
$topic_form->addElement(new XoopsFormLabel(''$topic_select_code));
    
// Make number options
    
$i 1;
    while (
$i <= $xoopsModuleConfig['max_items']) {
        
$options[$i] = $i;
        if (
$i == 1) {
            
$i 5;
        }
        else {
            
$i $i 5;
        }
    }
    
$storynum_select = new XoopsFormSelect('''storynum'$xoopsOption['storynum']);
    
$storynum_select->addOptionArray($options);

    
$submit_btn = new XoopsFormButton('''submit'_GO'submit');

    
$topic_form->addElement($storynum_select);
    
$topic_form->addElement($submit_btn);
    
$topic_form->assign($xoopsTpl);
}
else {
    
$xoopsTpl->assign('displaynav'false);
}
if (
$showclassic) {
    
$ihome $xoopsOption['storytopic'] > 0;

    
$sarray AmsStory::getAllPublished($xoopsOption['storynum'], $start$xoopsModuleConfig['restrictindex'], $xoopsOption['storytopic'], $ihome);

    
$scount count($sarray);
    
$xoopsTpl->assign('story_count'$scount);
    if (
$scount 0) {
        
$uids = array();
        foreach (
$sarray as $storyid => $thisstory) {
            
$uids[$thisstory->uid()] = $thisstory->uid();
        }
        
$member_handler =& xoops_gethandler('member');
        
$user_arr $member_handler->getUsers(new Criteria('uid'"(".implode(','array_keys($uids)).")"'IN') , true);
        foreach (
$sarray as $storyid => $thisstory) {
            
$stories[] = $thisstory->toArray(falsefalse0$user_arr);
        }
        
$xoopsTpl->assign('stories'$stories);
    }
    else {
        
$xoopsTpl->assign('stories', array());
    }
    
$xoopsTpl->assign('columns'$column_count);

    
$totalcount AmsStory::countPublishedByTopic($xoopsOption['storytopic'], $xoopsModuleConfig['restrictindex']);
    if ( 
$totalcount $scount ) {
        include_once 
XOOPS_ROOT_PATH.'/class/pagenav.php';
        
$pagenav = new XoopsPageNav($totalcount$xoopsOption['storynum'], $start'start''storytopic='.$xoopsOption['storytopic']);
        
$xoopsTpl->assign('pagenav'$pagenav->renderNav());
    }
    else {
        
$xoopsTpl->assign('pagenav''');
    }

    if(
$xoopsOption['storytopic'] > 0)
    {
        if (!isset(
$xt)) {
            
$xt = new AmsTopic($xoopsDB->prefix('ams_topics'));
        }
        
$xt->getTopic($xoopsOption['storytopic']);
        
$pagetitle .= ' - ' $xt->topic_title();
        
$xoopsTpl->assign('breadcrumb'$xt->getTopicPath());
    }
    else {
        
$xoopsTpl->assign('breadcrumb''');
    }
}
else {
    include_once(
XOOPS_ROOT_PATH."/class/tree.php");
    
$xt = new AmsTopic($xoopsDB -> prefix("ams_topics"));
    
$allTopics $xt->getAllTopics($xoopsModuleConfig['restrictindex']);
    
$topic_obj_tree = new XoopsObjectTree($allTopics'topic_id''topic_pid');
    
$alltopics $topic_obj_tree->getFirstChild(0);
    
    
$article_counts AmsStory::countPublishedOrderedByTopic();
    
    
$smarty_topics = array();
    foreach (
array_keys($alltopics) as $i) {
        
$allstories[$i] = AmsStory::getAllPublished($xoopsOption['storynum'], 0false$i0);
        if (
count($allstories[$i]) > 0) {
            foreach (
$allstories[$i] as $thisstory) {
                
$uids[$thisstory->uid()] = $thisstory->uid();
            }
        }
        if (!isset(
$article_counts[$i])) {
            
$article_counts[$i] = 0;
        }
    }
    if (
count($uids) > 0) {
        
$member_handler =& xoops_gethandler('member');
        
$user_arr $member_handler->getUsers(new Criteria('uid'"(".implode(','array_keys($uids)).")"'IN') , true);
        foreach (
$alltopics as $topicid => $topic) {
            
$topicstories = array();
            foreach (
$allstories[$topicid] as $thisstory) {
                
$topicstories[] = $thisstory->toArray(falsefalse0$user_arr);
            }
            
$subcount 0;
            
$subs = array();
            
//$key = findKey($smarty_topics, $topicstories[0]['posttimestamp']);
            
$subtopics $topic_obj_tree->getFirstChild($topicid);
            
$subcount count($subtopics);
            foreach (
array_keys($subtopics) as $i) {
                
$subs[$i] = array('id' => $i'title' => $subtopics[$i]->topic_title(), 'imageurl' => $subtopics[$i]->topic_imgurl());
            }
            
$smarty_topics[] = array('title' => $topic->topic_title(), 'stories' => $topicstories'id' => $topicid'subtopics' => $subs'articlecount' => $article_counts[$topicid], 'subtopiccount' => $subcount);
            unset(
$subs);
        }
    }
    
//krsort($smarty_topics);
    
$xoopsTpl->assign('topics'$smarty_topics);
    
$xoopsTpl->assign('columns'$column_count);
    
$xoopsTpl->assign('breadcrumb''');
}
if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
    
$showcomments 1;
}
else {
    
$showcomments 0;
}
$xoopsTpl->assign('showcomments'$showcomments);
$xoopsTpl->assign('xoops_pagetitle'$pagetitle);
$xoopsTpl->assign('lang_go'_GO);
$xoopsTpl->assign('lang_on'_ON);
$xoopsTpl->assign('lang_printerpage'_AMS_NW_PRINTERFRIENDLY);
$xoopsTpl->assign('lang_sendstory'_AMS_NW_SENDSTORY);
$xoopsTpl->assign('lang_postedby'_POSTEDBY);
$xoopsTpl->assign('lang_reads'_READS);
$xoopsTpl->assign('lang_morereleases'_AMS_NW_MORERELEASES);
if (
$xoopsOption['storytopic'] > 0) {
    
$topic = new AmsTopic($xoopsDB->prefix('ams_topics'), $xoopsOption['storytopic']);
    
$xoopsTpl->assign('topicbanner'$myts->displayTarea($topic->getBanner(), 1));
}
include_once 
XOOPS_ROOT_PATH.'/footer.php';


function 
findKey($array$suggested_key) {
    if (isset(
$array[$suggested_key])) {
        return 
findKey($array$suggested_key +);
    }
    return 
$suggested_key;
}
?>

Login

Who's Online

149 user(s) are online (104 user(s) are browsing Support Forums)


Members: 0


Guests: 149


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