protected function _separatorToSeparatorFilter($value)
 {
     if ($this->_searchSeparator == null) {
         require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception('You must provide a search separator for this filter to work.');
     }
     $this->setMatchPattern('#' . preg_quote($this->_searchSeparator, '#') . '#');
     $this->setReplacement($this->_replacementSeparator);
     return parent::filter($value);
 }
Beispiel #2
0
 public function init()
 {
     $this->setMethod('post');
     // Hidden referrer url
     $urlFilter = new Zend_Filter_PregReplace();
     // Filter to remove any host names
     $urlFilter->setMatchPattern('/[a-zA-Z0-9]*:\\/\\/.*\\//');
     $urlFilter->setReplacement('/');
     $this->addElement('hidden', 'referrerUrl', array('required' => false, 'filters' => array($urlFilter)));
     // Email entry
     $this->addElement('text', 'email', array('required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your email address'))))));
     // Modify email error messages & add validator
     $emailValidator = new Zend_Validate_EmailAddress();
     $emailValidator->setMessages(array(Zend_Validate_EmailAddress::INVALID_HOSTNAME => "Domain name invalid in email address", Zend_Validate_EmailAddress::INVALID_FORMAT => "Invalid email address"));
     $this->getElement('email')->addValidator($emailValidator);
     // Password entry
     $this->addElement('password', 'password', array('required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your password'))))));
     // Set up the element decorators
     $this->setElementDecorators(array('ViewHelper', 'Label', 'Errors'));
     // Add the submit button
     $this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Retrieve My Quotes', 'class' => 'btn btn-primary pull-left'));
     // Add a resend validation link button
     $this->addElement('submit', 'resendValidation', array('ignore' => true, 'label' => 'Resend Account Validation', 'class' => 'btn btn-primary'));
     // Add a forgotten password button
     $this->addElement('submit', 'forgottenPassword', array('ignore' => true, 'label' => 'Reset Password', 'class' => 'btn btn-primary'));
     // Remove the label from the submit buttons
     $element = $this->getElement('submit');
     $element->removeDecorator('label');
     $element = $this->getElement('resendValidation');
     $element->removeDecorator('label');
     $element = $this->getElement('forgottenPassword');
     $element->removeDecorator('label');
     // Set up the decorator on the form and add in decorators which are removed
     /*$this->addDecorator('FormElements')
       ->addDecorator(
           'HtmlTag', 
           array('tag' => 'div', 'class' => 'form_section one-col')
           )
       ->addDecorator('Form');*/
     $this->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div')), 'Form'));
 }
 public function __construct(array $config = array())
 {
     parent::__construct($config);
     $process = new Diggin_Scraper_Process();
     $process->setExpression($config['expression']);
     $process->setName('kumo');
     $process->setArrayFlag(isset($config['arrayflag']) ? (bool) $config['arrayflag'] : true);
     $process->setType(isset($config['type']) ? $config['type'] : 'TEXT');
     // use only first filter
     if (isset($config['filters'])) {
         if (($match = $config['filters']['matchpattern']) && ($replace = $config['filters']['replacement'])) {
             require_once 'Zend/Filter/PregReplace.php';
             $pregreplace = new Zend_Filter_PregReplace();
             $pregreplace->setMatchPattern($match);
             $pregreplace->setReplacement($replace);
             $process->setFilters(array($pregreplace));
         }
     }
     $this->scraper = new Diggin_Scraper();
     $this->scraper->process($process);
 }
