| @@ 1574-1623 (lines=50) @@ | ||
| 1571 | * the dir and file as the name implies if image does not exist it will |
|
| 1572 | * return the unknow image if anonymous parameter is true if not it returns an empty array |
|
| 1573 | */ |
|
| 1574 | public static function get_user_picture_path_by_id($id, $type = 'web', $userInfo = []) |
|
| 1575 | { |
|
| 1576 | switch ($type) { |
|
| 1577 | case 'system': // Base: absolute system path. |
|
| 1578 | $base = api_get_path(SYS_CODE_PATH); |
|
| 1579 | break; |
|
| 1580 | case 'web': // Base: absolute web path. |
|
| 1581 | default: |
|
| 1582 | $base = api_get_path(WEB_CODE_PATH); |
|
| 1583 | break; |
|
| 1584 | } |
|
| 1585 | ||
| 1586 | $anonymousPath = array( |
|
| 1587 | 'dir' => $base.'img/', |
|
| 1588 | 'file' => 'unknown.jpg', |
|
| 1589 | 'email' => '' |
|
| 1590 | ); |
|
| 1591 | ||
| 1592 | if (empty($id) || empty($type)) { |
|
| 1593 | return $anonymousPath; |
|
| 1594 | } |
|
| 1595 | ||
| 1596 | $id = intval($id); |
|
| 1597 | if (empty($userInfo)) { |
|
| 1598 | $user_table = Database::get_main_table(TABLE_MAIN_USER); |
|
| 1599 | $sql = "SELECT email, picture_uri FROM $user_table |
|
| 1600 | WHERE id=".$id; |
|
| 1601 | $res = Database::query($sql); |
|
| 1602 | ||
| 1603 | if (!Database::num_rows($res)) { |
|
| 1604 | return $anonymousPath; |
|
| 1605 | } |
|
| 1606 | $user = Database::fetch_array($res); |
|
| 1607 | if (empty($user['picture_uri'])) { |
|
| 1608 | return $anonymousPath; |
|
| 1609 | } |
|
| 1610 | } else { |
|
| 1611 | $user = $userInfo; |
|
| 1612 | } |
|
| 1613 | ||
| 1614 | $pictureFilename = trim($user['picture_uri']); |
|
| 1615 | ||
| 1616 | $dir = self::getUserPathById($id, $type); |
|
| 1617 | ||
| 1618 | return array( |
|
| 1619 | 'dir' => $dir, |
|
| 1620 | 'file' => $pictureFilename, |
|
| 1621 | 'email' => $user['email'] |
|
| 1622 | ); |
|
| 1623 | } |
|
| 1624 | ||
| 1625 | /** |
|
| 1626 | * *** READ BEFORE REVIEW THIS FUNCTION *** |
|
| @@ 1640-1690 (lines=51) @@ | ||
| 1637 | * the dir and file as the name implies if image does not exist it will |
|
| 1638 | * return the unknown image if anonymous parameter is true if not it returns an empty array |
|
| 1639 | */ |
|
| 1640 | public static function getUserPicturePathById($id, $type = 'web', $userInfo = []) |
|
| 1641 | { |
|
| 1642 | switch ($type) { |
|
| 1643 | case 'system': // Base: absolute system path. |
|
| 1644 | $base = api_get_path(SYS_CODE_PATH); |
|
| 1645 | break; |
|
| 1646 | case 'web': // Base: absolute web path. |
|
| 1647 | default: |
|
| 1648 | $base = api_get_path(WEB_CODE_PATH); |
|
| 1649 | break; |
|
| 1650 | } |
|
| 1651 | ||
| 1652 | $anonymousPath = array( |
|
| 1653 | 'dir' => $base.'img/', |
|
| 1654 | 'file' => 'unknown.jpg', |
|
| 1655 | 'email' => '' |
|
| 1656 | ); |
|
| 1657 | ||
| 1658 | if (empty($id) || empty($type)) { |
|
| 1659 | return $anonymousPath; |
|
| 1660 | } |
|
| 1661 | ||
| 1662 | $id = intval($id); |
|
| 1663 | ||
| 1664 | if (empty($userInfo)) { |
|
| 1665 | $user_table = Database::get_main_table(TABLE_MAIN_USER); |
|
| 1666 | $sql = "SELECT email, picture_uri FROM $user_table WHERE id=$id"; |
|
| 1667 | $res = Database::query($sql); |
|
| 1668 | ||
| 1669 | if (!Database::num_rows($res)) { |
|
| 1670 | return $anonymousPath; |
|
| 1671 | } |
|
| 1672 | $user = Database::fetch_array($res); |
|
| 1673 | ||
| 1674 | if (empty($user['picture_uri'])) { |
|
| 1675 | return $anonymousPath; |
|
| 1676 | } |
|
| 1677 | } else { |
|
| 1678 | $user = $userInfo; |
|
| 1679 | } |
|
| 1680 | ||
| 1681 | $pictureFilename = trim($user['picture_uri']); |
|
| 1682 | ||
| 1683 | $dir = self::getUserPathById($id, $type); |
|
| 1684 | ||
| 1685 | return array( |
|
| 1686 | 'dir' => $dir, |
|
| 1687 | 'file' => $pictureFilename, |
|
| 1688 | 'email' => $user['email'] |
|
| 1689 | ); |
|
| 1690 | } |
|
| 1691 | ||
| 1692 | /** |
|
| 1693 | * Get user path from user ID (returns an array). |
|