Ignore:
Timestamp:
Jul 14, 2011, 4:01:17 PM (13 years ago)
Author:
nikrou
Message:

Make plugin works as expected using webservice.

Location:
extensions/user_tags/include
Files:
1 added
1 deleted
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • extensions/user_tags/include/autoload.inc.php

    r11099 r11741  
    2020// +-----------------------------------------------------------------------+
    2121
    22 if (!defined('PHPWG_ROOT_PATH')) {
    23   die('Hacking attempt!');
     22global $__t4u_autoload;
     23$__t4u_autoload['t4u_Ws'] = T4U_PLUGIN_ROOT . '/include/t4u_ws.class.php';
     24$__t4u_autoload['t4u_Config'] = T4U_PLUGIN_ROOT . '/include/t4u_config.class.php';
     25$__t4u_autoload['t4u_Content'] = T4U_PLUGIN_ROOT . '/include/t4u_content.class.php';
     26
     27
     28if (function_exists('spl_autoload_register')) {
     29  spl_autoload_register('t4u_autoload');
     30} else {
     31  function __autoload($name) {
     32    t4u_autoload($name);
     33  }
    2434}
    2535
    26 if (!empty($_GET['action']) && in_array($_GET['action'], array('add', 'get'))) {
    27   include_once T4U_PLUGIN_ROOT . "/include/t4u_admin_action.inc.php";
     36function t4u_autoload($name) {
     37  global $__t4u_autoload;
     38
     39  if (!empty($__t4u_autoload[$name])) {
     40    require_once $__t4u_autoload[$name];
     41  }
    2842}
    29 
    30 include_once T4U_PLUGIN_ROOT . "/include/t4u_content.class.php";
    31 
    32 $public_content = new t4u_Content($plugin_config);
    33 add_event_handler('render_element_content',
    34                   array($public_content, 'render_element_content'),
    35                   EVENT_HANDLER_PRIORITY_NEUTRAL,
    36                   2
    37                   );
    38 ?>
  • extensions/user_tags/include/constants.inc.php

    r6798 r11741  
    2626define('T4U_IMGS', PHPWG_PLUGINS_PATH . basename(T4U_PLUGIN_ROOT). '/imgs');
    2727define('T4U_JS', PHPWG_PLUGINS_PATH . basename(T4U_PLUGIN_ROOT). '/js');
     28define('T4U_WS', 'user_tags.tags.');
    2829?>
  • extensions/user_tags/include/default_values.inc.php

    r11081 r11741  
    2121
    2222$default_values = array();
    23 $default_values['t4u_permission_add'] = null;
    24 $default_values['t4u_permission_delete'] = null;
     23$default_values['t4u_permission_update'] = null;
    2524?>
  • extensions/user_tags/include/t4u_config.class.php

    r11081 r11741  
    2222class t4u_Config
    2323{
    24     private
    25       $config = array(),
    26       $plugin_dir;
     24  private $config = array();
     25  protected static $instance;
    2726
    2827  public function __construct($plugin_dir, $plugin_name) {
     
    3534
    3635    if (!file_exists($this->get_config_filename())) {
     36      $this->setDefaults();
    3737      $this->save_config();
    3838    }
    3939  }
     40
     41  public static function getInstance() {
     42    if (!isset(self::$instance)) {
     43      self::$instance = new t4u_Config(T4U_PLUGIN_ROOT, T4U_PLUGIN_NAME);
     44    }
     45    return self::$instance;
     46  }
     47
    4048
    4149  public function load_config() {
     
    4553      $this->config = $c;
    4654    }
    47     $this->setDefaults();
    4855  }
    4956
     
    100107 
    101108  public function getActionUrl($action, $method='POST') {
    102     $url = get_root_url().'admin.php?page=plugin';
    103     $file = basename($this->plugin_dir) . '/' .'admin.php';
    104     if (strtoupper($method)=='POST') {
    105         $url .= '&section='.urlencode($file);
    106         $url .= '&action='.urlencode($action);
    107     } else {
    108         $url .= '&section='.$file;
    109         $url .= '&action='.$action;
    110     }
     109    $ws = get_root_url();
     110    $ws .= 'ws.php?format=json&method=user_tags.tags.list';
    111111
    112     return $url;
     112    /* $url = get_root_url().'admin.php?page=plugin'; */
     113    /* $file = basename($this->plugin_dir) . '/' .'admin.php'; */
     114    /* if (strtoupper($method)=='POST') { */
     115    /*  $url .= '&section='.urlencode($file); */
     116    /*  $url .= '&action='.urlencode($action); */
     117    /* } else { */
     118    /*  $url .= '&section='.$file; */
     119    /*  $url .= '&action='.$action; */
     120    /* } */
     121
     122    return $ws;
    113123  }
    114124
  • extensions/user_tags/include/t4u_content.class.php

    r11081 r11741  
    3030
    3131    if (!$this->plugin_config->hasPermission('add')) {
    32       return false;
     32      return $content;
    3333    }
     34
     35    load_language('plugin.lang', T4U_PLUGIN_LANG);
    3436
    3537    $template->assign('T4U_JS', T4U_JS);
    3638    $template->assign('T4U_CSS', T4U_CSS);
    3739    $template->assign('T4U_IMGS', T4U_IMGS);
    38     $template->assign('T4U_ADD_SCRIPT', $this->plugin_config->getActionUrl('add', 'GET'));
    39     $template->assign('T4U_GET_SCRIPT', $this->plugin_config->getActionUrl('get', 'GET'));
     40    $template->assign('T4U_PERMISSION_DELETE', $this->plugin_config->hasPermission('delete'));
     41    $template->assign('T4U_UPDATE_SCRIPT', get_root_url().'ws.php?format=json&method='.T4U_WS.'update');
     42    $template->assign('T4U_UPDATE_METHOD', T4U_WS.'update');
     43    $template->assign('T4U_GET_SCRIPT', get_root_url().'ws.php?format=json&method='.T4U_WS.'list');
    4044    $template->assign('T4U_IMAGE_ID', $picture['id']);
    4145    $template->assign('T4U_REFERER', urlencode($picture['url']));
     
    5155
    5256    $template->set_filename('add_tags', T4U_TEMPLATE.'/add_tags.tpl');
    53     $template->assign_var_from_handle('PLUGIN_PICTURE_BEFORE', 'add_tags');
     57
     58    $plugin_picture_before = $template->get_template_vars('PLUGIN_PICTURE_BEFORE');
     59    $plugin_picture_before .= $template->parse('add_tags', true);
     60    $template->append('PLUGIN_PICTURE_BEFORE', $plugin_picture_before);
    5461
    5562    return $content;
Note: See TracChangeset for help on using the changeset viewer.