Opengraph.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Copyright © 2016 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Block\Post\View;
  9. use Magento\Store\Model\ScopeInterface;
  10. /**
  11. * Blog post view opengraph
  12. */
  13. class Opengraph extends \Magefan\Blog\Block\Post\AbstractPost
  14. {
  15. /**
  16. * Retrieve page type
  17. *
  18. * @return string
  19. */
  20. public function getType()
  21. {
  22. return $this->stripTags(
  23. $this->getPost()->getOgType()
  24. );
  25. }
  26. /**
  27. * Retrieve page title
  28. *
  29. * @return string
  30. */
  31. public function getTitle()
  32. {
  33. return $this->stripTags(
  34. $this->getPost()->getOgTitle()
  35. );
  36. }
  37. /**
  38. * Retrieve page short description
  39. *
  40. * @return string
  41. */
  42. public function getDescription()
  43. {
  44. return $this->stripTags(
  45. $this->getPost()->getOgDescription()
  46. );
  47. }
  48. /**
  49. * Retrieve page url
  50. *
  51. * @return string
  52. */
  53. public function getPageUrl()
  54. {
  55. return $this->stripTags(
  56. $this->getPost()->getPostUrl()
  57. );
  58. }
  59. /**
  60. * Retrieve page main image
  61. *
  62. * @return string | null
  63. */
  64. public function getImage()
  65. {
  66. $image = $this->getPost()->getOgImage();
  67. if (!$image) {
  68. $image = $this->getPost()->getFirstImage();
  69. }
  70. if ($image) {
  71. return $this->stripTags($image);
  72. }
  73. }
  74. }