From 678f3805840fcc7b1fe89be5c4792574366ecedf Mon Sep 17 00:00:00 2001 From: Magnus Arebalus <26823544+arebalus@users.noreply.github.com> Date: Sat, 31 Mar 2018 11:16:26 -0600 Subject: [PATCH] 1.3 version changes --- docs/index.html | 93 ++- helpers/helper.php | 662 +++++++++--------- injector_related.php | 75 +- injector_related.xml | 157 ++++- .../en-GB.plg_content_injector_related.ini | 28 +- .../es-ES.plg_content_injector_related.ini | 26 +- media/css/backend.css | 3 + media/js/backend.js | 46 ++ tmpl/bootstrap-table.php | 6 +- tmpl/default.php | 6 +- tmpl/slick-carousel.php | 40 +- tmpl/with-image.php | 38 +- version.xml | 6 +- 13 files changed, 806 insertions(+), 380 deletions(-) create mode 100644 media/css/backend.css create mode 100644 media/js/backend.js diff --git a/docs/index.html b/docs/index.html index 1fd5a88..9b1377a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,7 +4,7 @@ - Injector Related - Documentation + Injector Related 1.3 - Documentation
@@ -58,9 +58,8 @@

Placement Params

  • Use "Division" if most of your content articles use <div>...</div> to organize their content blocks. If you use nested divisions, like in the case of bootstrap, which uses them to generate a grid, then you should want to set the Class parameter.
  • -
  • Only at Root Level: It's advised to keep this param set to Yes, thus only tags at the root level are taken in account for the collocation of the related articles. Otherwise (setting this to No) will cause that every HTML tag is included in the calculations. For example, this may cause unexpected behavior if you have paragraphs in tables. However you might want to enable set this parameter to No in case of divisions with an specific class. -
  • Class: Since the divisions <div>...</div> can be nested within the HTML code, then it could be helpful to count only certain ones. So you can set the class of the divisions that will be counted to determine the right placement of the plugin result.
  • +
  • Only at Root Level: It's advised to keep this param set to Yes, thus only tags at the root level are taken in account for the collocation of the related articles. Otherwise (setting this to No) will cause that every HTML tag is included in the calculations. For example, this may cause unexpected behavior if you have paragraphs in tables. However you might want to enable set this parameter to No in case of divisions with an specific class.
  • Location: Set where in the content article text will be placed the plugin result. You can select "Top of Article", "Bottom of Article" or "Middle of Article". Regarding "Middle of Article", you may use the "Position" paramenter in order to set more specifically the point of the article text to place the plugin result.
  • Position: If the Location parameter is set to Middle, then you may want to fine-tune where in the middle of the content is placed the related articles list. Notice that Injector Related counts the number of HTML tags regardless of the ammount of text they may contain. @@ -77,14 +76,39 @@

    Layout Params

  • Layout: Change the appearance of the plugin output choosing one of the available layouts.
  • Max. Items in Slide: The number of content articles to be shown at once in a slider. Notice that the slider is responsive and automatically will reduce the number of shown articles at once, depending on the available width to display this content. Useful with slick-carousel.php ONLY.
  • Default Image: Sets a default image to use in case there are not any image set as Intro Image or Full Text Image of from within the article body. Useful with with-image.php and slick-carousel.php ONLY.
  • -
  • Image Height: Set the image height in pixels (only the integer value). Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Image Height: Set the image height in pixels (only the integer value). Setting this parameter to 0 (zero) will hide the image. Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Linked Image: Useful with with-image.php and slick-carousel.php ONLY. + +
  • +
  • Title Color: Set the color (in Hex format) for title section, regardless if it is linked or not. Set this to empty to use the website default style. Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Uppercase Title: Useful with with-image.php and slick-carousel.php ONLY. + +
  • Single Line Title: Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Linked Title: Useful with with-image.php and slick-carousel.php ONLY. + +
  • +
  • Title Font Size: Set the title font size in pixels (only the integer value). Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Title Margin Up: Set the space above the title text in pixels (only the integer value). Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Title Margin Down: Set the space below the title text in pixels (only the integer value). Useful with with-image.php and slick-carousel.php ONLY.
  • Text Length: Set the maximum number of characters to display of the article's body. If you count the character it may not be exactly the fixed number, because only whole words will be included. Please notice that setting this parameter to 0 (zero) will hide the body text. Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Text Color: Set the color (in Hex format) for text section. Set this to empty to use the website default style. Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Text Font Size: Set the text font size in pixels (only the integer value). Useful with with-image.php and slick-carousel.php ONLY.
  • +
  • Text Margin Bottom: Set the space below the related article body text in pixels (only the integer value). Useful with slick-carousel.php ONLY.

  • :mag: Back to Index

    Override Configuration

    @@ -109,8 +133,8 @@

    Attributes Table

    General Params - Param - Attribute + Param + Attribute Valid values @@ -136,12 +160,12 @@

    Attributes Table

    3rd Relation relation3 - non - None (disabled)
    key - By Keywords
    tag - By Tags
    cat - By Category
    aut - By Author
    + non - None (disabled)
    key - By Keywords
    tag - By Tags
    cat - By Category
    aut - By Author
    4th Relation relation4 - non - None (disabled)
    key - By Keywords
    tag - By Tags
    cat - By Category
    aut - By Author
    + non - None (disabled)
    key - By Keywords
    tag - By Tags
    cat - By Category
    aut - By Author
    Placement Params @@ -212,13 +236,49 @@

    Attributes Table

    Image Height image-height - Any positive integer + Any positive integer or
    + 0 (zero) to disable this feature + + + Linked Image + linked-image + 0 (zero) for No
    1 (one) for Yes + + + Title Color + color-title + Any color in hex format like #777777 (don't omit the # symbol). + + + Uppercase Title + uppercase-title + 0 (zero) for No
    1 (one) for Yes Single Line Title single-line-title 0 (zero) for No
    1 (one) for Yes + + Linked Title + linked-title + 0 (zero) for No
    1 (one) for Yes + + + Title Font Size + font-size-title + Any integer between 5 and 50 + + + Title Margin Up + margin-up-title + Any integer between 1 and 50 + + + Title Margin Down + margin-down-title + Any integer between 1 and 50 + Text Length text-length @@ -226,6 +286,21 @@

    Attributes Table

    0 (zero) to disable this feature + + Text Color + text-color + Any color in hex format like #777777 (don't omit the # symbol) + + + Text Font Size + text-font-size + Any integer between 5 and 50 + + + Text Margin Bottom + margin-bottom-text + Any integer between 1 and 50 +


    :mag: Back to Index

    Override Design

    diff --git a/helpers/helper.php b/helpers/helper.php index e6e8ab6..5eefe3f 100644 --- a/helpers/helper.php +++ b/helpers/helper.php @@ -1,6 +1,6 @@ id) return $return; - - if ($relation == 1 || (isset($config['relation'.$relation]) && $config['relation'.$relation] != 'non')) - { - $doQuery= true; - $db = JFactory::getDbo(); - $query = $db->getQuery(true); - switch($config['relation'.$relation]) - { - - case 'tag': - $query ->select($db->quoteName('tag_id')) - ->from($db->quoteName('#__contentitem_tag_map')) - ->where($db->quoteName('content_item_id').'='.$article->id) - ->where($db->quoteName('type_alias').'='.$db->quote('com_content.article')) - ; - $db ->setQuery($query); - $tags = $db->loadColumn(); - - $query ->clear(); - if (is_array($tags) && count($tags)) - { - $query ->join('', - $db->quoteName('#__contentitem_tag_map','tm') - .'ON ' - .$db->quoteName('tm.content_item_id') - .' = ' - .$db->quoteName('c.id') - ) - ->where($db->quoteName('tm.tag_id').' IN ('.implode(',',$tags).')') - ->group($db->quoteName('c.id')); - ; - } - else - { - $doQuery = false; - } - break; - case 'cat': - $query ->where($db->quoteName('c.catid').'='.$article->catid); - break; - case 'aut': - $query ->where($db->quoteName('c.created_by').'='.$article->created_by); - break; - case 'key': - $kwds = explode(',',$article->metakey); - for($i=0,$n=count($kwds);$i<$n;$i++) - { - $kwds[$i] = trim($kwds[$i]); - if (strlen($kwds[$i])) - { - $kwds[$i] = $db->quoteName('c.metakey').' LIKE '.$db->quote('%'.$kwds[$i].'%'); - } - else - { - unset($kwds[$i]); - } - } - if (count($kwds)) - { - $query->where('('.implode(' OR ',$kwds).')'); - } - else - { - $doQuery = false; - } - default: - break; - } - if ($doQuery) - { - $now = $query->currentTimestamp(); - $null = $query->nullDate(); - $query ->select( - $db->quoteName('c.id','id') - .','.$db->quoteName('c.title','title') - .','.$db->quoteName('c.introtext','introtext') - .','.$db->quoteName('c.catid','catid') - .','.$db->quoteName('c.images','images') - .','.$db->quoteName('c.introtext','introtext') - .','.$db->quoteName('c.fulltext','fulltext') - ) - ->from ($db->quoteName('#__content','c')) - ->where($db->quoteName('c.id').'<>'.$article->id) - ->where($db->quoteName('c.state').'=1') - ->where('('.$db->quoteName('c.publish_up').' < '.$now.' OR '.$db->quoteName('c.publish_up').'='.$null.')' ) - ->where('('.$db->quoteName('c.publish_down').' > '.$now.' OR '.$db->quoteName('c.publish_down').'='.$null.')' ) - ->setLimit(intval($number)) - ; - if (is_array($already) && count ($already)) - { - $query ->where($db->quoteName('c.id').' NOT IN ('.implode(',',$already).')'); - } - # To-Do: Add more sorting options - $query ->order($db->quoteName('c.publish_up').' DESC'); - $db->setQuery($query); - $rows = $db->loadObjectList(); - } - - $selIds = array(); - - //die (JPATH_ROOT); - if (is_array($rows)) - { - for ($i=0,$n=count($rows);$i<$n;$i++) - { - $selIds[] = $rows[$i]->id; - $images = (array)json_decode($rows[$i]->images); - if ( - isset($images['image_intro']) - && strlen($images['image_intro']) - //&& file_exists(JPATH_ROOT.'/'.$images['image_intro']) - ) - { - $rows[$i]->image = $images['image_intro']; - } - elseif ( - isset($images['image_fulltext']) - && strlen($images['image_fulltext']) - //&& file_exists(JPATH_ROOT.'/'.$images['image_fulltext']) - ) - { - $rows[$i]->image = $images['image_fulltext']; - } - else - { - $txt = $rows[$i]->introtext.$rows[$i]->fulltext; - $ptrn = '/]+)(?:\'|")/si'; - if (preg_match($ptrn,$txt,$imgMatch)) - { - $rows[$i]->image = html_entity_decode($imgMatch[1]); - } - else - { - $rows[$i]->image = $config['default-image']; - } - - } - } - $already = array_merge($already,$selIds); - if (count($rows) < $number && $relation < 4) - { - $rows = array_merge($rows,self::_getRelatedList($article,$config,$relation+1,$number-count($rows),$already)); - } - $return = $rows; - } - - } - return $return; - } - + public static function cleanText($text,$lenght) + { + # Remove plugins syntax + if (preg_match_all('/\{[^\}]{1,}\}/si',$text,$MATCHES)) + { + if (isset($MATCHES[0]) && is_array($MATCHES[0]) && count($MATCHES[0])) + { + foreach($MATCHES[0] as $match) + { + $text = str_replace($match,'',$text); + } + } + } + + # Remove HTML tags + $text = strip_tags($text); + + # Convert HTML Entities + $text = html_entity_decode($text,ENT_NOQUOTES,'UTF-8'); + + # Remove format characters + $text = str_replace(array("\r","\n","\t",' '),' ',$text); + + # Remove doble spaces + while (strpos($text,' ') !== false) + { + $text = str_replace(' ',' ',$text); + } + + # Build the return without truncate words + $words = explode(' ',$text); + $return = ''; + if (is_array($words) && count($words)) + { + $return = $words[0]; + $i=0; + while(strlen($return.' '.$words[$i+1])<$lenght) + { + $return .= ' '.$words[$i+1]; + $i++; + } + if ($i < count($words)) + { + $return .= ' …'; + } + } + return $return; + } + private static function _injector(&$article,$config,$text) { switch($config['location']) @@ -335,33 +228,129 @@ private static function _injector(&$article,$config,$text) break; } } - - - private static function _validateConfig($config) + + private static function _getGlobalConfig(&$params) { - $valid = array(); - foreach($config as $k=>$v) + static $config = null; + + if (is_null($config)) { - switch ($k) + $config = array(); + + # Basic params + $config['enable'] = $params->get('enable','1'); + $config['number'] = $params->get('number','3'); + $config['relation1'] = $params->get('relation1','key'); + $config['relation2'] = $params->get('relation2','non'); + $config['relation3'] = $params->get('relation3','non'); + $config['relation4'] = $params->get('relation4','non'); + + # Where params + $config['filter'] = $params->get('filter','exc'); + $config['categories'] = $params->get('categories',''); + $config['mode'] = $params->get('mode','p'); + $config['class'] = $params->get('class',''); + $config['only-root'] = $params->get('only-root',1); + $config['location'] = $params->get('location','mid'); + $config['position'] = $params->get('position','center'); + + # Layout params + $config['layout'] = $params->get('layout','default.php'); + $config['max-items-in-slide'] = $params->get('max-items-in-slide','4'); + $config['default-image'] = $params->get('default-image','media/plg_content_injector_related/default.jpg'); + $config['image-height'] = $params->get('image-height','120'); + $config['linked-image'] = $params->get('linked-image','1'); + $config['uppercase-title'] = $params->get('uppercase-title','1'); + $config['font-size-title'] = $params->get('font-size-title','11'); + $config['single-line-title'] = $params->get('single-line-title','1'); + $config['margin-up-title'] = $params->get('margin-up-title','10'); + $config['margin-down-title'] = $params->get('margin-down-title','10'); + $config['linked-title'] = $params->get('linked-title','1'); + $config['text-length'] = $params->get('text-length','200'); + $config['text-color'] = $params->get('text-color',''); + $config['color-title'] = $params->get('color-title',''); + $config['text-font-size'] = $params->get('text-font-size','11'); + $config['margin-bottom-text'] = $params->get('margin-bottom-text','10'); + + $config = self::_validateConfig($config); + } + return $config; + } + + private static function _getInlineConfig(&$article) + { + // TO-DO: Make parser stronger by now must avoid spaces between pairs valuss. + // key=val Will work + // key = val Will NOT work + $config = array('string'=>'','params'=>array()); + + # strpos is faster than preg_match, so we'll avoid unless it's necessary + if (strpos($article->text,'{injector_related ') !== false) + { + if (preg_match('/\{injector_related([^\}]{1,})\}/si',$article->text,$MATCHES)) { - case 'enable': - case 'only-root': - case 'single-line-title': - $valid[$k] = ($v == '0') ? '0' : '1'; - break; - case 'number': - $v = intval($v); - $valid['number'] = ($v >= 1 && $v <= 15) ? $v : 3; - break; - case 'relation1': - $valid['relation1'] = in_array($v,array('key','tag','cat','aut')) ? $v : 'key'; - break; - case 'relation2': - case 'relation3': - case 'relation4': - $valid[$k] = in_array($v,array('non','key','tag','cat','aut')) ? $v : 'non'; - break; - case 'filter': + $config['string'] = $MATCHES[0]; + $pairs = explode(' ',$MATCHES[1]); + $params = array(); + foreach($pairs as $pair) + { + if (strpos($pair,'=')) + { + list($key,$val) = explode('=',$pair); + $key = trim($key); + $val = trim($val); + if (strlen($key) && strlen($val)) + { + $params[$key] = $val; + } + } + } + if (count($params)) + { + $params['filter'] = 'inc'; + $params['categories'] = $article->catid; + if (!isset($params['enable'])) + { + $params['enable']='1'; + } + $config['params'] = $params; + } + $article->text = str_replace($MATCHES[0],'',$article->text); + $article->introtext = str_replace($MATCHES[0],'',$article->introtext); + $article->fulltext = str_replace($MATCHES[0],'',$article->fulltext); + } + } + return $config; + } + + private static function _validateConfig($config) + { + $valid = array(); + foreach($config as $k=>$v) + { + switch ($k) + { + case 'enable': + case 'only-root': + case 'single-line-title': + case 'uppercase-title': + case 'linked-image': + case 'linked-title': + $valid[$k] = ($v == '0') ? '0' : '1'; + break; + case 'number': + $v = intval($v); + $valid['number'] = ($v >= 1 && $v <= 15) ? $v : 3; + break; + case 'relation1': + $valid['relation1'] = in_array($v,array('key','tag','cat','aut')) ? $v : 'key'; + break; + case 'relation2': + case 'relation3': + case 'relation4': + $valid[$k] = in_array($v,array('non','key','tag','cat','aut')) ? $v : 'non'; + break; + case 'filter': $valid['filter'] = in_array($v,array('inc','exc')) ? $v : 'exc'; break; case 'mode': @@ -415,21 +404,35 @@ private static function _validateConfig($config) && file_exists(JPATH_ROOT.'/'.$v) ) { - $valid['default-image'] = JUri::base(false).'/'.$v; + $valid['default-image'] = rtrim(JUri::base(false),'/').'/'.ltrim($v,'/'); } else { - $valid['default-image'] = JUri::base(false).'/media/plg_content_injector_related/default.jpg'; + $valid['default-image'] = rtrim(JUri::base(false),'/').'/media/plg_content_injector_related/default.jpg'; } break; case 'image-height': $v = intval($v); - $valid[$k] = $v > 0 ? $v : 120; + $valid[$k] = $v >= 0 ? $v : 120; break; case 'text-length': $v = intval($v); $valid[$k] = $v >= 0 ? $v : 200; break; + case 'font-size-title': + case 'text-font-size': + $v = intval($v); + $valid[$k] = $v >= 5 && $v <= 50 ? $v : 11; + break; + case 'margin-up-title': + case 'margin-down-title': + case 'margin-bottom-text': + $v = intval($v); + $valid[$k] = $v >= 1 && $v <= 50 ? $v : 10; + break; + case 'text-color': + case 'color-title': + $valid[$k] = (!strlen($v) || preg_match('/^#(?:[0-9a-fA-F]{3}){1,2}$/',$v))? $v : ''; default: # None other parameter is accepted. break; @@ -438,141 +441,158 @@ private static function _validateConfig($config) return $valid; } - - private static function _getInlineConfig(&$article) - { - // TO-DO: Make parser stronger by now must avoid spaces between pairs valuss. - // key=val Will work - // key = val Will NOT work - $config = array('string'=>'','params'=>array()); + private static function _getRelatedList(&$article,$config,$relation=1,$number=3,$already=array()) + { + $return = array(); + $rows = array(); - # strpos is faster than preg_match, so we'll avoid unless it's necessary - if (strpos($article->text,'{injector_related ') !== false) - { - - if (preg_match('/\{injector_related([^\}]{1,})\}/si',$article->text,$MATCHES)) - { - $config['string'] = $MATCHES[0]; - $pairs = explode(' ',$MATCHES[1]); - $params = array(); - foreach($pairs as $pair) - { - if (strpos($pair,'=')) - { - list($key,$val) = explode('=',$pair); - $key = trim($key); - $val = trim($val); - if (strlen($key) && strlen($val)) - { - $params[$key] = $val; - } - } - } - if (count($params)) - { - $params['filter'] = 'inc'; - $params['categories'] = $article->catid; - if (!isset($params['enable'])) - { - $params['enable']='1'; - } - $config['params'] = $params; - } - $article->text = str_replace($MATCHES[0],'',$article->text); - $article->introtext = str_replace($MATCHES[0],'',$article->introtext); - $article->fulltext = str_replace($MATCHES[0],'',$article->fulltext); - - } - } - return $config; - } - - public static function cleanText($text,$lenght) - { - # Remove plugins syntax - if (preg_match_all('/\{[^\}]{1,}\}/si',$text,$MATCHES)) - { - if (isset($MATCHES[0]) && is_array($MATCHES[0]) && count($MATCHES[0])) - { - foreach($MATCHES[0] as $match) - { - $text = str_replace($match,'',$text); - } - } - } - - # Remove HTML tags - $text = strip_tags($text); - - # Convert HTML Entities - $text = html_entity_decode($text,ENT_NOQUOTES,'UTF-8'); - - # Remove format characters - $text = str_replace(array("\r","\n","\t",' '),' ',$text); - - # Remove doble spaces - while (strpos($text,' ') !== false) - { - $text = str_replace(' ',' ',$text); - } - - # Build the return without truncate words - $words = explode(' ',$text); - $return = ''; - if (is_array($words) && count($words)) - { - $return = $words[0]; - $i=0; - while(strlen($return.' '.$words[$i+1])<$lenght) - { - $return .= ' '.$words[$i+1]; - $i++; - } - if ($i < count($words)) - { - $return .= ' …'; - } - } - return $return; - } - - private static function _getGlobalConfig(&$params) - { - static $config = null; - - if (is_null($config)) - { - $config = array(); - - # Basic params - $config['enable'] = $params->get('enable','1'); - $config['number'] = $params->get('number','3'); - $config['relation1'] = $params->get('relation1','key'); - $config['relation2'] = $params->get('relation2','non'); - $config['relation3'] = $params->get('relation3','non'); - $config['relation4'] = $params->get('relation4','non'); - - # Where params - $config['filter'] = $params->get('filter','exc'); - $config['categories'] = $params->get('categories',''); - $config['mode'] = $params->get('mode','p'); - $config['class'] = $params->get('class',''); - $config['only-root'] = $params->get('only-root',1); - $config['location'] = $params->get('location','mid'); - $config['position'] = $params->get('position','center'); - - # Layout params - $config['layout'] = $params->get('layout','default.php'); - $config['max-items-in-slide'] = $params->get('max-items-in-slide','4'); - $config['default-image'] = $params->get('default-image','media/plg_content_injector_related/default.jpg'); - $config['image-height'] = $params->get('image-height','120'); - $config['single-line-title'] = $params->get('single-line-title','1'); - $config['text-length'] = $params->get('text-length','200'); - - $config = self::_validateConfig($config); - } - return $config; - } - -} - + if (!$article->id) return $return; + + if ($relation == 1 || (isset($config['relation'.$relation]) && $config['relation'.$relation] != 'non')) + { + $doQuery= true; + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + switch($config['relation'.$relation]) + { + + case 'tag': + $query ->select($db->quoteName('tag_id')) + ->from($db->quoteName('#__contentitem_tag_map')) + ->where($db->quoteName('content_item_id').'='.$article->id) + ->where($db->quoteName('type_alias').'='.$db->quote('com_content.article')) + ; + $db ->setQuery($query); + $tags = $db->loadColumn(); + + $query ->clear(); + if (is_array($tags) && count($tags)) + { + $query ->join('', + $db->quoteName('#__contentitem_tag_map','tm') + .'ON ' + .$db->quoteName('tm.content_item_id') + .' = ' + .$db->quoteName('c.id') + ) + ->where($db->quoteName('tm.tag_id').' IN ('.implode(',',$tags).')') + ->group($db->quoteName('c.id')); + ; + } + else + { + $doQuery = false; + } + break; + case 'cat': + $query ->where($db->quoteName('c.catid').'='.$article->catid); + break; + case 'aut': + $query ->where($db->quoteName('c.created_by').'='.$article->created_by); + break; + case 'key': + $kwds = explode(',',$article->metakey); + for($i=0,$n=count($kwds);$i<$n;$i++) + { + $kwds[$i] = trim($kwds[$i]); + if (strlen($kwds[$i])) + { + $kwds[$i] = $db->quoteName('c.metakey').' LIKE '.$db->quote('%'.$kwds[$i].'%'); + } + else + { + unset($kwds[$i]); + } + } + if (count($kwds)) + { + $query->where('('.implode(' OR ',$kwds).')'); + } + else + { + $doQuery = false; + } + default: + break; + } + if ($doQuery) + { + $now = $query->currentTimestamp(); + $null = $query->nullDate(); + $query ->select( + $db->quoteName('c.id','id') + .','.$db->quoteName('c.title','title') + .','.$db->quoteName('c.catid','catid') + .','.$db->quoteName('c.images','images') + .','.$db->quoteName('c.introtext','introtext') + .','.$db->quoteName('c.fulltext','fulltext') + ) + ->from ($db->quoteName('#__content','c')) + ->where($db->quoteName('c.id').'<>'.$article->id) + ->where($db->quoteName('c.state').'=1') + ->where('('.$db->quoteName('c.publish_up').' < '.$now.' OR '.$db->quoteName('c.publish_up').'='.$null.')' ) + ->where('('.$db->quoteName('c.publish_down').' > '.$now.' OR '.$db->quoteName('c.publish_down').'='.$null.')' ) + ->setLimit(intval($number)) + ; + if (is_array($already) && count ($already)) + { + $query ->where($db->quoteName('c.id').' NOT IN ('.implode(',',$already).')'); + } + # To-Do: Add more sorting options + $query ->order($db->quoteName('c.publish_up').' DESC'); + $db->setQuery($query); + $rows = $db->loadObjectList(); + } + + $selIds = array(); + $base = rtrim(JUri::base(false),'/'); + + if (is_array($rows)) + { + for ($i=0,$n=count($rows);$i<$n;$i++) + { + $selIds[] = $rows[$i]->id; + $images = (array)json_decode($rows[$i]->images); + if ( + isset($images['image_intro']) + && strlen($images['image_intro']) + //&& file_exists(JPATH_ROOT.'/'.$images['image_intro']) + ) + { + $rows[$i]->image = $images['image_intro']; + } + elseif ( + isset($images['image_fulltext']) + && strlen($images['image_fulltext']) + //&& file_exists(JPATH_ROOT.'/'.$images['image_fulltext']) + ) + { + $rows[$i]->image = $images['image_fulltext']; + } + else + { + $txt = $rows[$i]->introtext.$rows[$i]->fulltext; + $ptrn = '/]+)(?:\'|")/si'; + if (preg_match($ptrn,$txt,$imgMatch)) + { + $rows[$i]->image = $base.'/'.ltrim(html_entity_decode($imgMatch[1]),'/'); + } + else + { + $rows[$i]->image = $config['default-image']; + } + + } + } + $already = array_merge($already,$selIds); + if (count($rows) < $number && $relation < 4) + { + $rows = array_merge($rows,self::_getRelatedList($article,$config,$relation+1,$number-count($rows),$already)); + } + $return = $rows; + } + + } + return $return; + } +} \ No newline at end of file diff --git a/injector_related.php b/injector_related.php index ec443a4..5480228 100644 --- a/injector_related.php +++ b/injector_related.php @@ -1,6 +1,6 @@ params,$article); - $input = JFactory::getApplication()->input; - if ( $input->getCmd('option')=='com_content' - && $input->getCmd('view')=='article' - ) + if (plgContentInjector_relatedHelper::shouldRun($context)) { - if ($config['enable']) + $config = plgContentInjector_relatedHelper::getConfig($this->params,$article); + $input = JFactory::getApplication()->input; + if ( $input->getCmd('option')=='com_content' + && $input->getCmd('view')=='article' + ) { $inject = true; - if ($config['filter'] == 'inc') + if ($config['enable']) { - if (!in_array($article->catid,$config['categories'])) $inject = false; + if ($config['filter'] == 'inc') + { + if (!in_array($article->catid,$config['categories'])) + { + $inject = false; + } + } + else + { + if (in_array($article->catid,$config['categories'])) + { + $inject = false; + } + } } else { - if (in_array($article->catid,$config['categories'])) $inject = false; + $inject = false; + } + if ($inject) + { + plgContentInjector_relatedHelper::injectText($article,$config); } } - if ($inject) + } + return true; + } + + public function onBeforeRender() + { + if ( + $this->app->isAdmin() + && $this->app->input->getCmd('option')=='com_plugins' + && $this->app->input->getCmd('view')=='plugin' + && $this->app->input->getCmd('layout')=='edit' + ) + { + $id = $this->app->input->getCmd('extension_id'); + if (!empty($id)) { - plgContentInjector_relatedHelper::injectText($article,$config); + $query = $this->db->getQuery(true); + $query ->select('*') + ->select($this->db->quoteName('folder')) + ->from($this->db->quoteName('#__extensions')) + ->where($this->db->quoteName('extension_id').'='.$id) + ->where($this->db->quoteName('folder').'='.$this->db->quote($this->_type)) + ->where($this->db->quoteName('element').'='.$this->db->quote($this->_name)) + ; + $this ->db->setQuery($query); + $rows = $this->db->loadObjectList(); + if (count($rows)) + { + $doc = JFactory::getDocument(); + $doc ->addScript(rtrim(JUri::root(true),'/').'/media/plg_content_injector_related/js/backend.js'); + $doc ->addStyleSheet(rtrim(JUri::root(true),'/').'/media/plg_content_injector_related/css/backend.css'); + } } } - return true; } } diff --git a/injector_related.xml b/injector_related.xml index 9496d4e..7549a21 100644 --- a/injector_related.xml +++ b/injector_related.xml @@ -1,7 +1,7 @@ plg_content_injector_related - 1.2 + 1.3 March 17th, 2018 PLG_CONTENT_INJECTOR_RELATED_XML_DESCRIPTION Magnus Arebalus @@ -21,6 +21,8 @@ placeholder.png index.html slick + js + css @@ -40,7 +42,7 @@ + /> - + - + + + + + + + + + + + JYES - + + + + + + + + + + + diff --git a/language/en-GB/en-GB.plg_content_injector_related.ini b/language/en-GB/en-GB.plg_content_injector_related.ini index 18ec6de..fa7be38 100644 --- a/language/en-GB/en-GB.plg_content_injector_related.ini +++ b/language/en-GB/en-GB.plg_content_injector_related.ini @@ -1,7 +1,7 @@ ; ; Copyright (C) 2018 Magnus Arebalus Marcus. All rights reserved. ; -; Project Content - Injector Related 1.2 +; Project Content - Injector Related 1.3 ; @@ -29,6 +29,19 @@ PLG_CONTENT_INJECTOR_RELATED_FIELD_SINGLE_LINE_TITLE_LABEL="Single Line Title" PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_LENGHT_LABEL="Text Length" PLG_CONTENT_INJECTOR_RELATED_FIELD_MAX_ITEMS_IN_SLIDE_LABEL="Max. Items in Slide" PLG_CONTENT_INJECTOR_RELATED_FIELD_ONLY_ROOT_LABEL="Only at Root Level" +PLG_CONTENT_INJECTOR_RELATED_FIELD_UPPERCASE_TITLE_LABEL="Uppercase Title" +PLG_CONTENT_INJECTOR_RELATED_FIELD_FONT_SIZE_TITLE_LABEL="Title Font Size" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_UP_TITLE_LABEL="Title Margin Up" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_DOWN_TITLE_LABEL="Title Margin Down" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_IMAGE_LABEL="Image Settings" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_TITLE_LABEL="Title Settings" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_TEXT_LABEL="Text Settings" +PLG_CONTENT_INJECTOR_RELATED_FIELD_LINKED_IMAGE_LABEL="Linked Image" +PLG_CONTENT_INJECTOR_RELATED_FIELD_LINKED_TITLE_LABEL="Linked Title" +PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_COLOR_LABEL="Text Color" +PLG_CONTENT_INJECTOR_RELATED_FIELD_COLOR_TITLE_LABEL="Title Color" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_BOTTOM_TEXT_LABEL="Text Margin Bottom" +PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_FONT_SIZE_LABEL="Text Font Size" ;Configuration Fields Descriptions PLG_CONTENT_INJECTOR_RELATED_FIELD_ENABLE_DESC="" @@ -50,6 +63,19 @@ PLG_CONTENT_INJECTOR_RELATED_FIELD_SINGLE_LINE_TITLE_DESC="" PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_LENGHT_DESC="" PLG_CONTENT_INJECTOR_RELATED_FIELD_MAX_ITEMS_IN_SLIDE_DESC="" PLG_CONTENT_INJECTOR_RELATED_FIELD_ONLY_ROOT_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_UPPERCASE_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_FONT_SIZE_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_UP_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_DOWN_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_IMAGE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_TEXT_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_LINKED_IMAGE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_LINKED_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_COLOR_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_COLOR_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_BOTTOM_TEXT_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_FONT_SIZE_DESC="" ;Other Translatable Texts diff --git a/language/es-ES/es-ES.plg_content_injector_related.ini b/language/es-ES/es-ES.plg_content_injector_related.ini index 0adfc50..b3ffc16 100644 --- a/language/es-ES/es-ES.plg_content_injector_related.ini +++ b/language/es-ES/es-ES.plg_content_injector_related.ini @@ -1,7 +1,7 @@ ; ; Copyright (C) 2018 Magnus Arebalus Marcus. All rights reserved. ; -; Project Content - Injector Related 1.2 +; Project Content - Injector Related 1.3 ; PLG_CONTENT_INJECTOR_RELATED="Contenido - Injector Related" @@ -28,7 +28,18 @@ PLG_CONTENT_INJECTOR_RELATED_FIELD_SINGLE_LINE_TITLE_LABEL="Título en una Líne PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_LENGHT_LABEL="Largo del Texto" PLG_CONTENT_INJECTOR_RELATED_FIELD_MAX_ITEMS_IN_SLIDE_LABEL="Artículos por Deslizador" PLG_CONTENT_INJECTOR_RELATED_FIELD_ONLY_ROOT_LABEL="Sólo en Raiz" - +PLG_CONTENT_INJECTOR_RELATED_FIELD_UPPERCASE_TITLE_LABEL="Título en Mayúsculas" +PLG_CONTENT_INJECTOR_RELATED_FIELD_FONT_SIZE_TITLE_LABEL="Tamaño de Fuente en Título" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_UP_TITLE_LABEL="Márgen Sup. Título" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_DOWN_TITLE_LABEL="Márgen Inf. Título" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_IMAGE_LABEL="Ajustes de Imagen" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_TITLE_LABEL="Ajustes del Título" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_TEXT_LABEL="Ajustes del Texto" +PLG_CONTENT_INJECTOR_RELATED_FIELD_LINKED_IMAGE_LABEL="Imagen Enlazada" +PLG_CONTENT_INJECTOR_RELATED_FIELD_LINKED_TITLE_LABEL="Título Enlazado" +PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_COLOR_LABEL="Color del Texto" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_BOTTOM_TEXT_LABEL="Margen Inf. Texto" +PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_FONT_SIZE_LABEL="Tamaño de Fuente en Texto" ;Configuration Fields Descriptions PLG_CONTENT_INJECTOR_RELATED_FIELD_ENABLE_DESC="" @@ -50,6 +61,17 @@ PLG_CONTENT_INJECTOR_RELATED_FIELD_SINGLE_LINE_TITLE_DESC="" PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_LENGHT_DESC="" PLG_CONTENT_INJECTOR_RELATED_FIELD_MAX_ITEMS_IN_SLIDE_DESC="" PLG_CONTENT_INJECTOR_RELATED_FIELD_ONLY_ROOT_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_UPPERCASE_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_UP_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_DOWN_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_IMAGE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_SPACER_TEXT_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_LINKED_IMAGE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_LINKED_TITLE_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_COLOR_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_MARGIN_BOTTOM_TEXT_DESC="" +PLG_CONTENT_INJECTOR_RELATED_FIELD_TEXT_FONT_SIZE_DESC="" ;Other Translatable Texts diff --git a/media/css/backend.css b/media/css/backend.css new file mode 100644 index 0000000..0bfc7a9 --- /dev/null +++ b/media/css/backend.css @@ -0,0 +1,3 @@ +/* +* Backend CSS style for Injector Reltated 1.3 +*/ \ No newline at end of file diff --git a/media/js/backend.js b/media/js/backend.js new file mode 100644 index 0000000..bbd644f --- /dev/null +++ b/media/js/backend.js @@ -0,0 +1,46 @@ +/* +* Backend JavaScript for Injector Reltated 1.3 +*/ + +jQuery(document).ready(function($){ + $('.injector-range').each(function(){ + var id = $(this).attr('id'); + var min = $(this).attr('min'); + var max = $(this).attr('max'); + var val = parseInt($(this).val()); + var cls = 'label-info'; + if (val > 0) + { + cls = 'label-success'; + } + if (val < 0) + { + cls = 'label-important'; + } + $( ''+min+' ' ).insertBefore( this ); + $( ' '+max+''+'       '+val+'      ' + ).insertAfter( this ); + $(this).attr('oninput', 'injectorSliderChange(\''+id+'\');'); + }); + +}); + +function injectorSliderChange(e) +{ + var v = parseInt(jQuery('#'+e).val()); + var l = '#'+e+'-value'; + var cls = 'label-info'; + if (v > 0) + { + cls = 'label-success'; + } + if (v < 0) + { + cls = 'label-important'; + } + jQuery(l).html('      '+v+'      '); + jQuery(l).removeClass('label-info'); + jQuery(l).removeClass('label-success'); + jQuery(l).removeClass('label-important'); + jQuery(l).addClass(cls); +}; \ No newline at end of file diff --git a/tmpl/bootstrap-table.php b/tmpl/bootstrap-table.php index e417c1d..f469a69 100644 --- a/tmpl/bootstrap-table.php +++ b/tmpl/bootstrap-table.php @@ -1,6 +1,6 @@ - title; ?> + >title; ?> diff --git a/tmpl/default.php b/tmpl/default.php index 368a772..d14f0ce 100644 --- a/tmpl/default.php +++ b/tmpl/default.php @@ -1,6 +1,6 @@
  • - title; ?> + >title; ?>
  • diff --git a/tmpl/slick-carousel.php b/tmpl/slick-carousel.php index 9247c0b..8b81f6c 100644 --- a/tmpl/slick-carousel.php +++ b/tmpl/slick-carousel.php @@ -1,6 +1,6 @@ 0 ? intval($config['image-height']) : 120; -$text_lenght = intval($config['text-length']) > 0 ? intval($config['text-length']) : 0; +$image_height = intval($config['image-height']) >= 0 ? intval($config['image-height']) : 120; +$text_lenght = intval($config['text-length']) >= 0 ? intval($config['text-length']) : 0; +$title_uppercase= intval($config['uppercase-title']) == 1 ? 'text-transform:uppercase; ' : '' ; + + $slides = (count($rows)) >= $config['max-items-in-slide'] ? $config['max-items-in-slide'] : count($rows) ; $slides_1024 = ($slides - 1) > 0 ? $slides - 1 : 1 ; $slides_600 = ($slides_1024 - 1) > 0 ? $slides_1024 - 1 : 1 ; @@ -66,18 +69,25 @@ .".injector-related-slider *{height:auto; min-width: 0;min-height: 0;}" .".injector-related-slider:after,{visibility: hidden;display: block;font-size: 0;content: \" \";clear: both;height: 0;} " .".injector-related-image{width:100%;background-position:center center;background-size: cover; } " - .".injector-related-image a img{width:100%; height:{$image_height}px !important;} " + .".injector-related-image img, .injector-related-image a img{width:100%; height:{$image_height}px !important;border:0;} " .".injector-related-slider-parent{ padding: 20px 30px;}" .".injector-related-slider-item{padding:0 5px;}" - .".injector-related-text{font-size:0.8em;line-height:1.1em;text-align:justify;color:#777;}" + .".injector-related-text{font-size:{$config['text-font-size']}px;line-height:1.1em;text-align:justify;color:{$config['text-color']};margin-bottom:{$config['margin-bottom-text']}px;}" ; +if (strlen($config['color-title'])) +{ + $style .= ".injector-related-title{color:{$config['color-title']};}" + .".injector-related-title a{color:{$config['color-title']};}" + ; + +} if ($config['single-line-title'] == '1') { - $style .= ".injector-related-title{text-transform:uppercase; font-size:0.8em; font-weight:bold; overflow: hidden; position: relative; text-overflow: ellipsis; white-space: nowrap;margin:20px 0 10px 0;} "; + $style .= ".injector-related-title{{$title_uppercase}font-size:{$config['font-size-title']}px; font-weight:bold;line-height:1.2em; overflow: hidden; position: relative; text-overflow: ellipsis; white-space: nowrap;margin:{$config['margin-up-title']}px 0 {$config['margin-down-title']}px 0;} "; } else { - $style .= ".injector-related-title{text-transform:uppercase; font-size:0.8em; font-weight:bold; line-height:1.2em;margin:20px 0 10px 0;} "; + $style .= ".injector-related-title{{$title_uppercase}font-size:{$config['font-size-title']}px; font-weight:bold; line-height:1.2em;margin:{$config['margin-up-title']}px 0 {$config['margin-down-title']}px 0;} "; } JFactory::getDocument()->addStyleDeclaration($style); @@ -94,7 +104,9 @@