Exemple #1
0
 public function show()
 {
     $aElements = $this->_oPage->getElementsByField($this->_oField);
     if (count($aElements)) {
         $oElement = $aElements[0];
         /* @var $oElement AM_Model_Db_Element */
         $aElementView = array('id' => $oElement->id);
         $aExtraDataItem = array(AM_Model_Db_Element_Data_Html::DATA_KEY_TEMPLATE_TYPE, AM_Model_Db_Element_Data_Html::DATA_KEY_URL);
         foreach ($aExtraDataItem as $sItem) {
             $aElementView[$sItem] = $oElement->getResources()->getDataValue($sItem);
         }
         $aResourceView = $this->_getResourceViewData($oElement);
         $aElementView = array_merge($aElementView, $aResourceView);
     }
     $aFieldView = array();
     if (isset($aElementView)) {
         $aFieldView['element'] = $aElementView;
     }
     if (!isset($aElementView) || !isset($aElementView['fileName'])) {
         $aFieldView['defaultImageUri'] = AM_Tools::getImageUrl(AM_Handler_Thumbnail_Interface::PRESET_FIELD . '-' . $this->_sPageOrientation, 'element', null, null);
     }
     $sExtensions = array_map('strtoupper', AM_Model_Db_Element_Data_Html::getAllowedFileExtensions());
     sort($sExtensions, SORT_STRING);
     $aFieldView['allowedExtensions'] = implode(' / ', $sExtensions);
     $this->_setFieldData($aFieldView);
     parent::show();
 }
 public function show()
 {
     $aElements = $this->_oPage->getElementsByField($this->_oField);
     $aFieldView = array();
     if (count($aElements)) {
         $aElementsView = array();
         foreach ($aElements as $oElement) {
             /* @var $oElement AM_Model_Db_Element */
             $aElementView = array('id' => $oElement->id);
             $mTopArea = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_DragAndDrop::DATA_KEY_TOP_AREA);
             if (false !== $mTopArea) {
                 $aFieldView['topAreaId'] = $oElement->id;
                 $aFieldView[AM_Model_Db_Element_Data_DragAndDrop::DATA_KEY_TOP_AREA] = $mTopArea;
                 continue;
             }
             $sUniq = '?' . strtotime($oElement->updated);
             $sVideo = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_DragAndDrop::DATA_KEY_VIDEO);
             if (false !== $sVideo) {
                 $aElementView[AM_Model_Db_Element_Data_DragAndDrop::DATA_KEY_VIDEO] = $sVideo;
             }
             $sThumbnail = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_DragAndDrop::DATA_KEY_THUMBNAIL);
             if (false !== $sThumbnail) {
                 $sFileExtension = pathinfo($sThumbnail, PATHINFO_EXTENSION);
                 $aElementView['thumbnail'] = $sThumbnail;
                 $aElementView['thumbnailUri'] = AM_Tools::getImageUrl('none', 'element', $oElement->id, AM_Model_Db_Element_Data_DragAndDrop::DATA_KEY_THUMBNAIL . '.' . $sFileExtension) . $sUniq;
             }
             $sThumbnailSelected = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_DragAndDrop::DATA_KEY_THUMBNAIL_SELECTED);
             if (false !== $sThumbnailSelected) {
                 $sFileExtension = pathinfo($sThumbnail, PATHINFO_EXTENSION);
                 $aElementView['thumbnailSelected'] = $sThumbnailSelected;
                 $aElementView['thumbnailSelectedUri'] = AM_Tools::getImageUrl('none', 'element', $oElement->id, AM_Model_Db_Element_Data_DragAndDrop::DATA_KEY_THUMBNAIL_SELECTED . '.' . $sFileExtension) . $sUniq;
             }
             $aResourceView = $this->_getResourceViewData($oElement);
             $aElementView = array_merge($aElementView, $aResourceView);
             $aElementsView[] = $aElementView;
         }
     }
     if (isset($aElementsView)) {
         $aFieldView['elements'] = $aElementsView;
     }
     $aExtensions = array_map('strtoupper', AM_Model_Db_Element_Data_DragAndDrop::getAllowedFileExtensions());
     sort($aExtensions, SORT_STRING);
     $aFieldView['allowedExtensions'] = implode(' / ', $aExtensions);
     $this->_setFieldData($aFieldView);
     parent::show();
 }
