diff options
| author | 2014-02-22 16:53:51 -0500 | |
|---|---|---|
| committer | 2014-02-22 17:03:36 -0500 | |
| commit | 27764b36353b3066a9e92da2a96ac17b546295be (patch) | |
| tree | e95e6dada362a45ef8d920fbe954ae1dd9c5b899 /app/Models/Share.php | |
| parent | 7313f9f3a306d16fac78ab587e3055482398ceac (diff) | |
Improve sharing
Previously, the share page can handle only a limited number of shares and only one of each type.
Now the configuration has been change to be more flexible and allows an unlimited number of shares.
The share description is located in an array and the share configuration is stored along with the
user configuration.
Note: I tried to include the specific javascript code in a separate file but I did not succeded to
import it.
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; + } + +} |
