public function manageMessages($entity)
 {
     $requester = new Requester();
     $publisher = new Publisher();
     $entityObject = new Entity();
     $downloader = new FileDownloader();
     $published = new Published();
     $summary = '';
     $title = '';
     $readmoreLabel = '';
     // get author id
     $author = $entity->author_id;
     // The entity is not active
     if (!$entity->activate) {
         return 0;
     }
     // Retrieve the entity categories
     $entityListCategory = [];
     $readmoreLabel = '';
     foreach ($entity->options as $key => $value) {
         if ($value->options_id == 1) {
             $entityListCategory[] = $value->value;
         }
         if ($value->options_id == 2) {
             $entityDisplayType = $value->value;
         }
         if ($value->options_id == 3) {
             $entityPublishType = $value->value;
         }
         if ($value->options_id == 5) {
             $entityImage = $value->value;
         }
         if ($value->options_id == 6) {
             $readmoreLabel = $value->value;
         }
     }
     // Try request to sociallymap on response
     try {
         if ($_ENV['ENVIRONNEMENT'] === 'dev') {
             $requester = new MockRequester();
             $jsonData = $requester->getMessages();
         } else {
             $_POST['entityId'] = esc_html($_POST['entityId']);
             $_POST['token'] = esc_html($_POST['token']);
             $_POST['environment'] = esc_html($_POST['environment']);
             $jsonData = $requester->launch($_POST['entityId'], $_POST['token'], $_POST['environment']);
         }
         if (empty($jsonData)) {
             throw new Exception('No data returned from request', 1);
             exit;
         }
         Logger::messageReceive('See return data', $jsonData);
         foreach ($jsonData as $key => $value) {
             $summary = '';
             $contentArticle = '';
             $readmore = '';
             // Check Link object existing
             if (isset($value->link)) {
                 // Check if Title existing
                 if (!empty($value->link->title)) {
                     $title = $value->link->title;
                 }
                 if (!empty($value->link->summary)) {
                     $summary = $value->link->summary;
                 }
                 // Check if Link URL existing
                 if (!empty($value->link->url)) {
                     $readmoreLabel = stripslashes($readmoreLabel);
                     $readmore = $this->templater->loadReadMore($value->link->url, $entityDisplayType, $entity->id, $readmoreLabel);
                 } else {
                     Logger::alert('This article not contain url');
                 }
             }
             $contentArticle = $summary;
             // add readmore to content if $readmore is not empty
             if ($readmore != '') {
                 $contentArticle .= $readmore;
             }
             $imageTag = '';
             $imageSrc = '';
             // Check if article posted
             $canBePublish = true;
             $messageId = $value->guid;
             if ($published->isPublished($messageId)) {
                 $contextMessageId = '(id message=' . $messageId . ')';
                 Logger::alert('Message of sociallymap existing, so he is not publish', $contextMessageId);
                 $canBePublish = false;
                 continue;
             }
             $pathTempory = plugin_dir_path(__FILE__) . 'tmp/';
             // Check if Media object exist
             if (isset($value->media) && $value->media->type == 'photo') {
                 try {
                     $returnDownload = $downloader->download($value->media->url, $pathTempory);
                     $filename = $returnDownload['filename'];
                     $fileExtension = $returnDownload['extension'];
                     $mediaManager = new MediaWordpressManager();
                     $imageSrc = $mediaManager->integrateMediaToWordpress($filename, $fileExtension);
                 } catch (fileDownloadException $e) {
                     Logger::error('error download' . $e);
                 }
                 // WHEN NO ERROR : FORMAT
                 if (gettype($imageSrc) == 'string') {
                     $imageTag = '<img class="aligncenter" src="' . $imageSrc . '" alt="">';
                 } else {
                     $imageTag = '';
                 }
             } elseif (isset($value->link) && !empty($value->link->thumbnail) && $value->link->thumbnail != ' ') {
                 // Check if Image thumbnail existing
                 try {
                     $returnDownload = $downloader->download($value->link->thumbnail, $pathTempory);
                     $filename = $returnDownload['filename'];
                     $fileExtension = $returnDownload['extension'];
                 } catch (fileDownloadException $e) {
                     Logger::error('error download' . $e);
                 }
                 $mediaManager = new MediaWordpressManager();
                 $imageSrc = $mediaManager->integrateMediaToWordpress($filename, $fileExtension);
                 // Create the img tag
                 if (gettype($imageSrc) == 'string') {
                     $imageTag = '<img class="aligncenter" src="' . $imageSrc . '" alt="">';
                 } else {
                     $imageTag = '';
                 }
             }
             // check if video exist
             $downloadVideo = false;
             if (isset($value->media) && $value->media->type == 'video') {
                 $returnDownload = $downloader->download($value->media->url, $pathTempory);
                 $filename = $returnDownload['filename'];
                 $fileExtension = $returnDownload['extension'];
                 $mediaManager = new MediaWordpressManager();
                 $videoSrc = $mediaManager->integrateMediaToWordpress($filename, $fileExtension);
                 $mediaVideo = '<video class="sm-video-display" controls>
                 <source src="' . $videoSrc . '" type="video/mp4">
                 <div class="sm-video-nosupport"></div>
                 </video>';
                 $contentArticle .= $mediaVideo;
                 Logger::info('download VIDEO', $videoSrc);
             }
             // If imageTag is '' so is false else $isDownload is true
             $isDownloaded = $imageTag !== '';
             // Attach image accordingly to options
             $imageAttachment = '';
             if ($isDownloaded) {
                 // Add image in the post content
                 if (in_array($entityImage, ['content', 'both'])) {
                     $contentArticle = $imageTag . $contentArticle;
                 }
                 // Add image as featured image
                 if (in_array($entityImage, ['thumbnail', 'both'])) {
                     $imageAttachment = $imageSrc;
                 }
             }
             // Publish the post
             $title = $value->content;
             if ($canBePublish == true) {
                 $dataPublish = [$title, $contentArticle, $author, $imageAttachment, $entityListCategory, $entityPublishType];
                 Logger::info('Try publish : ', $dataPublish);
                 $contentArticle = $this->prePosting($contentArticle);
                 $articlePublished = $publisher->publish($title, $contentArticle, $author, $imageAttachment, $entityListCategory, $entityPublishType);
                 if (!$articlePublished) {
                     // throw new Exception('Error from post publish', 1);
                     Logger::error('Error from post publish', [$title]);
                 } else {
                     $entityObject->updateHistoryPublisher($entity->id, $entity->counter);
                     // save published article
                     $published->add($messageId, $entity->id, $articlePublished);
                 }
             }
         }
     } catch (Exception $e) {
         Logger::alert('Error exeption', $e->getMessage());
     }
     return true;
 }