Exemple #3
0
 public function show()
 {
     $aElements = $this->_oPage->getElementsByField($this->_oField);
     $aFieldView = array();
     if (count($aElements)) {
         $aElementView = array();
         $oElement = $aElements[0];
         /* @var $oElement AM_Model_Db_Element */
         $sBody = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_Html5::DATA_KEY_HTML5_BODY);
         $aElementView[AM_Model_Db_Element_Data_Html5::DATA_KEY_HTML5_BODY] = $sBody;
         if (!empty($sBody)) {
             /** Select and fill fields, that refers to selected body */
             foreach (AM_Model_Db_Element_Data_Html5::$aFieldList[$sBody] as $sFieldName) {
                 $sFieldValue = $oElement->getResources()->getDataValue($sFieldName);
                 if (AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE == $sFieldName && !empty($sFieldValue)) {
                     $aFileInfo = pathinfo($sFieldValue);
                     $sFileName = $aFileInfo['filename'];
                     $sFileExtension = $aFileInfo['extension'];
                     $aElementView['element']['fileName'] = $sFileName . '.' . $sFileExtension;
                     $aElementView['element']['fileNameShort'] = $this->getHelper('String')->cut($sFileName) . '.' . $sFileExtension;
                     $sResourceFileName = AM_Model_Db_Element_Data_Html5::DATA_KEY_RESOURCE . '.' . $sFileExtension;
                     $aElementView['element']['smallUri'] = AM_Tools::getIconForNonImageFile($sResourceFileName);
                 }
                 $aElementView[$sFieldName] = $sFieldValue;
             }
             $aElementView['element']['id'] = $oElement->id;
         }
     }
     if (isset($aElementView)) {
         $aFieldView = $aElementView;
     }
     $aFieldView['select_body'] = AM_Model_Db_Element_Data_Html5::$aBodyList;
     $aExtensions = array_map('strtoupper', AM_Model_Db_Element_Data_Html5::getAllowedFileExtensions());
     sort($aExtensions, SORT_STRING);
     $aFieldView['allowedExtensions'] = implode(' / ', $aExtensions);
     $aFieldView['defaultImageUri'] = AM_Tools::getImageUrl(AM_Handler_Thumbnail_Interface::PRESET_FIELD . '-' . $this->_sPageOrientation, 'element', null, null);
     $this->_setFieldData($aFieldView);
     parent::show();
 }
 /**
  * Save action
  */
 public function saveAction()
 {
     try {
         $aMessage = array('status' => 0);
         $sKey = trim($this->_getParam('key'));
         $sValue = trim($this->_getParam('value'));
         if (empty($sKey)) {
             throw new AM_Exception('Trying to set value with empty key');
         }
         $oField = AM_Model_Db_Table_Abstract::factory('field')->findOneBy('id', $this->_iFieldId);
         /* @var $oField AM_Model_Db_Field */
         if (is_null($oField)) {
             throw new AM_Exception(sprintf('Field with id "%d" not found.', $this->_iFieldId));
         }
         $oPage = AM_Model_Db_Table_Abstract::factory('page')->findOneBy('id', $this->_iPageId);
         /* @var $oPage AM_Model_Db_Page */
         if (is_null($oPage)) {
             throw new AM_Exception(sprintf('Page with id "%d" not found.', $this->_iPageId));
         }
         $iTopAreaId = intval($this->_getParam('topAreaId'));
         if ($iTopAreaId) {
             $oElement = AM_Model_Db_Table_Abstract::factory('element')->findOneBy(array('id' => $iTopAreaId));
         } else {
             $oElement = $oPage->getElementForField($oField);
         }
         /* @var $oElement AM_Model_Db_Element */
         $oElement->getResources()->addKeyValue($sKey, $sValue);
         $oPage->setUpdated(false);
         $aMessage['defaultImageUri'] = AM_Tools::getImageUrl(AM_Handler_Thumbnail_Interface::PRESET_FIELD . '-' . $oPage->getOrientation(), 'element', null, '');
         $aMessage['status'] = 1;
         $aMessage['value'] = $oElement->getResources()->getDataValue($sKey);
     } catch (Exception $oException) {
         $aMessage["message"] = $this->__("Error. Can't set value! ") . PHP_EOL . $oException->getMessage();
     }
     return $this->getHelper('Json')->sendJson($aMessage, false);
 }
Exemple #5
0
 public function show()
 {
     if (!$this->isSubmitted) {
         if (!$this->controls['preview']->getValue()) {
             $this->controls['preview']->setValue(0);
         }
     }
     if ($this->primaryKeyValue) {
         $oApplication = AM_Model_Db_Table_Abstract::factory('application')->findOneBy('id', $this->primaryKeyValue);
         if ($oApplication->newsstand_cover_image) {
             $sIssueImageUri = AM_Tools::getImageUrl('270-150', AM_Model_Db_Application::PRESET_APPLICATION_IMAGE, $this->primaryKeyValue, $oApplication->newsstand_cover_image, 'png');
             if (!empty($oApplication->updated)) {
                 $sIssueImageUri .= '?' . strtotime($oApplication->updated);
             }
         }
     }
     $aRecord = array('imageUri' => isset($sIssueImageUri) ? $sIssueImageUri : null);
     if (isset($this->view->{$this->getName()})) {
         $aRecord = array_merge($aRecord, $this->view->{$this->getName()});
     }
     $this->view->{$this->getName()} = $aRecord;
     parent::show();
 }
