当前位置: 首页>>代码示例>>PHP>>正文


PHP sanitise_int函数代码示例

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


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

示例1: menu_builder_get_menu_select_option

/**
 * Recursively loop through all menu items and children to get correct options.
 *
 * @param array $menu_items  the current level of menu items
 * @param int   $entity_guid the current entity being edited (optional)
 * @param int   $depth       recursive depth for layout
 *
 * @return array the selection options
 */
function menu_builder_get_menu_select_option($menu_items, $entity_guid = 0, $depth = 0)
{
    $result = array();
    $entity_guid = sanitise_int($entity_guid, false);
    $depth = sanitise_int($depth, false);
    if (!empty($menu_items) && $depth < 4) {
        foreach ($menu_items as $menu_item) {
            $name = $menu_item->getName();
            if (!is_numeric($name)) {
                // skip extra menu items
                continue;
            }
            if (!empty($entity_guid) && $name == $entity_guid) {
                // skip yourself and all your children
                continue;
            }
            $result[$name] = trim(str_repeat("-", $depth) . " " . $menu_item->getText());
            $children = $menu_item->getChildren();
            if (!empty($children)) {
                $child_items = menu_builder_get_menu_select_option($children, $entity_guid, $depth + 1);
                if (!empty($child_items)) {
                    $result += $child_items;
                }
            }
        }
    }
    return $result;
}
开发者ID:n8b,项目名称:VMN,代码行数:37,代码来源:functions.php

示例2: DoTask

function DoTask()
{
    global $Administrator, $GAME;
    if (!$Administrator) {
        $mypage = page::standard();
        $mypage->title_body('Not authorised');
        $mypage->leaf('p', 'You are not authorised to make use of this page. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.');
        $mypage->finish();
    }
    $thenumber = sanitise_int(@$_POST['thenumber']);
    if ($thenumber < -9 or $thenumber > 99 or $thenumber == 0) {
        $mypage = page::standard();
        $mypage->title_body('Invalid input');
        $mypage->leaf('p', 'Expected a nonzero integer between -9 and 99 inclusive, but received ' . $thenumber . '. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.');
        $mypage->finish();
    }
    $interval = sanitise_enum(@$_POST['theinterval'], array('MINUTE', 'HOUR', 'DAY'));
    if (@$_POST['whattime'] == 'now') {
        $whattime = 'UTC_TIMESTAMP()';
    } else {
        $whattime = '"LastMove"';
    }
    $time_expr = 'TIMESTAMPADD(' . $interval . ', :thenumber:, ' . $whattime . ')';
    dbquery(DBQUERY_WRITE, 'UPDATE "Game" JOIN "GameInProgress" ON "Game"."GameID" = "GameInProgress"."Game" SET "Game"."LastMove" = ' . $time_expr . ', "GameInProgress"."GIPLastMove" = ' . $time_expr . ' "Game"."GameTicker" = CONCAT("Game"."GameTicker", :tickerconcat:), "Game"."GameTickerNames" = CONCAT("Game"."GameTickerNames", :namesconcat:) WHERE "GameID" = :game:', 'thenumber', $thenumber, 'tickerconcat', '3A' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), 'namesconcat', '|' . $_SESSION['MyUserName'], 'game', $GAME['GameID']);
    dbquery(DBQUERY_COMMIT);
    page::redirect(3, 'board.php?GameID=' . $GAME['GameID'], 'Successfully altered clock.');
}
开发者ID:hdp,项目名称:brass,代码行数:27,代码来源:gab.php

示例3: todos_get_open_assigned_item_options

/**
 * returns an array to be used in elgg_get_* functions
 *
 * @param int $assignee     the guid of the assigned user
 * @param int $group_filter optional group filter
 *
 * @return array
 */
