public function setTags() { /* save tags */ $tags = $this->getProperty('tags'); if (isset($tags)) { $tagNames = explode(',', $tags); foreach ($tagNames as $tagName) { $tagName = trim($tagName); if (empty($tagName)) { continue; } /** @var galTag $tag */ $tag = $this->modx->newObject('galTag'); $tag->set('item', $this->object->get('id')); $tag->set('tag', $tagName); $tag->save(); } } }
public function uploadItem(galItem $item, $filePath, $name, $mediaSource) { $fileName = false; $albumDir = $this->getPath(false); $targetDir = str_ireplace(MODX_BASE_PATH, '', $this->getPath()); /* if directory doesnt exist, create it */ if (!$mediaSource->createContainer($targetDir, '/')) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, '[Gallery] Could not create directory (possibly already exists?): ' . $targetDir); } /* upload the file */ $extension = pathinfo($name, PATHINFO_EXTENSION); $shortName = $item->get('id') . '.' . $extension; $relativePath = $albumDir . $shortName; $absolutePath = $targetDir . $shortName; $fileName = str_replace(' ', '', $relativePath); $file = array("name" => $shortName, "tmp_name" => $filePath, "error" => "0"); // emulate a $_FILES object $success = true; // modFileMediaSource class uses move_uploaded_file - because we create a local file - we cannot use this function and we use streams instead if (!is_uploaded_file($filePath) && get_class($mediaSource) == 'modFileMediaSource_mysql') { $input = fopen($filePath, "r"); $target = fopen($this->getPath(true) . $shortName, "w"); $bytes = stream_copy_to_stream($input, $target); fclose($input); fclose($target); } else { $success = $mediaSource->uploadObjectsToContainer($targetDir, array($file)); } // if(!$success) { // $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] An error occurred while trying to upload the file: '.$filePath.' to '.$absolutePath); // return false; // } return $fileName; }