/** * This method navigates thru the tree structure and validates the article content. * * @param InstantArticle $article The article that will be checked. * @return array of string with the warnings raised during the check. */ public static function check($article) { Type::enforce($article, InstantArticle::getClassName()); $warnings = array(); self::getReport(array($article), $warnings); return $warnings; }
/** * Appends unescaped HTML to a element using the right strategy. * * @param \DOMNode $element - The element to append the HTML to. * @param \DOMNode $content - The unescaped HTML to append. */ protected function dangerouslyAppendUnescapedHTML($element, $content) { Type::enforce($content, 'DOMNode'); Type::enforce($element, 'DOMNode'); $imported = $element->ownerDocument->importNode($content, true); $element->appendChild($imported); }
/** * @param string $level * @param string $message */ public function __construct($level, $message) { Type::enforceWithin($level, [self::FATAL, self::ERROR, self::WARNING, self::INFO]); Type::enforce($message, Type::STRING); $this->level = $level; $this->message = $message; }
/** * Returns the set of pages and their associated tokens based on a * short-lived user access token. * * @param AccessToken $accessToken A short-lived user access token. * * @return array * * @throws FacebookSDKException */ public function getPagesAndTokens($accessToken) { Type::enforce($accessToken, 'Facebook\\Authentication\\AccessToken'); // If we don't have a long-lived user token, exchange for one if (!$accessToken->isLongLived()) { try { // The OAuth 2.0 client handler helps us manage access tokens $OAuth2Client = $this->facebook->getOAuth2Client(); $accessToken = $OAuth2Client->getLongLivedAccessToken($accessToken); } catch (FacebookResponseException $e) { throw new FacebookSDKException("Failed to exchange short-lived access token for long-lived access token."); } } // Set this access token as the default $this->facebook->setDefaultAccessToken($accessToken); // Request the list of pages and associated page tokens that are // connected to this user try { $response = $this->facebook->get('/me/accounts?fields=name,id,access_token,supports_instant_articles,picture'); } catch (FacebookResponseException $e) { throw new FacebookSDKException('Graph API returned an error: ' . $e->getMessage()); } // Return the array of page objects for this user return $response->getGraphEdge(); }
public function get($node) { Type::enforce($node, 'DOMNode'); $elements = self::findAll($node, $this->selector); if (!empty($elements) && $elements->item(0)) { $element = $elements->item(0); do { $element = $element->nextSibling; } while ($element !== null && !Type::is($element, 'DOMElement')); if ($element && Type::is($element, 'DOMElement')) { if ($this->siblingSelector) { $siblings = self::findAll($element, $this->siblingSelector); if (!empty($siblings) && $siblings->item(0)) { $siblingElement = $siblings->item(0); } else { // Returns null because sibling content doesn't match return null; } } else { $siblingElement = $element; } Transformer::markAsProcessed($siblingElement); return Transformer::cloneNode($siblingElement); } } return null; }
/** * Sets the geotag on the image. * * @see {link:http://geojson.org/} * * @param string $script * * @return $this */ public function withScript($script) { Type::enforce($script, Type::STRING); $this->script = $script; // TODO Validate the json informed return $this; }
/** * Adds a new item to the List * * @param string|ListItem $new_item The new item that will be pushed to the end of the list * * @return $this */ public function addItem($new_item) { Type::enforce($new_item, [ListItem::getClassName(), Type::STRING]); if (Type::is($new_item, Type::STRING)) { $new_item = ListItem::create()->appendText($new_item); } $this->items[] = $new_item; return $this; }
/** * Sets the attribution string * * @param string|Cite $attribution The attribution text * * @return $this */ public function withAttribution($attribution) { Type::enforce($attribution, [Type::STRING, Cite::getClassName()]); if (Type::is($attribution, Type::STRING)) { $this->attribution = Cite::create()->appendText($attribution); } else { $this->attribution = $attribution; } return $this; }
public function get($node) { Type::enforce($node, 'DOMNode'); $elements = self::findAll($node, $this->selector); if (!empty($elements) && $elements->item(0)) { if (!$this->attribute) { return true; } return $elements->item(0)->hasAttribute($this->attribute); } return false; }
public function get($node) { Type::enforce($node, 'DOMNode'); $elements = self::findAll($node, $this->selector); if (!empty($elements) && $elements->item(0)) { $element = $elements->item(0); if ($this->attribute) { return $element->getAttribute($this->attribute); } return $element->textContent; } return null; }
public function get($node) { Type::enforce($node, 'DOMNode'); $domXPath = new \DOMXPath($node->ownerDocument); $elements = $domXPath->query($this->selector, $node); if (!empty($elements) && $elements->item(0)) { $element = $elements->item(0); if ($this->attribute) { return $element->getAttribute($this->attribute); } return $element->textContent; } return null; }
public function get($node) { $content = null; Type::enforce($node, 'DOMNode'); $elements = self::findAll($node, $this->selector); if (!empty($elements) && $elements->item(0)) { $element = $elements->item(0); if ($this->attribute) { $content = $element->getAttribute($this->attribute); } else { $content = $element->textContent; } } if (!Type::isTextEmpty($content)) { return json_decode($content, true); } return null; }
public function pages() { if (get_option('instant_articles_app_user_access_token')) { $userAccessToken = new AccessToken(get_option('instant_articles_app_user_access_token')); Type::enforce($userAccessToken, 'Facebook\\Authentication\\AccessToken'); $helper = Helper::create(get_option('instant_articles_app_id'), get_option('instant_articles_app_secret')); try { $helper->getPagesAndTokens($userAccessToken)->all(); } catch (Facebook\Exceptions\FacebookResponseException $e) { print_r($e); die; } // Grab pages you are admin of and tokens $pages_data = $helper->getPagesAndTokens($userAccessToken)->all(); //print_r($pages_data);die; return $pages_data; } else { return false; } }
public function get($node) { Type::enforce($node, 'DOMNode'); $elements = self::findAll($node, $this->selector); if (!empty($elements) && $elements->item(0)) { $element = $elements->item(0); if ($this->attribute) { $result = $element->getAttribute($this->attribute); } else { $result = $element->textContent; } if (!Type::isTextEmpty($this->prefix)) { $result = $this->prefix . $result; } if (!Type::isTextEmpty($this->suffix)) { $result = $result . $this->suffix; } return $result; } return null; }
/** * @param Rule $rule */ public function addRule($rule) { Type::enforce($rule, Rule::getClassName()); // Use context class as a key $contexts = $rule->getContextClass(); // Handles multiple contexts if (!is_array($contexts)) { $contexts = [$contexts]; } foreach ($contexts as $context) { if (!isset($this->rules[$context])) { $this->rules[$context] = []; } $this->rules[$context][$this->ruleCount++] = $rule; } }
/** * Sets the attribution string * * @param string $attribution The attribution text * * @return $this */ public function withAttribution($attribution) { Type::enforce($attribution, Type::STRING); $this->attribution = $attribution; return $this; }
/** * Sets the article URL * * @param string $url The related article URL * * @return $this */ public function withURL($url) { Type::enforce($url, Type::STRING); $this->url = $url; return $this; }
/** * The caption credit. optional. * * @param string $credit the caption credit text that will be shown * * @return $this */ public function withCredit($credit) { Type::enforce($credit, [Type::STRING, Cite::getClassName()]); if (Type::is($credit, Type::STRING)) { $credit = Cite::create()->appendText($credit); } $this->credit = $credit; return $this; }
/** * Sets the unescaped text within the blockquote. * * @param string $text The unescaped string. * * @return $this */ public function withText($text) { Type::enforce($text, Type::STRING); $this->text = $text; return $this; }
/** * Get the submission status of an Instant Article. * * @param string|null $submissionStatusID the submission status ID * @return InstantArticleStatus */ public function getSubmissionStatus($submissionStatusID) { if (!$submissionStatusID) { return InstantArticleStatus::notFound(); } Type::enforce($submissionStatusID, Type::STRING); $response = $this->facebook->get($submissionStatusID . '?fields=status,errors'); $articleStatus = $response->getGraphNode(); $messages = []; $errors = $articleStatus->getField('errors'); if (null !== $errors) { foreach ($errors as $error) { $messages[] = ServerMessage::fromLevel($error['level'], $error['message']); } } return InstantArticleStatus::fromStatus($articleStatus->getField('status'), $messages); }
/** * Sets the sponsor for this Article. * * @param Sponsor $sponsor The sponsor of article to be set. * * @return $this */ public function withSponsor($sponsor) { Type::enforce($sponsor, Sponsor::getClassName()); $this->sponsor = $sponsor; return $this; }
/** * Overwrites the current date in the object * * @param \DateTime $date The date and time * * @return $this */ public function withDatetime($date) { Type::enforce($date, 'DateTime'); $this->date = $date; return $this; }
/** * @param string $value * * @return $this */ public function withValue($value) { Type::enforce($value, Type::STRING); $this->value = $value; return $this; }
/** * Adds new child elements to the front of this InstantArticle * * @param Element to be added to this Article. * * @return $this */ public function unshiftChild($child) { Type::enforce($child, [Ad::getClassName(), Analytics::getClassName(), AnimatedGIF::getClassName(), Audio::getClassName(), Blockquote::getClassName(), Image::getClassName(), H1::getClassName(), H2::getClassName(), Interactive::getClassName(), ListElement::getClassName(), Map::getClassName(), Paragraph::getClassName(), Pullquote::getClassName(), RelatedArticles::getClassName(), Slideshow::getClassName(), SocialEmbed::getClassName(), Video::getClassName()]); array_unshift($this->children, $child); return $this; }
/** * @param string $selector * * @return $this */ public function withSelector($selector) { Type::enforce($selector, Type::STRING); $this->selector = $selector; return $this; }
/** * @param ServerMessage $message */ public function addMessage($message) { Type::enforce($message, ServerMessage::getClassName()); $this->messages[] = $message; }
/** * Author role/contribution * * @param string $role_contribution The author short text to characterize role or contribution * * @return $this */ public function withRoleContribution($role_contribution) { Type::enforce($role_contribution, Type::STRING); $this->roleContribution = $role_contribution; return $this; }
/** * Sets the title of Related articles content block * * @param string $title the name of related articles block * * @return $this */ public function withTitle($title) { Type::enforce($title, Type::STRING); $this->title = $title; return $this; }
/** * @param string $fragment * * @return $this */ public function withFragment($fragment) { Type::enforce($fragment, Type::STRING); $this->fragment = $fragment; return $this; }
public function testIsNotStringException() { $this->setExpectedException('InvalidArgumentException'); Type::enforce(1, Type::STRING); }