本文整理汇总了PHP中URL::media方法的典型用法代码示例。如果您正苦于以下问题:PHP URL::media方法的具体用法?PHP URL::media怎么用?PHP URL::media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类URL
的用法示例。
在下文中一共展示了URL::media方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_fupload
public function action_fupload()
{
if (!empty($_FILES['file'])) {
$user_id = Auth::instance()->get_user()->id;
$storage_id = Storage::instance()->add($_FILES['file'], $user_id);
if ($storage_id) {
$image = ORM::factory('Storage', $storage_id);
$fname = URL::media($image->file_path);
// displaying file
$array = array('filelink' => $fname, 'filename' => $image->name);
echo stripslashes(json_encode($array));
exit;
} else {
throw new HTTP_Exception_404('Ошибка при сохранении');
}
} else {
throw new HTTP_Exception_404('Не верный формат картинки');
}
////////////////////
/*
$dir = APPPATH . '../media/upload/';
$fname = substr(md5(time()), 0, 8) . '_' . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $dir . $fname);
$array = array(
'filelink' => Url::site('/media/upload/').'/'. $fname,
'filename' => $_FILES['file']['name']
);
echo stripslashes(json_encode($array));
exit;
*/
}
示例2: action_index
public function action_index()
{
header('Access-Control-Allow-Origin: *');
$photosets = ORM::factory('Photoset')->where('published', '=', 1)->where('is_important', '=', 1)->where('show_' . $this->language, '=', 1)->order_by('date', 'DESC')->limit(1)->find_all();
if (count($photosets) < 1) {
$this->data['error'] = 'Publication not found';
}
foreach ($photosets as $k => $v) {
$this->data['lastphoto']['id'] = $v->id;
$this->data['lastphoto']['name'] = $v->name;
$this->data['lastphoto']['date'] = $v->date;
$attach = $v->attach->where('main', '=', '1')->find();
$this->data['lastphoto']['file_path'] = 'http://' . $_SERVER['HTTP_HOST'] . URL::media('/images/w505-h680/' . $attach->photo->file_path);
}
$publications = ORM::factory('Publication')->where('title_' . I18n::$lang, '<>', '')->where('published', '=', 1)->and_where('is_slider', '=', 1)->order_by('order', 'desc')->limit(3)->find_all();
$pub = array();
foreach ($publications as $k => $v) {
$coverUrl = '';
if (!empty($v->picture->file_path)) {
$coverUrl = 'http://' . $_SERVER['HTTP_HOST'] . URL::media('/images/w333-h214/' . $v->picture->file_path);
}
$pub['id'] = $v->id;
$pub['url'] = 'http://' . $_SERVER['HTTP_HOST'] . URL::site('api/smartpublications/view/' . $v->id);
$pub['title'] = $v->title;
$pub['desc'] = strip_tags($v->desc);
$pub['coverUrl'] = $coverUrl;
$this->data['publications'][] = $pub;
}
$this->response->body(json_encode($this->data));
}
示例3: action_feed
public function action_feed()
{
$info = array('title' => __($this->metadata->title), 'pubDate' => date('r'), 'description' => $this->metadata->description, 'language' => I18n::lang(), 'ttl' => 60);
$news = ORM::factory('Publication')->where('published', '=', 1)->order_by('date', 'desc')->limit(40)->find_all();
$items = array();
foreach ($news as $item) {
$items[] = array('title' => $item->title, 'description' => strip_tags($item->desc), 'image' => isset($item->picture->file_path) && $item->picture->file_path ? URL::media($item->picture->file_path, TRUE) : '', 'content' => strip_tags($item->text), 'link' => Url::site('publications/view/' . $item->id, true), 'pubDate' => date('r', strtotime($item->date)));
}
header('Content-Type: text/xml; charset=utf-8');
$xml = Feed::create($info, $items, 'UTF-8');
echo $xml;
die;
}
示例4: userdata
function userdata($userid)
{
$user = ORM::factory('User', $userid);
if ($user->profile->first_name != '' and $user->profile->last_name != '') {
$username = $user->profile->first_name . ' ' . $user->profile->last_name;
} else {
$username = $user->username;
}
if (!empty($user->profile->img->file_path)) {
$author = array('name' => $username, 'id' => $user->id, 'photoUrl' => URL::media($user->profile->img->file_path, true));
} else {
$author = array('name' => $username, 'id' => $user->id, 'photoUrl' => '');
}
return $author;
}
示例5: action_view
public function action_view()
{
header('Access-Control-Allow-Origin: *');
$id = (int) $this->request->param('id', 0);
$material = ORM::factory('Education', $id);
if (!$material->loaded()) {
$this->data['error'] = '404 Not found';
$this->response->body(json_encode($this->data));
return;
}
$materials = $material->materials->find_all();
$this->data = array('id' => $material->id, 'title' => $material->title);
foreach ($materials as $k => $v) {
$this->data['materials'][] = array('type' => $v->type, 'path' => URL::media('media/scorm/' . $material->id . '/' . $v->path, true), 'title' => $v->title);
}
$this->response->body(json_encode($this->data));
}
示例6: action_view
public function action_view()
{
header('Access-Control-Allow-Origin: *');
$id = (int) $this->request->param('id', 0);
$photoset = ORM::factory('Photoset')->where('id', '=', $id)->where('show_' . $this->language, '=', 1)->find();
if (!$photoset->loaded()) {
$this->data['error'] = '404 Not Found';
$this->response->body(json_encode($this->data));
return;
}
$attach = $photoset->attach->order_by('order', 'asc')->find_all();
$this->data['name'] = $photoset->name();
foreach ($attach as $a) {
$this->data['photos'][] = array('name' => $a->name, 'thumb' => 'http://' . $_SERVER['HTTP_HOST'] . URL::media('images/w184-h184-ccc-si/' . $a->photo->file_path), 'full' => 'http://' . $_SERVER['HTTP_HOST'] . URL::media($a->photo->file_path));
}
$this->response->body(json_encode($this->data));
}
示例7: action_view
public function action_view()
{
header('Access-Control-Allow-Origin: *');
$id = (int) $this->request->param('id', 0);
$item = ORM::factory('Publication', $id);
if (!$item->loaded()) {
throw new HTTP_Exception_404();
}
if (!$item->translation()) {
throw new HTTP_Exception_404('no_translation');
}
$this->data['id'] = $item->id;
$this->data['title'] = $item->title;
$this->data['text'] = $item->text;
$this->data['image'] = 'http://' . $_SERVER['HTTP_HOST'] . URL::media($item->picture->file_path);
$tags = $item->tags->where('type', '=', 'publication')->find_all()->as_array('id', 'name');
$tags = implode(', ', $tags);
$this->data['tags'] = (array) $tags;
$this->response->body(json_encode($this->data));
}
示例8: action_index
public function action_index()
{
$email = Security::xss_clean(Arr::get($this->post, 'email', ''));
$user = ORM::factory('User')->where('email', '=', $email)->find();
if ($user->loaded() && $user->network_reg == 0 && empty($user->link_activate)) {
$date = date("Y-m-d H:i:s");
$code = md5($date . $user->password);
Email::connect();
Email::View('reminderapi');
Email::set(array('username' => $user->username, 'id' => $code, 'url' => URL::media($this->language . '/auth/recovery/', true)));
Email::send($user->email, array('no-reply@e-history.kz', 'e-history.kz'), "E-history.kz, ссылка для смены пароля.", '', true);
$save_code = ORM::factory('User', $user->id);
$save_code->link_recovery = $code;
$save_code->save();
$this->data = true;
} else {
$this->data['error'] = 'Email is not registered';
}
$this->response->body(json_encode($this->data));
}
示例9: action_materials
public function action_materials()
{
if (!Auth::instance()->logged_in()) {
$this->redirect('/', 301);
}
$user_id = $this->user->id;
$materials = ORM::factory('Material')->where('user_id', '=', $user_id);
$paginate = Paginate::factory($materials)->paginate(NULL, NULL, 3)->render();
$materials = $materials->find_all();
$this->set('materials', $materials);
$this->set('paginate', $paginate);
$uploader = View::factory('storage/materials')->set('user_id', $user_id)->render();
$this->set('uploader', $uploader);
if ($this->request->method() == Request::POST) {
$journal = (int) Arr::get($_POST, 'material_type', 0);
if ($journal !== 1) {
$journal = 0;
}
try {
$material = ORM::factory('Material');
$material->theme = substr(Arr::get($_POST, 'theme', ''), 0, 250);
$material->message = substr(Arr::get($_POST, 'message', ''), 0, 500);
$material->user_id = $user_id;
$material->date = date('Y-m-d H:i:s');
$material->lang_notice = strtolower(Kohana_I18n::lang());
if ($journal) {
$material->is_journal = 1;
$material->is_moderator = 0;
}
$material->save();
$files = Arr::get($_POST, 'files', '');
if ($files) {
foreach ($files as $key => $file) {
if ($key > 7) {
break;
}
if ($file) {
$storage = ORM::factory('Storage', (int) $file);
try {
$upload = ORM::factory('Material_File');
$upload->user_id = $user_id;
$upload->material_id = $material->id;
$upload->date = date('Y-m-d H:i:s');
$upload->storage_id = (int) $file;
$upload->filesize = filesize($storage->file_path);
$upload->save();
} catch (ORM_Validation_Exception $e) {
}
}
}
}
Message::success(i18n::get('The material sent to the moderator. Thank you!'));
$user = ORM::factory('User', $user_id);
$user_email = $user->email;
Email::connect();
Email::View('review_now_' . i18N::lang());
Email::set(array('message' => I18n::get('Оставленный вами материал находится на рассмотрении редакционной коллегии портала')));
Email::send($user_email, array('no-reply@e-history.kz', 'e-history.kz'), I18n::get('Рассмотрение материала на портале "История Казахстана" e-history.kz'), '', true);
if ($journal != 1) {
$material_type = 'Интересные материалы';
$url = URL::media('/manage/materials', TRUE);
} else {
$material_type = 'Журнал e-history';
$url = URL::media('/manage/materials/ehistory', TRUE);
}
$user_profile = ORM::factory('User_Profile', $user_id);
if ($user_profile->first_name != '') {
$user_name = $user_profile->first_name . ' ' . $user_profile->last_name;
} else {
$user_name = $user->username;
}
$email = 'kaz.ehistory@gmail.com';
Email::connect();
Email::View('new_material');
Email::set(array('url' => $url, 'material_type' => $material_type, 'username' => $user_name));
Email::send($email, array('no-reply@e-history.kz', 'e-history.kz'), "Новый материал на e-history.kz", '', true);
$this->redirect('profile/materials', 301);
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors($e->alias());
$files = Arr::get($_POST, 'files', '');
$this->set('errors', $errors)->set('material', $_POST)->set('files', $files);
}
}
$this->add_cumb('User profile', 'profile');
$this->add_cumb('Downloaded Content', '/');
}
示例10: action_index
public function action_index()
{
$start = Arr::get($_POST, 'start', date('Y-m-d 00:00:00'));
$end = Arr::get($_POST, 'end', date('Y-m-d 23:59:59'));
$logs = ORM::factory('Log')->where('date', '>=', $start)->and_where('date', '<=', $end)->find_all();
$data = array();
$models = array('Model_Publication' => __('Publications'), 'Model_News' => __('News'), 'Model_Pages_Content' => __('Pages'), 'Model_Expert_Opinion' => __('Expert opinions'), 'Model_Biography' => __('Biographies'), 'Model_Briefing' => __('Briefings'), 'Model_Calendar' => __('Calendar'), 'Model_Chronology_Line' => __('Chronology'), 'Model_Video' => __('Video'), 'Model_Audio' => __('Audio'), 'Model_Photoset' => __('Photosets'), 'Model_Point' => __('Point'), 'Model_Infograph' => __('Infographics'), 'Model_Slider' => __('Slider'), 'Model_Book' => __('Library'), 'Model_Debate' => __('Debate'));
$all = array();
$today = array();
foreach ($models as $model => $garbage) {
$e = explode('_', $model);
array_shift($e);
$count = ORM::factory(implode('_', $e))->count_all();
$all[$model] = $count;
$today[$model] = 0;
}
$this->set('all', $all);
foreach ($logs as $log) {
$user = ORM::factory('User', $log->user_id);
$model = $log->model;
$u = $user->email . ', ' . $user->username;
if (isset($data[$model][$u]['count'])) {
$data[$model][$u]['count']++;
} else {
$data[$model][$u]['count'] = 1;
}
if (isset($data[$model][$u]['words'])) {
$data[$model][$u]['words'] = $data[$model][$u]['words'] + $log->count;
} else {
$data[$model][$u]['words'] = $log->count;
}
$today[$model]++;
if ($model == 'Model_Publication') {
$publication = ORM::factory('Publication', $log->content_id);
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/publications/publication/view/' . $publication->id) . '">' . $publication->title . '</a>';
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $publication->loaded() ? 1 : 0;
}
if ($model == 'Model_News') {
$news = ORM::factory('News', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/publications/news/view/' . $news->id) . '">' . $news->title . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $news->loaded() ? 1 : 0;
}
if ($model == 'Model_Pages_Content') {
$content = ORM::factory('Pages_Content', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/contents/show/' . $content->id) . '">' . $content->title . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $content->loaded() ? 1 : 0;
}
if ($model == 'Model_Expert_Opinion') {
$opinion = ORM::factory('Expert_Opinion', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/expertopinions/view/' . $opinion->id) . '">' . $opinion->title . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $opinion->loaded() ? 1 : 0;
}
if ($model == 'Model_Debate') {
$debate = ORM::factory('Debate', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/debate/edit/' . $debate->id) . '">' . $debate->title . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $debate->loaded() ? 1 : 0;
}
if ($model == 'Model_Biography') {
$biography = ORM::factory('Biography', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/biography/view/' . $biography->id) . '">' . $biography->name . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $biography->loaded() ? 1 : 0;
}
if ($model == 'Model_Briefing') {
$briefing = ORM::factory('Briefing', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/briefings/view/' . $briefing->id) . '">' . $briefing->title . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $briefing->loaded() ? 1 : 0;
}
if ($model == 'Model_Calendar') {
$calendar = ORM::factory('Calendar', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/calendar/view/' . $calendar->id) . '">' . $calendar->title . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $calendar->loaded() ? 1 : 0;
}
if ($model == 'Model_Chronology_Line') {
$line = ORM::factory('Chronology_Line', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/chronology/edit/' . $line->id) . '">' . $line->title . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
$data[$model][$u]['has'][] = $line->loaded() ? 1 : 0;
}
if ($model == 'Model_Video') {
$video = ORM::factory('Video', $log->content_id);
$data[$model][$u]['pubs'][] = '<a target="_blank" href="' . URL::media('manage/video/view/' . $video->id) . '">' . $video->title . '</a>';
$data[$model][$u]['event'][] = $log->event;
$data[$model][$u]['title'][] = $log->title;
//.........这里部分代码省略.........
示例11: action_picturecut
public function action_picturecut()
{
$x1 = (int) Arr::get($_POST, 'x1', 0);
$h = (int) Arr::get($_POST, 'h', 0);
$y1 = (int) Arr::get($_POST, 'y1', 0);
$w = (int) Arr::get($_POST, 'w', 0);
$path = Arr::get($_POST, 'path', 0);
$user_id = Auth::instance()->get_user()->id;
$storage_id = Storage::instance()->save_jcrop_photo(URL::media($path, true), $user_id);
$storage = ORM::factory('Storage', $storage_id);
$newpath = $storage->file_path;
$targ_w = 280;
$targ_h = 186;
$ext = explode('.', $path);
$ext = $ext[1];
if ($ext != 'png') {
$img_r = imagecreatefromjpeg(URL::media($newpath, true));
} else {
$img_r = imagecreatefrompng(URL::media($newpath, true));
}
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r, $img_r, 0, 0, $x1, $y1, $targ_w, $targ_h, $w, $h);
if ($ext != 'png') {
imagejpeg($dst_r, $newpath, 90);
} else {
imagepng($dst_r, $newpath, 9);
}
$result['path'] = $newpath;
$result['id'] = $storage_id;
$this->response->body(json_encode($result));
}
示例12: foreach
</div>
<?php endif; ?>
*/
?>
<div id="comments-block">
<?php
foreach ($commentaries as $comment) {
?>
<div class="one-comment">
<div class="c-user-avatar">
<?php
if (isset($comment->user->profile->img->file_path)) {
?>
<div>
<img src="<?php
echo URL::media('images/w65-h65-cct-si/' . $comment->user->profile->img->file_path);
?>
" alt="" />
</div>
<?php
}
?>
</div>
<div class="c-user-comment">
<p class="comment-information">
<strong>
<?php
if (!$comment->status) {
?>
<?php
echo HTML::chars($comment->user->show_name());
示例13: action_delete_answer
public function action_delete_answer()
{
$id = (int) $this->request->param('id', 0);
$question = ORM::factory('Question', $id);
if (!$question->loaded()) {
throw new HTTP_Exception_404();
}
$token = Arr::get($_POST, 'token', false);
if ($this->request->post() and Security::token() === $token) {
$question->values(array('text_answer' => '', 'author' => '', 'date_answer' => NULL, 'status' => 1))->save();
Message::success('Ответ на вопрос удален');
$this->redirect('manage/questions/list/' . ($status = $question->status ? $question->status : ''));
}
$this->template->set_filename('manage/questions/delete');
$this->template->set('question', $question)->set('status', $question->status)->set('title', 'ответ на вопрос')->set('token', Security::token(true))->set('cancel_url', URL::media('manage/questions/list/' . ($status = $question->status ? $question->status : '')));
}
示例14: before
public function before()
{
parent::before();
// detecting language, setting it
// $this->detect_language();
// $this->set('_language', $this->language);
$this->set('device', $this->detect_device());
//var_dump($_COOKIE);
// creating and attaching page metadata
$this->metadata = new Model_Metadata();
$this->metadata->title(__(Application::instance()->get('title')), false);
$this->set('_metadata', $this->metadata);
$this->set('_token', Security::token());
// Handles return urls, cropping language out of it (will be appended by url.site at redirect time)
// $rr = Request::initial()->uri();
// $rr = trim($rr, '/');
// $rr = explode('/', $rr);
// if (in_array($rr[0], Application::instance()->get('language.list'))) {
// array_shift($rr);
// }
// $rr = implode('/', $rr);
// $this->set('_return', $rr . Url::query());
View::bind_global('_breadcumbs', $this->breadcumbs);
// detecting if user is logged in
if (method_exists(Auth::instance(), 'auto_login')) {
Auth::instance()->auto_login();
}
//
if (Auth::instance()->logged_in()) {
$id = Auth::instance()->get_user()->id;
$user = ORM::factory('user', $id);
$input = $user->has('roles', ORM::factory('role', array('name' => 'admin')));
$this->set("admin_mode", $input);
} else {
$this->set("admin_mode", false);
}
//
$this->user = Auth::instance()->get_user();
$this->set('_user', $this->user);
if (Auth::instance()->logged_in() && $this->user->profile->is_visited != 1 && strtolower($this->request->controller()) == 'profile') {
$this->redirect('profile/information', 301);
}
$sliders = ORM::factory('Slider')->where('is_active', '=', 1)->and_where('type', '=', 'slider')->order_by('order', 'asc')->find_all();
$this->set('sliders', $sliders);
$banner = ORM::factory('Slider')->where('is_active', '=', 1)->and_where('type', '=', 'banner')->find_all();
$this->set('menu_banner', $banner);
$menu = ORM::factory('Page')->where('key', '=', 'menu')->find();
//Для SEO (сортировка)
if ($this->request->controller() == 'Auth' or $this->request->controller() == 'Search' or $this->request->controller() == 'Profile') {
$this->set('sort', 1);
}
//end SEO
$page_roots = ORM::factory('Page', $menu->id)->children();
$page_main = array();
$children_pages = array();
$children_pages_last = array();
$children_pages_last_last = array();
foreach ($page_roots as $p) {
$page_main[$p->key] = array('id' => $p->id, 'name' => $p->name, 'description' => $p->description);
$children_pages[$p->key] = $p->children();
//ORM::factory('Page')->where('parent_id','=',$p->id)->find_all();//только первый уровень детей
//второй уровень детей.
foreach ($children_pages[$p->key] as $ch_p) {
if ($ch_p->id == 232 or $ch_p->id == 159) {
continue;
}
$children_pages_last[$ch_p->id] = $ch_p->children();
//третий уровень детей
foreach ($children_pages_last[$ch_p->id] as $ch_p_l) {
$children_pages_last_last[$ch_p_l->id] = $ch_p_l->children();
}
}
}
$page_halyk_kaharmany = ORM::factory('Page', 319);
$this->set('page_halyk_kaharmany', $page_halyk_kaharmany);
$this->set('_pages', $page_main)->set('_children_pages', $children_pages)->set('_children_pages_last', $children_pages_last)->set('_children_pages_last_last', $children_pages_last_last)->set('_return_url', URL::media(Request::initial()->uri()));
//для вывода сообщения о регистрации восстановления пароля и прочих действий
//само сообщение выводится в модальном окне, находится в шаблоне footer
if (Message::get()) {
$this->set('basic_message', Message::display('/message/basic'));
}
$nofollowlink = url::media(Request::initial()->uri());
$controller = strtolower(Request::initial()->controller());
$action = strtolower(Request::initial()->action());
if ($controller == 'books' and $action == 'index') {
$params = explode('books/', $_SERVER['REQUEST_URI']);
if (isset($params[1]) and isset($params[0])) {
$params = explode('?', $params[1]);
$razdel = $params[0];
} else {
$razdel = '';
}
if (isset($params[1])) {
$params = explode('=', $params[1]);
$idbook = $params[1];
} else {
$idbook = '';
}
$wherestring = 'books_' . $razdel . '_' . $idbook;
$page = ORM::factory('Page')->where('key', '=', $wherestring)->find();
//.........这里部分代码省略.........
示例15: action_view
public function action_view()
{
header('Access-Control-Allow-Origin: *');
$id = (int) $this->request->param('id', 0);
$debate = ORM::factory('Debate', $id);
if (!isset($has_access)) {
$has_access = 0;
}
if (!isset($has_ma_access)) {
$has_ma_access = 0;
}
if (!$debate->loaded() or !$has_ma_access and ($debate->is_public != 1 and !$has_access or $debate->is_closed)) {
$this->data['error'] = 'Not access to this debate';
$this->response->body(json_encode($this->data));
return;
}
$nowdate = date('Y-m-d H:i:s');
if ($debate->author->profile->img->file_path) {
$this->data['author_avatar'] = URL::media('/images/w140-h140-ccc-si/' . $debate->author->profile->img->file_path, true);
} else {
$this->data['author_avatar'] = URL::media('/images/w140-h140-ccc-si/media/images/no_user.jpg', true);
}
if ($debate->opponent->profile->img->file_path) {
$this->data['opponent_avatar'] = URL::media('/images/w140-h140-ccc-si/' . $debate->opponent->profile->img->file_path, true);
} else {
$this->data['opponent_avatar'] = URL::media('/images/w140-h140-ccc-si/media/images/no_user.jpg', true);
}
//URL.media('/images/w140-h140-ccc-si/media/images/no_user.jpg')
$this->data['id'] = $debate->id;
$this->data['title'] = $debate->title;
$this->data['preview'] = $debate->description;
$this->data['createdDate'] = $debate->date;
$this->data['authorId'] = $debate->author->id;
$this->data['authorUsername'] = $debate->author->username;
$this->data['opponentId'] = $debate->opponent->id;
$this->data['opponentUsername'] = $debate->opponent->username;
$this->data['endTime'] = $debate->end_time;
$this->data['url'] = URL::site('/', true) . $this->language . '/api/smartdebates/view/' . $debate->id;
$this->data['commentCount'] = $debate->comments_count;
$this->data['nowdate'] = $nowdate;
$opinions = ORM::factory('Debate_Opinion')->where('debate_id', '=', $id)->order_by('date', 'ASC')->find_all();
$comments = ORM::factory('Debate_Comment')->where('debate_id', '=', $id);
if (!$has_ma_access) {
$comments = $comments->and_where('hide', '=', 0);
}
$comments = $comments->order_by('date', 'ASC');
$comments_count = clone $comments;
$comments_count = $comments_count->count_all();
$comments = $comments->find_all();
foreach ($opinions as $k => $v) {
$op = array();
$op['moderator_text'] = $v->moderator_text;
$op['date'] = $v->date;
$op['minus'] = $v->minus;
$op['plus'] = $v->plus;
$this->data['opinions'][] = $op;
}
$this->response->body(json_encode($this->data));
}