<?php

/* ========================================================================
 * $Id: store.php 2223 2017-06-26 18:14:12Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onezphp.com
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
#名称：应用商店
#标识：store

class onezphp_store extends onezphp{
  function __construct(){
    
  }
  function storeurl($type){
    return $this->href('/store/store.php?market='.$type);
  }
  function shopurl($type){
    return $this->href('/store/shop.php?market='.$type);
  }
  #引擎内所有应用
  function addons(){
    global $G;
    return array();
    if($G['store.$addons']){
      return $G['store.$addons'];
    }
    $ptokens=onez('cache')->get('store.$addons.'.$G['this']->token);
    if(!$ptokens){
      $ptokens=$this->update_addons();
    }
    $addons=array();
    foreach($ptokens as $ptoken){
      $addons[$ptoken]=onez($ptoken);
    }
    $G['store.$addons']=$addons;
    return $addons;
  }
  function update_addons(){
    global $G;
    return array();
    $ptokens=array();
    $T=$G['this']->data()->open('addons')->record("index1='1' order by step,id");
    foreach($T as $rs){
      $ptoken=$rs['key11'];
      if(!$ptoken){
        continue;
      }
      if(in_array($ptoken,$ptokens)){
        continue;
      }
      if(!onez()->exists($ptoken)){
        continue;
      }
      $ptokens[]=$ptoken;
      #查找依赖
      if(onez($ptoken)->config['abouts']){
        foreach(onez($ptoken)->config['abouts'] as $myptoken){
          if(!$myptoken){
            continue;
          }
          if(in_array($myptoken,$ptokens)){
            continue;
          }
          $ptokens[]=$myptoken;
        }
      }
    }
    onez('cache')->set('store.$addons.'.$G['this']->token,$ptokens);
    return $ptokens;
  }
  function urls_admin($ptoken){
    if(!$ptoken){
      return;
    }
    if(!onez()->exists($ptoken)){
      return;
    }
    $html=array();
    if(method_exists(onez($ptoken),'setting')){
      $html[]='<a href="'.$this->href('/manage/setting.php?ptoken='.$ptoken).'" class="onez-miniwin btn btn-xs btn-success">设置</a>';
    }
    if(method_exists(onez($ptoken),'urls_admin')){
      $urls=onez($ptoken)->urls_admin();
      foreach($urls as $v){
        $html[]='<a href="'.$v['href'].'" class="onez-miniwin btn btn-xs btn-success">'.$v['name'].'</a>';
      }
    }
    return implode('|',$html);
  }
}