Exemplo n.º 1
0
 /**
  * Get link to comment author's provided URL
  *
  * @param string String to display for link: leave empty to display URL
  * @param string String to display before link, if link exists
  * @param string String to display after link, if link exists
  * @param boolean false if you want NO html link
  * @return boolean true if URL has been displayed
  */
 function get_author_url_link($linktext = '', $before = '', $after = '', $makelink = true)
 {
     global $Plugins;
     $url = $this->get_author_url();
     if (evo_strlen($url) < 10) {
         return false;
     }
     // If URL exists:
     $r = $before;
     if ($makelink) {
         $r .= '<a ';
         if ($this->nofollow) {
             $r .= 'rel="nofollow" ';
         }
         $r .= 'href="' . $url . '">';
     }
     $r .= empty($linktext) ? $url : $linktext;
     if ($makelink) {
         $r .= '</a>';
     }
     $r .= $after;
     $Plugins->trigger_event('FilterCommentAuthorUrl', array('data' => &$r, 'makelink' => $makelink, 'Comment' => $this));
     return $r;
 }
Exemplo n.º 2
0
     // Special form template that will be replaced to current skin on ajax response
     $Form->fieldstart = '#fieldstart#';
     $Form->fieldend = '#fieldend#';
     $Form->labelclass = '#labelclass#';
     $Form->labelstart = '#labelstart#';
     $Form->labelend = '#labelend#';
     $Form->inputstart = '#inputstart#';
     $Form->inputend = '#inputend#';
     $org_suffix .= ' ' . get_icon('add', 'imgtag', array('class' => 'add_org', 'style' => 'cursor:pointer'));
     $org_suffix .= ' ' . get_icon('minus', 'imgtag', array('class' => 'remove_org', 'style' => 'cursor:pointer'));
     $Form->select_input_object('organizations[]', 0, $OrganizationCache, T_('Organization'), array('allow_none' => $first_org ? true : false, 'field_suffix' => $org_suffix));
     break;
 case 'autocomplete_usernames':
     // Get usernames by first chars for autocomplete jQuery plugin & TinyMCE autocomplete plugin
     $q = param('q', 'string', '');
     if (!is_valid_login($q) || evo_strlen($q) < 4) {
         // Restrict a wrong request
         debug_die('Wrong request');
     }
     // Add backslash for special char of sql operator LIKE
     $q = str_replace('_', '\\_', $q);
     if (utf8_strlen($q) == 0) {
         // Don't search logins with empty request
         $usernames = array();
     } else {
         $SQL = new SQL();
         $SQL->SELECT('user_login');
         $SQL->FROM('T_users');
         $SQL->WHERE('user_login LIKE ' . $DB->quote($q . '%'));
         $SQL->WHERE_and('user_status = "activated" OR user_status = "autoactivated"');
         $SQL->ORDER_BY('user_login');
Exemplo n.º 3
0
/**
 * Remove trailing slash, if present
 *
 * @param string the path/url
 * @return string the path/url without trailing slash
 */
function no_trailing_slash($path)
{
    if (evo_substr($path, -1) == '/') {
        return evo_substr($path, 0, evo_strlen($path) - 1);
    } else {
        return $path;
    }
}
Exemplo n.º 4
0
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
// ---------------------------- EMAIL HEADER INCLUDED HERE ----------------------------
emailskin_include('_email_header.inc.txt.php', $params);
// ------------------------------- END OF EMAIL HEADER --------------------------------
global $admin_url, $baseurl, $htsrv_url;
// Default params:
$params = array_merge(array('notify_full' => false, 'Item' => NULL, 'recipient_User' => NULL, 'notify_type' => ''), $params);
$recipient_User = $params['recipient_User'];
$Item = $params['Item'];
$Blog =& $Item->get_Blog();
if ($params['notify_full']) {
    /* Full notification */
    // Calculate length for str_pad to align labels:
    $pad_len = max(evo_strlen(T_('Blog')), evo_strlen(T_('Author')), evo_strlen(T_('Title')), evo_strlen(T_('Url')), evo_strlen(T_('Content')));
    echo str_pad(T_('Blog'), $pad_len) . ': ' . $Blog->get('shortname') . ' ( ' . str_replace('&amp;', '&', $Blog->gen_blogurl()) . ' )' . "\n";
    echo str_pad(T_('Author'), $pad_len) . ': ' . $Item->creator_User->get('preferredname') . ' (' . $Item->creator_User->get('login') . ")\n";
    echo str_pad(T_('Title'), $pad_len) . ': ' . $Item->get('title') . "\n";
    // linked URL or "-" if empty:
    echo str_pad(T_('Url'), $pad_len) . ': ' . (empty($Item->url) ? '-' : str_replace('&amp;', '&', $Item->get('url'))) . "\n";
    if ($params['notify_type'] == 'moderator') {
        echo T_('Status') . ': ' . $Item->get('t_status') . "\n";
    }
    echo str_pad(T_('Content'), $pad_len) . ': ';
    // TODO: We MAY want to force a short URL and avoid it to wrap on a new line in the mail which may prevent people from clicking
    // TODO: might get moved onto a single line, at the end of the content..
    echo $Item->get_permanent_url('', '', '&') . "\n\n";
    echo $Item->get('content') . "\n";
    if ($recipient_User->check_perm('item_post!CURSTATUS', 'edit', false, $Item)) {
        // User has permission to edit this post
Exemplo n.º 5
0
/**
 * Helper function for "Requested URI" column
 * @param integer Blog ID
 * @param string Requested URI
 * @param integer Output string lenght
 * @param string Display
 * @param string Controller
 * @return string
 */
function stats_format_req_URI($hit_blog_ID, $hit_uri, $max_len = 40, $hit_disp = NULL, $hit_ctrl = NULL, $hit_action = NULL)
{
    if (!empty($hit_blog_ID)) {
        $BlogCache =& get_BlogCache();
        $tmp_Blog =& $BlogCache->get_by_ID($hit_blog_ID);
        $full_url = $tmp_Blog->get_baseurl_root() . $hit_uri;
    } else {
        $full_url = $hit_uri;
    }
    $int_search_uri = urldecode($hit_uri);
    if (evo_strpos($int_search_uri, '?s=') !== false || evo_strpos($int_search_uri, '&s=') !== false) {
        // This is an internal search:
        preg_match('~[?&]s=([^&#]*)~', $int_search_uri, $res);
        $hit_uri = 'Internal search : ' . $res[1];
    } elseif (evo_strlen($hit_uri) > $max_len) {
        $hit_uri = '...' . evo_substr($hit_uri, -$max_len);
    }
    if ($hit_disp != NULL || $hit_ctrl != NULL || $hit_action != NULL) {
        $hit_uri = '';
        if ($hit_disp != NULL) {
            $hit_uri = '[disp=<a href="' . $full_url . '">' . $hit_disp . '</a>]';
        }
        if ($hit_ctrl != NULL) {
            $hit_uri = $hit_uri . ' [ctrl=<a href="' . $full_url . '">' . $hit_ctrl . '</a>]';
        }
        if ($hit_action != NULL) {
            $hit_uri = $hit_uri . ' [action=<a href="' . $full_url . '">' . $hit_action . '</a>]';
        }
        return $hit_uri;
    }
    return '<a href="' . $full_url . '">' . $hit_uri . '</a>';
}
Exemplo n.º 6
0
 function send_a_tweet($content, &$Item, &$xmlrpcresp)
 {
     // Uses either plugin CollSettings or UserSettings
     $oauth = $this->get_oauth_info(array('user_ID' => $Item->get_creator_User()->ID, 'blog_ID' => $Item->get_Blog()->ID));
     if (empty($oauth['msg_format']) || empty($oauth['token']) || empty($oauth['token_secret'])) {
         // Not found, fallback to Trying to get twitter account for User:
         $xmlrpcresp = T_('You must configure a twitter username/password before you can post to twitter.');
         return false;
     }
     $content = array_merge(array('title' => '', 'excerpt' => '', 'url' => ''), $content);
     $msg = str_replace(array('$title$', '$excerpt$'), array($content['title'], $content['excerpt']), $oauth['msg_format']);
     $msg_len = evo_strlen($msg);
     $full_url_len = evo_strlen($content['url']);
     $base_url_len = evo_strlen($Item->get_Blog()->get_baseurl_root());
     if (evo_strpos($msg, '$url$') === 0 && $base_url_len + $msg_len - 5 > $this->message_length_limit) {
         // The message is too long and is starting with $url$
         $max_len = $this->message_length_limit + $full_url_len - $base_url_len;
         $msg = strmaxlen(str_replace('$url$', $content['url'], $msg), $max_len, '...');
     } elseif (evo_strpos(strrev($msg), 'p2b# $lru$') === 0 && $base_url_len + $msg_len - 10 > $this->message_length_limit) {
         // The message is too long and is ending on '$url$ #b2p'
         // Strip $url$, crop the message, and add URL to the end
         $max_len = $this->message_length_limit - $base_url_len - 1;
         // save room for space character
         $msg = strmaxlen(str_replace('$url$ #b2p', '', $msg), $max_len, '...');
         $msg .= ' ' . $content['url'] . ' #b2p';
     } elseif (evo_strpos(strrev($msg), '$lru$') === 0 && $base_url_len + $msg_len - 5 > $this->message_length_limit) {
         // Same as above, but without '#b2p' suffix
         $max_len = $this->message_length_limit - $base_url_len - 1;
         // save room for space character
         $msg = strmaxlen(str_replace('$url$', '', $msg), $max_len, '...');
         $msg .= ' ' . $content['url'];
     } elseif (evo_strpos($msg, '$url$') !== false && $base_url_len + $msg_len - 5 > $this->message_length_limit) {
         // Message is too long and $url$ is somewhere in the middle
         // We can't do much, it will be rejected by Twitter
         // TODO: find a way to trim X chars before the URL and Y chars after
         $msg = str_replace('$url$', $content['url'], $msg);
     } else {
         // We don't want to add URL. Crop the message if needed
         $msg = strmaxlen(str_replace('$url$', $content['url'], $msg), $this->message_length_limit, '...');
     }
     require_once 'twitteroauth/twitteroauth.php';
     $connection = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $oauth['token'], $oauth['token_secret']);
     $result = $connection->post('statuses/update', array('status' => $msg));
     if (empty($result)) {
         $xmlrpcresp = 'Unknown error while posting "' . $msg . '" to account @' . $oauth['contact'];
         return false;
     } elseif (!empty($result->error)) {
         $xmlrpcresp = $result->error;
         return false;
     }
     if (empty($oauth['contact'])) {
         $oauth['contact'] = $this->get_twitter_contact($oauth['token'], $oauth['token_secret']);
     }
     $xmlrpcresp = T_('Posted to account @') . $oauth['contact'];
     return true;
 }
Exemplo n.º 7
0
/**
 * Process Header information like subject and date of a mail.
 *
 * @param array $header header as set by mime_parser_class::Analyze()
 * @param string message subject by reference
 * @param string message date by reference
 * @return bool true if valid subject prefix is detected
 */
function pbm_process_header($header, &$subject, &$post_date)
{
    global $Settings;
    $subject = $header['Subject'];
    $ddate = $header['Date'];
    $prefix = $Settings->get('eblog_subject_prefix');
    pbm_msg('Subject: ' . $subject);
    if (evo_substr($subject, 0, evo_strlen($prefix)) !== $prefix) {
        pbm_msg('Subject prefix is not "' . $prefix . '", skip this email');
        return false;
    }
    $subject = evo_substr($subject, evo_strlen($prefix));
    // Parse Date
    if (!preg_match('#^(.{3}, )?(\\d{2}) (.{3}) (\\d{4}) (\\d{2}):(\\d{2}):(\\d{2})#', $ddate, $match)) {
        $ddate_U = @strtotime($ddate);
        if (empty($ddate_U) || strlen($ddate_U) < 2) {
            pbm_msg(sprintf(T_('Could not parse date header "%s"'), $ddate), true);
            return false;
        }
    }
    if (empty($ddate_U)) {
        $dmonths = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12);
        $ddate_H = $match[5];
        $ddate_i = $match[6];
        $ddate_s = $match[7];
        if (!isset($dmonths[$match[3]])) {
            pbm_msg(T_('Invalid month name in message date string.'), true);
            return false;
        }
        $ddate_m = $dmonths[$match[3]];
        $ddate_d = $match[2];
        $ddate_Y = $match[4];
        $ddate_U = mktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
    }
    $post_date = date('Y-m-d H:i:s', $ddate_U);
    return true;
}
Exemplo n.º 8
0
/**
 * Check profile parameters and add errors through {@link param_error()}.
 *
 * @param array associative array.
 *     Either array( $value, $input_name ) or just $value;
 *     ($input_name gets used for associating it to a form fieldname)
 *     - 'login': check for non-empty
 *     - 'nickname': check for non-empty
 *     - 'icq': must be a number
 *     - 'email': mandatory, must be well formed
 *     - 'country': check for non-empty
 *     - 'url': must be well formed, in allowed scheme, not blacklisted
 *     - 'pass1' / 'pass2': passwords (twice), must be the same and not == login (if given)
 *     - 'pass_required': false/true (default is true)
 * @param User|NULL A user to use for additional checks (password != login/nick).
 */
function profile_check_params($params, $User = NULL)
{
    global $Messages, $Settings;
    foreach ($params as $k => $v) {
        // normalize params:
        if ($k != 'pass_required' && !is_array($v)) {
            $params[$k] = array($v, $k);
        }
    }
    // checking login has been typed:
    if (isset($params['login'][0])) {
        if (empty($params['login'][0])) {
            // login can't be empty
            param_error($params['login'][1], T_('Please enter your login.'));
        } else {
            param_check_valid_login('login');
        }
    }
    // checking e-mail address
    if (isset($params['email'][0])) {
        if (empty($params['email'][0])) {
            param_error($params['email'][1], T_('Please enter your e-mail address.'));
        } elseif (!is_email($params['email'][0])) {
            param_error($params['email'][1], T_('The email address is invalid.'));
        }
    }
    // Checking country
    if (isset($params['country']) && empty($params['country'][0])) {
        param_error('country', T_('Please select country.'));
    }
    // Checking first name
    if (isset($params['firstname']) && empty($params['firstname'][0])) {
        param_error('firstname', T_('Please enter your first name.'));
    }
    // Checking gender
    if (isset($params['gender'])) {
        if (empty($params['gender'][0])) {
            param_error('gender', T_('Please select gender.'));
        } elseif ($params['gender'][0] != 'M' && $params['gender'][0] != 'F') {
            param_error('gender', 'Gender value is invalid');
        }
    }
    // Checking URL:
    if (isset($params['url'])) {
        if ($error = validate_url($params['url'][0], 'commenting')) {
            param_error($params['url'][1], T_('Supplied URL is invalid: ') . $error);
        }
    }
    // Check passwords:
    $pass_required = isset($params['pass_required']) ? $params['pass_required'] : true;
    if (isset($params['pass1'][0]) && isset($params['pass2'][0])) {
        if ($pass_required || !empty($params['pass1'][0]) || !empty($params['pass2'][0])) {
            // Password is required or was given
            // checking the password has been typed twice
            if (empty($params['pass1'][0]) || empty($params['pass2'][0])) {
                param_error($params['pass2'][1], T_('Please enter your password twice.'));
            }
            // checking the password has been typed twice the same:
            if ($params['pass1'][0] !== $params['pass2'][0]) {
                param_error($params['pass1'][1], T_('You typed two different passwords.'));
            } elseif ($Settings->get('passwd_special') && !preg_match('~[\\x20-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7f]~', $params['pass1'][0])) {
                param_error($params['pass1'][1], T_('Your password should contain at least one special character (like & ! $ * - _ + etc.)'));
            } elseif (evo_strlen($params['pass1'][0]) < $Settings->get('user_minpwdlen')) {
                param_error($params['pass1'][1], sprintf(T_('The minimum password length is %d characters.'), $Settings->get('user_minpwdlen')));
            } elseif (isset($User) && $params['pass1'][0] == $User->get('login')) {
                param_error($params['pass1'][1], T_('The password must be different from your login.'));
            } elseif (isset($User) && $params['pass1'][0] == $User->get('nickname')) {
                param_error($params['pass1'][1], T_('The password must be different from your nickname.'));
            }
        }
    }
}
Exemplo n.º 9
0
/**
 * Add a javascript ban action icon after each url in the given content
 *
 * @param string Comment content
 * @return string the content with a ban icon after each url if the user has spamblacklist permission, the incoming content otherwise
 */
function add_ban_icons($content)
{
    global $current_User;
    if (!$current_User->check_perm('spamblacklist', 'edit')) {
        return $content;
    }
    $atags = get_atags($content);
    $imgtags = get_imgtags($content);
    $urls = get_urls($content);
    $result = '';
    $from = 0;
    // current processing position
    $length = 0;
    // current url or tag length
    $i = 0;
    // url counter
    $j = 0;
    // "a" tag counter
    $k = 0;
    // "img" tag counter
    while (isset($urls[$i])) {
        // there is unprocessed url
        $url = $urls[$i];
        if (validate_url($url, 'posting', false)) {
            // skip not valid urls
            $i++;
            continue;
        }
        while (isset($imgtags[$k]) && strpos($content, $imgtags[$k]) < $from) {
            // skipp already passed img tags
            $k++;
        }
        $pos = strpos($content, $url, $from);
        $length = evo_strlen($url);
        $i++;
        // check img tags
        if (isset($imgtags[$k]) && strpos($imgtags[$k], $url) !== false && $pos > strpos($content, $imgtags[$k], $from)) {
            // current url is inside the img tag, we need to skip this url.
            $result .= substr($content, $from, $pos + $length - $from);
            $from = $pos + $length;
            $k++;
            continue;
        }
        // check a tags
        if (isset($atags[$j])) {
            // there is unprocessed "a" tag
            $tag = $atags[$j];
            if (($urlpos = strpos($tag, $url)) !== false && $pos > strpos($content, $tag, $from)) {
                // the url is inside the current tag, we have to add ban icon after the tag
                $pos = strpos($content, $tag, $from);
                $length = strlen($tag);
                while (isset($urls[$i]) && ($urlpos = strpos($tag, $urls[$i], $urlpos + 1)) !== false) {
                    // skip all other urls from this tag
                    $i++;
                }
                $j++;
            }
        }
        // add processed part and ban icon to result and set current position
        $result .= substr($content, $from, $pos + $length - $from);
        $from = $pos + $length;
        $result .= add_jsban($url);
    }
    // add the end of the content to the result
    $result .= substr($content, $from, strlen($content) - $from);
    return $result;
}
Exemplo n.º 10
0
/**
 * Get the base domain that could be blacklisted from an URL.
 *
 * We want to concentrate on the main domain and we want to prefix it with either . or // in order not
 * to blacklist too large.
 *
 * {@internal This function gets tested in _misc.funcs.simpletest.php}}
 *
 * @param string URL or domain
 * @return string|false the pattern to match this domain in the blacklist; false if we could not extract the base domain
 */
function get_ban_domain($url)
{
    // echo '<p>'.$url;
    // Remove http:// part + everything after the last path element ( '/' alone is ignored on purpose )
    $domain = preg_replace('~^ ([a-z]+://)? ([^/#]+) (/ ([^/]*/)+ )? .* ~xi', '\\2\\3', $url);
    // echo '<br>'.$domain;
    if (preg_match('~^[0-9.]+$~', $domain)) {
        // All numeric = IP address, don't try to cut it any further
        return '//' . $domain;
    }
    // Remove any www*. prefix:
    $base_domain = preg_replace('~^(www \\w* \\. )~xi', '', $domain);
    if (empty($base_domain)) {
        return false;
    }
    if (evo_strlen($base_domain) < evo_strlen($domain)) {
        // The guy is spamming with subdomains (or www):
        return '.' . $base_domain;
    }
    // The guy is spamming with the base domain:
    return '//' . $base_domain;
}
Exemplo n.º 11
0
 /**
  * Get link to User
  *
  * @return string
  */
 function get_link($params = array())
 {
     // Make sure we are not missing any param:
     $params = array_merge(array('format' => 'htmlbody', 'link_to' => 'userpage', 'link_text' => 'preferredname', 'link_rel' => '', 'link_class' => '', 'thumb_size' => 'crop-top-32x32', 'thumb_class' => ''), $params);
     if ($params['link_text'] == 'avatar') {
         $r = $this->get_avatar_imgtag($params['thumb_size'], $params['thumb_class']);
     } else {
         $r = $this->dget('preferredname', $params['format']);
     }
     switch ($params['link_to']) {
         case 'userpage':
         case 'userpage>userurl':
             $url = $this->get_userpage_url();
             break;
         case 'userurl':
             $url = $this->url;
             break;
         case 'userurl>userpage':
             // We give priority to user submitted url:
             if (evo_strlen($this->url) > 10) {
                 $url = $this->url;
             } else {
                 $url = $this->get_userpage_url();
             }
             break;
     }
     if (!empty($url)) {
         $link = '<a href="' . $url . '"';
         if (!empty($params['link_rel'])) {
             $link .= ' rel="' . $params['link_rel'] . '"';
         }
         if (!empty($params['link_class'])) {
             $link .= ' class="' . $params['link_class'] . '"';
         }
         $r = $link . '>' . $r . '</a>';
     }
     return $r;
 }
Exemplo n.º 12
0
        param('delhits', 'integer', 0);
        $all_statuses = get_visibility_statuses('keys', array('trash', 'redirected'));
        $delstatuses = array();
        foreach ($all_statuses as $status) {
            // collect which comments should be delteded
            if (param('del' . $status, 'integer', 0)) {
                // matching comments with this status should be deleted
                $delstatuses[] = $status;
            }
        }
        $delcomments = count($delstatuses);
        param('blacklist_locally', 'integer', 0);
        param('report', 'integer', 0);
        // Check if the string is too short,
        // it has to be a minimum of 5 characters to avoid being too generic
        if (evo_strlen($keyword) < 5) {
            $Messages->add(sprintf(T_('The keyword &laquo;%s&raquo; is too short, it has to be a minimum of 5 characters!'), htmlspecialchars($keyword)), 'error');
            break;
        }
        if ($delhits) {
            // Delete all banned hit-log entries
            $r = $DB->query('DELETE FROM T_hitlog
												WHERE hit_referer LIKE ' . $DB->quote('%' . $keyword . '%'), 'Delete all banned hit-log entries');
            $Messages->add(sprintf(T_('Deleted %d logged hits matching &laquo;%s&raquo;.'), $r, htmlspecialchars($keyword)), 'success');
        }
        if ($delcomments) {
            // select banned comments
            $del_condition = blog_restrict($delstatuses);
            $keyword_cond = '(comment_author LIKE ' . $DB->quote('%' . $keyword . '%') . '
							OR comment_author_email LIKE ' . $DB->quote('%' . $keyword . '%') . '
							OR comment_author_url LIKE ' . $DB->quote('%' . $keyword . '%') . '
Exemplo n.º 13
0
/**
 * Validates settings according to their meta info recursively.
 *
 * @todo Init "checkbox" values in "array" type settings (they do not get send) (dh)
 * @param string Param name
 * @param array Meta info
 * @return boolean
 */
function autoform_validate_param_value($param_name, $value, $meta)
{
    global $Messages;
    if (is_array($value) && isset($meta['entries'])) {
        $r = true;
        if (isset($meta['key'])) {
            // validate keys:
            foreach (array_keys($value) as $k) {
                if (!autoform_validate_param_value($param_name . '[' . $k . '][__key__]', $k, $meta['key'])) {
                    $r = false;
                }
            }
        }
        // Check max_count/min_count
        // dh> TODO: find a way to link it to the form's fieldset (and add an "error" class to it)
        if (isset($meta['max_count']) && count($value) > $meta['max_count']) {
            $r = false;
            $label = isset($meta['label']) ? $meta['label'] : $param_name;
            $Messages->add(sprintf(T_('Too many entries in the "%s" set. It must have %d at most.'), $label, $meta['max_count']), 'error');
        } elseif (isset($meta['min_count']) && count($value) < $meta['min_count']) {
            $r = false;
            $label = isset($meta['label']) ? $meta['label'] : $param_name;
            $Messages->add(sprintf(T_('Too few entries in the "%s" set. It must have %d at least.'), $label, $meta['min_count']), 'error');
        }
        foreach ($meta['entries'] as $mk => $mv) {
            foreach ($value as $vk => $vv) {
                if (!isset($vv[$mk])) {
                    continue;
                }
                if (!autoform_validate_param_value($param_name . '[' . $vk . '][' . $mk . ']', $vv[$mk], $mv)) {
                    $r = false;
                }
            }
        }
        return $r;
    }
    if (isset($meta['type'])) {
        switch ($meta['type']) {
            case 'integer':
                if (!preg_match('~^[-+]?\\d+$~', $value)) {
                    param_error($param_name, sprintf(T_('The value for &laquo;%s&raquo; must be numeric.'), $meta['label']), T_('The value must be numeric.'));
                    return false;
                }
                break;
            case 'float':
                if (!preg_match('~^[-+]?\\d+(\\.\\d+)?$~', $value)) {
                    param_error($param_name, sprintf(T_('The value for &laquo;%s&raquo; must be numeric.'), $meta['label']), T_('The value must be numeric.'));
                    return false;
                }
                break;
            case 'radio':
                $check_value = false;
                foreach ($meta['options'] as $arr) {
                    if (!is_array($arr)) {
                        param_error($param_name, sprintf(T_('Invalid option &laquo;%s&raquo;.'), $arr));
                        return false;
                    }
                    if ($value == $arr[0]) {
                        $check_value = true;
                        break;
                    }
                }
                if (!$check_value) {
                    param_error($param_name, sprintf(T_('Invalid option &laquo;%s&raquo;.'), $value));
                    return false;
                }
                break;
            case 'select':
                $check_options = $value;
                if (!is_array($check_options)) {
                    // no "multiple" select:
                    $check_options = array($check_options);
                }
                foreach ($check_options as $v) {
                    if (!in_array($v, array_keys($meta['options']))) {
                        param_error($param_name, sprintf(T_('Invalid option &laquo;%s&raquo;.'), $v));
                        return false;
                    }
                }
                break;
            case 'select_blog':
            case 'select_group':
            case 'select_user':
                if (is_array($value) && empty($value) || !is_array($value) && !strlen($value)) {
                    if (empty($meta['allow_none'])) {
                        // empty is not ok
                        param_error($param_name, sprintf(T_('Invalid option &laquo;%s&raquo;.'), $value));
                        return false;
                    }
                } else {
                    // Try retrieving the value from the corresponding Cache:
                    switch ($meta['type']) {
                        case 'select_blog':
                            $Cache =& get_BlogCache();
                            break;
                        case 'select_group':
                            $Cache =& get_GroupCache();
                            break;
                        case 'select_user':
                            $Cache =& get_UserCache();
                            break;
                    }
                    $check_options = $value;
                    if (!is_array($check_options)) {
                        // no "multiple" select:
                        $check_options = array($check_options);
                    }
                    foreach ($check_options as $v) {
                        if (empty($v) && !empty($meta['allow_none'])) {
                            // empty is ok:
                            continue;
                        }
                        if (!$Cache->get_by_ID($v, false, false)) {
                            param_error($param_name, sprintf(T_('Invalid option &laquo;%s&raquo;.'), $v));
                            return false;
                        }
                    }
                }
                break;
        }
    }
    // Check maxlength:
    if (isset($meta['maxlength'])) {
        if (evo_strlen($value) > $meta['maxlength']) {
            param_error($param_name, sprintf(T_('The value is too long.'), $value));
        }
    }
    // Check valid pattern:
    if (isset($meta['valid_pattern'])) {
        $param_pattern = is_array($meta['valid_pattern']) ? $meta['valid_pattern']['pattern'] : $meta['valid_pattern'];
        if (!preg_match($param_pattern, $value)) {
            $param_error = is_array($meta['valid_pattern']) ? $meta['valid_pattern']['error'] : sprintf(T_('The value is invalid. It must match the regular expression &laquo;%s&raquo;.'), $param_pattern);
            param_error($param_name, $param_error);
            return false;
        }
    }
    // Check valid range:
    if (isset($meta['valid_range'])) {
        // Transform numeric indexes into associative keys:
        if (!isset($meta['valid_range']['min'], $meta['valid_range']['max']) && isset($meta['valid_range'][0], $meta['valid_range'][1])) {
            $meta['valid_range']['min'] = $meta['valid_range'][0];
            $meta['valid_range']['max'] = $meta['valid_range'][1];
        }
        if (isset($meta['valid_range'][2]) && !isset($meta['valid_range']['error'])) {
            $meta['valid_range']['error'] = $meta['valid_range'][2];
        }
        if (isset($meta['valid_range']['min']) && $value < $meta['valid_range']['min'] || isset($meta['valid_range']['max']) && $value > $meta['valid_range']['max']) {
            if (isset($meta['valid_range']['error'])) {
                $param_error = $meta['valid_range']['error'];
            } else {
                if (isset($meta['valid_range']['min']) && isset($meta['valid_range']['max'])) {
                    $param_error = sprintf(T_('The value is invalid. It must be in the range from %s to %s.'), $meta['valid_range']['min'], $meta['valid_range']['max']);
                } elseif (isset($meta['valid_range']['max'])) {
                    $param_error = sprintf(T_('The value is invalid. It must be smaller than or equal to %s.'), $meta['valid_range']['max']);
                } else {
                    $param_error = sprintf(T_('The value is invalid. It must be greater than or equal to %s.'), $meta['valid_range']['min']);
                }
            }
            param_error($param_name, $param_error);
            return false;
        }
    }
    return true;
}
/**
 * Get content after email and before terminator line
 *
 * @param mixed $message
 * @param mixed $emails
 * @return string Content
 */
function dre_get_processing_content($content, $emails)
{
    $error_text = '';
    $emails = explode(', ', $emails);
    if (count($emails) > 0) {
        // If emails exist
        // Get last email
        $email = $emails[count($emails) - 1];
        if (!empty($email)) {
            // Get error text after last email address
            $error_text = trim(evo_substr($content, evo_strpos($content, $email) + evo_strlen($email)));
        }
        if (empty($error_text)) {
            // If error text is empty we should get all content before email
            $error_text = trim(evo_substr($content, 0, evo_strpos($content, $email)));
        }
    } else {
        // If no emails - get full content as error text
        $error_text = $content;
    }
    if (!empty($error_text)) {
        // Replace all new line sumbols with space symbol
        $error_text = str_replace(array("\r\n\r\n", "\r\n", "\n\n", "\n"), " ", $error_text);
    }
    return $error_text;
}
Exemplo n.º 15
0
/**
 * @param string param name
 * @param string param name
 * @param boolean Is a password required? (non-empty)
 * @param integer Minimum password length
 * @return boolean true if OK
 */
function param_check_passwords($var1, $var2, $required = false, $min_length = 6)
{
    $pass1 = get_param($var1);
    $pass2 = get_param($var2);
    if (!strlen($pass1) && !strlen($pass2) && !$required) {
        // empty is OK:
        return true;
    }
    if (!strlen($pass1)) {
        param_error($var1, T_('Please enter your new password.'));
        param_error($var2, T_('Please enter your new password twice.'));
        return false;
    }
    if (!strlen($pass2)) {
        param_error($var2, T_('Please enter your new password twice.'));
        return false;
    }
    // checking the password has been typed twice the same:
    if ($pass1 != $pass2) {
        param_error_multiple(array($var1, $var2), T_('You typed two different passwords.'));
        return false;
    }
    if (evo_strlen($pass1) < $min_length) {
        param_error_multiple(array($var1, $var2), sprintf(T_('The minimum password length is %d characters.'), $min_length));
        return false;
    }
    return true;
}
Exemplo n.º 16
0
/**
 * Display an URL, constrained to a max length
 *
 * @param string
 * @param integer
 */
function disp_url($url, $max_length = NULL)
{
    if (!empty($max_length) && evo_strlen($url) > $max_length) {
        $disp_url = htmlspecialchars(substr($url, 0, $max_length - 1)) . '&hellip;';
    } else {
        $disp_url = htmlspecialchars($url);
    }
    echo '<a href="' . $url . '">' . $disp_url . '</a>';
}