Exemple #6
0
 /**
  * @return void
  */
 public function show()
 {
     $oTermEntities = AM_Model_Db_Table_Abstract::factory('termEntity')->findAllBy(array('entity' => $this->primaryKeyValue, 'entity_type' => 'issue'));
     $sExistingTags = '';
     foreach ($oTermEntities as $oTermEntity) {
         $oTag = AM_Model_Db_Table_Abstract::factory('term')->findOneBy('id', $oTermEntity->term);
         $sExistingTags .= $oTag->title . ', ';
     }
     if (!$this->controls['tags']->getValue()) {
         $this->controls['tags']->setValue($sExistingTags);
     }
     if ($this->primaryKeyValue) {
         $oIssue = AM_Model_Db_Table_Abstract::factory('issue')->findOneBy('id', $this->primaryKeyValue);
         if ($oIssue->image) {
             $sIssueImageUri = AM_Tools::getImageUrl('270-150', AM_Model_Db_Issue::PRESET_ISSUE_IMAGE, $this->primaryKeyValue, $oIssue->image, 'png') . '?' . strtotime($oIssue->updated);
         }
     }
     $aPricingPlans = AM_Model_Db_Issue::getPricingPlans();
     $aRecord = array('appId' => $this->applicationId, 'imageUri' => isset($sIssueImageUri) ? $sIssueImageUri : null, 'pricingPlans' => $aPricingPlans);
     if (isset($this->view->{$this->getName()})) {
         $aRecord = array_merge($aRecord, $this->view->{$this->getName()});
     }
     $this->view->{$this->getName()} = $aRecord;
     parent::show();
 }
 /**
  * Editor toc-delete-summary action
  */
 public function tocDeleteSummaryAction()
 {
     $aMessage = array('status' => 0);
     try {
         $iRevisionId = intval($this->_getParam('rid'));
         $iTocItemId = intval($this->_getParam('id'));
         if (!AM_Model_Db_Table_Abstract::factory('term')->checkAccess($iTocItemId, $this->_aUserInfo)) {
             throw new AM_Controller_Exception_BadRequest('Error. Invalid params were given');
         }
         $oRevision = AM_Model_Db_Table_Abstract::factory('revision')->findOneBy('id', $iRevisionId);
         /* @var $oRevision AM_Model_Db_Revision */
         if (is_null($oRevision)) {
             throw new AM_Controller_Exception_Forbidden('Access denied');
         }
         $oTerm = AM_Model_Db_Table_Abstract::factory('term')->findOneBy('id', $iTocItemId);
         /* @var $oTerm AM_Model_Db_Term */
         if (is_null($oTerm)) {
             throw new AM_Controller_Exception_Forbidden('Access denied');
         }
         AM_Tools::clearContent(AM_Model_Db_Term_Data_Abstract::TYPE, $oTerm->id, 'sumary.*');
         AM_Tools::clearResizerCache(AM_Model_Db_Term_Data_Abstract::TYPE, AM_Model_Db_Term_Data_Abstract::TYPE, $oTerm->id, 'sumary.*');
         $oTerm->thumb_summary = null;
         $oTerm->updated = new Zend_Db_Expr('NOW()');
         $oTerm->save();
         $oRevision->exportRevision();
         $aDefaultImage = array();
         $aDefaultImage['defaultUri'] = AM_Tools::getImageUrl('toc-summary', 'toc', $iTocItemId);
         $aMessage['file'] = $aDefaultImage;
         $aMessage['status'] = 1;
     } catch (Exception $oException) {
         $aMessage['message'] = $this->__('Error. Can\'t delete file') . PHP_EOL . $oException->getMessage();
     }
     return $this->getHelper('Json')->sendJson($aMessage);
 }
 /**
  * Issue upload-help-page action
  *
  * Upload help page for issue
  */
 public function uploadHelpPageAction()
 {
     $aMessage = array('status' => 0);
     try {
         $iIssueId = intval($this->_getParam('iid'));
         $sHelpPageType = (string) $this->_getParam('type');
         if (!AM_Model_Db_Table_Abstract::factory('issue')->checkAccess($iIssueId, $this->_aUserInfo)) {
             throw new AM_Controller_Exception_Forbidden('Access denied');
         }
         $oIssue = AM_Model_Db_Table_Abstract::factory('issue')->findOneBy('id', $iIssueId);
         /* @var $oIssue AM_Model_Db_Issue */
         if (is_null($oIssue)) {
             throw new AM_Controller_Exception_Forbidden('Access denied');
         }
         $oHelpPage = $oIssue->uploadHelpPage($sHelpPageType);
         /* @var $oHelpPage AM_Model_Db_IssueHelpPage */
         $aFile = array();
         $aFile['name'] = $oHelpPage->name;
         $aFile['nameShort'] = $this->getHelper('String')->cut($oHelpPage->name, 12);
         $aFile['smallUri'] = AM_Tools::getImageUrl($oHelpPage->getThumbnailPresetType(), $oHelpPage->getThumbnailPresetType(), $iIssueId, $oHelpPage->getResource()->getResourceBaseName()) . '?' . strtotime($oHelpPage->updated);
         $aFile['bigUri'] = AM_Tools::getImageUrl($oHelpPage->getResolutionForPreview(), $oHelpPage->getThumbnailPresetType(), $iIssueId, $oHelpPage->getResource()->getResourceBaseName()) . '?' . strtotime($oHelpPage->updated);
         $aMessage['file'] = $aFile;
         $aMessage['status'] = 1;
     } catch (Exception $e) {
         if (isset($oHelpPage)) {
             $oHelpPage->delete();
         }
         $aMessage['message'] = 'Error. Can\'t upload file.' . PHP_EOL . $e->getMessage();
     }
     return $this->sendJsonAsPlainText($aMessage);
 }
