Insert Post tags.

@param array  $selectedTags The list of selected tags
@param int    $postID       ID of the Post
@param object $postType     The slug of post type

@return array  List of inserted media files
421124
public static function insertTags($selectedTags, $postID, $postType)
    {
        if(count($selectedTags)) {
            $tagsIDs = [];

            $newTagsRelations = [];
            foreach ($selectedTags as $langSlug => $selectedTagForLanguage){
                if($selectedTagForLanguage) {
                    foreach ($selectedTagForLanguage as $selectedTag){

                        //insert tag if it doesn't exist
                        if($selectedTag['tagID'] == 0) {
                            $tagSlug = str_slug($selectedTag['title'], '-');
                            $tagsID = DB::table('tags')->insertGetId(
                                [
                                'postTypeID' => $postType['postTypeID'],
                                'createdByUserID' => Auth::user()->userID,
                                'title' => $selectedTag['title'],
                                'description' => $selectedTag['description'],
                                'slug' => $tagSlug,
                                ]
                            );
                        }else{
                            $tagsID = $selectedTag['tagID'];
                        }

                        //add new tag relationship
                        $newTagsRelations[] = [
                          'tagID' => $tagsID,
                          'postID' => $postID,
                          'language' => $langSlug
                        ];
                        $tagsIDs[] = $tagsID;
                    }
                }
            }

            // if post is in the main database
            $insertedTags = (new TagRelation())->setTable($postType->slug.'_tags')->insert($newTagsRelations);
            if($insertedTags) {
                return $tagsIDs;
            }
        }
        return [];
    }
765687
public function insert($projectId, Manager_Template $postBody, $optParams = array())
  {
    $params = array('projectId' => $projectId, 'postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('insert', array($params), "Manager_Template");
  }
196702
public function insert(AdExchangeBuyer_OfferDto $postBody, $optParams = array())
  {
    $params = array('postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('insert', array($params), "AdExchangeBuyer_OfferDto");
  }
88910
public function insert(Google_Service_AdExchangeBuyer_OfferDto $postBody, $optParams = array())
  {
    $params = array('postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('insert', array($params), "Google_Service_AdExchangeBuyer_OfferDto");
  }
844986
public function insert($seriesId, Topic $postBody, $optParams = array()) {
      $params = array('seriesId' => $seriesId, 'postBody' => $postBody);
      $params = array_merge($params, $optParams);
      $data = $this->__call('insert', array($params));
      if ($this->useObjects()) {
        return new Topic($data);
      } else {
        return $data;
      }
    }
918172
public function addDocumentType($postValues)
    {
        $documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);

        $documentTypes = $this->repository->documentTypes;
        $documentTypes[] = $documentTypeObject;
        $this->repository->documentTypes = $documentTypes;

        $this->save();
    }
240026
final public function registerPostType(string $postType): void {
		
		// we make this a public method because we use it in our
		// initialization method below but frequently from the activation
		// action of the plugin itself so that we can flush permalinks
		// based on our new types.
		
		$args = $this->getPostTypeArgs($postType);
		$args["labels"] = $this->getPostTypeLabels($postType);
		$args["rewrite"] = $this->getPostTypeRewrite($postType);
		unset($args["label"], $args["register_meta_box_cb"]);
		
		register_post_type($postType, $args);
	}
1206274
public static function getPostModules($postId)
    {

        //Declarations
        $modules = array();
        $retModules = array();

        //Get current post id
        $postId = self::pageForPostTypeTranscribe($postId);

        // Get enabled modules
        $available = \Modularity\ModuleManager::$available;
        $enabled = \Modularity\ModuleManager::$enabled;

        // Get modules structure
        $moduleIds = array();
        $moduleSidebars = null;

        if (is_numeric($postId)) {
            $moduleSidebars = get_post_meta($postId, 'modularity-modules', true);
        } else {
            $moduleSidebars = get_option('modularity_' . $postId . '_modules');
        }

        //Create array of visible modules
        if (!empty($moduleSidebars)) {
            foreach ($moduleSidebars as $sidebar) {
                foreach ($sidebar as $module) {
                    if (!isset($module['postid'])) {
                        continue;
                    }

                    $moduleIds[] = $module['postid'];
                }
            }
        }

        //Get allowed post statuses
        $postStatuses = array('publish');
        if (is_user_logged_in()) {
            $postStatuses[] = 'private';
        }

        // Get module posts
        $modulesPosts = get_posts(array(
            'posts_per_page' => -1,
            'post_type' => $enabled,
            'include' => $moduleIds,
            'post_status' => $postStatuses
        ));

        // Add module id's as keys in the array
        if (!empty($modulesPosts)) {
            foreach ($modulesPosts as $module) {
                $modules[$module->ID] = $module;
            }
        }

        // Create an strucural correct array with module post data
        if (!empty($moduleSidebars)) {
            foreach ($moduleSidebars as $key => $sidebar) {
                $retModules[$key] = array(
                    'modules' => array(),

                    // Todo: This will duplicate for every sidebar, move it to top level of array(?)
                    // Alternatively only fetch options for the current sidebar (not all like now)
                    'options' => get_post_meta($postId, 'modularity-sidebar-options', true)
                );

                $arrayIndex = 0;

                foreach ($sidebar as $moduleUid => $module) {
                    if (!isset($module['postid'])) {
                        continue;
                    }
                    $moduleId = $module['postid'];

                    if (!isset($modules[$moduleId])) {
                        continue;
                    }

                    $moduleObject = self::getModule($moduleId, $module);
                    if (!$moduleObject) {
                        continue;
                    }

                    $retModules[$key]['modules'][$arrayIndex] = $moduleObject;

                    $arrayIndex++;
                }
            }
        }

        return $retModules;
    }
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 );
		}

	}
