本文整理汇总了PHP中FetchPageInfo函数的典型用法代码示例。如果您正苦于以下问题:PHP FetchPageInfo函数的具体用法?PHP FetchPageInfo怎么用?PHP FetchPageInfo使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FetchPageInfo函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchPageInfo
public function fetchPageInfo($Url, $ThrowError = false)
{
$PageInfo = FetchPageInfo($Url, 3, $ThrowError);
$Title = val('Title', $PageInfo, '');
if ($Title == '') {
if ($ThrowError) {
throw new Gdn_UserException(t("The page didn't contain any information."));
}
$Title = formatString(t('Undefined discussion subject.'), array('Url' => $Url));
} else {
if ($Strip = c('Vanilla.Embed.StripPrefix')) {
$Title = stringBeginsWith($Title, $Strip, true, true);
}
if ($Strip = c('Vanilla.Embed.StripSuffix')) {
$Title = StringEndsWith($Title, $Strip, true, true);
}
}
$Title = trim($Title);
$Description = val('Description', $PageInfo, '');
$Images = val('Images', $PageInfo, array());
$Body = formatString(t('EmbeddedDiscussionFormat'), array('Title' => $Title, 'Excerpt' => $Description, 'Image' => count($Images) > 0 ? img(val(0, $Images), array('class' => 'LeftAlign')) : '', 'Url' => $Url));
if ($Body == '') {
$Body = $Url;
}
if ($Body == '') {
$Body = formatString(t('EmbeddedNoBodyFormat.'), array('Url' => $Url));
}
$Result = array('Name' => $Title, 'Body' => $Body, 'Format' => 'Html');
return $Result;
}
示例2: FetchPageInfo
/**
* Return some meta information about any page on the internet in JSON format.
*/
public function FetchPageInfo($Url = '')
{
$PageInfo = FetchPageInfo($Url);
$this->SetData('PageInfo', $PageInfo);
$this->MasterView = 'default';
$this->RemoveCssFile('admin.css');
$this->AddCssFile('style.css');
$this->AddCssFile('vanillicon.css', 'static');
$this->SetData('_NoPanel', TRUE);
$this->Render();
}
示例3: Embed
/**
* Alternate version of Index that uses the embed master view.
*/
public function Embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
{
$this->CanEditComments = FALSE;
// Don't show the comment checkboxes on the embed comments page
$this->Theme = 'default';
// Force the default theme on embedded comments
// Add some css to help with the transparent bg on embedded comments
if ($this->Head) {
$this->Head->AddString('<style type="text/css">
body { background: transparent !important; }
ul.MessageList li.Item { background: #fff; }
ul.MessageList li.Item.Mine { background: #E3F4FF; }
</style>');
}
$Session = Gdn::Session();
$this->AddJsFile('jquery.ui.packed.js');
$this->AddJsFile('jquery.gardenmorepager.js');
$this->AddJsFile('jquery.autogrow.js');
$this->AddJsFile('options.js');
$this->AddJsFile('discussion.js');
$this->MasterView = 'empty';
// Define incoming variables (prefer querystring parameters over method parameters)
$DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
$DiscussionID = GetIncomingValue('vanilla_discussion_id', $DiscussionID);
$Offset = GetIncomingValue('Offset', $Offset);
$Limit = GetIncomingValue('Limit', $Limit);
$ForeignID = GetIncomingValue('vanilla_identifier', '');
$ForeignType = GetIncomingValue('vanilla_type', '');
$ForeignName = GetIncomingValue('vanilla_name', '');
$ForeignUrl = GetIncomingValue('vanilla_url', '');
$this->SetData('ForeignUrl', $ForeignUrl);
$this->AddDefinition('ForeignUrl', $ForeignUrl);
$ForeignBody = GetIncomingValue('vanilla_body', '');
$CategoryID = GetIncomingValue('vanilla_category_id', '');
// Retrieve the discussion record.
$Discussion = FALSE;
if ($DiscussionID > 0) {
$Discussion = $this->DiscussionModel->GetID($DiscussionID);
} else {
if ($ForeignID != '' && $ForeignType != '') {
$Discussion = $this->DiscussionModel->GetForeignID($ForeignID, $ForeignType);
}
}
// If no discussion record was found, but foreign id was provided, create it now
if (!$Discussion && $ForeignID != '' && $ForeignType != '') {
if ($ForeignName == '' || $ForeignBody == '') {
$PageInfo = FetchPageInfo($ForeignUrl);
if (!$PageInfo['Exception']) {
$ForeignName = $PageInfo['Title'];
$ForeignBody = Wrap(Anchor($ForeignName, $ForeignUrl), 'strong') . "\n" . '<br />' . Wrap(Anchor($ForeignUrl, $ForeignUrl), 'small') . "\n" . Wrap($PageInfo['Description'], 'p');
if (count($PageInfo['Images']) > 0) {
$ForeignBody = Anchor(Img($PageInfo['Images'][0], array('alt' => $ForeignName, 'class' => 'Thumbnail')), $ForeignUrl) . "\n" . $ForeignBody;
}
}
}
$Body = $ForeignBody;
if ($Body == '' && $ForeignUrl != '') {
$Body = $ForeignUrl;
}
if ($Body == '') {
$Body = T('This discussion is related to an undefined foriegn content source.');
}
// Validate the CategoryID for inserting
if (!is_numeric($CategoryID)) {
$CategoryID = C('Vanilla.Embed.DefaultCategoryID', 0);
if ($CategoryID <= 0) {
// No default category defined, so grab the first non-root category and use that.
try {
$CategoryID = $this->DiscussionModel->SQL->Select('CategoryID')->From('Category')->Where('CategoryID >', 0)->Get()->FirstRow()->CategoryID;
} catch (Exception $ex) {
// No categories in the db? default to 0
$CategoryID = 0;
}
}
}
$SystemUserID = Gdn::UserModel()->GetSystemUserID();
$DiscussionID = $this->DiscussionModel->SQL->Insert('Discussion', array('InsertUserID' => $SystemUserID, 'DateInserted' => Gdn_Format::ToDateTime(), 'UpdateUserID' => $SystemUserID, 'DateUpdated' => Gdn_Format::ToDateTime(), 'CategoryID' => $CategoryID == '' ? NULL : $CategoryID, 'ForeignID' => $ForeignID, 'Type' => $ForeignType, 'Name' => $ForeignName == '' ? T('Undefined foreign content') : $ForeignName, 'Body' => $Body, 'Attributes' => serialize(array('ForeignUrl' => $ForeignUrl))));
$ValidationResults = $this->DiscussionModel->ValidationResults();
if (count($ValidationResults) == 0 && $DiscussionID > 0) {
$Discussion = $this->DiscussionModel->GetID($DiscussionID);
// Update the category discussion count
if ($CategoryID > 0) {
$this->DiscussionModel->UpdateDiscussionCount($CategoryID, $DiscussionID);
}
}
}
// If no discussion was found, 404
if (!$Discussion) {
$this->Render('FileNotFound', 'HomeController', 'Dashboard');
return;
}
$this->SetData('Discussion', $Discussion, TRUE);
$this->SetData('DiscussionID', $Discussion->DiscussionID, TRUE);
$this->Title($this->Discussion->Name);
// Actual number of comments, excluding the discussion itself
$ActualResponses = $this->Discussion->CountComments - 1;
// Define the query offset & limit
//.........这里部分代码省略.........
示例4: Comment
/**
* Create or update a comment.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique ID to add the comment to. If blank, this method will throw an error.
*/
public function Comment($DiscussionID = '')
{
// Get $DiscussionID from RequestArgs if valid
if ($DiscussionID == '' && count($this->RequestArgs)) {
if (is_numeric($this->RequestArgs[0])) {
$DiscussionID = $this->RequestArgs[0];
}
}
// If invalid $DiscussionID, get from form.
$this->Form->SetModel($this->CommentModel);
$DiscussionID = is_numeric($DiscussionID) ? $DiscussionID : $this->Form->GetFormValue('DiscussionID', 0);
// Set discussion data
$this->DiscussionID = $DiscussionID;
$this->Discussion = $Discussion = $this->DiscussionModel->GetID($DiscussionID);
// Is this an embedded comment being posted to a discussion that doesn't exist yet?
$vanilla_type = $this->Form->GetFormValue('vanilla_type', '');
$vanilla_url = $this->Form->GetFormValue('vanilla_url', '');
$vanilla_category_id = $this->Form->GetFormValue('vanilla_category_id', '');
$Attributes = array('ForeignUrl' => $vanilla_url);
$vanilla_identifier = $this->Form->GetFormValue('vanilla_identifier', '');
// Only allow vanilla identifiers of 32 chars or less - md5 if larger
if (strlen($vanilla_identifier) > 32) {
$Attributes['vanilla_identifier'] = $vanilla_identifier;
$vanilla_identifier = md5($vanilla_identifier);
}
if (!$Discussion && $vanilla_url != '' && $vanilla_identifier != '') {
$Discussion = $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
if ($Discussion) {
$this->DiscussionID = $DiscussionID = $Discussion->DiscussionID;
$this->Form->SetValue('DiscussionID', $DiscussionID);
}
}
// If so, create it!
if (!$Discussion && $vanilla_url != '' && $vanilla_identifier != '') {
// Add these values back to the form if they exist!
$this->Form->AddHidden('vanilla_identifier', $vanilla_identifier);
$this->Form->AddHidden('vanilla_type', $vanilla_type);
$this->Form->AddHidden('vanilla_url', $vanilla_url);
$this->Form->AddHidden('vanilla_category_id', $vanilla_category_id);
$PageInfo = FetchPageInfo($vanilla_url);
if (!($Title = $this->Form->GetFormValue('Name'))) {
$Title = GetValue('Title', $PageInfo, '');
if ($Title == '') {
$Title = T('Undefined discussion subject.');
}
}
$Description = GetValue('Description', $PageInfo, '');
$Images = GetValue('Images', $PageInfo, array());
$LinkText = T('EmbededDiscussionLinkText', 'Read the full story here');
if (!$Description && count($Images) == 0) {
$Body = FormatString('<p><a href="{Url}">{LinkText}</a></p>', array('Url' => $vanilla_url, 'LinkText' => $LinkText));
} else {
$Body = FormatString('
<div class="EmbeddedContent">{Image}<strong>{Title}</strong>
<p>{Excerpt}</p>
<p><a href="{Url}">{LinkText}</a></p>
<div class="ClearFix"></div>
</div>', array('Title' => $Title, 'Excerpt' => $Description, 'Image' => count($Images) > 0 ? Img(GetValue(0, $Images), array('class' => 'LeftAlign')) : '', 'Url' => $vanilla_url, 'LinkText' => $LinkText));
}
if ($Body == '') {
$Body = $vanilla_url;
}
if ($Body == '') {
$Body = T('Undefined discussion body.');
}
// Validate the CategoryID for inserting.
$Category = CategoryModel::Categories($vanilla_category_id);
if (!$Category) {
$vanilla_category_id = C('Vanilla.Embed.DefaultCategoryID', 0);
if ($vanilla_category_id <= 0) {
// No default category defined, so grab the first non-root category and use that.
$vanilla_category_id = $this->DiscussionModel->SQL->Select('CategoryID')->From('Category')->Where('CategoryID >', 0)->Get()->FirstRow()->CategoryID;
// No categories in the db? default to 0
if (!$vanilla_category_id) {
$vanilla_category_id = 0;
}
}
} else {
$vanilla_category_id = $Category['CategoryID'];
}
$EmbedUserID = C('Garden.Embed.UserID');
if ($EmbedUserID) {
$EmbedUser = Gdn::UserModel()->GetID($EmbedUserID);
}
if (!$EmbedUserID || !$EmbedUser) {
$EmbedUserID = Gdn::UserModel()->GetSystemUserID();
}
$EmbeddedDiscussionData = array('InsertUserID' => $EmbedUserID, 'DateInserted' => Gdn_Format::ToDateTime(), 'DateUpdated' => Gdn_Format::ToDateTime(), 'CategoryID' => $vanilla_category_id, 'ForeignID' => $vanilla_identifier, 'Type' => $vanilla_type, 'Name' => $Title, 'Body' => $Body, 'Format' => 'Html', 'Attributes' => serialize($Attributes));
$this->EventArguments['Discussion'] = $EmbeddedDiscussionData;
$this->FireEvent('BeforeEmbedDiscussion');
$DiscussionID = $this->DiscussionModel->SQL->Insert('Discussion', $EmbeddedDiscussionData);
$ValidationResults = $this->DiscussionModel->ValidationResults();
//.........这里部分代码省略.........
示例5: FetchPageInfo
public function FetchPageInfo($Url)
{
$PageInfo = FetchPageInfo($Url);
$Title = GetValue('Title', $PageInfo, '');
if ($Title == '') {
$Title = FormatString(T('Undefined discussion subject.'), array('Url' => $Url));
} else {
if ($Strip = C('Vanilla.Embed.StripPrefix')) {
$Title = StringBeginsWith($Title, $Strip, TRUE, TRUE);
}
if ($Strip = C('Vanilla.Embed.StripSuffix')) {
$Title = StringEndsWith($Title, $Strip, TRUE, TRUE);
}
}
$Title = trim($Title);
$Description = GetValue('Description', $PageInfo, '');
$Images = GetValue('Images', $PageInfo, array());
$Body = FormatString(T('EmbeddedDiscussionFormat'), array('Title' => $Title, 'Excerpt' => $Description, 'Image' => count($Images) > 0 ? Img(GetValue(0, $Images), array('class' => 'LeftAlign')) : '', 'Url' => $Url));
if ($Body == '') {
$Body = $ForeignUrl;
}
if ($Body == '') {
$Body = FormatString(T('EmbeddedNoBodyFormat.'), array('Url' => $Url));
}
$Result = array('Name' => $Title, 'Body' => $Body, 'Format' => 'Html');
return $Result;
}