Exemple #9
0
 /**
  * Get client application/issues/revision tree
  *
  * @param int $iApplicationId
  * @param string $sUdid
  * @return array
  */
 public function getIssues($iApplicationId, $sUdid = null, $sPlatform = self::PLATFORM_IOS, $sPublisherToken = NULL)
 {
     $iApplicationId = intval($iApplicationId);
     if ($iApplicationId <= 0) {
         throw new AM_Api_Client_Exception(sprintf('Invalid application id "%d"', $iApplicationId));
     }
     $sPlatform = trim($sPlatform);
     if (!in_array($sPlatform, $this->_aValidPlatforms)) {
         $sPlatform = self::PLATFORM_IOS;
     }
     if (!is_null($sUdid)) {
         $sUdid = trim($sUdid);
     }
     //Does udid belong to admin user
     $bIsUdidUserAdmin = false;
     $oDevice = null;
     if (!empty($sUdid)) {
         $oDevice = AM_Model_Db_Table_Abstract::factory('device')->findOneBy(array('identifer' => $sUdid));
         if (!is_null($oDevice)) {
             $this->getLogger()->debug(sprintf('Existing device given: %s', $sUdid));
             $oUser = $oDevice->getUser();
             if (!is_null($oUser)) {
                 $bIsUdidUserAdmin = (bool) $oUser->is_admin;
             }
         }
     }
     $aResult = array('code' => self::RESULT_SUCCESS, 'applications' => array());
     $oApplications = AM_Model_Db_Table_Abstract::factory('application')->findAllBy(array('id' => $iApplicationId, 'deleted' => 'no'));
     foreach ($oApplications as $oApplication) {
         if ($this->authenticatePublisher($sPublisherToken, $oApplication->id, $oApplication) == self::RESULT_SUCCESS) {
             $bIsUdidUserAdmin = true;
         }
         if (!is_null($oDevice)) {
             if (!is_null($oDevice->getUser()) && $oApplication->client == $oDevice->getUser()->client) {
                 $bIsUdidUserAdmin = true;
             }
         }
         $oVocabulary = AM_Model_Db_Table_Abstract::factory('application')->findOneBy('id', $iApplicationId)->getVocabularyTag();
         $aApplicationTags = array();
         $oApplicationTags = AM_Model_Db_Table_Abstract::factory('term')->getTagsForApplicationExisting($oVocabulary->id);
         foreach ($oApplicationTags as $oApplicationTag) {
             $aApplicationTags[] = array('id' => $oApplicationTag->id, 'title' => $oApplicationTag->title);
         }
         $aApplication = array('application_id' => $oApplication->id, 'application_title' => $oApplication->title, 'application_type' => $oApplication->type, 'application_description' => $oApplication->description, 'application_product_id' => $oApplication->product_id, 'application_notification_email' => $oApplication->{'nm_email_' . $sPlatform}, 'application_notification_email_title' => $oApplication->{'nt_email_' . $sPlatform}, 'application_notification_twitter' => $oApplication->{'nm_twitter_' . $sPlatform}, 'application_notification_facebook' => $oApplication->{'nm_fbook_' . $sPlatform}, 'application_preview' => $oApplication->preview, 'application_tags' => $aApplicationTags);
         if ($oApplication->type == AM_Model_Db_ApplicationType::TYPE_RUE98WE) {
             $aApplication['application_welcome_message'] = !empty($oApplication->welcome) ? str_replace("\n", "\\n", $oApplication->welcome) : null;
             $aApplication['application_welcome_message_part2'] = !empty($oApplication->welcome_part2) ? str_replace("\n", "\\n", $oApplication->welcome_part2) : null;
             $aApplication['application_message_for_readers'] = $oApplication->message_for_readers;
             $aApplication['application_share_url'] = $oApplication->share_url;
             $aApplication['application_share_message'] = $oApplication->share_message;
             $aApplication['application_email'] = $oApplication->application_email;
             $aApplication['application_contact_email_subject'] = $oApplication->contact_email_subject;
             $aApplication['application_contact_email_text'] = $oApplication->contact_email_text;
             $aApplication['application_subscribe_title'] = $oApplication->subscribe_title;
             $aApplication['application_subscribe_button'] = $oApplication->subscribe_button;
             $oSubscriptions = AM_Model_Db_Table_Abstract::factory('subscription')->findAllBy(array('application' => $oApplication->id));
             $aApplication['application_subscriptions'] = array();
             foreach ($oSubscriptions as $oSubscription) {
                 $aApplication['application_subscriptions'][$oSubscription->id] = array('button_title' => $oSubscription->button_title, 'itunes_id' => $oSubscription->itunes_id, 'google_id' => $oSubscription->google_id);
             }
             if (!empty($oApplication->newsstand_cover_image)) {
                 $aApplication['application_newsstand_cover_path'] = AM_Tools::getImageUrl('1066-600', AM_Model_Db_Application::PRESET_APPLICATION_IMAGE, $oApplication->id, $oApplication->newsstand_cover_image, 'png') . '?' . strtotime($oApplication->updated);
             }
         }
         $aApplication['issues'] = array();
         //Checking subscripton
         $oSubscription = null;
         if (!is_null($oDevice)) {
             $aProductIds = array($oApplication->product_id);
             foreach (AM_Api_Purchase::$aSubscriptionTypes as $sType) {
                 $aProductIds[] = $oApplication->product_id . '.' . $sType;
             }
             foreach ($aProductIds as $sProductId) {
                 $oSubscription = AM_Model_Db_Table_Abstract::factory('purchase')->findOneBy(array('device_id' => $oDevice->id, 'product_id' => $sProductId, 'deleted' => 'no'));
                 /* @var $oSubscription AM_Model_Db_Purchase */
                 if (!is_null($oSubscription)) {
                     $this->getLogger()->debug(sprintf('Found subscription for device: %s', $sUdid));
                     if ($oSubscription->isExpired()) {
                         $this->getLogger()->debug(sprintf('Subscription is expired: %s', $sUdid));
                         $oSubscription = null;
                     } else {
                         break;
                     }
                 }
             }
         }
         //Looking for the issues
         $aCriteria = array('application' => $oApplication->id, 'deleted' => 'no');
         if (!$bIsUdidUserAdmin) {
             $aCriteria['state'] = AM_Model_Db_State::STATE_PUBLISHED;
         }
         $oIssues = AM_Model_Db_Table_Abstract::factory('issue')->findAllBy($aCriteria);
         foreach ($oIssues as $oIssue) {
             if (!empty($oIssue->exclude)) {
                 continue;
             }
             $oTermEntities = AM_Model_Db_Table_Abstract::factory('termEntity')->findAllBy(array('entity' => $oIssue->id, 'entity_type' => 'issue'));
             $aTags = array();
             foreach ($oTermEntities as $oTermEntity) {
                 $oTag = AM_Model_Db_Table_Abstract::factory('term')->findOneBy('id', $oTermEntity->term);
                 $aTags[] = array('id' => $oTag->id, 'title' => $oTag->title);
             }
             $aIssue = array('issue_id' => $oIssue->id, 'issue_title' => $oIssue->title, 'issue_number' => $oIssue->number, 'issue_state' => AM_Model_Db_State::stateToName($oIssue->state), 'revisions' => array(), 'tags' => $aTags, 'issue_publish_date' => $oIssue->state == AM_Model_Db_State::STATE_PUBLISHED && !empty($oIssue->publish_date) ? $oIssue->publish_date : null, 'updated' => $oIssue->updated);
             if ($oApplication->type == AM_Model_Db_ApplicationType::TYPE_GENERIC) {
                 $aIssue['paid'] = !empty($oIssue->paid) ? true : false;
                 $aIssue['issue_product_id'] = $oIssue->product_id;
             }
             if ($oApplication->type == AM_Model_Db_ApplicationType::TYPE_RUE98WE) {
                 $aIssue['issue_author'] = $oIssue->author;
                 $aIssue['issue_words'] = $oIssue->words;
                 $aIssue['issue_excerpt'] = !empty($oIssue->excerpt) ? str_replace("\n", "\\n", $oIssue->excerpt) : null;
                 $aIssue['issue_title_short'] = $oIssue->title_short;
                 $aIssue['issue_excerpt_short'] = !empty($oIssue->excerpt_short) ? str_replace("\n", "\\n", $oIssue->excerpt_short) : null;
                 $aIssue['issue_category'] = !empty($oIssue->category) ? str_replace("\n", "\\n", $oIssue->category) : null;
                 $aIssue['issue_pricing_plan'] = AM_Model_Db_Issue::pricingToName($oIssue->pricing_plan);
                 $aIssue['issue_google_play_id'] = $oIssue->google_play_id;
                 $aIssue['issue_itunes_id'] = $oIssue->itunes_id;
                 if (!empty($oIssue->image)) {
                     $aIssue['issue_image_large'] = AM_Tools::getImageUrl('1066-600', AM_Model_Db_Issue::PRESET_ISSUE_IMAGE, $oIssue->id, $oIssue->image, 'png') . '?' . strtotime($oIssue->updated);
                     $aIssue['issue_image_small'] = AM_Tools::getImageUrl('533-300', AM_Model_Db_Issue::PRESET_ISSUE_IMAGE, $oIssue->id, $oIssue->image, 'png') . '?' . strtotime($oIssue->updated);
                 }
             }
             //Prepearing help pages
             $oHelpPages = AM_Model_Db_Table_Abstract::factory('issue_help_page')->findAllBy(array('id_issue' => $oIssue->id));
             //Checking the payment
             if (!is_null($oDevice)) {
                 if (!is_null($oSubscription)) {
                     $aIssue['paid'] = true;
                     $aIssue['subscription_type'] = $oSubscription->subscription_type;
                 } else {
                     $this->getLogger()->debug(sprintf('Checking purchase: %s', $sUdid));
                     $oPurchase = AM_Model_Db_Table_Abstract::factory('purchase')->findOneBy(array('device_id' => $oDevice->id, 'product_id' => $oIssue->product_id, 'deleted' => 'no'));
                     if (!is_null($oPurchase)) {
                         $this->getLogger()->debug(sprintf('Found purchase record: %s', $sUdid));
                         $aIssue['paid'] = true;
                     } else {
                         $this->getLogger()->debug(sprintf('Purchases not found: %s', $sUdid));
                     }
                 }
             }
             //Looking for the revisions
             $aCriteria = array('issue' => $oIssue->id, 'deleted' => 'no');
             if (!$bIsUdidUserAdmin) {
                 $aCriteria['state'] = AM_Model_Db_State::STATE_PUBLISHED;
             }
             $oRevisions = AM_Model_Db_Table_Abstract::factory('revision')->findAllBy($aCriteria);
             foreach ($oRevisions as $oRevision) {
                 $aRevision = array('revision_id' => $oRevision->id, 'revision_title' => $oRevision->title, 'revision_state' => AM_Model_Db_State::stateToName($oRevision->state), 'revision_cover_image_list' => '', 'revision_video' => '', 'revision_created' => null, 'revision_color' => $oIssue->issue_color, 'summary_color' => $oIssue->summary_color, 'pastille_color' => $oIssue->pastille_color, 'revision_horizontal_mode' => $oIssue->static_pdf_mode, 'revision_orientation' => $oIssue->orientation, 'help_pages' => array(AM_Model_Db_IssueHelpPage::TYPE_HORIZONTAL => '', AM_Model_Db_IssueHelpPage::TYPE_VERTICAL => ''));
                 foreach ($oHelpPages as $oHelpPage) {
                     /* @var $oHelpPage AM_Model_Db_IssueHelpPage */
                     $aRevision['help_pages'][$oHelpPage->type] = (string) $oHelpPage->getResource()->getResourcePathForExport();
                 }
                 //Revision creation date
                 $oDate = new Zend_Date($oRevision->created);
                 $aRevision['revision_created'] = $oDate->toString(Zend_Date::ISO_8601);
                 $oPageCover = AM_Model_Db_Table_Abstract::factory('revision')->findOneBy('id', $oRevision->id)->getPageRoot();
                 /* @var $oPageCover AM_Model_Db_Page */
                 if (!is_null($oPageCover)) {
                     $aRevision['revision_cover_image_list'] = (string) $oPageCover->getPageCoverUri();
                     $aRevision['revision_video'] = (string) $oPageCover->getStartVideoUri();
                 }
                 $aIssue['revisions'][$oRevision->id] = $aRevision;
             }
             $aApplication['issues'][$oIssue->id] = $aIssue;
         }
         $aResult['applications'][$oApplication->id] = $aApplication;
     }
     return $aResult;
 }
