@@ 1483-1532 (lines=50) @@ | ||
1480 | * the dir and file as the name implies if image does not exist it will |
|
1481 | * return the unknow image if anonymous parameter is true if not it returns an empty array |
|
1482 | */ |
|
1483 | public static function get_user_picture_path_by_id($id, $type = 'web', $userInfo = []) |
|
1484 | { |
|
1485 | switch ($type) { |
|
1486 | case 'system': // Base: absolute system path. |
|
1487 | $base = api_get_path(SYS_CODE_PATH); |
|
1488 | break; |
|
1489 | case 'web': // Base: absolute web path. |
|
1490 | default: |
|
1491 | $base = api_get_path(WEB_CODE_PATH); |
|
1492 | break; |
|
1493 | } |
|
1494 | ||
1495 | $anonymousPath = array( |
|
1496 | 'dir' => $base.'img/', |
|
1497 | 'file' => 'unknown.jpg', |
|
1498 | 'email' => '' |
|
1499 | ); |
|
1500 | ||
1501 | if (empty($id) || empty($type)) { |
|
1502 | return $anonymousPath; |
|
1503 | } |
|
1504 | ||
1505 | $id = intval($id); |
|
1506 | if (empty($userInfo)) { |
|
1507 | $user_table = Database:: get_main_table(TABLE_MAIN_USER); |
|
1508 | $sql = "SELECT email, picture_uri FROM $user_table |
|
1509 | WHERE id=".$id; |
|
1510 | $res = Database::query($sql); |
|
1511 | ||
1512 | if (!Database::num_rows($res)) { |
|
1513 | return $anonymousPath; |
|
1514 | } |
|
1515 | $user = Database::fetch_array($res); |
|
1516 | if (empty($user['picture_uri'])) { |
|
1517 | return $anonymousPath; |
|
1518 | } |
|
1519 | } else { |
|
1520 | $user = $userInfo; |
|
1521 | } |
|
1522 | ||
1523 | $pictureFilename = trim($user['picture_uri']); |
|
1524 | ||
1525 | $dir = self::getUserPathById($id, $type); |
|
1526 | ||
1527 | return array( |
|
1528 | 'dir' => $dir, |
|
1529 | 'file' => $pictureFilename, |
|
1530 | 'email' => $user['email'] |
|
1531 | ); |
|
1532 | } |
|
1533 | ||
1534 | /** |
|
1535 | * *** READ BEFORE REVIEW THIS FUNCTION *** |
|
@@ 1549-1599 (lines=51) @@ | ||
1546 | * the dir and file as the name implies if image does not exist it will |
|
1547 | * return the unknow image if anonymous parameter is true if not it returns an empty array |
|
1548 | */ |
|
1549 | public static function getUserPicturePathById($id, $type = 'web', $userInfo = []) |
|
1550 | { |
|
1551 | switch ($type) { |
|
1552 | case 'system': // Base: absolute system path. |
|
1553 | $base = api_get_path(SYS_CODE_PATH); |
|
1554 | break; |
|
1555 | case 'web': // Base: absolute web path. |
|
1556 | default: |
|
1557 | $base = api_get_path(WEB_CODE_PATH); |
|
1558 | break; |
|
1559 | } |
|
1560 | ||
1561 | $anonymousPath = array( |
|
1562 | 'dir' => $base.'img/', |
|
1563 | 'file' => 'unknown.jpg', |
|
1564 | 'email' => '' |
|
1565 | ); |
|
1566 | ||
1567 | if (empty($id) || empty($type)) { |
|
1568 | return $anonymousPath; |
|
1569 | } |
|
1570 | ||
1571 | $id = intval($id); |
|
1572 | ||
1573 | if (empty($userInfo)) { |
|
1574 | $user_table = Database:: get_main_table(TABLE_MAIN_USER); |
|
1575 | $sql = "SELECT email, picture_uri FROM $user_table WHERE id=$id"; |
|
1576 | $res = Database::query($sql); |
|
1577 | ||
1578 | if (!Database::num_rows($res)) { |
|
1579 | return $anonymousPath; |
|
1580 | } |
|
1581 | $user = Database::fetch_array($res); |
|
1582 | ||
1583 | if (empty($user['picture_uri'])) { |
|
1584 | return $anonymousPath; |
|
1585 | } |
|
1586 | } else { |
|
1587 | $user = $userInfo; |
|
1588 | } |
|
1589 | ||
1590 | $pictureFilename = trim($user['picture_uri']); |
|
1591 | ||
1592 | $dir = self::getUserPathById($id, $type); |
|
1593 | ||
1594 | return array( |
|
1595 | 'dir' => $dir, |
|
1596 | 'file' => $pictureFilename, |
|
1597 | 'email' => $user['email'] |
|
1598 | ); |
|
1599 | } |
|
1600 | ||
1601 | /** |
|
1602 | * Get user path from user ID (returns an array). |