Skip to content

Commit

Permalink
Typos
Browse files Browse the repository at this point in the history
  • Loading branch information
nitriques committed Dec 14, 2012
1 parent 93d5c5e commit c9a500f
Showing 1 changed file with 56 additions and 58 deletions.
114 changes: 56 additions & 58 deletions fields/field.image_preview_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

/**
*
* Field class that will represent an oEmbed resource
* @author Nicolas
*
* Based on @nickdunn's Vimeo field: https://github.com/nickdunn/vimeo_videos/
* Field class that will represent settings for image previews
* @author Deux Huit Huit
*
*/
class FieldImage_Preview_Settings extends Field {
Expand All @@ -26,7 +24,7 @@ class FieldImage_Preview_Settings extends Field {

/**
*
* Constructor for the oEmbed Field object
* Constructor for the Field object
* @param mixed $parent
*/
public function __construct(){
Expand All @@ -44,9 +42,9 @@ public function __construct(){
$this->set('unique', 'no');
// set to show thumbs in table by default
$this->set('thumbs', 'yes');

}

public function isSortable(){
return false;
}
Expand Down Expand Up @@ -94,7 +92,7 @@ public function checkPostFieldData($data, &$message, $entry_id=NULL){

// Always valid, since we do not have any
// entry data

$message = NULL;

return self::__OK__;
Expand Down Expand Up @@ -136,24 +134,24 @@ public function setFromPOST(Array $settings = array()) {

// always display in table mode
$new_settings['show_column'] = 'yes';


// set new settings
$new_settings['field-classes'] = ( $settings['field-handles'] );

//var_dump(isset($settings['table-width']));die;
$new_settings['table-width'] = ( isset($settings['table-width']) ? $settings['table-width'] : NULL);
$new_settings['table-height'] = ( isset($settings['table-height']) ? $settings['table-height'] : NULL);
$new_settings['table-resize'] = ( isset($settings['table-resize']) ? $settings['table-resize'] : NULL);
$new_settings['table-position'] = ( isset($settings['table-position']) ? $settings['table-position'] : NULL);
$new_settings['table-absolute'] = ( isset($settings['table-absolute']) && $settings['table-absolute'] == 'on' ? 'yes' : 'no');

$new_settings['entry-width'] = ( isset($settings['entry-width']) ? $settings['entry-width'] : NULL);
$new_settings['entry-height'] = ( isset($settings['entry-height']) ? $settings['entry-height'] : NULL);
$new_settings['entry-resize'] = ( isset($settings['entry-resize']) ? $settings['entry-resize'] : NULL);
$new_settings['entry-position'] = ( isset($settings['entry-position']) ? $settings['entry-position'] : NULL);
$new_settings['entry-absolute'] = ( isset($settings['entry-absolute']) && $settings['entry-absolute'] == 'on' ? 'yes' : 'no');

// save it into the array
$this->setArray($new_settings);
}
Expand All @@ -165,19 +163,19 @@ public function setFromPOST(Array $settings = array()) {
*/
public function checkFields(Array &$errors, $checkForDuplicates) {
parent::checkFields($errors, $checkForDuplicates);

$field_handles = $this->get('field-handles');

if (empty($field_handles)) {
$errors['field-handles'] = __('You must set at least one field handle or * to enable those settings for all fields in this section');
}

foreach ($this->prefixes as $key => $prefix) {
$width = $this->get($prefix.'width');
$height = $this->get($prefix.'height');
$resize = $this->get($prefix.'resize');
$position = $this->get($prefix.'position');

if (!empty($width) && (!is_numeric($width) || intval($width) < 0)) {
$errors[$prefix.'width'] = __('Width must be a positive integer');
}
Expand All @@ -191,7 +189,7 @@ public function checkFields(Array &$errors, $checkForDuplicates) {
$errors[$prefix.'position'] = __('Position must be a positive integer between 1 and 9');
}
}

return (!empty($errors) ? self::__ERROR__ : self::__OK__);
}

Expand All @@ -203,21 +201,21 @@ public function commit() {

// if the default implementation works...
if(!parent::commit()) return FALSE;

$id = $this->get('id');

// exit if there is no id
if($id == false) return FALSE;

// declare an array contains the field's settings
$settings = array();

$t_width = $this->get('table-width');
$t_height = $this->get('table-height');
$t_resize = $this->get('table-resize');
$t_position = $this->get('table-position');
$t_absolute = $this->get('table-absolute');

$e_width = $this->get('entry-width');
$e_height = $this->get('entry-height');
$e_resize = $this->get('entry-resize');
Expand All @@ -226,7 +224,7 @@ public function commit() {

// the field id
$settings['field_id'] = $id;

// the related fields handles
$settings['field-handles'] = $this->get('field-handles');

Expand All @@ -236,14 +234,14 @@ public function commit() {
$settings['table-resize'] = empty($t_resize) ? NULL : $t_resize;
$settings['table-position'] = empty($t_position) ? NULL : $t_position;
$settings['table-absolute'] = empty($t_absolute) ? 'no' : $t_absolute;

// the 'entry' settings
$settings['entry-width'] = empty($e_width) ? NULL : $e_width;
$settings['entry-height'] = empty($e_height) ? NULL : $e_height;
$settings['entry-resize'] = empty($e_resize) ? NULL : $e_resize;
$settings['entry-position'] = empty($e_position) ? NULL : $e_position;
$settings['entry-absolute'] = empty($e_absolute) ? 'no' : $e_absolute;

// DB
$tbl = self::FIELD_TBL_NAME;

Expand Down Expand Up @@ -285,28 +283,28 @@ public function appendFormattedElement(&$wrapper, $data) {

private function convertHandlesIntoIds($handles) {
$ids = '';

if (!empty($handles) && $handles != '*' ) {
$aHandles = explode(',', $handles);
$parent_section = $this->get('parent_section');

foreach ($aHandles as $handle) {
$where = "AND t1.`element_name` = '$handle'";
$field = FieldManager::fetch(NULL, $parent_section, 'ASC', 'sortorder', NULL, NULL, $where);
$fieldId = array_keys($field);
$fieldId = $fieldId[0];

if (!empty($fieldId)) {
$ids .= 'field-' . $field[$fieldId]->get('id') . ',';
}
}
} else {
$ids = '*'; // valid for all fields
}
return $ids;

return $ids;
}

/**
*
* Builds the UI for the publish page
Expand All @@ -320,14 +318,14 @@ public function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL,

// only set data-attributes
$params = new XMLElement('div');

$params->setAttribute('data-field-classes', $this->convertHandlesIntoIds($this->get('field-handles')));
$params->setAttribute('data-width', $this->get('entry-width'));
$params->setAttribute('data-height', $this->get('entry-height'));
$params->setAttribute('data-resize', $this->get('entry-resize'));
$params->setAttribute('data-position', $this->get('entry-position'));
$params->setAttribute('data-absolute', $this->get('entry-absolute'));

$wrapper->appendChild($params);
}

Expand All @@ -341,40 +339,40 @@ public function displaySettingsPanel(&$wrapper, $errors=NULL){

/* first line, label and such */
parent::displaySettingsPanel($wrapper, $errors);

$handles_wrap = new XMLElement('div', NULL, array('class' => 'image_preview'));
$handles_wrap->appendChild( $this->createInput('Fields handles <i>Type * for all fields; Comma separated list for multiple fields</i>', 'field-handles', $errors) );
$wrapper->appendChild($handles_wrap);

foreach ($this->prefixes as $key => $prefix) {
/* new line, settings */
$set_wrap = new XMLElement('div', NULL, array('class' => 'compact image_preview'));
$set_wrap->appendChild( new XMLElement('label', __($key . ' Preview settings')) );

/* new line, width/height */
$wh_wrap = new XMLElement('div', NULL, array('class' => 'two columns'));
$wh_wrap->appendChild($this->createInput('Width <i>JIT image manipulation width parameter</i>', $prefix.'width', $errors));
$wh_wrap->appendChild($this->createInput('Height <i>JIT image manipulation height parameter</i>', $prefix.'height', $errors));


/* new line, resize/position */
$rp_wrap = new XMLElement('div', NULL, array('class' => 'two columns'));
$rp_wrap->appendChild($this->createInput('Resize <i>JIT image manipulation resize mode [1-3]</i>', $prefix.'resize', $errors));
$rp_wrap->appendChild($this->createInput('Position <i>JIT image manipulation position parameter [1-9]</i>', $prefix.'position', $errors));

/* new line, absolute */
$a_wrap = new XMLElement('div', NULL, array('class' => 'two columns'));
$a_wrap->appendChild($this->createCheckbox('Absolute ? <i>Makes the image absolute</i>', $prefix.'absolute', $errors));


/* append to wrapper */
$wrapper->appendChild($set_wrap);
$wrapper->appendChild($wh_wrap);
$wrapper->appendChild($rp_wrap);
$wrapper->appendChild($a_wrap);
}


}


Expand All @@ -387,15 +385,15 @@ private function createInput($text, $key, $errors=NULL) {
'name' => "fields[$order][$key]"
));
$input->setSelfClosingTag(true);

$lbl->prependChild($input);

//var_dump($errors[$key]);

if (isset($errors[$key])) {
$lbl = Widget::wrapFormElementWithError($lbl, $errors[$key]);
}

return $lbl;
}

Expand All @@ -407,19 +405,19 @@ private function createCheckbox($text, $key) {
'name' => "fields[$order][$key]"
));
$input->setSelfClosingTag(true);

if ($this->get($key) == 'yes') {
$input->setAttribute('checked','checked');
}

$lbl->prependChild($input);

return $lbl;
}


private $tableValueGenerated = FALSE;

/**
*
* Build the UI for the table view
Expand All @@ -428,8 +426,8 @@ private function createCheckbox($text, $key) {
* @return string - the html of the link
*/
public function prepareTableValue($data, XMLElement $link=NULL){
if (!$this->tableValueGenerated) {

if (!$this->tableValueGenerated) {

$this->tableValueGenerated = TRUE;

Expand All @@ -438,18 +436,18 @@ public function prepareTableValue($data, XMLElement $link=NULL){
// if not, wrap our html with a external link to the resource url
$link = new XMLElement('div');
}

$link->setAttribute('data-field-classes', $this->convertHandlesIntoIds($this->get('field-handles')));
$link->setAttribute('data-width', $this->get('table-width'));
$link->setAttribute('data-height', $this->get('table-height'));
$link->setAttribute('data-resize', $this->get('table-resize'));
$link->setAttribute('data-position', $this->get('table-position'));
$link->setAttribute('data-absolute', $this->get('table-absolute'));

// returns the link's html code
return $link->generate();


}
return NULL;
}
Expand Down Expand Up @@ -485,18 +483,18 @@ public function tearDown() {
* Creates table needed for entries of invidual fields
*/
public function createTable(){

return Symphony::Database()->query(

"CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` (
`id` int(11) unsigned NOT NULL auto_increment,
`entry_id` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `entry_id` (`entry_id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"

);

//return FALSE;
}

Expand Down

0 comments on commit c9a500f

Please sign in to comment.