Add tag

Add tags to images

@api

@param string $name The tag value to be added to the image.
@param string $image 6-digit image ID.
@param string $sid Session ID that is provided when logged in. This is also set as a cookie.
344885
public function add($name, $image, $sid = NULL) {
  $setting = new Setting;
  if ($setting->get('tags_need_auth')) {
    $user = new User;
    if ( !$user->isLoggedIn($sid) ) throw new \Exception('Must be logged in to add a tag', 1032);
  }
  if (strlen($name) < 1 OR $name == NULL) throw new \Exception('Tag name cannot be empty');
  if (strlen($image) !== 6) throw new \JohnVanOrange\Core\Exception\Invalid('Invalid image UID');
  $tag = htmlspecialchars(trim(stripslashes($name)));
  $slug = $this->text2slug($tag);
  if ($slug == '') throw new \Exception('Invalid tag name', 1030);
  $blacklist = new Blacklist;
  if ($blacklist->check($slug)) throw new \Exception('Tag has been banned', 1031);
  $query = new \Peyote\Select('tag_list');
  $query->columns('id')
        ->where('basename', '=', $slug);
  $result = $this->db->fetch($query);
  $tag_id = NULL;
  if (isset($result[0]['id'])) $tag_id = $result[0]['id'];
  if(!isset($tag_id)) {
   $tag_id = $this->addtoList($tag);
  }
  //check for dupe
  $query = new \Peyote\Select('resources');
  $query->where('image', '=', $image)
        ->where('value', '=', $tag_id)
        ->where('type', '=', 'tag');
  $result = $this->db->fetch($query);
  if ($result) throw new \Exception('Tag already exists');

  $res = new \JohnVanOrange\Core\Resource('tag', $sid);
  $res->setImage($image)->setValue($tag_id)->setPublic();
  $res->add();

  return [
   'message' => 'Tag added',
   'tags' => $this->get($image)
  ];
 }
1211100
protected function addCookieIntOption($name, $value)
    {
        $value = trim($value);
        if ($value !== null && $value !== '' && is_numeric($value)) {
            $this->addOption('cookie', $name, (int)$value);
        }
    }
1174354
public function tag(string $name, string $repo, string $tag = 'latest')
    {
        $data = [
            'repo' => $repo,
            'tag' => $tag,
        ];

        $url = self::$base_url.'/'.$name.'/tag?'.http_build_query($data);

        return self::$curl->post($url);
    }
54163
public function hasTag($name)
    {
        foreach ($this->tags as $tag) {
            if (strtolower($tag->getName()) == $name) {
                return true;
            }
        }
        return false;
    }
929134
public function imageToText($image, string $session_id)
    {
        $image = self::encode($image);

        return Request::exec(self::IMAGE_TO_TEXT, compact('image', 'session_id'));
    }
152140
public function addButton(string $name): void
    {
        $options = $this->formOptions['fields'][$name];

        $button = HtmlTag::createElement('button')
            ->set('id', $name)
            ->set('type', $options['type'] ?? 'button')
            ->text($options['text'] ?? '');

        if (isset($options['text'])) {
            unset($options['text']);
        }

        foreach ($options as $attr => $value) {
            $button->set($attr, $value);
        }

        echo $button;
    }
943247
protected function _add_data_srcset_to_content_image( $image, $image_id ) {
		return preg_replace_callback(
			'@(<img decoding="async"[^>]*?)srcset="([^"]+?)"([^>]*?>)@m',
			function( $matches ) use ( $image_id ) {
				return sprintf(
					'%s srcset="" data-srcset="%s" %s',
					$matches[1],
					$matches[2],
					$matches[3]
				);
			},
			$image
		);
	}
1110124
public function tag( $version ) {

		$this->versionSet( $version );

		$this->taskGitStack()
		     ->stopOnFail()
		     ->add( 'laps.php' )
		     ->commit( "Updated header version to {$version}" )
		     ->tag( $version )
		     ->run();
	}
1110452
public function add(string $name, string $value): void
	{
		$this->cookies[$name] = $value;
	}
1129513
public static function add(Tag &$Tag)
    {
        if (Config::get('store') == 'global') {
            self::$_tagStore[$Tag->ID] = &$Tag;
        } elseif (Config::get('store') == 'internal') {
            Config::getHTMLInstance()->tagStore[$Tag->ID] = &$Tag;
        }
    }
927165
public function addFilter($name, $query = array(), $tag = 'root_type')
	{
		if (is_array($query))
		{
			$string = $this->makeQueryString($query);
		}
		elseif (is_string($query))
		{
			$string = $query;
			if ($name == 'BoundingBox')
			{
				$this->query->setOptions(array('geo'=> true));
			}
		}
		$filterParams = array();
		$filterParams['key'] = $name;
		$filterParams['query'] = $string;
		if ($tag)
		{
			$filterParams['tag'] = $tag;
		}

		$this->query->createFilterQuery($filterParams);
		return $this;
	}
201916
public function registerSession($name, Session $session)
    {
        $name = strtolower($name);

        $this->sessions[$name] = $session;
    }
146925
public function addImage(Image $image)
    {
        // Find the image based on UUID inside the internal state.
        $existingImage = $this->images->findImageByUUID($image->getMediaObjectId());

        if ($existingImage === null) {
            $this->apply(
                $this->createImageAddedEvent($image)
            );
        }
    }
597409
public function updateTags($id, $name)
    {
        $url = "https://api.weixin.qq.com/cgi-bin/tags/update?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, ['tag' => ['name' => $name, 'id' => $id]]);
    }
1198160
private function createTag(string $body, string $name, TypeContext $context): ?Tag
    {
        $handlerClassName = $this->findHandlerClassName($name, $context);
        $arguments = $this->getArgumentsForParametersFromWiring(
            $this->fetchParametersForHandlerFactoryMethod($handlerClassName),
            $this->getServiceLocatorWithDynamicParameters($context, $name, $body)
        );

        return call_user_func_array([$handlerClassName, 'create'], $arguments);
    }
782571
def add_tag(self, name, value):
        

        self.tags.append(Tag(name, value))
283978
public function add( $name = null ) {
		$name = $name ? $name : $this->getName();
		$path = __DIR__;
		$name = ucfirst( $name );
		include  "{$path}/Views/{$name}.php";
	}