Esempio n. 1
0
/**
 * adapted from https://gist.github.com/ev3rywh3re/4573482
 */
function fnbx_html_tag($html)
{
    if (myEmpty($html)) {
        return;
    }
    $attributes = '';
    $composite = '';
    $spacer = '';
    if (!myIsset($html['return'])) {
        $html['return'] = false;
    }
    $reserved = array('tag', 'tag_type', 'attributes', 'tag_content', 'tag_content_before', 'tag_content_after', 'return');
    foreach ($html as $name => $option) {
        if (myInArray($name, $reserved)) {
            continue;
        }
        $attributes .= $name . '="' . $option . '" ';
    }
    if (myIsset($html['attributes'])) {
        $attributes .= $html['attributes'] . ' ' . $attributes;
    }
    if ($attributes != '') {
        $attributes = myRTrim($attributes);
        $spacer = ' ';
    }
    if (!myIsset($html['tag_type'])) {
        $html['tag_type'] = 'default';
    }
    if (myIsset($html['tag_content_before'])) {
        $composite .= $html['tag_content_before'];
    }
    $tmp = $html['tag_type'];
    if ($tmp == 'single') {
        if (myIsset($html['tag_content'])) {
            $composite .= $html['tag_content'];
        }
        if (myIsset($html['tag'])) {
            $composite .= '<' . $html['tag'] . $spacer . $attributes . '/>';
        }
    } else {
        if ($tmp == 'open') {
            if (myIsset($html['tag'])) {
                $composite .= '<' . $html['tag'] . $spacer . $attributes . '>';
            }
            if (myIsset($html['tag_content'])) {
                $composite .= $html['tag_content'];
            }
        } else {
            if ($tmp == 'close') {
                if (myIsset($html['tag_content'])) {
                    $composite .= $html['tag_content'];
                }
                if (myIsset($html['tag'])) {
                    $composite .= '</' . $html['tag'] . '>';
                }
            } else {
                if ($tmp == 'attributes') {
                    $composite = $attributes;
                } else {
                    if (myIsset($html['tag'])) {
                        $composite .= '<' . $html['tag'] . $spacer . $attributes . '>';
                    }
                    if (myIsset($html['tag_content'])) {
                        $composite .= $html['tag_content'];
                    }
                    if (myIsset($html['tag'])) {
                        $composite .= '</' . $html['tag'] . '>';
                    }
                }
            }
        }
    }
    if (myIsset($html['tag_content_after'])) {
        $composite .= $html['tag_content_after'];
    }
    if ($html['return'] == true) {
        return $composite;
    }
    echo $composite;
    return null;
}
function myIsset($variable)
{
    if (!isset($variable) || trim($variable) == '') {
        return false;
    } else {
        return true;
    }
}
if (myIsset($_POST['newPass']) && myIsset($_POST['verifyPass']) && $_POST['changePassSubmit'] != 'true') {
    if ($_POST['newPass'] == $_POST['verifyPass']) {
        echo '';
    } else {
        echo "Passwords don't match.";
    }
} else {
    if (myIsset($_POST['currentPass']) && myIsset($_POST['newPass']) && $_POST['changePassSubmit'] == 'true') {
        $pass = htmlspecialchars($_POST['currentPass']);
        $user = $_SESSION['loggedin'];
        if (checkCredentials($user, $pass)) {
            $newPass = htmlspecialchars($_POST['newPass']);
            if ($newPass == $pass) {
                echo 'Your new password must be different from your current password.';
                exit;
            }
            $link = retrieve_mysqli();
            $queryString = 'UPDATE user SET salt = ?, hashed_password = ? WHERE username = ?';
            // get salt and hash password
            mt_srand();
            $salt = mt_rand();
            $hashPass = generateHash($salt . $newPass);
            // query the database
Esempio n. 3
0
/**
 * adapted from https://developer.wordpress.org/reference/functions/backslashit/
 */
function force_balance_tags($text)
{
    $tagstack = array();
    $stacksize = 0;
    $tagqueue = '';
    $newtext = '';
    // Known single-entity/self-closing tags
    $single_tags = array('area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source');
    // Tags that can be immediately nested within themselves
    $nestable_tags = array('blockquote', 'div', 'object', 'q', 'span');
    // WP bug fix for comments - in case you REALLY meant to type '< !--'
    $text = str_replace('< !--', '<    !--', $text);
    // WP bug fix for LOVE <3 (and other situations with '<' before a number)
    $text = myPregReplace('#<([0-9]{1})#', '&lt;$1', $text);
    $regex = [];
    while (myPregMatch("/<(\\/?[\\w:]*)\\s*([^>]*)>/", $text, $regex)) {
        $newtext .= $tagqueue;
        $i = myStrPos($text, $regex[0]);
        $l = myStrLen($regex[0]);
        // clear the shifter
        $tagqueue = '';
        // Pop or Push
        if (myIsset($regex[1][0]) && '/' == $regex[1][0]) {
            // End Tag
            $tag = myStrToLower(mySubstr2($regex[1], 1));
            // if too many closing tags
            if ($stacksize <= 0) {
                $tag = '';
                // or close to be safe $tag = '/' . $tag;
            } else {
                if ($tagstack[$stacksize - 1] == $tag) {
                    // found closing tag
                    $tag = '</' . $tag . '>';
                    // Close Tag
                    // Pop
                    myArrayPop($tagstack);
                    $stacksize--;
                } else {
                    // closing tag not at top, search for it
                    for ($j = $stacksize - 1; $j >= 0; $j--) {
                        if ($tagstack[$j] == $tag) {
                            // add tag to tagqueue
                            for ($k = $stacksize - 1; $k >= $j; $k--) {
                                $tagqueue .= '</' . myArrayPop($tagstack) . '>';
                                $stacksize--;
                            }
                            break;
                        }
                    }
                    $tag = '';
                }
            }
        } else {
            // Begin Tag
            $tag = myStrToLower($regex[1]);
            // Tag Cleaning
            // If it's an empty tag "< >", do nothing
            if ('' == $tag) {
                // do nothing
            } else {
                if (mySubstr2($regex[2], -1) == '/') {
                    // ...but it isn't a known single-entity self-closing tag, then don't let it be treated as such and
                    // immediately close it with a closing tag (the tag will encapsulate no text as a result)
                    if (!myInArray($tag, $single_tags)) {
                        $regex[2] = myTrim(mySubstr($regex[2], 0, -1)) . '></' . $tag;
                    }
                } else {
                    if (myInArray($tag, $single_tags)) {
                        $regex[2] .= '/';
                    } else {
                        // If the top of the stack is the same as the tag we want to push, close previous tag
                        if ($stacksize > 0 && !myInArray($tag, $nestable_tags) && $tagstack[$stacksize - 1] == $tag) {
                            $tagqueue = '</' . myArrayPop($tagstack) . '>';
                            $stacksize--;
                        }
                        $stacksize = myArrayPush($tagstack, $tag);
                    }
                }
            }
            // Attributes
            $attributes = $regex[2];
            if (!myEmpty($attributes) && $attributes[0] != '>') {
                $attributes = ' ' . $attributes;
            }
            $tag = '<' . $tag . $attributes . '>';
            //If already queuing a close tag, then put this tag on, too
            if (!myEmpty($tagqueue)) {
                $tagqueue .= $tag;
                $tag = '';
            }
        }
        $newtext .= mySubstr($text, 0, $i) . $tag;
        $text = mySubstr2($text, $i + $l);
    }
    // Clear Tag Queue
    $newtext .= $tagqueue;
    // Add Remaining text
    $newtext .= $text;
    // Empty Stack
    while ($x = myArrayPop($tagstack)) {
        $newtext .= '</' . $x . '>';
    }
    // Add remaining tags to close
    // WP fix for the bug with HTML comments
    $newtext = str_replace("< !--", "<!--", $newtext);
    $newtext = str_replace("<    !--", "< !--", $newtext);
    return $newtext;
}