PageRenderTime 66ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/views/admin/data_catcher/applications.view.php

https://github.com/jay3/core
PHP | 81 lines | 66 code | 7 blank | 8 comment | 19 complexity | b038d545f9f5e593fb375f8798a93093 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * NOVIUS OS - Web OS for digital communication
  4. *
  5. * @copyright 2011 Novius
  6. * @license GNU Affero General Public License v3 or (at your option) any later version
  7. * http://www.gnu.org/licenses/agpl-3.0.html
  8. * @link http://www.novius-os.org
  9. */
  10. \Nos\I18n::current_dictionary('nos::common');
  11. if (isset($nuggets[\Nos\DataCatcher::TYPE_IMAGE])) {
  12. $image = \Nos\Media\Model_Media::find($nuggets[\Nos\DataCatcher::TYPE_IMAGE]);
  13. if (empty($image)) {
  14. unset($nuggets[\Nos\DataCatcher::TYPE_IMAGE]);
  15. } else {
  16. $nuggets['media_url'] = \Nos\Tools_Url::encodePath($image->url());
  17. }
  18. }
  19. if (isset($nuggets[\Nos\DataCatcher::TYPE_URL])) {
  20. if (strpos($nuggets[\Nos\DataCatcher::TYPE_URL], '::') !== false) {
  21. list($page_id, $path) = preg_split("/\:\:/", $nuggets[\Nos\DataCatcher::TYPE_URL]);
  22. if (!empty($path)) {
  23. $page = \Nos\Page\Model_Page::find($page_id);
  24. if (empty($page)) {
  25. unset($nuggets[\Nos\DataCatcher::TYPE_URL]);
  26. } else {
  27. $page_path = preg_replace('`'.preg_quote('.html').'$`iUu', '', \Nos\Tools_Url::encodePath($page->url()));
  28. $nuggets['absolute_url'] = rtrim($page_path, '/').'/'.$path;
  29. }
  30. }
  31. } else {
  32. $nuggets['absolute_url'] = $nuggets[\Nos\DataCatcher::TYPE_URL];
  33. }
  34. }
  35. $onDemande = false;
  36. $auto = false;
  37. $one = false;
  38. foreach ($data_catchers as $catcher_name => $data_catcher) {
  39. if (!is_array($data_catcher['required_data'])) {
  40. $data_catcher['required_data'] = array();
  41. }
  42. $compatible = true;
  43. foreach ($data_catcher['required_data'] as $type_data) {
  44. if (empty($nuggets[$type_data])) {
  45. $compatible = false;
  46. break;
  47. }
  48. }
  49. if (!$compatible) {
  50. continue;
  51. }
  52. $one = true;
  53. if (isset($data_catcher['onDemand']) && $data_catcher['onDemand'] && !$onDemande) {
  54. $onDemande = true;
  55. echo '<div>', strtr(__('‘{{item}}’ can be shared with the following applications.'), array('{{item}}' => htmlspecialchars($item->title_item()))) ,'</div>';
  56. echo '<h4>', __('Click to share:') ,'</h4>';
  57. echo '<small>', __('(Don’t worry, you’ll get a preview first)') ,'</small>';
  58. } elseif ((!isset($data_catcher['onDemand']) || !$data_catcher['onDemand']) && !$auto) {
  59. echo '<div>', strtr(__('‘{{item}}’ is automatically shared with the following applications.'), array('{{item}}' => htmlspecialchars($item->title_item()))) ,'</div>';
  60. echo '<h4>', __('No action required, click to customise:') ,'</h4>';
  61. $auto = true;
  62. }
  63. if ($auto) {
  64. $data_catcher['url'] .= '?'.http_build_query(array(
  65. 'model' => $model_name,
  66. 'id' => $model_id,
  67. 'catcher' => $catcher_name,
  68. ), '', '&');
  69. }
  70. echo '<button class="catcher" data-params="', htmlspecialchars(\Format::forge($data_catcher)->to_json()) ,'" data-nuggets="', htmlspecialchars(\Format::forge($nuggets)->to_json()) ,'">', $data_catcher['title'],'</button>';
  71. }
  72. if (!$one) {
  73. echo '<div>', strtr(__('How sad! ‘{{item}}’ cannot be shared with any application yet. Ask your developer to set up content sharing for you.'), array('{{item}}' => htmlspecialchars($item->title_item()))) ,'</div>';
  74. }