| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | <?php | 
					
						
							|  |  |  | namespace Grav\Plugin; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | use Grav\Common\Data; | 
					
						
							| 
									
										
										
										
											2014-10-07 12:12:21 +03:00
										 |  |  | use Grav\Common\File\CompiledYamlFile; | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | use Grav\Common\GPM\GPM; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | use Grav\Common\Grav; | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | use Grav\Common\Page\Page; | 
					
						
							|  |  |  | use Grav\Common\Page\Pages; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | use Grav\Common\Plugins; | 
					
						
							|  |  |  | use Grav\Common\Themes; | 
					
						
							|  |  |  | use Grav\Common\Uri; | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | use Grav\Common\User\User; | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  | use RocketTheme\Toolbox\File\File; | 
					
						
							| 
									
										
										
										
											2015-04-27 13:37:22 +02:00
										 |  |  | use RocketTheme\Toolbox\File\JsonFile; | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  | use RocketTheme\Toolbox\File\LogFile; | 
					
						
							| 
									
										
										
										
											2014-10-07 12:12:21 +03:00
										 |  |  | use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  | use RocketTheme\Toolbox\Session\Message; | 
					
						
							|  |  |  | use RocketTheme\Toolbox\Session\Session; | 
					
						
							| 
									
										
										
										
											2014-09-26 14:10:32 +03:00
										 |  |  | use Symfony\Component\Yaml\Yaml; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-28 11:11:43 -06:00
										 |  |  | define('LOGIN_REDIRECT_COOKIE', 'grav-login-redirect'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | class Admin | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @var Grav | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $grav; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @var Uri $uri | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $uri; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $pages = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |      * @var Session | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      */ | 
					
						
							|  |  |  |     protected $session; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var Data\Blueprints | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $blueprints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $base; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $location; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $route; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |      * @var User | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public $user; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-02 12:14:13 -07:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |      * @var Grav\Common\GPM\GPM | 
					
						
							| 
									
										
										
										
											2014-10-02 12:14:13 -07:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |     protected $gpm; | 
					
						
							| 
									
										
										
										
											2014-10-02 12:14:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Constructor. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |      * @param Grav   $grav | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      * @param string $base | 
					
						
							|  |  |  |      * @param string $location | 
					
						
							|  |  |  |      * @param string $route | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |     public function __construct(Grav $grav, $base, $location, $route) | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |         $this->grav = $grav; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         $this->base = $base; | 
					
						
							|  |  |  |         $this->location = $location; | 
					
						
							|  |  |  |         $this->route = $route; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |         $this->uri = $this->grav['uri']; | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |         $this->session = $this->grav['session']; | 
					
						
							|  |  |  |         $this->user = $this->grav['user']; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Get current session. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |      * @return Session | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function session() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->session; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Add message into the session queue. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $msg | 
					
						
							|  |  |  |      * @param string $type | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setMessage($msg, $type = 'info') | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |         /** @var Message $messages */ | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |         $messages = $this->grav['messages']; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         $messages->add($msg, $type); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Fetch and delete messages from the session queue. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $type | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |      * @return array | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function messages($type = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |         /** @var Message $messages */ | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |         $messages = $this->grav['messages']; | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |         return $messages->fetch($type); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Authenticate user. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  array $form Form fields. | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function authenticate($form) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |         if (!$this->user->authenticated && isset($form['username']) && isset($form['password'])) { | 
					
						
							| 
									
										
										
										
											2015-04-11 17:47:37 +02:00
										 |  |  |             $user = User::load($form['username']); | 
					
						
							|  |  |  |             if ($user->exists()) { | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |                 $user->authenticated = true; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 // Authenticate user.
 | 
					
						
							|  |  |  |                 $result = $user->authenticate($form['password']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if ($result) { | 
					
						
							|  |  |  |                     $this->user = $this->session->user = $user; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     /** @var Grav $grav */ | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |                     $grav = $this->grav; | 
					
						
							| 
									
										
										
										
											2015-07-28 11:11:43 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-28 16:10:48 -06:00
										 |  |  |                     $l = $this->grav['language']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-13 20:44:56 +02:00
										 |  |  |                     $this->setMessage($l->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'), 'info'); | 
					
						
							| 
									
										
										
										
											2015-07-28 16:10:48 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-28 12:09:53 -06:00
										 |  |  | //                    $redirect_route =$this->getLoginRedirect() ?: $this->uri->route();
 | 
					
						
							|  |  |  |                     $redirect_route = $this->uri->route(); | 
					
						
							| 
									
										
										
										
											2015-07-28 11:11:43 -06:00
										 |  |  |                     $grav->redirect($redirect_route); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->authorise(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Checks user authorisation to the action. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * @param  string $action | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function authorise($action = 'admin.login') | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |         $action = (array)$action; | 
					
						
							| 
									
										
										
										
											2015-05-11 16:35:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         foreach ($action as $a) { | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |             if ($this->user->authorise($a)) { | 
					
						
							| 
									
										
										
										
											2015-05-11 16:35:23 +02:00
										 |  |  |                 return true; | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-05-11 16:35:23 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Returns edited page. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param bool $route | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      * @return Page | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function page($route = false) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $path = $this->route; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($route && !$path) { | 
					
						
							|  |  |  |             $path = '/'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!isset($this->pages[$path])) { | 
					
						
							|  |  |  |             $this->pages[$path] = $this->getPage($path); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->pages[$path]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Returns blueprints for the given type. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $type | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      * @return Data\Blueprint | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function blueprints($type) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if ($this->blueprints === null) { | 
					
						
							| 
									
										
										
										
											2015-01-11 18:33:45 +01:00
										 |  |  |             $this->blueprints = new Data\Blueprints($this->grav['locator']->findResource('blueprints://')); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         return $this->blueprints->get($type); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Gets configuration data. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $type | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * @param array  $post | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      * @return Data\Data|null | 
					
						
							|  |  |  |      * @throws \RuntimeException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function data($type, $post = array()) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-10-10 13:26:39 +03:00
										 |  |  |         static $data = []; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (isset($data[$type])) { | 
					
						
							|  |  |  |             return $data[$type]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-10 13:26:39 +03:00
										 |  |  |         if (!$post) { | 
					
						
							|  |  |  |             $post = isset($_POST) ? $_POST : []; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         switch ($type) { | 
					
						
							|  |  |  |             case 'configuration': | 
					
						
							|  |  |  |             case 'system': | 
					
						
							|  |  |  |                 $type = 'system'; | 
					
						
							| 
									
										
										
										
											2014-10-06 14:38:14 +03:00
										 |  |  |                 $blueprints = $this->blueprints("config/{$type}"); | 
					
						
							|  |  |  |                 $config = $this->grav['config']; | 
					
						
							|  |  |  |                 $obj = new Data\Data($config->get('system'), $blueprints); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                 $obj->merge($post); | 
					
						
							| 
									
										
										
										
											2015-05-29 14:30:58 +02:00
										 |  |  |                 $file = CompiledYamlFile::instance($this->grav['locator']->findResource("config://{$type}.yaml")); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                 $obj->file($file); | 
					
						
							|  |  |  |                 $data[$type] = $obj; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'settings': | 
					
						
							|  |  |  |             case 'site': | 
					
						
							|  |  |  |                 $type = 'site'; | 
					
						
							| 
									
										
										
										
											2014-10-06 14:38:14 +03:00
										 |  |  |                 $blueprints = $this->blueprints("config/{$type}"); | 
					
						
							|  |  |  |                 $config = $this->grav['config']; | 
					
						
							|  |  |  |                 $obj = new Data\Data($config->get('site'), $blueprints); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                 $obj->merge($post); | 
					
						
							| 
									
										
										
										
											2015-05-29 14:30:58 +02:00
										 |  |  |                 $file = CompiledYamlFile::instance($this->grav['locator']->findResource("config://{$type}.yaml")); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                 $obj->file($file); | 
					
						
							|  |  |  |                 $data[$type] = $obj; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'login': | 
					
						
							|  |  |  |                 $data[$type] = null; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             default: | 
					
						
							| 
									
										
										
										
											2014-10-07 12:12:21 +03:00
										 |  |  |                 /** @var UniformResourceLocator $locator */ | 
					
						
							|  |  |  |                 $locator = $this->grav['locator']; | 
					
						
							|  |  |  |                 $filename = $locator->findResource("config://{$type}.yaml", true, true); | 
					
						
							|  |  |  |                 $file = CompiledYamlFile::instance($filename); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                 if (preg_match('|plugins/|', $type)) { | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |                     /** @var Plugins $plugins */ | 
					
						
							|  |  |  |                     $plugins = $this->grav['plugins']; | 
					
						
							|  |  |  |                     $obj = $plugins->get(preg_replace('|plugins/|', '', $type)); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                     $obj->merge($post); | 
					
						
							| 
									
										
										
										
											2014-10-07 12:12:21 +03:00
										 |  |  |                     $obj->file($file); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     $data[$type] = $obj; | 
					
						
							|  |  |  |                 } elseif (preg_match('|themes/|', $type)) { | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |                     /** @var Themes $themes */ | 
					
						
							|  |  |  |                     $themes = $this->grav['themes']; | 
					
						
							|  |  |  |                     $obj = $themes->get(preg_replace('|themes/|', '', $type)); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                     $obj->merge($post); | 
					
						
							| 
									
										
										
										
											2014-10-07 12:12:21 +03:00
										 |  |  |                     $obj->file($file); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-10 15:04:12 +03:00
										 |  |  |                     $data[$type] = $obj; | 
					
						
							|  |  |  |                 } elseif (preg_match('|users/|', $type)) { | 
					
						
							|  |  |  |                     $obj = User::load(preg_replace('|users/|', '', $type)); | 
					
						
							|  |  |  |                     $obj->merge($post); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                     $data[$type] = $obj; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     throw new \RuntimeException("Data type '{$type}' doesn't exist!"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $data[$type]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-30 11:22:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get the GPM instance | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return GPM The GPM instance | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |     public function gpm() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (!$this->gpm) { | 
					
						
							|  |  |  |             $this->gpm = new GPM(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->gpm; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Converts dot notation to array notation. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $name | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function field($name) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $path = explode('.', $name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return array_shift($path) . ($path ? '[' . implode('][', $path) . ']' : ''); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get all routes. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function routes() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |         /** @var Pages $pages */ | 
					
						
							|  |  |  |         $pages = $this->grav['pages']; | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |         return $pages->routes(); | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Get all plugins. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |     public function plugins($local = true) | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |         $gpm = $this->gpm(); | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $local ? $gpm->getInstalledPlugins() : $gpm->getRepositoryPlugins()->filter(function ( | 
					
						
							|  |  |  |             $package, | 
					
						
							|  |  |  |             $slug | 
					
						
							|  |  |  |         ) use ($gpm) { | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |             return !$gpm->isPluginInstalled($slug); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2014-10-03 15:40:58 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Get all themes. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |     public function themes($local = true) | 
					
						
							| 
									
										
										
										
											2014-10-03 15:40:58 -06:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |         $gpm = $this->gpm(); | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $local ? $gpm->getInstalledThemes() : $gpm->getRepositoryThemes()->filter(function ($package, $slug) use | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |             $gpm | 
					
						
							|  |  |  |         ) { | 
					
						
							| 
									
										
										
										
											2015-04-04 14:49:40 +02:00
										 |  |  |             return !$gpm->isThemeInstalled($slug); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get log file for fatal errors. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function logs() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |         if (!isset($this->logs)) { | 
					
						
							| 
									
										
										
										
											2015-01-11 00:47:27 +01:00
										 |  |  |             $file = LogFile::instance($this->grav['locator']->findResource('log://exception.log')); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |             $content = $file->content(); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |             $this->logs = array_reverse($content); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |         return $this->logs; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Used by the Dashboard in the admin to display the X latest pages | 
					
						
							|  |  |  |      * that have been modified | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  integer $count number of pages to pull back | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |      * @return array | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-10-02 12:14:13 -07:00
										 |  |  |     public function latestPages($count = 10) | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |         /** @var Pages $pages */ | 
					
						
							|  |  |  |         $pages = $this->grav['pages']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |         $latest = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |         foreach ($pages->routes() as $url => $path) { | 
					
						
							|  |  |  |             $page = $pages->dispatch($url); | 
					
						
							| 
									
										
										
										
											2014-12-10 10:23:22 -07:00
										 |  |  |             if ($page && $page->routable()) { | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |                 $latest[$page->route()] = ['modified' => $page->modified(), 'page' => $page]; | 
					
						
							| 
									
										
										
										
											2014-12-10 10:23:22 -07:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // sort based on modified
 | 
					
						
							| 
									
										
										
										
											2014-10-02 12:14:13 -07:00
										 |  |  |         uasort($latest, function ($a, $b) { | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |             if ($a['modified'] == $b['modified']) { | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |             return ($a['modified'] > $b['modified']) ? -1 : 1; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // build new array with just pages in it
 | 
					
						
							|  |  |  |         // TODO: Optimized this
 | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |         $list = array(); | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |         foreach ($latest as $item) { | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |             $list[] = $item['page']; | 
					
						
							| 
									
										
										
										
											2014-09-05 22:27:30 -06:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |         return array_slice($list, 0, $count); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Get log file for fatal errors. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function logEntry() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-01-11 00:47:27 +01:00
										 |  |  |         $file = File::instance($this->grav['locator']->findResource("log://{$this->route}.html")); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         $content = $file->content(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $content; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-30 11:22:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Search in the logs when was the latest backup made | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array Array containing the latest backup information | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-04-27 13:37:22 +02:00
										 |  |  |     public function lastBackup() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $file = JsonFile::instance($this->grav['locator']->findResource("log://backup.log")); | 
					
						
							|  |  |  |         $content = $file->content(); | 
					
						
							|  |  |  |         if (empty($content)) { | 
					
						
							|  |  |  |             return [ | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |                 'days'        => '∞', | 
					
						
							|  |  |  |                 'chart_fill'  => 100, | 
					
						
							| 
									
										
										
										
											2015-04-27 13:37:22 +02:00
										 |  |  |                 'chart_empty' => 0 | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $backup = new \DateTime(); | 
					
						
							|  |  |  |         $backup->setTimestamp($content['time']); | 
					
						
							|  |  |  |         $diff = $backup->diff(new \DateTime()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $days = $diff->days; | 
					
						
							|  |  |  |         $chart_fill = $days > 30 ? 100 : round($days / 30 * 100); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |             'days'        => $days, | 
					
						
							|  |  |  |             'chart_fill'  => $chart_fill, | 
					
						
							| 
									
										
										
										
											2015-04-27 13:37:22 +02:00
										 |  |  |             'chart_empty' => 100 - $chart_fill | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Returns the page creating it if it does not exist. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param $path | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      * @return Page | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function getPage($path) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** @var Pages $pages */ | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |         $pages = $this->grav['pages']; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($path && $path[0] != '/') { | 
					
						
							|  |  |  |             $path = "/{$path}"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $page = $path ? $pages->dispatch($path, true) : $pages->root(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!$page) { | 
					
						
							|  |  |  |             $slug = basename($path); | 
					
						
							| 
									
										
										
										
											2015-08-07 12:05:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if ($slug == '') { | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |                 return null; | 
					
						
							| 
									
										
										
										
											2015-08-07 12:05:34 +02:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |             $ppath = dirname($path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Find or create parent(s).
 | 
					
						
							|  |  |  |             $parent = $this->getPage($ppath != '/' ? $ppath : ''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Create page.
 | 
					
						
							|  |  |  |             $page = new Page; | 
					
						
							|  |  |  |             $page->parent($parent); | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |             $page->filePath($parent->path() . '/' . $slug . '/' . $page->name()); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |             // Add routing information.
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |             $pages->addPage($page, $path); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 18:07:55 -06:00
										 |  |  |             // Set if Modular
 | 
					
						
							|  |  |  |             $page->modularTwig($slug[0] == '_'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |             // Determine page type.
 | 
					
						
							|  |  |  |             if (isset($this->session->{$page->route()})) { | 
					
						
							| 
									
										
										
										
											2014-09-17 11:54:57 +03:00
										 |  |  |                 // Found the type and header from the session.
 | 
					
						
							|  |  |  |                 $data = $this->session->{$page->route()}; | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |                 $visible = isset($data['visible']) && $data['visible'] != '' ? (bool)$data['visible'] : $this->guessVisibility($page); | 
					
						
							| 
									
										
										
										
											2015-08-05 19:04:55 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 $header = ['title' => $data['title'], 'visible' => $visible]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if ($data['type'] == 'modular') { | 
					
						
							|  |  |  |                     $header['body_classes'] = 'modular'; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 18:07:55 -06:00
										 |  |  |                 $name = $page->modular() ? str_replace('modular/', '', $data['type']) : $data['type']; | 
					
						
							|  |  |  |                 $page->name($name . '.md'); | 
					
						
							| 
									
										
										
										
											2015-08-05 19:04:55 -06:00
										 |  |  |                 $page->header($header); | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |                 $page->frontmatter(Yaml::dump((array)$page->header())); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 // Find out the type by looking at the parent.
 | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |                 $type = $parent->childType() ? $parent->childType() : $parent->blueprints()->get('child_type', | 
					
						
							|  |  |  |                     'default'); | 
					
						
							|  |  |  |                 $page->name($type . CONTENT_EXT); | 
					
						
							| 
									
										
										
										
											2014-09-17 11:54:57 +03:00
										 |  |  |                 $page->header(); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2014-10-10 11:57:57 +03:00
										 |  |  |             $page->modularTwig($slug[0] == '_'); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $page; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 15:30:30 -06:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Guess the intended visibility status based on other sibling folders | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param \Grav\Common\Page\Page $page | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function guessVisibility(Page $page) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $children = $page->parent()->children(); | 
					
						
							|  |  |  |         foreach ($children as $child) { | 
					
						
							|  |  |  |             if ($child->order()) { | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 15:30:30 -06:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Static helper method to return current route. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function route() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |         return dirname('/' . Grav::instance()['admin']->route); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-27 19:33:52 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-30 11:16:05 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Determine if the plugin or theme info passed is from Team Grav | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param object $info Plugin or Theme info object | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-07-30 11:16:05 +02:00
										 |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-07-27 19:33:52 -06:00
										 |  |  |     public function isTeamGrav($info) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (isset($info['author']['name']) && $info['author']['name'] == 'Team Grav') { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-11 18:30:27 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function phpinfo() { | 
					
						
							|  |  |  |         ob_start(); | 
					
						
							|  |  |  |         phpinfo(); | 
					
						
							|  |  |  |         $pinfo = ob_get_contents(); | 
					
						
							|  |  |  |         ob_end_clean(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $pinfo = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1',$pinfo); | 
					
						
							|  |  |  |         return $pinfo; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | } |