Beispiel #1
0
 function execute($temp_name, $allow_existing_file = false)
 {
     if ($this->_autoRename) {
         $this->_cleanFilename();
         $this->_path_target = $this->_findSafeFilename();
     }
     if (!isset($this->_whitelist[$this->_file_extension])) {
         die('File extension is not permitted.');
     }
     $finfo = new finfo(FILEINFO_MIME);
     $mime_type = $finfo->file($temp_name);
     $mime_type = explode(';', $mime_type);
     $mime_type = $mime_type[0];
     if ($mime_type != $this->_whitelist[$this->_file_extension]) {
         die('File type/extension combination not permitted for security reasons.');
     }
     if (is_uploaded_file($temp_name)) {
         if (!move_uploaded_file($temp_name, $this->_path_target)) {
             return false;
         }
     } elseif ($allow_existing_file) {
         if (!rename($temp_name, $this->_path_target)) {
             return false;
         }
     } else {
         return false;
     }
     chmod($this->_path_target, 0755);
     AMP_s3_save($this->_path_target);
     AMP_lookup_clear_cached('downloads');
     return true;
 }
Beispiel #2
0
 function display_response()
 {
     $renderer =& new AMPDisplay_HTML();
     $this->message(sprintf(AMP_TEXT_DATA_SAVE_SUCCESS, AMP_TEXT_YOUR_COMMENT));
     if ($this->_article_id) {
         AMP_lookup_clear_cached('comments_live_by_article', $this->_article_id);
         ampredirect(AMP_Url_AddVars(AMP_CONTENT_URL_ARTICLE, array('id=' . $this->_article_id)));
     }
     if ($this->_userdata_id) {
         require_once 'AMP/UserData/Lookups.inc.php';
         $form_id_lookup =& FormLookup::instance('modin');
         if (isset($form_id_lookup[$this->_userdata_id])) {
             $target_modin = $form_id_lookup[$this->_userdata_id];
             ampredirect(AMP_Url_AddVars(AMP_CONTENT_URL_FORM_DISPLAY, array('uid=' . $this->_userdata_id, 'modin=' . $target_modin)));
         }
     }
 }
Beispiel #3
0
 function execute($temp_name, $allow_existing_file = false)
 {
     if ($this->_autoRename) {
         $this->_cleanFilename();
         $this->_path_target = $this->_findSafeFilename();
     }
     if (is_uploaded_file($temp_name)) {
         if (!move_uploaded_file($temp_name, $this->_path_target)) {
             return false;
         }
     } elseif ($allow_existing_file) {
         if (!rename($temp_name, $this->_path_target)) {
             return false;
         }
     } else {
         return false;
     }
     chmod($this->_path_target, 0755);
     AMP_s3_save($this->_path_target);
     AMP_lookup_clear_cached('downloads');
     return true;
 }
Beispiel #4
0
 function update_routes()
 {
     AMP_lookup_clear_cached('article_routes');
     AMP_lookup_clear_cached('section_routes');
     AMP_lookup_clear_cached('dispatch_for');
 }
Beispiel #5
0
 function delete()
 {
     if ($image_db_id = $this->db_id()) {
         require_once 'AMP/Content/Image/Image.php';
         $image = new AMP_Content_Image(AMP_Registry::getDbcon(), $image_db_id);
         $image->delete();
         AMP_lookup_clear_cached('images');
         AMP_lookup_clear_cached('db_images');
     }
     $image_classes = AMP_lookup('image_classes');
     foreach ($image_classes as $class => $class_desc) {
         $path = AMP_image_path($this->getName(), $class);
         # delete of current copy handled by parent class below
         if ($path == $this->getPath()) {
             continue;
         }
         if (file_exists($path)) {
             unlink($path);
         }
     }
     return parent::delete();
 }
Beispiel #6
0
 function _manageUpload($data, $filefield)
 {
     if (isset($this->_fileNames[$filefield])) {
         return $this->_fileNames[$filefield];
     }
     if (!(isset($_FILES[$filefield]['tmp_name']) && $_FILES[$filefield]['tmp_name'])) {
         if (!isset($data[$filefield . '_value'])) {
             return false;
         }
         $this->_fileNames[$filefield] = $data[$filefield . '_value'];
         return $this->_fileNames[$filefield];
     }
     require_once 'AMP/System/Upload.inc.php';
     $upLoader =& new AMPSystem_Upload($_FILES[$filefield]['name']);
     $this->_initUploader($data, $filefield, $upLoader);
     if (!$upLoader->execute($_FILES[$filefield]['tmp_name'])) {
         return false;
     }
     require_once 'AMP/Content/Image/Resize.inc.php';
     $reSizer =& new ContentImage_Resize();
     if ($reSizer->setImageFile($upLoader->getTargetPath())) {
         $reSizer->execute();
         AMP_lookup_clear_cached('images');
     }
     $this->_fileNames[$filefield] = basename($upLoader->getTargetPath());
     return $this->_fileNames[$filefield];
 }
function AMP_add_image_subfolder($folder_name)
{
    $ok = false;
    foreach (AMP_lookup('image_classes') as $image_class => $image_class_name) {
        $class_folder = AMP_LOCAL_PATH . AMP_IMAGE_PATH . $image_class . DIRECTORY_SEPARATOR . $folder_name;
        $ok = AMP_mkdir($class_folder);
        if (!$ok) {
            trigger_error('Unable to create folder' . $class_folder);
            break;
        }
    }
    if ($ok) {
        AMP_lookup_clear_cached('image_folders');
        return $folder_name;
    }
    return false;
}
require_once 'JSON/JSON.php';
require_once 'AMP/Base/Config.php';
require_once 'AMP/System/Upload.inc.php';
require_once 'AMP/Content/Image/Resize.inc.php';
require_once 'AMP/User/Profile/Profile.php';
$filefield = 'custom4upload';
$upLoader =& new AMPSystem_Upload($_FILES[$filefield]['name']);
// $this->_initUploader( $data, $filefield, $upLoader );
$upLoader->setFolder(AMP_CONTENT_URL_IMAGES . AMP_IMAGE_CLASS_ORIGINAL);
if (!$upLoader->execute($_FILES[$filefield]['tmp_name'])) {
    return false;
}
$reSizer =& new ContentImage_Resize();
if ($reSizer->setImageFile($upLoader->getTargetPath())) {
    $reSizer->execute();
    AMP_lookup_clear_cached('images');
}
$imagePath = explode('/', $upLoader->getTargetPath());
$imageName = array_pop($imagePath);
if ($imageName) {
    $output = saveUserData($imageName);
    header("HTTP/1.1 200 OK");
    echo $output;
    //	exit();
}
ampredirect('/article.php?list=type&type=12');
function saveUserData($imageName)
{
    $json = new Services_JSON();
    $filefield = 'custom4upload';
    $debug = '';
Beispiel #9
0
 function _save_image_db($data)
 {
     $db_data = $data;
     if (!(isset($data['id']) && $data['id'])) {
         //create new db record
         if (isset($data['folder']) && $data['folder']) {
             $db_data['name'] = $data['folder'] . DIRECTORY_SEPARATOR . $data['image'];
             $db_data['folder'] = $data['folder'];
         } else {
             $db_data['name'] = $data['image'];
         }
         $db_data['publish'] = AMP_CONTENT_STATUS_LIVE;
         $db_data['created_at'] = date("Y-m-d h:i:s");
         $db_data['created_by'] = AMP_SYSTEM_USER_ID;
     } else {
         // update db record
         $db_data['updated_at'] = date("Y-m-d h:i:s");
     }
     //read height and width from image file
     $this->_model->setFile(AMP_image_path($this->_file_name_affected, AMP_IMAGE_CLASS_ORIGINAL));
     $db_data['height'] = $this->_model->height;
     $db_data['width'] = $this->_model->width;
     $this->_model->set_display_metadata($db_data);
     AMP_lookup_clear_cached('db_images');
     require_once 'AMP/Content/Image/Image.php';
     $image = new AMP_Content_Image(AMP_Registry::getDbcon());
     $image->setDefaults();
     //db data has to be merged explicitly to include blank values
     $image->mergeData($db_data);
     $image->mergeData($this->_model->getData());
     return $image->save();
 }
Beispiel #10
0
 function update($item_id, $rating_value)
 {
     if (!AMP_SYSTEM_UNIQUE_VISITOR_ID) {
         return false;
     }
     $session = AMP_SYSTEM_UNIQUE_VISITOR_ID;
     $articles_rated = AMP_lookup('article_ids_rated_by_session', $session);
     if (!isset($articles_rated[$item_id])) {
         return ArticleRating::create($item_id, $rating_value);
     }
     $rating_id = $articles_rated[$item_id];
     $rating = new Rating(AMP_Registry::getDbcon(), $rating_id);
     if (!$rating->hasData()) {
         return false;
     }
     $rating->mergeData(array('rating' => $rating_value, 'updated_at' => date('Y-m-d h:i:s')));
     $result = $rating->save();
     AMP_lookup_clear_cached('article_ids_rated_by_session', $session);
     AMP_lookup_clear_cached('article_ratings_by_session', $session);
     AMP_lookup_clear_cached('article_ratings');
     AMP_lookup_clear_cached('article_ratings_last_week');
     AMP_lookup_clear_cached('article_ratings_last_month');
     return $result;
 }
Beispiel #11
0
 function _after_request()
 {
     if ($this->_request->getPerformedAction() != 'delete' && $this->_request->getPerformedAction() != 'move') {
         return;
     }
     AMP_lookup_clear_cached('images');
     AMP_lookup_clear_cached('db_images');
     AMP_lookup_clear_cached('gallery_images');
     ampredirect($_SERVER['REQUEST_URI']);
 }