/**
  * Adds a property with the name & type specified. This is used while setting up the config system.
  * @param ref object $field A {@link SchemaField} defining the properties of this field.
  * @param optional object $default The default value for this property. Must be the correct class that is associated
  * with the {@link SchemaField} type value, as defined by the DataTypeManager.
  * @access public
  * @return void
  */
 function addProperty($field, $default = null)
 {
     $typeManager = Services::getService("DataTypeManager");
     if ($default == null || $typeManager->isObjectOfDataType($default, $field->getType())) {
         $this->_schema->addField($field);
         if ($default) {
             $this->_defaults[$field->getLabel()] = $default;
         }
     }
 }
/**
 * Allows a module to change the contents of the $document object before it is
 * sent to the Solr Server. To add a new field to the document you should
 * generally use one of the pre-defined dynamic fields. Follow the naming
 * conventions for the type of data being added based on the schema.xml file.
 *
 * @param object $document
 *   The ApacheSolrDocument instance. No need for &.
 * @param object $node
 *   The node object which is being indexed.
 * @param string $namespace
 *   Usually the calling module (eg. 'apachesolr_search').
 */
function HOOK_apachesolr_update_index($document, $node, $namespace)
{
    // Add the full node object of 'story' nodes to the index.
    if ($node->type == 'story') {
        $document->addField('tm_node', urlencode(serialize(node_load($node->nid))));
    }
}
 /**
  * Parses fields for saving into the database, results are stored in $this->out_fields
  *
  * @param	array	$field_data	Array that contains the fields to parse, usually $this->request
  * @return	@e void
  */
 public function parseToSave($field_data, $mode = 'normal')
 {
     /* Parse the fields */
     $save_fields = $this->cfields_obj->getFieldsToSave($field_data);
     /* Save the raw error data */
     $this->error_fields = $save_fields['errors'];
     /* Reformat the errors into nicer output */
     if (is_array($this->error_fields) && count($this->error_fields)) {
         /* Make sure error message texts are loaded */
         ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_profile'), 'members');
         foreach ($this->error_fields as $id => $err) {
             /* Can we view this field? */
             if (!$this->_checkFieldAuth($this->cfields[str_replace('field_', '', $id)], $mode)) {
                 continue;
             }
             $_error_messages = array();
             foreach ($err as $e) {
                 $_error_messages[] = ipsRegistry::getClass('class_localization')->words['profile_field_error__' . $e];
             }
             $this->error_messages[$id] = $this->cache_data[str_replace('field_', '', $id)]['pf_title'] . ': ' . implode(', ', $_error_messages);
         }
     }
     /* Loop through our custom fields */
     foreach ($this->cfields as $id => $field) {
         /* Can we view this field? */
         if (!$this->_checkFieldAuth($field, $mode)) {
             continue;
         }
         /* Now add any missing content fields */
         if (!isset($this->member_data['field_' . $id]) or IN_ACP) {
             if (!$this->DB->checkForField("field_{$id}", 'pfields_content') and !isset($this->_addedFields[$id])) {
                 $this->DB->addField('pfields_content', "field_{$id}", 'text');
                 $this->_addedFields[$id] = $id;
             }
         }
         $this->out_fields['field_' . $id] = IPSText::getTextClass('bbcode')->stripBadWords($save_fields['save_array']['field_' . $id]);
         //-----------------------------------------
         // Blacklisted urls
         // @link	http://community.invisionpower.com/tracker/issue-7872-url-black-list-in-profile/
         //-----------------------------------------
         if ($this->cache_data[$id]['restrictions']['urlfilter'] and !IPSText::getTextClass('bbcode')->checkBlacklistUrls($save_fields['save_array']['field_' . $id])) {
             /* Make sure error message texts are loaded */
             ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_profile'), 'members');
             if (isset($this->error_messages['field_' . $id])) {
                 $this->error_messages['field_' . $id] .= ', ' . ipsRegistry::getClass('class_localization')->words['profile_field_error__blacklist'];
             } else {
                 $this->error_messages['field_' . $id] = $this->cache_data[$id]['pf_title'] . ': ' . ipsRegistry::getClass('class_localization')->words['profile_field_error__blacklist'];
             }
         }
     }
     //print_r($this->error_messages);
 }
 /**
  * Form generator for admin area
  * @param object $fieldset - Varien_Data_Form_Element_Fieldset object
  * @param object $collection - array of Mage_Eav_Model_Mysql4_Entity_Attribute
  * @param array $attributeValues - array of values as [attribute_code]-> [mixed:value]
  * 
  * @refactor Split and move to block
  */
 public function prepareAdminForm($fieldset, $collection, $suffix, $attributeValues = '', $bById = false)
 {
     foreach ($collection as $attribute) {
         if ($inputType = $attribute->getFrontend()->getInputType()) {
             $yesNo = false;
             if ($inputType !== 'static') {
                 $class = '';
                 $exclReq = false;
                 if ($inputType === 'boolean') {
                     $inputType = "select";
                     $yesNo = $this->getYesNo();
                 }
                 if ($inputType === 'radio') {
                     $inputType = 'radios';
                     $exclReq = true;
                 }
                 if ($inputType === 'checkbox') {
                     $inputType = 'checkboxes';
                     $exclReq = true;
                 }
                 $elementName = $bById ? 'aitoc_checkout_' . $attribute->getId() : $attribute->getAttributeCode();
                 if (in_array($inputType, array('select', 'multiselect', 'radios', 'checkboxes')) && !$yesNo) {
                     $options = $attribute->getSource()->getAllOptions(false);
                 }
                 if ($inputType !== 'checkboxes') {
                     $element = $fieldset->addField($attribute->getAttributeCode(), $inputType, array('name' => $suffix . '[' . $elementName . ']' . ($inputType === 'checkboxes' ? '[]' : ''), 'label' => $attribute->getFrontend()->getLabel(), 'required' => $exclReq ? 0 : $attribute->getIsRequired(), 'value' => isset($attributeValues[$attribute->getAttributeCode()]) ? is_array($attributeValues[$attribute->getAttributeCode()]) ? $attributeValues[$attribute->getAttributeCode()] : htmlspecialchars_decode($attributeValues[$attribute->getAttributeCode()]) : $attribute->getDefaultValue(), 'note' => current($this->getAttributeDescription($attribute->getId()))));
                 }
                 // fix for internal magento bug with required radios
                 if ($inputType === 'radios') {
                     $element->setData('separator', '</td></tr><tr><td class="label"></td><td class="value">');
                     if ($attribute->getIsRequired()) {
                         $element->setData('label', $element->getData('label') . '__*__');
                         $element->addClass('validate-one-required-by-name');
                     }
                     $element->addClass('product-custom-option');
                 }
                 // fix for internal magento bug with required checkboxes
                 if ($inputType === 'checkboxes') {
                     $i = 0;
                     foreach ($options as $option) {
                         if (!isset($attributeValues[$attribute->getAttributeCode()])) {
                             $defaultValues = explode(',', $attribute->getDefaultValue());
                             $attributeValues[$attribute->getAttributeCode()] = $defaultValues;
                         }
                         $label = $attribute->getFrontend()->getLabel() . ($attribute->getIsRequired() ? '__*__' : '');
                         $fieldset->addField($attribute->getAttributeCode() . '_' . $option['value'], 'checkbox', array('label' => $i == 0 ? $label : '', 'name' => $suffix . '[' . $elementName . '][]', 'checked' => in_array($option['value'], $attributeValues[$attribute->getAttributeCode()]) ? 'checked' : '', 'value' => $option['value'], 'disabled' => false, 'class' => $attribute->getIsRequired() ? 'validate-one-required-by-name' : '', 'after_element_html' => '<label for="' . $attribute->getAttributeCode() . '_' . $option['value'] . '">' . $option['label'] . '</label>'));
                         $i++;
                     }
                 }
                 if ($inputType === 'date') {
                     $element->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
                     $element->setImage(Mage::getDesign()->getSkinUrl('images/grid-cal.gif'));
                     $element->setValue(isset($attributeValues[$attribute->getAttributeCode()]) ? $attributeValues[$attribute->getAttributeCode()] : $attribute->getDefaultValue(), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
                 }
                 if (in_array($inputType, array('select', 'multiselect', 'radios', 'checkboxes'))) {
                     if (is_array($yesNo)) {
                         $element->setValues($yesNo);
                     } else {
                         if ($inputType === 'radios' && !$attribute->getIsRequired()) {
                             array_unshift($options, array('value' => '', 'label' => Mage::helper('catalog')->__('None')));
                         }
                         if ($inputType === 'select') {
                             array_unshift($options, array('value' => '', 'label' => Mage::helper('catalog')->__('Please select')));
                         }
                         if ($inputType !== 'checkboxes') {
                             $element->setValues($options);
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Parses fields for saving into the database, results are stored in $this->out_fields
  *
  * @access	public
  * @param	array	$field_data	Array that contains the fields to parse, usually $this->request
  * @return	void
  */
 public function parseToSave($field_data, $mode = 'normal')
 {
     /* Parse the fields */
     $save_fields = $this->cfields_obj->getFieldsToSave($field_data);
     /* Save the raw error data */
     $this->error_fields = $save_fields['errors'];
     /* Reformat the errors into nicer output */
     if (is_array($this->error_fields) && count($this->error_fields)) {
         /* Make sure error message texts are loaded */
         ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_profile'), 'members');
         foreach ($this->error_fields as $id => $err) {
             /* Can we view this field? */
             if (!$this->_checkFieldAuth($this->cfields[str_replace('field_', '', $id)], $mode)) {
                 continue;
             }
             $_error_messages = array();
             foreach ($err as $e) {
                 $_error_messages[] = ipsRegistry::getClass('class_localization')->words['profile_field_error__' . $e];
             }
             $this->error_messages[$id] = $this->cache_data[str_replace('field_', '', $id)]['pf_title'] . ': ' . implode(', ', $_error_messages);
         }
     }
     /* Loop through our custom fields */
     foreach ($this->cfields as $id => $field) {
         /* Can we view this field? */
         if (!$this->_checkFieldAuth($field, $mode)) {
             continue;
         }
         /* Now add any missing content fields */
         if (!isset($this->member_data['field_' . $id])) {
             if (!$this->DB->checkForField("field_{$id}", 'pfields_content')) {
                 $this->DB->addField('pfields_content', "field_{$id}", 'text');
             }
         }
         $this->out_fields['field_' . $id] = IPSText::getTextClass('bbcode')->stripBadWords($save_fields['save_array']['field_' . $id]);
     }
 }