本文整理汇总了PHP中Notice::getParent方法的典型用法代码示例。如果您正苦于以下问题:PHP Notice::getParent方法的具体用法?PHP Notice::getParent怎么用?PHP Notice::getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notice
的用法示例。
在下文中一共展示了Notice::getParent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatNotice
/**
* makes a plain-text formatted version of a notice, suitable for IM distribution
*
* @param Notice $notice notice being sent
*
* @return string plain-text version of the notice, with user nickname prefixed
*/
protected function formatNotice(Notice $notice)
{
$profile = $notice->getProfile();
try {
$parent = $notice->getParent();
$orig_profile = $parent->getProfile();
$nicknames = sprintf('%1$s => %2$s', $profile->nickname, $orig_profile->nickname);
} catch (NoParentNoticeException $e) {
$nicknames = $profile->nickname;
}
return sprintf('%1$s: %2$s [%3$u]', $nicknames, $notice->content, $notice->id);
}
示例2: realpath
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
print "This script must be run from the command line\n";
exit;
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('GNUSOCIAL', true);
define('STATUSNET', true);
// compatibility
require_once INSTALLDIR . '/lib/common.php';
common_log(LOG_INFO, 'Starting to do old notices.');
$notice = new Notice();
$cnt = $notice->find();
while ($notice->fetch()) {
common_log(LOG_INFO, 'Getting tags for notice #' . $notice->id);
$notice->saveTags();
$original = clone $notice;
$notice->rendered = common_render_content($notice->content, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null);
$result = $notice->update($original);
if (!$result) {
common_log_db_error($notice, 'UPDATE', __FILE__);
}
}
示例3: saveNew
//.........这里部分代码省略.........
// unknown remote user - within a known conversation.
if (empty($notice->conversation) and !empty($options['conversation'])) {
$conv = Conversation::getKV('uri', $options['conversation']);
if ($conv instanceof Conversation) {
common_debug('Conversation stitched together from (probably) a reply to unknown remote user. Activity creation time (' . $notice->created . ') should maybe be compared to conversation creation time (' . $conv->created . ').');
} else {
// Conversation entry with specified URI was not found, so we must create it.
common_debug('Conversation URI not found, so we will create it with the URI given in the options to Notice::saveNew: ' . $options['conversation']);
// The insert in Conversation::create throws exception on failure
$conv = Conversation::create($options['conversation'], $notice->created);
}
$notice->conversation = $conv->getID();
unset($conv);
}
}
// If it's not part of a conversation, it's the beginning of a new conversation.
if (empty($notice->conversation)) {
$conv = Conversation::create();
$notice->conversation = $conv->getID();
unset($conv);
}
$notloc = new Notice_location();
if (!empty($lat) && !empty($lon)) {
$notloc->lat = $lat;
$notloc->lon = $lon;
}
if (!empty($location_ns) && !empty($location_id)) {
$notloc->location_id = $location_id;
$notloc->location_ns = $location_ns;
}
if (!empty($rendered)) {
$notice->rendered = $rendered;
} else {
$notice->rendered = common_render_content($final, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null);
}
if (empty($verb)) {
if ($notice->isRepeat()) {
$notice->verb = ActivityVerb::SHARE;
$notice->object_type = ActivityObject::ACTIVITY;
} else {
$notice->verb = ActivityVerb::POST;
}
} else {
$notice->verb = $verb;
}
if (empty($object_type)) {
$notice->object_type = empty($notice->reply_to) ? ActivityObject::NOTE : ActivityObject::COMMENT;
} else {
$notice->object_type = $object_type;
}
if (is_null($scope) && $reply instanceof Notice) {
$notice->scope = $reply->scope;
} else {
$notice->scope = $scope;
}
$notice->scope = self::figureOutScope($profile, $groups, $notice->scope);
if (Event::handle('StartNoticeSave', array(&$notice))) {
// XXX: some of these functions write to the DB
try {
$notice->insert();
// throws exception on failure, if successful we have an ->id
if ($notloc->lat && $notloc->lon || $notloc->location_id && $notloc->location_ns) {
$notloc->notice_id = $notice->getID();
$notloc->insert();
// store the notice location if it had any information
}
示例4: format_entry
/**
* extra information for XMPP messages, as defined by Twitter
*
* @param Profile $profile Profile of the sending user
* @param Notice $notice Notice being sent
*
* @return string Extra information (Atom, HTML, addresses) in string format
*/
protected function format_entry(Notice $notice)
{
$profile = $notice->getProfile();
$entry = $notice->asAtomEntry(true, true);
$xs = new XMLStringer();
$xs->elementStart('html', array('xmlns' => 'http://jabber.org/protocol/xhtml-im'));
$xs->elementStart('body', array('xmlns' => 'http://www.w3.org/1999/xhtml'));
$xs->element('a', array('href' => $profile->profileurl), $profile->nickname);
try {
$parent = $notice->getParent();
$orig_profile = $parent->getProfile();
$orig_profurl = $orig_profile->getUrl();
$xs->text(" => ");
$xs->element('a', array('href' => $orig_profurl), $orig_profile->nickname);
$xs->text(": ");
} catch (InvalidUrlException $e) {
$xs->text(sprintf(' => %s', $orig_profile->nickname));
} catch (NoParentNoticeException $e) {
$xs->text(": ");
}
if (!empty($notice->rendered)) {
$notice->rendered = str_replace("\t", "", $notice->rendered);
$xs->raw($notice->rendered);
} else {
$xs->raw(common_render_content($notice->content, $notice));
}
$xs->text(" ");
$xs->element('a', array('href' => common_local_url('conversation', array('id' => $notice->conversation)) . '#notice-' . $notice->id), sprintf(_m('[%u]'), $notice->id));
$xs->elementEnd('body');
$xs->elementEnd('html');
$html = $xs->getString();
return $html . ' ' . $entry;
}
示例5: format_entry
/**
* extra information for XMPP messages, as defined by Twitter
*
* @param Profile $profile Profile of the sending user
* @param Notice $notice Notice being sent
*
* @return string Extra information (Atom, HTML, addresses) in string format
*/
protected function format_entry(Notice $notice)
{
$profile = $notice->getProfile();
$entry = $notice->asAtomEntry(true, true);
$xs = new XMLStringer();
$xs->elementStart('html', array('xmlns' => 'http://jabber.org/protocol/xhtml-im'));
$xs->elementStart('body', array('xmlns' => 'http://www.w3.org/1999/xhtml'));
$xs->element('a', array('href' => $profile->profileurl), $profile->nickname);
try {
$parent = $notice->getParent();
$orig_profile = $parent->getProfile();
$orig_profurl = $orig_profile->getUrl();
$xs->text(" => ");
$xs->element('a', array('href' => $orig_profurl), $orig_profile->nickname);
$xs->text(": ");
} catch (InvalidUrlException $e) {
$xs->text(sprintf(' => %s', $orig_profile->nickname));
} catch (NoParentNoticeException $e) {
$xs->text(": ");
} catch (NoResultException $e) {
// Parent notice was probably deleted.
$xs->text(": ");
}
// FIXME: Why do we replace \t with ''? is it just to make it pretty? shouldn't whitespace be handled well...?
$xs->raw(str_replace("\t", "", $notice->getRendered()));
$xs->text(" ");
$xs->element('a', array('href' => common_local_url('conversation', array('id' => $notice->conversation)) . '#notice-' . $notice->id), sprintf(_m('[%u]'), $notice->id));
$xs->elementEnd('body');
$xs->elementEnd('html');
$html = $xs->getString();
return $html . ' ' . $entry;
}
示例6: common_find_mentions
/**
* Find @-mentions in the given text, using the given notice object as context.
* References will be resolved with common_relative_profile() against the user
* who posted the notice.
*
* Note the return data format is internal, to be used for building links and
* such. Should not be used directly; rather, call common_linkify_mentions().
*
* @param string $text
* @param Notice $notice notice in whose context we're building links
*
* @return array
*
* @access private
*/
function common_find_mentions($text, Notice $notice)
{
// The getProfile call throws NoProfileException on failure
$sender = $notice->getProfile();
$mentions = array();
if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) {
// Get the context of the original notice, if any
$origAuthor = null;
$origNotice = null;
$origMentions = array();
// Is it a reply?
if ($notice instanceof Notice) {
try {
$origNotice = $notice->getParent();
$origAuthor = $origNotice->getProfile();
$ids = $origNotice->getReplies();
foreach ($ids as $id) {
$repliedTo = Profile::getKV('id', $id);
if ($repliedTo instanceof Profile) {
$origMentions[$repliedTo->nickname] = $repliedTo;
}
}
} catch (NoProfileException $e) {
common_log(LOG_WARNING, sprintf('Notice %d author profile id %d does not exist', $origNotice->id, $origNotice->profile_id));
} catch (NoParentNoticeException $e) {
// This notice is not in reply to anything
} catch (Exception $e) {
common_log(LOG_WARNING, __METHOD__ . ' got exception ' . get_class($e) . ' : ' . $e->getMessage());
}
}
$matches = common_find_mentions_raw($text);
foreach ($matches as $match) {
try {
$nickname = Nickname::normalize($match[0]);
} catch (NicknameException $e) {
// Bogus match? Drop it.
continue;
}
// Try to get a profile for this nickname.
// Start with conversation context, then go to
// sender context.
if ($origAuthor instanceof Profile && $origAuthor->nickname == $nickname) {
$mentioned = $origAuthor;
} else {
if (!empty($origMentions) && array_key_exists($nickname, $origMentions)) {
$mentioned = $origMentions[$nickname];
} else {
$mentioned = common_relative_profile($sender, $nickname);
}
}
if ($mentioned instanceof Profile) {
$user = User::getKV('id', $mentioned->id);
if ($user instanceof User) {
$url = common_local_url('userbyid', array('id' => $user->id));
} else {
$url = $mentioned->profileurl;
}
$mention = array('mentioned' => array($mentioned), 'type' => 'mention', 'text' => $match[0], 'position' => $match[1], 'url' => $url);
if (!empty($mentioned->fullname)) {
$mention['title'] = $mentioned->fullname;
}
$mentions[] = $mention;
}
}
// @#tag => mention of all subscriptions tagged 'tag'
preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)@#([\\pL\\pN_\\-\\.]{1,64})/', $text, $hmatches, PREG_OFFSET_CAPTURE);
foreach ($hmatches[1] as $hmatch) {
$tag = common_canonical_tag($hmatch[0]);
$plist = Profile_list::getByTaggerAndTag($sender->id, $tag);
if (!$plist instanceof Profile_list || $plist->private) {
continue;
}
$tagged = $sender->getTaggedSubscribers($tag);
$url = common_local_url('showprofiletag', array('tagger' => $sender->nickname, 'tag' => $tag));
$mentions[] = array('mentioned' => $tagged, 'type' => 'list', 'text' => $hmatch[0], 'position' => $hmatch[1], 'url' => $url);
}
preg_match_all('/(?:^|[\\s\\.\\,\\:\\;]+)!(' . Nickname::DISPLAY_FMT . ')/', $text, $hmatches, PREG_OFFSET_CAPTURE);
foreach ($hmatches[1] as $hmatch) {
$nickname = Nickname::normalize($hmatch[0]);
$group = User_group::getForNickname($nickname, $sender);
if (!$group instanceof User_group || !$sender->isMember($group)) {
continue;
}
$profile = $group->getProfile();
$mentions[] = array('mentioned' => array($profile), 'type' => 'group', 'text' => $hmatch[0], 'position' => $hmatch[1], 'url' => $group->permalink(), 'title' => $group->getFancyName());
//.........这里部分代码省略.........
示例7: formatNotice
/**
* makes a plain-text formatted version of a notice, suitable for IM distribution
*
* @param Notice $notice notice being sent
*
* @return string plain-text version of the notice, with user nickname prefixed
*/
protected function formatNotice(Notice $notice)
{
$profile = $notice->getProfile();
$nicknames = $profile->getNickname();
try {
$parent = $notice->getParent();
$orig_profile = $parent->getProfile();
$nicknames = sprintf('%1$s => %2$s', $profile->getNickname(), $orig_profile->getNickname());
} catch (NoParentNoticeException $e) {
// Not a reply, no parent notice stored
} catch (NoResultException $e) {
// Parent notice was probably deleted
}
return sprintf('%1$s: %2$s [%3$u]', $nicknames, $notice->content, $notice->id);
}