Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.22 KB | None | 0 0
  1. From 1ab56685ccd027103b868282282f23306052d871 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Patricio=20P=C3=A9rez?= <janitux@boaboa.org>
  3. Date: Fri, 20 Aug 2010 19:03:22 -0400
  4. Subject: [PATCH] * Designer profiles
  5.  
  6. ---
  7. server/lib/user.php | 90 ++++++++++++++++++++++++++++--
  8. server/profile.php | 26 ++++++++-
  9. server/templates/change_user_details.php | 29 ++++++++-
  10. server/templates/gallery.php | 54 +++++++++++++++++-
  11. static/css/style.css | 66 +++++++++++++++++++++-
  12. 5 files changed, 250 insertions(+), 15 deletions(-)
  13. mode change 100644 => 100755 server/lib/user.php
  14. mode change 100644 => 100755 server/templates/change_user_details.php
  15. mode change 100644 => 100755 server/templates/gallery.php
  16. mode change 100644 => 100755 static/css/style.css
  17.  
  18. diff --git a/server/lib/user.php b/server/lib/user.php
  19. old mode 100644
  20. new mode 100755
  21. index 064b4ea..efa1df3
  22. --- a/server/lib/user.php
  23. +++ b/server/lib/user.php
  24. @@ -68,6 +68,9 @@ class PersonaUser
  25. var $_privs = 0;
  26. var $_errors = array();
  27. var $_no_signup = 0;
  28. + var $_location = null;
  29. + var $_homepage = null;
  30. + var $_public_mail = 0;
  31.  
  32. function __construct($username = null, $password = null, $hostname = null, $dbname = null)
  33. {
  34. @@ -161,7 +164,7 @@ class PersonaUser
  35.  
  36. try
  37. {
  38. - $select_stmt = 'select username, display_username, email, privs, description from users where username = :username';
  39. + $select_stmt = 'select username, display_username, email, privs, description, location, homepage, public_mail from users where username = :username';
  40. $sth = $this->_dbh->prepare($select_stmt);
  41. $sth->bindParam(':username', $username);
  42. $sth->execute();
  43. @@ -245,6 +248,63 @@ class PersonaUser
  44. }
  45.  
  46. #####
  47. +# Get the users public email preference. If called without a username, uses the record of the authed user.
  48. +
  49. + function get_public_email($username = null)
  50. + {
  51. + if(!$username)
  52. + return $this->_public_mail;
  53. +
  54. + $data = $this->get_user_data($username);
  55. + return $data['public_mail'];
  56. + }
  57. +
  58. +#####
  59. +# Get the users location. If called without a username, uses the record of the authed user.
  60. +
  61. + function get_location($username = null)
  62. + {
  63. + if(!$username)
  64. + return $this->_location;
  65. +
  66. + $data = $this->get_user_data($username);
  67. + return $data['location'];
  68. + }
  69. +
  70. +#####
  71. +# Get the users homepage. If called without a username, uses the record of the authed user.
  72. +
  73. + function get_homepage($username = null)
  74. + {
  75. + if(!$username)
  76. + return $this->_homepage;
  77. +
  78. + $data = $this->get_user_data($username);
  79. + return $data['homepage'];
  80. + }
  81. +
  82. +#####
  83. +# Get the users picture. If the user doesn't have a picture, default_picture is shown
  84. +
  85. + function get_picture($username)
  86. + {
  87. + $user_picture = PERSONAS_STORAGE_PREFIX . "/user_pictures/" . $username . ".png";
  88. + if(!(file_exists($user_picture) && is_file($user_picture)))
  89. + return STATIC_BASE_URL.PERSONAS_LIVE_PREFIX . "/user_pictures/" . "default_picture.png";
  90. +
  91. + return STATIC_BASE_URL.PERSONAS_LIVE_PREFIX . "/user_pictures/" . $username . ".png";
  92. + }
  93. +
  94. +#####
  95. +# Resizes and moves the user picture
  96. +
  97. + function resize_picture($avatar_file, $username = null)
  98. + {
  99. + $conv_cmd = "convert " . $avatar_file . " -resize 150x150 " . PERSONAS_STORAGE_PREFIX . "/user_pictures/" . $username . ".png";
  100. + exec($conv_cmd);
  101. + }
  102. +
  103. +#####
  104. # Returns the contents of the error array, if anything has been written to it.
  105.  
  106. function get_errors()
  107. @@ -289,7 +349,7 @@ class PersonaUser
  108. #####
  109. # Adds a user to the database
  110.  
  111. - function create_user($username, $password, $display_username = null, $email = "", $description = "", $news = 0)
  112. + function create_user($username, $password, $display_username = null, $email = "", $description = "", $news = 0, $location = "", $homepage = "", $public_mail = 0)
  113. {
  114. if (!$username)
  115. throw new Exception("No username", 404);
  116. @@ -305,7 +365,7 @@ class PersonaUser
  117.  
  118. try
  119. {
  120. - $insert_stmt = 'insert into users (username, display_username, md5, email, description, news, privs) values (:username, :display_username, :md5, :email, :description, :news, 1)';
  121. + $insert_stmt = 'insert into users (username, display_username, md5, email, description, news, privs, location, homepage, public_mail) values (:username, :display_username, :md5, :email, :description, :news, 1, :location, :homepage, :public_mail)';
  122. $sth = $this->_dbh_master->prepare($insert_stmt);
  123. $sth->bindParam(':username', $username);
  124. $sth->bindParam(':display_username', $display_username);
  125. @@ -313,6 +373,9 @@ class PersonaUser
  126. $sth->bindParam(':email', $email);
  127. $sth->bindParam(':description', $description);
  128. $sth->bindParam(':news', $news);
  129. + $sth->bindParam(':location', $location);
  130. + $sth->bindParam(':homepage', $homepage);
  131. + $sth->bindParam(':public_mail', $public_mail);
  132. $sth->execute();
  133. }
  134. catch( PDOException $exception )
  135. @@ -328,6 +391,9 @@ class PersonaUser
  136. $this->_display_username = $display_username;
  137. $this->_description = $description;
  138. $this->_email = $email;
  139. + $this->_location = $location;
  140. + $this->_homepage = $homepage;
  141. + $this->_public_mail = $public_mail;
  142. $this->_cookie_value = $username . " " . md5($username . md5($password) . PERSONAS_LOGIN_SALT);
  143. setcookie('PERSONA_USER', $this->_cookie_value, time() + 60*60*24*365, '/');
  144.  
  145. @@ -349,7 +415,7 @@ class PersonaUser
  146.  
  147. try
  148. {
  149. - $insert_stmt = 'insert into users (username, display_username, md5, email, description, news, privs) values (:username, :display_username, "", "", "", 0, 0)';
  150. + $insert_stmt = 'insert into users (username, display_username, md5, email, description, news, privs, location, homepage, public_mail) values (:username, :display_username, "", "", "", 0, 0, "", "", 0)';
  151. $sth = $this->_dbh_master->prepare($insert_stmt);
  152. $sth->bindParam(':username', $username);
  153. $sth->bindParam(':display_username', $username);
  154. @@ -367,7 +433,7 @@ class PersonaUser
  155. #####
  156. # Updates a user record
  157.  
  158. - function update_user($username, $display_username = null, $email = "", $description = "", $news = 0)
  159. + function update_user($username, $display_username = null, $email = "", $description = "", $news = 0, $location = "", $homepage = "", $public_mail = 0)
  160. {
  161. if (!$username)
  162. throw new Exception("No username", 404);
  163. @@ -380,13 +446,16 @@ class PersonaUser
  164.  
  165. try
  166. {
  167. - $insert_stmt = 'update users set display_username = :display_username, email = :email, description = :description, news = :news where username = :username';
  168. + $insert_stmt = 'update users set display_username = :display_username, email = :email, description = :description, news = :news, location = :location, homepage = :homepage, public_mail = :public_mail where username = :username';
  169. $sth = $this->_dbh_master->prepare($insert_stmt);
  170. $sth->bindParam(':username', $username);
  171. $sth->bindParam(':display_username', $display_username);
  172. $sth->bindParam(':email', $email);
  173. $sth->bindParam(':description', $description);
  174. $sth->bindParam(':news', $news);
  175. + $sth->bindParam(':location', $location);
  176. + $sth->bindParam(':homepage', $homepage);
  177. + $sth->bindParam(':public_mail', $public_mail);
  178. $sth->execute();
  179. }
  180. catch( PDOException $exception )
  181. @@ -400,6 +469,9 @@ class PersonaUser
  182. $this->_email = $email;
  183. $this->_display_username = $display_username;
  184. $this->_description = $description;
  185. + $this->_location = $location;
  186. + $this->_homepage = $homepage;
  187. + $this->_public_mail = $public_mail;
  188.  
  189. if ($this->_memcache)
  190. $this->_memcache->delete('user:' . $username);
  191. @@ -532,6 +604,9 @@ class PersonaUser
  192. $this->_email = $result['email'];
  193. $this->_description = $result['description'];
  194. $this->_news = $result['news'];
  195. + $this->_location = $result['location'];
  196. + $this->_homepage = $result['homepage'];
  197. + $this->_public_mail = $result['public_mail'];
  198. return 1;
  199. }
  200. return 0;
  201. @@ -579,6 +654,9 @@ class PersonaUser
  202. $this->_email = $result['email'];
  203. $this->_description = $result['description'];
  204. $this->_news = $result['news'];
  205. + $this->_location = $result['location'];
  206. + $this->_homepage = $result['homepage'];
  207. + $this->_public_mail = $result['public_mail'];
  208. return 1;
  209. }
  210. return 0;
  211. diff --git a/server/profile.php b/server/profile.php
  212. index 32465dc..7d1791f 100755
  213. --- a/server/profile.php
  214. +++ b/server/profile.php
  215. @@ -24,10 +24,16 @@
  216. $create['description'] = array_key_exists('create_description', $_POST) ? (ini_get('magic_quotes_gpc') ? stripslashes($_POST['create_description']) : $_POST['create_description']) : null;
  217. $create['news'] = array_key_exists('news', $_POST);
  218. $create['display_username'] = trim($create['display_username']);
  219. + $create['location'] = array_key_exists('create_location', $_POST) ? (ini_get('magic_quotes_gpc') ? stripslashes($_POST['create_location']) : $_POST['create_location']) : null;
  220. + $create['homepage'] = array_key_exists('create_homepage', $_POST) ? (ini_get('magic_quotes_gpc') ? stripslashes($_POST['create_homepage']) : $_POST['create_homepage']) : null;
  221. + $create['public_mail'] = array_key_exists('public_mail', $_POST);
  222. + $create['picture'] = array_key_exists('picture', $_FILES);
  223.  
  224. $create['display_username'] = htmlspecialchars($create['display_username']);
  225. $create['description'] = htmlspecialchars($create['description']);
  226. $create['email'] = htmlspecialchars($create['email']);
  227. + $create['location'] = htmlspecialchars($create['location']);
  228. + $create['homepage'] = htmlspecialchars($create['homepage']);
  229.  
  230. if (!preg_match('/^[A-Z0-9\._%+-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}$/i', $create['email']))
  231. $_errors['create_email'] = _("Invalid email address");
  232. @@ -38,9 +44,24 @@
  233. if (strlen($create['description']) > 256)
  234. $_errors['create_description'] = _("Please limit your description to 256 characters or less");
  235.  
  236. - if (count($_errors) == 0 && $user->update_user($user->get_username(), $create['display_username'], $create['email'], $create['description'], $create['news']))
  237. + if (strlen($create['location']) > 32)
  238. + $_errors['create_location'] = _("Please limit your location to 32 characters or less");
  239. +
  240. + if (strlen($create['homepage']) > 32)
  241. + $_errors['create_homepage'] = _("Please limit your homepage to 32 characters or less");
  242. +
  243. + if ($_FILES['picture']['size'] > 307200)
  244. + $_errors['create_picture'] = _("Please limit your profile picture file size to 300K");
  245. +
  246. + $img_identify_cmd = "identify -format \"%m\" ";
  247. + $picture_ftype = exec($img_identify_cmd . $_FILES['picture']['tmp_name']);
  248. + if (!($picture_ftype == 'JPEG' || $picture_ftype == 'PNG'))
  249. + $_errors['create_picture'] = sprintf(/*L10N: %s is an email address*/_("We do not recognize the format of your profile picture. Please let us know at %s if you think this is in error."), 'persona-devel@mozilla.com');
  250. +
  251. + if (count($_errors) == 0 && $user->update_user($user->get_username(), $create['display_username'], $create['email'], $create['description'], $create['news'], $create['location'], $create['homepage'], $create['public_mail']))
  252. {
  253. $db->update_display_username($user->get_username(), $create['display_username']);
  254. + $user->resize_picture($_FILES['picture']['tmp_name'], $user->get_username());
  255. $updated = 1;
  256. }
  257. }
  258. @@ -50,6 +71,9 @@
  259. $create['display_username'] = $user->_display_username;
  260. $create['description'] = $user->_description;
  261. $create['news'] = $user->_news;
  262. + $create['location'] = $user->_location;
  263. + $create['homepage'] = $user->_homepage;
  264. + $create['public_mail'] = $user->_public_mail;
  265. }
  266.  
  267. $title = _("Change User Details");
  268. diff --git a/server/templates/change_user_details.php b/server/templates/change_user_details.php
  269. old mode 100644
  270. new mode 100755
  271. index 22ad46b..97dbaa6
  272. --- a/server/templates/change_user_details.php
  273. +++ b/server/templates/change_user_details.php
  274. @@ -1,6 +1,6 @@
  275. <div id="signup">
  276. <h4><?= _("Change User Details");?></h3>
  277. - <form action="profile" method="post">
  278. + <form action="profile" method="post" enctype="multipart/form-data">
  279. <input type="hidden" name="update" value="1">
  280. <p><label for="username"><?=_("Login Name:");?> <?= $user->get_username() ?></label>
  281.  
  282. @@ -11,19 +11,40 @@
  283. <?php if (array_key_exists('create_email', $_errors)) echo '<span class="error-message">' . $_errors['create_email'] . '</span>' ?>
  284. </p>
  285.  
  286. - <p><label for="username"><?= _("Display Username");?>*</label>
  287. + <p><label for="username"><?= _("Display Username (optional)");?></label>
  288. <input type="text" name="create_display_username" value="<?= $create['display_username'] ?>" id="" <?php if (array_key_exists('create_display_username', $_errors)) echo 'class="error"' ?>/>
  289. <?php if (array_key_exists('create_display_username', $_errors)) echo '<span class="error-message">' . $_errors['create_display_username'] . '</span>' ?>
  290. </p>
  291.  
  292. <p>
  293. - <label for="description"><?=_("User Description");?>*</label>
  294. + <label for="description"><?=_("Bio (optional)");?></label>
  295. <textarea name="create_description" id="create_description" <?php if (array_key_exists('create_description', $_errors)) echo 'class="error"' ?> ><?= $create['description'] ?></textarea>
  296. <?php if (array_key_exists('create_description', $_errors)) echo '<span class="error-message">' . $_errors['create_description'] . '</span>' ?>
  297. </p>
  298.  
  299. + <p>
  300. + <label for="location"><?= _("Location (optional)");?></label>
  301. + <input type="text" name="create_location" value="<?= $create['location'] ?>" id="" <?php if (array_key_exists('create_location', $_errors)) echo 'class="error"' ?>/>
  302. + <?php if (array_key_exists('create_location', $_errors)) echo '<span class="error-message">' . $_errors['create_location'] . '</span' ?>
  303. + </p>
  304. +
  305. + <p>
  306. + <label for="homepage"><?= _("Homepage (optional)");?></label>
  307. + <input type="text" name="create_homepage" value="<?= $create['homepage'] ?>" id="" <?php if (array_key_exists('create_homepage', $_errors)) echo 'class="error"' ?>/>
  308. + <?php if (array_key_exists('create_homepage', $_errors)) echo '<span class="error-message">' . $_errors['create_homepage'] . '</span' ?>
  309. + </p>
  310. +
  311. + <p>
  312. + <label for="public_mail"><input type="checkbox" name="public_mail" id="public_mail" value="" <?= $create['public_mail'] ? "checked" : "" ?>/> <?=_("Publicly display my email address (optional)");?></label>
  313. + </p>
  314. +
  315. + <p>
  316. + <label for="picture"><?= _("Picture (optional)");?></label>
  317. + <span><input type="file" name="picture" value="" id="picture" <?php if (array_key_exists('create_picture', $_errors)) echo 'class="error"' ?>/></span>
  318. + <?php echo $_errors['create_picture'];?>
  319. + </p>
  320. +
  321. <p class="news"><label for="news"><input type="checkbox" name="news" id="news" value="" <?= $create['news'] ? "checked" : "" ?>/> <?=_("I'd like to receive news and information about Personas");?></label></p>
  322. - <p>* <i><?=_("denotes an optional field. These entries will be displayed in the personas gallery.");?></i></p>
  323. <button type="submit" class="button"><span><?=_("change");?></span><span class="arrow"></span></button>
  324. </form>
  325. </div>
  326. diff --git a/server/templates/gallery.php b/server/templates/gallery.php
  327. old mode 100644
  328. new mode 100755
  329. index 27ba53b..b50adb9
  330. --- a/server/templates/gallery.php
  331. +++ b/server/templates/gallery.php
  332. @@ -6,16 +6,64 @@
  333. <div id="inner-wrapper">
  334. <?php include 'nav.php'; ?>
  335. <?php
  336. - if (!($category == 'Designer' && $header_text = $user->get_description($tab)))
  337. - {
  338. $header_text = _("Your browser, your style! Dress it up with easy-to-use themes for your Firefox.");
  339. - }
  340. ?>
  341. <div id="header">
  342. <h2><?= htmlentities($page_header, ENT_QUOTES, 'UTF-8', false) ?></h2>
  343. <h3><?= $header_text ?></h3>
  344. </div>
  345. <div id="maincontent">
  346. +<?php
  347. + if ($category == 'Designer')
  348. + { ?>
  349. + <div class="featured">
  350. + <div class="featured-inner object-lead">
  351. + <h3><?php printf(/*L10N: %s is the author name*/_("About %s") , $tab); ?></h3>
  352. + <img class="avatar thumbnail" src="<?= $user->get_picture($tab); ?>" alt="">
  353. + <div class="user-info">
  354. + <?php if ($tab == $user->get_unauthed_username()) { ?>
  355. + <p class="edit-profile"><?printf("<a href=\"%s\">" . _("Edit my info") . "</a>", $locale_conf->url('/profile'));?></p>
  356. + <?php } ?>
  357. + <div>
  358. + <table class="designerinfo" summary="Designer Information">
  359. + <tbody>
  360. + <tr>
  361. + <th><?= _("Name");?></th>
  362. + <td><?= $display_username;?></td>
  363. + </tr>
  364. + <?php if($user->get_public_email($tab)) { ?>
  365. + <tr>
  366. + <th><?= _("Email");?></th>
  367. + <td><?printf("<a href=\"mailto://%s\">" .$user->get_email($tab) . "</a>", $user->get_email($tab));?></td>
  368. + </tr>
  369. + <?php } ?>
  370. + <?php if($user->get_location($tab)) { ?>
  371. + <tr>
  372. + <th><?= _("Location");?></th>
  373. + <td><?= $user->get_location($tab);?></td>
  374. + </tr>
  375. + <?php } ?>
  376. + <?php if($user->get_homepage($tab)) {
  377. + $homepage = preg_replace('/(https?\:\/\/[^ ]+[A-Za-z0-9\/])/e', '"<a href=\"".external_link(\'\\1\')."\">\\1</a>"', $user->get_homepage($tab)); ?>
  378. + <tr>
  379. + <th><?= _("Homepage");?></th>
  380. + <td><?= $homepage ?></td>
  381. + </tr>
  382. + <?php } ?>
  383. + <?php if($user->get_description($tab)) { ?>
  384. + <tr>
  385. + <th><?= _("Bio");?></th>
  386. + <td><?= $user->get_description($tab);?>
  387. + </tr>
  388. + <?php } ?>
  389. + </tbody>
  390. + </table>
  391. + </div>
  392. + </div>
  393. + </div>
  394. + </div>
  395. +
  396. +<?php } ?>
  397. <div id="gallery">
  398. <?php
  399.  
  400. diff --git a/static/css/style.css b/static/css/style.css
  401. old mode 100644
  402. new mode 100755
  403. index fc08eb7..39b4392
  404. --- a/static/css/style.css
  405. +++ b/static/css/style.css
  406. @@ -153,7 +153,7 @@ h4.section {
  407. clear: both;
  408. }
  409.  
  410. -#inner-wrapper:after, #nav ul:after, .mini-gallery:after{
  411. +#inner-wrapper:after, #nav ul:after, .mini-gallery:after .featured:after{
  412. content: '.';
  413. display: block;
  414. clear: both;
  415. @@ -2492,3 +2492,67 @@ div#gsfn_list_widget div#gsfn_content li { text-align:left; margin-bottom:6px; m
  416. div#gsfn_list_widget div#gsfn_content a.gsfn_link { line-height: 1; }
  417. div#gsfn_list_widget div#gsfn_content span.time { font-size: 90%; padding-left: 3px; }
  418. div#gsfn_list_widget div#gsfn_content p.gsfn_summary { margin-top: 2px }
  419. +
  420. +.featured {
  421. + -moz-border-radius: 5px 5px 5px 5px;
  422. + background-color: #B5D9E5;
  423. + border: 4px solid #B5D9E5;
  424. + clear: both;
  425. + margin-bottom: 2em;
  426. +}
  427. +
  428. +.object-lead {
  429. + margin: 0;
  430. + padding: 1em;
  431. + position: relative;
  432. +}
  433. +
  434. +.object-lead h3 {
  435. + margin-top: 0;
  436. +}
  437. +
  438. +.object-lead img.avatar {
  439. + border: 3px solid #C8E8F3;
  440. + float: left;
  441. + margin: 0 15px 15px 0;
  442. + margin-right: 1em;
  443. +}
  444. +
  445. +.object-lead .avatar {
  446. + clear: right;
  447. +}
  448. +
  449. +.object-lead .edit-profile {
  450. + font-size: 0.846em;
  451. + padding: 0.3em 1.18em 0.3em 35px;
  452. + position: absolute;
  453. + right: 0;
  454. + top: 1em;
  455. +}
  456. +
  457. +.object-lead table {
  458. + margin-top: 1em;
  459. + width: 100%;
  460. +}
  461. +
  462. +.object-lead table, .object-lead tbody {
  463. + border-bottom: medium none;
  464. + border-top: medium none;
  465. +}
  466. +
  467. +.object-lead table tr th {
  468. + border-bottom: medium none;
  469. + color: #444444;
  470. + background: #FFFFFF;
  471. + font-weight: bold;
  472. +}
  473. +
  474. +.featured-inner {
  475. + -moz-border-radius: 3px 3px 3px 3px;
  476. + background-color: #FFFFFF;
  477. + border: 1px solid #2E5186;
  478. +}
  479. +
  480. +.object-content {
  481. + margin-left: 220px;
  482. +}
  483. --
  484. 1.7.0.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement