// UPLOAD_ERR_NO_FILE = 4 // UPLOAD_ERR_NO_TMP_DIR = 6 // UPLOAD_ERR_OK = 0 // UPLOAD_ERR_PARTIAL = 3 if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { $gal_image = tnb_get_artista_galeria($profileuser->ID, 'images'); $acceptedFormats = array('image/gif', 'image/png', 'image/jpeg', 'image/pjpeg', 'image/x-png'); if (in_array($_FILES['image']['type'], $acceptedFormats)) { $post = array("post_title" => $_POST['image_title'], "post_content" => $_FILES['image']['name'], "post_excerpt" => $_FILES['image']['name'], "post_author" => $profileuser->ID); unset($GLOBALS['post']); $media_id = media_handle_upload('image', $gal_image->ID, $post); if ($media_id->errors) { $msg['error'][] = implode(' ', $media_id->errors['upload_error']); } if (!$msg['error']) { $menu_order = count(tnb_get_artista_fotos($profileuser->ID)); $update = array('ID' => $media_id, 'menu_order' => $menu_order); wp_update_post($update); tnb_cache_unset("ARTISTAS_FOTOS", $profileuser->ID); } } else { $msg['error'][] = __('Tipo de arquivo não permitido', 'tnb'); } } break; case 'edit-image-save': $update = array('ID' => $_POST['mid'], 'post_title' => $_POST['image_title']); wp_update_post($update); $msg['success'][] = __('Foto atualizada', 'tnb'); break; case 'edit-image':
<?php $fotos = tnb_get_artista_fotos($profileuser->ID); ?> <section id="photo" class="content clearfix"> <form method='post' enctype="multipart/form-data" action="<?php echo remove_query_arg(array('tnb_user_action', 'mid', 'mtype')); ?> " > <input type='hidden' name='tnb_user_action' value='<?php echo $edit ? 'edit-image-save' : 'insert-image'; ?> ' /> <h2 class="section-title"> <span class="bg-blue"><?php echo $edit ? __("Editar Foto", "tnb") : __("Nova Foto", "tnb"); ?> </span> </h2> <?php if (!$edit) { ?> <div class="clearfix"> <label><?php _e("Arquivo", "tnb"); ?> </label> <input type="file" name="image" />
protected function update_form() { $formID = uniqid('form'); $fotos = tnb_get_artista_fotos($this->user_id); ?> <h3><?php _e('Fotos', 'tnb'); ?> </h3> <div id='<?php echo $formID; ?> _ecomo'> <?php _e("exibir fotos como", "tnb"); ?> : <label><input type='radio' name='property[exibir_como]' value='galeria' <?php if ($this->property['exibir_como'] == 'galeria') { echo 'checked="checked"'; } ?> ><?php _e('galeria', 'tnb'); ?> </label> <label><input type='radio' name='property[exibir_como]' value='slideshow' <?php if ($this->property['exibir_como'] == 'slideshow') { echo 'checked="checked"'; } ?> ><?php _e('slideshow', 'tnb'); ?> </label> </div> <hr/> <label id='<?php echo $formID; ?> _title_label' for='<?php echo $formID; ?> _title'><?php if ($this->property['exibir_como'] == 'galeria') { _e('título da galeria', 'tnb'); } else { _e('título do slideshow', 'tnb'); } ?> : </label> <input type="text" name='property[title]' value='<?php echo htmlentities(utf8_decode($this->property['title'])); ?> ' /> <hr /> <div id='<?php echo $formID; ?> _efotos'> <?php _e("quais fotos exibir", "tnb"); ?> : <label><input type='radio' name='property[exibir_fotos]' value='todas' <?php if ($this->property['exibir_fotos'] == 'todas') { echo 'checked="checked"'; } ?> ><?php _e('todas', 'tnb'); ?> </label> <label><input type='radio' name='property[exibir_fotos]' value='selecionadas' <?php if ($this->property['exibir_fotos'] == 'selecionadas') { echo 'checked="checked"'; } ?> ><?php _e('somente as selecionadas', 'tnb'); ?> </label> </div> <hr/> <div id='<?php echo $formID; ?> _fotos' <?php if ($this->property['exibir_fotos'] == 'todas') { echo 'class="hide"'; } ?> > <?php _e('clique nas fotos para selecionar as que deseja exibir', 'tnb'); ?> : <div class='clearfix<?php if ($this->property['exibir_fotos'] == 'todas') { echo 'hide'; } ?> '> <?php foreach ($fotos as $foto) { ?> <div id="<?php echo $formID; ?> _widget_foto_<?php echo $foto->ID; ?> " class='<?php if (in_array($foto->ID, $this->property['fotos'])) { echo "selected "; } ?> foto'> <input type="hidden" id='<?php echo $formID; ?> _widget_foto_<?php echo $foto->ID; ?> _input' name="property[fotos][]" value='<?php if (in_array($foto->ID, $this->property['fotos'])) { echo $foto->ID; } ?> ' /> <?php echo wp_get_attachment_image($foto->ID, array(130, 130)); ?> </div> <?php } ?> </div> </div> <script type="text/javascript"> <?php foreach ($fotos as $foto) { ?> jQuery("#<?php echo $formID; ?> _widget_foto_<?php echo $foto->ID; ?> ").click(function(){ if(jQuery("#<?php echo $formID; ?> _widget_foto_<?php echo $foto->ID; ?> _input").val() == ''){ jQuery("#<?php echo $formID; ?> _widget_foto_<?php echo $foto->ID; ?> _input").val("<?php echo $foto->ID; ?> "); jQuery(this).addClass('selected'); }else{ jQuery("#<?php echo $formID; ?> _widget_foto_<?php echo $foto->ID; ?> _input").val(""); jQuery(this).removeClass('selected'); } }); <?php } ?> jQuery('#<?php echo $formID; ?> _ecomo input').change(function(){ if(jQuery(this).val() == 'galeria') jQuery("#<?php echo $formID; ?> _title_label").html('<?php _e('título da galeria'); ?> : '); else jQuery("#<?php echo $formID; ?> _title_label").html('<?php _e('título do slideshow'); ?> : '); }); jQuery('#<?php echo $formID; ?> _efotos input').change(function(){ if(jQuery(this).val() == 'todas') jQuery("#<?php echo $formID; ?> _fotos").slideUp(); else jQuery("#<?php echo $formID; ?> _fotos").slideDown(); }); </script> <?php }