Увеличить счетчик просмотров поста

@param int $post_id Номер поста
@return array
@throws IncorrectUsageException
494820
public function increaseCount($post_id)
    {
        $this->checkId($post_id);

        return $this->adapter->put(sprintf('/post/%d/viewcount', $post_id));
    }
20616
public static function ltiRawPostArray() {
        global $TSUGI_LAUNCH;
        if ( isset($TSUGI_LAUNCH) ) {
            return $TSUGI_LAUNCH->ltiRawPostArray();
        }
        if ( ! isset($_SESSION) ) return array();
        if ( ! isset($_SESSION['lti_post']) ) return array();
        return($_SESSION['lti_post']);
    }
189711
private function _get_post_types(){
    global $wpdb;

    $query = sprintf('SELECT * FROM %s ORDER BY id',MF_TABLE_POSTTYPES);
    $posttypes = $wpdb->get_results( $query, ARRAY_A );
    return $posttypes;
  }
298748
public function getValue ($post_ID)
    {
        if ($post_ID === self::SITE)
            return get_option($this->identifier, $this->default);
        else {
            $value = get_post_meta($post_ID, $this->identifier, true);
            return $value === '' ? $this->default : $value;
        }
    }
459553
function get_options( $options, $post_id )
	{
		// loaded by PHP already?
		if( !empty($options) )
		{
			return $options;	
		}
		
		
		// defaults
	 	$options = array(
	 		'position'			=>	'normal',
	 		'layout'			=>	'no_box',
	 		'hide_on_screen'	=>	array(),
	 	);
	 	
	 	
	 	// vars
	 	$position = get_post_meta($post_id, 'position', true);
	 	if( $position )
		{
			$options['position'] = $position;
		}
		
		$layout = get_post_meta($post_id, 'layout', true);
	 	if( $layout )
		{
			$options['layout'] = $layout;
		}
		
		$hide_on_screen = get_post_meta($post_id, 'hide_on_screen', true);
	 	if( $hide_on_screen )
		{
			$hide_on_screen = maybe_unserialize($hide_on_screen);
			$options['hide_on_screen'] = $hide_on_screen;
		}
		
	 	
	 	// return
	 	return $options;
	}
1333662
public function save_meta( $post_id, $post ) {

		$this->post = $post;
		$data       = $this->get_data();

		if ( ! $this->is_active() || empty( $data ) ) {
			return;
		}

		// save compiled data
		update_post_meta( $post_id, $this->slug, $data );
		$data = call_user_func_array( 'array_merge', $data );

		foreach ( $data as $meta_key => $meta_value ) {

			$this->save_meta_data( $meta_key, $meta_value );
		}

	}
686201
public function save_post($post_id, \WP_Post $post ){
        // Skip auto save
        if( wp_is_post_revision($post) || wp_is_post_autosave($post) ){
            return;
        }
        // Check Nonce
        if( !$this->verify_nonce() ){
            return;
        }
        // O.K., let's save
        foreach( $this->loop_fields() as $field ){
            try{
                if( is_wp_error($field) ){
                    /** @var \WP_Error $field */
                    throw new \Exception($field->get_error_message(), $field->get_error_code());
                }
                if( !$this->is_override_field($field->name) ){
                    /** @var \WPametu\UI\Field\Base $field */
                    $field->update($this->input->post($field->name), $post);
                }
            }catch ( \Exception $e ){
                $this->prg->addErrorMessage($e->getMessage());
            }

        }
    }
