public function getRouting($route = array(), $dispatch = true)
 {
     if ($this->_routes === null || $dispatch) {
         $routes = parent::getRouting($route);
         /**
          * Extend routing via plugin routes
          * @event routing
          * @param array $routes
          * @return array routes collected for every plugin
          */
         $result = wa()->event(array('site', 'routing'), $routes);
         $all_plugins_routes = array();
         foreach ($result as $plugin_id => $routing_rules) {
             if ($routing_rules) {
                 $plugin = str_replace('-plugin', '', $plugin_id);
                 foreach ($routing_rules as $url => &$route) {
                     if (!is_array($route)) {
                         list($route_ar['module'], $route_ar['action']) = explode('/', $route);
                         $route = $route_ar;
                     }
                     $route['plugin'] = $plugin;
                     $all_plugins_routes[$url] = $route;
                 }
                 unset($route);
             }
         }
         $routes = array_merge($all_plugins_routes, $routes);
         if ($dispatch) {
             return $routes;
         }
         $this->_routes = $routes;
     }
     return $this->_routes;
 }
Beispiel #2
0
 public function getRouting($route = array(), $dispatch = false)
 {
     $url_type = isset($route['url_type']) ? $route['url_type'] : 0;
     if (!isset($this->_routes[$url_type]) || $dispatch) {
         $routes = parent::getRouting($route);
         if ($routes) {
             if (isset($routes[$url_type])) {
                 $routes = $routes[$url_type];
             } else {
                 $routes = $routes[0];
             }
         }
         // for URL <category_url>/<product_url>/
         if ($dispatch && $url_type == 2) {
             $category_model = new shopCategoryModel();
             $categories = $category_model->getByRoute(wa()->getRouting()->getDomain(null, true) . '/' . $route['url']);
             $categories_routes = array();
             foreach ($categories as $c) {
                 $categories_routes[$c['full_url'] . '/'] = array('module' => 'frontend', 'action' => 'category', 'category_id' => $c['id']);
             }
             $routes = array_merge($categories_routes, $routes);
         }
         /**
          * Extend routing via plugin routes
          * @event routing
          * @param array $routes
          * @return array $routes routes collected for every plugin
          */
         $result = wa()->event(array($this->application, 'routing'), $route);
         $all_plugins_routes = array();
         foreach ($result as $plugin_id => $routing_rules) {
             if ($routing_rules) {
                 $plugin = str_replace('-plugin', '', $plugin_id);
                 /*
                 if ($url_type == 0) {
                 $routing_rules = $routing_rules[0];
                 } else {
                 $routing_rules = $routing_rules[1];
                 }
                 */
                 foreach ($routing_rules as $url => &$route) {
                     if (!is_array($route)) {
                         list($route_ar['module'], $route_ar['action']) = explode('/', $route);
                         $route = $route_ar;
                     }
                     $route['plugin'] = $plugin;
                     $all_plugins_routes[$url] = $route;
                 }
                 unset($route);
             }
         }
         $routes = array_merge($all_plugins_routes, $routes);
         if ($dispatch) {
             return $routes;
         }
         $this->_routes[$url_type] = $routes;
     }
     return $this->_routes[$url_type];
 }
 public function setCount($n = null)
 {
     wa()->getStorage()->open();
     $model = new waAppSettingsModel();
     $app_id = $this->getApplication();
     $model->set($app_id, 'update_counter', $n);
     $model->set($app_id, 'update_counter_timestamp', $n === false ? 0 : time());
     return parent::setCount($n);
 }
 /**
  * Trigger event with given $name from current active application.
  *
  * @param  string    $name        Event name.
  * @param  mixed     $params      Parameters passed to event handlers.
  * @param  string[]  $array_keys  Array of expected template items for UI events.
  * @return  array  app_id or plugin_id => data returned from handler (unless null is returned)
  */
 public function event($name, &$params = null, $array_keys = null)
 {
     $result = array();
     if (is_array($name)) {
         $event_app_id = $name[0];
         $event_system = self::getInstance($event_app_id);
         $name = $name[1];
     } else {
         $event_app_id = $this->getConfig()->getApplication();
         $event_system = $this;
     }
     $event_prefix = wa($event_app_id)->getConfig()->getPrefix();
     if (!isset(self::$handlers['apps'])) {
         self::$handlers['apps'] = array();
         $cache_file = $this->config->getPath('cache', 'config/handlers');
         if (!waSystemConfig::isDebug() && file_exists($cache_file)) {
             self::$handlers['apps'] = (include $cache_file);
         }
         if (!self::$handlers['apps'] || !is_array(self::$handlers['apps'])) {
             $apps = $this->getApps();
             $path = $this->getConfig()->getPath('apps');
             foreach ($apps as $app_id => $app_info) {
                 $files = waFiles::listdir($path . '/' . $app_id . '/lib/handlers/');
                 foreach ($files as $file) {
                     if (substr($file, -12) == '.handler.php') {
                         $file = explode('.', substr($file, 0, -12), 2);
                         self::$handlers['apps'][$file[0]][$file[1]][] = $app_id;
                     }
                 }
             }
             if (!waSystemConfig::isDebug()) {
                 waUtils::varExportToFile(self::$handlers['apps'], $cache_file);
             }
         }
     }
     if (!isset(self::$handlers['plugins'][$event_app_id])) {
         self::$handlers['plugins'][$event_app_id] = array();
         $plugins = $event_system->getConfig()->getPlugins();
         foreach ($plugins as $plugin_id => $plugin) {
             if (!empty($plugin['handlers'])) {
                 foreach ($plugin['handlers'] as $handler_event => $handler_method) {
                     self::$handlers['plugins'][$event_app_id][$handler_event][$plugin_id] = $handler_method;
                 }
             }
         }
     }
     if (isset(self::$handlers['apps'][$event_app_id][$name])) {
         $path = $this->getConfig()->getPath('apps');
         foreach (self::$handlers['apps'][$event_app_id][$name] as $app_id) {
             $file_path = $path . '/' . $app_id . '/lib/handlers/' . $event_prefix . "." . $name . ".handler.php";
             if (!file_exists($file_path)) {
                 continue;
             }
             wa($app_id);
             include_once $file_path;
             $class_name = $name;
             if (strpos($name, '.') !== false) {
                 $class_name = strtok($class_name, '.') . ucfirst(strtok(''));
             }
             $class_name = $app_id . ucfirst($event_prefix) . ucfirst($class_name) . "Handler";
             /**
              * @var $handler waEventHandler
              */
             $handler = new $class_name();
             try {
                 $r = $handler->execute($params);
                 if ($r !== null) {
                     $result[$app_id] = $r;
                 }
             } catch (Exception $e) {
                 waLog::log('Event handling error in ' . $file_path . ': ' . $e->getMessage());
             }
         }
     }
     if (isset(self::$handlers['plugins'][$event_app_id][$name])) {
         $plugins = $event_system->getConfig()->getPlugins();
         foreach (self::$handlers['plugins'][$event_app_id][$name] as $plugin_id => $method) {
             if (!isset($plugins[$plugin_id])) {
                 continue;
             }
             $plugin = $plugins[$plugin_id];
             self::pushActivePlugin($plugin_id, $event_prefix);
             $class_name = $event_app_id . ucfirst($plugin_id) . 'Plugin';
             try {
                 $class = new $class_name($plugin);
                 // Load plugin locale if it exists
                 $locale_path = $this->getAppPath('plugins/' . $plugin_id . '/locale', $event_app_id);
                 if (is_dir($locale_path)) {
                     waLocale::load($this->getLocale(), $locale_path, self::getActiveLocaleDomain(), false);
                 }
                 if (method_exists($class, $method) && null !== ($r = $class->{$method}($params))) {
                     if ($array_keys && is_array($r)) {
                         foreach ($array_keys as $k) {
                             if (!isset($r[$k])) {
                                 $r[$k] = '';
                             }
                         }
                     }
                     $result[$plugin_id . '-plugin'] = $r;
                 }
             } catch (Exception $e) {
                 waLog::log('Event handling error in ' . $class_name . '->' . $name . '(): ' . $e->getMessage());
             }
             self::popActivePlugin();
         }
     }
     return $result;
 }
 public function getRootUrl($absolute = false, $script = false)
 {
     return $this->config->getRootUrl($absolute, $script);
 }
