1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00
php-e107/e107_admin/image.php

1789 lines
49 KiB
PHP
Raw Normal View History

2006-12-02 04:36:16 +00:00
<?php
/*
2008-12-10 16:59:19 +00:00
* e107 website system
*
2009-11-18 01:06:08 +00:00
* Copyright (C) 2008-2009 e107 Inc (e107.org)
2008-12-10 16:59:19 +00:00
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Image Administration Area
*
* $URL$
* $Id$
2008-12-10 16:59:19 +00:00
*
2006-12-02 04:36:16 +00:00
*/
2012-04-22 06:19:21 +00:00
if (!defined('e107_INIT'))
{
require_once("../class2.php");
}
if (!getperms("A"))
{
2008-12-10 16:59:19 +00:00
header("location:".e_HTTP."index.php");
2006-12-02 04:36:16 +00:00
exit;
}
2008-12-10 16:59:19 +00:00
/*
* CLOSE - GO TO MAIN SCREEN
*/
if(isset($_POST['submit_cancel_show']))
{
header('Location: '.e_SELF);
exit();
}
2009-08-28 16:11:02 +00:00
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
2006-12-02 04:36:16 +00:00
$e_sub_cat = 'image';
2008-12-10 16:59:19 +00:00
// $frm = new e_form(); //new form handler
$emessage = eMessage::getInstance();
2006-12-02 04:36:16 +00:00
class media_admin extends e_admin_dispatcher
{
protected $modes = array(
'main' => array(
'controller' => 'media_admin_ui',
'path' => null,
2009-11-18 07:16:51 +00:00
'ui' => 'media_form_ui',
'uipath' => null
2009-11-18 07:16:51 +00:00
),
'cat' => array(
2010-10-04 16:01:17 +00:00
'controller' => 'media_cat_ui',
2009-11-18 07:16:51 +00:00
'path' => null,
2010-10-04 16:01:17 +00:00
'ui' => 'media_cat_form_ui',
2009-11-18 07:16:51 +00:00
'uipath' => null
)
);
protected $adminMenu = array(
'main/list' => array('caption'=> 'Media Library', 'perm' => 'A'),
'main/create' => array('caption'=> "Add New Media", 'perm' => 'A'), // Should be handled in Media-Import.
2012-04-22 06:19:21 +00:00
'main/import' => array('caption'=> "Media Import", 'perm' => 'A|A2'),
2009-11-18 07:16:51 +00:00
'cat/list' => array('caption'=> 'Media Categories', 'perm' => 'A'),
2012-04-22 06:19:21 +00:00
'cat/create' => array('caption'=> "Create Category", 'perm' => 'A'), // is automatic.
// 'main/icons' => array('caption'=> IMALAN_71, 'perm' => 'A'),
'main/settings' => array('caption'=> LAN_PREFS, 'perm' => 'A'),
'main/avatar' => array('caption'=> IMALAN_23, 'perm' => 'A')
);
/*
$var['main']['text'] = IMALAN_7;
$var['main']['link'] = e_SELF;
$var['icons']['text'] = IMALAN_71;
$var['icons']['link'] = e_SELF."?icons";
$var['avatars']['text'] = IMALAN_23;
$var['avatars']['link'] = e_SELF."?avatars";
$var['editor']['text'] = "Image Manipulation (future release)";
$var['editor']['link'] = e_SELF."?editor";*/
2009-11-18 07:16:51 +00:00
protected $adminMenuAliases = array(
'main/edit' => 'main/list'
);
protected $menuTitle = LAN_MEDIAMANAGER;
}
2010-10-04 16:01:17 +00:00
class media_cat_ui extends e_admin_ui
{
2009-11-18 07:16:51 +00:00
protected $pluginTitle = 'Media Categories';
protected $pluginName = 'core';
protected $table = "core_media_cat";
protected $pid = "media_cat_id";
protected $perPage = 0; //no limit
protected $batchDelete = false;
2012-04-22 06:19:21 +00:00
public $ownerCount = array();
// protected $listQry = "SELECT * FROM #faq_info"; // without any Order or Limit.
2009-11-18 07:16:51 +00:00
// protected $editQry = "SELECT * FROM #faq_info WHERE faq_info_id = {ID}";
2009-11-18 07:16:51 +00:00
protected $fields = array(
//'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'media_cat_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE),
2012-04-22 06:19:21 +00:00
'media_cat_image' => array('title'=> LAN_IMAGE, 'type' => 'image', 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>FALSE, 'batch' => FALSE, 'filter'=>FALSE),
2012-04-22 07:53:34 +00:00
'media_cat_owner' => array('title'=> "Owner", 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
2012-04-22 06:19:21 +00:00
'media_cat_category' => array('title'=> LAN_CATEGORY, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE),
'media_cat_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
'media_cat_diz' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=150&bb=1','readonly'=>FALSE), // Display name
2009-11-18 07:16:51 +00:00
'media_cat_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int'),
2012-04-22 06:19:21 +00:00
'media_cat_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center')
);
2012-04-22 06:19:21 +00:00
function init()
2009-11-18 07:16:51 +00:00
{
2012-04-22 06:19:21 +00:00
$this->fields['media_cat_owner']['writeParms'] = array(
"_common" => "_common",
2012-04-22 07:53:34 +00:00
"_icon" => "_icon",
"news" => "news",
2012-04-22 06:19:21 +00:00
"page" => "page",
2012-04-22 07:53:34 +00:00
"gallery" => "gallery",
"download" => "download"
2012-04-22 06:19:21 +00:00
);
$sql = e107::getDb();
$sql->db_Select_gen("SELECT media_cat_owner, count(media_cat_id) as number FROM `#core_media_cat` GROUP BY media_cat_owner");
while($row = $sql->db_Fetch())
{
$this->ownerCount[$row['media_cat_owner']] = $row['number'];
}
2009-11-18 07:16:51 +00:00
}
2012-04-22 06:19:21 +00:00
public function beforeCreate($new_data)
{
2012-04-22 06:19:21 +00:00
//$replace = array("_"," ","'",'"',"."); //FIXME Improve
//$new_data['media_cat_category'] = str_replace($replace,"-",$new_data['media_cat_category']);
$increment = ($this->ownerCount[$new_data['media_cat_owner']] +1);
$new_data['media_cat_category'] = $new_data['media_cat_owner']."_".$increment;
return $new_data;
}
public function beforeUpdate($new_data, $old_data, $id)
2009-11-18 07:16:51 +00:00
{
2012-04-22 06:19:21 +00:00
$mes = e107::getMessage();
if($new_data['media_cat_owner'] != "gallery")
2009-11-18 07:16:51 +00:00
{
2012-04-22 06:19:21 +00:00
$mes->addError("Modification is not permitted");
return FALSE;
2009-11-18 07:16:51 +00:00
}
2012-04-22 06:19:21 +00:00
return $new_data;
}
}
class media_cat_form_ui extends e_admin_form_ui
{
2010-10-04 16:01:17 +00:00
}
2009-11-18 07:16:51 +00:00
class media_form_ui extends e_admin_form_ui
{
2009-11-18 07:16:51 +00:00
function init()
{
2010-10-04 16:01:17 +00:00
/*$sql = e107::getDb();
2012-04-22 06:19:21 +00:00
// $sql->db_Select_gen("SELECT media_cat_title, media_title_nick FROM #core_media as m LEFT JOIN #core_media_cat as c ON m.media_category = c.media_cat_owner GROUP BY m.media_category");
$sql->db_Select_gen("SELECT media_cat_title, media_cat_owner FROM #core_media_cat");
2009-11-18 07:16:51 +00:00
while($row = $sql->db_Fetch())
{
2012-04-22 06:19:21 +00:00
$cat = $row['media_cat_owner'];
$this->cats[$cat] = $row['media_cat_title'];
2009-11-18 07:16:51 +00:00
}
2010-10-04 16:01:17 +00:00
asort($this->cats);*/
2009-11-18 07:16:51 +00:00
}
2012-04-22 06:19:21 +00:00
function media_category($curVal,$mode) // not really necessary since we can use 'dropdown' - but just an example of a custom function.
2009-11-18 07:16:51 +00:00
{
2012-04-22 06:19:21 +00:00
2009-11-18 07:16:51 +00:00
if($mode == 'read')
{
2010-10-04 16:01:17 +00:00
return $this->getController()->getMediaCategory($curVal);
//return $this->cats[$curVal];
2009-11-18 07:16:51 +00:00
}
2009-11-18 07:16:51 +00:00
if($mode == 'batch') // Custom Batch List for release_type
{
2010-10-04 16:01:17 +00:00
return $this->getController()->getMediaCategory();
2009-11-18 07:16:51 +00:00
}
2009-11-18 07:16:51 +00:00
if($mode == 'filter') // Custom Filter List for release_type
{
2010-10-04 16:01:17 +00:00
return $this->getController()->getMediaCategory();
2009-11-18 07:16:51 +00:00
}
2009-11-18 07:16:51 +00:00
$text = "<select class='tbox>' name='media_category' >";
2010-10-04 16:01:17 +00:00
$cats = $this->getController()->getMediaCategory();
foreach($cats as $key => $val)
2009-11-18 07:16:51 +00:00
{
$selected = ($curVal == $key) ? "selected='selected'" : "";
$text .= "<option value='{$key}' {$selected}>".$val."</option>\n";
}
$text .= "</select>";
return $text;
}
}
class media_admin_ui extends e_admin_ui
{
protected $pluginTitle = LAN_MEDIAMANAGER;
protected $pluginName = 'core';
protected $table = "core_media";
protected $listQry = "SELECT m.*,u.user_id,u.user_name FROM #core_media AS m LEFT JOIN #user AS u ON m.media_author = u.user_id "; // without any Order or Limit.
// //protected $editQry = "SELECT * FROM #comments WHERE comment_id = {ID}";
2009-11-18 07:16:51 +00:00
// protected $tableJoin = array(
// 'u.user' => array('leftField' => 'media_author', 'rightField' => 'user_id', 'fields' => 'user_id,user_loginname,user_name')
// );
protected $pid = "media_id";
protected $perPage = 10;
protected $batchDelete = true;
// protected $defaultOrder = 'desc';
protected $listOrder = 'm.media_id desc'; // show newest images first.
//TODO - finish 'user' type, set 'data' to all editable fields, set 'noedit' for all non-editable fields
2009-11-14 04:13:11 +00:00
/*
* We need a column with a preview that is generated from the path of another field.
* ie. the preview column should show a thumbnail which is generated from the media_url column.
* It needs to also take into consideration the type of media (image, video etc) which comes from another field.
2009-11-14 04:13:11 +00:00
*/
2009-11-14 04:13:11 +00:00
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'data'=> null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'media_id' => array('title'=> LAN_ID, 'type' => 'number', 'data'=> 'int', 'width' =>'5%', 'forced'=> TRUE, 'nolist'=>TRUE),
2012-04-22 06:19:21 +00:00
'media_url' => array('title'=> 'Preview', 'type' => 'image', 'data'=> 'str', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>TRUE, 'writeParams' => 'path={e_MEDIA}', 'width' => '110px'),
'media_category' => array('title'=> LAN_CATEGORY, 'type' => 'method', 'data'=> 'str', 'width' => 'auto', 'filter' => true, 'batch' => true,),
2012-04-22 06:19:21 +00:00
// Upload should be managed completely separately via upload-handler.
'media_upload' => array('title'=> "Upload File", 'type' => 'upload', 'data'=> false, 'readParms' => 'hidden', 'writeParms' => 'disable_button=1', 'width' => '10%', 'nolist' => true),
'media_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data'=> 'str', 'width' => 'auto'),
'media_caption' => array('title'=> "Caption", 'type' => 'text', 'data'=> 'str', 'width' => 'auto'),
// media_description is type = textarea until bbarea can be reduced to not include youtube etc
'media_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'data'=> 'str', 'width' => 'auto', 'thclass' => 'left first', 'readParms' => 'truncate=100', 'writeParms' => 'counter=0'),
'media_type' => array('title'=> "Mime Type", 'type' => 'text', 'data'=> 'str', 'width' => 'auto', 'noedit'=>TRUE),
'media_author' => array('title'=> LAN_USER, 'type' => 'user', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center','readParms' => 'link=1', 'filter' => true, 'batch' => true, 'noedit'=>TRUE ),
'media_datestamp' => array('title'=> LAN_DATESTAMP, 'type' => 'datestamp', 'data'=> 'int', 'width' => '10%', 'noedit'=>TRUE), // User date
'media_size' => array('title'=> "Size", 'type' => 'number', 'data'=> 'int', 'width' => 'auto', 'noedit'=>TRUE),
2012-04-27 02:02:38 +00:00
'media_dimensions' => array('title'=> "Dimensions", 'type' => 'text', 'data'=> 'str', 'width' => '5%', 'readonly'=>TRUE, 'class'=>'nowrap','noedit'=>TRUE),
'media_userclass' => array('title'=> LAN_USERCLASS, 'type' => 'userclass', 'data'=> 'str', 'width' => '10%', 'thclass' => 'center','filter'=>TRUE,'batch'=>TRUE ),
'media_tags' => array('title'=> "Tags/Keywords", 'type' => 'text', 'data'=> 'str', 'width' => '10%', 'filter'=>TRUE,'batch'=>TRUE ),
2010-10-04 16:01:17 +00:00
'media_usedby' => array('title'=> '', 'type' => 'text', 'data'=> 'text', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'nolist'=>true, 'readonly'=>TRUE ),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'data'=> null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center')
);
2009-11-18 07:16:51 +00:00
protected $mimePaths = array(
'text' => e_MEDIA_FILE,
'multipart' => e_MEDIA_FILE,
'application' => e_MEDIA_FILE,
'audio' => e_MEDIA_AUDIO,
'image' => e_MEDIA_IMAGE,
'video' => e_MEDIA_VIDEO,
'other' => e_MEDIA_FILE
2009-11-18 07:16:51 +00:00
);
2009-11-14 04:13:11 +00:00
// protected $fieldpref = array('checkboxes','media_url', 'media_id', 'media_thumb', 'media_title', 'media_caption', 'media_description', 'media_category', 'media_datestamp','media_userclass', 'options');
2009-11-14 04:13:11 +00:00
/*
protected $prefs = array(
'pref_type' => array('title'=> 'type', 'type'=>'text'),
'pref_folder' => array('title'=> 'folder', 'type' => 'boolean'),
'pref_name' => array('title'=> 'name', 'type' => 'text')
);*/
2009-11-18 07:16:51 +00:00
protected $cats = array();
2012-04-22 06:19:21 +00:00
protected $owner = array();
protected $ownercats = array();
function init()
{
$sql = e107::getDb();
2012-04-22 06:19:21 +00:00
// $sql->db_Select_gen("SELECT media_cat_title, media_title_nick FROM #core_media as m LEFT JOIN #core_media_cat as c ON m.media_category = c.media_cat_owner GROUP BY m.media_category");
$sql->db_Select_gen("SELECT media_cat_title, media_cat_owner, media_cat_category FROM #core_media_cat");
while($row = $sql->db_Fetch())
{
2012-04-22 06:19:21 +00:00
$cat = $row['media_cat_category'];
$owner = $row['media_cat_owner'];
$this->owner[$owner] = $owner;
$this->ownercats[$owner.'|'.$cat] = $row['media_cat_title'];
$this->cats[$cat] = $row['media_cat_title'];
}
asort($this->cats);
if(varset($_POST['batch_import_selected']))
{
$this->batchImport();
}
2012-04-22 07:53:34 +00:00
if(varset($_POST['update_options']))
{
$this->updateSettings();
}
if($this->getQuery('iframe'))
2012-04-30 10:39:03 +00:00
{
if($this->getQuery('bbcode'))
{
e107::getJs()->headerFile(e_PLUGIN_ABS.'tinymce/tiny_mce_popup.js',2);
e107::getJS()->headerInline("
/* Send the generated IMG bbcode back to the textarea/window */
function saveBB()
{
var add = document.getElementById('bbcode_holder').value;
addtext(add);
// tinyMCE.execCommand('mceInsertContent',false,'hi there');
tinyMCEPopup.close();
//parent.e107Widgets.DialogManagerDefault.getWindow('e-dialog').close();
return false;
}
");
}
$this->getResponse()->setIframeMod(); // disable header/footer menus etc.
if(!$this->getQuery('for'))
{
$this->setPosted('media_category', "_common");
$this->getModel()->set('media_category', "_common");
}
elseif($this->getMediaCategory($this->getQuery('for')))
{
$this->setPosted('media_category', $this->getQuery('for'));
if(!$this->getId())
{
$this->getModel()->set('media_category', $this->getQuery('for'));
}
}
2012-04-30 10:39:03 +00:00
}
//
// if($this->getQuery('for') && $this->getMediaCategory($this->getQuery('for')))
// {
//
// $this->setPosted('media_category', $this->getQuery('for'));
// if(!$this->getId())
// {
// $this->getModel()->set('media_category', $this->getQuery('for'));
// }
// }
//
}
function dialogPage() // Popup dialogPage for Image Selection.
{
// $this->getModel()->setAction('create');
// $this->getUI()->getController()->getRequest()->setAction('create');
//$this->setAction('create');;
if($_POST['etrigger_submit'])
{
$data = $this->beforeCreate($_POST);
e107::getDb()->db_Insert('core_media',$data); // Replace with Generic (needs parm sent)
}
echo $this->imageSelectUpload();
}
function imageSelectUpload()
{
2012-04-30 10:39:03 +00:00
$frm = e107::getForm();
$bbcodeMode = ($this->getQuery('bbcode')==1) ? 'bbcode=1' : FALSE;
$text = "
<div class='admintabs' id='tab-container'>
<ul class='e-tabs e-hideme' id='core-emote-tabs'>
<li id='tab-select'><a href='#core-media-select'>Choose from Library</a></li>
2012-04-30 10:39:03 +00:00
<li id='tab-upload'><a href='#core-media-upload'>Upload a File</a></li>";
if($bbcodeMode)
{
$text .= "<li id='tab-style'><a href='#core-media-style'>Appearance</a></li>\n";
}
$text .= "
</ul>
<fieldset id='core-media-select'>
<legend>Library</legend>
<table cellpadding='0' cellspacing='0' class='adminedit'>
<tbody><tr><td>
2012-04-29 11:15:44 +00:00
";
2012-04-30 10:39:03 +00:00
$text .= e107::getMedia()->mediaSelect($this->getQuery('for'),$this->getQuery('tagid'),$bbcodeMode); // eg. news, news-thumbnail
2012-04-29 11:15:44 +00:00
$text .= "
</td></tr>
</tbody></table>
</fieldset>
<fieldset id='core-media-upload'>
<legend>Upload</legend>";
$this->fields['media_category']['readonly'] = TRUE;
$this->fields['media_url']['noedit'] = TRUE;
$this->fields['media_userclass']['noedit'] = TRUE;
$text .= $this->CreatePage();
$text .= "
2012-04-30 10:39:03 +00:00
</fieldset>";
/* In BBCODE-Mode this dialog rerturns an [img] bbcode to the 'tagid' container with the appropriate parms generated.
* eg. [img style=float:left;margin-right:3px]{e_MEDIA_IMAGE}someimage.jpg[/img]
* Then the dialog may be used as a bbcode img popup and within TinyMce also.
*
*/
if($bbcodeMode)
{
$text .= "<fieldset id='core-media-style'>
<legend>Appearance</legend>
<table cellpadding='0' cellspacing='0' class='adminedit'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
<tbody>
<tr>
<td>Dimensions: </td>
<td>
<input type='text' id='width' name='width' size='4' style='width:50px' value='' onkeyup='updateBB()' /> px
X <input type='text' id='height' name='height' size='4' style='width:50px' value='' onkeyup='updateBB()' /> px
</td>
</tr>
<tr>
<td>Text flow: </td>
<td>".$frm->selectbox('float', array('default'=>'Default','left'=>'Right','right'=>"Left"))."</td>
</tr>
<tr>
<td>Margin-Left: </td>
<td><input type='text' id='margin-left' name='margin_left' value='' onkeyup='updateBB()' /></td>
</tr>
<tr>
<td>Margin-Right: </td>
<td><input type='text' id='margin-right' name='margin_right' value='' onkeyup='updateBB()' /></td>
</tr>
<tr>
<td>Margin-Top: </td>
<td><input type='text' id='margin-top' name='margin_top' value='' onkeyup='updateBB()' /></td>
</tr>
<tr>
<td>Margin-Bottom: </td>
<td><input type='text' id='margin-bottom' name='margin_bottom' value='' onkeyup='updateBB()' /></td>
</tr>
</tbody></table>
</fieldset>";
}
$text .= "</div>";
// For BBCODE mode. //TODO image-float.
if($bbcodeMode)
{
$text .= "To be Hidden<br />
bbcode: <input type='text' style='width:800px' id='bbcode_holder' name='bbcode_holder' value='' /><br />
html: <input type='text' style='width:800px' id='html_holder' name='html_holder' value='' />
<br />src: <input type='text' style='width:600px' id='src' name='src' value='' />
";
$text .= "<div style='text-align:right;padding:5px'>
<button type='submit' class='submit' name='save_image' value='Save' onclick=\"saveBB();\" >
<span>Save</span>
</button>
<button type='submit' class='submit' name='cancel_image' value='Cancel' onclick=\"parent.e107Widgets.DialogManagerDefault.getWindow('e-dialog').close();\" >
<span>Cancel</span>
</button>
</div>";
2012-04-30 10:39:03 +00:00
e107::getJs()->footerInline("
/* Generate an IMG bbcode based on input by user */
function updateBB()
{
var style = '';
var bb = '';
var src = document.getElementById('src').value;
var width = document.getElementById('width').value;
var height = document.getElementById('height').value;
var margin_top = document.getElementById('margin-top').value;
var margin_bottom = document.getElementById('margin-bottom').value;
var margin_right = document.getElementById('margin-right').value;
var margin_left = document.getElementById('margin-left').value;
if(width !='')
{
style = style + 'width:' + width + 'px;';
}
if(height !='')
{
style = style + 'height:' + height + 'px;';
}
if(margin_right !='')
{
style = style + 'margin-right:' + margin_right + 'px;';
}
if(margin_left !='')
{
style = style + 'margin-left:' + margin_left + 'px;';
}
if(margin_top !='')
{
style = style + 'margin-top:' + margin_top + 'px;';
}
if(margin_bottom !='')
{
style = style + 'margin-bottom:' + margin_bottom + 'px;';
}
bb = '[img';
if(style !='')
{
bb = bb + ' style='+style;
}
bb = bb + ']';
bb = bb + src;
bb = bb + '[/img]';
document.getElementById('bbcode_holder').value = bb;
var html = '<img src=\''+ src +'\' style=\'' + style + '\' />';
document.getElementById('html_holder').value = html;
}
");
}
return $text;
}
function importPage()
{
$this->batchImportForm();
}
function settingsPage()
{
main_config();
}
function avatarPage()
{
show_avatars();
}
function iconsPage()
{
// $this->icon_editor();
}
/**
* Invoked just before item create event
* @return array
*/
public function beforeCreate($new_data)
{
// print_a($_POST);
// return data to be merged with posted model data
2009-11-18 07:16:51 +00:00
$this->getRequest()->setPosted('media_upload', null);
//$dataFields = $this->getModel()->getDataFields();
//unset($dataFields['media_upload']);
2010-10-04 16:01:17 +00:00
//$this->getModel()->setDataFields($dataFields);
if($this->getQuery('for') && $this->getMediaCategory($this->getQuery('for')))
{
$new_data['media_category'] = $this->getQuery('for');
}
2009-11-18 09:53:39 +00:00
return $this->observeUploaded($new_data);
}
/**
* Same as beforeCreate() but invoked on edit
2009-12-13 21:52:32 +00:00
* @return TBD
*/
public function beforeUpdate($new_data, $old_data, $id)
{
// return data to be merged with posted model data
return $this->observeUploaded($new_data);
}
2010-10-04 16:01:17 +00:00
public function mediaData($sc_path)
{
if(!$sc_path) return array();
$path = e107::getParser()->replaceConstants($sc_path);
$info = e107::getFile()->get_file_info($path);
return array(
2010-10-04 16:01:17 +00:00
'media_type' => $info['mime'],
'media_datestamp' => time(),
'media_url' => e107::getParser()->createConstants($path, 'rel'),
'media_size' => filesize($path),
'media_author' => USERID,
'media_usedby' => '',
'media_tags' => '',
'media_dimensions' => $info['img-width']." x ".$info['img-height']
);
}
// XXX - strict mysql error on Create without UPLOAD!
2009-11-18 09:53:39 +00:00
function observeUploaded($new_data)
{
$fl = e107::getFile();
2009-11-18 07:16:51 +00:00
$mes = e107::getMessage();
if(vartrue($_FILES['file_userfile'])) // CREATE
{
2012-04-27 02:02:38 +00:00
2010-10-04 16:01:17 +00:00
$pref['upload_storagetype'] = "1";
require_once(e_HANDLER."upload_handler.php"); //TODO - still not a class!
$uploaded = process_uploaded_files(e_MEDIA.'temp/'); //FIXME doesn't handle xxx.JPG (uppercase)
$upload = array_shift($uploaded);
2009-11-18 07:16:51 +00:00
if(vartrue($upload['error']))
{
$mes->addError($upload['message']);
2012-04-27 02:02:38 +00:00
return FALSE;
}
2010-10-04 16:01:17 +00:00
if(!$typePath = $this->getPath($upload['type']))
{
$mes->addError("Couldn't generated path from upload data");
2010-10-04 16:01:17 +00:00
return FALSE;
}
$mes->addDebug(print_a($upload,TRUE));
$oldpath = e_MEDIA."temp/".$upload['name'];
$newpath = $this->checkDupe($oldpath,$typePath.'/'.$upload['name']);
if(!rename($oldpath, e_MEDIA.$newpath))
2010-10-04 16:01:17 +00:00
{
$mes->add("Couldn't move file from ".$oldpath." to ".$newpath, E_MESSAGE_ERROR);
return FALSE;
};
$img_data = $this->mediaData($newpath); // Basic File Info only
$img_data['media_name'] = $new_data['name'];
$img_data['media_caption'] = $new_data['media_caption'];
$img_data['media_category'] = $new_data['media_category'];
$img_data['media_description'] = $new_data['media_description'];
$img_data['media_tags'] = $new_data['media_tags'];
$img_data['media_userclass'] = 0;
$img_data['media_author'] = USERID;
if(!varset($img_data['media_name']))
2010-10-04 16:01:17 +00:00
{
$img_data['media_name'] = $upload['name'];
}
2012-04-27 02:02:38 +00:00
$mes->addDebug(print_a($img_data,TRUE));
return $img_data;
2010-10-04 16:01:17 +00:00
}
else // Update Only ?
2010-10-04 16:01:17 +00:00
{
2010-10-04 16:01:17 +00:00
$img_data = $this->mediaData($new_data['media_url']);
2010-10-04 16:01:17 +00:00
if(!($typePath = $this->getPath($img_data['media_type'])))
{
2012-04-27 02:02:38 +00:00
$mes->addError("Couldn't get path ".$typePath);
2009-11-18 09:53:39 +00:00
return FALSE;
}
2012-04-27 02:02:38 +00:00
2010-10-04 16:01:17 +00:00
$fname = basename($new_data['media_url']);
// move to the required place
if(strpos($new_data['media_url'], '{e_MEDIA}temp/') !== FALSE)
2009-11-18 09:53:39 +00:00
{
2010-10-04 16:01:17 +00:00
$tp = e107::getParser();
$oldpath = $tp->replaceConstants($new_data['media_url']);
$newpath = $this->checkDupe($oldpath,$typePath.'/'.$fname);
2010-10-04 16:01:17 +00:00
if(!rename($oldpath, $newpath))
{
$mes->add("Couldn't move file from ".$oldpath." to ".str_replace('../', '', $newpath), E_MESSAGE_ERROR);
return FALSE;
}
$img_data['media_url'] = $tp->createConstants($newpath, 'rel');
2009-11-18 07:16:51 +00:00
}
2009-11-18 09:53:39 +00:00
if(!varset($new_data['media_name']))
{
2010-10-04 16:01:17 +00:00
$img_data['media_name'] = basename($new_data['media_url']);
2009-11-18 09:53:39 +00:00
}
return $img_data;
}
2012-04-27 02:02:38 +00:00
}
// Check for existing image path in db and rename if found.
function checkDupe($oldpath,$newpath)
{
$mes = e107::getMessage();
$tp = e107::getParser();
$f = e107::getFile()->get_file_info($oldpath,TRUE);
// $mes->addDebug("checkDupe(): newpath=".$newpath."<br />oldpath=".$oldpath."<br />".print_r($upload,TRUE));
if(file_exists($newpath) || e107::getDb()->db_Select("core_media","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
{
// $mes->addWarning($newpath." already exists and was renamed during import.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
$newpath = $this->getPath($f['mime']).'/'.$file;
}
return $newpath;
}
function beforeDelete($data, $id) // call before 'delete' is executed. - return false to prevent delete execution (e.g. some dependencies check)
{
return true;
}
function afterDelete($deleted_data, $id) // call after 'delete' is successfully executed. - delete the file with the db record (optional pref)
{
}
function getPath($mime)
{
2009-11-18 07:16:51 +00:00
$mes = e107::getMessage();
list($pmime,$tmp) = explode('/',$mime);
2009-11-18 07:16:51 +00:00
if(!vartrue($this->mimePaths[$pmime]))
{
2010-10-10 22:08:57 +00:00
$mes->add("Couldn't detect mime-type($mime). Upload failed.", E_MESSAGE_ERROR);
2009-11-18 07:16:51 +00:00
return FALSE;
}
$dir = $this->mimePaths[$pmime].date("Y-m");
2009-11-18 07:16:51 +00:00
if(!is_dir($dir))
{
if(!mkdir($dir, 0755))
2009-11-18 10:16:50 +00:00
{
$mes->add("Couldn't create folder ($dir).", E_MESSAGE_ERROR);
return FALSE;
2009-11-18 10:16:50 +00:00
};
}
return $dir;
}
function batchImportForm()
{
$frm = e107::getForm();
$mes = e107::getMessage();
$fl = e107::getFile();
$fl->setFileInfo('all');
$files = $fl->get_files(e_MEDIA."temp/");
2010-10-04 16:01:17 +00:00
e107::getJs()->requireCoreLib('core/admin.js');
//TODO Detect XML file, and if found - read that instead of the directory.
if(!vartrue($_POST['batch_import_selected']))
{
$mes->add("Scanning for new media (images, videos, files) in folder: ".e_MEDIA."temp/", E_MESSAGE_INFO);
}
if(!count($files))
{
$mes->add("No media Found! Please upload some files and then refresh this page.", E_MESSAGE_INFO);
return;
}
$text = "
<form method='post' action='".e_SELF."?".e_QUERY."' id='batch_import'>
<fieldset id='core-mediamanager-batch'>
<legend class='e-hideme'>".DBLAN_20."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='4'>
<col style='width: 5%'></col>
<col></col>
<col></col>
<col></col>
</colgroup>
<thead>
<tr>
2010-10-04 16:01:17 +00:00
<th class='center'>".e107::getForm()->checkbox_toggle('e-column-toggle', 'batch_selected')."</th>
<th class='center' style='width:50px'>Preview</th>
<th class='center'>".LAN_FILE."</th>
2012-04-22 06:19:21 +00:00
<th >Title</th>
<th >Caption</th>
<th>Mime Type</th>
<th>File Size</th>
<th>".LAN_DATESTAMP."</th>
<th class='center last'>Dimensions</th>
</tr>
</thead>
<tbody>";
2012-04-22 06:19:21 +00:00
$c = 0;
foreach($files as $f)
{
2012-04-22 07:53:34 +00:00
$text .= "
<tr>
<td class='center'>".$frm->checkbox("batch_selected[".$c."]",$f['fname'])."</td>
2012-04-22 06:19:21 +00:00
<td class='center'>".$this->preview($f)."</td>
<td>".$f['fname']."</td>
2012-04-22 07:53:34 +00:00
<td>".$frm->text('batch_import_name['.$c.']', ($_POST['batch_import_name'][$c] ? $_POST['batch_import_name'][$c] : $f['fname']))."</td>
<td>".$frm->textarea('batch_import_diz['.$c.']', $_POST['batch_import_diz'][$c])."</td>
<td>".$f['mime']."</td>
<td>".$f['fsize']."</td>
<td>".e107::getDateConvert()->convert_date($f['modified'])."</td>
<td class='center last'>".$f['img-width']." x ".$f['img-height']."</td>
2012-04-22 07:53:34 +00:00
</tr>
\n";
2012-04-22 06:19:21 +00:00
$c++;
}
$text .= "
</tbody>
</table>
<div class='buttons-bar center'>
Import into Category: ".$frm->selectbox('batch_category',$this->cats);
$waterMarkPath = e_THEME.e107::getPref('sitetheme')."/images/watermark.png";
if(is_readable($waterMarkPath))
{
$text .= $frm->checkbox_label("Add Watermark", 'batch_import_watermark',1);
}
$text .= "
</div>
<div class='buttons-bar center'>
".$frm->admin_button('batch_import_selected', "Import Selected Files", 'import');
$text .= "
</div>
</fieldset>
</form>
";
echo $mes->render().$text;
}
function batchImport()
{
$fl = e107::getFile();
$mes = e107::getMessage();
$sql = e107::getDb();
$tp = e107::getParser();
2011-07-10 23:21:09 +00:00
if(!count($_POST['batch_selected']))
{
$mes->addError("Please check at least one image.");
return;
}
2012-04-22 06:19:21 +00:00
require(e_HANDLER.'phpthumb/ThumbLib.inc.php'); // For resizing on import.
list($img_import_w,$img_import_h) = explode("x",e107::getPref('img_import_resize'));
if(vartrue($_POST['batch_import_watermark']))
{
$WM = TRUE;
$watermarkPath = e_THEME.e107::getPref('sitetheme')."/images/watermark.png";
$watermark = PhpThumbFactory::create($watermarkPath);
}
else
{
$WM = FALSE;
}
2012-04-22 06:19:21 +00:00
foreach($_POST['batch_selected'] as $key=>$file)
{
2012-04-22 06:19:21 +00:00
$oldpath = e_MEDIA."temp/".$file;
// Resize on Import Routine ------------------------
if(vartrue($img_import_w) && vartrue($img_import_h))
{
try
{
$thumb = PhpThumbFactory::create($oldpath);
$thumb->setOptions(array('correctPermissions' => true));
}
catch (Exception $e)
{
$mes->addError($e->getMessage());
continue;
// return $this;
}
if($WM) // TODO Add watermark prefs for alpha and position.
{
$thumb->resize($img_import_w,$img_import_h)->addWatermark($watermark, 'rightBottom', 30, 0, 0)->save($oldpath);
}
else
{
$thumb->resize($img_import_w,$img_import_h)->save($oldpath);
}
}
// End Resize routine. ---------------------
$f = $fl->get_file_info($oldpath);
2010-10-10 22:08:57 +00:00
if(!$f['mime'])
{
$mes->add("Couldn't get file info from : ".$oldpath, E_MESSAGE_ERROR);
2010-10-10 22:08:57 +00:00
}
$newpath = $this->checkDupe($oldpath,$this->getPath($f['mime']).'/'.$file);
2012-04-22 06:19:21 +00:00
$newname = $tp->toDB($_POST['batch_import_name'][$key]);
$newdiz = $tp->toDB($_POST['batch_import_diz'][$key]);
$f['fname'] = $file;
2012-04-22 06:19:21 +00:00
/*
if(file_exists($newpath) || $sql->db_Select("core_media","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
{
$mes->addWarning($newpath." already exists and was renamed during import.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
$newpath = $this->getPath($f['mime']).'/'.$file;
}
*/
2012-04-22 07:53:34 +00:00
if(rename($oldpath,$newpath))
{
$insert = array(
2012-04-22 06:19:21 +00:00
'media_caption' => $newdiz,
'media_description' => '',
'media_category' => $_POST['batch_category'],
'media_datestamp' => $f['modified'],
'media_url' => $tp->createConstants($newpath,'rel'),
'media_userclass' => 0,
2012-04-22 06:19:21 +00:00
'media_name' => $newname,
'media_author' => USERID,
'media_size' => $f['fsize'],
'media_dimensions' => $f['img-width']." x ".$f['img-height'],
'media_usedby' => '',
'media_tags' => '',
'media_type' => $f['mime']
);
if($sql->db_Insert("core_media",$insert))
{
$mes->add("Importing Media: ".$f['fname'], E_MESSAGE_SUCCESS);
}
else
{
rename($newpath,$oldpath); //move it back.
}
}
}
}
function preview($f)
{
list($type,$tmp) = explode("/",$f['mime']);
if($type == 'image')
{
2010-10-04 16:01:17 +00:00
$url = e107::getParser()->thumbUrl($f['path'].$f['fname'], 'w=100', true);
//echo $url;
return "<img src='".$url."' alt=\"".$f['name']."\" width='50px' />";
}
else
{
return; //TODO generic icon/image for no preview.
}
}
2010-10-04 16:01:17 +00:00
public function getMediaCategory($id = false)
{
if($id) return (isset($this->cats[$id]) ? $this->cats[$id] : 0);
return $this->cats;
}
2012-04-22 07:53:34 +00:00
/*
* UPDATE IMAGE OPTIONS - MAIN SCREEN
*/
function updateSettings()
{
global $pref,$admin_log,$tp;
$mes = e107::getMessage();
$tmp = array();
$tmp['image_post'] = intval($_POST['image_post']);
$tmp['resize_method'] = $tp->toDB($_POST['resize_method']);
$tmp['im_path'] = trim($tp->toDB($_POST['im_path']));
$tmp['image_post_class'] = intval($_POST['image_post_class']);
$tmp['image_post_disabled_method'] = intval($_POST['image_post_disabled_method']);
$tmp['enable_png_image_fix'] = intval($_POST['enable_png_image_fix']);
if($_POST['img_import_resize_w'] && $_POST['img_import_resize_h'])
{
$tmp['img_import_resize'] = intval($_POST['img_import_resize_w'])."x".intval($_POST['img_import_resize_h']);
}
if ($admin_log->logArrayDiffs($tmp, $pref, 'IMALAN_04'))
{
save_prefs(); // Only save if changes
$mes->add(IMALAN_9, E_MESSAGE_SUCCESS);
}
else
{
$mes->add(IMALAN_20, E_MESSAGE_INFO);
}
}
2006-12-02 04:36:16 +00:00
}
new media_admin();
require_once(e_ADMIN."auth.php");
e107::getAdminUI()->runPage();
// -----------------------------------------------------------------------
$action = e_QUERY;
if(varset($_GET['action']) == "icons")
{
// icon_editor();
}
if(varset($_GET['action']) == "avatars")
{
// show_avatars();
}
if(varset($_GET['action']) == 'settings')
{
// main_config();
}
2008-12-10 16:59:19 +00:00
/*
* DELETE CHECKED AVATARS - SHOW AVATAR SCREEN
*/
2008-12-10 16:59:19 +00:00
if (isset($_POST['submit_show_delete_multi']))
{
if(varset($_POST['multiaction']))
{
$tmp = array(); $tmp1 = array(); $message = array();
foreach ($_POST['multiaction'] as $todel)
{
$todel = explode('#', $todel);
$todel[1] = basename($todel[1]);
$image_type = 2;
if(strpos($todel[1], '-upload-') === 0)
{
$image_type = 1;
$todel[1] = substr($todel[1], strlen('-upload-'));
}
//delete it from server
@unlink(e_UPLOAD."avatars/".$todel[1]);
2008-12-10 16:59:19 +00:00
//admin log & sysmessage
$message[] = $todel[1];
//It's owned by an user
if($todel[0])
{
switch ($image_type)
{
case 1: //avatar
$tmp[] = intval($todel[0]);
break;
case 2: //photo
$tmp1[] = intval($todel[0]);
break;
}
}
}
//Reset all deleted user avatars with one query
if(!empty($tmp))
{
$sql->db_Update("user", "user_image='' WHERE user_id IN (".implode(',', $tmp).")");
}
//Reset all deleted user photos with one query
if(!empty($tmp1))
{
$sql->db_Update("user", "user_sess='' WHERE user_id IN (".implode(',', $tmp1).")");
}
unset($tmp, $tmp1);
//Format system message
if(!empty($message))
{
$admin_log->log_event('IMALAN_01', implode('[!br!]', $message), E_LOG_INFORMATIVE, '');
$emessage->add(implode(', ', $message).' '.IMALAN_28, E_MESSAGE_SUCCESS);
2008-12-10 16:59:19 +00:00
}
}
}
2008-12-10 16:59:19 +00:00
/*
* DELETE ALL UNUSED IMAGES - SHOW AVATAR SCREEN
*/
if (isset($_POST['submit_show_deleteall']))
{
$handle = opendir(e_UPLOAD."avatars/");
2008-12-10 16:59:19 +00:00
$dirlist = array();
while ($file = readdir($handle)) {
if (!is_dir(e_UPLOAD."avatars/{$file}") && $file != '.' && $file != '..' && $file != "index.html" && $file != "null.txt" && $file != '/' && $file != 'CVS' && $file != 'Thumbs.db') {
2006-12-02 04:36:16 +00:00
$dirlist[] = $file;
}
}
closedir($handle);
2008-12-10 16:59:19 +00:00
if(!empty($dirlist))
{
2008-12-10 16:59:19 +00:00
$imgList = '';
$count = 0;
foreach ($dirlist as $image_name)
{
$image_name = basename($image_name);
$image_todb = $tp->toDB($image_name);
if (!$sql->db_Count('user', '(*)', "WHERE user_image='-upload-{$image_todb}' OR user_sess='{$image_todb}'")) {
unlink(e_UPLOAD."avatars/".$image_name);
2008-12-10 16:59:19 +00:00
$imgList .= '[!br!]'.$image_name;
$count++;
}
2006-12-02 04:36:16 +00:00
}
2008-12-10 16:59:19 +00:00
$message = $count." ".IMALAN_26;
$emessage->add($message, E_MESSAGE_SUCCESS);
2008-12-10 16:59:19 +00:00
$admin_log->log_event('IMALAN_02', $message.$imgList,E_LOG_INFORMATIVE, '');
unset($imgList);
2006-12-02 04:36:16 +00:00
}
}
2008-12-10 16:59:19 +00:00
/*
* DELETE ALL CHECKED BAD IMAGES - VALIDATE SCREEN
*/
if (isset($_POST['submit_avdelete_multi']))
{
2006-12-02 04:36:16 +00:00
require_once(e_HANDLER."avatar_handler.php");
$avList = array();
2008-12-10 16:59:19 +00:00
$tmp = array();
$uids = array();
//Sanitize
$_POST['multiaction'] = $tp->toDB($_POST['multiaction']);
//sql queries significant reduced
if(!empty($_POST['multiaction']) && $sql->db_Select("user", 'user_id, user_name, user_image', "user_id IN (".implode(',', $_POST['multiaction']).")"))
2006-12-02 04:36:16 +00:00
{
2008-12-10 16:59:19 +00:00
$search_users = $sql->db_getList('ALL', FALSE, FALSE, 'user_id');
foreach($_POST['multiaction'] as $uid)
{
2008-12-10 16:59:19 +00:00
if (varsettrue($search_users[$uid]))
{
$avname = avatar($search_users[$uid]['user_image']);
if (strpos($avname, "http://") === FALSE)
{ // Internal file, so unlink it
@unlink($avname);
}
$uids[] = $uid;
$tmp[] = $search_users[$uid]['user_name'];
$avList[] = $uid.':'.$search_users[$uid]['user_name'].':'.$search_users[$uid]['user_image'];
2006-12-02 04:36:16 +00:00
}
}
2008-12-10 16:59:19 +00:00
//sql queries significant reduced
if(!empty($uids))
{
$sql->db_Update("user", "user_image='' WHERE user_id IN (".implode(',', $uids).")");
}
$emessage->add(IMALAN_51.'<strong>'.implode(', ', $tmp).'</strong> '.IMALAN_28, E_MESSAGE_SUCCESS);
2008-12-10 16:59:19 +00:00
$admin_log->log_event('IMALAN_03', implode('[!br!]', $avList), E_LOG_INFORMATIVE, '');
2008-12-12 09:55:33 +00:00
2008-12-10 16:59:19 +00:00
unset($search_users);
2006-12-02 04:36:16 +00:00
}
2008-12-10 16:59:19 +00:00
unset($avList, $tmp, $uids);
2006-12-02 04:36:16 +00:00
}
2008-12-10 16:59:19 +00:00
2006-12-02 04:36:16 +00:00
2008-12-10 16:59:19 +00:00
/*
* SHOW AVATARS SCREEN
*/
function show_avatars()
{
global $e107, $pref;
$ns = e107::getRender();
$sql = e107::getDb();
$frm = e107::getForm();
$tp = e107::getParser();
$mes = e107::getMessage();
$handle = opendir(e_UPLOAD."avatars/"); //TODO replace with $fl
2008-12-10 16:59:19 +00:00
$dirlist = array();
while ($file = readdir($handle))
{
if ($file != '.' && $file != '..' && $file != "index.html" && $file != "null.txt" && $file != '/' && $file != 'CVS' && $file != 'Thumbs.db' && !is_dir($file))
{
2006-12-02 04:36:16 +00:00
$dirlist[] = $file;
}
}
closedir($handle);
$text = '';
2006-12-02 04:36:16 +00:00
2008-12-10 16:59:19 +00:00
if (empty($dirlist))
{
2006-12-02 04:36:16 +00:00
$text .= IMALAN_29;
}
else
{
$text = "
<form method='post' action='".e_SELF."?avatars' id='core-iamge-show-avatars-form'>
2008-12-10 16:59:19 +00:00
<fieldset id='core-iamge-show-avatars'>
";
$count = 0;
while (list($key, $image_name) = each($dirlist))
{
2006-12-02 04:36:16 +00:00
$users = IMALAN_21." | ";
2008-12-10 16:59:19 +00:00
$row = array('user_id' => '');
$image_pre = '';
$disabled = false;
2008-12-10 16:59:19 +00:00
if ($sql->db_Select("user", "*", "user_image='-upload-".$tp->toDB($image_name)."' OR user_sess='".$tp->toDB($image_name)."'"))
{
$row = $sql->db_Fetch();
2008-12-10 16:59:19 +00:00
if($row['user_image'] == '-upload-'.$image_name) $image_pre = '-upload-';
$users .= "<a href='".$e107->url->create('user/profile/view', 'name='.$row['user_name'].'&id='.$row['user_id'])."'>{$row['user_name']}</a> <span class='smalltext'>(".($row['user_sess'] == $image_name ? IMALAN_24 : IMALAN_23).")</span>";
}
else
{
$users = '<span class="warning">'.IMALAN_22.'</span>';
2006-12-02 04:36:16 +00:00
}
2008-12-10 16:59:19 +00:00
//directory?
if(is_dir(e_UPLOADE."avatars/".$image_name))
2008-12-10 16:59:19 +00:00
{
//File info
$users = "<a class='e-tooltip' href='#' title='".IMALAN_69.": {$image_name}'><img class='icon S16' src='".e_IMAGE_ABS."admin_images/info_16.png' alt='".IMALAN_66.": {$image_name}' /></a> <span class='error'>".IMALAN_69."</span>";
2008-12-10 16:59:19 +00:00
//Friendly UI - click text to select a form element
$img_src = '<span class="error">'.IMALAN_70.'</span>';
$disabled = true;
}
2008-12-10 16:59:19 +00:00
else
{
//File info
$users = "<a class='e-tooltip' href='#' title='".IMALAN_66.": {$image_name}'><img src='".e_IMAGE_ABS."admin_images/info_16.png' alt='".IMALAN_66.": {$image_name}' /></a> ".$users;
2008-12-10 16:59:19 +00:00
// Control over the image size (design)
$image_size = getimagesize(e_UPLOAD."avatars/".$image_name);
2008-12-10 16:59:19 +00:00
//Friendly UI - click text to select a form element
$img_src = "<label for='image-action-{$count}' title='".IMALAN_56."'><img src='".e_FILE_ABS."public/avatars/{$image_name}' alt='{$image_name}' /></label>";
if ($image_size[0] > $pref['im_width'] || $image_size[1] > $pref['im_height'])
{
$img_src = "<a class='image-preview' href='".e_FILE_ABS."public/avatars/".rawurlencode($image_name)."' rel='external'>".IMALAN_57."</a>";
}
}
2008-12-10 16:59:19 +00:00
//style attribute allowed here - server side width/height control
//autocheck class - used for JS selectors (see eCoreImage object)
$text .= "
<div class='image-box f-left center autocheck' style='width: ".(intval($pref['im_width'])+40)."px; height: ".(intval($pref['im_height'])+100)."px;'>
<div class='spacer'>
<div class='image-users'>{$users}</div>
<div class='image-preview'>{$img_src}</div>
<div class='image-delete'>
".$frm->checkbox('multiaction[]', "{$row['user_id']}#{$image_pre}{$image_name}", false, array('id' => false, 'disabled' => $disabled))."
</div>
</div>
</div>
";
$count++;
2006-12-02 04:36:16 +00:00
}
$text .= "
<div class='spacer clear'>
2008-12-10 16:59:19 +00:00
<div class='buttons-bar'>
<input type='hidden' name='show_avatars' value='1' />
".$frm->admin_button('check_all', LAN_CHECKALL, 'action')."
".$frm->admin_button('uncheck_all', LAN_UNCHECKALL, 'action')."
".$frm->admin_button('submit_show_delete_multi', LAN_DELCHECKED, 'delete')."
".$frm->admin_button('submit_show_deleteall', IMALAN_25, 'delete')."
".$frm->admin_button('submit_cancel_show', IMALAN_68, 'cancel')."
2008-12-10 16:59:19 +00:00
</div>
</div>
2008-12-10 16:59:19 +00:00
</fieldset>
2006-12-02 04:36:16 +00:00
</form>
";
2006-12-02 04:36:16 +00:00
}
echo $mes->render().$text;
return;
// $ns->tablerender(LAN_MEDIAMANAGER." :: ".IMALAN_18, $mes->render().$text);
2006-12-02 04:36:16 +00:00
}
2008-12-10 16:59:19 +00:00
/*
* CHECK AVATARS SCREEN
*/
if (isset($_POST['check_avatar_sizes']))
{
2006-12-02 04:36:16 +00:00
// Set up to track what we've done
//
$iUserCount = 0;
$iAVinternal = 0;
$iAVexternal = 0;
$iAVnotfound = 0;
$iAVtoobig = 0;
require_once(e_HANDLER."avatar_handler.php");
$text = "
<form method='post' action='".e_SELF."'>
2008-12-10 16:59:19 +00:00
<fieldset id='core-image-check-avatar'>
<legend class='e-hideme'>".CACLAN_3."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
2008-12-10 16:59:19 +00:00
<colgroup span='4'>
<col style='width:10%'></col>
<col style='width:20%'></col>
<col style='width:25%'></col>
<col style='width:45%'></col>
</colgroup>
<thead>
<tr>
<th class='center'>".LAN_OPTIONS."</th>
<th class='center'>".LAN_USER."</th>
<th class='center'>".IMALAN_62."</th>
<th class='center last'>".LAN_URL."</th>
</tr>
</thead>
<tbody>
";
2006-12-02 04:36:16 +00:00
//
// Loop through avatar field for every user
//
$iUserCount = $sql->db_Count("user");
2008-12-10 16:59:19 +00:00
$found = false;
$allowedWidth = intval($pref['im_width']);
$allowedHeight = intval($pref['im_width']);
2006-12-02 04:36:16 +00:00
if ($sql->db_Select("user", "*", "user_image!=''")) {
2008-12-10 16:59:19 +00:00
while ($row = $sql->db_Fetch())
{
2008-12-10 16:59:19 +00:00
//Check size
$avname=avatar($row['user_image']);
if (strpos($avname,"http://")!==FALSE)
2006-12-02 04:36:16 +00:00
{
$iAVexternal++;
$bAVext=TRUE;
} else {
$iAVinternal++;
$bAVext=FALSE;
}
2008-12-10 16:59:19 +00:00
2006-12-02 04:36:16 +00:00
$image_stats = getimagesize($avname);
$sBadImage="";
2008-12-10 16:59:19 +00:00
2006-12-02 04:36:16 +00:00
if (!$image_stats)
{
$iAVnotfound++;
// allow delete
$sBadImage=IMALAN_42;
2008-12-10 16:59:19 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
$imageWidth = $image_stats[0];
$imageHeight = $image_stats[1];
2008-12-10 16:59:19 +00:00
if ( ($imageHeight > $allowedHeight) || ($imageWidth > $allowedWidth) )
2006-12-02 04:36:16 +00:00
{ // Too tall or too wide
$iAVtoobig++;
2008-12-10 16:59:19 +00:00
if ($imageWidth > $allowedWidth)
{
2006-12-02 04:36:16 +00:00
$sBadImage = IMALAN_40." ($imageWidth)";
}
2008-12-10 16:59:19 +00:00
if ($imageHeight > $allowedHeight)
{
2006-12-02 04:36:16 +00:00
if (strlen($sBadImage))
{
$sBadImage .= ", ";
}
$sBadImage .= IMALAN_41." ($imageHeight)";
}
}
}
2008-12-10 16:59:19 +00:00
//If not found or too large, allow delete
2006-12-02 04:36:16 +00:00
if (strlen($sBadImage))
{
2008-12-10 16:59:19 +00:00
$found = true;
2006-12-02 04:36:16 +00:00
$text .= "
<tr>
<td class='autocheck center'>
2008-12-10 16:59:19 +00:00
<input class='checkbox' type='checkbox' name='multiaction[]' id='avdelete-{$row['user_id']}' value='{$row['user_id']}' />
</td>
<td>
2008-12-10 16:59:19 +00:00
<label for='avdelete-{$row['user_id']}' title='".IMALAN_56."'>".IMALAN_51."</label><a href='".e_BASE."user.php?id.{$row['user_id']}'>".$row['user_name']."</a>
</td>
<td>".$sBadImage."</td>
<td>".$avname."</td>
2006-12-02 04:36:16 +00:00
</tr>";
}
2008-12-10 16:59:19 +00:00
}
}
//Nothing found
if(!$found)
{
$text .= "
<tr>
<td colspan='4' class='center'>".IMALAN_65."</td>
2008-12-10 16:59:19 +00:00
</tr>
";
2006-12-02 04:36:16 +00:00
}
2008-12-10 16:59:19 +00:00
2006-12-02 04:36:16 +00:00
$text .= "
</tbody>
</table>
<div class='buttons-bar'>
2008-12-10 16:59:19 +00:00
<input type='hidden' name='check_avatar_sizes' value='1' />
".$frm->admin_button('check_all', LAN_CHECKALL, 'action')."
".$frm->admin_button('uncheck_all', LAN_UNCHECKALL, 'action')."
".$frm->admin_button('submit_avdelete_multi', LAN_DELCHECKED, 'delete')."
</div>
</fieldset>
</form>
<table cellpadding='0' cellspacing='0' class='adminform'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
2008-12-10 16:59:19 +00:00
</colgroup>
<tbody>
<tr>
<td>".IMALAN_38."</td>
<td>{$allowedWidth}</td>
2008-12-10 16:59:19 +00:00
</tr>
<tr>
<td>".IMALAN_39."</td>
<td>{$allowedHeight}</td>
2008-12-10 16:59:19 +00:00
</tr>
<tr>
<td>".IMALAN_45."</td>
<td>{$iAVnotfound}</td>
2008-12-10 16:59:19 +00:00
</tr>
<tr>
<td>".IMALAN_46."</td>
<td>{$iAVtoobig}</td>
2008-12-10 16:59:19 +00:00
</tr>
<tr>
<td>".IMALAN_47."</td>
<td>{$iAVinternal}</td>
2008-12-10 16:59:19 +00:00
</tr>
<tr>
<td>".IMALAN_48."</td>
<td>{$iAVexternal}</td>
2008-12-10 16:59:19 +00:00
</tr>
<tr>
<td>".IMALAN_49."</td>
<td>".($iAVexternal+$iAVinternal)." (".(int)(100.0*(($iAVexternal+$iAVinternal)/$iUserCount)).'%, '.$iUserCount." ".IMALAN_50.")</td>
2008-12-10 16:59:19 +00:00
</tr>
</tbody>
</table>
";
2006-12-02 04:36:16 +00:00
$ns->tablerender(IMALAN_37, $emessage->render().$text);
2006-12-02 04:36:16 +00:00
}
2008-12-10 20:54:06 +00:00
/*
* MAIN CONFIG SCREEN
*/
function main_config()
{
global $pref;
$frm = e107::getForm();
$tp = e107::getParser();
$sql = e107::getDb();
$ns = e107::getRender();
$mes = e107::getMessage();
if(function_exists('gd_info'))
{
$gd_info = gd_info();
$gd_version = $gd_info['GD Version'];
}
else
{
$gd_version = "<span class='error'> ".IMALAN_55."</span>";
}
$IM_NOTE = "";
if($pref['im_path'] != "")
{
$im_file = $pref['im_path'].'convert';
if(!file_exists($im_file))
{
$IM_NOTE = "<span class='error'>".IMALAN_52."</span>";
}
else
{
$cmd = "{$im_file} -version";
$tmp = `$cmd`;
if(strpos($tmp, "ImageMagick") === FALSE)
{
$IM_NOTE = "<span class='error'>".IMALAN_53."</span>";
}
}
}
$text = "
<form method='post' action='".e_SELF."?".e_QUERY."'>
<fieldset id='core-image-settings'>
<legend class='e-hideme'>".IMALAN_7."</legend>
<table cellpadding='0' cellspacing='0' class='adminform'>
<colgroup span='2'>
<col class='col-label'></col>
<col class='col-control'></col>
</colgroup>
<tbody>
<tr>
<td class='label'>
".IMALAN_1."
</td>
<td class='control'>
<div class='auto-toggle-area autocheck'>
".$frm->checkbox('image_post', 1, $pref['image_post'])."
2009-10-29 12:39:21 +00:00
<div class='field-help'>".IMALAN_2."</div>
</div>
</td>
</tr>
<tr>
<td class='label'>
".IMALAN_10."
</td>
<td class='control'>
".r_userclass('image_post_class',$pref['image_post_class'],"off","public,guest,nobody,member,admin,main,classes")."
2009-10-29 12:39:21 +00:00
<div class='field-help'>".IMALAN_11."</div>
</td>
</tr>
<tr>
<td class='label'>
".IMALAN_12."
</td>
<td class='control'>
".$frm->select_open('image_post_disabled_method')."
".$frm->option(IMALAN_14, '0', ($pref['image_post_disabled_method'] == "0"))."
".$frm->option(IMALAN_15, '1', ($pref['image_post_disabled_method'] == "1"))."
".$frm->select_close()."
2009-10-29 12:39:21 +00:00
<div class='field-help'>".IMALAN_13."</div>
</td>
</tr>";
list($img_import_w,$img_import_h) = explode("x",$pref['img_import_resize']);
//TODO LANS
$text .= "
<tr>
<td class='label'>Resize images during media import<div class='label-note'>Leave empty to disable</div></td>
<td class='control'>
".$frm->text('img_import_resize_w', $img_import_w,4)."px X ".$frm->text('img_import_resize_h', $img_import_h,4)."px
<div class='field-help'>".IMALAN_6."</div>
</td>
</tr>
<tr>
<td class='label'>".IMALAN_3."<div class='label-note'>".IMALAN_54." {$gd_version}</div></td>
<td class='control'>
".$frm->select_open('resize_method')."
".$frm->option('gd1', 'gd1', ($pref['resize_method'] == "gd1"))."
".$frm->option('gd2', 'gd2', ($pref['resize_method'] == "gd2"))."
".$frm->option('ImageMagick', 'ImageMagick', ($pref['resize_method'] == "ImageMagick"))."
".$frm->select_close()."
2009-10-29 12:39:21 +00:00
<div class='field-help'>".IMALAN_4."</div>
</td>
</tr>
<tr>
<td class='label'>".IMALAN_5."<div class='label-note'>{$IM_NOTE}</div></td>
<td class='control'>
".$frm->text('im_path', $pref['im_path'])."
2009-10-29 12:39:21 +00:00
<div class='field-help'>".IMALAN_6."</div>
</td>
</tr>
<tr>
<td class='label'>".IMALAN_34."
</td>
<td class='control'>
<div class='auto-toggle-area autocheck'>
".$frm->checkbox('enable_png_image_fix', 1, ($pref['enable_png_image_fix']))."
2009-10-29 12:39:21 +00:00
<div class='field-help'>".IMALAN_35."</div>
</div>
</td>
</tr>
<tr>
<td class='label'>".IMALAN_36."</td>
<td class='control'>
".$frm->admin_button('check_avatar_sizes', ADLAN_145)."
</td>
</tr>
</tbody>
</table>
<div class='buttons-bar center'>
".$frm->admin_button('update_options', IMALAN_8, 'update')."
</div>
</fieldset>
</form>";
echo $mes->render().$text;
return;
$ns->tablerender(LAN_MEDIAMANAGER." :: ".IMALAN_7, $mes->render().$text);
}
//Just in case...
if(!e_AJAX_REQUEST) require_once("footer.php");
2006-12-02 04:36:16 +00:00
2008-12-10 16:59:19 +00:00
/**
* Handle page DOM within the page header
*
* @return string JS source
*/
//function headerjs()
//{
// require_once(e_HANDLER.'js_helper.php');
// //FIXME - how exactly to auto-call JS lan? This and more should be solved in Stage II.
// $ret = "
// <script type='text/javascript'>
// //add required core lan - delete confirm message
// (".e_jshelper::toString(LAN_JSCONFIRM).").addModLan('core', 'delete_confirm');
// </script>
// <script type='text/javascript' src='".e_FILE_ABS."jslib/core/admin.js'></script>
// ";
//
// return $ret;
//}
?>