Inheritance: extends BaseModel
コード例 #1
0
ファイル: DevelopWidget.class.php プロジェクト: cjmi/miniblog
 public function render($data)
 {
     import("ORG.Util.Input");
     $db = new WidgetModel();
     $rs = $db->where("name='develop'")->find();
     if ($rs['switch'] != 1) {
         return false;
         exit;
     }
     $db = new WorldsModel();
     $rs = $db->field('id,text')->limit(5)->where("last_time<>''")->order('last_time desc')->select();
     //dump($rs);
     if ($rs === null || $rs === false) {
         return false;
         exit;
     }
     echo "<h2>最新动态</h2>";
     echo "<ul>";
     foreach ($rs as $rs) {
         $content = Input::truncate($rs['text'], 20);
         $link .= "[微博]:“";
         $link .= "<a href='";
         $link .= __APP__;
         $link .= "/Worlds/view/id/";
         $link .= $rs['id'];
         $link .= "'>";
         $link .= $content;
         $link .= "</a>";
         echo "<li>" . $link . "”有新回复</li>";
         unset($link);
     }
     echo "</ul>";
 }
コード例 #2
0
ファイル: DoubanWidget.class.php プロジェクト: cjmi/miniblog
 public function render($data)
 {
     $db = new WidgetModel();
     $rs = $db->where("name='douban'")->find();
     if ($rs['switch'] != 1) {
         return false;
         exit;
     }
     $db = new ConfigModel();
     $rs = $db->where("k='douban_fm'")->find();
     if ($rs === null || $rs === false) {
         return false;
         exit;
     }
     $douban_fm = $rs['v'];
     $rs = $db->where("k='douban_show'")->find();
     if ($rs === null || $rs === false) {
         return false;
         exit;
     }
     $douban_show = $rs['v'];
     echo "<h2>我的豆瓣</h2>";
     echo "<ul>";
     echo $douban_fm == '' ? '' : "<li>{$douban_fm}</li>";
     echo "</ul>";
 }
コード例 #3
0
 /**
  * Init dashboard check early.
  */
 public function init()
 {
     // Don't run when in console
     if (!craft()->isConsole()) {
         // Get current user
         $currentUser = craft()->userSession->getUser();
         // Make sure we're logged in onto CP
         if ($currentUser && $currentUser->can('accessCp') && craft()->request->isCpRequest()) {
             // Check if this user already has widgets
             $userWidgetRecords = WidgetRecord::model()->ordered()->findAllByAttributes(array('userId' => $currentUser->id));
             if (!$userWidgetRecords) {
                 // Get enabled admin widgets
                 $adminWidgetRecords = WidgetRecord::model()->ordered()->findAllByAttributes(array('userId' => 1, 'enabled' => 1));
                 // Populate widget models
                 $adminWidgets = WidgetModel::populateModels($adminWidgetRecords);
                 // Loop through widget models
                 foreach ($adminWidgets as $widget) {
                     // Clear widget id
                     $widget->id = null;
                     // Save on user
                     $result = craft()->dashboard->saveUserWidget($widget);
                     // If that worked then we should have an id on the model
                     // and can go ahead and update the colspan
                     if ($result && $widget->id) {
                         craft()->dashboard->changeWidgetColspan($widget->id, $widget->colspan);
                     }
                 }
             }
         }
     }
 }
コード例 #4
0
 /**
  * Returns a widget by its ID.
  *
  * @param int $id
  * @return WidgetModel
  */
 public function getUserWidgetById($id)
 {
     $widgetRecord = WidgetRecord::model()->findByAttributes(array('id' => $id, 'userId' => craft()->userSession->getUser()->id));
     if ($widgetRecord) {
         return WidgetModel::populateModel($widgetRecord);
     }
 }
コード例 #5
0
 public static function SaveWidgetHandler(Form $form)
 {
     $id = $form->getElement('id')->get('value');
     // ID can be null, that just means it's a new widget!
     if (!$id) {
         // Generate an id!
         $id = Core::GenerateUUID();
     }
     $model = new WidgetModel('/gallery/view/' . $id);
     $model->set('editurl', '/gallerywidget/update/' . $id);
     $model->set('deleteurl', '/gallerywidget/delete/' . $id);
     $model->set('title', $form->getElement('title')->get('value'));
     $model->setSetting('album', $form->getElement('album')->get('value'));
     $model->setSetting('count', $form->getElement('count')->get('value'));
     $model->setSetting('order', $form->getElement('order')->get('value'));
     $model->setSetting('dimensions', $form->getElement('dimensions')->get('value'));
     $model->setSetting('uselightbox', $form->getElement('uselightbox')->get('value'));
     $model->save();
     return 'back';
 }
