コード例 #1
0
 public function delete()
 {
     self::$__object = "ElementFeed";
     self::$__table = "pcms_element_feed";
     //*** Remove Feed Fields.
     $objFields = ElementFieldFeed::selectByElement($this->getElementId());
     foreach ($objFields as $objField) {
         $objField->delete();
     }
     return parent::delete();
 }
コード例 #2
0
ファイル: class.impex.php プロジェクト: laiello/punchcms
 public static function exportElement($objDoc, $intAccountId, $intId, &$arrFiles, $arrTemplateFilters = NULL, $arrElementFilters = NULL, $includeSelf = false)
 {
     global $_CONF;
     $objElements = $objDoc->createElement('elements');
     if ($includeSelf) {
         $objElement = Element::selectByPK($intId);
         $objDbElements = new DBA__Collection();
         $objDbElements->addObject($objElement);
     } else {
         //$objDbTemplates = Templates::getFromParent($intId, false, $intAccountId);
         $objDbElements = Elements::getFromParent($intId, false, "'1', '2', '3', '4', '5'", $intAccountId);
     }
     if ($objDbElements->count() > 0) {
         foreach ($objDbElements as $objDbElement) {
             if (($arrTemplateFilters == NULL || in_array($objDbElement->getTemplateId(), $arrTemplateFilters)) && ($arrElementFilters == NULL || in_array($objDbElement->getId(), $arrElementFilters))) {
                 $objElement = $objDoc->createElement('element');
                 $objElement->setAttribute("id", $objDbElement->getId());
                 $objElement->setAttribute("name", $objDbElement->getName());
                 $objElement->setAttribute("nameCount", $objDbElement->getNameCount());
                 $objElement->setAttribute("apiName", $objDbElement->getApiName());
                 $objElement->setAttribute("description", $objDbElement->getDescription());
                 $objElement->setAttribute("typeId", $objDbElement->getTypeId());
                 $objElement->setAttribute("templateId", $objDbElement->getTemplateId());
                 $objElement->setAttribute("isPage", $objDbElement->getIsPage());
                 $objElement->setAttribute("userId", $objDbElement->getUserId());
                 $objElement->setAttribute("groupId", $objDbElement->getGroupId());
                 $objElement->setAttribute("sort", $objDbElement->getSort());
                 $objElement->setAttribute("active", $objDbElement->getActive());
                 $objElement->setAttribute("username", $objDbElement->getUsername());
                 $objElement->setAttribute("created", $objDbElement->getCreated());
                 $objElement->setAttribute("modified", $objDbElement->getModified());
                 //*** Schedule.
                 $objSchedule = $objDbElement->getSchedule();
                 $objElement->setAttribute("scheduleStartActive", $objSchedule->getStartActive());
                 $objElement->setAttribute("scheduleStartDate", $objSchedule->getStartDate());
                 $objElement->setAttribute("scheduleEndActive", $objSchedule->getEndActive());
                 $objElement->setAttribute("scheduleEndDate", $objSchedule->getEndDate());
                 //*** Fields.
                 $arrActiveLangs = $objDbElement->getLanguageActives();
                 $objContentLangs = ContentLanguage::select();
                 $objFields = $objDoc->createElement('fields');
                 $objDbFields = $objDbElement->getFields();
                 foreach ($objDbFields as $objDbField) {
                     $objField = $objDoc->createElement('field');
                     $objField->setAttribute("templateFieldId", $objDbField->getTemplateFieldId());
                     $objField->setAttribute("sort", $objDbField->getSort());
                     foreach ($objContentLangs as $objContentLanguage) {
                         $objValue = $objDbField->getValueObject($objContentLanguage->getId());
                         if (is_object($objValue)) {
                             $strValue = str_replace("&", "&", $objValue->getValue());
                             $objLanguage = $objDoc->createElement('language', $strValue);
                             $objLanguage->setAttribute("id", $objContentLanguage->getId());
                             $objLanguage->setAttribute("active", in_array($objContentLanguage->getId(), $arrActiveLangs) ? 1 : 0);
                             $objLanguage->setAttribute("cascade", $objValue->getCascade());
                             $objField->appendChild($objLanguage);
                             switch ($objDbField->getTypeId()) {
                                 case FIELD_TYPE_FILE:
                                     $arrFileTemp = explode("\n", $strValue);
                                     foreach ($arrFileTemp as $fileValue) {
                                         if (!empty($fileValue)) {
                                             $arrTemp = explode(":", $fileValue);
                                             $strSrc = count($arrTemp) > 1 ? $arrTemp[1] : $arrTemp[0];
                                             array_push($arrFiles, $strSrc);
                                         }
                                     }
                                     break;
                                 case FIELD_TYPE_IMAGE:
                                     $arrFileTemp = explode("\n", $strValue);
                                     foreach ($arrFileTemp as $fileValue) {
                                         if (!empty($fileValue)) {
                                             $arrTemp = explode(":", $fileValue);
                                             $strSrc = count($arrTemp) > 1 ? $arrTemp[1] : $arrTemp[0];
                                             $objImageField = new ImageField($objDbField->getTemplateFieldId());
                                             $arrSettings = $objImageField->getSettings();
                                             foreach ($arrSettings as $key => $arrSetting) {
                                                 if (!empty($arrSetting['width']) || !empty($arrSetting['height'])) {
                                                     //*** Add file.
                                                     array_push($arrFiles, FileIO::add2Base($strSrc, $arrSetting['key']));
                                                 }
                                             }
                                             array_push($arrFiles, $strSrc);
                                         }
                                     }
                                     break;
                             }
                         }
                     }
                     $objFields->appendChild($objField);
                 }
                 if ($objDbFields->count() > 0) {
                     $objElement->appendChild($objFields);
                 } else {
                     $objDbLanguages = ElementLanguage::selectByElement($objDbElement->getId());
                     $objLanguages = $objDoc->createElement('languages');
                     foreach ($objDbLanguages as $objDbLanguage) {
                         if ($objDbLanguage->getActive()) {
                             $objLanguage = $objDoc->createElement('language');
                             $objLanguage->setAttribute("id", $objDbLanguage->getLanguageId());
                             $objLanguage->setAttribute("active", $objDbLanguage->getActive());
                             $objLanguage->setAttribute("cascade", $objDbLanguage->getCascade());
                             $objLanguages->appendChild($objLanguage);
                         }
                     }
                     if ($objDbLanguages->count() > 0) {
                         $objElement->appendChild($objLanguages);
                     }
                 }
                 //*** Feed fields.
                 $objDbFeed = $objDbElement->getFeed();
                 if (is_object($objDbFeed) && $objDbFeed->getId() > 0) {
                     $objFeed = $objDoc->createElement('feed');
                     $objFeed->setAttribute("feedId", $objDbFeed->getFeedId());
                     $objFeed->setAttribute("feedPath", $objDbFeed->getFeedPath());
                     $objFeed->setAttribute("maxItems", $objDbFeed->getMaxItems());
                     $objFeed->setAttribute("sortBy", $objDbFeed->getSortBy());
                     $objFeed->setAttribute("aliasField", $objDbFeed->getAliasField());
                     $objDbFields = ElementFieldFeed::selectByElement($objDbElement->getId());
                     foreach ($objDbFields as $objDbField) {
                         $objField = $objDoc->createElement('feedfield');
                         $objField->setAttribute("templateFieldId", $objDbField->getTemplateFieldId());
                         $objField->setAttribute("feedPath", $objDbField->getFeedPath());
                         $objField->setAttribute("xpath", $objDbField->getXpath());
                         $objField->setAttribute("languageId", $objDbField->getLanguageId());
                         $objField->setAttribute("cascade", $objDbField->getCascade());
                         $objField->setAttribute("sort", $objDbField->getSort());
                         $objFeed->appendChild($objField);
                     }
                     $objElement->appendChild($objFeed);
                 }
                 //*** Meta values.
                 if ($objDbElement->isPage()) {
                     $blnHasMeta = false;
                     $objMeta = $objDoc->createElement('meta');
                     foreach ($objContentLangs as $objContentLanguage) {
                         $objDbMeta = $objDbElement->getMeta($objContentLanguage->getId());
                         if (is_object($objDbMeta)) {
                             $objLanguage = $objDoc->createElement('language');
                             $objLanguage->setAttribute("id", $objContentLanguage->getId());
                             $strValue = str_replace("&", "&", $objDbMeta->getValueByValue("name", "title"));
                             $objLanguage->setAttribute("title", $strValue);
                             $strValue = str_replace("&", "&", $objDbMeta->getValueByValue("name", "keywords"));
                             $objLanguage->setAttribute("keywords", $strValue);
                             $strValue = str_replace("&", "&", $objDbMeta->getValueByValue("name", "description"));
                             $objLanguage->setAttribute("description", $strValue);
                             $objMeta->appendChild($objLanguage);
                             $blnHasMeta = true;
                         }
                     }
                     if ($blnHasMeta) {
                         $objElement->appendChild($objMeta);
                     }
                 }
                 //*** Permissions.
                 $objPermissions = $objDoc->createElement('permissions');
                 $objDbPermissions = $objDbElement->getPermissions();
                 $objPermissions->setAttribute("users", implode(",", $objDbPermissions->getUserId()));
                 $objPermissions->setAttribute("groups", implode(",", $objDbPermissions->getGroupId()));
                 $objElement->appendChild($objPermissions);
                 //*** Sub elements.
                 $objSubElements = self::exportElement($objDoc, $intAccountId, $objDbElement->getId(), $arrFiles, $arrTemplateFilters, $arrElementFilters);
                 if ($objSubElements) {
                     $objElement->appendChild($objSubElements);
                 }
                 $objElements->appendChild($objElement);
             }
         }
     }
     return $objElements;
 }
コード例 #3
0
ファイル: class.feed.php プロジェクト: laiello/punchcms
 private function recursiveFeedInsert($objElement, $objParent, $objNode, $objLangs)
 {
     global $objLiveUser;
     $objElementFeed = $objElement->getFeed();
     $objTemplate = Template::selectByPK($objElement->getTemplateId());
     if (is_null($objNode)) {
         $objNodes = $objElementFeed->getBody();
     } else {
         $strFeedPath = $objElementFeed->getFeedPath();
         if (empty($strFeedPath)) {
             $objNodes = array($objNode);
         } else {
             $objNodes = $objNode->xpath($objElementFeed->getFeedPath());
         }
     }
     $intMaxItems = $objElementFeed->getMaxItems();
     if (empty($intMaxItems)) {
         $intMaxItems = 0;
     }
     $intCount = 1;
     foreach ($objNodes as $objNode) {
         //*** Create elements.
         $strName = "";
         $objInsertElement = new InsertFeedElement($objParent);
         $objInsertElement->setTemplate($objElement->getTemplateId());
         foreach ($objLangs as $objLang) {
             $objFeedFields = ElementFieldFeed::selectByElement($objElement->getId(), $objLang->getId());
             foreach ($objFeedFields as $objFeedField) {
                 $strPath = $objFeedField->getXPath();
                 if (stripos($strPath, "user->") !== false) {
                     $strValue = str_replace("user->", "", $strPath);
                     $objInsertElement->addField($objFeedField->getTemplateFieldId(), $strValue, $objLang->getId(), $objFeedField->getCascade());
                 } else {
                     $strValue = $this->valueByPath($objNode, $strPath);
                     if (!empty($strValue)) {
                         $objInsertElement->addField($objFeedField->getTemplateFieldId(), $strValue, $objLang->getId(), $objFeedField->getCascade());
                         if (!is_numeric($strValue) && empty($strName)) {
                             $strName = getShortValue(strip_tags($strValue), 40, true, "");
                         }
                     }
                 }
             }
         }
         $strName = empty($strName) ? "Dynamic" : $strName;
         $objInsertElement->setName($strName);
         $objInsertElement->setUsername("PunchCMS");
         $objInsertElement->setActive(true);
         $objInsertedElement = $objInsertElement->save();
         //*** Add the alias.
         $strAlias = "";
         $strAliasField = $objElementFeed->getAliasField();
         if (!empty($strAliasField)) {
             //*** Get the alias field value.
             $strValue = $this->valueByPath($objNode, $objElementFeed->getAliasField());
             $strAlias = $objElement->getAlias();
             if (!empty($strAlias) && stripos($strAlias, "%s") !== false) {
                 //*** Merge value with the flat alias.
                 $strAlias = sprintf($strAlias, $strValue);
             } else {
                 //*** Use just the value.
                 $strAlias = $strValue;
             }
         } else {
             //*** Use the flat alias.
             $strAlias = $objElement->getAlias();
         }
         if (!empty($strAlias)) {
             $objAlias = new Alias();
             $objAlias->setAlias($strAlias);
             $objInsertedElement->setAlias($objAlias);
         }
         //*** Sub elements.
         $objSubElements = $objElement->getElements(false, ELM_TYPE_DYNAMIC, $this->getAccountId());
         foreach ($objSubElements as $objSubElement) {
             $this->recursiveFeedInsert($objSubElement, $objInsertedElement, $objNode, $objLangs);
         }
         if ($intMaxItems > 0 && $intCount >= $intMaxItems) {
             break;
         }
         $intCount++;
     }
 }