Exemple #10
0
 /**
  * @return void
  */
 public function show()
 {
     if (!$this->controls['state']->getValue()) {
         $this->controls['state']->setValue(AM_Model_Db_State::STATE_WORK_IN_PROGRESS);
     }
     $aStates = null;
     $oQuery = $this->db->select()->from('state', array('id', 'title'))->where('id in (' . implode(',', self::$_aValidStates) . ')')->order('id ASC');
     $aStates = $this->db->fetchPairs($oQuery);
     $iLastRevision = null;
     $oQuery = $this->db->select()->from('revision', array('last_revision' => 'MAX(revision.id)'))->where('revision.issue = ?', $this->primaryKeyValue);
     $iLastRevision = $this->db->fetchOne($oQuery);
     $aSimplePdf = false;
     $aVerticalHelpPage = false;
     $aHorizontalHelpPage = false;
     if ($this->primaryKeyValue) {
         $oIssue = AM_Model_Db_Table_Abstract::factory('issue')->findOneBy('id', $this->primaryKeyValue);
         $sStaticPdfMode = $oIssue->static_pdf_mode;
         $oQuery = $this->db->select()->from('static_pdf', array('id', 'name', 'issue', 'updated' => 'UNIX_TIMESTAMP(updated)'))->where('issue = ?', $this->primaryKeyValue)->order('weight ASC');
         $aPdfFiles = $this->db->fetchAll($oQuery);
         foreach ($aPdfFiles as &$aFile) {
             $aFile['smallUri'] = AM_Tools::getImageUrl('static-pdf-thumbnail', 'static-pdf', $aFile['issue'], $aFile['id'] . '.png') . '?' . strtotime($aFile['updated']);
             $aFile['name'] = $aFile['name'];
             $aFile['nameShort'] = $this->actionController->getHelper('String')->cut($aFile['name']);
             $aFile['bigUri'] = AM_Tools::getImageUrl('1024-768', 'static-pdf', $aFile['issue'], $aFile['id'] . '.png') . '?' . strtotime($aFile['updated']);
         }
         //Get simple PDF
         $oSimplePdf = AM_Model_Db_Table_Abstract::factory('issue_simple_pdf')->findOneBy('id_issue', $this->primaryKeyValue);
         if (!is_null($oSimplePdf)) {
             $aSimplePdf['smallUri'] = AM_Tools::getImageUrl(AM_Model_Db_IssueSimplePdf_Data_Abstract::TYPE, AM_Model_Db_IssueSimplePdf_Data_Abstract::TYPE, $oSimplePdf->id_issue, $oSimplePdf->id_issue . '.png') . '?' . strtotime($oSimplePdf->updated);
             $aSimplePdf['name'] = $oSimplePdf->name;
             $aSimplePdf['nameShort'] = $this->actionController->getHelper('String')->cut($oSimplePdf->name);
             $aSimplePdf['bigUri'] = AM_Tools::getImageUrl('768-1024', AM_Model_Db_IssueSimplePdf_Data_Abstract::TYPE, $oSimplePdf->id_issue, $oSimplePdf->id_issue . '.png') . '?' . strtotime($oSimplePdf->updated);
         }
         //Get help pages
         $oVerticalHelpPage = AM_Model_Db_Table_Abstract::factory('issue_help_page')->findOneBy(array('id_issue' => $this->primaryKeyValue, 'type' => AM_Model_Db_IssueHelpPage::TYPE_VERTICAL));
         if (!is_null($oVerticalHelpPage)) {
             $aVerticalHelpPage['smallUri'] = AM_Tools::getImageUrl($oVerticalHelpPage->getThumbnailPresetType(), $oVerticalHelpPage->getThumbnailPresetType(), $oVerticalHelpPage->id_issue, $oVerticalHelpPage->type . '.' . $oVerticalHelpPage->getResource()->getImageType()) . '?' . strtotime($oVerticalHelpPage->updated);
             $aVerticalHelpPage['name'] = $oVerticalHelpPage->name;
             $aVerticalHelpPage['nameShort'] = $this->actionController->getHelper('String')->cut($oVerticalHelpPage->name, 12);
             $aVerticalHelpPage['bigUri'] = AM_Tools::getImageUrl($oVerticalHelpPage->getResolutionForPreview(), $oVerticalHelpPage->getThumbnailPresetType(), $oVerticalHelpPage->id_issue, $oVerticalHelpPage->type . '.' . $oVerticalHelpPage->getResource()->getImageType()) . '?' . strtotime($oVerticalHelpPage->updated);
         }
         $oHorizontalHelpPage = AM_Model_Db_Table_Abstract::factory('issue_help_page')->findOneBy(array('id_issue' => $this->primaryKeyValue, 'type' => AM_Model_Db_IssueHelpPage::TYPE_HORIZONTAL));
         if (!is_null($oHorizontalHelpPage)) {
             $aHorizontalHelpPage['smallUri'] = AM_Tools::getImageUrl($oHorizontalHelpPage->getThumbnailPresetType(), $oHorizontalHelpPage->getThumbnailPresetType(), $oHorizontalHelpPage->id_issue, $oHorizontalHelpPage->type . '.' . $oHorizontalHelpPage->getResource()->getImageType()) . '?' . strtotime($oHorizontalHelpPage->updated);
             $aHorizontalHelpPage['name'] = $oHorizontalHelpPage->name;
             $aHorizontalHelpPage['nameShort'] = $this->actionController->getHelper('String')->cut($oHorizontalHelpPage->name, 12);
             $aHorizontalHelpPage['bigUri'] = AM_Tools::getImageUrl($oHorizontalHelpPage->getResolutionForPreview(), $oHorizontalHelpPage->getThumbnailPresetType(), $oHorizontalHelpPage->id_issue, $oHorizontalHelpPage->type . '.' . $oHorizontalHelpPage->getResource()->getImageType()) . '?' . strtotime($oHorizontalHelpPage->updated);
         }
     }
     $aRecord = array('staticPdfMode' => isset($sStaticPdfMode) && $sStaticPdfMode ? $sStaticPdfMode : null, 'states' => $aStates, 'orientations' => self::$_aValidOrientations, 'pdf' => isset($aPdfFiles) ? $aPdfFiles : array(), 'appId' => $this->applicationId, 'last_revision' => $iLastRevision, 'simplePdf' => $aSimplePdf, 'verticalHelpPage' => $aVerticalHelpPage, 'horizontalHelpPage' => $aHorizontalHelpPage);
     if (isset($this->view->{$this->getName()})) {
         $aRecord = array_merge($aRecord, $this->view->{$this->getName()});
     }
     $this->view->{$this->getName()} = $aRecord;
     parent::show();
 }