function todos_get_open_assigned_item_options($assignee = 0, $group_filter = 0)
{
    $assignee = sanitise_int($assignee, false);
    $group_filter = sanitise_int($group_filter, false);
    $options = array('type' => 'object', 'subtype' => TodoItem::SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => array(array('name' => 'order', 'value' => 0, 'operand' => '>')), 'full_view' => false, 'item_class' => 'todos-list-item', 'list_class' => 'todos-list mtl', 'pagination' => false);
    if (!empty($assignee)) {
        // assiged to specific person
        $options['metadata_name_value_pairs'][] = array('name' => 'assignee', 'value' => $assignee);
        $options['show_assignee'] = false;
    } else {
        // just assigned
        $options['metadata_name_value_pairs'][] = array('name' => 'assignee', 'value' => 0, 'operand' => '>');
    }
    if (!empty($group_filter) && $assignee !== $group_filter) {
        $group_lists = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => TodoList::SUBTYPE, 'container_guid' => $group_filter, 'limit' => false, 'callback' => false, 'metadata_name_value_pairs' => array('active' => true)));
        if (!empty($group_lists)) {
            $guids = array();
            foreach ($group_lists as $row) {
                $guids[] = (int) $row->guid;
            }
            $options['wheres'] = array('e.container_guid IN (' . implode(',', $guids) . ')');
        }
    }
    return $options;
}
开发者ID:coldtrick,项目名称:todos,代码行数:33,代码来源:functions.php

示例4: DoTask

function DoTask()
{
    global $GAME;
    if ($GAME['MyColour'] == 50) {
        $mypage = page::standard();
        $mypage->title_body('Not playing in this game');
        $mypage->leaf('p', 'You are not currently playing in this game. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.');
        $mypage->finish();
    }
    if (@$_POST['FirstCardNotMyTurn'] == 'NoCardSelected' or @$_POST['SecondCardNotMyTurn'] == 'NoCardSelected') {
        $mypage = page::standard();
        $mypage->title_body('Cards not selected');
        $mypage->leaf('p', 'You omitted to select a card in one or both of the selection lists. Please select a card in each list and then try again. Click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.');
        $mypage->finish();
    }
    $FC = sanitise_int(@$_POST['FirstCardNotMyTurn'], SANITISE_NO_FLAGS, 0, $GAME['HandSize'][$GAME['MyColour']] - 1);
    $SC = sanitise_int(@$_POST['SecondCardNotMyTurn'], SANITISE_NO_FLAGS, 0, $GAME['HandSize'][$GAME['MyColour']] - 1);
    if ($FC == $SC) {
        $mypage = page::standard();
        $mypage->title_body('Same cards selected');
        $mypage->leaf('p', 'You selected the same card in each selection list. Please select a different card in each list and then try again. Click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.');
        $mypage->finish();
    }
    $CardSwitch = $GAME['Cards'][$GAME['MyColour']][$FC];
    $GAME['Cards'][$GAME['MyColour']][$FC] = $GAME['Cards'][$GAME['MyColour']][$SC];
    $GAME['Cards'][$GAME['MyColour']][$SC] = $CardSwitch;
    dbformatgamedata();
    page::redirect(3, 'board.php?GameID=' . $GAME['GameID'], 'Successfully swapped cards.');
}
开发者ID:hdp,项目名称:brass,代码行数:29,代码来源:gaq.php

示例5: batchSync

 /**
  * Batch sync data to ElasticSearch
  *
  * This function is timed at a max runtime of 30sec
  *
  * @param array  $options   the options for elgg_get_entities()
  * @param int    $crontime the starttime of the cron in order to limit max runtime
  * @param string $getter    the getter function to use for \ElggBatch
  *
  * @return bool|void
  */
 protected static function batchSync($options, $crontime, $getter = '')
 {
     if (empty($options) || !is_array($options)) {
         return;
     }
     if (empty($getter)) {
         $getter = 'elgg_get_entities_from_private_settings';
     }
     if (!is_callable($getter)) {
         return false;
     }
     $client = elasticsearch_get_client();
     if (empty($client)) {
         return;
     }
     $crontime = sanitise_int($crontime, false);
     if (empty($crontime)) {
         $crontime = time();
     }
     if (time() - $crontime >= 30) {
         return false;
     }
     set_time_limit(40);
     $ia = elgg_set_ignore_access(true);
     $time_left = true;
     $batch_size = 100;
     $options['callback'] = false;
     $options['limit'] = $batch_size;
     while ($time_left && ($rows = call_user_func($getter, $options))) {
         $guids = array();
         foreach ($rows as $row) {
             $guids[] = (int) $row->guid;
         }
         $result = $client->bulkIndexDocuments($guids);
         if (empty($result)) {
             break;
         }
         $items = elgg_extract('items', $result);
         foreach ($items as $item) {
             $guid = (int) elgg_extract('_id', elgg_extract('index', $item));
             $status = elgg_extract('status', elgg_extract('index', $item));
             if ($status !== 200) {
                 continue;
             }
             if (empty($guid)) {
                 continue;
             }
             set_private_setting($guid, ELASTICSEARCH_INDEXED_NAME, time());
         }
         if (time() - $crontime >= 30) {
             $time_left = false;
             break;
         }
     }
     // restore access
     elgg_set_ignore_access($ia);
     return $time_left;
 }