Beispiel #4
0
 /**
  * Generates a set of radio button elements.
  *
  * @access public
  *
  * @param string|array $name If a string, the element name.  If an
  * array, all other parameters are ignored, and the array elements
  * are extracted in place of added parameters.
  *
  * @param mixed $value The radio value to mark as 'checked'.
  *
  * @param array $options An array of key-value pairs where the array
  * key is the radio value, and the array value is the radio text.
  *
  * @param array|string $attribs Attributes added to each radio.
  *
  * @return string The radio buttons XHTML.
  */
 public function formRadio($name, $value = null, $attribs = null, $options = null, $listsep = "<br />\n")
 {
     $info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
     extract($info);
     // name, value, attribs, options, listsep, disable
     // retrieve attributes for labels (prefixed with 'label_' or 'label')
     $label_attribs = array();
     foreach ($attribs as $key => $val) {
         $tmp = false;
         $keyLen = strlen($key);
         if (6 < $keyLen && substr($key, 0, 6) == 'label_') {
             $tmp = substr($key, 6);
         } elseif (5 < $keyLen && substr($key, 0, 5) == 'label') {
             $tmp = substr($key, 5);
         }
         if ($tmp) {
             // make sure first char is lowercase
             $tmp[0] = strtolower($tmp[0]);
             $label_attribs[$tmp] = $val;
             unset($attribs[$key]);
         }
     }
     $labelPlacement = 'append';
     foreach ($label_attribs as $key => $val) {
         switch (strtolower($key)) {
             case 'placement':
                 unset($label_attribs[$key]);
                 $val = strtolower($val);
                 if (in_array($val, array('prepend', 'append'))) {
                     $labelPlacement = $val;
                 }
                 break;
         }
     }
     // the radio button values and labels
     $options = (array) $options;
     // build the element
     $xhtml = '';
     $list = array();
     // should the name affect an array collection?
     $name = $this->view->escape($name);
     if ($this->_isArray && '[]' != substr($name, -2)) {
         $name .= '[]';
     }
     // ensure value is an array to allow matching multiple times
     $value = (array) $value;
     // Set up the filter - Alnum + hyphen + underscore
     // require_once 'Zend/Filter/PregReplace.php';
     $pattern = @preg_match('/\\pL/u', 'a') ? '/[^\\p{L}\\p{N}\\-\\_]/u' : '/[^a-zA-Z0-9\\-\\_]/';
     // No Unicode
     $filter = new Zend_Filter_PregReplace($pattern, "");
     // add radio buttons to the list.
     foreach ($options as $opt_value => $opt_label) {
         // Should the label be escaped?
         if ($escape) {
             $opt_label = $this->view->escape($opt_label);
         }
         // is it disabled?
         $disabled = '';
         if (true === $disable) {
             $disabled = ' disabled="disabled"';
         } elseif (is_array($disable) && in_array($opt_value, $disable)) {
             $disabled = ' disabled="disabled"';
         }
         // is it checked?
         $checked = '';
         if (in_array($opt_value, $value)) {
             $checked = ' checked="checked"';
         }
         // generate ID
         $optId = $id . '-' . $filter->filter($opt_value);
         // Wrap the radios in labels
         $radio = '<label' . $this->_htmlAttribs($label_attribs) . '>' . ('prepend' == $labelPlacement ? $opt_label : '') . '<input type="' . $this->_inputType . '"' . ' name="' . $name . '"' . ' id="' . $optId . '"' . ' value="' . $this->view->escape($opt_value) . '"' . $checked . $disabled . $this->_htmlAttribs($attribs) . $this->getClosingBracket() . ('append' == $labelPlacement ? $opt_label : '') . '</label>';
         // add to the array of radio buttons
         $list[] = $radio;
     }
     // XHTML or HTML for standard list separator?
     if (!$this->_isXhtml() && false !== strpos($listsep, '<br />')) {
         $listsep = str_replace('<br />', '<br>', $listsep);
     }
     // done!
     $xhtml .= implode($listsep, $list);
     return $xhtml;
 }
Beispiel #5
0
 /**
  * Method to cache the regex needed to determine if unicode support is available
  *
  * @return bool
  */
 protected static function _determineUnicodeSupport()
 {
     self::$_unicodeSupportEnabled = @preg_match('/\\pL/u', 'a') ? true : false;
 }
Beispiel #6
0
 public function clean($pageUrl)
 {
     $filter = new Zend_Filter_PregReplace(array('match' => '/\\.html$/', 'replace' => ''));
     return $filter->filter($pageUrl);
 }
