Ejemplo n.º 1
0
 /**
  * Lists all menus and items
  *
  * @param {string} $siteId
  * @return {array}
  */
 public static function listExtended($siteId)
 {
     $menus = Menu::listAll($siteId);
     $i = 0;
     foreach ($menus as $menu) {
         $menus[$i]['items'] = MenuItem::listAll($menu['id'], $siteId);
         $i++;
     }
     return $menus;
 }
Ejemplo n.º 2
0
 /**
  * Adds a menu item
  *
  * @param {files} $data
  * @return {array}
  */
 public static function add($html, $cssClass, $isNested, $url, $menuId, $siteId)
 {
     $menu = Menu::getById($menuId, $siteId);
     // strip any trailing .html from url
     $url = preg_replace('/\\.[^.\\s]{3,4}$/', '', $url);
     $item = array('html' => $html, 'cssClass' => $cssClass, 'isNested' => $isNested, 'url' => $url);
     array_push($menu->items, $item);
     $menu->save($siteId);
     return $item;
 }
Ejemplo n.º 3
0
 /**
  * Removes the menu
  *
  * @return Response
  */
 public function remove(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $siteId = $request->input('auth-id');
     // get id
     $id = $request->json()->get('id');
     $menu = Menu::getById($id, $siteId);
     if ($menu !== NULL) {
         $menu->remove($siteId);
         // return OK
         return response('OK, menu removed at = ' . $menu->id, 200);
     }
     return response('Menu not found', 400);
 }
Ejemplo n.º 4
0
 /**
  * Publishes plugins for the site
  *
  * @param {Site} $site
  */
 public static function publishPlugins($user, $site)
 {
     // get plugins for the site
     $dir = app()->basePath() . '/public/sites/' . $site->id . '/plugins/';
     $exts = array('html');
     $files = Utilities::listFiles($dir, $site->id, $exts);
     $plugins = array();
     foreach ($files as $file) {
         $path = app()->basePath() . '/public/sites/' . $site->id . '/' . $file;
         if (file_exists($path)) {
             $html = file_get_contents($path);
             $id = basename($path);
             $id = str_replace('.html', '', $id);
             // push plugin to array
             array_push($plugins, $id);
         }
     }
     // location where twig should look for templates (local to site, then global)
     $template_dirs = array(app()->basePath() . '/public/sites/' . $site->id . '/plugins');
     $global_plugin_dir = app()->basePath() . '/resources/plugins';
     if (file_exists($global_plugin_dir)) {
         array_push($template_dirs, $global_plugin_dir);
     }
     // setup twig
     $loader = new \Twig_Loader_Filesystem($template_dirs);
     $twig = new \Twig_Environment($loader);
     $twig->addExtension(new BetterSortTwigExtension());
     // get all pages
     $pages = Page::listAll($user, $site);
     // list all forms, menus, galleries
     $forms = Form::listExtended($site->id);
     $menus = Menu::listExtended($site->id);
     $galleries = Gallery::listExtended($site->id);
     $i = 0;
     // get html of pages
     foreach ($pages as $page) {
         // stript html
         $url = $page['url'];
         $url = preg_replace('/\\.[^.\\s]{3,4}$/', '', $url);
         // get html of page
         $file = app()->basePath() . '/public/sites/' . $site->id . '/' . $url . '.html';
         if (file_exists($file)) {
             $html = file_get_contents($file);
             // set parser
             $dom = HtmlDomParser::str_get_html($html, $lowercase = true, $forceTagsClosed = false, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = false, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT);
             // find main content
             $el = $dom->find('[role=main]');
             $main_content = '';
             // get the fragment content
             if (isset($el[0])) {
                 $main_content = $el[0]->innertext;
             }
             // set html
             $pages[$i]['html'] = $main_content;
         }
         $i++;
     }
     $i = 0;
     // public plugin for pages
     foreach ($pages as $item) {
         // get page
         $page = new Page($item);
         // setup current page
         $current_page = array('url' => $page->url, 'title' => $page->title, 'description' => $page->description, 'keywords' => $page->keywords, 'callout' => $page->callout, 'photo' => $page->photo, 'thumb' => $page->thumb, 'language' => $page->language, 'direction' => $page->direction, 'firstName' => $page->firstName, 'lastName' => $page->lastName, 'lastModifiedBy' => $page->lastModifiedBy, 'lastModifiedDate' => $page->lastModifiedDate);
         // setup whether the site is using friendly urls
         $useFriendlyURLs = false;
         if (env('FRIENDLY_URLS') === true || env('FRIENDLY_URLS') === 'true') {
             $useFriendlyURLs = true;
         }
         // setup current site
         $current_site = array('id' => $site->id, 'name' => $site->name, 'email' => $site->email, 'api' => Utilities::retrieveAppUrl() . '/api', 'useFriendlyURLs' => $useFriendlyURLs);
         // set url
         $url = $page->url;
         $url = preg_replace('/\\.[^.\\s]{3,4}$/', '', $url);
         $location = app()->basePath() . '/public/sites/' . $site->id . '/' . $url . '.html';
         // check for valid location
         if (file_exists($location)) {
             // get html from page
             $html = file_get_contents($location);
             // walk through plugins
             foreach ($plugins as $plugin) {
                 // insert into respond-plugin comments
                 $start = '<!-- respond-plugin:' . $plugin . ' -->';
                 $end = '<!-- /respond-plugin:' . $plugin . ' -->';
                 // check for start and end
                 if (strpos($html, $start) !== FALSE && strpos($html, $end) !== FALSE) {
                     // load the template
                     $template = $twig->loadTemplate($plugin . '.html');
                     // render the template
                     $plugin_html = $template->render(array('pages' => $pages));
                     // replace content
                     $html = Utilities::replaceBetween($html, $start, $end, $plugin_html);
                 }
             }
             // make sure the html is not empty
             if (!empty($html)) {
                 // load the parser
                 $dom = HtmlDomParser::str_get_html($html, $lowercase = true, $forceTagsClosed = false, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = false, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT);
                 // insert into [respond-plugin] elements
                 foreach ($dom->find('[respond-plugin]') as $el) {
                     if (isset($el->type)) {
                         if (array_search($el->type, $plugins) !== FALSE) {
                             // load the template
                             $template = $twig->loadTemplate($el->type . '.html');
                             $render_arr = array('page' => $current_page, 'site' => $current_site, 'pages' => $pages, 'forms' => $forms, 'galleries' => $galleries, 'menus' => $menus, 'attributes' => $el->attr);
                             // render the template
                             $plugin_html = $template->render($render_arr);
                             // set the inner text
                             $el->innertext = $plugin_html;
                         }
                     }
                 }
             }
             // find main content
             $el = $dom->find('[role=main]');
             $main_content = '';
             // get the fragment content
             if (isset($el[0])) {
                 $main_content = $el[0]->innertext;
             }
             // put html back
             file_put_contents($location, $dom);
             // update html in the array
             $pages[$i]['html'] = $main_content;
             // increment
             $i++;
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Removes the menu item
  *
  * @return Response
  */
 public function remove(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $siteId = $request->input('auth-id');
     // name, items
     $menuId = $request->json()->get('id');
     $index = $request->json()->get('index');
     // update order in file
     $menu = Menu::getById($menuId, $siteId);
     if ($menu != NULL) {
         array_splice($menu->items, $index, 1);
         $menu->save($siteId);
         // get site and user
         $site = Site::getById($siteId);
         $user = User::getByEmail($email, $siteId);
         // re-publish plugins
         Publish::publishPlugins($user, $site);
         return response('Ok', 200);
     }
     return response('Menu Item not found', 400);
 }