Exemplo n.º 1
0
 function uploadSiteImageAction($siteId)
 {
     $this->viewClass = 'JsonView';
     $siteId = intval($siteId);
     $site = $this->site->findByPk($siteId);
     $siteImage = new UploadedFile("siteImage");
     $siteImage->addFilter("extension", array("jpg", "png", "gif"));
     $thumbsPath = Config::get("SITES_THUMBS_PATH");
     $siteImage->setSavePath($thumbsPath);
     $siteImage->save();
     $newImageSrc = $siteImage->getSavedFileName();
     if ($newImageSrc) {
         if ($site->imageSrc) {
             $oldFilePath = $thumbsPath . basename($site->imageSrc);
             if (file_exists($oldFilePath)) {
                 unlink($oldFilePath);
             }
         }
         $site->imageSrc = $newImageSrc;
         $site->save();
     }
     $site->updateImageSrc(false);
     $this->set('status', 'ok');
     $this->set('imageSrc', $site->imageSrc);
 }
Exemplo n.º 2
0
 function savePackageAction($packageId = null)
 {
     $fields = array('name', 'amount', 'allopassId', 'allopassNumber', 'priority', 'description', 'siteDescriptionMaxLength', 'maxKeywordsCountPerSite', 'backLinkMandatory', 'siteDescriptionHtmlEnabled', 'siteDescriptionHtmlAllowedTags', 'siteDescriptionHtmlAllowedCssProperties', 'siteDescriptionMinLength');
     $data = $this->request->getArray($fields);
     $package = empty($packageId) ? new PackageRecord() : $this->package->findByPk($packageId);
     $package->fromArray($data);
     $siteImage = new UploadedFile("uploadImage");
     $siteImage->addFilter("extension", array("jpg", "png", "gif"));
     if ($siteImage->wasUploaded()) {
         $thumbsPath = Config::get("PACKAGES_THUMBS_PATH");
         $siteImage->setSavePath($thumbsPath);
         $siteImage->save();
         $newImageSrc = $siteImage->getSavedFileName();
         if ($newImageSrc) {
             if (!empty($package->imageSrc)) {
                 $oldFilePath = $thumbsPath . basename($package->imageSrc);
                 if (file_exists($oldFilePath)) {
                     unlink($oldFilePath);
                 }
             }
             $package->imageSrc = $newImageSrc;
         }
     }
     $package->save();
     $this->redirect($this->moduleLink("package"));
 }
Exemplo n.º 3
0
 function saveExtraFieldsValues($item, $newItem)
 {
     $fields = $this->getCategoryFieldsWithOptions($item->categoryId);
     $itemId = $item->siteId;
     $c = new Criteria();
     $c->addInnerJoin('extrafields', 'extrafields.fieldId', 'extrafieldvalues.fieldId');
     $c->add('type', 'file');
     $files = $this->extraFieldValue->getArray($c, 'text', 'extrafields.fieldId');
     $c = new Criteria();
     $c->add("itemId", $itemId);
     $this->extraFieldValue->del($c);
     foreach ($fields as $fieldId => $field) {
         $extraFieldValue = new ExtraFieldValueRecord();
         $extraFieldValue->itemId = $itemId;
         $extraFieldValue->fieldId = $fieldId;
         if (!isset($newItem->extraField[$fieldId])) {
             continue;
         }
         $newItemExtraFieldData = $newItem->extraField[$fieldId];
         try {
             switch ($field['type']) {
                 case "text":
                 case "textarea":
                     $extraFieldValue->text = $newItemExtraFieldData;
                     break;
                 case "select":
                 case "radio":
                     if (!isset($field['options'][$newItemExtraFieldData])) {
                         continue 2;
                     }
                 case "range":
                     $extraFieldValue->value = $newItemExtraFieldData;
                     break;
                 case 'url':
                     $extraFieldValue->text = serialize($newItemExtraFieldData);
                     break;
                 case "checkbox":
                     $value = 0;
                     foreach ($newItemExtraFieldData as $checkBoxValue) {
                         if (!isset($field['options'][$checkBoxValue])) {
                             continue 3;
                         }
                         $value += pow(2, $checkBoxValue - 1);
                         //minus 1 because we count from 1,2,3,4.. to have 1,2,4,8
                     }
                     $extraFieldValue->value = $value;
                     break;
                 case 'file':
                     $file = new UploadedFile('extraField_' . $fieldId . '_file');
                     if (!empty($files[$fieldId])) {
                         $data = unserialize($files[$fieldId]);
                     } else {
                         $data = array();
                     }
                     $data['title'] = $newItemExtraFieldData['title'];
                     if ($file->wasUploaded()) {
                         $filesPath = CODE_ROOT_DIR . 'uploads/files/';
                         $file->setSavePath($filesPath);
                         $file->save();
                         $fileSrc = $file->getSavedFileName();
                         $data['fileSrc'] = $fileSrc;
                     }
                     $extraFieldValue->text = serialize($data);
             }
             $extraFieldValue->save();
         } catch (Exception $e) {
         }
     }
     $this->site->updateByPk(array("haveExtraFields" => !empty($newItem->extraField) ? "1" : "0"), $itemId);
 }
Exemplo n.º 4
0
 function saveCategoryAction()
 {
     $rebuild = false;
     $edit = !empty($this->request->categoryId);
     $imageSrc = false;
     try {
         $file = new UploadedFile("categoryImage");
         $file->addFilter("extension", array("jpg", "gif", "png"));
         //check and save image
         if ($file->wasUploaded()) {
             $file->setSavePath(CODE_ROOT_DIR . 'uploads/images_categories/');
             $file->save();
             $imageSrc = $file->getSavedFileName();
         }
     } catch (Exception $e) {
     }
     if (!$edit && $imageSrc == false) {
         $imageSrc = 'defaultCategoryImage.gif';
     }
     //create and save new category
     $fields = $this->request->getArray(array("name", "urlName", "navigationName", "title", "headerDescription", "possibleTender", "description", "metaDescription", "parentCategoryId", "forbidden"));
     if ($edit) {
         $category = $this->category->findByPk($this->request->categoryId);
         //handle categoryParentId change
         if ($category->parentCategoryId != $this->request->parentCategoryId && $category->changeParent($this->request->parentCategoryId)) {
             $rebuild = true;
         }
     } else {
         $category = new CategoryRecord();
     }
     $category->fromArray($fields);
     if ($imageSrc) {
         if ($edit) {
             $category->removeImage();
         }
         $category->imageSrc = $imageSrc;
     }
     if (empty($category->urlName)) {
         $category->urlName = $category->name;
     }
     $excludeCategoryId = $edit ? $category->categoryId : false;
     $category->urlName = $this->category->getFreeUrlName($category->urlName, $excludeCategoryId);
     $category->save();
     if (!$edit) {
         $this->categoryParent->addNode($this->request->parentCategoryId, $category->categoryId);
     }
     if ($rebuild) {
         $this->categoryParent->moveNode($category->categoryId, $category->parentCategoryId);
         $this->category->updateValidatedSitesCount();
     }
     $redirect = AppRouter::getRewrittedUrl("/admin/category/index/" . $category->parentCategoryId);
     $this->redirect($redirect);
 }