Пример #2
0
<?php

include "publisher.php";
//define hub and feeds
$hub = 'http://pubsubhubbub.appspot.com/';
$feeds = array('http://www.example.com/feed1.xml', 'http://www.example.com/feed2.xml', 'http://www.example.com/feed3.xml');
//create new subscriber
$publisher = new Publisher($hub);
//publish feeds
$response = $publisher->publish($feed);
//print response
var_dump($response);
Пример #3
0
 public function publishpage()
 {
     global $varChecker;
     /**
      *TODO: check user access
      *		canPublish does not actually check, dummy method
      **/
     $page = $this->getPage();
     if ($varChecker->getValue('action') == 'publish') {
         if ($page->published() == 1 || $page->published() == 2) {
             echo json_encode(array('error' => 'alredy_published'));
             return false;
         }
     } else {
         if ($varChecker->getValue('action') == 'expire') {
             if ($page->published() > 2) {
                 echo json_encode(array('error' => 'alredy_expired'));
                 return false;
             }
         } else {
             throw new DataException('invalid_pubaction');
         }
     }
     if ($this->INK_User->canPublish($page)) {
         switch ($page->published()) {
             case 0:
                 //draft
             //draft
             case 2:
                 //waiting publish approval
             //waiting publish approval
             case 4:
                 //withdrawn, set to publish
             //withdrawn, set to publish
             case 5:
                 $status = 1;
                 $msg = 'pub';
                 break;
                 //Expired -- Set all these to published
             //Expired -- Set all these to published
             case 3:
                 //waiting withdraw approval
             //waiting withdraw approval
             case 1:
                 $status = 4;
                 $msg = 'withdrawn';
                 break;
                 //published, set to withdrawn
         }
     } else {
         switch ($page->published()) {
             case 4:
                 //withdrawn
             //withdrawn
             case 5:
                 //expired
             //expired
             case 3:
                 //waiting withdrawn approval
             //waiting withdrawn approval
             case 0:
                 $status = 2;
                 $msg = 'pub_wait';
                 break;
                 //draft --- set all these to waiting publish approval
             //draft --- set all these to waiting publish approval
             case 2:
                 //waiting publish approval
             //waiting publish approval
             case 1:
                 $status = 3;
                 $msg = 'withdrawn_wait';
                 break;
                 //published -- set all these to waithing withdraw approval
         }
     }
     $page->setPublished($status);
     $this->dRep->updatePage($page, 'published', $page->published());
     $page = $this->dRep->getPage($page->getId());
     $publisher = new Publisher($page);
     switch ($status) {
         case 1:
         case 4:
             $publisher->publish();
             break;
     }
     echo json_encode(array('success' => $msg, 'status' => $status, 'oldStatus' => $page->published(true), 'date' => $page->getPublishDate('l j F @ g:ia')));
 }
Пример #4
0
 *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *
 * $Id$
 *
 ******************************************************************************/
include "../interface/EventChannel.php";
include "../interface/Publisher.php";
$subject = "testsubj";
print "generating Famouso EventChannel\n";
$EventChannel = new EventChannel($subject);
print "generating PHP Publisher\n";
$Publisher = new Publisher($EventChannel);
print "sending announcement\n";
if (!$Publisher->announce()) {
    print "announcement failed - exit\n";
    exit;
}
print "start publishing data\n";
for ($i = 0; $i < 10; $i++) {
    sleep(2);
    $Publisher->publish("testdata");
    print $i . " published\n";
}
print "sending unannouncement\n";
$Publisher->unannounce();