Beispiel #7
0
 /**
  * Generates a set of radio button elements.
  *
  * @access public
  *
  * @param string|array $name If a string, the element name.  If an
  * array, all other parameters are ignored, and the array elements
  * are extracted in place of added parameters.
  *
  * @param mixed $value The radio value to mark as 'checked'.
  *
  * @param array|string $attribs Attributes added to each radio.
  *
  * @param array $options An array of key-value pairs where the array
  * key is the radio value, and the array value is the radio text.
  *
  * @param string $listsep
  * @return string The radio buttons XHTML.
  * @throws Zend_Filter_Exception
  */
 public function form_MultiCheckboxDataTable($name, $value = null, $attribs = null, $options = null, $listsep = "<br />\n")
 {
     $info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
     extract($info);
     /**
      * @var $name
      * @var $value
      * @var $attribs
      * @var $options
      * @var $listsep
      * @var $disable
      * @var $id
      * @var $escape
      */
     // retrieve attributes for labels (prefixed with 'label_' or 'label')
     $label_attribs = array();
     foreach ($attribs as $key => $val) {
         $tmp = false;
         $keyLen = strlen($key);
         if (6 < $keyLen && substr($key, 0, 6) == 'label_') {
             $tmp = substr($key, 6);
         } elseif (5 < $keyLen && substr($key, 0, 5) == 'label') {
             $tmp = substr($key, 5);
         }
         if ($tmp) {
             // make sure first char is lowercase
             $tmp[0] = strtolower($tmp[0]);
             $label_attribs[$tmp] = $val;
             unset($attribs[$key]);
         }
     }
     $labelPlacement = 'append';
     foreach ($label_attribs as $key => $val) {
         switch (strtolower($key)) {
             case 'placement':
                 unset($label_attribs[$key]);
                 $val = strtolower($val);
                 if (in_array($val, array('prepend', 'append'))) {
                     $labelPlacement = $val;
                 }
                 break;
         }
     }
     // the radio button values and labels
     $options = (array) $options;
     $columnFilter = array("sPlaceHolder" => "head:after", "aoColumns" => [null, array("type" => "text"), array("type" => "text"), array("type" => "text"), array("type" => "text")]);
     $columnFilterJson = json_encode($columnFilter);
     // build the element
     $xhtml = '<table class="table table-striped table-condensed table-hover table-columnfilter table-checkable datatable"
     data-widget="false"
    data-paging="false"
    data-columnFilter=\'' . $columnFilterJson . '\'
    data-columnFilter-select2="true"
    data-searching="true"
    width="100%">';
     $xhtml .= '<thead><tr>';
     $firstRow = $options[key($options)];
     $xhtml .= '<th class="checkbox-column"><input type="checkbox" class="uniform"></th>';
     foreach ($firstRow as $collName => $valll) {
         $xhtml .= '<th>' . $collName . '</th>';
     }
     $xhtml .= '</tr></thead><tbody>';
     $list = array();
     // should the name affect an array collection?
     $name = $this->view->escape($name);
     if ($this->_isArray && '[]' != substr($name, -2)) {
         $name .= '[]';
     }
     // ensure value is an array to allow matching multiple times
     $value = (array) $value;
     // Set up the filter - Alnum + hyphen + underscore
     require_once 'Zend/Filter/PregReplace.php';
     $pattern = @preg_match('/\\pL/u', 'a') ? '/[^\\p{L}\\p{N}\\-\\_]/u' : '/[^a-zA-Z0-9\\-\\_]/';
     // No Unicode
     $filter = new Zend_Filter_PregReplace($pattern, "");
     // add radio buttons to the list.
     foreach ($options as $opt_value => $fields) {
         // is it disabled?
         $disabled = '';
         if (true === $disable) {
             $disabled = ' disabled="disabled"';
         } elseif (is_array($disable) && in_array($opt_value, $disable)) {
             $disabled = ' disabled="disabled"';
         }
         // is it checked?
         $checked = '';
         if (in_array($opt_value, $value)) {
             $checked = ' checked="checked"';
         }
         // generate ID
         $optId = $id . '-' . $filter->filter($opt_value);
         // Wrap the radios in labels
         $radio = '<label' . $this->_htmlAttribs($label_attribs) . '>' . '<input type="' . $this->_inputType . '"' . ' name="' . $name . '"' . ' id="' . $optId . '"' . ' value="' . $this->view->escape($opt_value) . '"' . $checked . $disabled . $this->_htmlAttribs($attribs) . $this->getClosingBracket() . '</label>';
         // add to the array of radio buttons
         $line = '<tr><td class="checkbox-column">' . $radio . '</td>';
         foreach ($fields as $labels) {
             $line .= '<td>' . $labels . '</td>';
         }
         $list[] = $line . '</tr>';
     }
     // done!
     $xhtml .= implode("\n", $list);
     $xhtml .= '</tbody></table>';
     return $xhtml;
 }
Beispiel #8
0
 public function testPassingReplacementToConstructorSetsReplacement()
 {
     $replace = 'foo/bar';
     $filter = new Zend_Filter_PregReplace(null, $replace);
     $this->assertEquals($replace, $filter->getReplacement());
 }
 /**
  * Validates the input string against a list of valid recipients.
  *
  * @param string $input The input to be validated as a recipient.
  *
  * @return bool True if input string is a valid recipient, otherwise
  *              False.
  */
 public function isValid($input)
 {
     $auditor = ESAPI::getAuditor('App_Validate_Recipient');
     if (!is_string($input)) {
         $auditor->warning(Auditor::SECURITY, false, 'isValid expects a string!');
         $this->_error(self::INVALID);
         return false;
     }
     if ($this->_recipients instanceof Zend_Config !== true) {
         $this->_error(self::INVALID_RECIPIENT);
         $auditor->warning(Auditor::SECURITY, false, 'isValid requires an array of recipients!');
         return false;
     }
     $encoder = ESAPI::getEncoder();
     // canonicalise the input string.
     $canonical = null;
     try {
         $canonical = $encoder->canonicalize($input, true);
     } catch (Exception $e) {
         // Process the input no further.
         $this->_error(self::INVALID_RECIPIENT);
         $auditor->warning(Auditor::SECURITY, false, 'isValid rejected a string in which double or mixed encoding was detected.', $e);
         return false;
     }
     // Convert input to lower case
     $charEnc = mb_detect_encoding($canonical);
     $canonicalLower = mb_strtolower($canonical, $charEnc);
     // Get a whitespace removal filter
     $whitespace = new Zend_Filter_PregReplace(array('match' => '/ /', 'replace' => ''));
     // for each of our valid recipients use an identical validator
     // to determine whether $canonical matches.
     $validator = new Zend_Validate_Identical();
     foreach ($this->_recipients as $_ => $cfg) {
         foreach ($cfg as $key => $validRecipient) {
             if ($key !== 'display') {
                 continue;
             }
             $charEnc = mb_detect_encoding($validRecipient . '');
             $validRecipientL = mb_strtolower($validRecipient, $charEnc);
             $validRecipientS = $whitespace->filter($validRecipientL);
             $validator->setToken($validRecipientL);
             if ($validator->isValid($canonicalLower)) {
                 return true;
             }
             $validator->setToken($validRecipientS);
             if ($validator->isValid($canonicalLower)) {
                 return true;
             }
         }
     }
     // if that fails, the form has been tampered with or a dummy option has
     // been selected - check for the latter of these now:
     foreach ($this->_dummyRecipients as $dummy => $value) {
         $charEnc = mb_detect_encoding($dummy . '');
         $dummyL = mb_strtolower($dummy, $charEnc);
         $dummyS = $whitespace->filter($dummyL);
         $validator->setToken($dummyL);
         if ($validator->isValid($canonicalLower)) {
             $this->_error(self::DUMMY_RECIPIENT);
             return false;
         }
         $validator->setToken($dummyS);
         if ($validator->isValid($canonicalLower)) {
             $this->_error(self::DUMMY_RECIPIENT);
             return false;
         }
     }
     $auditor->warning(Auditor::SECURITY, false, "isValid. Input [{$canonicalLower}] is not a valid recipient.");
     $this->_error(self::INVALID_RECIPIENT);
     return false;
 }
 /**
  * Produces the json for the "available methods" dropdown in the backend.
  * used by pimcore.object.classes.data.dynamicDropdown
  */
 public function methodsAction()
 {
     $methods = array();
     $filter = new Zend_Filter_PregReplace(array("match" => "@[^a-zA-Z0-9_\\-]@", "replace" => ""));
     $class_name = $filter->filter($this->_getParam("classname"));
     if (!empty($class_name)) {
         $class_methods = get_class_methods("Object_" . ucfirst($class_name));
         if (!is_null($class_methods)) {
             foreach ($class_methods as $method_name) {
                 if (substr($method_name, 0, 3) == "get") {
                     $methods[] = array("value" => $method_name, "key" => $method_name);
                 }
             }
         }
     }
     $this->_helper->json($methods);
 }
