Share.php 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. class FreshRSS_Share {
  3. static public function generateUrl($options, $selected, $link, $title) {
  4. if (!array_key_exists('url', $selected)) {
  5. $selected['url'] = '';
  6. }
  7. $share = $options[$selected['type']];
  8. $matches = array(
  9. '~URL~',
  10. '~TITLE~',
  11. '~LINK~',
  12. );
  13. $replaces = array(
  14. $selected['url'],
  15. self::transformData($title, self::getTransform($share, 'title')),
  16. self::transformData($link, self::getTransform($share, 'link')),
  17. );
  18. $url = str_replace($matches, $replaces, $share['url']);
  19. return $url;
  20. }
  21. static private function transformData($data, $transform) {
  22. if (!is_array($transform)) {
  23. return $data;
  24. }
  25. if (count($transform) === 0) {
  26. return $data;
  27. }
  28. foreach ($transform as $action) {
  29. $data = call_user_func($action, $data);
  30. }
  31. return $data;
  32. }
  33. static private function getTransform($options, $type) {
  34. $transform = $options['transform'];
  35. if (array_key_exists($type, $transform)) {
  36. return $transform[$type];
  37. }
  38. return $transform;
  39. }
  40. }