• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP url_image_size函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中url_image_size函数的典型用法代码示例。如果您正苦于以下问题:PHP url_image_size函数的具体用法?PHP url_image_size怎么用?PHP url_image_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了url_image_size函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: imageTags

 protected function imageTags(&$data)
 {
     global $modSettings;
     // Do <img ... /> - with security... action= -> action-.
     preg_match_all('~&lt;img\\s+src=((?:&quot;)?)((?:https?://)\\S+?)\\1(?:\\s+alt=(&quot;.*?&quot;|\\S*?))?(?:\\s?/)?&gt;~i', $data, $matches, PREG_PATTERN_ORDER);
     if (!empty($matches[0])) {
         $replaces = array();
         foreach ($matches[2] as $match => $imgtag) {
             $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
             // Remove action= from the URL - no funny business, now.
             if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) !== 0) {
                 $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
             }
             // Check if the image is larger than allowed.
             // @todo - We should seriously look at deprecating some of this in favour of CSS resizing.
             if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) {
                 // For images, we'll want this
                 list($width, $height) = url_image_size($imgtag);
                 if (!empty($modSettings['max_image_width']) && $width > $modSettings['max_image_width']) {
                     $height = (int) ($modSettings['max_image_width'] * $height / $width);
                     $width = $modSettings['max_image_width'];
                 }
                 if (!empty($modSettings['max_image_height']) && $height > $modSettings['max_image_height']) {
                     $width = (int) ($modSettings['max_image_height'] * $width / $height);
                     $height = $modSettings['max_image_height'];
                 }
                 // Set the new image tag.
                 $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
             } else {
                 $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
             }
         }
         $data = strtr($data, $replaces);
     }
 }
开发者ID:joshuaadickerson,项目名称:BBC-Parser,代码行数:35,代码来源:HtmlParser.php


示例2: fixTags

function fixTags(&$message)
{
    global $modSettings;
    // WARNING: Editing the below can cause large security holes in your forum.
    // Edit only if you are sure you know what you are doing.
    $fixArray = array(array('tag' => 'img', 'protocols' => array('http', 'https'), 'embeddedUrl' => false, 'hasEqualSign' => false, 'hasExtra' => true), array('tag' => 'url', 'protocols' => array('http', 'https'), 'embeddedUrl' => true, 'hasEqualSign' => false), array('tag' => 'url', 'protocols' => array('http', 'https'), 'embeddedUrl' => true, 'hasEqualSign' => true), array('tag' => 'iurl', 'protocols' => array('http', 'https'), 'embeddedUrl' => true, 'hasEqualSign' => false), array('tag' => 'iurl', 'protocols' => array('http', 'https'), 'embeddedUrl' => true, 'hasEqualSign' => true), array('tag' => 'ftp', 'protocols' => array('ftp', 'ftps'), 'embeddedUrl' => true, 'hasEqualSign' => false), array('tag' => 'ftp', 'protocols' => array('ftp', 'ftps'), 'embeddedUrl' => true, 'hasEqualSign' => true), array('tag' => 'flash', 'protocols' => array('http', 'https'), 'embeddedUrl' => false, 'hasEqualSign' => false, 'hasExtra' => true));
    // Fix each type of tag.
    foreach ($fixArray as $param) {
        fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
    }
    // Now fix possible security problems with images loading links automatically...
    $message = preg_replace('~(\\[img.*?\\])(.+?)\\[/img\\]~eis', '\'$1\' . preg_replace(\'~action(=|%3d)(?!dlattach)~i\', \'action-\', \'$2\') . \'[/img]\'', $message);
    // Limit the size of images posted?
    if (!empty($modSettings['max_image_width']) || !empty($modSettings['max_image_height'])) {
        // Find all the img tags - with or without width and height.
        preg_match_all('~\\[img(\\s+width=\\d+)?(\\s+height=\\d+)?(\\s+width=\\d+)?\\](.+?)\\[/img\\]~is', $message, $matches, PREG_PATTERN_ORDER);
        $replaces = array();
        foreach ($matches[0] as $match => $dummy) {
            // If the width was after the height, handle it.
            $matches[1][$match] = !empty($matches[3][$match]) ? $matches[3][$match] : $matches[1][$match];
            // Now figure out if they had a desired height or width...
            $desired_width = !empty($matches[1][$match]) ? (int) substr(trim($matches[1][$match]), 6) : 0;
            $desired_height = !empty($matches[2][$match]) ? (int) substr(trim($matches[2][$match]), 7) : 0;
            // One was omitted, or both.  We'll have to find its real size...
            if (empty($desired_width) || empty($desired_height)) {
                list($width, $height) = url_image_size(un_htmlspecialchars($matches[4][$match]));
                // They don't have any desired width or height!
                if (empty($desired_width) && empty($desired_height)) {
                    $desired_width = $width;
                    $desired_height = $height;
                } elseif (empty($desired_width) && !empty($height)) {
                    $desired_width = (int) ($desired_height * $width / $height);
                } elseif (!empty($width)) {
                    $desired_height = (int) ($desired_width * $height / $width);
                }
            }
            // If the width and height are fine, just continue along...
            if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
                continue;
            }
            // Too bad, it's too wide.  Make it as wide as the maximum.
            if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width'])) {
                $desired_height = (int) ($modSettings['max_image_width'] * $desired_height / $desired_width);
                $desired_width = $modSettings['max_image_width'];
            }
            // Now check the height, as well.  Might have to scale twice, even...
            if ($desired_height > $modSettings['max_image_height'] && !empty($modSettings['max_image_height'])) {
                $desired_width = (int) ($modSettings['max_image_height'] * $desired_width / $desired_height);
                $desired_height = $modSettings['max_image_height'];
            }
            $replaces[$matches[0][$match]] = '[img' . (!empty($desired_width) ? ' width=' . $desired_width : '') . (!empty($desired_height) ? ' height=' . $desired_height : '') . ']' . $matches[4][$match] . '[/img]';
        }
        // If any img tags were actually changed...
        if (!empty($replaces)) {
            $message = strtr($message, $replaces);
        }
    }
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:58,代码来源:Subs-Post.php


示例3: parse_bbc


//.........这里部分代码省略.........
            $last_pos = max($last_pos, 0);
            // Pick a block of data to do some raw fixing on.
            $data = substr($message, $last_pos, $pos - $last_pos);
            // Take care of some HTML!
            if (!empty($modSettings['enablePostHTML']) && strpos($data, '&lt;') !== false) {
                $data = preg_replace('~&lt;a\\s+href=((?:&quot;)?)((?:https?://|ftps?://|mailto:)\\S+?)\\1&gt;~i', '[url=$2]', $data);
                $data = preg_replace('~&lt;/a&gt;~i', '[/url]', $data);
                // <br /> should be empty.
                $empty_tags = array('br', 'hr');
                foreach ($empty_tags as $tag) {
                    $data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
                }
                // b, u, i, s, pre... basic tags.
                $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
                foreach ($closable_tags as $tag) {
                    $diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
                    $data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
                    if ($diff > 0) {
                        $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
                    }
                }
                // Do <img ... /> - with security... action= -> action-.
                preg_match_all('~&lt;img\\s+src=((?:&quot;)?)((?:https?://|ftps?://)\\S+?)\\1(?:\\s+alt=(&quot;.*?&quot;|\\S*?))?(?:\\s?/)?&gt;~i', $data, $matches, PREG_PATTERN_ORDER);
                if (!empty($matches[0])) {
                    $replaces = array();
                    foreach ($matches[2] as $match => $imgtag) {
                        $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
                        // Remove action= from the URL - no funny business, now.
                        if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
                            $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
                        }
                        // Check if the image is larger than allowed.
                        if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) {
                            list($width, $height) = url_image_size($imgtag);
                            if (!empty($modSettings['max_image_width']) && $width > $modSettings['max_image_width']) {
                                $height = (int) ($modSettings['max_image_width'] * $height / $width);
                                $width = $modSettings['max_image_width'];
                            }
                            if (!empty($modSettings['max_image_height']) && $height > $modSettings['max_image_height']) {
                                $width = (int) ($modSettings['max_image_height'] * $width / $height);
                                $height = $modSettings['max_image_height'];
                            }
                            // Set the new image tag.
                            $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
                        } else {
                            $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
                        }
                    }
                    $data = strtr($data, $replaces);
                }
            }
            if (!empty($modSettings['autoLinkUrls'])) {
                // Are we inside tags that should be auto linked?
                $no_autolink_area = false;
                if (!empty($open_tags)) {
                    foreach ($open_tags as $open_tag) {
                        if (in_array($open_tag['tag'], $no_autolink_tags)) {
                            $no_autolink_area = true;
                        }
                    }
                }
                // Don't go backwards.
                //!!! Don't think is the real solution....
                $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
                if ($pos < $lastAutoPos) {
                    $no_autolink_area = true;
开发者ID:AhoyLemon,项目名称:ballpit,代码行数:67,代码来源:Subs.backup.2.php


示例4: resizeBBCImages

/**
 * Updates BBC img tags in a message so that the width / height respect the forum settings.
 *
 * - Will add the width/height attrib if needed, or update existing ones if they break the rules
 *
 * @package Posts
 * @param string $message
 */
function resizeBBCImages(&$message)
{
    global $modSettings;
    // We'll need this for image processing
    require_once SUBSDIR . '/Attachments.subs.php';
    // Find all the img tags - with or without width and height.
    preg_match_all('~\\[img(\\s+width=\\d+)?(\\s+height=\\d+)?(\\s+width=\\d+)?\\](.+?)\\[/img\\]~is', $message, $matches, PREG_PATTERN_ORDER);
    $replaces = array();
    foreach ($matches[0] as $match => $dummy) {
        // If the width was after the height, handle it.
        $matches[1][$match] = !empty($matches[3][$match]) ? $matches[3][$match] : $matches[1][$match];
        // Now figure out if they had a desired height or width...
        $desired_width = !empty($matches[1][$match]) ? (int) substr(trim($matches[1][$match]), 6) : 0;
        $desired_height = !empty($matches[2][$match]) ? (int) substr(trim($matches[2][$match]), 7) : 0;
        // One was omitted, or both.  We'll have to find its real size...
        if (empty($desired_width) || empty($desired_height)) {
            list($width, $height) = url_image_size(un_htmlspecialchars($matches[4][$match]));
            // They don't have any desired width or height!
            if (empty($desired_width) && empty($desired_height)) {
                $desired_width = $width;
                $desired_height = $height;
            } elseif (empty($desired_width) && !empty($height)) {
                $desired_width = (int) ($desired_height * $width / $height);
            } elseif (!empty($width)) {
                $desired_height = (int) ($desired_width * $height / $width);
            }
        }
        // If the width and height are fine, just continue along...
        if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
            continue;
        }
        // Too bad, it's too wide.  Make it as wide as the maximum.
        if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width'])) {
            $desired_height = (int) ($modSettings['max_image_width'] * $desired_height / $desired_width);
            $desired_width = $modSettings['max_image_width'];
        }
        // Now check the height, as well.  Might have to scale twice, even...
        if ($desired_height > $modSettings['max_image_height'] && !empty($modSettings['max_image_height'])) {
            $desired_width = (int) ($modSettings['max_image_height'] * $desired_width / $desired_height);
            $desired_height = $modSettings['max_image_height'];
        }
        $replaces[$matches[0][$match]] = '[img' . (!empty($desired_width) ? ' width=' . $desired_width : '') . (!empty($desired_height) ? ' height=' . $desired_height : '') . ']' . $matches[4][$match] . '[/img]';
    }
    // If any img tags were actually changed...
    if (!empty($replaces)) {
        $message = strtr($message, $replaces);
    }
}
开发者ID:KeiroD,项目名称:Elkarte,代码行数:56,代码来源:Post.subs.php


示例5: action_signatureSettings_display


//.........这里部分代码省略.........
                                                $sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset));
                                                // Stop looping.
                                                $img_offset = false;
                                            }
                                        }
                                    } else {
                                        $replaces[$image] = '';
                                    }
                                    continue;
                                }
                                // Does it have predefined restraints? Width first.
                                if ($matches[6][$key]) {
                                    $matches[2][$key] = $matches[6][$key];
                                }
                                if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) {
                                    $width = $sig_limits[5];
                                    $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
                                } elseif ($matches[2][$key]) {
                                    $width = $matches[2][$key];
                                }
                                // ... and height.
                                if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) {
                                    $height = $sig_limits[6];
                                    if ($width != -1) {
                                        $width = $width * ($height / $matches[4][$key]);
                                    }
                                } elseif ($matches[4][$key]) {
                                    $height = $matches[4][$key];
                                }
                                // If the dimensions are still not fixed - we need to check the actual image.
                                if ($width == -1 && $sig_limits[5] || $height == -1 && $sig_limits[6]) {
                                    // We'll mess up with images, who knows.
                                    require_once SUBSDIR . '/Attachments.subs.php';
                                    $sizes = url_image_size($matches[7][$key]);
                                    if (is_array($sizes)) {
                                        // Too wide?
                                        if ($sizes[0] > $sig_limits[5] && $sig_limits[5]) {
                                            $width = $sig_limits[5];
                                            $sizes[1] = $sizes[1] * ($width / $sizes[0]);
                                        }
                                        // Too high?
                                        if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) {
                                            $height = $sig_limits[6];
                                            if ($width == -1) {
                                                $width = $sizes[0];
                                            }
                                            $width = $width * ($height / $sizes[1]);
                                        } elseif ($width != -1) {
                                            $height = $sizes[1];
                                        }
                                    }
                                }
                                // Did we come up with some changes? If so remake the string.
                                if ($width != -1 || $height != -1) {
                                    $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
                                }
                                // Record that we got one.
                                $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
                            }
                            if (!empty($replaces)) {
                                $sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
                            }
                        }
                    }
                    // Try to fix disabled tags.
                    if (!empty($disabledTags)) {
开发者ID:KeiroD,项目名称:Elkarte,代码行数:67,代码来源:ManageFeatures.controller.php


示例6: ModifySignatureSettings


//.........这里部分代码省略.........
                                        if ($rep_img_count > $image_count_holder[$image]) {
                                            // Only replace the excess.
                                            $sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset));
                                            // Stop looping.
                                            $img_offset = false;
                                        }
                                    }
                                } else {
                                    $replaces[$image] = '';
                                }
                                continue;
                            }
                            // Does it have predefined restraints? Width first.
                            if ($matches[6][$key]) {
                                $matches[2][$key] = $matches[6][$key];
                            }
                            if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) {
                                $width = $sig_limits[5];
                                $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
                            } elseif ($matches[2][$key]) {
                                $width = $matches[2][$key];
                            }
                            // ... and height.
                            if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) {
                                $height = $sig_limits[6];
                                if ($width != -1) {
                                    $width = $width * ($height / $matches[4][$key]);
                                }
                            } elseif ($matches[4][$key]) {
                                $height = $matches[4][$key];
                            }
                            // If the dimensions are still not fixed - we need to check the actual image.
                            if ($width == -1 && $sig_limits[5] || $height == -1 && $sig_limits[6]) {
                                $sizes = url_image_size($matches[7][$key]);
                                if (is_array($sizes)) {
                                    // Too wide?
                                    if ($sizes[0] > $sig_limits[5] && $sig_limits[5]) {
                                        $width = $sig_limits[5];
                                        $sizes[1] = $sizes[1] * ($width / $sizes[0]);
                                    }
                                    // Too high?
                                    if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) {
                                        $height = $sig_limits[6];
                                        if ($width == -1) {
                                            $width = $sizes[0];
                                        }
                                        $width = $width * ($height / $sizes[1]);
                                    } elseif ($width != -1) {
                                        $height = $sizes[1];
                                    }
                                }
                            }
                            // Did we come up with some changes? If so remake the string.
                            if ($width != -1 || $height != -1) {
                                $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
                            }
                            // Record that we got one.
                            $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
                        }
                        if (!empty($replaces)) {
                            $sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
                        }
                    }
                }
                // Try to fix disabled tags.
                if (!empty($disabledTags)) {
开发者ID:Glyph13,项目名称:SMF2.1,代码行数:67,代码来源:ManageSettings.php


示例7: makeAvatarChanges

function makeAvatarChanges($memID, &$post_errors)
{
    global $modSettings, $sourcedir, $db_prefix;
    if (!isset($_POST['avatar_choice']) || empty($memID)) {
        return;
    }
    require_once $sourcedir . '/ManageAttachments.php';
    $uploadDir = empty($modSettings['custom_avatar_enabled']) ? $modSettings['attachmentUploadDir'] : $modSettings['custom_avatar_dir'];
    $downloadedExternalAvatar = false;
    if ($_POST['avatar_choice'] == 'external' && allowedTo('profile_remote_avatar') && strtolower(substr($_POST['userpicpersonal'], 0, 7)) == 'http://' && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external'])) {
        if (!is_writable($uploadDir)) {
            fatal_lang_error('attachments_no_write');
        }
        require_once $sourcedir . '/Subs-Package.php';
        $url = parse_url($_POST['userpicpersonal']);
        $contents = fetch_web_data('http://' . $url['host'] . (empty($url['port']) ? '' : ':' . $url['port']) . $url['path']);
        if ($contents != false && ($tmpAvatar = fopen($uploadDir . '/avatar_tmp_' . $memID, 'wb'))) {
            fwrite($tmpAvatar, $contents);
            fclose($tmpAvatar);
            $downloadedExternalAvatar = true;
            $_FILES['attachment']['tmp_name'] = $uploadDir . '/avatar_tmp_' . $memID;
        }
    }
    if ($_POST['avatar_choice'] == 'server_stored' && allowedTo('profile_server_avatar')) {
        $_POST['avatar'] = strtr(empty($_POST['file']) ? empty($_POST['cat']) ? '' : $_POST['cat'] : $_POST['file'], array('&amp;' => '&'));
        $_POST['avatar'] = preg_match('~^([\\w _!@%*=\\-#()\\[\\]&.,]+/)?[\\w _!@%*=\\-#()\\[\\]&.,]+$~', $_POST['avatar']) != 0 && preg_match('/\\.\\./', $_POST['avatar']) == 0 && file_exists($modSettings['avatar_directory'] . '/' . $_POST['avatar']) ? $_POST['avatar'] == 'blank.gif' ? '' : $_POST['avatar'] : '';
        // Get rid of their old avatar. (if uploaded.)
        removeAttachments('a.ID_MEMBER = ' . $memID);
    } elseif ($_POST['avatar_choice'] == 'external' && allowedTo('profile_remote_avatar') && strtolower(substr($_POST['userpicpersonal'], 0, 7)) == 'http://' && empty($modSettings['avatar_download_external'])) {
        // Remove any attached avatar...
        removeAttachments('a.ID_MEMBER = ' . $memID);
        $_POST['avatar'] = preg_replace('~action(=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']);
        if ($_POST['avatar'] == 'http://' || $_POST['avatar'] == 'http:///') {
            $_POST['avatar'] = '';
        } elseif (substr($_POST['avatar'], 0, 7) != 'http://') {
            $post_errors[] = 'bad_avatar';
        } elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external'])) {
            // Now let's validate the avatar.
            $sizes = url_image_size($_POST['avatar']);
            if (is_array($sizes) && ($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external']) || $sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))) {
                // Houston, we have a problem. The avatar is too large!!
                if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
                    $post_errors[] = 'bad_avatar';
                } elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') {
                    require_once $sourcedir . '/Subs-Graphics.php';
                    if (downloadAvatar($_POST['avatar'], $memID, $modSettings['avatar_max_width_external'], $modSettings['avatar_max_height_external'])) {
                        $_POST['avatar'] = '';
                    } else {
                        $post_errors[] = 'bad_avatar';
                    }
                }
            }
        }
    } elseif ($_POST['avatar_choice'] == 'upload' && allowedTo('profile_upload_avatar') || $downloadedExternalAvatar) {
        if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '' || $downloadedExternalAvatar) {
            // Get the dimensions of the image.
            if (!$downloadedExternalAvatar) {
                if (!is_writable($uploadDir)) {
                    fatal_lang_error('attachments_no_write');
                }
                if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $uploadDir . '/avatar_tmp_' . $memID)) {
                    fatal_lang_error('smf124');
                }
                $_FILES['attachment']['tmp_name'] = $uploadDir . '/avatar_tmp_' . $memID;
            }
            $sizes = @getimagesize($_FILES['attachment']['tmp_name']);
            // No size, then it's probably not a valid pic.
            if ($sizes === false) {
                $post_errors[] = 'bad_avatar';
            } elseif (!empty($modSettings['avatar_max_width_upload']) && $sizes[0] > $modSettings['avatar_max_width_upload'] || !empty($modSettings['avatar_max_height_upload']) && $sizes[1] > $modSettings['avatar_max_height_upload']) {
                if (!empty($modSettings['avatar_resize_upload'])) {
                    // Attempt to chmod it.
                    @chmod($uploadDir . '/avatar_tmp_' . $memID, 0644);
                    require_once $sourcedir . '/Subs-Graphics.php';
                    downloadAvatar($uploadDir . '/avatar_tmp_' . $memID, $memID, $modSettings['avatar_max_width_upload'], $modSettings['avatar_max_height_upload']);
                } else {
                    $post_errors[] = 'bad_avatar';
                }
            } elseif (is_array($sizes)) {
                // Though not an exhaustive list, better safe than sorry.
                $fp = fopen($_FILES['attachment']['tmp_name'], 'rb');
                if (!$fp) {
                    fatal_lang_error('smf124');
                }
                // Now try to find an infection.
                while (!feof($fp)) {
                    if (preg_match('~(iframe|\\<\\?php|\\<\\?[\\s=]|\\<%[\\s=]|html|eval|body|script\\W)~', fgets($fp, 4096)) === 1) {
                        if (file_exists($uploadDir . '/avatar_tmp_' . $memID)) {
                            @unlink($uploadDir . '/avatar_tmp_' . $memID);
                        }
                        fatal_lang_error('smf124');
                    }
                }
                fclose($fp);
                $extensions = array('1' => '.gif', '2' => '.jpg', '3' => '.png', '6' => '.bmp');
                $extension = isset($extensions[$sizes[2]]) ? $extensions[$sizes[2]] : '.bmp';
                $destName = 'avatar_' . $memID . $extension;
                list($width, $height) = getimagesize($_FILES['attachment']['tmp_name']);
                // Remove previous attachments this member might have had.
                removeAttachments('a.ID_MEMBER = ' . $memID);
//.........这里部分代码省略.........
开发者ID:alencarmo,项目名称:OCF,代码行数:101,代码来源:Profile.php


示例8: profileValidateSignature


//.........这里部分代码省略.........
                    $limit_broke = (int) $sig_limits[7] * 0.75 . 'pt';
                } elseif ($matches[2][$ind] == 'em' && $size > (double) $sig_limits[7] / 16) {
                    $limit_broke = (double) $sig_limits[7] / 16 . 'em';
                } elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
                    $limit_broke = 'large';
                }
                if ($limit_broke) {
                    $txt['profile_error_signature_max_font_size'] = sprintf($txt['profile_error_signature_max_font_size'], $limit_broke);
                    return 'signature_max_font_size';
                }
            }
        }
        // The difficult one - image sizes! Don't error on this - just fix it.
        if (!empty($sig_limits[5]) || !empty($sig_limits[6])) {
            // Get all BBC tags...
            preg_match_all('~\\[img(\\s+width=([\\d]+))?(\\s+height=([\\d]+))?(\\s+width=([\\d]+))?\\s*\\](?:<br />)*([^<">]+?)(?:<br />)*\\[/img\\]~i', $unparsed_signature, $matches);
            // ... and all HTML ones.
            preg_match_all('~<img\\s+src=(?:")?((?:http://|ftp://|https://|ftps://).+?)(?:")?(?:\\s+alt=(?:")?(.*?)(?:")?)?(?:\\s?/)?>~i', $unparsed_signature, $matches2, PREG_PATTERN_ORDER);
            // And stick the HTML in the BBC.
            if (!empty($matches2)) {
                foreach ($matches2[0] as $ind => $dummy) {
                    $matches[0][] = $matches2[0][$ind];
                    $matches[1][] = '';
                    $matches[2][] = '';
                    $matches[3][] = '';
                    $matches[4][] = '';
                    $matches[5][] = '';
                    $matches[6][] = '';
                    $matches[7][] = $matches2[1][$ind];
                }
            }
            $replaces = array();
            // Try to find all the images!
            if (!empty($matches)) {
                foreach ($matches[0] as $key => $image) {
                    $width = -1;
                    $height = -1;
                    // Does it have predefined restraints? Width first.
                    if ($matches[6][$key]) {
                        $matches[2][$key] = $matches[6][$key];
                    }
                    if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) {
                        $width = $sig_limits[5];
                        $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
                    } elseif ($matches[2][$key]) {
                        $width = $matches[2][$key];
                    }
                    // ... and height.
                    if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) {
                        $height = $sig_limits[6];
                        if ($width != -1) {
                            $width = $width * ($height / $matches[4][$key]);
                        }
                    } elseif ($matches[4][$key]) {
                        $height = $matches[4][$key];
                    }
                    // If the dimensions are still not fixed - we need to check the actual image.
                    if ($width == -1 && $sig_limits[5] || $height == -1 && $sig_limits[6]) {
                        $sizes = url_image_size($matches[7][$key]);
                        if (is_array($sizes)) {
                            // Too wide?
                            if ($sizes[0] > $sig_limits[5] && $sig_limits[5]) {
                                $width = $sig_limits[5];
                                $sizes[1] = $sizes[1] * ($width / $sizes[0]);
                            }
                            // Too high?
                            if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) {
                                $height = $sig_limits[6];
                                if ($width == -1) {
                                    $width = $sizes[0];
                                }
                                $width = $width * ($height / $sizes[1]);
                            } elseif ($width != -1) {
                                $height = $sizes[1];
                            }
                        }
                    }
                    // Did we come up with some changes? If so remake the string.
                    if ($width != -1 || $height != -1) {
                        $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
                    }
                }
                if (!empty($replaces)) {
                    $value = str_replace(array_keys($replaces), array_values($replaces), $value);
                }
            }
        }
        // Any disabled BBC?
        $disabledSigBBC = implode('|', $disabledTags);
        if (!empty($disabledSigBBC)) {
            if (preg_match('~\\[(' . $disabledSigBBC . ')~i', $unparsed_signature, $matches) !== false && isset($matches[1])) {
                $disabledTags = array_unique($disabledTags);
                $txt['profile_error_signature_disabled_bbc'] = sprintf($txt['profile_error_signature_disabled_bbc'], implode(', ', $disabledTags));
                return 'signature_disabled_bbc';
            }
        }
    }
    preparsecode($value);
    return true;
}
开发者ID:valek0972,项目名称:hackits,代码行数:101,代码来源:Profile-Modify.php