开发者ID:coldtrick,项目名称:elasticsearch,代码行数:69,代码来源:Cron.php

示例6: setIframeHeight

 function setIframeHeight($height)
 {
     $result = false;
     $height = sanitise_int($height);
     if (!empty($height)) {
         $result = $this->set("iframe_height", $height);
     }
     return $result;
 }
开发者ID:remy40,项目名称:gvrs,代码行数:9,代码来源:MultiDashboard.php

示例7: dataroot_browser_format_size

/**
 * Convert a byte size into something readable
 *
 * @param int $size the size to convert
 *
 * @return string
 */
function dataroot_browser_format_size($size)
{
    $size = sanitise_int($size, false);
    if (empty($size)) {
        return 'n/a';
    }
    $sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
    return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $sizes[$i];
}
开发者ID:coldtrick,项目名称:dataroot_browser,代码行数:16,代码来源:functions.php

示例8: elggx_fivestar_vote

/**
 * Handles voting on an entity
 *
 * @param  integer  $guid  The entity guid being voted on
 * @param  integer  $vote The vote
 * @return string   A status message to be returned to the client
 */
function elggx_fivestar_vote($guid, $vote)
{
    $result = false;
    // do we have an entity
    if (!empty($guid) && ($entity = get_entity($guid))) {
        // do we have a logged in user
        if ($user_guid = elgg_get_logged_in_user_guid()) {
            $vote = sanitise_int($vote, false);
            $annotation_options = array("guid" => $entity->getGUID(), "type" => $entity->getType(), "annotation_name" => "fivestar", "annotation_owner_guid" => $user_guid, "limit" => 1);
            // already voted?
            if ($annotations = elgg_get_annotations($annotation_options)) {
                // yes
                // are we allowed the change/cancel our vote
                // 1 = yes
                // 0 = no
                $change_cancel = (int) elgg_get_plugin_setting("change_cancel", "elggx_fivestar");
                // check if we want to cancel (vote = 0)
                if ($vote == 0 && $change_cancel) {
                    // fire a hook to allow other plugins to halt the action
                    $params = array("entity" => $entity, "vote" => $vote, "user_guid" => $user_guid);
                    if (!elgg_trigger_plugin_hook("elggx_fivestar:cancel", "all", $params, false)) {
                        // nobody stopped us, so remove the annotation
                        $annotations[0]->delete();
                        // let the user know
                        $result = elgg_echo("elggx_fivestar:deleted");
                    }
                } else {
                    if ($change_cancel) {
                        // we want to update
                        update_annotation($annotations[0]->id, "fivestar", $vote, "integer", $user_guid, ACCESS_PUBLIC);
                        $result = elgg_echo("elggx_fivestar:updated");
                    } else {
                        // not allowed to update/cancel
                        $result = elgg_echo("elggx_fivestar:nodups");
                    }
                }
            } elseif ($vote > 0) {
                // no, and wish to vote
                // fire a hook to allow other plugins to halt the action
                $params = array("entity" => $entity, "vote" => $vote, "user_guid" => $user_guid);
                if (!elgg_trigger_plugin_hook("elggx_fivestar:vote", "all", $params, false)) {
                    // nobody stopped us, so save the vote
                    $entity->annotate("fivestar", $vote, ACCESS_PUBLIC, $user_guid);
                }
            } else {
                // incorrect vote
                $result = elgg_echo("elggx_fivestar:novote");
            }
            // update the avarage vote on the entity
            elggx_fivestar_set_rating($entity);
        }
    }
    return $result;
}
开发者ID:pleio,项目名称:elggx_fivestar,代码行数:61,代码来源:functions.php

