test
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • syntom Friend
    #184775

    Hi,

    i like to restrict the introtext. I use the field in k2 kategorie, but in the homepage are many categorys. And the introtext is not to restrict.

    My idea is to rextrict the fild introtext with maxlength. I search in itemform, but i cant find the form for introtext.

    Is there a chance to restrict it?

    THX:-[

    Wall Crasher Developer
    #482860

    Hi syntom,

    You can limit the intro text by using this modify function templatesja_walltemplate_tools.php

    This will work with JA Wall 1.0.7.

    public static function extractFirstParagraph($text, $limit = 50){
    static $regex = '#<p[^>]*>(.*)</p>#i';
    static $allowtag = '<a><b><strong><br>';

    $result = '';
    if (preg_match_all ($regex, $text, $matches)) {
    $p = array();
    $c = 0;
    $cl = 50;

    if($limit > 0){
    $cl = $limit;
    }

    foreach ($matches[1] as $match) {
    $t = trim(strip_tags ($match, $allowtag));
    if ($t){
    $l = strlen($t);
    if ($limit > 0 && $c + $l >= $cl){
    $w = JString::strpos($t, ' ', $cl - $c);
    if($w === false){
    $w = $cl - $c;
    }

    $t = JString::substr($t, 0, $w) . ($cl - $c < $l ? '...' : '');
    $l = $cl - $c;
    }

    $p[] = $t;

    $c += $l;
    if($c >= $cl){
    break;
    }
    }
    }
    $t = implode ('<br/>', $p);

    $result = (strlen($t) > 7) ? $t : trim(strip_tags ($text, $allowtag));
    } else {
    $result = trim(strip_tags ($text, $allowtag));
    }

    return $result;
    }

    <blockquote>$limit = 50</blockquote>
    Please change this number in the function for the maxlength of intro text show in wall block.

    Regards

    sokakis Friend
    #483484

    [PHP]<?php
    /**
    * ————————————————————————
    * JA Wall Template for Joomla25
    * ————————————————————————
    * Copyright (C) 2004-2011 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
    * @license – Copyrighted Commercial Software
    * Author: J.O.O.M Solutions Co., Ltd
    * Websites: http://www.joomlart.comhttp://www.joomlancers.com
    * This file may not be redistributed in whole or significant part.
    * ————————————————————————
    */

    // no direct access
    defined(‘_JEXEC’) or die(‘Restricted access’);

    // sidebar module position
    define(‘_SIDE_BAR_POS’, ‘sidebar’);
    define(‘_CORNER_STAMP_POS’, ‘corner-stamp’);

    // aside module position
    define(‘_ASIDE_POS_1’, ‘aside-1’);
    define(‘_ASIDE_POS_2’, ‘aside-2’);
    define(‘_ASIDE_POS_3’, ‘aside-3’);

    class WallHelper {

    public static function getBodyClass () {
    $app = JFactory::getApplication();
    $menus = $app->getMenu();
    $tmpl = JFactory::getDocument();
    $cls = ”;
    // check if home
    if (($menu = $menus->getActive())) {
    if ($menu->home) {
    $cls .= ‘ bd-home’;
    }
    }
    // check view
    if (self::isGridView()) {
    $cls .= ‘ gridview hoverable’;
    }

    // check has sidebar
    if (self::hasSidebar()) {
    $cls .= ‘ has-sidebar’;
    }
    // check has aside
    if (self::hasAside()) {
    $cls .= ‘ has-aside’;
    }

    if (JRequest::getCmd(‘option’) == ‘com_k2’) {
    $cls .= ‘ k2-component’;
    }

    // check extended parameter in menu item
    if (($menu && $menu->params->get (‘jawall_preview’) == ‘no’) ||
    ($menu && !$menu->params->get (‘jawall_preview’) &&
    $tmpl->params->get(‘jawall_preview’) == ‘no’) ||
    (!$menu && $tmpl->params->get(‘jawall_preview’) == ‘no’)) {
    $cls .= ‘ no-preview’;
    }

    if ($menu && $menu->params->get (‘jawall_basegrid’)) {
    $cls .= ‘ fixed-basegrid basegrid-‘.$menu->params->get (‘jawall_basegrid’);
    }
    if ($menu && $menu->params->get (‘jawall_display’)) {
    $cls .= ‘ fixed-display display-‘.$menu->params->get (‘jawall_display’);
    }
    return trim($cls);
    }

    /**
    * Check if show sidebar
    * sidebar is available when
    * – has modules in _SIDE_BAR_POS position
    */
    public static function hasSidebar(){
    $tmpl = JFactory::getDocument();
    if (!$tmpl->countModules(_SIDE_BAR_POS)) {
    return false;
    }
    return true;
    }

    /**
    * Check if show aside modules
    * aside is available when
    * – not in grid-view
    * – has modules in _ASIDE_POS position
    */
    public static function hasAside(){
    if (self::isGridView()){
    return false;
    }

    $tmpl = JFactory::getDocument();
    if (!$tmpl->countModules(_ASIDE_POS_1) && !$tmpl->countModules(_ASIDE_POS_2) && !$tmpl->countModules(_ASIDE_POS_3)) {
    return false;
    }
    return true;
    }

    public static function isGridView(){
    // check if defined in component
    if (defined(‘_IS_GRID_VIEW’)){
    return true;
    }

    // if this content is cache, we check if there a div with id=masonry-container
    $tmpl = JFactory::getDocument();
    $component_content = $tmpl->getBuffer(‘component’);
    if (preg_match (‘#ids*=s*([“‘]?)masonry-container1#i’, $component_content)){
    return true;
    }

    return false;
    }

    public static function genCSPosition(){
    $document = JFactory::getDocument();
    $renderer = $document->loadRenderer(‘module’);
    $modules = JModuleHelper::getModules(_CORNER_STAMP_POS);
    $params = array(‘style’ => ‘JAxhtml’);
    $csexclass = JFactory::getApplication()->getTemplate(true)->params->get(‘jawall_cs_class’, ”);

    if(count($modules)) {
    echo
    ‘<div class=”corner-stamp’, (!empty($csexclass) ? ‘ ‘ . $csexclass : ”), ‘”>’,
    ‘<div class=”corner-inner”>’;

    foreach ($modules as $module) {
    echo $renderer->render($module, $params);
    }

    echo
    ‘</div>’,
    ‘</div>’;
    }
    }

    /**
    * get some first paragraph in introtext, trip tags (keep a, strong, br, b…)
    */
    public static function extractFirstParagraph($text, $limit = 50){
    static $regex = ‘#<p[^>]*>(.*)</p>#i’;
    static $allowtag = ‘<a><b><strong><br>’;

    $result = ”;
    if (preg_match_all ($regex, $text, $matches)) {
    $p = array();
    $c = 0;
    $cl = 50;

    if($limit > 0){
    $cl = $limit;
    }

    foreach ($matches[1] as $match) {
    $t = trim(strip_tags ($match, $allowtag));
    if ($t){
    $l = strlen($t);
    if ($limit > 0 && $c + $l >= $cl){
    $w = JString::strpos($t, ‘ ‘, $cl – $c);
    if($w === false){
    $w = $cl – $c;
    }

    $t = JString::substr($t, 0, $w) . ($cl – $c < $l ? ‘…’ : ”);
    $l = $cl – $c;
    }

    $p[] = $t;

    $c += $l;
    if($c >= $cl){
    break;
    }
    }
    }
    $t = implode (‘<br/>’, $p);

    $result = (strlen($t) > 7) ? $t : trim(strip_tags ($text, $allowtag));
    } else {
    $result = trim(strip_tags ($text, $allowtag));
    }

    return $result;
    }

    // build intro images
    // if intro images exists in $images, use it
    // if not, get images from intro content
    // if not, get from full image in $images
    public static function buildImage(&$images, $item){
    static $regex1 = ‘#(<img[^>]*>)#i’;
    static $regex2 = ‘#s+srcs*=s*([“‘])([^'”]+)1#i’;
    static $regex3 = ‘#salts*=s*([“‘])([^'”]+)1#i’;

    if (empty($images->image_intro)) {
    if (preg_match ($regex1, $item->introtext, $match)) {
    $image = $match[1];
    // get img src
    if (preg_match ($regex2, $image, $match)) {
    $images->image_intro = $match[2];
    }
    // get img caption
    $item->image_caption = ”;
    if (preg_match ($regex3, $image, $match)) {
    $images->image_intro_alt = $images->image_intro_caption = $match[2];
    } else {
    $images->image_intro_alt = $images->image_intro_caption = ”;
    }
    }
    }

    return $images;
    }

    public static function getExClass($k2item) {
    static $xclass_key = ‘Extended Classes’;

    $xclass = ”;
    $extra_fields = array();
    if(is_string($k2item->extra_fields)){
    $extra_fields = K2Model::getInstance(‘Item’, ‘K2Model’)->getItemExtraFields($k2item->extra_fields, $k2item);
    }
    if(count($extra_fields)) {
    foreach ($extra_fields as $key=>$extraField) {
    if ($extraField->name == $xclass_key) {
    $xclass = $extraField->value;
    break;
    }
    }
    }

    return $xclass;
    }

    // build intro images
    // if intro images exists in $images, use it
    // if not, get images from intro content
    // if not, get from full image in $images
    public static function buildK2Image(&$item){
    static $regex1 = ‘#(<img[^>]*>)#i’;
    static $regex2 = ‘#s+srcs*=s*([“‘])([^'”]+)1#i’;
    static $regex3 = ‘#salts*=s*([“‘])([^'”]+)1#i’;

    if (empty($item->image)) {
    if (preg_match ($regex1, $item->introtext, $match)) {
    $image = $match[1];

    // get img src
    if (preg_match ($regex2, $image, $match)) {
    $item->image = $match[2];
    }

    // get img caption
    $item->image_caption = ”;
    if (preg_match ($regex3, $image, $match)) {
    $item->image_caption = $match[2];
    }
    }
    }

    return $item;
    }
    }[/PHP]

    not working :/

    Wall Crasher Developer
    #483531

    Hi sokakis,

    I have copied your code to my local JA Wall site and it is working,

    Please see my attached file with those intro text and three dot (…)

    Regards


    1. Untitled
    sokakis Friend
    #484194

    to me not working Joomla 2.5 – k2 2.6.5 – ja-wall 1.0.7

    Wall Crasher Developer
    #484204

    Hi sokakis,

    Please make sure you clear the system cache and browser cache.
    You can also pm the information (url/admin) of your site for me to check.

    Regards

    sokakis Friend
    #484265

    <em>@Wall Crasher 361264 wrote:</em><blockquote>Hi sokakis,

    Please make sure you clear the system cache and browser cache.
    You can also pm the information (url/admin) of your site for me to check.

    Regards</blockquote>

    check pm for admin/ftp

    sokakis Friend
    #484315

    Ok i fixed it from k2 source. What you suggested didn’t work because i used an other editor with clean code on.
    For those who want to use it change from ja_wall/html/k2/ja_wall/category_item.php.
    find (line 163)
    [PHP]<?php if($this->item->params->get(‘catItemIntroText’)): ?>
    <?php echo $introtext; ?>
    <?php endif; ?>[/PHP]

    change to
    [PHP]<?php if($this->item->params->get(‘catItemIntroText’)): ?>
    <?php echo K2HelperUtilities::wordLimit($this->item->introtext, 50); ?>
    <?php endif; ?>[/PHP]

    Wall Crasher Developer
    #484343

    Hi sokakis,

    It is good that you happy with your solutions.
    For $introtext variable, we have extract the intro text with pure text in there.
    The $this->item->introtext may contains some tag which may load and cause unexpected result. (though it is rarely :laugh:)

    Regards

    sokakis Friend
    #484376

    <em>@Wall Crasher 361539 wrote:</em><blockquote>Hi sokakis,

    It is good that you happy with your solutions.
    For $introtext variable, we have extract the intro text with pure text in there.
    The $this->item->introtext may contains some tag which may load and cause unexpected result. (though it is rarely :laugh:)

    Regards</blockquote>

    Your way is better but not working with jck editor… work only with tinyMCE (tested)

    Wall Crasher Developer
    #484528

    Hi,

    You just need to add ‘s’ in the regular expression.

    Here the modify if you like my solution.

    static $regex = '#<p[^>]*>(.*)</p>#is';

    Regards

    sokakis Friend
    #484643

    thanks, it works fine! 🙂 wall for joomla 3.0 when will it be released?

    Wall Crasher Developer
    #484663

    Hi sokakis,

    If all goes well, it would be released in the next 1-2 weeks.

    Regards

    syntom Friend
    #485578

    It works. THX

Viewing 14 posts - 1 through 14 (of 14 total)

This topic contains 14 replies, has 3 voices, and was last updated by  syntom 11 years, 8 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum