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


PHP SQL::LIMIT方法代码示例

本文整理汇总了PHP中SQL::LIMIT方法的典型用法代码示例。如果您正苦于以下问题:PHP SQL::LIMIT方法的具体用法?PHP SQL::LIMIT怎么用?PHP SQL::LIMIT使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQL的用法示例。


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

示例1: CaptchaQuestionNew

    /**
     * Assign new random question for current IP address
     *
     * @return object Question row from DB table "questions"
     */
    function CaptchaQuestionNew()
    {
        global $DB, $Session;
        $IP = ip2int($_SERVER['REMOTE_ADDR']);
        // Get new random question from DB
        $SQL = new SQL();
        $SQL->SELECT('*');
        $SQL->FROM($this->get_sql_table('questions'));
        $SQL->ORDER_BY('RAND()');
        $SQL->LIMIT(1);
        $question = $DB->get_row($SQL->get());
        // Insert a record for current IP address with assigned question ID
        $DB->query('INSERT INTO ' . $this->get_sql_table('ip_question') . '
			( cptip_IP, cptip_cptq_ID ) VALUES
			( ' . $DB->quote($IP) . ', ' . $DB->quote($question->cptq_ID) . ' )');
        // Save the assigned question ID in the session
        $Session->set('captcha_qstn_' . $this->ID . '_ID', $question->cptq_ID);
        $Session->dbsave();
        $this->question_ID = $question->cptq_ID;
        return $question;
    }
开发者ID:ldanielz,项目名称:uesp.blog,代码行数:26,代码来源:_captcha_qstn.plugin.php

示例2: query

 /**
  * Run Query: GET DATA ROWS *** HEAVY ***
  */
 function query()
 {
     global $DB, $Session, $localtimenow;
     if (!is_null($this->rows)) {
         // Query has already executed:
         return;
     }
     // INIT THE QUERY:
     $this->query_init();
     // We are going to proceed in two steps (we simulate a subquery)
     // 1) we get the IDs we need
     // 2) we get all the other fields matching these IDs
     // This is more efficient than manipulating all fields at once.
     // *** STEP 1 ***
     $user_IDs = isset($this->filters['users']) ? $this->filters['users'] : array();
     if ($this->refresh_query || $localtimenow - $Session->get($this->filterset_name . '_refresh_time') > 7200) {
         // We should create new list of user IDs
         global $Timer;
         $Timer->start('Users_IDs', false);
         $step1_SQL = new SQL();
         $step1_SQL->SELECT('T_users.user_ID, IF( user_avatar_file_ID IS NOT NULL, 1, 0 ) as has_picture, COUNT( DISTINCT blog_ID ) AS nb_blogs');
         if (!empty($this->filters['reported']) && $this->filters['reported']) {
             // Filter is set to 'Reported users'
             $step1_SQL->SELECT_add(', COUNT( DISTINCT urep_reporter_ID ) AS user_rep');
         }
         $step1_SQL->FROM($this->UserQuery->get_from(''));
         $step1_SQL->WHERE($this->UserQuery->get_where(''));
         $step1_SQL->GROUP_BY($this->UserQuery->get_group_by(''));
         $step1_SQL->ORDER_BY($this->UserQuery->get_order_by(''));
         $step1_SQL->LIMIT(0);
         // Get list of the IDs we need:
         $user_IDs = $DB->get_col($step1_SQL->get(), 0, 'UserList::Query() Step 1: Get ID list');
         // Update filter with user IDs
         $this->filters['users'] = $user_IDs;
         $this->save_filterset();
         $Timer->stop('Users_IDs');
     }
     // GET TOTAL ROW COUNT:
     parent::count_total_rows(count($user_IDs));
     // Pagination, Get user IDs from array for current page
     $user_IDs_paged = array_slice($user_IDs, ($this->page - 1) * $this->limit, $this->limit);
     // *** STEP 2 ***
     $step2_SQL = $this->UserQuery;
     if (!empty($user_IDs_paged)) {
         // Init sql query to get users by IDs
         $step2_SQL->WHERE($this->Cache->dbIDname . ' IN (' . implode(',', $user_IDs_paged) . ') ');
         $step2_SQL->ORDER_BY('FIND_IN_SET( user_ID, "' . implode(',', $user_IDs_paged) . '" )');
     } else {
         // No users
         $step2_SQL->WHERE('user_ID IS NULL');
     }
     $this->sql = $step2_SQL->get();
     // ATTENTION: we skip the parent on purpose here!! fp> refactor
     DataObjectList2::query(false, false, false, 'UserList::Query() Step 2');
 }
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:58,代码来源:_userlist.class.php

示例3: SQL

 /**
  * Get messaging possibilities between current user and $this user
  *
  * @param object Current User (the one trying to send the PM)
  * @param string Type of contact method to check first: 'PM' > 'email'  
  * @return NULL|string allowed messaging possibility: PM > email > login > NULL
  */
 function get_msgform_possibility($current_User = NULL, $check_level = 'PM')
 {
     global $DB;
     $check_owner_SQL = new SQL();
     $check_owner_SQL->SELECT('blog_ID');
     $check_owner_SQL->FROM('T_blogs');
     $check_owner_SQL->WHERE('blog_owner_user_ID = ' . $DB->quote($this->ID));
     $check_owner_SQL->LIMIT('1');
     if ($DB->get_var($check_owner_SQL->get())) {
         // Always allow to contact this user because he is owner of at least one collection:
         $is_collection_owner = true;
     } else {
         $is_collection_owner = false;
     }
     if (!$is_collection_owner && !$this->check_status('can_receive_any_message')) {
         // In case of a closed account:
         return NULL;
     }
     if (is_logged_in()) {
         // current User is a registered user
         if ($current_User == NULL) {
             global $current_User;
         }
         if (!$is_collection_owner && has_cross_country_restriction('contact') && (empty($current_User->ctry_ID) || $current_User->ctry_ID !== $this->ctry_ID)) {
             // Contat to this user is not enabled
             return NULL;
         }
         if ($check_level == 'PM' && $this->accepts_pm() && $current_User->accepts_pm() && $this->ID != $current_User->ID) {
             // both user has permission to send or receive private message and not the same user
             // check if current_User is allowed to create a new conversation with this user.
             $blocked_contact = check_blocked_contacts(array($this->ID));
             if (empty($blocked_contact) && !$current_User->must_accept_terms()) {
                 // user is allowed to send pm to this user, and he didn't reached his new thread limit yet
                 return 'PM';
             }
         }
         if ($is_collection_owner || $this->accepts_email()) {
             // This User allows email => send email OR Force to allow to contact with this user because he is owner of the selected collection:
             return 'email';
         }
     } else {
         // current User is not logged in
         if ($is_collection_owner || $this->accepts_email()) {
             // This User allows email => send email OR Force to allow to contact with this user because he is owner of the selected collection:
             return 'email';
         }
         if ($this->accepts_pm()) {
             // no email option - try to log in and send private message (only registered users can send PM)
             return 'login';
         }
     }
     // no messaging option between current_User and this user
     return NULL;
 }
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:61,代码来源:_user.class.php

示例4: SQL

             $group_perms_SQL->SELECT('user_login');
             $group_perms_SQL->FROM('T_users');
             $group_perms_SQL->FROM_add('INNER JOIN T_coll_group_perms ON user_grp_ID = bloggroup_group_ID');
             $group_perms_SQL->WHERE('user_login LIKE "' . $DB->escape($text) . '%"');
             $group_perms_SQL->WHERE_and('bloggroup_blog_ID = ' . $DB->quote($blog_ID));
             $group_perms_SQL->WHERE_and('bloggroup_can_be_assignee <> 0');
             // Union two sql queries to execute one query and save an order as one list
             $users_sql = '( ' . $user_perms_SQL->get() . ' )' . ' UNION ' . '( ' . $group_perms_SQL->get() . ' )' . ' ORDER BY user_login' . ' LIMIT 10';
             break;
         default:
             // Get all users:
             $SQL = new SQL();
             $SQL->SELECT('user_login');
             $SQL->FROM('T_users');
             $SQL->WHERE('user_login LIKE "' . $DB->escape($text) . '%"');
             $SQL->LIMIT('10');
             $SQL->ORDER_BY('user_login');
             $users_sql = $SQL->get();
             break;
     }
     $user_logins = $DB->get_col($users_sql);
     if ($data_type == 'json') {
         // Return data in JSON format
         echo evo_json_encode($user_logins);
         exit(0);
         // Exit here to don't break JSON data by following debug data
     } else {
         // Return data as multilines
         echo implode("\n", $user_logins);
     }
 }
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:31,代码来源:async.php

示例5: display

    /**
     * Display the widget!
     *
     * @param array MUST contain at least the basic display params
     */
    function display($params)
    {
        $this->init_display($params);
        $UserCache =& get_UserCache();
        $UserList = new DataObjectList2($UserCache);
        switch ($this->disp_params['order_by']) {
            case 'regdate':
                $sql_order = 'user_created_datetime DESC';
                break;
            case 'moddate':
                $sql_order = 'user_profileupdate_date DESC';
                break;
            case 'random':
            default:
                $sql_order = 'RAND()';
                break;
        }
        // Query list of users with picture and not closed:
        $SQL = new SQL();
        $SQL->SELECT('*');
        $SQL->FROM('T_users');
        $SQL->WHERE('user_avatar_file_ID IS NOT NULL');
        $SQL->WHERE_and('user_status <> "closed"');
        if (is_logged_in()) {
            // Add filters
            global $current_User, $DB;
            switch ($this->disp_params['gender']) {
                // Filter by gender
                case 'same':
                    $SQL->WHERE_and('user_gender = "' . $current_User->gender . '"');
                    break;
                case 'opposite':
                    $SQL->WHERE_and('user_gender != "' . $current_User->gender . '"');
                    break;
            }
            switch ($this->disp_params['location']) {
                // Filter by location
                case 'city':
                    $SQL->WHERE_and('user_city_ID ' . (empty($current_User->city_ID) ? 'IS NULL' : '= "' . $current_User->city_ID . '"'));
                case 'subregion':
                    $SQL->WHERE_and('user_subrg_ID ' . (empty($current_User->subrg_ID) ? 'IS NULL' : '= "' . $current_User->subrg_ID . '"'));
                case 'region':
                    $SQL->WHERE_and('user_rgn_ID ' . (empty($current_User->rgn_ID) ? 'IS NULL' : '= "' . $current_User->rgn_ID . '"'));
                case 'country':
                    $SQL->WHERE_and('user_ctry_ID ' . (empty($current_User->ctry_ID) ? 'IS NULL' : '= "' . $current_User->ctry_ID . '"'));
                    break;
                case 'closest':
                    if (!empty($current_User->city_ID)) {
                        // Check if users exist with same city
                        $user_exists = $DB->get_var('SELECT user_ID
							 FROM T_users
							WHERE user_city_ID ="' . $current_User->city_ID . '"
							  AND user_ID != "' . $current_User->ID . '"
							LIMIT 1');
                        if (!empty($user_exists)) {
                            $SQL->WHERE_and('user_city_ID = "' . $current_User->city_ID . '"');
                            $SQL->WHERE_and('user_subrg_ID = "' . $current_User->subrg_ID . '"');
                            $SQL->WHERE_and('user_rgn_ID = "' . $current_User->rgn_ID . '"');
                            $SQL->WHERE_and('user_ctry_ID = "' . $current_User->ctry_ID . '"');
                            break;
                        }
                    }
                    if (!empty($current_User->subrg_ID) && empty($user_exists)) {
                        // Check if users exist with same sub-region
                        $user_exists = $DB->get_var('SELECT user_ID
							 FROM T_users
							WHERE user_subrg_ID ="' . $current_User->subrg_ID . '"
							  AND user_ID != "' . $current_User->ID . '"
							LIMIT 1');
                        if (!empty($user_exists)) {
                            $SQL->WHERE_and('user_subrg_ID = "' . $current_User->subrg_ID . '"');
                            $SQL->WHERE_and('user_rgn_ID = "' . $current_User->rgn_ID . '"');
                            $SQL->WHERE_and('user_ctry_ID = "' . $current_User->ctry_ID . '"');
                            break;
                        }
                    }
                    if (!empty($current_User->rgn_ID) && empty($user_exists)) {
                        // Check if users exist with same region
                        $user_exists = $DB->get_var('SELECT user_ID
							 FROM T_users
							WHERE user_rgn_ID ="' . $current_User->rgn_ID . '"
							  AND user_ID != "' . $current_User->ID . '"
							LIMIT 1');
                        if (!empty($user_exists)) {
                            $SQL->WHERE_and('user_rgn_ID = "' . $current_User->rgn_ID . '"');
                            $SQL->WHERE_and('user_ctry_ID = "' . $current_User->ctry_ID . '"');
                            break;
                        }
                    }
                    if (!empty($current_User->ctry_ID) && empty($user_exists)) {
                        // Check if users exist with same country
                        $user_exists = $DB->get_var('SELECT user_ID
							 FROM T_users
							WHERE user_ctry_ID ="' . $current_User->ctry_ID . '"
							  AND user_ID != "' . $current_User->ID . '"
//.........这里部分代码省略.........
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:101,代码来源:_user_avatars.widget.php

示例6: display

    /**
     * Display the widget!
     *
     * @param array MUST contain at least the basic display params
     */
    function display($params)
    {
        global $localtimenow;
        $this->init_display($params);
        if ($this->disp_params['order_by'] == 'RAND' && isset($this->BlockCache)) {
            // Do NOT cache if display order is random
            $this->BlockCache->abort_collect();
        }
        global $Blog;
        $list_blogs = $this->disp_params['blog_ID'] ? $this->disp_params['blog_ID'] : $Blog->ID;
        //pre_dump( $list_blogs );
        // Display photos:
        // TODO: permissions, complete statuses...
        // TODO: A FileList object based on ItemListLight but adding File data into the query?
        //          overriding ItemListLigth::query() for starters ;)
        $FileCache =& get_FileCache();
        $FileList = new DataObjectList2($FileCache);
        // Query list of files:
        $SQL = new SQL();
        $SQL->SELECT('post_ID, post_datestart, post_datemodified, post_main_cat_ID, post_urltitle, post_canonical_slug_ID,
									post_tiny_slug_ID, post_ptyp_ID, post_title, post_excerpt, post_url, file_ID,
									file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc');
        $SQL->FROM('T_categories INNER JOIN T_postcats ON cat_ID = postcat_cat_ID
									INNER JOIN T_items__item ON postcat_post_ID = post_ID
									INNER JOIN T_links ON post_ID = link_itm_ID
									INNER JOIN T_files ON link_file_ID = file_ID');
        $SQL->WHERE('cat_blog_ID IN (' . $list_blogs . ')');
        // fp> TODO: want to restrict on images :]
        $SQL->WHERE_and('post_status = "published"');
        // TODO: this is a dirty hack. More should be shown.
        $SQL->WHERE_and('post_datestart <= \'' . remove_seconds($localtimenow) . '\'');
        if (!empty($this->disp_params['item_type'])) {
            // Get items only with specified type
            $SQL->WHERE_and('post_ptyp_ID = ' . intval($this->disp_params['item_type']));
        }
        $SQL->GROUP_BY('link_ID');
        $SQL->LIMIT($this->disp_params['limit'] * 4);
        // fp> TODO: because we have no way of getting images only, we get 4 times more data than requested and hope that 25% at least will be images :/
        $SQL->ORDER_BY(gen_order_clause($this->disp_params['order_by'], $this->disp_params['order_dir'], 'post_', 'post_ID ' . $this->disp_params['order_dir'] . ', link_ID'));
        $FileList->sql = $SQL->get();
        $FileList->query(false, false, false, 'Media index widget');
        $layout = $this->disp_params['thumb_layout'];
        $nb_cols = $this->disp_params['grid_nb_cols'];
        $count = 0;
        $r = '';
        /**
         * @var File
         */
        while ($File =& $FileList->get_next()) {
            if ($count >= $this->disp_params['limit']) {
                // We have enough images already!
                break;
            }
            if (!$File->is_image()) {
                // Skip anything that is not an image
                // fp> TODO: maybe this property should be stored in link_ltype_ID or in the files table
                continue;
            }
            if ($layout == 'grid') {
                if ($count % $nb_cols == 0) {
                    $r .= $this->disp_params['grid_colstart'];
                }
                $r .= $this->disp_params['grid_cellstart'];
            } else {
                $r .= $this->disp_params['item_start'];
            }
            // 1/ Hack a dirty permalink( will redirect to canonical):
            // $link = url_add_param( $Blog->get('url'), 'p='.$post_ID );
            // 2/ Hack a link to the right "page". Very daring!!
            // $link = url_add_param( $Blog->get('url'), 'paged='.$count );
            // 3/ Instantiate a light object in order to get permamnent url:
            $ItemLight = new ItemLight($FileList->get_row_by_idx($FileList->current_idx - 1));
            // index had already been incremented
            $r .= '<a href="' . $ItemLight->get_permanent_url() . '">';
            // Generate the IMG THUMBNAIL tag with all the alt, title and desc if available
            $r .= $File->get_thumb_imgtag($this->disp_params['thumb_size'], '', '', $ItemLight->title);
            $r .= '</a>';
            if ($this->disp_params['disp_image_title']) {
                $title = $File->get('title') ? $this->get('title') : $ItemLight->title;
                $r .= '<span class="note">' . $title . '</span>';
            }
            ++$count;
            if ($layout == 'grid') {
                $r .= $this->disp_params['grid_cellend'];
                if ($count % $nb_cols == 0) {
                    $r .= $this->disp_params['grid_colend'];
                }
            } else {
                $r .= $this->disp_params['item_end'];
            }
        }
        // Exit if no files found
        if (empty($r)) {
            return;
        }
//.........这里部分代码省略.........
开发者ID:ldanielz,项目名称:uesp.blog,代码行数:101,代码来源:_coll_media_index.widget.php

示例7: create_profile_picture_links

/**
 * Create links between users and image files from the users profile_pictures folder
 */
function create_profile_picture_links()
{
    global $DB;
    load_class('files/model/_filelist.class.php', 'Filelist');
    load_class('files/model/_fileroot.class.php', 'FileRoot');
    $path = 'profile_pictures';
    $FileRootCache =& get_FileRootCache();
    $UserCache =& get_UserCache();
    // SQL query to get all users and limit by page below
    $users_SQL = new SQL();
    $users_SQL->SELECT('*');
    $users_SQL->FROM('T_users');
    $users_SQL->ORDER_BY('user_ID');
    $page = 0;
    $page_size = 100;
    while (count($UserCache->cache) > 0 || $page == 0) {
        // Load users by 100 at one time to avoid errors about memory exhausting
        $users_SQL->LIMIT($page * $page_size . ', ' . $page_size);
        $UserCache->clear();
        $UserCache->load_by_sql($users_SQL);
        while (($iterator_User =& $UserCache->get_next()) != NULL) {
            // Iterate through UserCache)
            $FileRootCache->clear();
            $user_FileRoot =& $FileRootCache->get_by_type_and_ID('user', $iterator_User->ID);
            if (!$user_FileRoot) {
                // User FileRoot doesn't exist
                continue;
            }
            $ads_list_path = get_canonical_path($user_FileRoot->ads_path . $path);
            // Previously uploaded avatars
            if (!is_dir($ads_list_path)) {
                // profile_picture folder doesn't exists in the user root dir
                continue;
            }
            $user_avatar_Filelist = new Filelist($user_FileRoot, $ads_list_path);
            $user_avatar_Filelist->load();
            if ($user_avatar_Filelist->count() > 0) {
                // profile_pictures folder is not empty
                $info_content = '';
                $LinkOwner = new LinkUser($iterator_User);
                while ($lFile =& $user_avatar_Filelist->get_next()) {
                    // Loop through all Files:
                    $fileName = $lFile->get_name();
                    if (process_filename($fileName)) {
                        // The file has invalid file name, don't create in the database
                        // TODO: asimo> we should collect each invalid file name here, and send an email to the admin
                        continue;
                    }
                    $lFile->load_meta(true);
                    if ($lFile->is_image()) {
                        $lFile->link_to_Object($LinkOwner);
                    }
                }
            }
        }
        // Increase page number to get next portion of users
        $page++;
    }
    // Clear cache data
    $UserCache->clear();
    $FileRootCache->clear();
}
开发者ID:ldanielz,项目名称:uesp.blog,代码行数:65,代码来源:_file.funcs.php

示例8: tool_create_sample_comments

/**
 * Create sample comments and display a process of creating
 *
 * @param integer Blog ID
 * @param integer Number of comments
 * @param integer Number of posts
 */
function tool_create_sample_comments($blog_ID, $num_comments, $num_posts)
{
    global $DB, $posttypes_specialtypes, $localtimenow, $Hit, $Messages, $Debuglog;
    $BlogCache =& get_BlogCache();
    $selected_Blog = $BlogCache->get_by_ID($blog_ID, false, false);
    if ($selected_Blog == NULL) {
        // Incorrect blog ID, Exit here
        return;
    }
    echo T_('Creating of the sample comments...');
    evo_flush();
    /**
     * Disable log queries because it increases the memory and stops the process with error "Allowed memory size of X bytes exhausted..."
     */
    $DB->log_queries = false;
    $curr_orderby = $selected_Blog->get_setting('orderby');
    if ($curr_orderby == 'RAND') {
        $curr_orderby .= '()';
    } else {
        $curr_orderby = 'post_' . $curr_orderby;
    }
    $curr_orderdir = $selected_Blog->get_setting('orderdir');
    // find the $num_posts latest posts in blog
    $SQL = new SQL();
    $SQL->SELECT('post_ID');
    $SQL->FROM('T_items__item');
    $SQL->FROM_add('INNER JOIN T_categories ON post_main_cat_ID = cat_ID');
    $SQL->WHERE('cat_blog_ID = ' . $DB->quote($blog_ID));
    $SQL->WHERE_and('post_status = ' . $DB->quote('published'));
    // Set condition to not create sample comments for special posts
    $SQL->WHERE_and('post_ptyp_ID NOT IN ( ' . $DB->quote($posttypes_specialtypes) . ' )');
    $SQL->ORDER_BY($curr_orderby . ' ' . $curr_orderdir . ', post_ID ' . $curr_orderdir);
    $SQL->LIMIT($num_posts);
    $items_result = $DB->get_results($SQL->get(), ARRAY_A, 'Find the x latest posts in blog');
    $count = 1;
    $fix_content = 'This is an auto generated comment for testing the moderation features.
					http://www.test.com/test_comment_';
    // go through on selected items
    foreach ($items_result as $row) {
        $item_ID = $row['post_ID'];
        $ItemCache =& get_ItemCache();
        $commented_Item =& $ItemCache->get_by_ID($item_ID);
        // create $num_comments comments for each item
        for ($i = 0; $i < $num_comments; $i++) {
            $author = 'Test ' . $count;
            $email = 'test_' . $count . '@test.com';
            $url = 'http://www.test-' . rand(1, 3) . '.com/test_comment_' . $count;
            $content = $fix_content . $count;
            for ($j = 0; $j < 50; $j++) {
                // create 50 random word
                $length = rand(1, 15);
                $word = generate_random_key($length, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
                $content = $content . ' ' . $word;
            }
            // create and save a new comment
            $Comment = new Comment();
            $Comment->set_Item($commented_Item);
            $Comment->set('status', 'draft');
            $Comment->set('author', $author);
            $Comment->set('author_email', $email);
            $Comment->set('author_url', $url);
            $Comment->set('content', $content);
            $Comment->set('date', date('Y-m-d H:i:s', $localtimenow));
            $Comment->set('author_IP', $Hit->IP);
            $Comment->dbsave();
            $count++;
            if ($count % 100 == 0) {
                // Display a process of creating by one dot for 100 comments
                echo ' .';
                evo_flush();
            }
            // Clear all debug messages, To avoid an error about full memory
            $Debuglog->clear('all');
        }
    }
    echo ' OK.';
    $Messages->add(sprintf(T_('Created %d comments.'), $count - 1), 'success');
}
开发者ID:ldanielz,项目名称:uesp.blog,代码行数:85,代码来源:_tool.funcs.php

示例9: get_tags

/**
 * Retrieves all tags from published posts
 *
 * @param integer the id of the blog or array of blog ids. Set NULL to use current blog
 * @param integer maximum number of returned tags
 * @param string a comma separated list of tags to ignore/exclude
 * @param bool true to skip tags from pages, intro posts and sidebar stuff
 * @return array of tags
 */
function get_tags($blog_ids, $limit = 0, $filter_list = NULL, $skip_intro_posts = false)
{
    global $DB, $localtimenow, $posttypes_specialtypes;
    $BlogCache =& get_BlogCache();
    if (is_null($blog_ids)) {
        global $blog;
        $blog_ids = $blog;
    }
    if (is_array($blog_ids)) {
        // Get quoted ID list
        $where_cat_clause = 'cat_blog_ID IN ( ' . $DB->quote($blog_ids) . ' )';
    } else {
        // Get list of relevant blogs
        $Blog =& $BlogCache->get_by_ID($blog_ids);
        $where_cat_clause = trim($Blog->get_sql_where_aggregate_coll_IDs('cat_blog_ID'));
    }
    // Build query to get the tags:
    $tags_SQL = new SQL();
    $tags_SQL->SELECT('tag_name, COUNT( DISTINCT itag_itm_ID ) AS tag_count, tag_ID, cat_blog_ID');
    $tags_SQL->FROM('T_items__tag');
    $tags_SQL->FROM_add('INNER JOIN T_items__itemtag ON itag_tag_ID = tag_ID');
    $tags_SQL->FROM_add('INNER JOIN T_items__item ON itag_itm_ID = post_ID');
    $tags_SQL->FROM_add('INNER JOIN T_postcats ON itag_itm_ID = postcat_post_ID');
    $tags_SQL->FROM_add('INNER JOIN T_categories ON postcat_cat_ID = cat_ID');
    $tags_SQL->WHERE($where_cat_clause);
    $tags_SQL->WHERE_and('post_status = "published"');
    $tags_SQL->WHERE_and('post_datestart < ' . $DB->quote(remove_seconds($localtimenow)));
    if ($skip_intro_posts) {
        // Skip "Intro" posts
        $tags_SQL->WHERE_and('post_ityp_ID NOT IN ( ' . implode(', ', $posttypes_specialtypes) . ' )');
    }
    if (!empty($filter_list)) {
        // Filter tags
        $tags_SQL->WHERE_and('tag_name NOT IN ( ' . $DB->quote(explode(', ', $filter_list)) . ' )');
    }
    $tags_SQL->GROUP_BY('tag_name');
    $tags_SQL->ORDER_BY('tag_count DESC');
    if (!empty($limit)) {
        // Limit
        $tags_SQL->LIMIT($limit);
    }
    return $DB->get_results($tags_SQL->get(), OBJECT, 'Get tags');
}
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:52,代码来源:_blog.funcs.php

示例10: dbm_delete_orphan_files

/**
 * Find and delete orphan File objects with no matching file on disk
 */
function dbm_delete_orphan_files()
{
    global $DB, $admin_url;
    $FileCache =& get_FileCache();
    $FileCache->clear();
    echo T_('Deleting of the orphan File objects from the database...');
    evo_flush();
    $files_SQL = new SQL();
    $files_SQL->SELECT('*');
    $files_SQL->FROM('T_files');
    $files_SQL->ORDER_BY('file_ID');
    $count_files_valid = 0;
    $count_files_invalid = 0;
    $count_files_deleted = 0;
    $page_size = 100;
    $current_page = 0;
    // Search the files by page to save memory
    $files_SQL->LIMIT('0, ' . $page_size);
    while ($loaded_Files = $FileCache->load_by_sql($files_SQL)) {
        // Check all loaded files
        foreach ($loaded_Files as $File) {
            if (is_null($File)) {
                // The File object couldn't be created because the db entry is invalid
                $count_files_invalid++;
                continue;
            }
            if ($File->exists()) {
                // File exists on the disk
                $count_files_valid++;
            } else {
                // File doesn't exist on the disk, Remove it from DB
                $File->dbdelete();
                $count_files_deleted++;
            }
        }
        echo ' .';
        evo_flush();
        // Clear cache after each page to save memory
        $FileCache->clear();
        $current_page++;
        $files_SQL->LIMIT($current_page * $page_size . ', ' . $page_size);
    }
    echo 'OK<p>';
    echo sprintf(T_('Number of deleted orphan File objects: %d.'), $count_files_deleted) . '<br />';
    echo sprintf(T_('Number of valid File objects in the database: %d.'), $count_files_valid) . '</p>';
    if ($count_files_invalid) {
        // There are invalid files in the database
        // Display warning to show that the 'Remove orphan file roots' tool should be also called
        $remove_orphan_file_roots = 'href="' . $admin_url . 'ctrl=tools&amp;action=delete_orphan_file_roots&amp;' . url_crumb('tools') . '"';
        $invalid_files_note = $count_files_invalid == 1 ? T_('An invalid File object was found in the database.') : sprintf(T_('%d invalid File objects were found in the database.'), $count_files_invalid);
        echo '<p class="warning">' . $invalid_files_note . "<br/>" . sprintf(T_('It is strongly recommended to also execute the &lt;<a %s>Remove orphan file roots</a>&gt; tool to remove invalid files from the database and from the disk as well!'), $remove_orphan_file_roots) . '</p>';
    }
}
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:56,代码来源:_dbmaintenance.funcs.php

示例11: recreate_autogenerated_excerpts

/**
 * Recreate posts autogenerated excerpts
 * Only those posts excerpt will be recreated which are visible in the front office
 *
 * Note: This process can be very very slow if there are many items in the database
 *
 * @param string the url to call if the process needs to be paused becuase of the max execution time
 * @param boolean set true to start from the beginning, false otherwise
 * @param boolean set to true to display recreated/all information or leave it on false to display only dots
 */
function recreate_autogenerated_excerpts($continue_url, $remove_all = true, $detailed_progress_log = false)
{
    global $DB, $localtimenow;
    $start_time = time();
    $max_exec_time = ini_get('max_execution_time');
    $load_limit = 50;
    $progress_log_id = 'progress_log';
    // The timestamp when the process was started
    $process_start_ts = param('start_ts', 'string', $localtimenow);
    // Update only those posts which may be visible in the front office
    $where_condition = '( post_excerpt_autogenerated = 1 OR post_excerpt_autogenerated IS NULL ) AND post_status IN ( \'' . implode('\',\' ', get_inskin_statuses(NULL, 'post')) . '\' )';
    // Update only those posts which were already created when the recreate process was started
    $where_condition .= ' AND post_datecreated < ' . $DB->quote(date2mysql($process_start_ts));
    if ($remove_all) {
        // We are in the beginning of the process and first we set all autogenerated excerpts values to NULL
        if ($detailed_progress_log) {
            // Display detailed progess information
            echo '<span id="' . $progress_log_id . '">' . T_('Clearing autogenerated excerpt values') . '</span>';
            evo_flush();
        }
        // Set all autogenerated excerpt values to NULL
        $query = 'UPDATE T_items__item SET post_excerpt = NULL WHERE ' . $where_condition;
        $DB->query($query, 'Remove all autogenerated excerpts');
        // Count all autogenerated excerpt which value is NULL ( Note: Maybe some of them was already NULL before we have started this process )
        $all_excerpt = $DB->get_var('SELECT count(*) FROM T_items__item WHERE post_excerpt IS NULL AND ' . $where_condition);
        $recreated_excerpts = 0;
    } else {
        // Init params with a previously started process status
        echo '<span id="progress_log"></span>';
        $all_excerpt = param('all_excerpt', 'integer', 0);
        $recreated_excerpts = param('recreated_excerpts', 'integer', 0);
    }
    // Display the current state of the process or a '.' character to indicate the ongoing process
    if ($detailed_progress_log) {
        echo_progress_log_update($progress_log_id, $recreated_excerpts, $all_excerpt);
    } else {
        echo ' .';
    }
    evo_flush();
    $load_SQL = new SQL();
    $load_SQL->SELECT('*');
    $load_SQL->FROM('T_items__item');
    $load_SQL->WHERE($where_condition . ' AND post_excerpt IS NULL');
    $load_SQL->LIMIT($load_limit);
    $ItemCache =& get_ItemCache();
    while (count($ItemCache->load_by_sql($load_SQL)) > 0) {
        // New portion of items was loaded
        $processed_items = 0;
        while (($iterator_Item =& $ItemCache->get_next()) != NULL) {
            // Create new autogenerated excerpt and save it in the database
            $excerpt = $iterator_Item->get_autogenerated_excerpt();
            // Update excerpt without Item->dbupdate() call to make it faster
            $DB->query('UPDATE T_items__item SET post_excerpt = ' . $DB->quote($excerpt) . ' WHERE post_ID = ' . $DB->quote($iterator_Item->ID));
            $processed_items++;
            if ($detailed_progress_log && $processed_items % 3 == 0) {
                // Update progress info after every 3 recreated excerpt when detailed progress log was requested
                echo_progress_log_update($progress_log_id, $recreated_excerpts + $processed_items, $all_excerpt);
                evo_flush();
            }
        }
        // Increase the number recreated excerpts
        $recreated_excerpts += $processed_items;
        // Clear already process items from the cache
        $ItemCache->clear();
        // Display progress log
        if ($detailed_progress_log) {
            echo_progress_log_update($progress_log_id, $recreated_excerpts, $all_excerpt);
        } else {
            echo ' .';
        }
        evo_flush();
        if ($max_exec_time != 0 && $recreated_excerpts < $all_excerpt) {
            // a max execution time limit is set and there are more excerpts to create
            $elapsed_time = time() - $start_time;
            if ($elapsed_time > $max_exec_time - 10) {
                // Increase the time limit in case if less than 10 seconds remained
                $max_exec_time = $max_exec_time + 100;
                if (!set_max_execution_time($max_exec_time)) {
                    $continue_url = url_add_param($continue_url, 'all_excerpt=' . $all_excerpt . '&amp;recreated_excerpts=' . $recreated_excerpts . '&amp;start_ts=' . $process_start_ts, '&amp;');
                    echo '<br />' . 'We are reaching the time limit for this script. Please click <a href="' . $continue_url . '">continue</a>...';
                    evo_flush();
                    exit(0);
                }
            }
        }
    }
    // Check if the recreated exceprts number match with the total number of autogenerated excerpts
    if ($detailed_progress_log && $recreated_excerpts < $all_excerpt) {
        // This means that we are in the end of the process but some post excerpt was updated outside of this process
        // Here we increase the recreated excerpts value because all excerpts were recreated, however some of them not during this process
//.........这里部分代码省略.........
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:101,代码来源:_item.funcs.php

示例12: array

 /**
  * Get list of attached Links
  *
  * @param integer Limit max result
  * @param string Restrict to files/images linked to a specific position.
  *               Position can be 'teaser'|'aftermore'|'inline'
  *               Use comma as separator
  * @param string File type: 'image', 'audio', 'other'; NULL - to select all
  * @param array Params
  * @return DataObjectList2 on success or NULL if no linked files found
  */
 function get_attachment_LinkList($limit = 1000, $position = NULL, $file_type = NULL, $params = array())
 {
     if (!isset($GLOBALS['files_Module'])) {
         return NULL;
     }
     $params = array_merge(array('sql_select_add' => '', 'sql_order_by' => 'link_order'), $params);
     global $DB;
     load_class('_core/model/dataobjects/_dataobjectlist2.class.php', 'DataObjectList2');
     $LinkCache =& get_LinkCache();
     $LinkList = new DataObjectList2($LinkCache);
     // IN FUNC
     $SQL = new SQL();
     $SQL->SELECT('l.*');
     $SQL->SELECT_add($params['sql_select_add']);
     $SQL->FROM('T_links AS l');
     $SQL->WHERE($this->get_where_condition());
     if (!empty($position)) {
         $position = explode(',', $position);
         $SQL->WHERE_and('link_position IN ( ' . $DB->quote($position) . ' )');
     }
     $SQL->ORDER_BY($params['sql_order_by']);
     $SQL->LIMIT($limit);
     if (!is_null($file_type)) {
         // Restrict the Links by File type
         $SQL->FROM_add('INNER JOIN T_files ON link_file_ID = file_ID');
         $SQL->WHERE_and('file_type = ' . $DB->quote($file_type) . ' OR file_type IS NULL');
     }
     $LinkList->sql = $SQL->get();
     $LinkList->query(false, false, false, 'get_attachment_LinkList');
     if ($LinkList->result_num_rows == 0) {
         // Nothing found
         $LinkList = NULL;
     }
     return $LinkList;
 }
开发者ID:Ariflaw,项目名称:b2evolution,代码行数:46,代码来源:_linkowner.class.php

示例13: display

 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     $this->init_display($params);
     $UserCache =& get_UserCache();
     $UserList = new DataObjectList2($UserCache);
     switch ($this->disp_params['order_by']) {
         case 'regdate':
             $sql_order = 'user_created_datetime DESC';
             break;
         case 'moddate':
             $sql_order = 'user_profileupdate_date DESC';
             break;
         case 'random':
         default:
             $sql_order = 'RAND()';
             break;
     }
     // Query list of files:
     $SQL = new SQL();
     $SQL->SELECT('*');
     $SQL->FROM('T_users');
     $SQL->WHERE('user_avatar_file_ID IS NOT NULL');
     $SQL->ORDER_BY($sql_order);
     $SQL->LIMIT($this->disp_params['limit']);
     $UserList->sql = $SQL->get();
     $UserList->query(false, false, false, 'User avatars widget');
     $layout = $this->disp_params['thumb_layout'];
     $nb_cols = $this->disp_params['grid_nb_cols'];
     $count = 0;
     $r = '';
     /**
      * @var User
      */
     while ($User =& $UserList->get_next()) {
         if ($layout == 'grid') {
             if ($count % $nb_cols == 0) {
                 $r .= $this->disp_params['grid_colstart'];
             }
             $r .= $this->disp_params['grid_cellstart'];
         } else {
             $r .= $this->disp_params['item_start'];
         }
         $identity_url = get_user_identity_url($User->ID);
         $avatar_tag = $User->get_avatar_imgtag($this->disp_params['thumb_size']);
         if ($this->disp_params['bubbletip'] == '1') {
             // Bubbletip is enabled
             $bubbletip_param = ' rel="bubbletip_user_' . $User->ID . '"';
             $avatar_tag = str_replace('<img ', '<img ' . $bubbletip_param . ' ', $avatar_tag);
         }
         if (!empty($identity_url)) {
             $r .= '<a href="' . $identity_url . '">' . $avatar_tag . '</a>';
         } else {
             $r .= $avatar_tag;
         }
         ++$count;
         if ($layout == 'grid') {
             $r .= $this->disp_params['grid_cellend'];
             if ($count % $nb_cols == 0) {
                 $r .= $this->disp_params['grid_colend'];
             }
         } else {
             $r .= $this->disp_params['item_end'];
         }
     }
     // Exit if no files found
     if (empty($r)) {
         return;
     }
     echo $this->disp_params['block_start'];
     // Display title if requested
     $this->disp_title();
     if ($layout == 'grid') {
         echo $this->disp_params['grid_start'];
     } else {
         echo $this->disp_params['list_start'];
     }
     echo $r;
     if ($layout == 'grid') {
         if ($count && $count % $nb_cols != 0) {
             echo $this->disp_params['grid_colend'];
         }
         echo $this->disp_params['grid_end'];
     } else {
         echo $this->disp_params['list_end'];
     }
     echo $this->disp_params['block_end'];
     return true;
 }
开发者ID:ldanielz,项目名称:uesp.blog,代码行数:93,代码来源:_user_avatars.widget.php

示例14: SQL

 /**
  * Get list of attached files
  * 
  * INNER JOIN on files ensures we only get back file links
  * 
  * @param integer Limit max result
  * @param string Restrict to files/images linked to a specific position.
  *               Position can be 'teaser'|'aftermore'|'inline'
  *               Use comma as separator
  * @param string order by
  * @return DataObjectList2 on success or NULL if no linked files found
  */
 function get_attachment_FileList($limit = 1000, $position = NULL, $order = 'link_ID')
 {
     if (!isset($GLOBALS['files_Module'])) {
         return NULL;
     }
     load_class('_core/model/dataobjects/_dataobjectlist2.class.php', 'DataObjectList2');
     $FileCache =& get_FileCache();
     $FileList = new DataObjectList2($FileCache);
     // IN FUNC
     $SQL = new SQL();
     $SQL->SELECT('file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc, link_ID');
     $SQL->FROM('T_links INNER JOIN T_files ON link_file_ID = file_ID');
     $SQL->WHERE($this->get_where_condition());
     if (!empty($position)) {
         global $DB;
         $position = explode(',', $position);
         $SQL->WHERE_and('link_position IN ( ' . $DB->quote($position) . ' )');
     }
     //$SQL->ORDER_BY( $order );
     $SQL->ORDER_BY('link_order');
     $SQL->LIMIT($limit);
     $FileList->sql = $SQL->get();
     $FileList->query(false, false, false, 'get_attachment_FileList');
     if ($FileList->result_num_rows == 0) {
         // Nothing found
         $FileList = NULL;
     }
     return $FileList;
 }
开发者ID:ldanielz,项目名称:uesp.blog,代码行数:41,代码来源:_linkowner.class.php

示例15: dbm_delete_orphan_files

/**
 * Find and delete orphan File objects with no matching file on disk
 */
function dbm_delete_orphan_files()
{
    global $DB;
    $FileCache =& get_FileCache();
    echo T_('Deleting of the orphan File objects from the database...');
    evo_flush();
    $files_SQL = new SQL();
    $files_SQL->SELECT('file_ID');
    $files_SQL->FROM('T_files');
    $files_SQL->ORDER_BY('file_ID');
    $count_files_valid = 0;
    $count_files_deleted = 0;
    $page_size = 100;
    $current_page = 0;
    while (1) {
        // Search the files by page to save memory
        $files_SQL->LIMIT($current_page * $page_size . ', ' . $page_size);
        $files = $DB->get_col($files_SQL->get());
        if (empty($files)) {
            // All files were verified, Stop here
            break;
        }
        foreach ($files as $file_ID) {
            $File = $FileCache->get_by_ID($file_ID, false, false);
            if ($File->exists()) {
                // File exists on the disk
                $count_files_valid++;
            } else {
                // File doesn't exist on the disk, Remove it from DB
                $File->dbdelete();
                $count_files_deleted++;
            }
        }
        echo ' .';
        evo_flush();
        // Clear cache after each page to save memory
        $FileCache->clear();
        $current_page++;
    }
    echo 'OK<br /><br />';
    echo sprintf(T_('%d File objects have been deleted.'), $count_files_deleted) . '<br />';
    echo sprintf(T_('%d File objects are valid entries.'), $count_files_valid);
}
开发者ID:ldanielz,项目名称:uesp.blog,代码行数:46,代码来源:_dbmaintenance.funcs.php


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