示例9: profileSaveAvatarData

/**
 * The avatar is incredibly complicated, what with the options... and what not.
 * @todo argh, the avatar here. Take this out of here!
 *
 * @param mixed[] $value
 * @return false|string
 */
function profileSaveAvatarData(&$value)
{
    global $modSettings, $profile_vars, $cur_profile, $context;
    $db = database();
    $memID = $context['id_member'];
    if (empty($memID) && !empty($context['password_auth_failed'])) {
        return false;
    }
    // We need to know where we're going to be putting it..
    require_once SUBSDIR . '/Attachments.subs.php';
    require_once SUBSDIR . '/ManageAttachments.subs.php';
    $uploadDir = getAvatarPath();
    $id_folder = getAvatarPathID();
    $downloadedExternalAvatar = false;
    $valid_http = isset($_POST['userpicpersonal']) && substr($_POST['userpicpersonal'], 0, 7) === 'http://' && strlen($_POST['userpicpersonal']) > 7;
    $valid_https = isset($_POST['userpicpersonal']) && substr($_POST['userpicpersonal'], 0, 8) === 'https://' && strlen($_POST['userpicpersonal']) > 8;
    if ($value == 'external' && allowedTo('profile_remote_avatar') && ($valid_http || $valid_https) && !empty($modSettings['avatar_download_external'])) {
        loadLanguage('Post');
        if (!is_writable($uploadDir)) {
            fatal_lang_error('attachments_no_write', 'critical');
        }
        require_once SUBSDIR . '/Package.subs.php';
        $url = parse_url($_POST['userpicpersonal']);
        $contents = fetch_web_data((empty($url['scheme']) ? 'http://' : $url['scheme'] . '://') . $url['host'] . (empty($url['port']) ? '' : ':' . $url['port']) . str_replace(' ', '%20', trim($url['path'])));
        if ($contents != false) {
            // Create a hashed name to save
            $new_avatar_name = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
            if (file_put_contents($new_avatar_name, $contents) !== false) {
                $downloadedExternalAvatar = true;
                $_FILES['attachment']['tmp_name'] = $new_avatar_name;
            }
        }
    }
    if ($value == 'none') {
        $profile_vars['avatar'] = '';
        // Reset the attach ID.
        $cur_profile['id_attach'] = 0;
        $cur_profile['attachment_type'] = 0;
        $cur_profile['filename'] = '';
        removeAttachments(array('id_member' => $memID));
    } elseif ($value == 'server_stored' && allowedTo('profile_server_avatar')) {
        $profile_vars['avatar'] = strtr(empty($_POST['file']) ? empty($_POST['cat']) ? '' : $_POST['cat'] : $_POST['file'], array('&amp;' => '&'));
        $profile_vars['avatar'] = preg_match('~^([\\w _!@%*=\\-#()\\[\\]&.,]+/)?[\\w _!@%*=\\-#()\\[\\]&.,]+$~', $profile_vars['avatar']) != 0 && preg_match('/\\.\\./', $profile_vars['avatar']) == 0 && file_exists($modSettings['avatar_directory'] . '/' . $profile_vars['avatar']) ? $profile_vars['avatar'] == 'blank.png' ? '' : $profile_vars['avatar'] : '';
        // Clear current profile...
        $cur_profile['id_attach'] = 0;
        $cur_profile['attachment_type'] = 0;
        $cur_profile['filename'] = '';
        // Get rid of their old avatar. (if uploaded.)
        removeAttachments(array('id_member' => $memID));
    } elseif ($value == 'gravatar' && allowedTo('profile_gravatar')) {
        $profile_vars['avatar'] = 'gravatar';
        // Reset the attach ID.
        $cur_profile['id_attach'] = 0;
        $cur_profile['attachment_type'] = 0;
        $cur_profile['filename'] = '';
        removeAttachments(array('id_member' => $memID));
    } elseif ($value == 'external' && allowedTo('profile_remote_avatar') && ($valid_http || $valid_https) && empty($modSettings['avatar_download_external'])) {
        // We need these clean...
        $cur_profile['id_attach'] = 0;
        $cur_profile['attachment_type'] = 0;
        $cur_profile['filename'] = '';
        // Remove any attached avatar...
        removeAttachments(array('id_member' => $memID));
        $profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
        if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
            $profile_vars['avatar'] = '';
        } elseif (!$valid_http && !$valid_https) {
            return 'bad_avatar';
        } elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external'])) {
            // Now let's validate the avatar.
            $sizes = url_image_size($profile_vars['avatar']);
            if (is_array($sizes) && ($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external']) || $sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))) {
                // Houston, we have a problem. The avatar is too large!!
                if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
                    return 'bad_avatar';
                } elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') {
                    // @todo remove this if appropriate
                    require_once SUBSDIR . '/Attachments.subs.php';
                    if (saveAvatar($profile_vars['avatar'], $memID, $modSettings['avatar_max_width_external'], $modSettings['avatar_max_height_external'])) {
                        $profile_vars['avatar'] = '';
                        $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
                        $cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
                        $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
                    } else {
                        return 'bad_avatar';
                    }
                }
            }
        }
    } elseif ($value == 'upload' && allowedTo('profile_upload_avatar') || $downloadedExternalAvatar) {
        if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '' || $downloadedExternalAvatar) {
            // Get the dimensions of the image.
            if (!$downloadedExternalAvatar) {
//.........这里部分代码省略.........
开发者ID:scripple,项目名称:Elkarte,代码行数:101,代码来源:Profile.subs.php


示例10: resizeImageURL

function resizeImageURL($sourceURL, $destinationFile, $max_width, $max_height)
{
    global $sourcedir;
    static $default_formats = array('1' => 'gif', '2' => 'jpeg', '3' => 'png', '6' => 'bmp', '15' => 'wbmp');
    require_once $sourcedir . '/Subs-Package.php';
    $success = false;
    $sizes = url_image_size($sourceURL);
    $fp_destination = fopen($destinationFile, 'wb');
    if ($fp_destination && substr($sourceURL, 0, 7) == 'http://') {
        $fileContents = fetch_web_data($sourceURL);
        fwrite($fp_destination, $fileContents);
        fclose($fp_destination);
    } elseif ($fp_destination) {
        $fp_source = fopen($sourceURL, 'rb');
        if ($fp_source !== false) {
            while (!feof($fp_source)) {
                fwrite($fp_destination, fread($fp_source, 8192));
            }
            fclose($fp_source);
        } else {
            $sizes = array(-1, -1, -1);
        }
        fclose($fp_destination);
    } else {
        $sizes = array(-1, -1, -1);
    }
    // Gif? That might mean trouble if gif support is not available.
    if ($sizes[2] == 1 && !function_exists('imagecreatefromgif') && function_exists('imagecreatefrompng')) {
        // Download it to the temporary file... use the special gif library... and save as png.
        if ($img = @gif_loadFile($destinationFile) && gif_outputAsPng($img, $destinationFile)) {
            $sizes[2] = 3;
        }
    }
    // A known and supported format?
    if (isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) {
        $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
        if ($src_img = @$imagecreatefrom($destinationFile)) {
            resizeImage($src_img, $destinationFile, imagesx($src_img), imagesy($src_img), $max_width === null ? imagesx($src_img) : $max_width, $max_height === null ? imagesy($src_img) : $max_height, true);
            $success = true;
        }
    }
    return $success;
}
开发者ID:Kheros,项目名称:MMOver,代码行数:43,代码来源:Subs-Graphics.php


示例11: downloadAvatar

function downloadAvatar($url, $memID, $max_width, $max_height)
{
    global $modSettings, $db_prefix, $sourcedir, $gd2;
    $destName = 'avatar_' . $memID . '.' . (!empty($modSettings['avatar_download_png']) ? 'png' : 'jpeg');
    $default_formats = array('1' => 'gif', '2' => 'jpeg', '3' => 'png', '6' => 'bmp', '15' => 'wbmp');
    // Check to see if GD is installed and what version.
    $testGD = get_extension_funcs('gd');
    // If GD is not installed, this function is pointless.
    if (empty($testGD)) {
        return false;
    }
    // Just making sure there is a non-zero member.
    if (empty($memID)) {
        return false;
    }
    // GD 2 maybe?
    $gd2 = in_array('imagecreatetruecolor', $testGD) && function_exists('imagecreatetruecolor');
    unset($testGD);
    require_once $sourcedir . '/ManageAttachments.php';
    removeAttachments('a.ID_MEMBER = ' . $memID);
    $avatar_hash = empty($modSettings['custom_avatar_enabled']) ? getAttachmentFilename($destName, false, true) : '';
    db_query("\n\t\tINSERT INTO {$db_prefix}attachments\n\t\t\t(ID_MEMBER, attachmentType, filename, file_hash, size)\n\t\tVALUES ({$memID}, " . (empty($modSettings['custom_avatar_enabled']) ? '0' : '1') . ", '{$destName}', '" . (empty($avatar_hash) ? "" : "{$avatar_hash}") . "', 1)", __FILE__, __LINE__);
    $attachID = db_insert_id();
    $destName = (empty($modSettings['custom_avatar_enabled']) ? $modSettings['attachmentUploadDir'] : $modSettings['custom_avatar_dir']) . '/' . $destName . '.tmp';
    $success = false;
    $sizes = url_image_size($url);
    require_once $sourcedir . '/Subs-Package.php';
    $fp = fopen($destName, 'wb');
    if ($fp && substr($url, 0, 7) == 'http://') {
        $fileContents = fetch_web_data($url);
        // Though not an exhaustive list, better safe than sorry.
        if (preg_match('~(iframe|\\<\\?php|\\<\\?[\\s=]|\\<%[\\s=]|html|eval|body|script\\W)~', $fileContents) === 1) {
            fclose($fp);
            return false;
        }
        fwrite($fp, $fileContents);
        fclose($fp);
    } elseif ($fp) {
        $fp2 = fopen($url, 'rb');
        $prev_chunk = '';
        while (!feof($fp2)) {
            $cur_chunk = fread($fp2, 8192);
            // Make sure nothing odd came through.
            if (preg_match('~(iframe|\\<\\?php|\\<\\?[\\s=]|\\<%[\\s=]|html|eval|body|script\\W)~', $prev_chunk . $cur_chunk) === 1) {
                fclose($fp2);
                fclose($fp);
                unlink($destName);
                return false;
            }
            fwrite($fp, $cur_chunk);
            $prev_chunk = $cur_chunk;
        }
        fclose($fp2);
        fclose($fp);
    } else {
        $sizes = array(-1, -1, -1);
    }
    // Gif? That might mean trouble if gif support is not available.
    if ($sizes[2] == 1 && !function_exists('imagecreatefromgif') && function_exists('imagecreatefrompng')) {
        // Download it to the temporary file... use the special gif library... and save as png.
        if ($img = @gif_loadFile($destName) && gif_outputAsPng($img, $destName)) {
            $sizes[2] = 3;
        }
    }
    // A known and supported format?
    if (isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) {
        $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
        if ($src_img = @$imagecreatefrom($destName)) {
            resizeImage($src_img, $destName, imagesx($src_img), imagesy($src_img), $max_width, $max_height);
            $success = true;
        }
    }
    // Remove the .tmp extension.
    $destName = substr($destName, 0, -4);
    if ($success) {
        // Remove the .tmp extension from the attachment.
        if (rename($destName . '.tmp', empty($avatar_hash) ? $destName : $m 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP url_implode函数代码示例发布时间:2022-05-23
下一篇:
PHP url_get_full_url函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap