| @@ 1525-1574 (lines=50) @@ | ||
| 1522 | * the dir and file as the name implies if image does not exist it will |
|
| 1523 | * return the unknow image if anonymous parameter is true if not it returns an empty array |
|
| 1524 | */ |
|
| 1525 | public static function get_user_picture_path_by_id($id, $type = 'web', $userInfo = []) |
|
| 1526 | { |
|
| 1527 | switch ($type) { |
|
| 1528 | case 'system': // Base: absolute system path. |
|
| 1529 | $base = api_get_path(SYS_CODE_PATH); |
|
| 1530 | break; |
|
| 1531 | case 'web': // Base: absolute web path. |
|
| 1532 | default: |
|
| 1533 | $base = api_get_path(WEB_CODE_PATH); |
|
| 1534 | break; |
|
| 1535 | } |
|
| 1536 | ||
| 1537 | $anonymousPath = array( |
|
| 1538 | 'dir' => $base.'img/', |
|
| 1539 | 'file' => 'unknown.jpg', |
|
| 1540 | 'email' => '' |
|
| 1541 | ); |
|
| 1542 | ||
| 1543 | if (empty($id) || empty($type)) { |
|
| 1544 | return $anonymousPath; |
|
| 1545 | } |
|
| 1546 | ||
| 1547 | $id = intval($id); |
|
| 1548 | if (empty($userInfo)) { |
|
| 1549 | $user_table = Database:: get_main_table(TABLE_MAIN_USER); |
|
| 1550 | $sql = "SELECT email, picture_uri FROM $user_table |
|
| 1551 | WHERE id=".$id; |
|
| 1552 | $res = Database::query($sql); |
|
| 1553 | ||
| 1554 | if (!Database::num_rows($res)) { |
|
| 1555 | return $anonymousPath; |
|
| 1556 | } |
|
| 1557 | $user = Database::fetch_array($res); |
|
| 1558 | if (empty($user['picture_uri'])) { |
|
| 1559 | return $anonymousPath; |
|
| 1560 | } |
|
| 1561 | } else { |
|
| 1562 | $user = $userInfo; |
|
| 1563 | } |
|
| 1564 | ||
| 1565 | $pictureFilename = trim($user['picture_uri']); |
|
| 1566 | ||
| 1567 | $dir = self::getUserPathById($id, $type); |
|
| 1568 | ||
| 1569 | return array( |
|
| 1570 | 'dir' => $dir, |
|
| 1571 | 'file' => $pictureFilename, |
|
| 1572 | 'email' => $user['email'] |
|
| 1573 | ); |
|
| 1574 | } |
|
| 1575 | ||
| 1576 | /** |
|
| 1577 | * *** READ BEFORE REVIEW THIS FUNCTION *** |
|
| @@ 1591-1641 (lines=51) @@ | ||
| 1588 | * the dir and file as the name implies if image does not exist it will |
|
| 1589 | * return the unknow image if anonymous parameter is true if not it returns an empty array |
|
| 1590 | */ |
|
| 1591 | public static function getUserPicturePathById($id, $type = 'web', $userInfo = []) |
|
| 1592 | { |
|
| 1593 | switch ($type) { |
|
| 1594 | case 'system': // Base: absolute system path. |
|
| 1595 | $base = api_get_path(SYS_CODE_PATH); |
|
| 1596 | break; |
|
| 1597 | case 'web': // Base: absolute web path. |
|
| 1598 | default: |
|
| 1599 | $base = api_get_path(WEB_CODE_PATH); |
|
| 1600 | break; |
|
| 1601 | } |
|
| 1602 | ||
| 1603 | $anonymousPath = array( |
|
| 1604 | 'dir' => $base.'img/', |
|
| 1605 | 'file' => 'unknown.jpg', |
|
| 1606 | 'email' => '' |
|
| 1607 | ); |
|
| 1608 | ||
| 1609 | if (empty($id) || empty($type)) { |
|
| 1610 | return $anonymousPath; |
|
| 1611 | } |
|
| 1612 | ||
| 1613 | $id = intval($id); |
|
| 1614 | ||
| 1615 | if (empty($userInfo)) { |
|
| 1616 | $user_table = Database:: get_main_table(TABLE_MAIN_USER); |
|
| 1617 | $sql = "SELECT email, picture_uri FROM $user_table WHERE id=$id"; |
|
| 1618 | $res = Database::query($sql); |
|
| 1619 | ||
| 1620 | if (!Database::num_rows($res)) { |
|
| 1621 | return $anonymousPath; |
|
| 1622 | } |
|
| 1623 | $user = Database::fetch_array($res); |
|
| 1624 | ||
| 1625 | if (empty($user['picture_uri'])) { |
|
| 1626 | return $anonymousPath; |
|
| 1627 | } |
|
| 1628 | } else { |
|
| 1629 | $user = $userInfo; |
|
| 1630 | } |
|
| 1631 | ||
| 1632 | $pictureFilename = trim($user['picture_uri']); |
|
| 1633 | ||
| 1634 | $dir = self::getUserPathById($id, $type); |
|
| 1635 | ||
| 1636 | return array( |
|
| 1637 | 'dir' => $dir, |
|
| 1638 | 'file' => $pictureFilename, |
|
| 1639 | 'email' => $user['email'] |
|
| 1640 | ); |
|
| 1641 | } |
|
| 1642 | ||
| 1643 | /** |
|
| 1644 | * Get user path from user ID (returns an array). |
|