コード例 #6
0
ファイル: LinkWidget.class.php プロジェクト: cjmi/miniblog
 function render($data)
 {
     $db = new WidgetModel();
     $rs = $db->where("name='link'")->find();
     if ($rs['switch'] != 1) {
         return false;
     }
     $db = new LinksModel();
     $rs = $db->where("pass_flag=1")->limit(5)->select();
     //dump($rs);
     if ($rs === null || $rs === false) {
         return false;
         exit;
     }
     echo "<h2>友情链接</h2>";
     echo "<ul>";
     foreach ($rs as $rs) {
         echo "<li><a href='" . $rs['www_url'] . "'>" . $rs['worlds'] . "</a></li>";
     }
     echo "</ul>";
 }
コード例 #7
0
	/**
	 * Get an array of all the parts of this request, including:
	 * 'controller', 'method', 'parameters', 'baseurl', 'rewriteurl'
	 *
	 * @return array
	 */
	public function splitParts() {
		$ret = WidgetModel::SplitBaseURL($this->get('baseurl'));

		// No?
		if (!$ret) {
			$ret = [
				'controller' => null,
				'method'     => null,
				'parameters' => null,
				'baseurl'    => null
			];
		}

		// Tack on the parameters
		if ($ret['parameters'] === null) $ret['parameters'] = [];

		return $ret;
	}
コード例 #8
0
	public static function _WidgetCreateUpdateHandler(Form $form){
		$baseurl = $form->getElement('baseurl')->get('value');

		$model = new WidgetModel($baseurl);
		$model->set('editurl', '/admin/widget/update?baseurl=' . $baseurl);
		$model->set('deleteurl', '/admin/widget/delete?baseurl=' . $baseurl);
		$model->set('title', $form->getElement('title')->get('value'));
		if($form->getElement('template')){
			$model->set('template', $form->getElementValue('template'));
		}

		$elements = $form->getElements();
		foreach($elements as $el){
			/** @var FormElement $el */
			if(strpos($el->get('name'), 'setting[') === 0){
				$name = substr($el->get('name'), 8, -1);
				$model->setSetting($name, $el->get('value'));
			}
		}
		$model->save();

		return 'back';
	}
コード例 #9
0
 public function delete()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     if (!\Core\user()->checkAccess('p:/gallery/manage_all')) {
         return View::ERROR_ACCESSDENIED;
     }
     if ($request->getParameter(0)) {
         $model = new WidgetModel('/gallery/view/' . $request->getParameter(0));
     } else {
         $model = new WidgetModel();
     }
     if (!$request->isPost()) {
         return View::ERROR_BADREQUEST;
     }
     if (!$model->exists()) {
         return View::ERROR_NOTFOUND;
     }
     $model->delete();
     \Core\go_back();
 }
コード例 #10
0
/**
 * Manually add a widget onto a template.
 *
 * @todo Finish documentation of smarty_function_widget
 *
 * @param array  $params  Associative (and/or indexed) array of smarty parameters passed in from the template
 * @param Smarty $smarty  Parent Smarty template object
 *
 * @return mixed
 *
 * @throws SmartyException
 */
