private function createEntry()
 {
     $rnd = rand(0, 9999) . '-' . time();
     $entity = new \IdnoPlugins\Text\Entry();
     $entity->setOwner($this->user());
     $entity->title = "The Title {$rnd}";
     $entity->body = 'Unlikely to be present elsewhere in the post template: hamstring baseball duckbill firecracker';
     $entity->save(true);
     return $entity;
 }
Пример #2
0
 function postContent()
 {
     $this->gatekeeper();
     $new = false;
     if (!empty($this->arguments)) {
         $object = \IdnoPlugins\Text\Entry::getByID($this->arguments[0]);
     }
     if (empty($object)) {
         $object = new \IdnoPlugins\Text\Entry();
     }
     if ($object->saveDataFromInput($this)) {
         $this->forward($object->getURL());
     }
 }
Пример #3
0
 function postContent()
 {
     $this->createGatekeeper();
     $new = false;
     if (!empty($this->arguments)) {
         $object = \IdnoPlugins\Text\Entry::getByID($this->arguments[0]);
     }
     if (empty($object)) {
         $object = new \IdnoPlugins\Text\Entry();
     }
     if ($object->saveDataFromInput($this)) {
         (new \Idno\Core\Autosave())->clearContext('entry');
         //$this->forward(\Idno\Core\site()->config()->getURL() . 'content/all/#feed');
         $this->forward($object->getURL());
     }
 }
Пример #4
0
 /**
  * Given the XML source of a WordPress export, imports each post into Known.
  * @param $xml
  */
 static function importWordPressXML($xml)
 {
     // XML will be imported as blog posts, so make sure we can import those ...
     if (!($text = site()->plugins()->get('Text'))) {
         return false;
     }
     if ($data = simplexml_load_string($xml, null, LIBXML_NOCDATA)) {
         $namespaces = $data->getDocNamespaces(false);
         $namespaces[] = null;
         unset($namespace_data);
         unset($xml);
         if (!empty($data->channel->item)) {
             foreach ($data->channel->item as $item_structure) {
                 $item = [];
                 foreach ($namespaces as $ns => $namespace) {
                     if ($properties = (array) $item_structure->children($namespace)) {
                         foreach ($properties as $name => $val) {
                             if (!empty($ns)) {
                                 $name = $ns . ':' . $name;
                             }
                             $item[$name] = $val;
                         }
                     }
                 }
                 if ($item['wp:post_type'] == 'post' && $item['wp:status'] == 'publish') {
                     $title = $item['title'];
                     if (!empty($item['content:encoded'])) {
                         $body = $item['content:encoded'];
                     } else {
                         if (!empty($item['description'])) {
                             $body = $item['description'];
                         } else {
                             $body = '';
                         }
                     }
                     if (!empty($item['wp:post_date'])) {
                         $published = strtotime($item['wp:post_date']);
                     } else {
                         if (!empty($item['pubDate'])) {
                             $published = strtotime($item['pubDate']);
                         } else {
                             $published = time();
                         }
                     }
                     if (!empty($item['category'])) {
                         $tags = [];
                         if (!is_array($item['category'])) {
                             $item['category'] = [$item['category']];
                         }
                         foreach ($item['category'] as $category) {
                             $category = strtolower(trim($category));
                             if ($category != 'general') {
                                 $tags[] = '#' . preg_replace('/\\W+/', '', $category);
                             }
                         }
                         if (!empty($tags)) {
                             $body .= '<p>' . implode(' ', $tags) . '</p>';
                         }
                     }
                     self::importImagesFromBodyHTML($body, parse_url($item['link'], PHP_URL_HOST));
                     $object = new \IdnoPlugins\Text\Entry();
                     $object->setTitle(html_entity_decode($title));
                     $object->created = $published;
                     $object->body = $body;
                     $object->save(true);
                 }
             }
         }
     }
 }