/**
  * Map a row to an array that can be parsed by
  * insert_item() or insert_files_for_item().
  *
  * @param array $row The row to map
  * @param array $result
  * @return array The result
  */
 public function map($row, $result)
 {
     $filter = new Omeka_Filter_HtmlPurifier();
     $text = $filter->filter($row[$this->_columnName]);
     if ($this->_elementDelimiter == '') {
         $texts = array($text);
     } else {
         $texts = explode($this->_elementDelimiter, $text);
     }
     if ($this->_elementId) {
         foreach ($texts as $text) {
             $result[] = array('element_id' => $this->_elementId, 'html' => $this->_isHtml ? 1 : 0, 'text' => $text);
         }
     }
     return $result;
 }
示例#2
0
 public function hookInitialize()
 {
     $purifier = Omeka_Filter_HtmlPurifier::getHtmlPurifier();
     $purifier->config->set('Attr.EnableID', true);
 }
示例#3
0
 protected function _getHtmlPurifier($allowedHtmlElements = null, $allowedHtmlAttributes = null)
 {
     $htmlPurifier = Omeka_Filter_HtmlPurifier::createHtmlPurifier($allowedHtmlElements, $allowedHtmlAttributes);
     Omeka_Filter_HtmlPurifier::setHtmlPurifier($htmlPurifier);
     return $htmlPurifier;
 }
示例#4
0
 private function _addOptions()
 {
     $task = new Installer_Task_Options();
     $task->setOptions(array('administrator_email' => $this->_getValue('administrator_email'), 'copyright' => $this->_getValue('copyright'), 'site_title' => $this->_getValue('site_title'), 'author' => $this->_getValue('author'), 'description' => $this->_getValue('description'), 'thumbnail_constraint' => $this->_getValue('thumbnail_constraint'), 'square_thumbnail_constraint' => $this->_getValue('square_thumbnail_constraint'), 'fullsize_constraint' => $this->_getValue('fullsize_constraint'), 'per_page_admin' => $this->_getValue('per_page_admin'), 'per_page_public' => $this->_getValue('per_page_public'), 'show_empty_elements' => $this->_getValue('show_empty_elements'), 'path_to_convert' => $this->_getValue('path_to_convert'), Theme::ADMIN_THEME_OPTION => Installer_Default::DEFAULT_ADMIN_THEME, Theme::PUBLIC_THEME_OPTION => Installer_Default::DEFAULT_PUBLIC_THEME, Omeka_Validate_File_Extension::WHITELIST_OPTION => Omeka_Validate_File_Extension::DEFAULT_WHITELIST, Omeka_Validate_File_MimeType::WHITELIST_OPTION => Omeka_Validate_File_MimeType::DEFAULT_WHITELIST, File::DISABLE_DEFAULT_VALIDATION_OPTION => (string) (!extension_loaded('fileinfo')), Omeka_Db_Migration_Manager::VERSION_OPTION_NAME => OMEKA_VERSION, 'display_system_info' => true, 'html_purifier_is_enabled' => 1, 'html_purifier_allowed_html_elements' => implode(',', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlElements()), 'html_purifier_allowed_html_attributes' => implode(',', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlAttributes()), 'tag_delimiter' => ',', Omeka_Navigation::PUBLIC_NAVIGATION_MAIN_OPTION_NAME => Omeka_Navigation::getNavigationOptionValueForInstall(Omeka_Navigation::PUBLIC_NAVIGATION_MAIN_OPTION_NAME), 'search_record_types' => serialize(get_search_record_types()), 'api_enable' => false, 'api_per_page' => 50, 'show_element_set_headings' => 1));
     $task->install($this->_db);
 }
示例#5
0
 protected function _setupHtmlPurifierOptions()
 {
     if (get_option('html_purifier_is_enabled') === null) {
         set_option('html_purifier_is_enabled', '1');
     }
     if (get_option('html_purifier_allowed_html_elements') === null) {
         set_option('html_purifier_allowed_html_elements', implode(',', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlElements()));
     }
     if (get_option('html_purifier_allowed_html_attributes') === null) {
         set_option('html_purifier_allowed_html_attributes', implode(',', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlAttributes()));
     }
 }
示例#6
0
 public function getHtmlPurifierAllowedHtmlAttributesAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     if ($this->_getParam('default')) {
         $body = implode(',', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlAttributes());
     } else {
         $body = get_option('html_purifier_allowed_html_attributes');
     }
     $this->getResponse()->setBody($body);
 }
 /**
  * Sets the html purifier singleton
  *
  * @param HTMLPurifier $purifier
  * @return void
  */
 public static function setHtmlPurifier($purifier)
 {
     self::$_purifier = $purifier;
     // Set this in the registry so that other plugins can get to it.
     Zend_Registry::set('html_purifier', $purifier);
 }
示例#8
0
 public function testHtmlPurifyCollectionFormWithAllowedAndUnallowedElementsAndAttributesInDescription()
 {
     $this->assertTrue(in_array('strong', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlElements()));
     $this->assertTrue(in_array('p', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlElements()));
     $this->assertFalse(in_array('j', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlElements()));
     $this->assertTrue(in_array('*.class', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlAttributes()));
     $this->assertFalse(in_array('*.id', Omeka_Filter_HtmlPurifier::getDefaultAllowedHtmlAttributes()));
     $dirtyHtml = '<p class="person" id="person">Bob is bad <j>and mean<j> and <strong id="trait">fun</strong>.</p>';
     $cleanHtml = '<p class="person">Bob is bad and mean and <strong>fun</strong>.</p>';
     $post = $this->_addElementTextWithDirtyHtmlToPost($dirtyHtml, 'Dublin Core', 'Title');
     $this->getRequest()->setMethod('POST');
     $this->getRequest()->setPost($post);
     $this->dispatch('/collections/edit/' . $this->collection->id);
     $collectionAfter = $this->db->getTable('Collection')->find($this->collection->id);
     $this->assertEquals($cleanHtml, metadata($collectionAfter, array('Dublin Core', 'Title')));
 }
示例#9
0
 public function testFilterAttributesWithMissingElements()
 {
     $htmlElements = array();
     $dirtyHtmlAttributes = array('strong.id', 'div.class', '*.class', 'p.id', 'a.href');
     $cleanHtmlAttributes = array();
     $this->assertEquals($cleanHtmlAttributes, Omeka_Filter_HtmlPurifier::filterAttributesWithMissingElements($dirtyHtmlAttributes, $htmlElements));
     $htmlElements = array('h1');
     $dirtyHtmlAttributes = array('strong.id', 'div.class', '*.class', 'p.id', 'a.href');
     $cleanHtmlAttributes = array('*.class');
     $this->assertEquals($cleanHtmlAttributes, Omeka_Filter_HtmlPurifier::filterAttributesWithMissingElements($dirtyHtmlAttributes, $htmlElements));
     $htmlElements = array('p', 'strong');
     $dirtyHtmlAttributes = array('strong.id', 'div.class', '*.class', 'p.id', 'a.href');
     $cleanHtmlAttributes = array('strong.id', '*.class', 'p.id');
     $this->assertEquals($cleanHtmlAttributes, Omeka_Filter_HtmlPurifier::filterAttributesWithMissingElements($dirtyHtmlAttributes, $htmlElements));
 }