facebook有哪些信息
Facebook like photo gallery with comments Have you thought about own facebook-style photo gallry system with comments? I think – yes. Today I made up my mind to prepare it for you. Main idea – when we click at images – they popup (ajax) with bigger image at the left and comments section at the right. All images are in the database (mySQL). And, of course, we will use PHP to achieve our result. Also, our comment system will prevent accepting more than 1 comment per 10 mins (to avoid spam).
Facebook喜欢带有评论的照片库您是否考虑过自己的带有评论的Facebook风格的照片库系统? 我想是的。 今天,我下定决心为您准备它。 主要思想-当我们单击图像时-它们会弹出(ajax),左侧显示较大的图像,右侧显示注释部分。 所有图像都在数据库(mySQL)中。 而且,当然,我们将使用PHP来达到目的。 此外,我们的评论系统将防止每10分钟接收超过1条评论(以避免垃圾邮件)。
[sociallocker]
[社交储物柜]
[/sociallocker]
[/ sociallocker]
Now – download the source files and lets start coding !
现在–下载源文件并开始编码!
For our gallery I prepared two SQL tables: first table keeps records of our images. It contains several fields: title, filename, description, time of adding and comments count. Another table keeps comments. So, execute next SQL instructions:
对于我们的画廊,我准备了两个SQL表:第一个表保留我们图像的记录。 它包含几个字段:标题,文件名,描述,添加时间和评论数。 另一个表保留注释。 因此,执行下一条SQL指令:
CREATE TABLE IF NOT EXISTS `s281_photos` (`id` int(10) unsigned NOT NULL auto_increment,`title` varchar(255) default '',`filename` varchar(255) default '',`description` text NOT NULL,`when` int(11) NOT NULL default '0',`comments_count` int(11) NOT NULL default '0',PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `s281_photos` (`title`, `filename`, `description`, `when`) VALUES
('Item #1', 'photo1.jpg', 'Description of Item #1', UNIX_TIMESTAMP()),
('Item #2', 'photo2.jpg', 'Description of Item #2', UNIX_TIMESTAMP()+1),
('Item #3', 'photo3.jpg', 'Description of Item #3', UNIX_TIMESTAMP()+2),
('Item #4', 'photo4.jpg', 'Description of Item #4', UNIX_TIMESTAMP()+3),
('Item #5', 'photo5.jpg', 'Description of Item #5', UNIX_TIMESTAMP()+4),
('Item #6', 'photo6.jpg', 'Description of Item #6', UNIX_TIMESTAMP()+5),
('Item #7', 'photo7.jpg', 'Description of Item #7', UNIX_TIMESTAMP()+6),
('Item #8', 'photo8.jpg', 'Description of Item #8', UNIX_TIMESTAMP()+7),
('Item #9', 'photo9.jpg', 'Description of Item #9', UNIX_TIMESTAMP()+8),
('Item #10', 'photo10.jpg', 'Description of Item #10', UNIX_TIMESTAMP()+9);
CREATE TABLE IF NOT EXISTS `s281_items_cmts` (`c_id` int(11) NOT NULL AUTO_INCREMENT ,`c_item_id` int(12) NOT NULL default '0',`c_ip` varchar(20) default NULL,`c_name` varchar(64) default '',`c_text` text NOT NULL ,`c_when` int(11) NOT NULL default '0',PRIMARY KEY (`c_id`),KEY `c_item_id` (`c_item_id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `s281_photos` (`id` int(10) unsigned NOT NULL auto_increment,`title` varchar(255) default '',`filename` varchar(255) default '',`description` text NOT NULL,`when` int(11) NOT NULL default '0',`comments_count` int(11) NOT NULL default '0',PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `s281_photos` (`title`, `filename`, `description`, `when`) VALUES
('Item #1', 'photo1.jpg', 'Description of Item #1', UNIX_TIMESTAMP()),
('Item #2', 'photo2.jpg', 'Description of Item #2', UNIX_TIMESTAMP()+1),
('Item #3', 'photo3.jpg', 'Description of Item #3', UNIX_TIMESTAMP()+2),
('Item #4', 'photo4.jpg', 'Description of Item #4', UNIX_TIMESTAMP()+3),
('Item #5', 'photo5.jpg', 'Description of Item #5', UNIX_TIMESTAMP()+4),
('Item #6', 'photo6.jpg', 'Description of Item #6', UNIX_TIMESTAMP()+5),
('Item #7', 'photo7.jpg', 'Description of Item #7', UNIX_TIMESTAMP()+6),
('Item #8', 'photo8.jpg', 'Description of Item #8', UNIX_TIMESTAMP()+7),
('Item #9', 'photo9.jpg', 'Description of Item #9', UNIX_TIMESTAMP()+8),
('Item #10', 'photo10.jpg', 'Description of Item #10', UNIX_TIMESTAMP()+9);
CREATE TABLE IF NOT EXISTS `s281_items_cmts` (`c_id` int(11) NOT NULL AUTO_INCREMENT ,`c_item_id` int(12) NOT NULL default '0',`c_ip` varchar(20) default NULL,`c_name` varchar(64) default '',`c_text` text NOT NULL ,`c_when` int(11) NOT NULL default '0',PRIMARY KEY (`c_id`),KEY `c_item_id` (`c_item_id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;
Now, please create empty index.php file and put next code:
现在,请创建一个空的index.php文件并放入下一个代码:
'.$aItemInfo['title'].' item
// disable warnings
if (version_compare(phpversion(), "5.3.0", ">=") == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
require_once('classes/CMySQL.php'); // include service classes to work with database and comments
require_once('classes/CMyComments.php');
if ($_POST['action'] == 'accept_comment') {echo $GLOBALS['MyComments']->acceptComment();exit;
}
// prepare a list with photos
$sPhotos = '';
$aItems = $GLOBALS['MySQL']->getAll("SELECT * FROM `s281_photos` ORDER by `when` ASC"); // get photos info
foreach ($aItems as $i => $aItemInfo) {$sPhotos .= '
}
?>Facebook like photo gallery with comments
Back to original tutorial on Script TutorialsLast photos:
= $sPhotos ?>
'.$aItemInfo['title'].' item
// disable warnings
if (version_compare(phpversion(), "5.3.0", ">=") == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
require_once('classes/CMySQL.php'); // include service classes to work with database and comments
require_once('classes/CMyComments.php');
if ($_POST['action'] == 'accept_comment') {echo $GLOBALS['MyComments']->acceptComment();exit;
}
// prepare a list with photos
$sPhotos = '';
$aItems = $GLOBALS['MySQL']->getAll("SELECT * FROM `s281_photos` ORDER by `when` ASC"); // get photos info
foreach ($aItems as $i => $aItemInfo) {$sPhotos .= '
}
?>Facebook like photo gallery with comments
Back to original tutorial on Script TutorialsLast photos:
= $sPhotos ?>
We have just created main index file of our gallery. By default – script generates a list of images (with title and description), and it also generates an empty hidden object which we are going to use in order to accept custom content by ajax requests. Also, when we post comments, we forward this request (to accept new comment) into comments class. Now, lets review next important php file:
我们刚刚创建了画廊的主索引文件。 默认情况下,脚本会生成一个图像列表(带有标题和描述),还会生成一个空的隐藏对象,我们将使用该对象来接受ajax请求的自定义内容。 同样,当我们发表评论时,我们会将这个请求(接受新评论)转发到评论类中。 现在,让我们回顾下一个重要的php文件:
// disable warnings
if (version_compare(phpversion(), "5.3.0", ">=") == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
if ($_POST[&#39;action&#39;] &#61;&#61; &#39;get_info&#39; && (int)$_POST[&#39;id&#39;] > 0) {require_once(&#39;classes/CMySQL.php&#39;); // include service classes to work with database and commentsrequire_once(&#39;classes/CMyComments.php&#39;);// get photo info$iPid &#61; (int)$_POST[&#39;id&#39;];$aImageInfo &#61; $GLOBALS[&#39;MySQL&#39;]->getRow("SELECT * FROM &#96;s281_photos&#96; WHERE &#96;id&#96; &#61; &#39;{$iPid}&#39;");// prepare last 10 comments$sCommentsBlock &#61; $GLOBALS[&#39;MyComments&#39;]->getComments($iPid);$aItems &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_photos&#96; ORDER by &#96;when&#96; ASC"); // get photos info// Prev & Next navigation$sNext &#61; $sPrev &#61; &#39;&#39;;$iPrev &#61; (int)$GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;id&#96; FROM &#96;s281_photos&#96; WHERE &#96;id&#96; <&#39;{$iPid}&#39; ORDER BY &#96;id&#96; DESC LIMIT 1");$iNext &#61; (int)$GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;id&#96; FROM &#96;s281_photos&#96; WHERE &#96;id&#96; > &#39;{$iPid}&#39; ORDER BY &#96;id&#96; ASC LIMIT 1");$sPrevBtn &#61; ($iPrev) ? &#39;&#39; : &#39;&#39;;$sNextBtn &#61; ($iNext) ? &#39;&#39; : &#39;&#39;;require_once(&#39;classes/Services_JSON.php&#39;);$oJson &#61; new Services_JSON();header(&#39;Content-Type:text/Javascript&#39;);echo $oJson->encode(array(&#39;data1&#39; &#61;> &#39;&#39; . $sPrevBtn . $sNextBtn,&#39;data2&#39; &#61;> $sCommentsBlock,));exit;
}
// disable warnings
if (version_compare(phpversion(), "5.3.0", ">&#61;") &#61;&#61; 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
if ($_POST[&#39;action&#39;] &#61;&#61; &#39;get_info&#39; && (int)$_POST[&#39;id&#39;] > 0) {require_once(&#39;classes/CMySQL.php&#39;); // include service classes to work with database and commentsrequire_once(&#39;classes/CMyComments.php&#39;);// get photo info$iPid &#61; (int)$_POST[&#39;id&#39;];$aImageInfo &#61; $GLOBALS[&#39;MySQL&#39;]->getRow("SELECT * FROM &#96;s281_photos&#96; WHERE &#96;id&#96; &#61; &#39;{$iPid}&#39;");// prepare last 10 comments$sCommentsBlock &#61; $GLOBALS[&#39;MyComments&#39;]->getComments($iPid);$aItems &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_photos&#96; ORDER by &#96;when&#96; ASC"); // get photos info// Prev & Next navigation$sNext &#61; $sPrev &#61; &#39;&#39;;$iPrev &#61; (int)$GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;id&#96; FROM &#96;s281_photos&#96; WHERE &#96;id&#96; <&#39;{$iPid}&#39; ORDER BY &#96;id&#96; DESC LIMIT 1");$iNext &#61; (int)$GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;id&#96; FROM &#96;s281_photos&#96; WHERE &#96;id&#96; > &#39;{$iPid}&#39; ORDER BY &#96;id&#96; ASC LIMIT 1");$sPrevBtn &#61; ($iPrev) ? &#39;&#39; : &#39;&#39;;$sNextBtn &#61; ($iNext) ? &#39;&#39; : &#39;&#39;;require_once(&#39;classes/Services_JSON.php&#39;);$oJson &#61; new Services_JSON();header(&#39;Content-Type:text/Javascript&#39;);echo $oJson->encode(array(&#39;data1&#39; &#61;> &#39;&#39; . $sPrevBtn . $sNextBtn,&#39;data2&#39; &#61;> $sCommentsBlock,));exit;
}
This file sends back information about requested photo. This is an enlarged image, block with comments and navigation buttons (to open previous / next images ajaxy). As you can see – we use comments class, now, it’s time to look at it too:
该文件发回有关所请求照片的信息。 这是一个放大的图像&#xff0c;带有注释和导航按钮的块(用于以ajaxy方式打开上一个/下一个图像)。 如您所见–我们现在使用注释类&#xff0c;现在也该看看它了&#xff1a;
Comment from {$aCmtsInfo[&#39;c_name&#39;]} ({$sWhen}): {$aCmtsInfo[&#39;c_text&#39;]} Comment from {$aCmtsInfo[&#39;c_name&#39;]} ({$sWhen}): {$aCmtsInfo[&#39;c_text&#39;]}
class CMyComments {// constructorfunction CMyComments() {}// return comments blockfunction getComments($i) {// draw last 10 comments$sComments &#61; &#39;&#39;;$aComments &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$i}&#39; ORDER BY &#96;c_when&#96; DESC LIMIT 10");foreach ($aComments as $i &#61;> $aCmtsInfo) {$sWhen &#61; date(&#39;F j, Y H:i&#39;, $aCmtsInfo[&#39;c_when&#39;]);$sComments .&#61; <<
EOF;}return <<Comments
EOF;}function acceptComment() {$iItemId &#61; (int)$_POST[&#39;id&#39;]; // prepare necessary information$sIp &#61; $this->getVisitorIP();$sName &#61; $GLOBALS[&#39;MySQL&#39;]->escape(strip_tags($_POST[&#39;name&#39;]));$sText &#61; $GLOBALS[&#39;MySQL&#39;]->escape(strip_tags($_POST[&#39;text&#39;]));if ($sName && $sText) {// check - if there is any recent post from you or not$iOldId &#61; $GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;c_item_id&#96; FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39; AND &#96;c_ip&#96; &#61; &#39;{$sIp}&#39; AND &#96;c_when&#96; >&#61; UNIX_TIMESTAMP() - 600 LIMIT 1");if (! $iOldId) {// if everything is fine - allow to add comment$GLOBALS[&#39;MySQL&#39;]->res("INSERT INTO &#96;s281_items_cmts&#96; SET &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39;, &#96;c_ip&#96; &#61; &#39;{$sIp}&#39;, &#96;c_when&#96; &#61; UNIX_TIMESTAMP(), &#96;c_name&#96; &#61; &#39;{$sName}&#39;, &#96;c_text&#96; &#61; &#39;{$sText}&#39;");$GLOBALS[&#39;MySQL&#39;]->res("UPDATE &#96;s281_photos&#96; SET &#96;comments_count&#96; &#61; &#96;comments_count&#96; &#43; 1 WHERE &#96;id&#96; &#61; &#39;{$iItemId}&#39;");// and print out last 10 comments$sOut &#61; &#39;&#39;;$aComments &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39; ORDER BY &#96;c_when&#96; DESC LIMIT 10");foreach ($aComments as $i &#61;> $aCmtsInfo) {$sWhen &#61; date(&#39;F j, Y H:i&#39;, $aCmtsInfo[&#39;c_when&#39;]);$sOut .&#61; <<
EOF;}return $sOut;}}return 1;}// get visitor IPfunction getVisitorIP() {$ip &#61; "0.0.0.0";if( ( isset( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] ) ) && ( !empty( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] ) ) ) {$ip &#61; $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;];} elseif( ( isset( $_SERVER[&#39;HTTP_CLIENT_IP&#39;])) && (!empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;] ) ) ) {$ip &#61; explode(".",$_SERVER[&#39;HTTP_CLIENT_IP&#39;]);$ip &#61; $ip[3].".".$ip[2].".".$ip[1].".".$ip[0];} elseif((!isset( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;])) || (empty($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]))) {if ((!isset( $_SERVER[&#39;HTTP_CLIENT_IP&#39;])) && (empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;]))) {$ip &#61; $_SERVER[&#39;REMOTE_ADDR&#39;];}}return $ip;}
}
$GLOBALS[&#39;MyComments&#39;] &#61; new CMyComments();
?>
Comment from {$aCmtsInfo[&#39;c_name&#39;]} ({$sWhen}): {$aCmtsInfo[&#39;c_text&#39;]} Comment from {$aCmtsInfo[&#39;c_name&#39;]} ({$sWhen}): {$aCmtsInfo[&#39;c_text&#39;]}
class CMyComments {// constructorfunction CMyComments() {}// return comments blockfunction getComments($i) {// draw last 10 comments$sComments &#61; &#39;&#39;;$aComments &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$i}&#39; ORDER BY &#96;c_when&#96; DESC LIMIT 10");foreach ($aComments as $i &#61;> $aCmtsInfo) {$sWhen &#61; date(&#39;F j, Y H:i&#39;, $aCmtsInfo[&#39;c_when&#39;]);$sComments .&#61; <<
EOF;}return <<Comments
EOF;}function acceptComment() {$iItemId &#61; (int)$_POST[&#39;id&#39;]; // prepare necessary information$sIp &#61; $this->getVisitorIP();$sName &#61; $GLOBALS[&#39;MySQL&#39;]->escape(strip_tags($_POST[&#39;name&#39;]));$sText &#61; $GLOBALS[&#39;MySQL&#39;]->escape(strip_tags($_POST[&#39;text&#39;]));if ($sName && $sText) {// check - if there is any recent post from you or not$iOldId &#61; $GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;c_item_id&#96; FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39; AND &#96;c_ip&#96; &#61; &#39;{$sIp}&#39; AND &#96;c_when&#96; >&#61; UNIX_TIMESTAMP() - 600 LIMIT 1");if (! $iOldId) {// if everything is fine - allow to add comment$GLOBALS[&#39;MySQL&#39;]->res("INSERT INTO &#96;s281_items_cmts&#96; SET &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39;, &#96;c_ip&#96; &#61; &#39;{$sIp}&#39;, &#96;c_when&#96; &#61; UNIX_TIMESTAMP(), &#96;c_name&#96; &#61; &#39;{$sName}&#39;, &#96;c_text&#96; &#61; &#39;{$sText}&#39;");$GLOBALS[&#39;MySQL&#39;]->res("UPDATE &#96;s281_photos&#96; SET &#96;comments_count&#96; &#61; &#96;comments_count&#96; &#43; 1 WHERE &#96;id&#96; &#61; &#39;{$iItemId}&#39;");// and print out last 10 comments$sOut &#61; &#39;&#39;;$aComments &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39; ORDER BY &#96;c_when&#96; DESC LIMIT 10");foreach ($aComments as $i &#61;> $aCmtsInfo) {$sWhen &#61; date(&#39;F j, Y H:i&#39;, $aCmtsInfo[&#39;c_when&#39;]);$sOut .&#61; <<
EOF;}return $sOut;}}return 1;}// get visitor IPfunction getVisitorIP() {$ip &#61; "0.0.0.0";if( ( isset( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] ) ) && ( !empty( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] ) ) ) {$ip &#61; $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;];} elseif( ( isset( $_SERVER[&#39;HTTP_CLIENT_IP&#39;])) && (!empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;] ) ) ) {$ip &#61; explode(".",$_SERVER[&#39;HTTP_CLIENT_IP&#39;]);$ip &#61; $ip[3].".".$ip[2].".".$ip[1].".".$ip[0];} elseif((!isset( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;])) || (empty($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]))) {if ((!isset( $_SERVER[&#39;HTTP_CLIENT_IP&#39;])) && (empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;]))) {$ip &#61; $_SERVER[&#39;REMOTE_ADDR&#39;];}}return $ip;}
}
$GLOBALS[&#39;MyComments&#39;] &#61; new CMyComments();
?>
This class performs two main functions – it can accept new comments and also it can give us a box with comments. There are two more service classes: CMySQL.php and Services_JSON.php. They are two known classes to work with database and json. You can adjust database settings in database class. Both classes available in our package.
此类执行两个主要功能–可以接受新评论&#xff0c;也可以给我们提供带有评论的框。 还有另外两个服务类&#xff1a;CMySQL.php和Services_JSON.php。 它们是两个与数据库和json一起使用的已知类。 您可以在数据库类中调整数据库设置。 这两个类均在我们的包装中提供。
// close photo preview block
function closePhotoPreview() {$(&#39;#photo_preview&#39;).hide();$(&#39;#photo_preview .pleft&#39;).html(&#39;empty&#39;);$(&#39;#photo_preview .pright&#39;).html(&#39;empty&#39;);
};
// display photo preview block
function getPhotoPreviewAjx(id) {$.post(&#39;photos_ajx.php&#39;, {action: &#39;get_info&#39;, id: id},function(data){$(&#39;#photo_preview .pleft&#39;).html(data.data1);$(&#39;#photo_preview .pright&#39;).html(data.data2);$(&#39;#photo_preview&#39;).show();}, "json");
};
// submit comment
function submitComment(id) {var sName &#61; $(&#39;#name&#39;).val();var sText &#61; $(&#39;#text&#39;).val();if (sName && sText) {$.post(&#39;index.php&#39;, { action: &#39;accept_comment&#39;, name: sName, text: sText, id: id },function(data){if (data !&#61; &#39;1&#39;) {$(&#39;#comments_list&#39;).fadeOut(1000, function () {$(this).html(data);$(this).fadeIn(1000);});} else {$(&#39;#comments_warning2&#39;).fadeIn(1000, function () {$(this).fadeOut(1000);});}});} else {$(&#39;#comments_warning1&#39;).fadeIn(1000, function () {$(this).fadeOut(1000);});}
};
// init
$(function(){// onclick event handlers$(&#39;#photo_preview .photo_wrp&#39;).click(function (event) {event.preventDefault();return false;});$(&#39;#photo_preview&#39;).click(function (event) {closePhotoPreview();});$(&#39;#photo_preview img.close&#39;).click(function (event) {closePhotoPreview();});// display photo preview ajaxy$(&#39;.container .photo img&#39;).click(function (event) {if (event.preventDefault) event.preventDefault();getPhotoPreviewAjx($(this).attr(&#39;id&#39;));});
})
// close photo preview block
function closePhotoPreview() {$(&#39;#photo_preview&#39;).hide();$(&#39;#photo_preview .pleft&#39;).html(&#39;empty&#39;);$(&#39;#photo_preview .pright&#39;).html(&#39;empty&#39;);
};
// display photo preview block
function getPhotoPreviewAjx(id) {$.post(&#39;photos_ajx.php&#39;, {action: &#39;get_info&#39;, id: id},function(data){$(&#39;#photo_preview .pleft&#39;).html(data.data1);$(&#39;#photo_preview .pright&#39;).html(data.data2);$(&#39;#photo_preview&#39;).show();}, "json");
};
// submit comment
function submitComment(id) {var sName &#61; $(&#39;#name&#39;).val();var sText &#61; $(&#39;#text&#39;).val();if (sName && sText) {$.post(&#39;index.php&#39;, { action: &#39;accept_comment&#39;, name: sName, text: sText, id: id },function(data){if (data !&#61; &#39;1&#39;) {$(&#39;#comments_list&#39;).fadeOut(1000, function () {$(this).html(data);$(this).fadeIn(1000);});} else {$(&#39;#comments_warning2&#39;).fadeIn(1000, function () {$(this).fadeOut(1000);});}});} else {$(&#39;#comments_warning1&#39;).fadeIn(1000, function () {$(this).fadeOut(1000);});}
};
// init
$(function(){// onclick event handlers$(&#39;#photo_preview .photo_wrp&#39;).click(function (event) {event.preventDefault();return false;});$(&#39;#photo_preview&#39;).click(function (event) {closePhotoPreview();});$(&#39;#photo_preview img.close&#39;).click(function (event) {closePhotoPreview();});// display photo preview ajaxy$(&#39;.container .photo img&#39;).click(function (event) {if (event.preventDefault) event.preventDefault();getPhotoPreviewAjx($(this).attr(&#39;id&#39;));});
})
Please note, we use jQuery instructions in our script (I hope that you haven’t forgot that we linked jQuery library in the header section through google service).
请注意&#xff0c;我们在脚本中使用了jQuery指令(希望您不要忘记我们通过Google服务在标头部分中链接了jQuery库)。
In the long run, we should stylize our page elements (our container with photos, photo preview area with comments):
从长远来看&#xff0c;我们应该样式化页面元素(带有照片的我们的容器&#xff0c;带有评论的照片预览区域)&#xff1a;
/* project styles */
.container {border: 1px solid #111111;color: #000000;margin: 20px auto;overflow: hidden;padding: 15px;position: relative;text-align: center;width: 1090px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.photo {border: 1px solid transparent;float: left;margin: 4px;overflow: hidden;padding: 4px;white-space: nowrap;/* CSS3 Box sizing property */-moz-box-sizing: border-box;-webkit-box-sizing: border-box;-o-box-sizing: border-box;box-sizing: border-box;/* CSS3 transition */-moz-transition: border 0.2s ease 0s;-ms-transition: border 0.2s ease 0s;-o-transition: border 0.2s ease 0s;-webkit-transition: border 0.2s ease 0s;transition: border 0.2s ease 0s;
}
.photo:hover {border-color: #444;
}
.photo img {cursor: pointer;width: 200px;
}
.photo p, .photo i {display: block;
}
.photo p {font-weight: bold;
}
/* preview styles */
#photo_preview {background-color: rgba(0, 0, 0, 0.7);bottom: 0;color: #000000;display: none;left: 0;overflow: hidden;position: fixed;right: 0;top: 0;z-index: 10;
}
.photo_wrp {background-color: #FAFAFA;height: auto;margin: 100px auto 0;overflow: hidden;padding: 15px;text-align: center;vertical-align: middle;width: 1000px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.close {cursor: pointer;float: right;
}
.pleft {float: left;overflow: hidden;position: relative;width: 600px;
}
.pright {float: right;position: relative;width: 360px;
}
.preview_prev, .preview_next {cursor: pointer;margin-top: -64px;opacity: 0.5;position: absolute;top: 50%;-moz-transition: opacity 0.2s ease 0s;-ms-transition: opacity 0.2s ease 0s;-o-transition: opacity 0.2s ease 0s;-webkit-transition: opacity 0.2s ease 0s;transition: opacity 0.2s ease 0s;
}
.preview_prev:hover, .preview_next:hover {opacity: 1;
}
.preview_prev {left: 20px;
}
.preview_next {right: 40px;
}
/* comments styles */
#comments form {margin: 10px 0;text-align: left;
}
#comments table td.label {color: #000;font-size: 13px;padding-right: 3px;text-align: right;width: 105px;
}
#comments table label {color: #000;font-size: 16px;font-weight: normal;vertical-align: middle;
}
#comments table td.field input, #comments table td.field textarea {border: 1px solid #96A6C5;font-family: Verdana,Arial,sans-serif;font-size: 16px;margin-top: 2px;padding: 6px;width: 250px;
}
#comments_list {margin: 10px 0;text-align: left;
}
#comments_list .comment {border-top: 1px solid #000;padding: 10px 0;
}
#comments_list .comment:first-child {border-top-width:0px;
}
#comments_list .comment span {font-size: 11px;
}
/* project styles */
.container {border: 1px solid #111111;color: #000000;margin: 20px auto;overflow: hidden;padding: 15px;position: relative;text-align: center;width: 1090px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.photo {border: 1px solid transparent;float: left;margin: 4px;overflow: hidden;padding: 4px;white-space: nowrap;/* CSS3 Box sizing property */-moz-box-sizing: border-box;-webkit-box-sizing: border-box;-o-box-sizing: border-box;box-sizing: border-box;/* CSS3 transition */-moz-transition: border 0.2s ease 0s;-ms-transition: border 0.2s ease 0s;-o-transition: border 0.2s ease 0s;-webkit-transition: border 0.2s ease 0s;transition: border 0.2s ease 0s;
}
.photo:hover {border-color: #444;
}
.photo img {cursor: pointer;width: 200px;
}
.photo p, .photo i {display: block;
}
.photo p {font-weight: bold;
}
/* preview styles */
#photo_preview {background-color: rgba(0, 0, 0, 0.7);bottom: 0;color: #000000;display: none;left: 0;overflow: hidden;position: fixed;right: 0;top: 0;z-index: 10;
}
.photo_wrp {background-color: #FAFAFA;height: auto;margin: 100px auto 0;overflow: hidden;padding: 15px;text-align: center;vertical-align: middle;width: 1000px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.close {cursor: pointer;float: right;
}
.pleft {float: left;overflow: hidden;position: relative;width: 600px;
}
.pright {float: right;position: relative;width: 360px;
}
.preview_prev, .preview_next {cursor: pointer;margin-top: -64px;opacity: 0.5;position: absolute;top: 50%;-moz-transition: opacity 0.2s ease 0s;-ms-transition: opacity 0.2s ease 0s;-o-transition: opacity 0.2s ease 0s;-webkit-transition: opacity 0.2s ease 0s;transition: opacity 0.2s ease 0s;
}
.preview_prev:hover, .preview_next:hover {opacity: 1;
}
.preview_prev {left: 20px;
}
.preview_next {right: 40px;
}
/* comments styles */
#comments form {margin: 10px 0;text-align: left;
}
#comments table td.label {color: #000;font-size: 13px;padding-right: 3px;text-align: right;width: 105px;
}
#comments table label {color: #000;font-size: 16px;font-weight: normal;vertical-align: middle;
}
#comments table td.field input, #comments table td.field textarea {border: 1px solid #96A6C5;font-family: Verdana,Arial,sans-serif;font-size: 16px;margin-top: 2px;padding: 6px;width: 250px;
}
#comments_list {margin: 10px 0;text-align: left;
}
#comments_list .comment {border-top: 1px solid #000;padding: 10px 0;
}
#comments_list .comment:first-child {border-top-width:0px;
}
#comments_list .comment span {font-size: 11px;
}
And again, we have just prepared our next practically useful tutorial. Sure that this material will useful for your own projects. Good luck in your work!
同样&#xff0c;我们刚刚准备了下一个实用的教程。 确保该材料将对您自己的项目有用。 祝您工作顺利&#xff01;
翻译自: https://www.script-tutorials.com/facebook-like-photo-gallery-with-comments/
facebook有哪些信息