This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,059 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
namespace Craft; | ||
|
||
/** | ||
* Seomatic Meta field type | ||
*/ | ||
class Seomatic_MetaFieldType extends BaseFieldType | ||
{ | ||
|
||
public function getName() | ||
{ | ||
return Craft::t('Seomatic Meta'); | ||
} | ||
|
||
public function defineContentAttribute() | ||
{ | ||
return AttributeType::Mixed; | ||
} | ||
|
||
public function getInputHtml($name, $value) | ||
{ | ||
|
||
if (!$value) | ||
$value = new Seomatic_MetaFieldModel(); | ||
|
||
$id = craft()->templates->formatInputId($name); | ||
$namespacedId = craft()->templates->namespaceInputId($id); | ||
|
||
// Include our Javascript & CSS | ||
craft()->templates->includeCssResource('seomatic/css/css-reset.css'); | ||
craft()->templates->includeCssResource('seomatic/css/prism.min.css'); | ||
craft()->templates->includeCssResource('seomatic/css/style.css'); | ||
craft()->templates->includeCssResource('seomatic/css/field.css'); | ||
craft()->templates->includeJsResource('seomatic/js/field.js'); | ||
craft()->templates->includeJsResource('seomatic/js/jquery.bpopup.min.js'); | ||
craft()->templates->includeJsResource('seomatic/js/prism.min.js'); | ||
|
||
$variables = array( | ||
'id' => $id, | ||
'name' => $name, | ||
'meta' => $value, | ||
'element' => $this->element, | ||
'field' => $this->model, | ||
); | ||
|
||
$jsonVars = array( | ||
'id' => $id, | ||
'name' => $name, | ||
'namespace' => $namespacedId, | ||
'prefix' => craft()->templates->namespaceInputId(""), | ||
); | ||
|
||
$jsonVars = json_encode($jsonVars); | ||
craft()->templates->includeJs("$('#{$namespacedId}').SeomaticFieldType(" . $jsonVars . ");"); | ||
|
||
if (isset($variables['locale'])) | ||
$locale = $variables['locale']; | ||
else | ||
$locale = craft()->language; | ||
|
||
$siteMeta = craft()->seomatic->getSiteMeta($locale); | ||
$variables['titleLength'] = (70 - strlen(" | ") - strlen($siteMeta['siteSeoName'])); | ||
|
||
/* -- Prep some parameters */ | ||
|
||
// Whether any assets sources exist | ||
$sources = craft()->assets->findFolders(); | ||
$variables['assetsSourceExists'] = count($sources); | ||
|
||
// URL to create a new assets source | ||
$variables['newAssetsSourceUrl'] = UrlHelper::getUrl('settings/assets/sources/new'); | ||
|
||
// Set asset ID | ||
$variables['seoImageId'] = $variables['meta']->seoImageId; | ||
|
||
// Set asset elements | ||
if ($variables['seoImageId']) { | ||
if (is_array($variables['seoImageId'])) { | ||
$variables['seoImageId'] = $variables['seoImageId'][0]; | ||
} | ||
$asset = craft()->elements->getElementById($variables['seoImageId']); | ||
$variables['elements'] = array($asset); | ||
} else { | ||
$variables['elements'] = array(); | ||
} | ||
|
||
// Set element type | ||
$variables['elementType'] = craft()->elements->getElementType(ElementType::Asset); | ||
|
||
/* -- Extract a list of the other plain text fields that are in this entry's layout */ | ||
|
||
$fieldList = array('title' => 'Title'); | ||
$imageFieldList = array(); | ||
$fieldLayouts = $this->element->fieldLayout->getFields(); | ||
foreach ($fieldLayouts as $fieldLayout) | ||
{ | ||
$field = craft()->fields->getFieldById($fieldLayout->fieldId); | ||
if ($field->fieldType->name == "Plain Text" | ||
|| $field->fieldType->name == "Rich Text" | ||
|| $field->fieldType->name == "Rich Text (Redactor I)" | ||
) | ||
$fieldList[$field->handle] = $field->name; | ||
if ($field->fieldType->name == "Assets") | ||
$imageFieldList[$field->handle] = $field->name; | ||
} | ||
$variables['fieldList'] = $fieldList; | ||
$variables['imageFieldList'] = $imageFieldList; | ||
$variables['elementId'] = $this->element->id; | ||
|
||
return craft()->templates->render('seomatic/field', $variables); | ||
} | ||
|
||
public function prepValueFromPost($value) | ||
{ | ||
if (empty($value)) | ||
{ | ||
return new Seomatic_MetaFieldModel(); | ||
} | ||
else | ||
{ | ||
return new Seomatic_MetaFieldModel($value); | ||
} | ||
} | ||
|
||
public function prepValue($value) | ||
{ | ||
|
||
if (craft()->request->isSiteRequest()) | ||
{ | ||
SeomaticPlugin::log("prepValue() called as a site request", LogLevel::Info, true); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
} /* -- Seomatic_MetaFieldType */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace Craft; | ||
|
||
class Seomatic_MetaFieldModel extends Seomatic_MetaModel | ||
{ | ||
protected $elementType = 'Seomatic_FieldMeta'; | ||
|
||
/** | ||
* @access protected | ||
* @return array | ||
*/ | ||
protected function defineAttributes() | ||
{ | ||
return array_merge(parent::defineAttributes(), array( | ||
'seoTitleSource' => array(AttributeType::Enum, 'values' => "custom,field", 'default' => 'custom'), | ||
'seoTitleSourceField' => array(AttributeType::String, 'default' => ''), | ||
'seoDescriptionSource' => array(AttributeType::Enum, 'values' => "custom,field", 'default' => 'custom'), | ||
'seoDescriptionSourceField' => array(AttributeType::String, 'default' => ''), | ||
'seoKeywordsSource' => array(AttributeType::Enum, 'values' => "custom,keywords,field", 'default' => 'custom'), | ||
'seoKeywordsSourceField' => array(AttributeType::String, 'default' => ''), | ||
'seoImageIdSource' => array(AttributeType::Enum, 'values' => "custom,field", 'default' => 'custom'), | ||
'seoImageIdSourceField' => array(AttributeType::String, 'default' => ''), | ||
)); | ||
} | ||
|
||
/** | ||
* Returns whether the current user can edit the element. | ||
* | ||
* @return bool | ||
*/ | ||
public function isEditable() | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the element's CP edit URL. | ||
* | ||
* @return string|false | ||
*/ | ||
public function getCpEditUrl() | ||
{ | ||
return ""; | ||
} | ||
|
||
} /* -- class Seomatic_MetaFieldModel */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.