field_type, self::$field_types) ) return; } // Method to create field's HTML display for frontend views function onDisplayFieldValue(&$field, $item, $values=null, $prop='display') { if ( !in_array($field->field_type, self::$field_types) ) return; $view = JRequest::getString('view', FLEXI_ITEMVIEW); //if ($view != FLEXI_ITEMVIEW) return; if (JRequest::getCmd('print')) return; global $mainframe, $addthis; //$scheme = JURI::getInstance()->getScheme(); // we replaced http(s):// with // $document = JFactory::getDocument(); $lang = $document->getLanguage(); $lang = $item->params->get('language', $lang); $lang = $lang ? $lang : 'en-GB'; $lang = substr($lang, 0, 2); $lang = in_array($lang, array('en','es','it','th')) ? $lang : 'en'; // parameters shortcuts $display_comments = $field->parameters->get(FLEXI_J16GE ? 'display_comments' : 'display-comments', 1) && $item->parameters->get('comments',0); $display_resizer = $field->parameters->get(FLEXI_J16GE ? 'display_resizer' : 'display-resizer', 1); $display_print = $field->parameters->get(FLEXI_J16GE ? 'display_print' : 'display-print', 1); $display_email = $field->parameters->get(FLEXI_J16GE ? 'display_email' : 'display-email', 1); $display_voice = $field->parameters->get(FLEXI_J16GE ? 'display_voice' : 'display-voice', 1); //$display_pdf = $field->parameters->get(FLEXI_J16GE ? 'display_pdf' : 'display-pdf', 1); $display_pdf = FLEXI_J16GE ? 0 : $field->parameters->get('display-pdf', 1); $load_css = $field->parameters->get(FLEXI_J16GE ? 'load_css' : 'load-css', 1); $display_social = $field->parameters->get(FLEXI_J16GE ? 'display_social' : 'display-social', 1); $addthis_user = $field->parameters->get(FLEXI_J16GE ? 'addthis_user' : 'addthis-user', ''); $addthis_pubid = $field->parameters->get('addthis_pubid', $addthis_user); $spacer_size = $field->parameters->get(FLEXI_J16GE ? 'spacer_size' : 'spacer-size', 21); $module_position = $field->parameters->get('module_position', ''); $default_size = $field->parameters->get(FLEXI_J16GE ? 'default_size' : 'default-size', 12); $default_line = $field->parameters->get(FLEXI_J16GE ? 'default_line' : 'default-line', 16); $target = $field->parameters->get('target', 'flexicontent'); $voicetarget = $field->parameters->get('voicetarget', 'flexicontent'); $spacer = ' style="width:'.$spacer_size.'px;"'; // define a global variable to be sure the script is loaded only once $addthis = isset($addthis) ? $addthis : 0; if ($load_css) { $document->addStyleSheet(JURI::root(true).'/plugins/flexicontent_fields/toolbar/'.(FLEXI_J16GE ? 'toolbar/' : '').'/toolbar.css'); } if ($display_social || $display_comments || $display_email || $display_print) { $item_url = FlexicontentHelperRoute::getItemRoute($item->slug, $item->categoryslug); $server = JURI::getInstance()->toString(array('scheme', 'host', 'port')); $item_link = $server . JRoute::_($item_url); // NOTE: this uses current SSL setting (e.g menu item), and not URL scheme: http/https //$item_link = JRoute::_($item_url, true, -1); } $display = '
'; // begin of the toolbar container // comments button if ($display_comments) { $comment_link = $item_link . '#addcomments'; $display .= '
'.($module_position ? '' : '').$this->_getCommentsCount($item->id).($module_position ? '' : '').' '.JText::_('FLEXI_FIELD_TOOLBAR_COMMENT').'
'; } // text resizer if ($display_resizer) { $document->addScriptDeclaration('var textsize = '.$default_size.'; var lineheight = '.$default_line.'; function fsize(size,line,unit,id){ var vfontsize = document.getElementById(id); if(vfontsize){ vfontsize.style.fontSize = size + unit; vfontsize.style.lineHeight = line + unit; } } function changetextsize(up){ if(up){ textsize = parseFloat(textsize)+2; lineheight = parseFloat(lineheight)+2; }else{ textsize = parseFloat(textsize)-2; lineheight = parseFloat(lineheight)-2; } }'); $display .= '
'.JText::_("FLEXI_FIELD_TOOLBAR_DECREASE").' '.JText::_("FLEXI_FIELD_TOOLBAR_INCREASE").' '.JText::_("FLEXI_FIELD_TOOLBAR_SIZE").'
'; } // email button if ($display_email) { require_once(JPATH_SITE.DS.'components'.DS.'com_mailto'.DS.'helpers'.DS.'mailto.php'); $url = 'index.php?option=com_mailto&tmpl=component&link='.MailToHelper::addLink( $item_link ); $estatus = 'width=400,height=400,menubar=yes,resizable=yes'; $display .= '
'; } // print button if ($display_print) { $pop = JRequest::getInt('pop'); $pstatus = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no'; $print_link = $pop ? '#' : $item_link . '&pop=1&print=1&tmpl=component'; $js_link = $pop ? 'onclick="window.print();return false;"' : 'onclick="window.open(this.href,\'win2\',\''.$pstatus.'\'); return false;"'; $display .= '
'.JText::_('FLEXI_FIELD_TOOLBAR_PRINT').'
'; } // pdf button if ($display_voice) { $display .= "
"; if ($lang=='th') { // Special case language case, maybe la=laos, and Bhutan languages in the future (NECTEC support these languages) $document->addScript(JURI::root(true).'/plugins/flexicontent_fields/toolbar'.(FLEXI_J16GE ? '/toolbar' : '').'/th.js'); $display .=" " . JTEXT::_('FLEXI_FIELD_TOOLBAR_VOICE') . " "; } else { $document->addScript('//vozme.com/get_text.js'); $display .=" " . JTEXT::_('FLEXI_FIELD_TOOLBAR_VOICE') . " "; } $display .="
"; } // pdf button if ($display_pdf) { $pdflink = 'index.php?view=items&cid='.$item->categoryslug.'&id='.$item->slug.'&format=pdf'; $display .= '
'.JText::_('FLEXI_FIELD_TOOLBAR_PDF').'
'; } // AddThis social SHARE buttons, also optionally add OPEN GRAPH TAGs if ($display_social) { // *************** // OPEN GRAPH TAGs // *************** // OPEN GRAPH: site name if ($field->parameters->get('add_og_site_name')) { $document->addCustomTag("getCfg('sitename')."\" />"); } // OPEN GRAPH: title if ($field->parameters->get('add_og_title')) { $title = flexicontent_html::striptagsandcut($item->title); $document->addCustomTag(""); } // OPEN GRAPH: description if ($field->parameters->get('add_og_descr')) { if ( $item->metadesc ) { $document->addCustomTag(''); } else { $text = flexicontent_html::striptagsandcut($item->text); $document->addCustomTag(""); } } // OPEN GRAPH: type $og_type = (int) $field->parameters->get('add_og_type'); if ($og_type) { if ($og_type > 2) $og_type = 1; $og_type_names = array(1=>'article', 2=>'website'); $document->addCustomTag(""); } // OPEN GRAPH: image (extracted from item's description text) if ($field->parameters->get('add_og_image')) { $og_image_field = $field->parameters->get('og_image_field'); $og_image_fallback = $field->parameters->get('og_image_fallback'); $og_image_thumbsize = $field->parameters->get('og_image_thumbsize'); if ($og_image_field) { $imageurl = FlexicontentFields::getFieldDisplay($item, $og_image_field, null, 'display_'.$og_image_thumbsize.'_src', 'module'); if ( $imageurl ) { $img_field = $item->fields[$og_image_field]; if ( (!$imageurl && $og_image_fallback==1) || ($imageurl && $og_image_fallback==2 && $img_field->using_default_value) ) { $imageurl = $this->_extractimageurl($item); } } } else { $imageurl = $this->_extractimageurl($item); } if ($imageurl) $document->addCustomTag(""); } // **************************** // AddThis social SHARE buttons // **************************** $addthis_outside_toolbar = $field->parameters->get('addthis_outside_toolbar', 0); $addthis_custom_code = $field->parameters->get('addthis_custom_code', false); $addthis_custom_predefined = $field->parameters->get('addthis_custom_predefined', false); $addthis_code = ''; if ($addthis_custom_code) { $addthis_code .= str_replace('_item_url_', $item_link, $addthis_custom_code); $addthis_code .= str_replace('_item_title_', htmlspecialchars( $item->title, ENT_COMPAT, 'UTF-8' ), $addthis_code); } else { switch ($addthis_custom_predefined) { case 1: $addthis_code .= '
'; break; case 2: $addthis_code .= '
'; break; default: case 3: $addthis_code .= '
'; break; case 4: $addthis_code .= ' '.JText::_('FLEXI_FIELD_TOOLBAR_SHARE').' '; break; case 5: $addthis_code .= '
'; break; case 6: $addthis_code .= '
'; break; case 7: $addthis_code .= '
'; break; } } if ($addthis_outside_toolbar) $display .= '
'.$addthis_code.'
'; else $display .= '
' .$addthis_code. '
'; if (!$addthis) { $document->addCustomTag(' '); $addthis = 1; } } $display .= '
'; // end of the toolbar container $field->{$prop} = $display; } // ************************************************************** // METHODS HANDLING before & after saving / deleting field events // ************************************************************** // Method to handle field's values before they are saved into the DB function onBeforeSaveField($field, &$post, $file) { if ( !in_array($field->field_type, self::$field_types) ) return; } // Method to take any actions/cleanups needed after field's values are saved into the DB function onAfterSaveField( &$field, &$post, &$file, &$item ) { } // Method called just before the item is deleted to remove custom item data related to the field function onBeforeDeleteField(&$field, &$item) { } // ********************** // VARIOUS HELPER METHODS // ********************** function _getCommentsCount($id) { $db = JFactory::getDBO(); static $jcomment_installed = null; if ($jcomment_installed===null) { $app = JFactory::getApplication(); $dbprefix = $app->getCfg('dbprefix'); $db->setQuery('SHOW TABLES LIKE "'.$dbprefix.'jcomments"'); $jcomment_installed = (boolean) count($db->loadObjectList()); } if (!$jcomment_installed) return 0; $query = 'SELECT COUNT(com.object_id)' . ' FROM #__jcomments AS com' . ' WHERE com.object_id = ' . (int)$id . ' AND com.object_group = ' . $db->Quote('com_flexicontent') . ' AND com.published = 1' ; $db->setQuery($query); return $db->loadResult() ? (int)$db->loadResult() : 0; } function _extractimageurl(& $item) { $matches = NULL; preg_match_all('//i', $item->text, $matches); $imageurl = @$matches[1][0]; if($imageurl) { if($imageurl{0} == '/') { $imageurls = explode('/', $imageurl); $paths = array(); $found = false; foreach($imageurls as $folder) { if(!$found) { if($folder!='images') continue; else { $found = true; } } $paths[] = $folder; } $imageurl = '/'.implode('/', $paths); $imageurl = JURI::root(true).$imageurl; }elseif(substr($imageurl, 0, 7)=='images/') { $imageurl = JURI::root(true).'/'.$imageurl; } } return $imageurl; } }