示例9: livesearch

 /**
  * listen to the livesearch in order to provide the objects picker
  *
  * @param string $hook         the name of the hook
  * @param string $type         the type of the hook
  * @param array  $return_value current return value
  * @param array  $params       supplied params
  *
  * @return void
  */
 public static function livesearch($hook, $type, $return_value, $params)
 {
     // only return results to logged in users.
     $user = elgg_get_logged_in_user_entity();
     if (empty($user)) {
         return;
     }
     $q = get_input('term', get_input('q'));
     if (empty($q)) {
         return;
     }
     $input_name = get_input('name', 'objects');
     $q = sanitise_string($q);
     // replace mysql vars with escaped strings
     $q = str_replace(['_', '%'], ['\\_', '\\%'], $q);
     $match_on = get_input('match_on', 'all');
     if (!is_array($match_on)) {
         $match_on = [$match_on];
     }
     // only take over groups search
     if (count($match_on) > 1 || !in_array('objects', $match_on)) {
         return;
     }
     $owner_guid = ELGG_ENTITIES_ANY_VALUE;
     if (get_input('match_owner', false)) {
         $owner_guid = $user->getGUID();
     }
     $subtype = get_input('subtype', ELGG_ENTITIES_ANY_VALUE);
     $limit = sanitise_int(get_input('limit', 10), false);
     $container_guid = sanitise_int(get_input('container_guid'), false);
     if (empty($container_guid)) {
         $container_guid = ELGG_ENTITIES_ANY_VALUE;
     }
     if ($subtype === 'static' && $container_guid) {
         $owner_guid = $container_guid;
         $container_guid = ELGG_ENTITIES_ANY_VALUE;
     }
     // grab a list of entities and send them in json.
     $results = [];
     $options = ['type' => 'object', 'subtype' => $subtype, 'limit' => $limit, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'joins' => ['JOIN ' . elgg_get_config('dbprefix') . 'objects_entity oe ON e.guid = oe.guid'], 'wheres' => ["(oe.title LIKE '%{$q}%' OR oe.description LIKE '%{$q}%')"]];
     $entities = elgg_get_entities($options);
     if (!empty($entities)) {
         foreach ($entities as $entity) {
             $output = elgg_view('input/objectpicker/item', ['entity' => $entity, 'input_name' => $input_name, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid]);
             $result = ['type' => 'object', 'name' => $entity->title, 'desc' => $entity->description, 'guid' => $entity->getGUID(), 'label' => $output, 'value' => $entity->getGUID(), 'url' => $entity->getURL(), 'html' => $output];
             $results[] = $result;
         }
     }
     header('Content-Type: application/json');
     echo json_encode($results);
     exit;
 }
开发者ID:coldtrick,项目名称:objectpicker,代码行数:62,代码来源:Router.php

示例10: DoTask