Beispiel #11
0
 function __construct()
 {
     parent::__construct('/\\W+/', '');
 }
 /**
  * Generates an option in the recipient select element for each recipient
  * display name defined in the recpients Zend_Config object.
  * If there are less than two recipients the the select element will be
  * deleted from the form.
  *
  * @return null
  */
 private function _setRecipientSelector()
 {
     // If the list of recipients contains less than two recipients then we
     // remove the unecessary select element from the form.
     if (sizeof($this->_recipients) < 2 && $this->recipientMap instanceof Zend_Form_Element) {
         $this->removeElement('recipientMap');
         $this->_conditionallyUseCaptcha = false;
         return;
     }
     // If the url contained a valid recipient name then that name will be
     // the selected option in the form.  The request parameter 'recipient'
     // will be set and it should exactly match a defined recipient.
     // Note that the user may have set the recipient parameter so validation
     // of that parameter must be done here.
     $fc = Zend_Controller_Front::getInstance();
     $validRecipient = $fc->getRequest()->getParam('recipient', null);
     if ($validRecipient !== null) {
         $recipientValidator = new Custom_Validate_ValidRecipient($this->_recipients);
         if ($recipientValidator->isValid($validRecipient) === false) {
             $validRecipient = null;
         }
     }
     if ($validRecipient === null) {
         $this->_conditionallyUseCaptcha = false;
     }
     // Before we generate an option for each valid recipient, get any
     // existing options - these will be dummy options (there should ideally
     // be just one) that are not valid recipients but allow us to generate
     // a select element that does not have a pre-selected option and fails
     // to validate if one of the dummy values is selected so that the user
     // is reminded to select a recipient.
     $dummy = $this->recipientMap->getMultiOptions();
     // Now add a multi option for each recipient.  If validRecipient is set
     // then mark the corresponding element as the selected one (setValue()).
     $validRecipientLower = null;
     if ($validRecipient !== null) {
         $charEnc = mb_detect_encoding($validRecipient);
         $validRecipientLower = mb_strtolower($validRecipient, $charEnc);
     }
     // Get a whitespace removal filter
     $whitespace = new Zend_Filter_PregReplace(array('match' => '/ /', 'replace' => ''));
     foreach ($this->_recipients as $_ => $cfg) {
         foreach ($cfg as $key => $displayName) {
             if ($key !== 'display') {
                 continue;
             }
             $this->recipientMap->addMultiOption($displayName, $displayName);
             if ($validRecipientLower !== null) {
                 $charEnc = mb_detect_encoding($displayName);
                 $displayNameL = mb_strtolower($displayName, $charEnc);
                 $displayNameS = $whitespace->filter($displayNameL);
                 if ($validRecipientLower === $displayNameL || $validRecipientLower === $displayNameS) {
                     $this->recipientMap->setValue($displayName);
                 }
             }
         }
     }
     $o = array('recipients' => $this->_recipients, 'dummy' => $dummy);
     $this->recipientMap->addValidator('validRecipient', false, $o);
     return;
 }
