Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 正在过期的链接插件未显示短代码_Wordpress_Shortcode - Fatal编程技术网

Wordpress 正在过期的链接插件未显示短代码

Wordpress 正在过期的链接插件未显示短代码,wordpress,shortcode,Wordpress,Shortcode,我得到的代码在WP 3.5.1升级之前运行良好。现在它什么都没显示,我也搞不懂 当我在管理面板中放置快捷代码时,生成的帖子或页面不会显示任何内容。甚至连原始的短码都没有 基本上,这段代码显示了AmazonS3内容的过期链接,以防止溢出 define('FPEAS3', __FILE__); define('FPEAS3_DIR', dirname(__FILE__)); @define('FPEAS3_AWS_S3_ACCESS_ID', ''); @define('FPEAS3_AWS_S3

我得到的代码在WP 3.5.1升级之前运行良好。现在它什么都没显示,我也搞不懂

当我在管理面板中放置快捷代码时,生成的帖子或页面不会显示任何内容。甚至连原始的短码都没有

基本上,这段代码显示了AmazonS3内容的过期链接,以防止溢出

define('FPEAS3', __FILE__);
define('FPEAS3_DIR', dirname(__FILE__));

@define('FPEAS3_AWS_S3_ACCESS_ID', '');
@define('FPEAS3_AWS_S3_SECRET', '');

add_action('init', 'fpeas3_init');

function fpeas3_init() {
  add_shortcode('s3', 'fpeas3_shortcode');
}

function fpeas3_shortcode($atts, $content = null) {
  extract(shortcode_atts(array(
    'expires' => '5',
    'bucket' => '',
    'path' => ''
  ), $atts));

  if (!$content = trim($content)) {
    $content = 'Download';
  }

  $keys = array(
    'access_id' => get_post_meta(get_the_ID(), 'aws_s3_access_id', true),
    'secret' => get_post_meta(get_the_ID(), 'aws_s3_secret', true)
  );

  if (empty($keys['access_id']) || empty($keys['secret'])) {
    $keys = fpeas3_get_static_keys();
  }

  if (empty($keys['access_id']) || empty($keys['secret'])) {
    $error = "Expiring Amazon S3 Links not setup correctly: missing Access ID or Secret.";
    error_log($error);
    if (current_user_can('admin')) {
      return $error;
    } else {
      return '';
    }
  }

  return sprintf('<a rel="nofollow" href="%s" class="s3-temp-link">%s</a>', 
    fpeas3_get_temporary_link($keys['access_id'], $keys['secret'], $bucket, $path, $expires), $content);
}

function fpeas3_get_static_keys() {
  return array(
    'access_id' => FPEAS3_AWS_S3_ACCESS_ID,
    'secret' => FPEAS3_AWS_S3_SECRET
  );
}

/**
 * Calculate the HMAC SHA1 hash of a string.
 * @param string $key The key to hash against
 * @param string $data The data to hash
 * @param int $blocksize Optional blocksize
 * @return string HMAC SHA1
 */
function fpeas3_crypto_hmacSHA1($key, $data, $blocksize = 64) {
  if (strlen($key) > $blocksize) $key = pack('H*', sha1($key));
  $key = str_pad($key, $blocksize, chr(0x00));
  $ipad = str_repeat(chr(0x36), $blocksize);
  $opad = str_repeat(chr(0x5c), $blocksize);
  $hmac = pack( 'H*', sha1(
    ($key ^ $opad) . pack( 'H*', sha1(
      ($key ^ $ipad) . $data
    ))
  ));
  return base64_encode($hmac);
}

/**
 * Create temporary URLs to your protected Amazon S3 files.
 * @param string $accessKey Your Amazon S3 access key
 * @param string $secretKey Your Amazon S3 secret key
 * @param string $bucket The bucket (bucket.s3.amazonaws.com)
 * @param string $path The target file path
 * @param int $expires In minutes
 * @return string Temporary Amazon S3 URL
 * @see http://awsdocs.s3.amazonaws.com/S3/20060301/s3-dg-20060301.pdf
 */
function fpeas3_get_temporary_link($accessKey, $secretKey, $bucket, $path, $expires = 5) {
  // Calculate expiry time
  $expires = time() + intval(floatval($expires) * 60);
  // Fix the path; encode and sanitize
  $path = str_replace('%2F', '/', rawurlencode($path = ltrim($path, '/')));
  // Path for signature starts with the bucket
  $signpath = '/'. $bucket .'/'. $path;
  // S3 friendly string to sign
  $signsz = implode("\n", $pieces = array('GET', null, null, $expires, $signpath));
  // Calculate the hash
  $signature = fpeas3_crypto_hmacSHA1($secretKey, $signsz);
  // Glue the URL ...
  $url = sprintf('http://%s.s3.amazonaws.com/%s', $bucket, $path);
  // ... to the query string ...
  $qs = http_build_query($pieces = array(
    'AWSAccessKeyId' => $accessKey,
    'Expires' => $expires,
    'Signature' => $signature,
  ));
  // ... and return the URL!
  $tempUrl = $url.'?'.$qs;
  return $tempUrl;
}
define('FPEAS3',_文件__);
定义('FPEAS3_DIR',dirname(_文件__));
@定义('FPEAS3\U AWS\U S3\U访问\U ID','';
@定义('FPEAS3_AWS_S3_SECRET','');
添加动作('init','fpeas3_init');
函数fpeas3_init(){
添加_短代码(“s3”、“fpeas3_短代码”);
}
函数fpeas3\u短代码($atts,$content=null){
提取(短码)附件(数组)(
“expires”=>“5”,
'桶'=>'',
“路径”=>“
)美元(附件);;
如果(!$content=trim($content)){
$content='Download';
}
$keys=数组(
'access_id'=>get_post_meta(get_the_id(),'aws_s3_access_id',true),
'secret'=>get_post_meta(get_ID(),'aws_s3_secret',true)
);
if(空($keys['access_id'])| |空($keys['secret'])){
$keys=fpeas3_get_static_keys();
}
if(空($keys['access_id'])| |空($keys['secret'])){
$error=“过期的Amazon S3链接设置不正确:缺少访问ID或密码。”;
错误日志($error);
if(当前用户可以('admin')){
返回$error;
}否则{
返回“”;
}
}
返回sprintf(“”,
fpeas3_get_temporary_link($keys['access\u id']、$keys['secret']、$bucket、$path、$expires)、$content);
}
函数fpeas3\u get\u static\u keys(){
返回数组(
“访问id”=>FPEAS3\U AWS\U S3\U访问id,
“机密”=>FPEAS3\u AWS\u S3\u机密
);
}
/**
*计算字符串的HMAC SHA1哈希。
*@param string$key要对其进行哈希的密钥
*@param string$data要散列的数据
*@param int$blocksize可选块大小
*@返回字符串HMAC SHA1
*/
函数fpeas3\u crypto\u hmacSHA1($key、$data、$blocksize=64){
如果(strlen($key)>$blocksize)$key=pack('H*',sha1($key));
$key=str_pad($key,$blocksize,chr(0x00));
$ipad=str_repeat(chr(0x36),$blocksize);
$opad=str_重复(chr(0x5c),$blocksize);
$hmac=pack('H*',sha1(
($key^$opad).pack('H*',sha1(
($key^$ipad)。$data
))
));
返回base64_编码($hmac);
}
/**
*为受保护的Amazon S3文件创建临时URL。
*@param string$accessKey您的Amazon S3访问密钥
*@param string$secretKey您的Amazon S3密钥
*@param string$bucket这个bucket(bucket.s3.amazonaws.com)
*@param string$path目标文件路径
*@param int$将在几分钟后过期
*@returnstring临时Amazon S3 URL
*@见http://awsdocs.s3.amazonaws.com/S3/20060301/s3-dg-20060301.pdf
*/
函数fpeas3\u get\u temporary\u link($accessKey、$secretKey、$bucket、$path、$expires=5){
//计算有效期
$expires=time()+intval(floatval($expires)*60);
//修正路径;编码和消毒
$path=str_replace('%2F','/',rawurlencode($path=ltrim($path'/'));
//签名的路径从bucket开始
$signpath='/'.$bucket'/'.$path;
//S3要签名的友好字符串
$signsz=内爆(“\n”,$pieces=array('GET',null,null,$expires,$signpath));
//计算散列
$signature=fpeas3_crypto_hmacSHA1($secretKey,$signsz);
//粘贴URL。。。
$url=sprintf('http://%s.s3.amazonaws.com/%s',$bucket,$path);
//…到查询字符串。。。
$qs=http\U构建\U查询($pieces=array)(
'AWSAccessKeyId'=>$accessKey,
“Expires”=>$Expires,
“签名”=>$Signature,
));
//…并返回URL!
$tempUrl=$url.“?”.$qs;
返回$tempUrl;
}

好的,所以我用新的眼光重新审视了这段代码。我想我已经成功了。还在测试一些东西

我对这行代码做了非常轻微的更改:

**return** sprintf('<a rel="nofollow" href="%s"
 class="s3-temp-link">%s</a>', 
     fpeas3_get_temporary_link($keys['access_id'], $keys['secret'], $bucket, $path, $expires), $content);
**返回**sprintf(“”,
fpeas3_get_temporary_link($keys['access\u id']、$keys['secret']、$bucket、$path、$expires)、$content);
改为:

**echo** sprintf('<a rel="nofollow" href="%s" class="s3-temp-link">%s</a>', 
    fpeas3_get_temporary_link($keys['access_id'], $keys['secret'], $bucket, $path, $expires), $content);
**echo**sprintf(“”,
fpeas3_get_temporary_link($keys['access\u id']、$keys['secret']、$bucket、$path、$expires)、$content);
我不是一个程序员,但经过一番挖掘,我发现有各种各样的方式来显示输出

这是否是编写代码的好方法,有什么意见吗