function DoTask()
{
    global $Administrator, $GAME, $unexpectederrormessage;
    $AdminKickList = sanitise_int(@$_POST['AdminKickList']);
    $PostFailureTitle = false;
    do {
        if (!$Administrator) {
            $PostFailureTitle = 'Not authorised';
            $PostFailureMessage = 'You are not authorised to make use of this page. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to return to the board page, or <a href="index.php">here</a> to return to the Main Page.';
            break;
        }
        if (!@$_POST['CheckC']) {
            $PostFailureTitle = 'Tick box left unticked';
            $PostFailureMessage = 'The tick box was left unticked. You need to make sure the box is ticked - this is to prevent accidental use of the administrator controls. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.';
            break;
        }
        if ($GAME['GameStatus'] != 'In Progress' and $GAME['GameStatus'] != 'Recruiting Replacement') {
            $PostFailureTitle = 'Cannot kick player';
            $PostFailureMessage = 'Players cannot be kicked right now, perhaps because the game has finished. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.';
            break;
        }
        if ($AdminKickList < 0 or $AdminKickList >= MAX_PLAYERS) {
            $PostFailureTitle = 'Invalid input';
            $PostFailureMessage = 'Expected an integer between 0 and ' . (MAX_PLAYERS - 1) . ' inclusive, but received ' . $AdminKickList . '. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.';
            break;
        }
        if (!$GAME['PlayerExists'][$AdminKickList] or $GAME['PlayerMissing'][$AdminKickList]) {
            $PostFailureTitle = 'Seat is empty';
            $PostFailureMessage = 'The chosen seat is empty, or the chosen colour does not exist in this game. Perhaps the player was kicked in the meantime. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.';
            break;
        }
        if ($GAME['PlayersMissing'] + 1 == $GAME['CurrentPlayers']) {
            $PostFailureTitle = 'Only one player is not missing';
            $PostFailureMessage = 'This is the only player who is not missing. If you do not want the game to continue, please select to abort it instead. Click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.';
            break;
        }
    } while (false);
    if ($PostFailureTitle !== false) {
        $mypage = page::standard();
        $mypage->title_body($PostFailureTitle);
        $mypage->leaf('p', $PostFailureMessage);
        $mypage->finish();
    }
    KickPlayer($AdminKickList, 1);
    dbformatgamedata();
    page::redirect(3, 'board.php?GameID=' . $GAME['GameID'], 'Successfully kicked player.');
}
开发者ID:hdp,项目名称:brass,代码行数:47,代码来源:gad.php

示例11: friend_request_create_river_events

/**
 * Create river events when a friend is added
 *
 * @param int $user_guid   the user who is accepting
 * @param int $friend_guid the friend who he accepted
 *
 * @return bool
 */
