function getImage($img) { try { if (strpos($img, 'http://') !== false) { $original_url = $img; $pos = strrpos($img, "."); $ext = substr($img, $pos + 1); $media = new Media(); $media->save(); $fileName = $media->getId() . "." . $ext; $basePath = sfConfig::get('sf_web_dir') . "/media/upload/"; file_put_contents($basePath . $fileName, file_get_contents($img)); $mime = explode(";", Media::mime_content_type($basePath . $fileName)); $mime = $mime[0]; $media->setFilename($fileName); $media->setFiletype($mime); $media->setFiledirpath($basePath); $media->save(null, $o); chmod($basePath . $fileName, 0777); $media->resizeImage(null, 450); $media->resizeImage(1, 150); } elseif (base64_decode($img)) { $ext = "jpg"; $media = new Media(); $media->save(); $fileName = $media->getId() . "." . $ext; $basePath = sfConfig::get('sf_web_dir') . "/media/upload/"; file_put_contents($basePath . $fileName, base64_decode($img)); $mime = explode(";", Media::mime_content_type($basePath . $fileName)); $mime = $mime[0]; $media->setFilename($fileName); $media->setFiletype($mime); $media->setFiledirpath($basePath); $media->save(null, $o); chmod($basePath . $fileName, 0777); $media->resizeImage(null, 450); $media->resizeImage(1, 150); } } catch (Exception $e) { $media->delete(); FileHelper::Log("CRON ERROR >>> Field : " . $k . " on item " . $o->getId() . "(" . $offer['originalid'] . ") is not a valid image. [" . $original_url . "]"); echo_cms("CRON ERROR >>> Field : " . $k . " on item " . $o->getId() . "(" . $offer['originalid'] . ") is not a valid image. [" . $original_url . "]"); } }
public function postRemoveMedia($id) { $media = Media::find($id); $media = new Media(); $media->delete(); $media = Media::find($id); $owner = $media->mediable_id; $ownerType = $media->mediable_type; $owner = $ownerType::find($owner); $isAjax = Request::ajax(); // Disasociate this from its parent exhibit foreach ($owner->media as $key => $image) { if ($image->id == $id) { $owner->media[$key]->update(['mediable_id' => 0, 'mediable_type' => null]); $mediasave = $owner->media[$key]->save(); } } if ($mediasave == true) { $outcome = $owner->update(array('cover_image' => '')); } return json_encode($outcome); }
public function actionToggleDefaultLogo() { $adminProf=ProfileChild::model()->findByAttributes(array('username'=>'admin')); $logo=Media::model()->findByAttributes(array('associationId'=>$adminProf->id,'associationType'=>'logo')); if(!isset($logo)) { $logo=new Media; $logo->associationType='logo'; $name='yourlogohere.png'; $logo->associationId=$adminProf->id; $logo->fileName='uploads/logos/'.$name; if($logo->save()) { } } else { $logo->delete(); } $this->redirect(array('index')); }
/** * Move the asset using the specified from and to paths * A shortcut for Media::copy() then Media::delete() * * @param string $pathfrom The virtual path source * @param string $pathto The virtual path destination * @return boolean true on success */ public static function move($pathfrom, $pathto) { if (Media::copy($pathfrom, $pathto)) { return Media::delete($pathfrom); } else { return false; } }
public function save($validate = true) { $this->logger->clear(); // validation $valid = !$validate || $this->validate(); // get a user_id, either by adding new user or fetching id of existing if ($valid) { $user = new User(null, $this->db); $user->email = $this->email; $user->name = $this->username; if (!is_null($user->email) && !empty($user->email)) { $user->loadFromEmail(); } else { if (!is_null($user->name) && !empty($user->name)) { $user->loadFromName(); } } if ($this->isImport) { $user->implied = 1; } if ($user->id) { $this->logger->log("user found..."); } else { $user->ip = $_SERVER['REMOTE_ADDR']; } $success = $user->save(); $this->user_id = $user->id; if (is_null($this->user_id)) { $valid = false; } } if ($valid && isset($this->imageUpload) && !empty($this->imageUpload["name"]) && $this->imageUpload["error"] == 0) { $this->logger->log("saving image..."); $image = new Media(null, $this->db); $image->name = time(); $image->mime_type = $this->imageUpload['type']; $image->tempFile = $this->imageUpload; if ($image->validate()) { if ($image->save()) { $this->logger->log("image saved..."); } else { $this->status = $image->errorMessage; $valid = false; $this->logger->log("error saving image..."); } } else { $this->status = $image->errorMessage; $valid = false; } } if ($valid && isset($this->audioUpload) && !empty($this->audioUpload["name"]) && $this->audioUpload["error"] == 0) { $this->logger->log("saving audio..."); $audio = new Media(null, $this->db); $audio->name = time(); $audio->mime_type = $this->audioUpload['type']; $audio->tempFile = $this->audioUpload; if ($audio->validate()) { if ($audio->save()) { $this->logger->log("audio saved..."); } else { $this->status = $audio->errorMessage; $valid = false; $this->logger->log("error saving audio..."); } } else { $this->status = $audio->errorMessage; $valid = false; $this->logger->log("error validating audio..."); } } $get_location = curl_init(); curl_setopt($get_location, CURLOPT_URL, "http://freegeoip.net/json/" . $_SERVER['REMOTE_ADDR']); curl_setopt($get_location, CURLOPT_RETURNTRANSFER, 1); $location = curl_exec($get_location); $location = json_decode($location); // import dream if ($valid) { $date = DateTime::createFromFormat($this->dateFormat, $this->date, new DateTimeZone($this->timezone)); $this->occur_date = $date->format('Y-m-d'); if ($location) { $this->city = $location->city; $this->country = $location->country_name; $this->latitude = $location->latitude; $this->longitude = $location->longitude; } else { $this->latitude = "0"; $this->longitude = "0"; } $success = parent::save(); if ($success) { $this->status = "Dream added!"; } else { if (isset($this->errorMessage)) { $this->status = $this->errorMessage; } else { $this->status = "Error updating dream"; } $valid = false; } } if (isset($image)) { if (!is_null($this->id) && !empty($this->id)) { $image->dream_id = $this->id; $image->save(); } else { $image->delete(); } $this->logger->log($image->logger->log); } if (isset($audio)) { if (!is_null($this->id) && !empty($this->id)) { $audio->dream_id = $this->id; $audio->save(); } else { $audio->delete(); } $this->logger->log($audio->logger->log); } $tags = array(); // add dream tags if ($valid && $this->useAlchemy) { $kb = strlen($this->description) / 1024; if ($kb <= 150) { $alchemy = new AlchemyAPI($this->alchemyApiKey); $params = array(); $params['maxRetrieve'] = 20; $params['keywordExtractMode'] = 'strict'; $params['sentiment'] = 1; $params['showSourceText'] = 0; try { $result = $alchemy->keywords('text', $this->description, $params); $this->logger->log("alchemy " . $result['status'] . ", " . (isset($result['keywords']) ? count($result['keywords']) : 0) . " keywords, " . $this->description); } catch (Exception $e) { $this->logger->log("alchemy, " . $result['status'] . ", " . $result['statusInfo']); } if (isset($result) && $result['status'] == "OK") { foreach ($result['keywords'] as $keyword) { $tag = stripslashes($keyword['text']); $tag = preg_replace("/^\\W|\\W\$|\\./", "", $tag); $tag = strtolower(trim($tag)); $tag = $this->db->real_escape_string($tag); // get tag_id $sql = "SELECT id FROM `tags` WHERE tag='" . $tag . "'"; $result2 = $this->db->query($sql); if ($this->db->affected_rows > 0) { $tag_row = $result2->fetch_assoc(); $tag_id = $tag_row['id']; } else { $sql = "INSERT INTO `tags` (tag,alchemy) VALUES ('" . $tag . "','1')"; $this->db->query($sql); $tag_id = $this->db->insert_id; } if ($tag_id) { $sentiment = $keyword['sentiment']; $sql = "INSERT INTO `dream_tags` (dream_id,tag_id,sentiment_type,sentiment_score) VALUES ('" . $this->id . "','" . $tag_id . "','" . $sentiment['type'] . "','" . (isset($sentiment['score']) ? $sentiment['score'] : 0) . "')"; $this->db->query($sql); } $tags[] = $tag; } } } else { $this->logger->log("Dream " . $this->id . " to big to process" . $kb); } } if ($valid && $this->postToTumblr && $this->tumblrPostEmail != null) { $to = $this->tumblrPostEmail; $subject = isset($this->title) ? $this->title : "untitled"; $body = $this->description; $body .= "\n\nDreamt on " . $this->date . " by a " . $this->age . " year old " . ($this->gender == "male" ? "man" : "woman") . " in " . $location->city; $body .= "\n\nhttp://artefactsofthecollectiveunconscious.net/browse.php?did=" . $this->id; $tagline = ''; foreach ($tags as $tag) { $tagline .= "#" . $tag . " "; } $body .= "\n\n" . $tagline; mail($to, $subject, $body); } if ($valid) { foreach ($this->feelings as $feeling_id) { if ($feeling_id) { $sql = "INSERT INTO `dream_feelings` (dream_id,feeling_id) VALUES ('" . $this->id . "','" . $feeling_id . "')"; $result = $this->db->query($sql); } } } if ($valid) { $this->init(); } return $valid; }
<?php include_once 'config/database.php'; include_once 'repository/Media.php'; $id = isset($_GET['id']) ? $_GET['id'] : die('ERROR: Property id not found.'); $database = new Database(); $db = $database->getConnection(); $media = new Media($db); $media->id = $id; $media->readOne(); $imageName = htmlspecialchars($media->newImageName, ENT_QUOTES); $output_dir = "uploads/"; $dir = opendir($output_dir); $media->delete(); unlink($output_dir . $imageName); closedir($dir);
function saveFeedItem($feedId,$feedVisibility,$item){ global $database, $db, $event; $db->query("SELECT id FROM {$database['prefix']}DeleteHistory WHERE feed='$feedId' and permalink='{$item['permalink']}'"); if ($db->numRows() > 0) return false; if ($item['written']>gmmktime()+86400) return false; $item['title']=$db->escape($db->lessen(UTF8::correct($item['title']))); list($useRssOut) = Settings::gets('useRssOut'); list($feedCreated,$localFilter,$localFilterType) = Feed::gets($feedId, 'created,filter,filterType'); $tagString=$db->escape($db->lessen(UTF8::correct(implode(', ',$item['tags'])))); list($globalFilter,$blackFilter,$globalFilterType,$blackFilterType) = Settings::gets('filter,blackfilter,filterType,blackfilterType'); $filter = empty($globalFilter)?$localFilter:$globalFilter; $filterType = empty($globalFilter)?$localFilterType:$globalFilterType; if (!Validator::is_empty($filter)) { $filtered = true; $allowTags = explode(',', $filter); if($filterType == 'tag' || $filterType == 'tag+title') { foreach ($allowTags as $ftag) { if (Validator::enum($ftag, $tagString)) { $filtered = false; break; } } } if($filtered && ($filterType == 'title' || $filterType == 'tag+title')) { foreach ($allowTags as $ftag) { if(strpos($item['title'],$ftag)!==false) { $filtered = false; break; } } } if ($filtered) return false; } if (!Validator::is_empty($blackFilter)) { $filtered = false; $denyTags = explode(',', $blackFilter); if($blackFilterType == 'tag' || $blackFilterType == 'tag+title') { foreach ($denyTags as $ftag) { if (Validator::enum($ftag, $tagString)) { $filtered = true; break; } } } if($filtered && ($filterType == 'title' || $filterType == 'tag+title')) { foreach ($denyTags as $ftag) { if(strpos($item['title'],$ftag)!==false) { $filtered = true; break; } } } if ($filtered) return false; } if (preg_match('/\((.[^\)]+)\)$/Ui', trim($item['author']), $_matches)) $item['author'] = $_matches[1]; $item['author']=$db->escape($db->lessen(UTF8::correct($item['author']))); $item['permalink']=$db->escape($db->lessen(UTF8::correct($item['permalink']))); $item['description']=$db->escape($db->lessen(UTF8::correct(trim($item['description'])),65535)); $enclosures = array(); foreach($item['enclosures'] as $en) { array_push($enclosures, $en['url']); } $enclosureString=$db->escape($db->lessen(UTF8::correct(implode('|',$enclosures)))); $deadLine=0; $feedLife = Settings::get('archivePeriod'); if ($feedLife > 0) $deadLine=gmmktime()-($feedLife*86400); requireComponent('Bloglounge.Data.FeedItems'); $oldTags = null; $id = FeedItem::getIdByURL($item['permalink']); if($id === false && isset($item['guid'])) { $item['guid']=$db->escape($db->lessen(UTF8::correct($item['guid']))); $id = FeedItem::getIdByURL($item['guid']); } $item['author'] = Feed::getAuthor($item, $feedId, $id); $item['title'] = Feed::getTitle($item, $feedId, $id); $affected = 0; $isRebuildData = false; $summarySave = Settings::get('summarySave'); $description = $item['description']; if(Validator::getBool($summarySave)) { // summarySave $description = func::stripHTML($item['description'].'>'); if (substr($description, -1) == '>') $description = substr($description, 0, strlen($description) - 1); $description = $db->lessen(func::htmltrim($description), 1000, ''); } if (preg_match("/^[0-9]+$/",$id)) { $baseItem = FeedItem::getFeedItem($id); // $baseItem['title']=$db->escape(UTF8::correct($baseItem['title'])); // $baseItem['description']=$db->escape(UTF8::correct(trim($baseItem['description']))); if(($baseItem['title']!=$item['title'])) { $isRebuildData = true; $tags = FeedItem::get($id, 'tags'); requireComponent('LZ.PHP.Media'); Media::delete($id); $oldTags = func::array_trim(explode(',', $tags)); $db->execute("UPDATE {$database['prefix']}FeedItems SET author = '{$item['author']}', title = '{$item['title']}', description = '{$description}', tags = '$tagString', enclosure = '$enclosureString', written = {$item['written']} WHERE id = $id"); } } else { if ($item['written']==0) $item['written']=gmmktime(); if ($item['written']>$deadLine) { $db->execute("INSERT INTO {$database['prefix']}FeedItems (feed, author, permalink, title, description, tags, enclosure, written, feedVisibility) VALUES ($feedId, '{$item['author']}', '{$item['permalink']}', '{$item['title']}', '{$description}', '$tagString', '$enclosureString', {$item['written']},'{$feedVisibility}')"); $id =$db->insertId(); $db->execute('UPDATE '.$database['prefix'].'Feeds SET feedCount=feedCount+1 WHERE id="'.$feedId.'"'); if (isset($this)) $this->updated++; } $isRebuildData = true; } if(Validator::getBool(Settings::get('saveImages'))) { if($description = FeedItem::saveImages($feedId, $id, $item)) { $db->execute("UPDATE {$database['prefix']}FeedItems SET description = '{$description}' WHERE id = $id"); } } $item = $event->on('Add.updateFeedItem', array($feedId, $id, $item)); if(count($item)==3) $item = $item[2]; $result = false; if($isRebuildData) { requireComponent('Bloglounge.Data.Groups'); GroupCategory::buildGroupCategory($id, $feedId, $item['tags']); Tag::buildTagIndex($id, $item['tags'], $oldTags); Category::buildCategoryRelations($id, $item['tags'], $oldTags); $isSaveThumbnail = FeedItem::cacheThumbnail($id, $item); // 썸네일 저장 이벤트 $event->on('Add.thumbnailSave',array($item, $feedId, $id, $isSaveThumbnail)); $result = true; } return $result; }
function deleteByFeedId($feedId) { global $database, $db; $itemIds = array(); requireComponent('LZ.PHP.Media'); requireComponent('Bloglounge.Data.Category'); requireComponent('Bloglounge.Data.Groups'); $result = $db->queryAll("SELECT id FROM {$database['prefix']}FeedItems WHERE feed='$feedId'"); if($result) { foreach($result as $item) { Media::delete($item['id']); array_push($itemIds, $item['id']); } $itemIds = array_unique($itemIds); $categoryIds = array(); foreach($itemIds as $itemId) { $result = $db->queryAll('SELECT category FROM '.$database['prefix'].'Categoryrelations WHERE item = ' . $itemId,MYSQL_ASSOC); foreach($result as $item) { array_push($categoryIds, $item['category']); } } $categoryIds = array_unique($categoryIds); $itemStr = implode(',', $itemIds); $db->execute("DELETE FROM {$database['prefix']}CategoryRelations WHERE item IN ($itemStr)"); // clear CategoryRelations $db->execute("DELETE FROM {$database['prefix']}TagRelations WHERE item IN ($itemStr)"); // clear TagRelations if ($db->execute('DELETE FROM '.$database['prefix'].'FeedItems WHERE feed='.$feedId)) { foreach($categoryIds as $categoryId) { Category::rebuildCount($categoryId); } return true; } else { return false; } } return true; }
<?php require_once '../model/paths.php'; $session = new Session(); if (!$session->isLogin) { redirect("../login.php"); } $database = new Database(); $user = new User(); $post = new Post(); $media = new Media(); // delete media if (isset($_POST['mediaId'])) { $mediaId = $database->escapeString($_POST['mediaId']); $media->setMediaId($mediaId); if ($media->delete($database)) { echo "true"; } else { echo "false"; } }
/** * Reverts the logo back to X2Engine. */ public function actionToggleDefaultLogo() { $adminProf = Yii::app()->params->adminProfile; $logo = Media::model()->findByAttributes(array('associationId' => $adminProf->id, 'associationType' => 'logo')); if (!isset($logo)) { $logo = new Media(); $logo->associationType = 'logo'; $name = 'yourlogohere.png'; $logo->associationId = $adminProf->id; $logo->fileName = 'uploads/protected/logos/' . $name; if ($logo->save()) { } } else { if ($logo->fileName != 'uploads/protected/logos/yourlogohere.png') { $logo->delete(); } } $this->redirect(array('index')); }