function smarty_function_widget($params, $smarty){

	$assign  = (isset($params['assign']))? $params['assign'] : false;
	$tmpl    = $smarty->getTemplateVars('__core_template');
	$topview = ($tmpl instanceof \Core\Templates\TemplateInterface) ? $tmpl->getView() : \Core\view();

	// Version 2.0 uses baseurl as the defining call.
	if(isset($params['baseurl'])){
		$api = 2.0;
		$parts = WidgetModel::SplitBaseURL($params['baseurl']);
		$original = $params['baseurl'];
		$name = $parts['controller'];
		$method = $parts['method'];
		$parameters = $parts['parameters'];
	}
	// Version 1.0 uses name.
	elseif(isset($params['name'])){
		$api = 1.0;
		$original = $params['name'];
		$name = $params['name'];
		// Try to look up this requested widget.
		$name .= 'Widget';
		$parameters = null;
		$method = null;
	}
	else{
		$api = 0.0;
		$name = null;
		$original = null;
		$parameters = null;
		$method = null;
	}


	if(!class_exists($name)){
		if(DEVELOPMENT_MODE){
			return '[ERROR, Class for ' . $original . ' not found on system, widget disabled.]';
		}
		else{
			return '';
		}

		//throw new SmartyException('Unable to locate class [' . $name . '] for requested widget', null, null);
	}
	// @todo Add support for requiring instancing.

	/** @var $w Widget_2_1 */
	$w = new $name();
	// Version 1.0 API
	if($api == 1.0){
		$dat = $w->execute()->fetch();
	}
	// Version 2.0 API
	elseif($api == 2.0){
		$w->_params = $parameters;

		// Ensure that the widget's View knows it's linked to a parent!
		$w->getView()->parent = $topview;

		// Populate the request with the inbound data too.
		$request = $w->getRequest();
		if(isset($params['baseurl'])) unset($params['baseurl']);

		if($parameters) $request->parameters = array_merge($params, $parameters);
		else $request->parameters = $params;

		$return = call_user_func(array($w, $method));
		$dat = null;

		if(is_int($return)){
			throw new SmartyException("widget $name/$method returned error code $return.", null, null);
		}
		elseif($return === null){
			// Hopefully it's setup!
			$return = $w->getView();
		}
		// If it's just a string, return that.
		elseif(is_string($return)) {
			$dat = $return;
		}


		// If dat is still null, (it probably is still null btw), then render the template!
		if($dat === null){
			// Try to guess the templatename if it wasn't set.
			if($return->error == View::ERROR_NOERROR && $return->contenttype == View::CTYPE_HTML && $return->templatename === null){
				$cnameshort = (strpos($name, 'Widget') == strlen($name) - 6) ? substr($name, 0, -6) : $name;
				$return->templatename = strtolower('/widgets/' . $cnameshort . '/' . $method . '.tpl');
			}

			$dat = $return->fetch();
		}
	}
	else{
		$dat = 'Invalid API version';
	}


	return $assign ? $smarty->assign($assign, $dat) : $dat;
}
コード例 #11
0
	/**
	 * Internal function to parse and handle the configs in the component.xml file.
	 * This is used for installations and upgrades.
	 *
	 * @param boolean $install   Set to false to force uninstall/disable mode.
	 * @param int     $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output.
	 *
	 * @return boolean | int
	 * @throws InstallerException
	 */
	public function _parseWidgets($install = true, $verbosity = 0) {
		$overallChanges  = [];
		$overallAction   = $install ? 'Installing' : 'Uninstalling';
		$overallActioned = $install ? 'Installed' : 'Uninstalled';
		$overallSet      = $install ? 'Set' : 'Remove';

		Core\Utilities\Logger\write_debug($overallAction . ' Widgets for ' . $this->getName());

		if(!$install){
			die('@todo Support uninstalling widgets via _parseWidgets!');
		}

		// I need to get the schema definitions first.
		$node = $this->_xmlloader->getElement('widgets');
		//$prefix = $node->getAttribute('prefix');

		// Now, get every table under this node.
		foreach ($node->getElementsByTagName('widget') as $subnode) {
			$baseurl     = $subnode->getAttribute('baseurl');
			$installable = $subnode->getAttribute('installable');
			$title       = $subnode->getAttribute('title');

			if($verbosity == 2){
				CLI::PrintActionStart($overallAction . ' widget ' . $baseurl . ' ("' . $title . '")');
			}

			// Insert/Update the defaults for an entry in the database.
			$m = new WidgetModel($baseurl);
			$action = ($m->exists()) ? 'Updated' : 'Added';

			if (!$m->get('title')){
				// Only set the title if it was previously unset
				$m->set('title', $title);
			}

			$m->set('installable', $installable);
			$saved = $m->save();

			if ($saved){
				if($verbosity == 2){
					CLI::PrintActionStatus(true);
				}
				$changes[] = $action . ' widget [' . $m->get('baseurl') . ']';

				// Is this a new widget and it's an admin installable one?
				// If so install it to the admin widgetarea!
				if($action == 'Added' && $installable == '/admin'){
					$weight = WidgetInstanceModel::Count(
						[
							'widgetarea' => 'Admin Dashboard',
							'page_baseurl' => '/admin',
						]
					) + 1;

					$wi = new WidgetInstanceModel();
					$wi->setFromArray(
						[
							'baseurl' => $m->get('baseurl'),
							'page_baseurl' => '/admin',
							'widgetarea' => 'Admin Dashboard',
							'weight' => $weight
						]
					);
					$wi->save();

					$overallChanges[] = $overallActioned . ' widget ' . $m->get('baseurl') . ' into the admin dashboard!';
				}
			}
			else{
				if($verbosity == 2){
					CLI::PrintActionStatus('skip');
				}
			}
		}

		return (sizeof($overallChanges) > 0) ? $overallChanges : false;
	}