本文整理汇总了PHP中SiteHelper::formatted方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteHelper::formatted方法的具体用法?PHP SiteHelper::formatted怎么用?PHP SiteHelper::formatted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteHelper
的用法示例。
在下文中一共展示了SiteHelper::formatted方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
echo $data->country->name . " | ";
?>
<?php
echo CHtml::encode(date("Y/m/d H:i", $data->time_submitted) . " UTC");
?>
</div>
<div class="row">
<?php
echo SiteHelper::subject_content($data);
?>
</div>
<div class="row">
<?php
echo SiteHelper::formatted($data->user_comment);
?>
</div>
<div class="row">
<?php
echo SiteHelper::share_links($data->urn, $data->title);
?>
</div>
<?php
$comments = Comment::model()->with('user')->findAll(array('condition' => "subject_id = {$data->id}", 'limit' => 5, 'order' => 't.id DESC'));
foreach ($comments as $comment) {
$i++;
?>
示例2:
<div class="row">
</div>
<div class="row">
<?php
echo SiteHelper::subject_content($model);
?>
</div>
<div class="row">
<?php
echo SiteHelper::formatted($model->user_comment);
?>
</div>
<div style="float:left;">
<?php
echo SiteHelper::share_links($model->urn, $model->title);
?>
</div>
<div style="float:right;margin-left:10px">
<?php
echo SiteHelper::subject_vote($model->id, $model->likes, $model->dislikes);
?>
</div>
<div class="clear_both"></div>
示例3: subject_content
/**
* Generates the proper html depending on the content_type_id
* @param object $subject the an instance of the Subject class
* @param string $mode in wich to return information(html or array of data)
* @return mixed string the html content OR array with content values
*/
public function subject_content($subject, $mode = 'html')
{
switch ($subject->content_type_id) {
case 1:
if ($subject->content_image->url) {
$img_url = $subject->content_image->url;
} else {
$img_url = Yii::app()->getRequest()->getBaseUrl(true) . '/' . $subject->content_image->path . '/';
$filename = $subject->content_image->id . '.' . $subject->content_image->extension;
$img_url .= Yii::app()->getTheme()->name == 'mobile' ? "small_" . $filename : $filename;
}
$html = '<img src="' . $img_url . '" class="content_image">';
//Yii::app()->getRequest()->getHostInfo().
if ($subject->content_image->url) {
$parsed_url = parse_url($subject->content_image->url);
$html .= "<br><span>Image source: " . $parsed_url['scheme'] . '://' . $parsed_url['host'];
}
$arr_content['image'] = $img_url;
break;
case 2:
$html = SiteHelper::formatted($subject->content_text->text);
break;
case 3:
preg_match_all('#\\bhttps?://[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/))#', $subject->content_video->embed_code, $match);
//would be nice to use yii validator to see if its an url but: http://code.google.com/p/yii/issues/detail?id=1324
if (SiteLibrary::valid_url($match[0][0])) {
//if its an url(if we could extract an url from the content)
$parsed_url = parse_url($match[0][0]);
$query_arr = SiteLibrary::parse_url_query($parsed_url['query']);
if (stristr($parsed_url['host'], 'youtube.com')) {
//and its from youtube
//get the V value $parsed_url['query'];
if (array_key_exists('v', $query_arr)) {
//set ?wmode=opaque because so that the the #header_top div does not get bellow the movie
//http://stackoverflow.com/questions/3820325/overlay-opaque-div-over-youtube-iframe
$time = $query_arr['t'] ? '#at=' . $query_arr['t'] : '';
//#at=** is the correct syntax for embed url, ie clic on the youtube logo while wathching a video on X seconds: it will open a new window with that param
$html = '<iframe width="640" height="390" src="http://www.youtube.com/embed/' . $query_arr['v'] . '?wmode=opaque' . $time . '" frameborder="0" allowfullscreen></iframe>';
} else {
$time = $query_arr['t'] ? '#at=' . $query_arr['t'] : '';
//#at=** is the correct syntax for embed url, ie clic on the youtube logo while wathching a video on X seconds: it will open a new window with that param
$vid_url = str_replace("/v/", "", $parsed_url['path']);
//remove the old embed code variable just in case it is present
if (strpos($vid_url, "?")) {
$vid_url = substr($vid_url, 0, strpos($vid_url, "?"));
} elseif (strpos($vid_url, "&")) {
$vid_url = substr($vid_url, 0, strpos($vid_url, "&"));
}
//remove the old params
$vid_url = str_replace("/embed/", "", $vid_url);
//remove the old embed code variable just in case it is present
$html = '<iframe width="640" height="390" src="http://www.youtube.com/embed/' . $vid_url . '?wmode=opaque' . $time . '" frameborder="0" allowfullscreen></iframe>';
}
} elseif (stristr($parsed_url['host'], 'youtu.be')) {
//and its from youtube shortly
$time = $query_arr['t'] ? '#at=' . $query_arr['t'] : '';
//#at=** is the correct syntax for embed url, ie clic on the youtube logo while wathching a video on X seconds: it will open a new window with that param
$html = '<iframe width="640" height="390" src="http://www.youtube.com/embed/' . $parsed_url['path'] . '?wmode=opaque' . $time . '" frameborder="0" allowfullscreen></iframe>';
} elseif (stristr($parsed_url['host'], 'dailymotion.com')) {
//the code is before the first undersore for the video source(pending verify if thats the syntax for all cases)
if ($last_code_pos = stripos($parsed_url['path'], '_')) {
$video_code = substr($parsed_url['path'], 1, $last_code_pos - 1);
if ($video_code) {
$html = '<iframe frameborder="0" width="640" height="390" src="http://www.dailymotion.com/embed/' . $video_code . '"></iframe>';
}
//$video_code already contains: /videdo/
}
} elseif (stristr($parsed_url['host'], 'vimeo.com')) {
if ($parsed_url['path']) {
//nice, we can play with params here, title, portrait, etc
$html = '<iframe src="http://player.vimeo.com/video' . $parsed_url['path'] . '?title=0&byline=0&portrait=0" width="640" height="390" frameborder="0"></iframe>';
}
} else {
$html = SiteHelper::formatted($subject->content_video->embed_code);
}
} else {
$html = SiteHelper::formatted($subject->content_video->embed_code);
}
//Get the iframe source url and set the image url for ogtags
//Also set opaque property for youtube videos
//src="...." second match (((?!").)*) searches for any string NOT containing " as that is our delimitter used in third match
$pattern = '/(src=")(((?!").)*)(")/i';
preg_match($pattern, $html, $matches);
//position 0 is the full match
$arr_content['url'] = $matches[2];
if (SiteLibrary::valid_url($arr_content['url'])) {
//if its an url
$parsed_url = parse_url($arr_content['url']);
$query_arr = SiteLibrary::parse_url_query($parsed_url['query']);
if (stripos($parsed_url['host'], 'youtube.com')) {
$pattern2 = strpos($arr_content['url'], '?') ? '/(embed\\/)(.+)(\\?)/i' : '/(embed\\/)(.+)$/i';
//the url can have extra params (a ? mark to pass extra params to the video)
preg_match($pattern2, $arr_content['url'], $matches);
//position 0 is the full match
//.........这里部分代码省略.........
示例4: array
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'user_comment');
?>
<?php
echo SiteHelper::formatted($model->user_comment);
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'User Comment code');
?>
<?php
echo CHtml::encode(SiteHelper::formatted($model->user_comment));
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'tag');
?>
<?php
foreach ($model->tags as $tag) {
$model->tag .= $tag->name . ',';
}
echo $form->textField($model, 'tag', array('size' => 40, 'maxlength' => 250));
?>
<?php
echo $form->error($model, 'tag');
示例5: getLiveData
/**
* Gets the latest live data about the current and next subject to be live
*
*
*/
public function getLiveData($subject_id = 0, $comment_id, $width = 0, $height = 0, $keepratio = true)
{
$arr_data = array();
$arr_comments = array();
$arr_data['new_comment'] = 0;
$arr_data['new_sub'] = 0;
//TODO: Store the whole subject record and its content as an array on the live_subject table
$live_subject = Yii::app()->db->createCommand()->select('*')->from('live_subject')->queryRow();
//returns an array, not an object
$arr_data['subject_id'] = $live_subject['subject_id'];
$arr_data['comment_id'] = $live_subject['comment_id'];
//If the subject cached on client's device its the same that the live_subject table indicates to be cached...
if ($subject_id != $live_subject['subject_id']) {
$subject_data = unserialize($live_subject['subject_data']);
$arr_data['title'] = $subject_data->title;
$arr_data['content_type_id'] = $subject_data->content_type_id;
$arr_data['content_type'] = strtolower($subject_data->content_type->name);
$arr_data['priority'] = strtolower($subject_data->priority_type->name);
$country = Country::model()->findByPk($subject_data->country_id);
$arr_data['country_code'] = $country->code ? $country->code : 'WW';
$arr_data['country_name'] = $country->name ? $country->name : 'WORLD';
$user = User::model()->findByPk($subject_data->user_id);
$arr_data['username'] = $user->username;
$arr_data['user_firstname'] = $user->firstname;
$arr_data['user_lastname'] = $user->lastname;
$arr_data['user_image'] = $user->getUserImage("small_");
$arr_data['content_html'] = SiteHelper::subject_content($subject_data);
$arr_data['content_data'] = (array) Subject::subject_content($subject_data)->getAttributes();
if ($arr_data['content_type'] == 'image') {
$img_name = $arr_data['content_data']['id'] . "." . $arr_data['content_data']['extension'];
$url_base = Yii::app()->getRequest()->getBaseUrl(true) . '/' . $arr_data['content_data']['path'] . '/';
if ($width or $height) {
$new_img_name = SiteLibrary::get_image_resized($img_name, Yii::app()->params['webdir'] . DIRECTORY_SEPARATOR . $arr_data['content_data']['path'], $width, $height, $keepratio);
if ($new_img_name) {
$arr_data['content_data']['image_url'] = $url_base . $new_img_name;
} else {
$arr_data['content_data']['image_url'] = $url_base . $img_name;
}
} else {
$arr_data['content_data']['image_url'] = $url_base . $img_name;
}
}
$arr_data['user_comment'] = SiteHelper::formatted($subject_data->user_comment);
$arr_data['time_submitted'] = $subject_data->time_submitted;
$arr_data['display_time'] = $subject_data->show_time;
$arr_data['scheduled_time'] = $subject_data->position;
if ($subject_id != $live_subject['subject_id']) {
$arr_data['new_sub']++;
}
$arr_data['likes'] = $subject_data->likes;
$arr_data['dislikes'] = $subject_data->dislikes;
$arr_data['urn'] = $subject_data->urn;
$arr_data['permalink'] = Yii::app()->getRequest()->getBaseUrl(true) . "/sub/" . $subject_data->urn;
//Send the last two previous subjects
$last_subs = Yii::app()->db->createCommand()->select('*')->from('subject')->where('show_time>:show_time AND id <>:id1', array(':show_time' => 0, ':id1' => $live_subject['subject_id']))->order('show_time DESC')->limit(5)->queryAll();
$arr_data['last_sub_title'] = $last_subs[0]['title'];
$arr_data['last_sub_2_title'] = $last_subs[1]['title'];
$arr_data['last_sub_urn'] = $last_subs[0]['urn'];
$arr_data['last_sub_2_urn'] = $last_subs[1]['urn'];
}
//Search comments
if ($subject_id != $live_subject['subject_id']) {
$comment_id = 0;
}
$live_comments = Yii::app()->db->createCommand()->select('*')->from('live_comment')->where('comment_id > :comment_id AND subject_id = :subject_id', array(':comment_id' => $comment_id, ':subject_id' => $live_subject['subject_id']))->order('comment_id ASC')->queryAll();
foreach ($live_comments as $live_comment) {
$arr_data['new_comment']++;
$arr_data['comment_id'] = $live_comment['comment_id'];
$user = User::model()->find('username=:username', array(':username' => $live_comment['username']));
$arr_comments[] = array('comment_id' => $live_comment['comment_id'], 'username' => $live_comment['username'], 'user_firstname' => $user->firstname, 'user_lastname' => $user->lastname, 'user_image' => $user->getUserImage("small_"), 'comment_text' => CHtml::encode($live_comment['comment_text']), 'comment_number' => $live_comment['comment_number'], 'comment_time' => date("H:i:s", $live_comment['comment_time']), 'comment_country' => $live_comment['comment_country'], 'likes' => $live_comment['likes'], 'dislikes' => $live_comment['dislikes']);
}
$arr_data['comments'] = $arr_comments;
//Add user session information
if (!$subject_id and !Yii::app()->user->isGuest) {
$arr_data['session_userid'] = Yii::app()->user->id;
$arr_data['session_username'] = Yii::app()->user->name;
$session_user = User::model()->findByPk((int) Yii::app()->user->id);
$arr_data['session_userimage'] = $session_user->getUserImage("small_");
}
//Set times
$utc_time = SiteLibrary::utc_time();
$arr_data['current_time'] = $utc_time;
$arr_data['current_time_h'] = date("H", $utc_time);
$arr_data['current_time_m'] = date("i", $utc_time);
$arr_data['current_time_s'] = date("s", $utc_time);
$arr_data['time_remaining'] = $live_subject['scheduled_time'] + Yii::app()->params['subject_interval'] * 60 - $utc_time + 2;
//lets give some seconds rage in case cron gets delayed
return $arr_data;
}