Beispiel #13
0
 public function content($acl = false, $fieldname = 'content', $label = 'Text:', $required = null)
 {
     $method = $acl ? 'addSupervisedElement' : 'addElement';
     $this->{$method}('textarea', $fieldname, array('label' => $label, 'filters' => array(new Base_Filter_Stripslashes()), 'validators' => array(array('Encoding', true, array('in_charset' => 'UTF-8'))), 'required' => is_null($required) ? $this->default_policy : $required, 'rows' => '20', 'cols' => '100', 'class' => 'bbcode_editor'));
     $filter = new Zend_Filter_PregReplace();
     $filter->setMatchPattern(array('/&#8222;/', '/&#8221;/', '/&#61485;/', '/&#8211;/', '/&#8217;/', '/&#8230;/', '/&#174;/', '/&#169;/', '/&#8482;/'))->setReplacement(array('&bdquo;', '&rdquo;', '&nbsp;', '&ndash;', '&rsquo;', '&hellip;', '&reg;', '&copy;', '&trade;'));
     $this->getElement($fieldname)->addFilter($filter);
     $this->notEmpty($fieldname);
 }
 public function formMultiCheckbox($name, $value = null, $attribs = null, $options = null, $listsep = '')
 {
     $info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
     extract($info);
     // name, value, attribs, options, listsep, disable
     // retrieve attributes for labels (prefixed with 'label_' or 'label')
     $label_attribs = [];
     foreach ($attribs as $key => $val) {
         $tmp = false;
         $keyLen = strlen($key);
         if (6 < $keyLen && substr($key, 0, 6) == 'label_') {
             $tmp = substr($key, 6);
         } elseif (5 < $keyLen && substr($key, 0, 5) == 'label') {
             $tmp = substr($key, 5);
         }
         if ($tmp) {
             // make sure first char is lowercase
             $tmp[0] = strtolower($tmp[0]);
             $label_attribs[$tmp] = $val;
             unset($attribs[$key]);
         }
     }
     if (!array_key_exists('class', $label_attribs)) {
         $label_attribs['class'] = '';
     }
     $label_attribs['class'] = trim($label_attribs['class']);
     $labelPlacement = 'append';
     foreach ($label_attribs as $key => $val) {
         switch (strtolower($key)) {
             case 'placement':
                 unset($label_attribs[$key]);
                 $val = strtolower($val);
                 if (in_array($val, ['prepend', 'append'])) {
                     $labelPlacement = $val;
                 }
                 break;
         }
     }
     // the radio button values and labels
     $options = (array) $options;
     // build the element
     $xhtml = '';
     $list = [];
     // should the name affect an array collection?
     $name = $this->view->escape($name);
     if ($this->_isArray && '[]' != substr($name, -2)) {
         $name .= '[]';
     }
     // ensure value is an array to allow matching multiple times
     $value = (array) $value;
     // XHTML or HTML end tag?
     $endTag = ' />';
     if ($this->view instanceof \Zend_View_Abstract && !$this->view->doctype()->isXhtml()) {
         $endTag = '>';
     }
     // Set up the filter - Alnum + hyphen + underscore
     // require_once 'Zend/Filter/PregReplace.php';
     $pattern = @preg_match('/\\pL/u', 'a') ? '/[^\\p{L}\\p{N}\\-\\_]/u' : '/[^a-zA-Z0-9\\-\\_]/';
     // No Unicode
     $filter = new \Zend_Filter_PregReplace($pattern, '');
     // add radio buttons to the list.
     foreach ($options as $opt_value => $opt_label) {
         // Should the label be escaped?
         if ($escape) {
             $opt_label = $this->view->escape($opt_label);
         }
         // is it disabled?
         $disabled = '';
         if (true === $disable) {
             $disabled = ' disabled="disabled"';
         } elseif (is_array($disable) && in_array($opt_value, $disable)) {
             $disabled = ' disabled="disabled"';
         }
         // is it checked?
         $checked = '';
         if (in_array($opt_value, $value)) {
             $checked = ' checked="checked"';
         }
         // generate ID
         $optId = $id . '-' . $filter->filter($opt_value);
         // Wrap the radios in labels
         $radio = '<div class="checkbox"><label' . $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">' . '<input type="' . $this->_inputType . '"' . ' name="' . $name . '"' . ' id="' . $optId . '"' . ' value="' . $this->view->escape($opt_value) . '"' . $checked . $disabled . $this->_htmlAttribs($attribs) . $endTag . '<span>' . $opt_label . '</span>' . '</label></div>';
         // add to the array of radio buttons
         $list[] = $radio;
     }
     // done!
     $xhtml .= implode($listsep, $list);
     return $xhtml;
 }