Jump to content

Recommended Posts

For starters I just want to say that i'm clueless when it comes to PHP, I'm more of a flash actioncript programmer.

 

Ok my problem is that I have this one cms video page which gives the user the option in a  combo box to either chose editing "youtube URL"  or "FLV upload" and being that youtube section is not workiog for me I would like to take it out of the combo box and have the "Flv upload " section be the one that the users first  sees,  cause right now the "youtube" combo option and "youtube url" input window is the one that comes up first.

 

If any one can help me I would greatly appreciate it and the more good karma for you.

 

Thank you in advance, here is the php code

 

<?
/*================INIT SETTINGS===============*/
if (!defined('IN_APP')) die('No direct access.');

$module_actions = Array(
                        array('prefix'=>'items','title'=>'Videos'),
                        array('prefix'=>'preview','title'=>'Preview'),
                        array('prefix'=>'settings','title'=>'Module settings')
                        );

/*================END OF INIT SETTINGS===============*/


function gen_items_list() {
GLOBAL $_cm,$_cmsettings;
$rows = array();
$caption = 'Videos';
$headers = Array(
                array('text'=>'Image','width'=>$_cmsettings['img_max_width']+10),
                array('text'=>'Description','width'=>'400'),
                );

$query = 'SELECT `id`, `title`, SUBSTR(`description`,1,50) AS `description`,`thumb` FROM `^$^items` WHERE 1 ORDER BY `ordering` ASC';
$arts = _q($query);

$id = (!empty($_GET['id'])) ? (int)$_GET['id'] : -1;
$i=0;
foreach ($arts as $art)
  {
    $rows[$i]['data'][0] = '<img alt="" src="'.$_cm.'/data/'.$art['thumb'].'" />';
    $rows[$i]['data'][1] = '<b>'.$art['title'].'</b><br /><small>'.$art['description'].'</small>';
    $rows[$i]['ondclick'] = 'location.href=\'admin.php?module='.$_cm.'&sub=items&act=edit&id='.$art['id'].'\'';
    $rows[$i]['selected'] = ($id == $art['id']) ? true : false;
    $i++;
  }

$k = gen_table($caption,$headers,$rows);
return $k;
}