function friend_request_create_river_events($user_guid, $friend_guid)
{
    $user_guid = sanitise_int($user_guid, false);
    $friend_guid = sanitise_int($friend_guid, false);
    if (empty($user_guid) || empty($friend_guid)) {
        return false;
    }
    // check plugin setting
    if (elgg_get_plugin_setting('add_river', 'friend_request') === 'no') {
        // no event are to be created
        return true;
    }
    // add to river
    elgg_create_river_item(['view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user_guid, 'object_guid' => $friend_guid]);
    elgg_create_river_item(['view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $friend_guid, 'object_guid' => $user_guid]);
    return true;
}
开发者ID:hypeJunction,项目名称:friend_request,代码行数:25,代码来源:functions.php

示例12: setUrl

 function setUrl($url = '')
 {
     if (preg_match('/(https?:\\/\\/)?((youtu\\.be\\/)|((www\\.)?(youtube\\.com\\/)))(.*)/', $url, $matches)) {
         $this->type = 'youtube';
     } elseif (preg_match('/(https?:\\/\\/)?(www\\.)?(vimeo\\.com\\/)(.*)/', $url, $matches)) {
         $this->type = 'vimeo';
     } elseif (preg_match('/(https?:\\/\\/)?(www\\.)?(dailymotion\\.com\\/)(.*)/', $url, $matches)) {
         $this->type = 'dailymotion';
     }
     switch ($this->type) {
         case 'youtube':
             $youtube_api_key = elgg_get_plugin_setting('youtube_api_key', 'izap_videos');
             if (preg_match('/(https?:\\/\\/)?(youtu\\.be\\/)(.*)/', $url, $matches)) {
                 $explode_char = '/';
                 $url_pram = explode($explode_char, $url);
                 $this->video_id = sanitise_string(end($url_pram));
             } else {
                 $url_pram = explode("?", $url);
                 $url_pram = explode("&", $url_pram[1]);
                 $url_pram = explode("=", $url_pram[0]);
                 $this->video_id = $url_pram[1];
             }
             $this->feed = array('url' => $this->youtube_api_capture['api_location'] . $this->video_id . '&key=' . $youtube_api_key, 'type' => 'youtube');
             break;
         case 'vimeo':
             $explode_char = '/';
             if (preg_match('/staffpicks#/', $url)) {
                 $explode_char = '#';
             }
             $url_pram = explode($explode_char, $url);
             $this->video_id = sanitise_int(end($url_pram));
             $this->feed = array('url' => $this->vimeo_api_capture['api_location'] . $this->video_id . '.php', 'type' => 'vimeo');
             break;
         case 'dailymotion':
             $explode_char = '/';
             $url_pram = explode($explode_char, $url);
             $this->video_id = sanitise_string(end($url_pram));
             $this->feed = array('url' => $this->dailymotion_api_capture['api_location'] . $this->video_id . '?fields=title,description,thumbnail_url,id,tags', 'type' => 'dailymotion');
             break;
         default:
             return 103;
             break;
     }
     return $this->capture();
 }
开发者ID:iionly,项目名称:izap_videos,代码行数:45,代码来源:video_feed.php

示例13: blog_tools_get_related_blogs

/**
 * Get related blogs to this blog
 *
 * @param ElggBlog $entity the blog to relate to
 * @param int      $limit  number of blogs to return
 *
 * @return bool|ElggBlog[]
 */
function blog_tools_get_related_blogs(ElggBlog $entity, $limit = 4)
{
    $result = false;
    $limit = sanitise_int($limit, false);
    if (!empty($entity) && elgg_instanceof($entity, "object", "blog")) {
        // transform to values
        $tag_values = $entity->tags;
        if (!empty($tag_values)) {
            if (!is_array($tag_values)) {
                $tag_values = array($tag_values);
            }
            // find blogs with these metadatavalues
            $options = array("type" => "object", "subtype" => "blog", "metadata_name" => "tags", "metadata_values" => $tag_values, "wheres" => array("(e.guid <> " . $entity->getGUID() . ")"), "group_by" => "e.guid", "order_by" => "count(msn.id) DESC", "limit" => $limit);
            $result = elgg_get_entities_from_metadata($options);
        }
    }
    return $result;
}
开发者ID:lorea,项目名称:Hydra-dev,代码行数:26,代码来源:functions.php

示例14: blog_tools_get_related_blogs

/**
 * Get related blogs to this blog
 *
 * @param ElggBlog $entity the blog to relate to
 * @param int      $limit  number of blogs to return
 *
 * @return false|ElggBlog[]
 */
function blog_tools_get_related_blogs(ElggBlog $entity, $limit = 4)
{
    $limit = sanitise_int($limit, false);
    if (!$entity instanceof ElggBlog) {
        return false;
    }
    // transform to values
    $tag_values = $entity->tags;
    if (empty($tag_values)) {
        return false;
    }
    if (!is_array($tag_values)) {
        $tag_values = [$tag_values];
    }
    // find blogs with these metadatavalues
    $options = ['type' => 'object', 'subtype' => 'blog', 'metadata_name' => 'tags', 'metadata_values' => $tag_values, 'wheres' => ["(e.guid <> {$entity->getGUID()})"], 'group_by' => 'e.guid', 'order_by' => 'count(msn.id) DESC', 'limit' => $limit];
    return elgg_get_entities_from_metadata($options);
}
开发者ID:coldtrick,项目名称:blog_tools,代码行数:26,代码来源:functions.php

示例15: quicklinks_check_relationship

/**
 * Check if the user has already linked this entity
 *
 * @param int $entity_guid the guid of the entity to check
 * @param int $user_guid   the user to check for (default: current user)
 *
 * @return bool
 */
function quicklinks_check_relationship($entity_guid, $user_guid = 0)
{
    static $cache;
    $entity_guid = sanitise_int($entity_guid, false);
    if (empty($entity_guid)) {
        return false;
    }
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return false;
    }
    if (!is_array($cache)) {
        $cache = [];
    }
    if (!isset($cache[$user_guid])) {
        $options = ['relationship' => QUICKLINKS_RELATIONSHIP, 'relationship_guid' => $user_guid, 'limit' => false, 'callback' => 'quicklinks_row_to_guid'];
        $cache[$user_guid] = elgg_get_entities_from_relationship($options);
    }
    return in_array($entity_guid, $cache[$user_guid]);
}
开发者ID:coldtrick,项目名称:quicklinks,代码行数:31,代码来源:functions.php


注:本文中的sanitise_int函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。