Files
FreshRSS/app/Models/Share.php
Alexis Degrugillier e9eca6aff6 Sharing optimization
Change the storage and display of sharings to improve the time needed to generate the page.
Instead of looking for a default value when displaying the sharing links, they are added
during the configuration.
2014-03-08 09:18:06 -05:00

45 lines
940 B
PHP

<?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;
}
}