Beispiel #6
0
 public function getRouting($route = array(), $dispatch = false)
 {
     static $routes_cache = array();
     $key = md5(serialize($route));
     if (!isset($routes_cache[$key])) {
         $routes = parent::getRouting();
         if ($routes) {
             $blog_id = isset($route['blog_url_type']) ? $route['blog_url_type'] : 0;
             switch (intval($blog_id)) {
                 case -1:
                     $rules = $routes[2];
                     break;
                 case 0:
                     $rules = $routes[0];
                     break;
                 default:
                     $rules = $routes[1];
                     break;
             }
             $post_url = isset($route['post_url_type']) ? $route['post_url_type'] : 0;
             $pattern = false;
             $year = '((19|20)[\\d]{2})';
             $month = '([0]?\\d|1[0-2])';
             $day = '([0-2]\\d|3[0-1]|\\d)';
             switch ($post_url) {
                 case 3:
                     $pattern = '<post_year:' . $year . '>/<post_month:' . $month . '>/<post_day:' . $day . '>/<post_url>';
                     break;
                 case 2:
                     $pattern = '<post_year:' . $year . '>/<post_month:' . $month . '>/<post_url>';
                     break;
                 case 1:
                     $pattern = '<post_year:' . $year . '>/<post_url>';
                     break;
                 case 0:
                 default:
                     break;
             }
             /**
              * Extend routing via plugin routes
              * @event routing
              * @param array $route
              * @return array route
              */
             $result = wa()->event(array('blog', 'routing'), $route);
             $plugin_routes = array();
             foreach ($result as $rs) {
                 $plugin_routes = array_merge($plugin_routes, $rs);
             }
             if ($plugin_routes) {
                 $rules = array_merge($plugin_routes, $rules);
             }
             if ($pattern) {
                 $new_rules = array();
                 foreach ($rules as $rule_id => $rule) {
                     if (strpos($rule_id, '<post_url>') === false) {
                         $new_rules[$rule_id] = $rule;
                     } else {
                         $rule_id = str_replace('<post_url>', $pattern, $rule_id);
                         $new_rules[$rule_id] = $rule;
                     }
                 }
                 $rules = $new_rules;
             }
             $routes_cache[$key] = $rules;
         } else {
             $routes_cache[$key] = array();
         }
     }
     return $routes_cache[$key];
 }
 public function explainLogs($logs)
 {
     $logs = parent::explainLogs($logs);
     $app_url = wa()->getConfig()->getBackendUrl(true) . $this->application . '/';
     $post_ids = array();
     $comment_ids = array();
     foreach ($logs as $l_id => $l) {
         if (in_array($l['action'], array('page_add', 'page_edit', 'page_move')) && isset($l['params_html'])) {
             $logs[$l_id]['params_html'] = str_replace('#/pages/', '?module=pages#/', $l['params_html']);
         } else {
             if ($l['action'] == 'post_edit' && version_compare(wa('webasyst')->getVersion(), '1.4.0.40888') >= 0) {
                 // Removal of log records in activity is only supported since 1.4.0.40888,
                 // but we don't want to raise requirements yet, so have to check for version here.
                 // !!! TODO: should probably remove the check later and update requirements.php
                 $logs[$l_id] = null;
             } else {
                 if (in_array($l['action'], array('post_edit', 'post_publish', 'post_unpublish')) && $l['params']) {
                     $post_ids[$l['params']] = 1;
                 } else {
                     if (in_array($l['action'], array('comment_add', 'comment_delete', 'comment_restore')) && $l['params']) {
                         $comment_ids[$l['params']] = 1;
                     }
                 }
             }
         }
     }
     if ($comment_ids) {
         $comment_model = new blogCommentModel();
         $comments = $comment_model->getById(array_keys($comment_ids));
         foreach ($comments as $c) {
             $post_ids[$c['post_id']] = 1;
         }
     }
     if ($post_ids) {
         $post_model = new blogPostModel();
         $posts = $post_model->getById(array_keys($post_ids));
     }
     foreach ($logs as $l_id => $l) {
         if (!$l) {
             continue;
         }
         // Link to blog post in question
         $p = $c = null;
         if (in_array($l['action'], array('post_edit', 'post_publish', 'post_unpublish')) && isset($posts[$l['params']])) {
             $p = $posts[$l['params']];
         } else {
             if (in_array($l['action'], array('comment_add', 'comment_delete', 'comment_restore')) && isset($comments[$l['params']])) {
                 $c = $comments[$l['params']];
                 if (isset($posts[$c['post_id']])) {
                     $p = $posts[$c['post_id']];
                 }
             }
         }
         if (!empty($p)) {
             if ($p['status'] == blogPostModel::STATUS_PUBLISHED) {
                 $url = $app_url . '?module=post&id=' . $p['id'];
             } else {
                 $url = $app_url . '?module=post&action=edit&id=' . $p['id'];
             }
             $logs[$l_id]['params_html'] = '<div class="activity-target"><a href="' . $url . '">' . htmlspecialchars($p['title']) . '</a></div>';
         }
         if (!empty($c)) {
             $logs[$l_id]['params_html'] .= '<div class="activity-body"><p' . ($c['status'] == 'deleted' ? ' class="strike gray"' : '') . '>' . nl2br(htmlspecialchars(mb_substr($c['text'], 0, 512))) . '</p></div>';
         }
     }
     return $logs;
 }
 public function uninstall()
 {
     // check uninstall.php
     $file = $this->path . '/lib/config/uninstall.php';
     if (file_exists($file)) {
         include $file;
     }
     $file_db = $this->path . '/lib/config/db.php';
     if (file_exists($file_db)) {
         $schema = (include $file_db);
         $model = new waModel();
         foreach ($schema as $table => $fields) {
             $sql = "DROP TABLE IF EXISTS " . $table;
             $model->exec($sql);
         }
     } else {
         // check plugin.sql
         $file_sql = $this->path . '/lib/config/plugin.sql';
         if (file_exists($file_sql)) {
             waAppConfig::executeSQL($file_sql, 2);
         }
     }
     // Remove plugin settings
     $app_settings_model = new waAppSettingsModel();
     $sql = "DELETE FROM " . $app_settings_model->getTableName() . "\n                WHERE app_id = s:app_id";
     $app_settings_model->exec($sql, array('app_id' => $this->app_id . "." . $this->id));
     if (!empty($this->info['rights'])) {
         // Remove rights to plugin
         $contact_rights_model = new waContactRightsModel();
         $sql = "DELETE FROM " . $contact_rights_model->getTableName() . "\n                    WHERE app_id = s:app_id AND (\n                        name = '" . $contact_rights_model->escape('plugin.' . $this->id) . "' OR\n                        name LIKE '" . $contact_rights_model->escape('plugin.' . $this->id) . ".%'\n                    )";
         $contact_rights_model->exec($sql, array('app_id' => $this->app_id));
     }
     // Remove cache of the appliaction
     waFiles::delete(wa()->getAppCachePath('', $this->app_id));
 }
 public function getRouting($route = array())
 {
     $url_type = isset($route['url_type']) ? $route['url_type'] : 0;
     $routes = parent::getRouting($route);
     if ($routes) {
         if ($url_type == 0) {
             $routes = $routes[0];
         } else {
             $routes = $routes[1];
         }
     }
     /**
      * Extend routing via plugin routes
      * @event routing
      * @param array $routes
      * @return array routes collected for every plugin
      */
     $result = wa()->event('routing', $routes);
     $all_plugins_routes = array();
     foreach ($result as $plugin_id => $routing_rules) {
         if ($routing_rules) {
             $plugin = str_replace('-plugin', '', $plugin_id);
             if ($url_type == 0) {
                 $routing_rules = $routing_rules[0];
             } else {
                 $routing_rules = $routing_rules[1];
             }
             foreach ($routing_rules as $url => &$route) {
                 if (!is_array($route)) {
                     list($route_ar['module'], $route_ar['action']) = explode('/', $route);
                     $route = $route_ar;
                 }
                 $route['plugin'] = $plugin;
                 $all_plugins_routes[$url] = $route;
             }
             unset($route);
         }
     }
     $routes = array_merge($all_plugins_routes, $routes);
     return $routes;
 }
 public function explainLogs($logs)
 {
     $logs = parent::explainLogs($logs);
     $photo_ids = array();
     foreach ($logs as $l_id => $l) {
         if (in_array($l['action'], array('photos_upload')) && $l['params']) {
             $photo_ids = array_merge($photo_ids, explode(',', $l['params']));
         }
     }
     if ($photo_ids) {
         $photo_model = new photosPhotoModel();
         $photos = $photo_model->getById($photo_ids);
     }
     foreach ($logs as $l_id => $l) {
         if (in_array($l['action'], array('photos_upload'))) {
             $ids = explode(',', $l['params']);
             $html = '';
             foreach ($ids as $id) {
                 if (!empty($photos[$id])) {
                     $p = $photos[$id];
                     $url = wa()->getConfig()->getBackendUrl(true) . $l['app_id'] . '/#/photo/' . $id . '/';
                     $_is_2x_enabled = $this->getOption('enable_2x');
                     $_image_size = '96x96';
                     if ($_is_2x_enabled) {
                         $_image_size = '96x96@2x';
                     }
                     $img = photosPhoto::getEmbedImgHtml($p, $_image_size);
                     $html .= '<div class="photo-item"><a href="' . $url . '">' . $img . '</a></div>';
                 }
             }
             if ($html) {
                 $logs[$l_id]['params_html'] = '<div class="activity-photo-wrapper"><div class="activity-photo-list">' . $html . '</div></div>';
             }
         }
     }
     return $logs;
 }
 public function getPlugins()
 {
     $fix = $this->plugins === null;
     parent::getPlugins();
     if ($fix) {
         foreach ($this->plugins as $p_id => $p) {
             if (!empty($p['blog_settings'])) {
                 $this->plugins[$p_id]['custom_settings_url'] = '?plugin=' . $p['id'] . '&module=backend&action=settings';
             }
         }
     }
     return $this->plugins;
 }