Exemple #11
0
 /**
  * Gets page's start video (API uses this method)
  * @return false|string
  */
 public function getStartVideoUri()
 {
     $oFieldVideo = AM_Model_Db_Table_Abstract::factory('field')->findOneBy(array('name' => AM_Model_Db_FieldType::TYPE_VIDEO, 'template' => AM_Model_Db_Template::TPL_COVER_PAGE));
     $oElementVideo = AM_Model_Db_Table_Abstract::factory('element')->findOneBy(array('page' => $this->id, 'field' => $oFieldVideo->id));
     /* @var $oElementVideo AM_Model_Db_Element */
     if (is_null($oElementVideo)) {
         // if it is root page, but not cover page template
         $oPage = AM_Model_Db_Table_Abstract::factory('page')->findOneBy('id', $this->id);
         if ($oPage->root_page) {
             $oFieldVideo = AM_Model_Db_Table_Abstract::factory('field')->findOneBy(array('name' => AM_Model_Db_FieldType::TYPE_VIDEO, 'template' => $this->template));
             if (empty($oFieldVideo)) {
                 return null;
             }
             $oElementVideo = AM_Model_Db_Table_Abstract::factory('element')->findOneBy(array('page' => $this->id, 'field' => $oFieldVideo->id));
         }
         if (is_null($oElementVideo)) {
             return null;
         }
     }
     $sResource = $oElementVideo->getResources()->getDataValue(AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE);
     if (empty($sResource)) {
         return null;
     }
     $sFileExtension = pathinfo($sResource, PATHINFO_EXTENSION);
     $sFileName = 'resource.' . $sFileExtension;
     $sUri = AM_Tools::getImageUrl('none', AM_Model_Db_Element_Data_Abstract::TYPE, $oElementVideo->id, $sFileName);
     return $sUri;
 }
