diff options
| author | 2014-02-23 21:26:38 +0100 | |
|---|---|---|
| committer | 2014-02-23 21:26:38 +0100 | |
| commit | 86846e7b97acb44a2ea0460d7951f7ef90558afd (patch) | |
| tree | 606a266e2fc8198c2851abf7488c02a2afebf608 /app/Models/Share.php | |
| parent | db120b4ed41584c7e33bfe63015f948e6230f1ab (diff) | |
| parent | 27764b36353b3066a9e92da2a96ac17b546295be (diff) | |
Merge pull request #433 from aledeg/share
Improve sharing
Diffstat (limited to 'app/Models/Share.php')
| -rw-r--r-- | app/Models/Share.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/Models/Share.php b/app/Models/Share.php new file mode 100644 index 000000000..b146db722 --- /dev/null +++ b/app/Models/Share.php @@ -0,0 +1,44 @@ +<?php + +class FreshRSS_Share { + + static public function generateUrl($options, $selected, $link, $title) { + $share = $options[$selected['type']]; + $matches = array( + '~URL~', + '~TITLE~', + '~LINK~', + ); + $replaces = array( + $selected['url'], + self::transformData($title, self::getTransform($share, 'title')), + self::transformData($link, self::getTransform($share, 'link')), + ); + $url = str_replace($matches, $replaces, $share['url']); + return $url; + } + + static private function transformData($data, $transform) { + if (!is_array($transform)) { + return $data; + } + if (count($transform) === 0) { + return $data; + } + foreach ($transform as $action) { + $data = call_user_func($action, $data); + } + return $data; + } + + static private function getTransform($options, $type) { + $transform = $options['transform']; + + if (array_key_exists($type, $transform)) { + return $transform[$type]; + } + + return $transform; + } + +} |