716017
public function addToBatchAndRun($batch, $postIDs) {
        if (!isset(static::$batchClasses[$batch])) {
            throw new \Exception("Batch '$batch' is not registered.");
        }

        $this->reset($batch);

        if (count($postIDs) == 0) {
            return;
        }

        $testResult = $this->testConnectivity();
        if ($testResult !== true) {
            $error = 'Unknown';

            if (is_wp_error($testResult)) {
                $error = $testResult->get_error_message();
            } else if (is_array($testResult)) {
                $error = 'HTTP response code was '.$testResult['response']['code'];
            }

            $storageSettingsURL = admin_url('admin.php?page=media-tools-s3#ilab-media-s3-batch-settings');
            $message = "There was an error attempting to run your batch.  Try changing the <strong>Connection Timeout</strong> in <a href='$storageSettingsURL'>Storage Settings</a> to a higher number like 0.1 or 1 to see if that helps.  The actual error was: $error";
            $this->setErrorMessage($batch, $message);

            throw new \Exception($message);
        }

        $firstPostFile = get_attached_file($postIDs[0]);
        $fileName = basename($firstPostFile);

        $this->setCurrent($batch, 1);
        $this->setTotalCount($batch, count($postIDs));
        $this->setCurrentFile($batch, $fileName);
        $this->setShouldCancel($batch, false);
        $this->setStatus($batch, true);

        /** @var BackgroundProcess $batchProcess */
        $batchProcess = new static::$batchClasses[$batch]();

        $index = 0;
        foreach($postIDs as $postID) {
            $batchProcess->push_to_queue(['index' => $index, 'post' => $postID]);
            $index++;
        }

        $batchProcess->save();
        $batchProcess->dispatch();

        $this->setLastRun($batch, time());
    }
74351
protected function addPostReferences(&$post, $data)
    {
        $typeMap = array(
            'user' => ReferenceType::USER,
            'page' => ReferenceType::PAGE,
            'group' => ReferenceType::GROUP,
            'application' => ReferenceType::APPLICATION,
        );

        if (!isset($data['message_tags'])) {
            return;
        }

        foreach ($data['message_tags'] as $messageTagGroup) {
            if (isset($messageTagGroup['offset'])) {
                $messageTag = $messageTagGroup;
                $reference = new Reference();
                $reference
                    ->setIndices(array($messageTag['offset'], $messageTag['offset'] + $messageTag['length']))
                    //->setType($typeMap[$messageTag['type']])
                    ->setData($messageTag);

                $post->addReference($reference);
            } else {
                foreach ($messageTagGroup as $messageTag) {
                    $reference = new Reference();
                    $reference
                        ->setIndices(array($messageTag['offset'], $messageTag['offset'] + $messageTag['length']))
                        ->setType($typeMap[$messageTag['type']])
                        ->setData($messageTag);

                    $post->addReference($reference);
                }
            }
        }
    }