Exemple #12
0
 /**
  * Prepares vew data for resource
  * @param AM_Model_Db_Element $oElement
  * @param string $sResourceKeyName
  * @return array
  */
 protected function _getResourceViewData(AM_Model_Db_Element $oElement, $sResourceKeyName = AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE)
 {
     $sFile = $oElement->getResources()->getDataValue($sResourceKeyName);
     $aElementView = array();
     if ($sFile) {
         $aFileInfo = pathinfo($sFile);
         $sFileName = $aFileInfo['filename'];
         $sFileExtension = $oElement->getResources()->getImageType();
         $aElementView['fileName'] = $sFileName . '.' . $aFileInfo['extension'];
         $aElementView['fileNameShort'] = $this->getHelper('String')->cut($sFileName) . '.' . $aFileInfo['extension'];
         $sResourceFileName = $sResourceKeyName . '.' . $sFileExtension;
         if (AM_Tools::isAllowedImageExtension($sFile)) {
             $sUniq = '?' . strtotime($oElement->updated);
             $aElementView['smallUri'] = AM_Tools::getImageUrl($this->_getThumbnailPresetName(), 'element', $oElement->id, $sResourceFileName) . $sUniq;
             $aElementView['bigUri'] = AM_Tools::getImageUrl('none', 'element', $oElement->id, $sResourceFileName) . $sUniq;
         } else {
             $aElementView['smallUri'] = AM_Tools::getIconForNonImageFile($sResourceFileName);
         }
         $aElementView['originUri'] = '/content/element/' . AM_Tools_String::generatePathFromId(intval($oElement->id), '/') . "/{$sResourceKeyName}.{$aFileInfo['extension']}";
     }
     return $aElementView;
 }
