Pommo_Pending::add PHP Method

add() public method

returns the pending code (str) or FALSE if error
public add ( &$subscriber, $type = null )
    function add(&$subscriber, $type = null)
    {
        global $pommo;
        $dbo =& Pommo::$_dbo;
        $logger =& Pommo::$_logger;
        switch ($type) {
            case 'add':
            case 'del':
            case 'change':
            case 'password':
                break;
            default:
                $logger->addErr('Unknown type passed to Pommo_Pending::add');
                return false;
        }
        $p = array('subscriber_id' => $subscriber['id'], 'type' => $type, 'code' => Pommo_Helper::makeCode(), 'array' => $type == 'change' ? $subscriber : array());
        $pending = Pommo_Pending::make($p);
        if (!Pommo_Pending::validate($pending)) {
            $logger->addErr('Pommo_Pending::add() failed validation');
            return false;
        }
        if (!empty($pending['array'])) {
            $pending['array'] = serialize($pending['array']);
        }
        // check for pre-existing pending request
        if (Pommo_Pending::isPending($pending['subscriber_id'])) {
            return false;
        }
        $query = "\n            INSERT INTO " . $dbo->table['subscriber_pending'] . "\n            SET\n                [pending_array='%S',]\n                subscriber_id=%i,\n                pending_type='%s',\n                pending_code='%s'";
        $query = $dbo->prepare($query, array($pending['array'], $pending['subscriber_id'], $pending['type'], $pending['code']));
        if (!$dbo->query($query)) {
            return false;
        }
        return $pending['code'];
    }

Usage Example

示例#1
0
文件: index.php 项目: soonick/poMMo
        // generate captcha
        $captcha = substr(md5(rand()), 0, 4);
        $view->assign('captcha', $captcha);
    } elseif ($_POST['captcha'] == $_POST['realdeal']) {
        // user inputted captcha matched. Reset password
        require_once Pommo::$_baseDir . 'classes/Pommo_Pending.php';
        require_once Pommo::$_baseDir . 'classes/Pommo_Helper_Messages.php';
        // see if there is already a pending request for the administrator
        // [subscriber id == 0]
        if (Pommo_Pending::isPending(0)) {
            $input = urlencode(serialize(array('adminID' => TRUE, 'Email' => Pommo::$_config['admin_email'])));
            Pommo::redirect(Pommo::$_http . Pommo::$_baseUrl . 'pending.php?input=' . $input);
        }
        // create a password change request, send confirmation mail
        $subscriber = array('id' => 0);
        $code = Pommo_Pending::add($subscriber, 'password');
        Pommo_Helper_Messages::sendMessage(array('to' => Pommo::$_config['admin_email'], 'code' => $code, 'type' => 'password'));
        $view->assign('captcha', FALSE);
    } else {
        // captcha did not match
        $logger->addMsg(Pommo::_T('Captcha did not match. Try again.'));
    }
} elseif (!Pommo::$_hasConfigFile && $_POST['configure']) {
    //	Try to connect to database with data entered from the user.
    //	I am not using /inc/classes/db.php because it kills the proccess when
    //	connection is not possible
    //	TODO: db.php shouldnt kill the process
    $link = @mysql_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass']);
    if (!$link) {
        //	Could not connect
        $configErrors[] = 'Could not connect to host. Check your settings
All Usage Examples Of Pommo_Pending::add