| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
|---|
| 3 | # This file is part of dcRevisions, a plugin for Dotclear. |
|---|
| 4 | # |
|---|
| 5 | # Copyright (c) 2010 Tomtom and contributors |
|---|
| 6 | # http://blog.zenstyle.fr/ |
|---|
| 7 | # |
|---|
| 8 | # Licensed under the GPL version 2.0 license. |
|---|
| 9 | # A copy of this license is available in LICENSE file or at |
|---|
| 10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|---|
| 11 | # -- END LICENSE BLOCK ------------------------------------ |
|---|
| 12 | |
|---|
| 13 | class dcRevisionsExtensions |
|---|
| 14 | { |
|---|
| 15 | public static function getDate($rs,$format = null) |
|---|
| 16 | { |
|---|
| 17 | $format === null ? $format = $rs->core->blog->settings->system->date_format : $format; |
|---|
| 18 | |
|---|
| 19 | return dt::dt2str($format,$rs->revision_dt,$rs->revision_tz); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | public static function getTime($rs,$format = null) |
|---|
| 23 | { |
|---|
| 24 | $format === null ? $format = $rs->core->blog->settings->system->time_format : $format; |
|---|
| 25 | |
|---|
| 26 | return dt::dt2str($format,$rs->revision_dt,$rs->revision_tz); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | public static function getAuthorCN($rs) |
|---|
| 30 | { |
|---|
| 31 | return dcUtils::getUserCN($rs->user_id, $rs->user_name, |
|---|
| 32 | $rs->user_firstname, $rs->user_displayname); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | public static function getAuthorLink($rs) |
|---|
| 36 | { |
|---|
| 37 | $res = '%1$s'; |
|---|
| 38 | $url = $rs->user_url; |
|---|
| 39 | if ($url) { |
|---|
| 40 | $res = '<a href="%2$s">%1$s</a>'; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | return sprintf($res,html::escapeHTML($rs->getAuthorCN()),html::escapeHTML($url)); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public static function canPatch($rs) |
|---|
| 47 | { |
|---|
| 48 | # If user is super admin, true |
|---|
| 49 | if ($rs->core->auth->isSuperAdmin()) { |
|---|
| 50 | return true; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | # If user is admin or contentadmin, true |
|---|
| 54 | if ($rs->core->auth->check('contentadmin',$rs->core->blog->id)) { |
|---|
| 55 | return true; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | # No user id in result ? false |
|---|
| 59 | if (!$rs->exists('user_id')) { |
|---|
| 60 | return false; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | # If user is usage and owner of the entrie |
|---|
| 64 | if ($rs->core->auth->check('usage',$rs->core->blog->id) |
|---|
| 65 | && $rs->user_id == $rs->core->auth->userID()) { |
|---|
| 66 | return true; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | return false; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | ?> |
|---|