function gen_edit_form_items($id) {
GLOBAL $_cm;
$current = 'New video';
$allowed_img = array('jpg','jpeg','png','gif');
$allowed_flv = array('flv');
$arty = Array(
              'id' => -1,
              'title' => '',
              'description' => '',
              'thumb' => '',
              'type' => 1,
              'youtube' => '',
              'youtube_params' => '',
              'ordering' => ''
              );

$query = 'SELECT * FROM `^$^items` WHERE `id`='.$id.' LIMIT 1';
$art = _q($query);

if ($art) {
$arty['id'] = $art[0]['id'];
$arty['title'] = $art[0]['title'];
$arty['description'] = $art[0]['description'];
$arty['thumb'] = $art[0]['thumb'];
$arty['type'] = $art[0]['type'];
$arty['youtube'] = $art[0]['youtube'];
$arty['youtube_params'] = $art[0]['youtube_params'];
$arty['ordering'] = $art[0]['ordering'];
$current = $art[0]['title'];
}

$query = 'SELECT * FROM `^$^items` WHERE 1 ORDER BY `ordering` ASC';
$cats = _q($query);

$current_ordering=-1;
$dropdown = '<select name="ordering" class="input">';
foreach ($cats as $cat) {
if ($id == $cat['id'])
{
  $current = $cat['title'];$current_ordering=$cat['ordering'];}
  else {
  $k = ($cat['ordering']-1 == $current_ordering) ? ' selected' : '';
  $dropdown .= '<option value="'.$cat['ordering'].'"'.$k.'>'.htmlspecialchars($cat['title']).'</otion>';
  }
}

$last = $cats[count($cats)-1]['ordering'];

if ($current_ordering == -1) {
$current_ordering = $last+1;
}
$k = ($current_ordering >=$last) ? ' selected' : '';
$dropdown .= '<option value="'.($last+1).'"'.$k.'>-make it last-</option></select>';

$out .= '<table class="workplace" border="0" cellpadding="0" cellspacing="0"><tr><td><h1>'.$current.'</h1>
<form action="admin.php?module='.$_cm.'&sub=items" method="POST" id="fieldsForm" enctype="multipart/form-data" name="frmData">
<table border="0" cellpadding="0" cellspacing="0" class="editfields">';
if ($id > 0)
  {
    if ($arty['type'] == 1)
      $out .= '<tr><td>'._preview_item($arty['thumb']).'</td><td class="fieldtitle">'._preview_item($id.'.flv').'</td></tr>';
    else
      $out .= '<tr><td>'._preview_item($arty['thumb']).'</td><td class="fieldtitle">'._preview_item($arty['youtube']).'</td></tr>';
  }
$type_selector = '<select name="type" onchange="do_type_change(this.value)" id="videotype">';
if ($arty['type'] == 1)
  {
      $type_selector .= '<option value="1">Youtube video</option><option value="2" selected>FLV file</option>';
  } else $type_selector .= '<option value="1" selected>Youtube video</option><option value="2">FLV file</option>';
$type_selector .= '</select>';

$out .='<tr><td class="fieldtitle">Title:</td><td><input type="text" class="input" name="title" value="'.htmlspecialchars($arty['title']).'"/></td></tr>
<tr><td class="fieldtitle">Video type:</td><td>'.$type_selector.'</td></tr>
<tr id="youtube_tr"><td class="fieldtitle">Youtube URL:</td><td><input type="text" class="input" name="youtube" value="'.htmlspecialchars($arty['youtube']).'"/></td></tr>
<tr id="flv_tr"><td class="fieldtitle">Upload FLV file <small>(max '._max_upload().')</small>:</td><td>'._swfupload('flv',$allowed_flv).'</td></tr>
<tr id="flv_thumb"><td class="fieldtitle">Upload THUMB file:</td><td>'._swfupload('thumb',$allowed_img).'</td></tr>
<tr><td class="fieldtitle">Place before:</td><td>'.$dropdown.'</td></tr>
<tr><td class="fieldtitle">Description:</td><td><textarea class="textarea" name="description">'.htmlspecialchars($arty['description']).'</textarea></td></tr>
<tr><td class="editbuttons" colspan="2">
<input type="hidden" name="thumb" value="" />
<input type="hidden" name="thumb_tname" value="" />
<input type="hidden" name="flv" value="" />
<input type="hidden" name="flv_tname" value="" />
<input type="hidden" name="act" id="formAct" value="save"/>
<input type="hidden" name="current_ordering" value="'.$current_ordering.'"/>
<input type="hidden" name="id" value="'.$id.'"/>
<input type="button" class="button" value="Save" onclick="multi_Upload('.$id.');"/>
<input type="button" class="button" value="Cancel" onclick="location.href=\'admin.php?module='.$_cm.'&sub=items\'"/>
<input type="button" class="button" value="Delete" onclick="if(confirm(\'Are you sure?\')) {var d=document; d.getElementById(\'formAct\').value=\'delete\'; d.getElementById(\'fieldsForm\').submit();}"/>
</td></tr>
</table>
</form></tr></td></table>
<script language="javascript">
var formcount = 0;
var filesloaded = 0;

function multi_Upload(id) {
vt = document.getElementById("videotype").value;
if (vt == 1)
  {
    formcount = 1;
    document.getElementById("fieldsForm").submit();
  } else {
    
    formcount = 2;
    thumb_Upload(id);
    flv_Upload(id);
  }
}


function do_type_change(vl) {
var d = document;
if (vl == 1)
  {
    d.getElementById(\'youtube_tr\').style.display="";
    d.getElementById(\'flv_tr\').style.display="none";
    d.getElementById(\'flv_thumb\').style.display="none";
  } else {
            d.getElementById(\'youtube_tr\').style.display="none";
            d.getElementById(\'flv_tr\').style.display="";
            d.getElementById(\'flv_thumb\').style.display="";
         }
}
do_type_change('.$arty['type'].');
</script>
';

return $out;
}

function reorder_items($current_ordering,$ordering) {
  if ($current_ordering != ($ordering-1))
    {
    if ($current_ordering > $ordering)
    $query = 'UPDATE `^$^items` SET `ordering` = `ordering`+1 WHERE (`ordering`>='.$ordering.') && (`ordering`<'.$current_ordering.')';
    else
    $query = 'UPDATE `^$^items` SET `ordering` = `ordering`-1 WHERE (`ordering`<'.$ordering.') && (`ordering`>'.$current_ordering.')';
    $k = _q($query,FALSE);
    }

}

function do_save_items() {
GLOBAL $_cm,$_cmsettings;

$allowed_flv = array('flv');
$actions_flv = array();
$allowed_img = array('jpg','jpeg','png','gif');
$actions_img = array(
                array('title' => 'resize','max_width' => $_cmsettings['img_max_width'],'max_height' => $_cmsettings['img_max_height'])
                );


$type = (int)$_POST['type'];
$type = ($type == 2) ? 2 : 1;

if (!empty($_POST['id'])) {
$id = (int)$_POST['id'];
$current_ordering = (int)$_POST['current_ordering'];
$ordering = (int)$_POST['ordering'];

if ($id>0)
  {
  reorder_items($current_ordering,$ordering);
  $ordering = ($ordering == 1) ? 2 : $ordering;
  $description = mysql_real_escape_string(stripslashes($_POST['description']));
  $title = mysql_real_escape_string(stripslashes($_POST['title']));
  $youtube = mysql_real_escape_string(stripslashes($_POST['youtube']));

  $query = 'UPDATE `^$^items` SET `title`=\''.$title.'\', `description`=\''.$description.'\', `ordering`='.($ordering-1).' WHERE `id`='.$id.' LIMIT 1';
  $k = _q($query,FALSE);
  
  if ($type == 2)
  {
    $flv = stripslashes($_POST['flv']);
    $fname = stripslashes($_POST['flv_tname']);

    if ($flv != '') {
      $f_flv = _upload_file($fname,$id.'.flv',$allowed_flv,$actions_flv,$flv);
      if ($f_flv['error']) 
        {
          die($f_flv['errorText']);
        }
      @rename($_cm.'/data/'.$f_flv['filename'],$_cm.'/data/'.$id.'.flv');
      $query = 'UPDATE `^$^items` SET `type`='.$type.' WHERE `id`='.$id.' LIMIT 1';
    }
  } else 
    {
      $v = _get_youtube_video($youtube);
      if ($v == FALSE)
        {
          die('Can\'t find video. Plase check entered url and <a href="javascript:history.back();">try again</a>');
        }
      $query = 'UPDATE `^$^items` SET `youtube`=\''.$youtube.'\', `youtube_params`=\''.$v.'\', `cached`=0 WHERE `id`='.$id.' LIMIT 1';
    }
  $k = _q($query,FALSE);


        $thumb = stripslashes($_POST['thumb']);
        $tname = stripslashes($_POST['thumb_tname']);
  
        if ($thumb != '') 
        {
          $query = 'SELECT `thumb` FROM `^$^items` WHERE `id`='.$id.' LIMIT 1';
          $art = _q($query);
        $arty['thumb'] = $art[0]['thumb'];

        $f_img = _upload_file($tname,$arty['thumb'],$allowed_img,$actions_img,$thumb);
        if (!$f_img['error']) 
          {
            $query = 'UPDATE `^$^items` SET `thumb` =\''.$f_img['filename'].'\' WHERE `id`='.$id.' LIMIT 1';
            $k = _q($query,FALSE);
          }
        }

  } else {
  $youtube = mysql_real_escape_string(stripslashes($_POST['youtube']));
  if ($type == 2)
  {
  
  $flv = stripslashes($_POST['flv']);
  $fname = stripslashes($_POST['flv_tname']);

  $f_flv = _upload_file($fname,'',$allowed_flv,$actions_flv,$flv);

    if ($f_flv['error']) 
      {
        die($f_flv['errorText']);
      }
  } else 
    {
      $v = _get_youtube_video($youtube);
      if ($v == FALSE)
        {
          die('Can\'t find video. Plase check entered url and <a href="javascript:history.back();">try again</a>');
        }
    }
  reorder_items($current_ordering,$ordering);
  $description = mysql_real_escape_string(stripslashes($_POST['description']));
  $title = mysql_real_escape_string(stripslashes($_POST['title']));

  $query = 'INSERT INTO `^$^items` (`title`,`description`,`type`,`ordering`) VALUES (\''.$title.'\', \''.$description.'\', '.$type.', '.$ordering.')';
  $k = _q($query,FALSE);
  $kk = mysql_insert_id();
  
  if ($type == 2) 
    {
      @rename($_cm.'/data/'.$f_flv['filename'],$_cm.'/data/'.$kk.'.flv');
    } else 
      {
        $query = 'UPDATE `^$^items` SET `youtube` =\''.$youtube.'\', `youtube_params` = \''.$v.'\' WHERE `id`='.$kk.' LIMIT 1';
        $k = _q($query,FALSE);
      }  
  
  
  $thumb = stripslashes($_POST['thumb']);
  $tname = stripslashes($_POST['thumb_tname']);

  $f_img = _upload_file($tname,'',$allowed_img,$actions_img,$thumb);

  if (!$f_img['error']) 
   {
      $query = 'UPDATE `^$^items` SET `thumb` =\''.$f_img['filename'].'\' WHERE `id`='.$kk.' LIMIT 1';
      $k = _q($query,FALSE);
   }
  
  }
}
}

function do_delete_items() {
GLOBAL $_cm;

if (!empty($_POST['id'])) {
$id = (int)$_POST['id'];
if ($id>0)
  {
  $current_ordering = (int)$_POST['current_ordering'];
  reorder_items($current_ordering,1000000);
  
  $query = 'SELECT `thumb` FROM `^$^items` WHERE `id`='.$id.' LIMIT 1';
  $art = _q($query);

  if ($art) {
  $arty['thumb'] = $art[0]['thumb'];
  @unlink($_cm.'/data/'.$id.'.flv');
  @unlink($_cm.'/data/'.$arty['thumb']);
  }
  $query = 'DELETE FROM `^$^items` WHERE `id`='.$id.' LIMIT 1';
  $k = _q($query,FALSE);
  }
}
}


function do_items() {
GLOBAL $_cm;
$edit_form = '';

if (!empty($_POST['act'])) {
switch ($_POST['act']) {
case 'save': do_save_items(); break;
case 'delete': do_delete_items(); break;
}
}

if (!empty($_GET['act'])) {
switch ($_GET['act']) {
case 'edit': 
              $id = (!empty($_GET['id'])) ? (int)$_GET['id'] : -1;
              $edit_form = gen_edit_form_items($id);  break;
}

}

$cat_list = gen_items_list();
echo '<input type="button" class="button" value="Add new video" onclick="location.href=\'admin.php?module='.$_cm.'&sub=items&act=edit&id=-1\'" style="margin-left:5px;"/><br style="clear:both"/><br style="clear:both"/>
<div style="float:left;">'.$cat_list.'</div>'.$edit_form.'<br style="clear:both"/>';
}


function do_xml() {
GLOBAL $_url,$_cm,$_preview;
$_p = $_url.'/';
$xml = '<module>
  <module_title><![CDATA[%module_title%]]></module_title>';
$xml .= '<videos>';

$query = 'SELECT * FROM `^$^settings` WHERE 1 ORDER BY `id` ASC';
$items = _q($query);
foreach ($items as $item)
$xml = str_replace('%'.$item['field_name'].'%',$item['value'],$xml);


$query = 'SELECT * FROM `^$^items` WHERE 1 ORDER BY `ordering` ASC';
$items = _q($query);
$tm = time();
foreach ($items as $item)
  {
    $xml .= '<video><title><![CDATA['.$item['title'].']]></title>';
    $xml .= '<description><![CDATA['.$item['description'].']]></description>'."\n";

      if ($item['type'] == 1)
      {
        if (($tm - $item['cached']) > 60*60*1)
        {
            $videolink = _getvideobyid($item['youtube_params']);
            $query = 'UPDATE `^$^items` SET `cached`='.$tm.', `videolink`=\''.mysql_real_escape_string(stripslashes($videolink)).'\' WHERE `id`='.$item['id'].' LIMIT 1';
            _q($query,FALSE);
            $item['videolink'] = $videolink;

        }
        $xml .= '<path><![CDATA['.$item['videolink'].']]></path>'."\n";
      }
      else
      $xml .= '<path><![CDATA['.$_p.$_cm.'/data/'.$item['id'].'.flv]]></path>'."\n";
    $xml .= '<thumb><![CDATA['.$_p.$_cm.'/data/'.$item['thumb'].']]></thumb></video>'."\n";
  }    
$xml .= '</videos>';

$k= '  <smooth_videos><![CDATA[%smooth_videos%]]></smooth_videos>
  <buffering_time><![CDATA[%buffering_time%]]></buffering_time>
  <autoplay_videos><![CDATA[%autoplay_videos%]]></autoplay_videos>
  <loop_videos_list><![CDATA[%loop_videos_list%]]></loop_videos_list>
  <initial_volume><![CDATA[%initial_volume%]]></initial_volume>
  <control_volume_via_mousewheel><![CDATA[%control_volume_via_mousewheel%]]></control_volume_via_mousewheel>
  <open_videos_list_on_load><![CDATA[%open_videos_list_on_load%]]></open_videos_list_on_load>
  <video_title_color><![CDATA[%video_title_color%]]></video_title_color>
  <video_description_color><![CDATA[%video_description_color%]]></video_description_color>
  <video_thumb_title_color><![CDATA[%video_thumb_title_color%]]></video_thumb_title_color>
  <video_thumb_description_color><![CDATA[%video_thumb_description_color%]]></video_thumb_description_color>
  <videos_list_background_color><![CDATA[%videos_list_background_color%]]></videos_list_background_color>
  <videos_list_slider_color><![CDATA[%videos_list_slider_color%]]></videos_list_slider_color>
  <video_controls_background_color><![CDATA[%video_controls_background_color%]]></video_controls_background_color></module>';

$query = 'SELECT * FROM `^$^settings` WHERE 1 ORDER BY `id` ASC';
$items = _q($query);
foreach ($items as $item)
$k = str_replace('%'.$item['field_name'].'%',$item['value'],$k);

echo $xml.$k;
}

/*==========================1.. 2.. 3.. GO!!! ==============================*/
$_cmsub = ($_cmsub == '') ? $module_actions[0]['prefix'] : $_cmsub;
echo get_toolbar($module_actions,$_cmsub); 

switch ($_cmsub) {
case 'items': do_items(); break;
case 'settings': _do_settings(); break;
case 'xml': do_xml(); break;
case 'preview': do_preview(); break;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/201064-help-editing-php-file/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.