SHARE
TWEET

PostData.php

a guest Feb 5th, 2019 72 in 68 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: turgutsaricam
  5.  * Date: 25/08/16
  6.  * Time: 11:33
  7.  */
  8.  
  9. namespace WPCCrawler\Objects\Crawling\Data;
  10.  
  11.  
  12. use WPCCrawler\Interfaces\Translatable;
  13. use WPCCrawler\Objects\File\MediaFile;
  14. use WPCCrawler\Utils;
  15.  
  16. class PostData implements Translatable {
  17.  
  18.     /**
  19.      * @var null|array An array of names of the post categories. Each item is a string or array. If the item is a
  20.      *                 string, then it is one of the main categories of the post. If it is an array, it represents
  21.      *                 a category hierarchy. Each previous category name in the array is the parent category name of the
  22.      *                 item. E.g. ['cat1', 'cat2', 'cat3'] represents 'cat1 > cat2 > cat3' hierarchy.
  23.      */
  24.     private $categoryNames;
  25.  
  26.     /** @var bool */
  27.     private $paginate;
  28.  
  29.     /** @var string */
  30.     private $nextPageUrl;
  31.  
  32.     /** @var array */
  33.     private $allPageUrls;
  34.  
  35.     /*
  36.      *
  37.      */
  38.  
  39.     /** @var string */
  40.     private $title;
  41.  
  42.     /** @var array */
  43.     private $excerpt;
  44.  
  45.     /** @var array */
  46.     private $contents;
  47.  
  48.     /** @var string */
  49.     private $dateCreated;
  50.  
  51.     /** @var array */
  52.     private $shortCodeData;
  53.  
  54.     /** @var array */
  55.     private $tags;
  56.  
  57.     /** @var array */
  58.     private $preparedTags;
  59.  
  60.     /** @var string */
  61.     private $slug;
  62.  
  63.     /*
  64.      * LIST
  65.      */
  66.  
  67.     /** @var int */
  68.     private $listStartPos;
  69.  
  70.     /** @var array */
  71.     private $listNumbers;
  72.  
  73.     /** @var array */
  74.     private $listTitles;
  75.  
  76.     /** @var array */
  77.     private $listContents;
  78.  
  79.     /*
  80.      * META
  81.      */
  82.  
  83.     /** @var string */
  84.     private $metaKeywords;
  85.  
  86.     /** @var array */
  87.     private $metaKeywordsAsTags;
  88.  
  89.     /** @var string */
  90.     private $metaDescription;
  91.  
  92.     /*
  93.      *
  94.      */
  95.  
  96.     /** @var null|MediaFile */
  97.     private $thumbnailData;
  98.  
  99.     /** @var MediaFile[] */
  100.     private $attachmentData = [];
  101.  
  102.     /*
  103.      *
  104.      */
  105.  
  106.     /** @var array */
  107.     private $customMeta;
  108.  
  109.     /** @var array */
  110.     private $customTaxonomies;
  111.  
  112.     /** @var string */
  113.     private $template;
  114.  
  115.     /*
  116.      *
  117.      */
  118.  
  119.     /** @var array WordPress post data */
  120.     private $wpPostData = [];
  121.  
  122.     /*
  123.      * GETTERS AND SETTERS
  124.      */
  125.  
  126.     /**
  127.      * @return array|null See {@link $categoryNames}
  128.      */
  129.     public function getCategoryNames() {
  130.         return $this->categoryNames;
  131.     }
  132.  
  133.     /**
  134.      * @param array|null $categoryNames
  135.      */
  136.     public function setCategoryNames($categoryNames) {
  137.         $this->categoryNames = $categoryNames;
  138.     }
  139.  
  140.     /**
  141.      * @return boolean
  142.      */
  143.     public function isPaginate() {
  144.         return $this->paginate;
  145.     }
  146.  
  147.     /**
  148.      * @param boolean $paginate
  149.      */
  150.     public function setPaginate($paginate) {
  151.         $this->paginate = $paginate;
  152.     }
  153.  
  154.     /**
  155.      * @return string
  156.      */
  157.     public function getNextPageUrl() {
  158.         return $this->nextPageUrl;
  159.     }
  160.  
  161.     /**
  162.      * @param string $nextPageUrl
  163.      */
  164.     public function setNextPageUrl($nextPageUrl) {
  165.         $this->nextPageUrl = $nextPageUrl;
  166.     }
  167.  
  168.     /**
  169.      * @return array
  170.      */
  171.     public function getAllPageUrls() {
  172.         return $this->allPageUrls;
  173.     }
  174.  
  175.     /**
  176.      * @param array $allPageUrls
  177.      */
  178.     public function setAllPageUrls($allPageUrls) {
  179.         $this->allPageUrls = $allPageUrls;
  180.     }
  181.  
  182.     /**
  183.      * @return string
  184.      */
  185.     public function getTitle() {
  186.         return $this->title;
  187.     }
  188.  
  189.     /**
  190.      * @param string $title
  191.      */
  192.     public function setTitle($title) {
  193.         $this->title = $title;
  194.     }
  195.  
  196.     /**
  197.      * @return array
  198.      */
  199.     public function getExcerpt() {
  200.         return $this->excerpt;
  201.     }
  202.  
  203.     /**
  204.      * @param array $excerpt
  205.      */
  206.     public function setExcerpt($excerpt) {
  207.         $this->excerpt = $excerpt;
  208.     }
  209.  
  210.     /**
  211.      * @return array
  212.      */
  213.     public function getContents() {
  214.         return $this->contents;
  215.     }
  216.  
  217.     /**
  218.      * @param array $contents
  219.      */
  220.     public function setContents($contents) {
  221.         $this->contents = $contents;
  222.     }
  223.  
  224.     /**
  225.      * @return string
  226.      */
  227.     public function getDateCreated() {
  228.         return $this->dateCreated;
  229.     }
  230.  
  231.     /**
  232.      * @param string $dateCreated
  233.      */
  234.     public function setDateCreated($dateCreated) {
  235.         $this->dateCreated = $dateCreated;
  236.     }
  237.  
  238.     /**
  239.      * @return array
  240.      */
  241.     public function getShortCodeData() {
  242.         return $this->shortCodeData;
  243.     }
  244.  
  245.     /**
  246.      * @param array $shortCodeData
  247.      */
  248.     public function setShortCodeData($shortCodeData) {
  249.         $this->shortCodeData = $shortCodeData;
  250.     }
  251.  
  252.     /**
  253.      * @return array
  254.      */
  255.     public function getTags() {
  256.         return $this->tags;
  257.     }
  258.  
  259.     /**
  260.      * @param array $tags
  261.      */
  262.     public function setTags($tags) {
  263.         $this->tags = $tags;
  264.     }
  265.  
  266.     /**
  267.      * @return array
  268.      */
  269.     public function getPreparedTags() {
  270.         return $this->preparedTags;
  271.     }
  272.  
  273.     /**
  274.      * @param array $preparedTags
  275.      */
  276.     public function setPreparedTags($preparedTags) {
  277.         $this->preparedTags = $preparedTags;
  278.     }
  279.  
  280.     /**
  281.      * @return string
  282.      */
  283.     public function getSlug() {
  284.         return $this->slug;
  285.     }
  286.  
  287.     /**
  288.      * @param string $slug
  289.      */
  290.     public function setSlug($slug) {
  291.         $this->slug = $slug;
  292.     }
  293.  
  294.     /**
  295.      * @return int
  296.      */
  297.     public function getListStartPos() {
  298.         return $this->listStartPos;
  299.     }
  300.  
  301.     /**
  302.      * @param int $listStartPos
  303.      */
  304.     public function setListStartPos($listStartPos) {
  305.         $this->listStartPos = $listStartPos;
  306.     }
  307.  
  308.     /**
  309.      * @return array
  310.      */
  311.     public function getListNumbers() {
  312.         return $this->listNumbers;
  313.     }
  314.  
  315.     /**
  316.      * @param array $listNumbers
  317.      */
  318.     public function setListNumbers($listNumbers) {
  319.         $this->listNumbers = $listNumbers;
  320.     }
  321.  
  322.     /**
  323.      * @return array
  324.      */
  325.     public function getListTitles() {
  326.         return $this->listTitles;
  327.     }
  328.  
  329.     /**
  330.      * @param array $listTitles
  331.      */
  332.     public function setListTitles($listTitles) {
  333.         $this->listTitles = $listTitles;
  334.     }
  335.  
  336.     /**
  337.      * @return array
  338.      */
  339.     public function getListContents() {
  340.         return $this->listContents;
  341.     }
  342.  
  343.     /**
  344.      * @param array $listContents
  345.      */
  346.     public function setListContents($listContents) {
  347.         $this->listContents = $listContents;
  348.     }
  349.  
  350.     /**
  351.      * @return string
  352.      */
  353.     public function getMetaKeywords() {
  354.         return $this->metaKeywords;
  355.     }
  356.  
  357.     /**
  358.      * @param string $metaKeywords
  359.      */
  360.     public function setMetaKeywords($metaKeywords) {
  361.         $this->metaKeywords = $metaKeywords;
  362.     }
  363.  
  364.     /**
  365.      * @return array
  366.      */
  367.     public function getMetaKeywordsAsTags() {
  368.         return $this->metaKeywordsAsTags;
  369.     }
  370.  
  371.     /**
  372.      * @param array $metaKeywordsAsTags
  373.      */
  374.     public function setMetaKeywordsAsTags($metaKeywordsAsTags) {
  375.         $this->metaKeywordsAsTags = $metaKeywordsAsTags;
  376.     }
  377.  
  378.     /**
  379.      * @return string
  380.      */
  381.     public function getMetaDescription() {
  382.         return $this->metaDescription;
  383.     }
  384.  
  385.     /**
  386.      * @param string $metaDescription
  387.      */
  388.     public function setMetaDescription($metaDescription) {
  389.         $this->metaDescription = $metaDescription;
  390.     }
  391.  
  392.     /**
  393.      * @return MediaFile|null
  394.      */
  395.     public function getThumbnailData() {
  396.         return $this->thumbnailData;
  397.     }
  398.  
  399.     /**
  400.      * @param MediaFile $mediaFile
  401.      */
  402.     public function setThumbnailData($mediaFile) {
  403.         $this->thumbnailData = $mediaFile;
  404.     }
  405.  
  406.     /**
  407.      * @return MediaFile[]
  408.      */
  409.     public function getAttachmentData() {
  410.         return $this->attachmentData;
  411.     }
  412.  
  413.     /**
  414.      * @param MediaFile[] $attachmentData
  415.      */
  416.     public function setAttachmentData($attachmentData) {
  417.         $this->attachmentData = $attachmentData ?: [];
  418.     }
  419.  
  420.     /**
  421.      * Deletes previously saved attachments.
  422.      */
  423.     public function deleteAttachments() {
  424.         if(!$this->getAttachmentData()) return;
  425.  
  426.         foreach($this->getAttachmentData() as $mediaFile) {
  427.             Utils::deleteFile($mediaFile->getLocalPath());
  428.  
  429.             // If the media file has an ID, delete the attachment with that ID.
  430.             if ($mediaFile->getMediaId()) {
  431.                 wp_delete_attachment($mediaFile->getMediaId(), true);
  432.             }
  433.         }
  434.     }
  435.  
  436.     /**
  437.      * @return array
  438.      */
  439.     public function getCustomMeta() {
  440.         return $this->customMeta;
  441.     }
  442.  
  443.     /**
  444.      * @param array $customMeta
  445.      */
  446.     public function setCustomMeta($customMeta) {
  447.         $this->customMeta = $customMeta;
  448.     }
  449.  
  450.     /**
  451.      * @return array
  452.      */
  453.     public function getCustomTaxonomies() {
  454.         return $this->customTaxonomies;
  455.     }
  456.  
  457.     /**
  458.      * @param array $customTaxonomies
  459.      */
  460.     public function setCustomTaxonomies($customTaxonomies) {
  461.         $this->customTaxonomies = $customTaxonomies;
  462.     }
  463.  
  464.     /**
  465.      * @return string
  466.      */
  467.     public function getTemplate() {
  468.         return $this->template;
  469.     }
  470.  
  471.     /**
  472.      * @param string $template
  473.      */
  474.     public function setTemplate($template) {
  475.         $this->template = $template;
  476.     }
  477.  
  478.     /**
  479.      * @return array
  480.      */
  481.     public function getWpPostData() {
  482.         return $this->wpPostData;
  483.     }
  484.  
  485.     /**
  486.      * @param array $wpPostData
  487.      */
  488.     public function setWpPostData($wpPostData) {
  489.         $this->wpPostData = $wpPostData;
  490.     }
  491.  
  492.     /**
  493.      * Get all media files, which contain attachment media files and the thumbnail media file.
  494.      *
  495.      * @return MediaFile[]
  496.      * @since 1.8.0
  497.      */
  498.     public function getAllMediaFiles() {
  499.         $mediaFiles = $this->getAttachmentData();
  500.         if ($this->getThumbnailData()) $mediaFiles[] = $this->getThumbnailData();
  501.         return $mediaFiles;
  502.     }
  503.  
  504.     /**
  505.      * NOTE: Translate more wisely. For example, instead of translating listNumbers, listTitles, etc., just translate
  506.      * the final post template. By this way, the number of chars to be translated will be less, hence, less money will
  507.      * be spent for the translation service.
  508.      *
  509.      * NOTE: The fields must have mutator and accessor methods. In other words, if there is "title", then there must be
  510.      * setTitle and getTitle methods so that "title" can be translated.
  511.      *
  512.      * @return array Stores the names of the fields that can be translated. The values indicate the translatable keys of
  513.      *      the fields. E.g. if the value of "attachmentData" field has a an array value, whose each item
  514.      *      has translatable values in "title" and "alt" keys, ["attachmentData" => ["title", "alt"]] indicates this.
  515.      *      Make sure the value is defined for a translatable field. If you do not specify a value, the field won't be
  516.      *      considered as translatable. So, ["title"] is not translatable, while ["title" => ""] is translatable. An
  517.      *      empty value means the value of the field is entirely translatable. Objects are translatable as well. In
  518.      *      case of objects, set the field names that have setter and getter methods. E.g. if "attachmentData" stores
  519.      *      an array of MediaFile instances, and each media file has a mediaTitle field and setMediaTitle and
  520.      *      getMediaTitle methods, then ["attachmentData" => ["mediaTitle"]] indicates this.
  521.      * @since 1.8.0
  522.      */
  523.     public function getTranslatableFields() {
  524.         return [
  525.             "title"                 => "",
  526.             "excerpt"               => "data",
  527.             'categoryNames'         => "",
  528.             "slug"                  => "",
  529.             "template"              => "",
  530.             "preparedTags"          => "",
  531.             "metaKeywords"          => "",
  532.             "metaDescription"       => "",
  533.             "customMeta"            => "data",
  534.             "attachmentData"        => ["mediaTitle", "mediaDescription", "mediaCaption", "mediaAlt"],
  535.             "thumbnailData"         => ["mediaTitle", "mediaDescription", "mediaCaption", "mediaAlt"],
  536.             "customTaxonomies"      => "data",
  537.         ];
  538.     }
  539. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top