本文整理汇总了PHP中IPSLib::safeUnserialize方法的典型用法代码示例。如果您正苦于以下问题:PHP IPSLib::safeUnserialize方法的具体用法?PHP IPSLib::safeUnserialize怎么用?PHP IPSLib::safeUnserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPSLib
的用法示例。
在下文中一共展示了IPSLib::safeUnserialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: topicDeletePollVotes
/**
* Remove votes
*
* @return @e void
*/
public function topicDeletePollVotes()
{
//-----------------------------------------
// Permissions check
//-----------------------------------------
if (!$this->settings['poll_allow_vdelete'] and !$this->memberData['g_is_supmod']) {
$this->registry->output->showError('topic_cannot_vote', 103147, null, null, 403);
}
//-----------------------------------------
// What did we vote for?
//-----------------------------------------
$voter = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'voters', 'where' => "tid=" . $this->topic['tid'] . " and member_id=" . $this->memberData['member_id']));
if (!$voter) {
$this->registry->output->redirectScreen($this->lang->words['poll_vote_deleted'], $this->settings['base_url'] . "showtopic={$this->topic['tid']}&st=" . $this->request['st'], $this->topic['title_seo'], 'showtopic');
}
//-----------------------------------------
// Ok, we're here.. delete the votes
//-----------------------------------------
$this->DB->delete('voters', "tid=" . $this->topic['tid'] . " and member_id=" . $this->memberData['member_id']);
//-----------------------------------------
// Remove our votes
//-----------------------------------------
$myVotes = IPSLib::safeUnserialize($voter['member_choices']);
$pollData = IPSLib::safeUnserialize(stripslashes($this->topic['choices']));
if (is_array($myVotes) and is_array($pollData)) {
foreach ($myVotes as $_questionID => $data) {
foreach ($data as $_choice) {
$pollData[$_questionID]['votes'][$_choice]--;
$pollData[$_questionID]['votes'][$_choice] = $pollData[$_questionID]['votes'][$_choice] < 0 ? 0 : $pollData[$_questionID]['votes'][$_choice];
}
}
}
//-----------------------------------------
// Update
//-----------------------------------------
$update['votes'] = $this->topic['votes'] - 1;
$update['votes'] = $update['votes'] < 0 ? 0 : $update['votes'];
$update['choices'] = serialize($pollData);
$this->DB->update('polls', $update, "tid=" . $this->topic['tid']);
/* done */
$this->registry->output->redirectScreen($this->lang->words['poll_vote_deleted'], $this->settings['base_url'] . "showtopic={$this->topic['tid']}&st=" . $this->request['st'], $this->topic['title_seo'], 'showtopic');
}
示例2: editPost
/**
* Edit a post
*
* Usage:
* $post->setForumID(1);
* $post->setTopicID(5);
* $post->setPostID(100);
* $post->setAuthor( $member );
*
* $post->setPostContent( "Hello [b]there![/b]" );
* # Optional: No bbcode, etc parsing will take place
* # $post->setPostContentPreFormatted( "Hello <b>there!</b>" );
* $post->editPost();
*
* Exception Error Codes:
* NO_POSTING_PPD : No post ID set
* NO_CONTENT : No post content set
* CONTENT_TOO_LONG : Post is too long
*
* @return mixed
*/
public function editPost()
{
//-----------------------------------------
// Global checks and functions
//-----------------------------------------
try {
$this->globalSetUp();
} catch (Exception $error) {
$e = $error->getMessage();
if ($e != 'NO_POSTING_PPD') {
$this->_postErrors = $error->getMessage();
}
}
if ($this->_bypassPermChecks !== TRUE && IPSMember::isOnModQueue($this->getAuthor()) === NULL) {
$this->_postErrors = 'warnings_restrict_post_perm';
}
if (!$this->getPostContent() and !$this->getPostContentPreFormatted()) {
$this->_postErrors = 'NO_CONTENT';
}
//-----------------------------------------
// Get topic
//-----------------------------------------
try {
$topic = $this->editSetUp();
} catch (Exception $error) {
$this->_postErrors = $error->getMessage();
}
//-----------------------------------------
// Parse the post, and check for any errors.
//-----------------------------------------
$post = $this->compilePostData();
//-----------------------------------------
// Do we have a valid post?
//-----------------------------------------
if (strlen(trim(IPSText::removeControlCharacters(IPSText::br2nl($post['post'])))) < 1) {
$this->_postErrors = 'NO_CONTENT';
}
if (IPSText::mbstrlen($post['post']) > $this->settings['max_post_length'] * 1024) {
$this->_postErrors = 'CONTENT_TOO_LONG';
}
if ($this->_postErrors != "") {
//-----------------------------------------
// Show the form again
//-----------------------------------------
return FALSE;
}
//-----------------------------------------
// Ajax specifics
//-----------------------------------------
if ($this->getIsAjax() === TRUE) {
# Prevent polls from being edited
$this->can_add_poll = 0;
# Prevent titles from being edited
$this->edit_title = 0;
# Prevent open time from being edited
$this->can_set_open_time = 0;
# Prevent close time from being edited
$this->can_set_close_time = 0;
# Set Settings
$this->setSettings(array('enableSignature' => $this->_originalPost['use_sig'] ? 1 : 0, 'enableEmoticons' => $this->_originalPost['use_emo'] ? 1 : 0, 'post_htmlstatus' => $this->getSettings('post_htmlstatus')));
if (!$this->getAuthor('g_append_edit')) {
$this->request['add_edit'] = ($this->_originalPost['append_edit'] or !$this->getAuthor('g_append_edit') ? 1 : 0);
}
}
//-----------------------------------------
// Compile the poll
//-----------------------------------------
if ($this->can_add_poll) {
//-----------------------------------------
// Load the poll from the DB
//-----------------------------------------
$this->poll_data = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'polls', 'where' => "tid=" . intval($topic['tid'])));
$this->poll_answers = !empty($this->poll_data['choices']) && IPSLib::isSerialized($this->poll_data['choices']) ? IPSLib::safeUnserialize(stripslashes($this->poll_data['choices'])) : array();
}
//-----------------------------------------
// Compile the poll
//-----------------------------------------
$this->poll_questions = $this->compilePollData();
if ($this->_postErrors != "" or $this->getIsPreview() === TRUE) {
//.........这里部分代码省略.........
示例3: saveCustomize
/**
* UserCP Save Form: Customize
*
* @return array Errors
*/
public function saveCustomize()
{
/* Init */
$errors = array();
$custom = array();
$bg_nix = trim($this->request['bg_nix']);
$bg_url = trim($this->request['bg_url']);
$bg_tile = intval($this->request['bg_tile']);
$bg_color = trim(str_replace('#', '', $this->request['bg_color']));
/* reset custom */
$custom = IPSLib::safeUnserialize($this->memberData['pp_customization']);
/* Bug #21578 */
if (!$bg_color && $custom['bg_color']) {
$bg_color = $custom['bg_color'];
}
/* Delete all? */
if ($bg_nix) {
/* reset array */
$custom = array('bg_url' => '', 'type' => '', 'bg_color' => '', 'bg_tile' => '');
/* remove bg images */
IPSMember::getFunction()->removeUploadedBackgroundImages($this->memberData['member_id']);
} else {
if ($bg_url and $this->memberData['gbw_allow_url_bgimage']) {
/* Check */
if (!stristr($bg_url, 'http://') or preg_match('#\\(\\*#', $bg_url)) {
return array(0 => $this->lang->words['pp_bgimg_url_bad']);
}
$image_extension = strtolower(pathinfo($bg_url, PATHINFO_EXTENSION));
if (!in_array($image_extension, array('png', 'jpg', 'gif', 'jpeg'))) {
return array(0 => $this->lang->words['pp_bgimg_ext_bad']);
}
$custom['bg_url'] = $bg_url;
$custom['type'] = 'url';
} else {
if ($this->memberData['gbw_allow_upload_bgimage']) {
/* Load more lang strings */
$this->registry->class_localization->loadLanguageFile(array('public_profile'), 'members');
/* Upload img */
$img = IPSMember::getFunction()->uploadBackgroundImage();
if ($img['status'] == 'fail') {
return array(0 => sprintf($this->lang->words['pp_' . $img['error']], $img['maxSize']));
} else {
if ($img['final_location']) {
$custom['bg_url'] = $img['final_location'];
$custom['type'] = 'upload';
}
}
}
}
}
/* BG color */
$custom['bg_color'] = $bg_nix ? '' : IPSText::alphanumericalClean($bg_color);
/* Tile */
$custom['bg_tile'] = $bg_nix ? '' : $bg_tile;
/* Save it */
if (!$this->memberData['bw_disable_customization'] and $this->memberData['gbw_allow_customization']) {
IPSMember::save($this->memberData['member_id'], array('extendedProfile' => array('pp_profile_update' => IPS_UNIX_TIME_NOW, 'pp_customization' => serialize($custom))));
}
return TRUE;
}
示例4: buildDisplayData
//.........这里部分代码省略.........
if (isset(self::$_parsedSignatures[$member['member_id']])) {
$member['signature'] = self::$_parsedSignatures[$member['member_id']];
} else {
if ($member['cache_content']) {
$member['signature'] = '<!--signature-cached-' . gmdate('r', $member['cache_updated']) . '-->' . $member['cache_content'];
} else {
/* Grab the parser file */
if (self::$_sigParser === null) {
/* Load parser */
$classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
self::$_sigParser = new $classToLoad();
}
/* set up parser */
self::$_sigParser->set(array('memberData' => $member, 'parseBBCode' => 1, 'parseHtml' => $group_cache[$member['member_group_id']]['g_dohtml'] && $member['bw_html_sig'], 'parseEmoticons' => 1, 'parseArea' => 'signatures'));
$member['signature'] = self::$_sigParser->display($member['signature']);
IPSContentCache::update($member['member_id'], 'sig', $member['signature']);
}
self::$_parsedSignatures[$member['member_id']] = $member['signature'];
}
}
//-----------------------------------------
// If current session, reset last_activity
//-----------------------------------------
if (!empty($member['running_time'])) {
$member['last_activity'] = $member['running_time'] > $member['last_activity'] ? $member['running_time'] : $member['last_activity'];
}
//-----------------------------------------
// Online?
//-----------------------------------------
$time_limit = time() - ipsRegistry::$settings['au_cutoff'] * 60;
$member['_online'] = 0;
$bypass_anon = ipsRegistry::member()->getProperty('g_access_cp') ? 1 : 0;
list($be_anon, $loggedin) = explode('&', empty($member['login_anonymous']) ? '0&0' : $member['login_anonymous']);
/* Is not anon but the group might be forced to? */
if (empty($be_anon) && self::isLoggedInAnon($member)) {
$be_anon = 1;
}
/* Finally set the online flag */
if (($member['last_visit'] > $time_limit or $member['last_activity'] > $time_limit) and ($be_anon != 1 or $bypass_anon == 1) and $loggedin == 1) {
$member['_online'] = 1;
}
//-----------------------------------------
// Last Active
//-----------------------------------------
$member['_last_active'] = ipsRegistry::getClass('class_localization')->getDate($member['last_activity'], 'SHORT');
// Member last logged in anonymous ?
if ($be_anon == 1 && !ipsRegistry::member()->getProperty('g_access_cp')) {
$member['_last_active'] = ipsRegistry::getClass('class_localization')->words['private'];
}
//-----------------------------------------
// Rating
//-----------------------------------------
$member['_pp_rating_real'] = intval($member['pp_rating_real']);
//-----------------------------------------
// Display name formatted
//-----------------------------------------
$member['members_display_name_formatted'] = self::makeNameFormatted($member['members_display_name'], $member['member_id'] ? $member['member_group_id'] : ipsRegistry::$settings['guest_group']);
//-----------------------------------------
// Long display names
//-----------------------------------------
$member['members_display_name_short'] = IPSText::truncate($member['members_display_name'], 16);
//-----------------------------------------
// Reputation
//-----------------------------------------
$member['pp_reputation_points'] = $member['pp_reputation_points'] ? $member['pp_reputation_points'] : 0;
if ($parseFlags['reputation'] and $member['member_id']) {
if (!ipsRegistry::isClassLoaded('repCache')) {
$classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/class_reputation_cache.php', 'classReputationCache');
ipsRegistry::setClass('repCache', new $classToLoad());
}
$member['author_reputation'] = ipsRegistry::getClass('repCache')->getReputation($member['pp_reputation_points']);
}
//-----------------------------------------
// Other stuff not worthy of individual comments
//-----------------------------------------
$member['members_profile_views'] = isset($member['members_profile_views']) ? $member['members_profile_views'] : 0;
/* BG customization */
if ($member['pp_customization'] and !empty($member['gbw_allow_customization']) and !$member['bw_disable_customization']) {
$member['customization'] = IPSLib::safeUnserialize($member['pp_customization']);
if (is_array($member['customization'])) {
/* Figure out BG URL */
if ($member['customization']['type'] == 'url' and $member['customization']['bg_url'] and $member['gbw_allow_url_bgimage']) {
$member['customization']['_bgUrl'] = $member['customization']['bg_url'];
} else {
if ($member['customization']['type'] == 'upload' and $member['customization']['bg_url'] and $member['gbw_allow_upload_bgimage']) {
$member['customization']['_bgUrl'] = ipsRegistry::$settings['upload_url'] . '/' . $member['customization']['bg_url'];
} else {
if ($member['customization']['bg_color']) {
$member['customization']['type'] = 'bgColor';
}
}
}
}
}
/* Title is ambigious */
$member['member_title'] = $member['title'];
IPSDebug::setMemoryDebugFlag("IPSMember::buildDisplayData: " . $member['member_id'] . " - Completed", $_NOW);
$buildMembers[$_key] = $member;
return $member;
}
示例5: _generatePollBox
/**
* Generates the poll box
*
* @param string Form type (new/edit/reply)
* @return string HTML
* @author MattMecham
*/
protected function _generatePollBox($formType)
{
if ($this->can_add_poll) {
//-----------------------------------------
// Did someone hit preview / do we have
// post info?
//-----------------------------------------
$poll_questions = array();
$poll_question = "";
$poll_view_voters = 0;
$poll_choices = array();
$show_open = 0;
$is_mod = 0;
$poll_votes = array();
$poll_only = 0;
$poll_multi = array();
if ($this->settings['ipb_poll_only'] and ipsRegistry::$request['poll_only'] and ipsRegistry::$request['poll_only'] == 1) {
$poll_only = 1;
}
if (isset($_POST['question']) and is_array($_POST['question']) and count($_POST['question'])) {
foreach ($_POST['question'] as $id => $question) {
$poll_questions[$id] = IPSText::parseCleanValue($question);
}
$poll_question = ipsRegistry::$request['poll_question'];
$show_open = 1;
}
if (isset($_POST['multi']) and is_array($_POST['multi']) and count($_POST['multi'])) {
foreach ($_POST['multi'] as $id => $checked) {
$poll_multi[$id] = $checked;
}
}
if (isset($_POST['choice']) and is_array($_POST['choice']) and count($_POST['choice'])) {
foreach ($_POST['choice'] as $id => $choice) {
$poll_choices[$id] = IPSText::parseCleanValue($choice);
}
}
if ($formType == 'edit') {
if (isset($_POST['votes']) && is_array($_POST['votes']) and count($_POST['votes'])) {
foreach ($_POST['votes'] as $id => $vote) {
$poll_votes[$id] = $vote;
}
}
}
if ($formType == 'edit' and (!isset($_POST['question']) or !is_array($_POST['question']) or !count($_POST['question']) or $this->getIsPreview())) {
//-----------------------------------------
// Load the poll from the DB
//-----------------------------------------
$this->poll_data = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'polls', 'where' => "tid=" . $this->getTopicID()));
$this->poll_answers = IPSLib::safeUnserialize(stripslashes($this->poll_data['choices']));
if (!is_array($this->poll_answers) or !count($this->poll_answers)) {
$this->poll_answers = IPSLib::safeUnserialize(preg_replace('!s:(\\d+):"(.*?)";!se', "'s:'.strlen('\$2').':\"\$2\";'", stripslashes($this->poll_data['choices'])));
}
if (!is_array($this->poll_answers) or !count($this->poll_answers)) {
$this->poll_answers = array();
}
//-----------------------------------------
// Lezz go
//-----------------------------------------
foreach ($this->poll_answers as $question_id => $data) {
if (!$data['question'] or !is_array($data['choice'])) {
continue;
}
$poll_questions[$question_id] = $data['question'];
$poll_multi[$question_id] = isset($data['multi']) ? intval($data['multi']) : 0;
foreach ($data['choice'] as $choice_id => $text) {
$poll_choices[$question_id . '_' . $choice_id] = stripslashes($text);
$poll_votes[$question_id . '_' . $choice_id] = intval($data['votes'][$choice_id]);
}
}
$poll_only = 0;
if ($this->settings['ipb_poll_only'] and $this->poll_data['poll_only'] == 1) {
$poll_only = 1;
}
$poll_view_voters = $this->poll_data['poll_view_voters'];
$poll_question = $this->poll_data['poll_question'];
$show_open = $this->poll_data['choices'] ? 1 : 0;
$is_mod = $this->can_add_poll_mod;
} else {
$poll_view_voters = $this->request['poll_view_voters'];
}
return $this->registry->getClass('output')->getTemplate('post')->pollBox(array('max_poll_questions' => $this->max_poll_questions, 'max_poll_choices' => $this->max_poll_choices_per_question, 'poll_questions' => IPSText::simpleJsonEncode($poll_questions), 'poll_choices' => IPSText::simpleJsonEncode($poll_choices), 'poll_votes' => IPSText::simpleJsonEncode($poll_votes), 'show_open' => $show_open, 'poll_question' => $poll_question, 'is_mod' => $is_mod, 'poll_multi' => json_encode($poll_multi), 'poll_only' => $poll_only, 'poll_view_voters' => $poll_view_voters, 'poll_total_votes' => intval($this->poll_data['votes']), 'poll_data' => $this->poll_data, 'poll_answers' => $this->poll_answers));
}
return '';
}
示例6: _generatePollOutput
/**
* Generate the Poll output
*
* @return string
*/
public function _generatePollOutput()
{
/* Init */
$topicData = $this->registry->getClass('topics')->getTopicData();
$forumData = $this->forumClass->getForumById($topicData['forum_id']);
$showResults = 0;
$pollData = array();
//-----------------------------------------
// Get the poll information...
//-----------------------------------------
$this->DB->build(array('select' => '*', 'from' => 'polls', 'where' => 'tid=' . $topicData['tid']));
$this->DB->execute();
$poll = $this->DB->fetch();
//-----------------------------------------
// check we have a poll
//-----------------------------------------
if (!$poll['pid']) {
return array('html' => '', 'poll' => '');
}
//-----------------------------------------
// Do we have a poll question?
//-----------------------------------------
if (!$poll['poll_question']) {
$poll['poll_question'] = $topicData['title'];
}
//-----------------------------------------
// Poll only?
//-----------------------------------------
if ($poll['poll_only'] == 1) {
$this->registry->getClass('topics')->setTopicData('poll_only', true);
}
//-----------------------------------------
// Additional Poll Vars
//-----------------------------------------
$poll['_totalVotes'] = 0;
$poll['_memberVoted'] = 0;
$memberChoices = array();
//-----------------------------------------
// Have we voted in this poll?
//-----------------------------------------
/* Save a join @link http://community.invisionpower.com/tracker/issue-35773-pollsvoters-voters-table-joining-to-million-plus-rows/ */
if ($poll['poll_view_voters'] and $this->settings['poll_allow_public']) {
$this->DB->build(array('select' => 'v.*', 'from' => array('voters' => 'v'), 'where' => 'v.tid=' . $topicData['tid'], 'add_join' => array(array('select' => 'm.*', 'from' => array('members' => 'm'), 'where' => 'm.member_id=v.member_id', 'type' => 'left'))));
} else {
$this->DB->build(array('select' => '*', 'from' => 'voters', 'where' => 'tid=' . $topicData['tid']));
}
$this->DB->execute();
while ($voter = $this->DB->fetch()) {
$poll['_totalVotes']++;
if ($voter['member_id'] == $this->memberData['member_id']) {
$poll['_memberVoted'] = 1;
}
/* Member choices */
if ($voter['member_choices'] and ($poll['poll_view_voters'] and $this->settings['poll_allow_public'] or $voter['member_id'] == $this->memberData['member_id'])) {
$_choices = IPSLib::safeUnserialize($voter['member_choices']);
if (is_array($_choices) and count($_choices)) {
$memberData = array('member_id' => $voter['member_id'], 'members_seo_name' => $voter['member_id'] == $this->memberData['member_id'] ? $this->memberData['members_seo_name'] : $voter['members_seo_name'], 'members_display_name' => $voter['member_id'] == $this->memberData['member_id'] ? $this->memberData['members_display_name'] : $voter['members_display_name'], 'members_colored_name' => str_replace('"', '\\"', $voter['member_id'] == $this->memberData['member_id'] ? IPSMember::makeNameFormatted($this->memberData['members_display_name'], $this->memberData['member_group_id']) : IPSMember::makeNameFormatted($voter['members_display_name'], $voter['member_group_id'])), '_last' => 0);
foreach ($_choices as $_questionID => $data) {
foreach ($data as $_choice) {
$memberChoices[$_questionID][$_choice][$voter['member_id']] = $memberData;
}
}
}
}
}
//-----------------------------------------
// Already Voted
//-----------------------------------------
if ($poll['_memberVoted']) {
$showResults = 1;
}
//-----------------------------------------
// Created poll and can't vote in it
//-----------------------------------------
if ($poll['starter_id'] == $this->memberData['member_id'] and $this->settings['allow_creator_vote'] != 1) {
$showResults = 1;
}
//-----------------------------------------
// Guest, but can view results without voting
//-----------------------------------------
if (!$this->memberData['member_id'] and $this->settings['allow_result_view']) {
$showResults = 1;
}
//-----------------------------------------
// is the topic locked?
//-----------------------------------------
if ($topicData['state'] == 'closed') {
$showResults = 1;
}
//-----------------------------------------
// Can we see the poll before voting?
//-----------------------------------------
if ($this->settings['allow_result_view'] == 1 and $this->request['mode'] == 'show') {
$showResults = 1;
}
//.........这里部分代码省略.........