Skip to content

Commit

Permalink
Improved - alpha index now JLayout for better reuse
Browse files Browse the repository at this point in the history
New Field - OpenGraph [Finied]

(cherry picked from commit dc58f9bc8e6699a673439be2b23690d6db172372)
  • Loading branch information
andiamine committed Apr 19, 2024
1 parent 882e7d5 commit 25e8180
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 42 deletions.
67 changes: 35 additions & 32 deletions components/com_joomcck/fields/opengraph/opengraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,42 @@

class JFormFieldCOpengraph extends CFormField
{

public $pictureFieldId = 0;
public $descriptionFieldId = 0;

/*
* Doesn't need it
*/
public function getInput()
{
return;
}

public function onRenderFull($record, $type, $section)
{
{
// set fields ids
$this->pictureFieldId = $this->params->get('params.pic_id',0);
$this->descriptionFieldId = $this->params->get('params.desc_id',0);

//init vars
// get general upload directory
$fupload = ComponentHelper::getParams('com_joomcck')->get('general_upload');
$default_pic = $this->params->get('params.default_pic');
$ids = $this->_getFieldId();

// get default pictures
$default_pic = $this->params->get('params.default_pic','');
$default_pic = !empty($default_pic) ? \Joomla\CMS\HTML\HTMLHelper::cleanImageURL($default_pic)->url : '';


// get og type
$og_type = $this->params->get('params.og_type');
$app_id = $this->params->get('params.app_id');

$site_name = $this->sitename();
$item_title = $record->title;
$item_link = Route::_($record->href);
$out = '';
$purl = '';



// get gallery field path
if(!empty($ids['pic'])){
Expand All @@ -43,11 +61,10 @@ public function onRenderFull($record, $type, $section)

if(!isset($fparams['params']['select_type'])){ // is gallery field

$purl = $this->routeurl().$fupload.'/'.$subf.'/';
$purl = \Joomla\CMS\Uri\Uri::root().$fupload.'/'.$subf.'/';
}

}else
$purl = '';
}


// get image url
Expand All @@ -65,12 +82,12 @@ public function onRenderFull($record, $type, $section)
}

}else{ // if simple image field
$item_pic_url = $this->routeurl().$pfiles;
$item_pic_url = \Joomla\CMS\Uri\Uri::root().$pfiles;
}

}else{
if(!empty($default_pic)){ // default image
$item_pic_url = $this->routeurl().$default_pic;
$item_pic_url = \Joomla\CMS\Uri\Uri::root().$default_pic;
}else
$item_pic_url = '';
}
Expand All @@ -79,7 +96,7 @@ public function onRenderFull($record, $type, $section)
}
elseif(!empty($default_pic)){ // default image

$item_pic_url = $this->routeurl().$default_pic;
$item_pic_url = \Joomla\CMS\Uri\Uri::root().$default_pic;
}
else{ // nothing found

Expand All @@ -98,6 +115,8 @@ public function onRenderFull($record, $type, $section)
$out .= '<meta property="og:title" content="'.$item_title.'">';
$out .= '<meta property="og:site_name" content="'.$site_name.'">';
$out .= '<meta property="og:url" content="'.$item_link.'">';

if(!empty($item_desc))
$out .= '<meta property="og:description" content="'.$item_desc.'">';

if(!empty($item_pic_url)){
Expand All @@ -119,6 +138,10 @@ public function onRenderFull($record, $type, $section)

}

public function setGalleryFieldPath(){

}

public function onRenderList($record, $type, $section)
{
return;
Expand Down Expand Up @@ -168,27 +191,7 @@ private function sitename(){
private function sitedesc(){
return Factory::getDocument()->getMetaData('description');
}

private function routeurl(){
return Factory::getURI()->base();
}

// return ids
private function _getFieldId(){

$id = array();

if($this->params->get('params.field_type'))

$id = array('pic' => $this->params->get('params.pic_id'), 'desc' => $this->params->get('params.desc_id'));

else

$id = array('pic' => $this->_getFieldIdFromDB($this->params->get('params.pic_key')), 'desc' => $this->_getFieldIdFromDB($this->params->get('params.desc_key')));

return $id ;

}


// strip bbcode in desc field
private function _stripBBCode($desc) {
Expand Down
15 changes: 5 additions & 10 deletions components/com_joomcck/fields/opengraph/opengraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
<name>Open Graph</name>
<group>SEO</group>
<config>
<fields name="params">
<fieldset name="tmpl">
<field type="filelist" name="template_output_list" filter="php$" hide_none="1" hide_default="1" directory="/components/com_joomcck/fields/opengraph/tmpl/output" label="F_TMPLLIST" default="default.php" />
<field type="filelist" name="template_output_full" filter="php$" hide_none="1" hide_default="1" directory="/components/com_joomcck/fields/opengraph/tmpl/output" label="F_TMPLFULL" default="default.php" />
</fieldset>
<fieldset name="general" label="FS_GENERAL" addfieldpath="/administrator/components/com_joomcck/models/fields">
<field name="app_id" type="text" default="" label="FB App ID" description="" />
<fields name="params" addfieldpath="/administrator/components/com_joomcck/models/fields">
<fieldset name="general" label="FS_GENERAL" >
<field name="og_type" type="list" default="article" label="Type" description="" multiple="false" required="true">
<option value="article">Article</option>
<option value="book">Book</option>
Expand Down Expand Up @@ -38,9 +33,9 @@
<option value="video.website">Website</option>
</field>
</fieldset>
<fieldset name="field_pos_list" label="Map Fields" addfieldpath="/administrator/components/com_joomcck/models/fields">
<field name="pic_id" showon="og_type:fitness.course" type="text" default="" label="F_PIC_FIELD"/>
<field name="desc_id" type="text" default="" label="F_DESC_FIELD"/>
<fieldset name="field_pos_list" label="Fields Mapping">
<field name="desc_id" type="fieldstype" required="true" allowedFieldsType="text,textarea,html" default="" label="F_DESC_FIELD"/>
<field name="pic_id" type="fieldstype" required="true" allowedFieldsType="image,gallery" default="" label="F_PIC_FIELD"/>
<field name="default_pic" type="media" label="F_DEFAULT_PIC"/>
</fieldset>
</fields>
Expand Down
84 changes: 84 additions & 0 deletions components/com_joomcck/models/fields/fieldstype.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Joomcck by joomcoder
* a component for Joomla! 1.7 - 2.5 CMS (http://www.joomla.org)
* Author Website: https://www.joomcoder.com/
* @copyright Copyright (C) 2012 joomcoder (https://www.joomcoder.com). All rights reserved.
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
*/

defined('_JEXEC') or die;

jimport('joomla.html.html');
jimport('joomla.form.formfield');

class JFormFieldFieldstype extends \Joomla\CMS\Form\Field\ListField
{

protected $type = 'Fieldstype';

public function getOptions()
{


$fieldsType = $this->buildfieldTypesForSql();
$typeId = $this->getTypeIdOfCurrentField();

// get fields list
$db = \Joomla\CMS\Factory::getDbo();
$query = $db->getQuery(true);

$query->select("id AS value, label AS text")
->from("#__js_res_fields")
->where("type_id = $typeId AND field_type IN $fieldsType");


$db->setQuery($query);

$list = $db->loadObjectList();


$opt = \Joomla\CMS\HTML\HTMLHelper::_('select.option', '', \Joomla\CMS\Language\Text::_('CSELECTFIELD'));

array_unshift($list, $opt);

return $list;

}

private function buildfieldTypesForSql(){

$fieldsType = $this->getAttribute('allowedFieldsType');
$fieldsType = explode(',', $fieldsType);

$db = \Joomla\CMS\Factory::getDbo();

foreach ($fieldsType as &$field){

$field = $db->quote($field);

}

return "(" . implode(',', $fieldsType) . ")";



}


public function getTypeIdOfCurrentField(){

$currentFieldId = \Joomla\CMS\Factory::getApplication()->input->getInt('id',0);

$db = \Joomla\CMS\Factory::getDbo();
$query = 'SELECT type_id' .
' FROM #__js_res_fields' .
' WHERE id = ' . $currentFieldId;
$db->setQuery($query);

return $db->loadResult();

}


}
5 changes: 5 additions & 0 deletions plugins/system/joomcck/joomcck.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,9 @@ public function onUserAfterDelete($user, $success, $msg)

return TRUE;
}





}

0 comments on commit 25e8180

Please sign in to comment.