Exemple #13
0
 /**
  * Upload resource
  */
 public function uploadAction()
 {
     try {
         $aMessage = array('status' => 0);
         if (!$this->_iPageId || !$this->_iFieldId) {
             throw new AM_Exception('Invalid params');
         }
         $oField = AM_Model_Db_Table_Abstract::factory('field')->findOneBy('id', $this->_iFieldId);
         /* @var $oField AM_Model_Db_Field */
         if (is_null($oField)) {
             throw new AM_Exception(sprintf('Field with id "%d" not found.', $this->_iFieldId));
         }
         $oPage = AM_Model_Db_Table_Abstract::factory('page')->findOneBy('id', $this->_iPageId);
         /* @var $oPage AM_Model_Db_Page */
         if (is_null($oPage)) {
             throw new AM_Exception(sprintf('Page with id "%d" not found.', $this->_iPageId));
         }
         $oElement = $oPage->getElementForField($oField);
         /* @var $oElement AM_Model_Db_Element */
         $oElement->uploadResource();
         $this->_postUpload($oElement);
         $sResourceFile = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE);
         $sResourceImageType = $oElement->getResources()->getDataValue(AM_Model_Db_Element_Data_Resource::DATA_KEY_IMAGE_TYPE);
         $aFileInfo = pathinfo($sResourceFile);
         $sFileName = $aFileInfo['filename'];
         $sFileExtension = empty($sResourceImageType) ? $aFileInfo['extension'] : $sResourceImageType;
         $aResourceFileViewInfo = array();
         $aResourceFileViewInfo['fileName'] = $sFileName . '.' . $aFileInfo['extension'];
         $aResourceFileViewInfo['fileNameShort'] = $this->getHelper('String')->cut($sFileName) . '.' . $aFileInfo['extension'];
         $sResourceFileName = AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE . '.' . $sFileExtension;
         if (AM_Tools::isAllowedImageExtension($sResourceFile)) {
             $sOrientation = $oPage->getOrientation();
             if (AM_Model_Db_Template::TPL_SCROLLING_PAGE_HORIZONTAL == $oPage->template) {
                 $sOrientation = AM_Model_Db_Issue::ORIENTATION_HORIZONTAL;
             }
             $sUniq = '?' . strtotime($oElement->updated);
             $aResourceFileViewInfo['smallUri'] = AM_Tools::getImageUrl(AM_Handler_Thumbnail_Interface::PRESET_FIELD . '-' . $sOrientation, 'element', $oElement->id, $sResourceFileName) . $sUniq;
             $aResourceFileViewInfo['bigUri'] = AM_Tools::getImageUrl('none', 'element', $oElement->id, $sResourceFileName) . $sUniq;
         } else {
             $aResourceFileViewInfo['smallUri'] = AM_Tools::getIconForNonImageFile($sResourceFileName);
         }
         $oPage->setUpdated();
         $aMessage['fieldTypeTitle'] = $oField->getFieldType()->title;
         $aMessage['background'] = $oPage->getPageBackgroundUri();
         $aMessage['element'] = $oElement->id;
         $aMessage['file'] = $aResourceFileViewInfo;
         $aMessage['status'] = 1;
     } catch (Exception $e) {
         $aMessage["message"] = $this->__('Error. Can\'t upload file') . PHP_EOL . $e->getMessage();
     }
     return $this->sendJsonAsPlainText($aMessage);
 }