五指cms系统使用教程:如何自定义字段为网站加优酷腾讯视频解析
功能:为自己网站解析添加的youku或者腾讯视频等源的视频解析
在coreframe/app/下建立图片所示文件夹结构
1.add.class.php负责写入数据库的时候调用。可以实现格式化后入库;下面是过滤不合法字符;然后再入库。
2.config.php 初始化设置字段时候一些内容,其中fieldname为添加字段显示的字段名字;
3.form.class.php 这是核心,是字段在添加内容时候显示的标准格式;特别注意这里name="form['.$field.']" id="'.$field.'",name和id必须用form['$field'],这里$field会解析成你添加字段的时候设置的字段name;
<?php exit();?>
private function video_txb($config, $value) {
extract($config,EXTR_SKIP);
if($setting) extract($setting,EXTR_SKIP);
if(!$value) $value = $defaultvalue;
if(!isset($placeholder)) $placeholder = '';
return '<input type="text" name="form['.$field.']" id="'.$field.'" size="'.$size.'" placeholder="播放页地址/转发地址均可" value="'.$value.'" class="form-control" '.$ext_code.' >';
}
extract($config,EXTR_SKIP);if($setting) extract($setting,EXTR_SKIP);顺序不能变,$config是$config.php.+$setting内容。setting是设置面板里的相关参数。他们存在于caches\model\field_modelid
4.form_setting.class.php 是设置面板里的相关参数模板;
<?php defined('IN_ADMIN') or exit('No permission resources.');?>
<table cellpadding="0" cellspacing="0" width="100%" class="table table-striped table-advance table-hover">
<tr>
<td>解析源</td>
<td><input type="radio" name="setting[jiexisource]" value="https://player.xxx.com/ipsign/player.php?v=" <?php if(output($setting,'jiexisource')=='https://player.xxx.com/ipsign/player.php?v=') echo 'checked';?>> 52老马解析(推荐)
<input type="radio" name="setting[jiexisource]" value="other" <?php if(output($setting,'jiexisource')=='other') echo 'checked';?>> other(其他)
</td>
</tr>
</table>
核心:https://player.xxx.com/ipsign/player.php?v= 你在网上购买的视频源地址;
5.format.class.php格式化后输出到模板。特别注意,这里获得setting的具体内容$setting = $this->fields[$field]['setting'];
<?php exit();?>
private function video_txb($field, $value) {
if($value=='') return "视频无法解析,请检查地址或者字段解析源";
$setting = $this->fields[$field]['setting'];
$return_values ='<iframe allowfullscreen="" mozallowfullscreen="" frameborder="0" id="player" width="100%" height="500" scrolling="yes" src="'.$setting['jiexisource'].$value.'" ></iframe>';
//$return_values['data'] = $value;
return $return_values;
}
原理:更新模型缓存cache_all生成合并,会在caches/model文件夹里生成,content_format是输出类,负责把原始的data记录,按照字段里format函数格式化好后输出。其他原理类似。
模板调用格式参考; {$ckplayer}这是是输出格式化后表现。
<!--视频模块内容开始-->
{if (($data['txbpoints']['data']==""||$data['txbpoints']['data']==0)&&$ckplayer['data'])||($data['txbpoints']['data']&&$result&&$ckplayer['data'])}
<!--ckplayer-->
{if $ckplayer['data']}
<div class="alert alert-warning" style="padding:5px;margin:10px 5px;">
<a href="#" class="close" data-dismiss="alert">
×
</a>
<strong>警告!</strong>{$siteconfigs[txb_notice1]}
</div>
{$ckplayer}
{/if}
<!--ckplayer结束-->
{else}
<!--ckplayer-->
{if $ckplayer_pre['data']}
<div class="alert alert-warning" style="padding:5px;margin:10px 5px;">
<a href="#" class="close" data-dismiss="alert">
×
</a>
<strong>警告!</strong>{$siteconfigs[txb_notice2]}
</div>
{$ckplayer_pre}
{/if}
<!--ckplayer结束-->
{/if}
<!--视频模块内容结束-->
请先 后发表评论~