Моя золотая мечта 05.01.2025
Всем привет! В 2008 г. что-то в голову стукнуло, захотел сделать свой фейсбук. Короче интерфейс такой:
1. Это вид профиля (слева) и стены (справа):
Это QR код:
Это просмотр фотографии:
Это музыкальный проигрыватель, когда нажимаете проигрывать, то видна надпись "Вы слушаете сейчас: ..." и слышно музыку в динамиках или наушниках:
Это просмотр видео:
Я автор этой соцсети. Короче я буду непопорядку, и покажу не всё. Это чтобы вот так показывало сколько секунд назад был добавлен пост см.:
Вот код:
wall.js:
const GET_TIMES = 'get_times.php'; function ct(id) // count timer { $$.ajax(path + GET_TIMES, 'POST', 'pid=' + id, function(curr_time) { if(curr_time != '') $('time_' + id).text(curr_time); }); }
get_times.php:
<?php require_once('./config/config.php'); require_once('./libs/core/mod_core.php'); require_once('./libs/core/mod_database.php'); require_once('./libs/core/mod_post.php'); require_once('./libs/core/mod_date.php'); require_once('./libs/i18n/mod_i18n.php'); session_start(); if(!isset($_SESSION['UserID'])) exit; if(isset($_POST['pid'])) { I18n_init(); I18n_lang('./i18n/' . core_get_current_language() . '_post.php', './i18n/en_post.php'); $int_pid = $_POST['pid']; $arr_result = post_show_post_from_by_postid($int_pid); if(count($arr_result) <= 0) exit; $str_now = date("y-m-d H:i:s"); $str_datetime = strtotime($arr_result[0]['date']); $str_db_dt = date("y-m-d H:i:s", $str_datetime); $str_result = date_datediff($str_db_dt, $str_now, __('post.date')); echo $str_result; } ?>
А так чтобы поставить/удалить лайк:
Вот мой код:
wall.js:
const SET_LIKE = 'like.php'; function p_gll() // get_like_list { //<div class="tooltip">' . $str_users_likes . '</div> } function p_sl(postid, likeid, uid) // set_like { var timer1 = null; var timer2 = null; var persons_text = ''; $$.ajax(path + SET_LIKE, 'POST', 'cmd=1&type=like&lid=' + likeid + '&uid=' + uid, function(value) { $('post_like_' + postid).text(value); $('post_like_' + postid).attr('onclick', 'p_usl(' + postid + ', ' + likeid + ');'); if(value != '' && value != null) { timer1 = setTimeout(function() { $$.ajax(path + SET_LIKE, 'POST', 'cmd=3&lid=' + likeid, function(persons) { persons_text = persons; }); }, 100); timer2 = setTimeout(function() { $$.ajax(path + SET_LIKE, 'POST', 'cmd=2&lid=' + likeid, function(count) { if(persons_text == '') $('like_counter_' + postid).text(count); else $('like_counter_' + postid).text('<div class="tooltip_likes">' + persons_text + '</div>' + count); }); }, 200); } }); clearTimeout(timer1); clearTimeout(timer2); } function p_usl(postid, likeid, uid) // un_set_like { var timer1 = null; var timer2 = null; var persons_text = ''; $$.ajax(path + SET_LIKE, 'POST', 'cmd=1&type=unlike&lid=' + likeid, function(value) { $('post_like_' + postid).text(value); $('post_like_' + postid).attr('onclick', 'p_sl(' + postid + ', ' + likeid + ',' + uid +');'); timer1 = setTimeout(function() { $$.ajax(path + SET_LIKE, 'POST', 'cmd=3&lid=' + likeid, function(persons) { persons_text = persons; }); }, 100); timer2 = setTimeout(function() { $$.ajax(path + SET_LIKE, 'POST', 'cmd=2&lid=' + likeid, function(count) { if(persons_text == '') $('like_counter_' + postid).text(count); else $('like_counter_' + postid).text('<div class="tooltip_likes">' + persons_text + '</div>' + count); }); }, 100); }); clearTimeout(timer1); clearTimeout(timer2); }
like.php:
<?php require_once('./config/config.php'); require_once('./libs/core/mod_core.php'); require_once('./libs/core/mod_database.php'); require_once('./libs/core/mod_like.php'); require_once('./libs/core/mod_notifications.php'); require_once('./libs/i18n/mod_i18n.php'); session_start(); if(!isset($_SESSION['UserID'])) exit; if(!isset($_POST['cmd'])) exit; $int_cmd = $_POST['cmd']; if(core_is_logged_in()) { if($int_cmd == 1) { I18n_init(); I18n_lang('./i18n/' . core_get_current_language() . '_like.php', './i18n/en_like.php'); if($_POST['type'] == 'like') { like_set_like($_POST['lid'], $_SESSION['UserID'], 1); if($_SESSION['UserID'] != $_POST['uid']) { $str_now = date("y-m-d H:i:s"); notifications_add_notification($_SESSION['UserID'], $_POST['uid'], NOTIFICATION_LIKE, $str_now, $_POST['lid']); } echo __('unlike'); } if($_POST['type'] == 'unlike') { like_set_like($_POST['lid'], $_SESSION['UserID'], 0); echo __('like'); } return ; } if($int_cmd == 2) { $int_likes_count = like_get_like_count($_POST['lid']); if($int_likes_count <= 1) echo sprintf(__choice(__('likes'), 0), $int_likes_count); else if($int_likes_count > 1) echo sprintf(__choice(__('likes'), 1), $int_likes_count); exit; } if($int_cmd == 3) { $int_like_count = like_get_like_count($_POST['lid']); $arr_users_likes = like_get_like_users($_POST['lid'], 0, 5); foreach($arr_users_likes as $arr_user_like) { echo $arr_user_like['flname']; echo '<br />'; } if($int_like_count > 5) { $int_other_count = $int_like_count - 5; if($int_other_count == 1) echo sprintf(__(__choice('other', 0)), $int_other_count); elseif($int_other_count > 1) echo sprintf(__(__choice('other', 1)), $int_other_count); } } } ?>
Чтобы ютуб отображался вот так:
Я делал вот так, soundcloud не работает!:
<?php define("TAG_VIDEO", 1); define("TAG_PHOTO", 2); define("TAG_YOUTUBE", 3); define("TAG_URL", 4); define("TAG_SOUNDCLOUD", 5); function _find_tags($str_message, $int_tag_type) { $arr_files = array(); if($int_tag_type == TAG_VIDEO) { if(preg_match_all('/@v:(.*?);/', $str_message, $arr_files)) return $arr_files; else return ''; } else if($int_tag_type == TAG_PHOTO) { if(preg_match_all('/@i:(.*?);/', $str_message, $arr_files)) return $arr_files; else return ''; } else if($int_tag_type == TAG_YOUTUBE) { if(preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $str_message, $arr_video)) return '<iframe width="100%" height="300px" src="https://www.youtube.com/embed/' . $arr_video[1] . '" frameborder="0" allowfullscreen></iframe>'; else return ''; } else if($int_tag_type == TAG_URL) { if(preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $str_message) && !preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $str_message)) return $str_message; else return ''; } /*Not implemented yet - soundcloud.com*/ else if($int_tag_type == TAG_SOUNDCLOUD) { return ''; if(preg_match("/\bhttps{0,1}:\/\/w{0,3}\.*soundcloud\.com\/([A-Za-z0-9_-]+)\/([A-Za-z0-9_-]+)[^< ]*/i", $str_message, $arr_result)) return '<iframe width="100%" height="450px" scrolling="no" frameborder="no" src="' . $arr_result[0] . '"></iframe>'; else return ''; } }
Аудиопроигрыватель я сделал так audioplayer.js:
var mySound = null; var timerSound = null; var currPlayerId = ''; var currDuration = 0; function ap_tot(s) // to_time { var sec_num = parseInt(s, 10); var hours = Math.floor(sec_num / 3600); var minutes = Math.floor((sec_num - (hours * 3600)) / 60); var seconds = sec_num - (hours * 3600) - (minutes * 60); if(hours < 10) { hours = "0"+hours; } if(minutes < 10) { minutes = "0"+minutes; } if(seconds < 10) { seconds = "0"+seconds; } return hours+':'+minutes+':'+seconds; } function ap_pbc(c, m) // progress_bar_calculate { return Math.floor((200.0 / m) * c); } function ap_fnl(n, l) // format_number_length { var r = '' + n; while(r.length < l) { r = '0' + r; } return r; } function ap_paa(id) // pause_audio { $$.title(''); mySound.pause(); clearInterval(timerSound); } function ap_sa(f, t, id) // stop_audio { var p = document.getElementById('img_' + currPlayerId); if(p != null) { p.src = path + 'images/play.png'; p.id = 'img_' + currPlayerId; // p.setAttribute("onclick", 'ap_pa(\''+ f + '\',\'' + t + '\',' + id + ');'); } // $('play_button_' + currPlayerId).text('<a class="player_button" href="javascript:void(0);" onclick="ap_pa(\'' // + f + '\',\'' + t + '\',' + id + ');"><img id="img_' + id + '" src="' + path + // 'images/play.png" width="20px" height="20px" /></a>'); mySound.pause(); clearInterval(timerSound); } function ap_pa(f, t, id, at) // play_audio { var duration = 0; currPlayerId = id; if(mySound != null) ap_sa(); // $$.title("On air '" + at + "'"); $$.title(sprintf(__('audio_onair'), at)); mySound = new Audio(path + '/userdata/mp3/' + f); mySound.play(); mySound.volume = ap_gav(); mySound.progress = function(e) { alert(''); } mySound.onloadedmetadata = function() { duration = Math.floor(mySound.duration / 60); currDuration = mySound.duration; if(duration > 59) { $('current_time_' + id).text('00:00:00'); $('time_' + id).text('01:' + ap_fnl(duration, 2) + ':' + ap_fnl(Math.floor(mySound.duration % 60) , 2)); } else { $('current_time_' + id).text('00:00'); $('time_' + id).text(ap_fnl(duration, 2) + ':' + ap_fnl(Math.floor(mySound.duration % 60), 2)); } timerSound = setInterval( function() { $('play_button_' + currPlayerId).text('<a class="player_button" href="javascript:void(0);" onclick="ap_sa(\''+ f + '\',\'' + t + '\',' + id + ');"><img id="img_' + id + '" src="' + path + 'images/stop.png" width="20px" height="20px" /></a>'); $('current_time_' + currPlayerId).text(ap_tot(Math.floor(mySound.currentTime /*% 60*/))); document.getElementById('progress_' + id).style.width = ap_pbc(mySound.currentTime, currDuration) + 'px'; } , 100); } } function ap_lsf(u, tr_uploaded) // load_sound_files { $$.ajax(path + MP3SOUNDSLOAD, 'POST', 'u=' + u, function(sounds) { var resp = JSON.parse(sounds); var items = ''; for(var index=0; index<resp.length; index++) { items += '<div id="player__' + resp[index].audioid + '"><div title="' + sprintf(tr_uploaded, resp[index].flname) +'" id="player_' + index + '"><div>' + resp[index].author + ' - ' + resp[index].title + '</div><table><tr><td><div id="play_button_' + index + '"><a class="player_button" href="javascript:void(0);" onclick="ap_pa(\'' + resp[index].file + '\', \'\',' + index + ', \'' + resp[index].author + ' - ' + resp[index].title + '\')"><img id="img_' + resp[index].audioid + '" src="' + path + 'images/play.png" width="20px" height="20px" /></a> </td><td class="" style="width:200px;"><div class="_auplayer_none"> </div><div class="_auplayer_pos" style="width:0px;" id="progress_' + index + '"> </div></td><td><span id="current_time_' + index + '">00:00</span> / <span id="time_' + index + '">' + resp[index].length + '</span></td><td><a class="command" href="#javascript:void(0);" onclick="ap_da(' + resp[index].audioid + ');">×</a></tr></table></div></div> '; } var items2 = '<div id="volume_inner"><a class="command" href="javascript:void(0);" onclick="ap_dec();">-</a> <input type="text" id="volume_value" value="0.5" style="text-align:center; width:50px;"' + ' disabled> <a class="command" href="javascript:void(0);" onclick="ap_inc();">+</a></div>'; $('volume').text(items2); $('sounds').text(items); }); } function ap_sfua(id) // show_form_upload_audio { $$.ajax(path + FORM_AUDIO, 'GET', '', function(form) { $(id).text(form); }); } function ap_sff(fid) // show_find_form { // fid = form id $$.ajax(path + FORM_SEARCH, 'GET', '', function(form) { $(fid).text(form); }); } function ap_hff(fid) // hide_find_form { // fid = form id $(fid).text(' '); } function ap_fa(s) // find_audio { $$.ajax(path + SEARCH_AUDIO, 'POST', 'title=' + s, function(sounds) { var resp = JSON.parse(sounds); var items = ''; for(var index=0; index<resp.length; index++) { items += '<div id="player__' + resp[index].audioid + '"><div title="Uploaded by ' + resp[index].flname +'" id="player_' + index + '"><div>' + resp[index].author + ' - ' + resp[index].title + '</div><table><tr><td><div id="play_button_' + index + '"><a class="player_button" href="javascript:void(0);" onclick="ap_pa(\'' + resp[index].file + '\', \'\',' + index + ', \'' + resp[index].author + ' - ' + resp[index].title + '\')"><img src="' + path + 'images/play.png" width="20px" height="20px" /></a> </td><td class="" style="width:200px;"><div class="_auplayer_none"> </div><div class="_auplayer_pos" style="width:0px;" id="progress_' + index + '"> </div></td><td><span id="current_time_' + index + '">00:00</span> / <span id="time_' + index + '">' + resp[index].length + '</span></td><td><a class="command" id="addb_' + resp[index].audioid + '" href="javascript:void(0);" onclick="ap_aea(' + resp[index].audioid + ');">+</a></tr></table></div></div> '; } $('sounds').text(items); }); } function ap_da(aid) // delete_audio { $$.ajax(path + DELETE_AUDIO, 'POST', 'aid=' + aid, function(v) { $('player__' + aid).css('visibility:hidden'); }); } function ap_aea(aid) // add_exist_audio { $$.ajax(path + ADD_AUDIO, 'POST', 'aid=' + aid, function(v) { $('addb_' + aid).text(''); }); } function ap_sav(volume) // set_audio_volume { LS.set('audio_volume', volume); $('volume_value').val(volume); mySound.volume = volume; } function ap_gav() // get_audio_volume { return parseFloat($('volume_value').val()); } function ap_inc() // increase { var v = parseFloat($('volume_value').val()); if(v < 1.00) v+=0.01; ap_sav(v); } function ap_dec() // decrease { var v = parseFloat($('volume_value').val()); if(v > 0.00) v-=0.01; ap_sav(v); }
QR код в профиле генерируется вот так https://phpqrcode.sourceforge.net/
Вот так qrgen.php:
<?php session_start(); if(!isset($_SESSION['UserID'])) exit; if(!isset($_GET['id'])) exit; header('Content-Type:image/png'); require_once('./config/config.php'); require_once('./thirdparty/phpqrcode/qrlib.php'); $str_content = DOMAIN . MAIN_CONTROLLER . '/id' . $_GET['id']; QRcode::png($str_content); ?>