1345325
function get_fields( $fields, $post_id )
	{
		// global
		global $wpdb;
		
		
		// loaded by PHP already?
		if( !empty($fields) )
		{
			return $fields;	
		}

		
		// get field from postmeta
		$rows = $wpdb->get_results( $wpdb->prepare("SELECT meta_key FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $post_id, 'field_%'), ARRAY_A);
		
		
		if( $rows )
		{
			foreach( $rows as $row )
			{
				$field = apply_filters('acf/load_field', false, $row['meta_key'], $post_id );
	
			 	$fields[ $field['order_no'] ] = $field;
			}
		 	
		 	// sort
		 	ksort( $fields );
	 	}
	 	
	 	
	 	
	 	// return
		return $fields;
		
	}
1023273
public function getShortcodeModules($post_id) : array
    {
        $post = get_post($post_id);
        $pattern = get_shortcode_regex();
        $modules = array();

        if (is_object($post) && preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches)
            && array_key_exists(2, $matches)
            && in_array('modularity', $matches[2])) {

            $shortcodes = preg_replace('/[^0-9]/', '', $matches[3]);
            foreach ($shortcodes as $key => $shortcode) {
                $modules[] = array(
                    'ID' => $shortcode,
                    'post_type' => get_post_type($shortcode)
                );
            }
        }

        return $modules;
    }
338390
public function redirectToPost($post_id)
    {
        $post_id = Container::get('hooks')->fire('model.topic.redirect_to_post', $post_id);

        $result['select'] = ['topic_id', 'posted'];

        $result = DB::forTable('posts')
                      ->select_many($result['select'])
                      ->where('id', $post_id);
        $result = Container::get('hooks')->fireDB('model.topic.redirect_to_post_query', $result);
        $result = $result->find_one();

        if (!$result) {
            throw new  RunBBException(__('Bad request'), 404);
        }

        $post['topic_id'] = $result['topic_id'];
        $posted = $result['posted'];

        // Determine on which page the post is located (depending on $forum_user['disp_posts'])
        $num_posts = DB::forTable('posts')
                        ->where('topic_id', $post['topic_id'])
                        ->where_lt('posted', $posted)
                        ->count('id');

        $num_posts = Container::get('hooks')->fire('model.topic.redirect_to_post_num', $num_posts);

        $post['get_p'] = ceil(($num_posts + 1) / User::get()->disp_posts);

        $post = Container::get('hooks')->fire('model.topic.redirect_to_post', $post);

        return $post;
    }
952827
public function collect($post_id, string $key = ''): array
    {
        $post_id = (int) ($post_id ?? get_the_ID());

        if (!$post_id) { // Empty key is OK here.
            return []; // Not possible; empty array.
        }
        $value        = get_post_meta($post_id, $this->key($key), false);
        return $value = !is_array($value) ? [] : $value;
    }
17083
public function checkIfManuallyPicked($id)
    {
        global $wpdb;

        $result = $wpdb->get_results("
            SELECT *
            FROM $wpdb->postmeta
            WHERE meta_key = 'posts_data_posts'
                  AND meta_value LIKE '%\"{$id}\"%'
        ", OBJECT);

        if (count($result) === 0) {
            return false;
        }

        $posts = array();
        foreach ($result as $item) {
            $posts[] = $item->post_id;
        }

        return $posts;
    }
992861
protected function prepare_data(array $postids) {
        global $DB;

        if (empty($postids)) {
            return;
        }

        list($in, $params) = $DB->get_in_or_equal(array_values($postids));
        $sql = "SELECT p.*, f.id AS forum, f.course
                  FROM {forum_posts} p
            INNER JOIN {forum_discussions} d ON d.id = p.discussion
            INNER JOIN {forum} f ON f.id = d.forum
                 WHERE p.id {$in}";

        $posts = $DB->get_recordset_sql($sql, $params);
        $discussionids = [];
        $forumids = [];
        $courseids = [];
        $userids = [];
        foreach ($posts as $post) {
            $discussionids[] = $post->discussion;
            $forumids[] = $post->forum;
            $courseids[] = $post->course;
            $userids[] = $post->userid;
            unset($post->forum);
            if (!isset($this->posts[$post->discussion])) {
                $this->posts[$post->discussion] = [];
            }
            $this->posts[$post->discussion][$post->id] = $post;
        }
        $posts->close();

        if (empty($discussionids)) {
            // All posts have been removed since the task was queued.
            return;
        }

        // Fetch all discussions.
        list($in, $params) = $DB->get_in_or_equal(array_values($discussionids));
        $this->discussions = $DB->get_records_select('forum_discussions', "id {$in}", $params);
        foreach ($this->discussions as $discussion) {
            if (empty($this->forumdiscussions[$discussion->forum])) {
                $this->forumdiscussions[$discussion->forum] = [];
            }
            $this->forumdiscussions[$discussion->forum][] = $discussion->id;
        }

        // Fetch all forums.
        list($in, $params) = $DB->get_in_or_equal(array_values($forumids));
        $this->forums = $DB->get_records_select('forum', "id {$in}", $params);
        foreach ($this->forums as $forum) {
            if (empty($this->courseforums[$forum->course])) {
                $this->courseforums[$forum->course] = [];
            }
            $this->courseforums[$forum->course][] = $forum->id;
        }

        // Fetch all courses.
        list($in, $params) = $DB->get_in_or_equal(array_values($courseids));
        $this->courses = $DB->get_records_select('course', "id $in", $params);

        // Fetch all authors.
        list($in, $params) = $DB->get_in_or_equal(array_values($userids));
        $users = $DB->get_recordset_select('user', "id $in", $params);
        foreach ($users as $user) {
            $this->minimise_user_record($user);
            $this->users[$user->id] = $user;
        }
        $users->close();

        // Fill subscription caches for each forum.
        // These are per-user.
        foreach (array_values($forumids) as $id) {
            \mod_forum\subscriptions::fill_subscription_cache($id);
            \mod_forum\subscriptions::fill_discussion_subscription_cache($id);
        }
    }
647223
public function save_post( $post_id, $post, $update = null ) {

		if ( empty( $post ) ) {
			return;
		}

		$is_new_item = false;

		if ( is_bool( $update ) ) {
			$is_new_item = ! $update;
		} // false is new item
		elseif ( isset( self::$old_post_status[ $post->post_type ] ) && in_array( self::$old_post_status[ $post->post_type ], array(
				'new',
				'auto-draft'
			), true ) ) {
			$is_new_item = true;
		}

		$nonced = wp_verify_nonce( pods_v( 'pods_meta', 'post' ), 'pods_meta_post' );

		if ( ! $is_new_item && false === $nonced ) {
			return;
		}

		// Unset to avoid manual new post issues
		if ( isset( self::$old_post_status[ $post->post_type ] ) ) {
			unset( self::$old_post_status[ $post->post_type ] );
		}

		$blacklisted_types = array(
			'revision',
			'_pods_pod',
			'_pods_field'
		);

		$blacklisted_types = apply_filters( 'pods_meta_save_post_blacklist_types', $blacklisted_types, $post_id, $post );

		// @todo Figure out how to hook into autosave for saving meta

		// Block Autosave and Revisions
		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || in_array( $post->post_type, $blacklisted_types ) ) {
			return;
		}

		// Block Quick Edits / Bulk Edits
		if ( 'edit.php' === pods_v( 'pagenow', 'global' ) && ( 'inline-save' === pods_v( 'action', 'post' ) || null !== pods_v( 'bulk_edit' ) || is_array( pods_v( 'post' ) ) ) ) {
			return;
		}

		// Block Trash
		if ( in_array( pods_v( 'action' ), array( 'untrash', 'trash' ), true ) ) {
			return;
		}

		// Block Auto-drafting and Trash (not via Admin action)
		$blacklisted_status = array(
			'auto-draft',
			'trash',
		);

		$blacklisted_status = apply_filters( 'pods_meta_save_post_blacklist_status', $blacklisted_status, $post_id, $post );

		if ( in_array( $post->post_status, $blacklisted_status ) ) {
			return;
		}

		$groups = $this->groups_get( 'post_type', $post->post_type );

		$id = $post_id;

		if ( ! is_object( self::$current_pod ) || self::$current_pod->pod !== $post->post_type ) {
			self::$current_pod = pods( $post->post_type, $id, true );
		} elseif ( is_object( self::$current_pod ) && (int) self::$current_pod->id() !== (int) $id ) {
			self::$current_pod->fetch( $id );
		}

		$pod  = self::$current_pod;
		$data = array();

		if ( $pod ) {
			$rest_enable = (boolean) pods_v( 'rest_enable', $pod->pod_data['options'], false );

			// Block REST API saves, we handle those separately in PodsRESTHandlers
			if ( defined( 'REST_REQUEST' ) && REST_REQUEST && $rest_enable ) {
				return;
			}
		}
		// The following code will run for all post_types (not just Pods)

		if ( false !== $nonced && ! empty( $groups ) ) {
			foreach ( $groups as $group ) {
				if ( empty( $group['fields'] ) ) {
					continue;
				}

				foreach ( $group['fields'] as $field ) {
					if ( false === PodsForm::permission( $field['type'], $field['name'], $field, $group['fields'], $pod, $id ) ) {
						if ( ! pods_v( 'hidden', $field['options'], false ) ) {
							continue;
						}
					}

					$data[ $field['name'] ] = '';

					if ( isset( $_POST[ 'pods_meta_' . $field['name'] ] ) ) {
						$data[ $field['name'] ] = $_POST[ 'pods_meta_' . $field['name'] ];
					}
				}
			}

			if ( $is_new_item ) {
				do_action( 'pods_meta_create_pre_post', $data, $pod, $id, $groups, $post, $post->post_type );
				do_action( "pods_meta_create_pre_post_{$post->post_type}", $data, $pod, $id, $groups, $post );
			}

			do_action( 'pods_meta_save_pre_post', $data, $pod, $id, $groups, $post, $post->post_type, $is_new_item );
			do_action( "pods_meta_save_pre_post_{$post->post_type}", $data, $pod, $id, $groups, $post, $is_new_item );
		}

		if ( $is_new_item || false !== $nonced ) {
			pods_no_conflict_on( 'post' );

			if ( ! empty( $pod ) ) {
				// Fix for Pods doing it's own sanitizing
				$data = pods_unslash( (array) $data );

				$pod->save( $data, null, null, array( 'is_new_item' => $is_new_item, 'podsmeta' => true ) );
			} elseif ( ! empty( $id ) ) {
				foreach ( $data as $field => $value ) {
					update_post_meta( $id, $field, $value );
				}
			}

			pods_no_conflict_off( 'post' );
		}

		if ( false !== $nonced && ! empty( $groups ) ) {
			if ( $is_new_item ) {
				do_action( 'pods_meta_create_post', $data, $pod, $id, $groups, $post, $post->post_type );
				do_action( "pods_meta_create_post_{$post->post_type}", $data, $pod, $id, $groups, $post );
			}

			do_action( 'pods_meta_save_post', $data, $pod, $id, $groups, $post, $post->post_type, $is_new_item );
			do_action( "pods_meta_save_post_{$post->post_type}", $data, $pod, $id, $groups, $post, $is_new_item );
		}

	}
123903
public static function getFields($post_type)
    {
        $postType = PostType::all()->where('slug', $post_type)->first();

        if($postType) {
            return $postType->fields;
        }
        
        return [];
    }
759744
public function lookForBrokenLinks($postId = null, $url = null)
    {
        \BrokenLinkDetector\App::checkInstall();
        $foundUrls = array();

        if ($url) {
            $url = "REGEXP ('.*(href=\"{$url}\").*')";
        } else {
            $url = "RLIKE ('href=*')";
        }

        global $wpdb;
        $sql = "
            SELECT ID, post_content
            FROM $wpdb->posts
            WHERE
                post_content {$url}
                AND post_type NOT IN ('attachment', 'revision', 'acf', 'acf-field', 'acf-field-group')
                AND post_status IN ('publish', 'private', 'password')
        ";

        if (is_numeric($postId)) {
            $sql .= " AND ID = $postId";
        }

        $posts = $wpdb->get_results($sql);

        if(is_array($posts) && !empty($posts)) {
            foreach ($posts as $post) {
                preg_match_all('/<a[^>]+href=([\'"])(http|https)(.+?)\1[^>]*>/i', $post->post_content, $m);

                if (!isset($m[3]) || count($m[3]) > 0) {
                    foreach ($m[3] as $key => $url) {
                        $url = $m[2][$key] . $url;

                        // Replace whitespaces in url
                        if (preg_match('/\s/', $url)) {
                            $newUrl = preg_replace('/ /', '%20', $url);
                            $wpdb->query(
                                $wpdb->prepare(
                                    "UPDATE $wpdb->posts
                                        SET post_content = REPLACE(post_content, %s, %s)
                                        WHERE post_content LIKE %s
                                        AND ID = %d",
                                    $url,
                                    $newUrl,
                                    '%' . $wpdb->esc_like($url) . '%',
                                    $post->ID
                                )
                            );
                            $url = $newUrl;
                        }

                        if ($postId !== 'internal' && !$this->isBroken($url)) {
                            continue;
                        }

                        $foundUrls[] = array(
                            'post_id' => $post->ID,
                            'url' => $url
                        );
                    }
                }
            }
        }

        $this->saveBrokenLinks($foundUrls, $postId);
    }
1131280
public function getAssociations($post_id = null)
    {
        $oConfig       = Factory::service('Config');
        $oDb           = Factory::service('Database');
        $_associations = $oConfig->item('blog_post_associations');

        if (!$_associations) {
            return array();
        }

        // --------------------------------------------------------------------------

        foreach ($_associations as &$assoc) {

            /**
             * Fetch the association data from the source, fail ungracefully - the dev
             * should have this configured correctly.
             *
             * Fetch current associations if a post_id has been supplied
             */

            if ($post_id) {

                $oDb->where('post_id', $post_id);
                $assoc->current = $oDb->get($assoc->target)->result();

            } else {

                $assoc->current = array();
            }

            //  Fetch the raw data
            $oDb->select($assoc->source->id . ' id, ' . $assoc->source->label . ' label');
            $oDb->order_by('label');

            if (isset($assoc->source->where) && $assoc->source->where) {

                $oDb->where($assoc->source->where);
            }

            $assoc->data = $oDb->get($assoc->source->table)->result();
        }

        return $_associations;
    }