752243
public function insert($tableId, Template $postBody, $optParams = array()) {
      $params = array('tableId' => $tableId, 'postBody' => $postBody);
      $params = array_merge($params, $optParams);
      $data = $this->__call('insert', array($params));
      if ($this->useObjects()) {
        return new Template($data);
      } else {
        return $data;
      }
    }
724352
public function createFromArray( $parentId, $parentType, $tags ) {

		foreach( $tags as $tagName ) {

			$tagName = trim( $tagName );

			if( empty( $tagName ) ) {

				continue;
			}

			$tag = $this->tagService->getFirstByNameType( $tagName, $parentType );

			if( !isset( $tag ) ) {

				$tag = $this->tagService->createByParams( [ 'siteId' => Yii::$app->core->siteId, 'name' => ucfirst( $tagName ), 'type' => $parentType ] );
			}

			$modelTag = $this->getFirstByParentModelId( $parentId, $parentType, $tag->id );

			// Create if does not exist
			if( empty( $modelTag ) ) {

				$this->createByParams( [ 'modelId' => $tag->id, 'parentId' => $parentId, 'parentType' => $parentType, 'order' => 0, 'active' => true ] );
			}
			// Activate if already exist
			else {

				$this->activate( $modelTag );
			}
		}
	}
743131
function postGetTags(id, cb) {
  var q  =
    'SELECT * FROM tags t ' +
      'JOIN posts_tags pt ON t.id = pt.tag_id AND pt.post_id = $1';

  db.getClient(function(err, client, done) {
    client.query(q, [id], function(err, r) {
      if(err) {
        cb(err);
        done(err);
      } else {
        cb(null, r.rows);
        done();
      }
    });
  });
}
1365395
public function getTags($postUuid)
    {
        $event = new GenericDataEvent([
            'class' => 'Icap\BlogBundle\Entity\Post',
            'ids' => [$postUuid],
        ]);

        $this->eventDispatcher->dispatch(
            'claroline_retrieve_used_tags_by_class_and_ids',
            $event
        );
        $tags = $event->getResponse();

        return $tags;
    }
200538
public function getPostsByTags($limit = 6, $tagIDs = [])
    {
        $tags = "tags";
        // Validate post type
        if(!$tagIDs) {
            $tagIDs = [];
            foreach ($this->$tags as $tag) {
                $tagIDs[] = $tag->tagID;
            }
        }

        if($tagIDs) {
            $postsObj = new Post();
            $postsObj->setTable($this->getTable());
            $posts = $postsObj
                ->select('postID', 'title', 'featuredImageID', 'slug')
                ->join($this->getTable().'_tags', $this->getTable().'_tags.postID', $this->getTable() . '.postID')
                ->with('featuredImage')
                ->published()
                ->whereIn('tagID', $tagIDs)
                ->where('postID', "!=", $this->postID)
                ->orderBy('published_at', 'DESC')
                ->limit($limit)
                ->get();

            return $posts;
        }else{
            return collect();
        }
    }
977414
function postSetTags(post_id, tags, cb) {
  var ids = _.pluck(tags, 'id')
    , q1 = 'DELETE FROM posts_tags WHERE post_id = $1'
    , q2 = 'INSERT INTO posts_tags (post_id, tag_id) VALUES ' +
    ids.map(function(id) {
      return '(' + post_id + ',' + id + ')';
    }).join(', ');

  db.getClient(function(err, client, done) {
    client.query(q1, [post_id], function(err, r) {
      if(err) { return cb(err); }
      client.query(q2, function(err, r) {
        if(err) {
          cb(err);
          done(err);
        } else {
          cb(null, r.rowCount);
          done();
        }
      });
    });
  });
}