Share.php 940 B

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