'', 'name' => $this->widget_name(), 'type' =>'', 'order' =>'', 'location' =>'', 'before' => true, 'after' => true ]; $this->args = array_merge($defaults,$args); try { $this->rand_number = random_int(999, 99999); } catch (\Exception $e) { } } /** * admin_render * this method must have to implement by all widget to render admin panel widget content * @since 1.0.0 * */ abstract public function admin_render(); /** * frontend_render * this method must have to implement by all widget to render frontend widget content * @since 1.0.0 * */ abstract public function frontend_render(); /** * widget_title * this method must have to implement by all widget to register widget title * @since 1.0.0 * */ abstract public function widget_title(); /** * widget_name * this method must have to implement by all widget to register widget name * @since 1.0.0 * */ public function widget_name() { // TODO: Implement widget_name() method. return substr(strrchr(get_called_class(), "\\"), 1); } /** * default_fields * this method will return all the default field required by any widget * @since 1.0.0 * */ public function default_fields() { //all initial field $output = ''; $output .= !empty($this->args['id']) ? '' : ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; return $output; } /** * get_settings * this method will return all the settings value saved for widget * @since 1.0.0 * */ public function get_settings() { $widget_data = !empty($this->args['id']) ? Widgets::find($this->args['id']) : null; $widget_content_data = $this->repairSerializeString($widget_data?->widget_content); $widget_data = !empty($widget_data) ? unserialize($widget_content_data,['class' => false]) : []; return $widget_data; } /** * widget_column_start * this method will add widget column markup for frontend * @since 1.0.0 */ public function widget_column_start() { if (isset($this->args['column']) && $this->args['column']){ return '
'; } } /** * widget_column_end * this method will add widget column markup for frontend * @since 1.0.0 */ public function widget_column_end() { if (isset($this->args['column']) && $this->args['column']){ return '
'; } } /** * widget_before * this method will add widget before html markup for widget in frontend * @since 1.0.0 */ public function widget_before($class = null) { return $this->widget_column_start().'
'; } /** * widget_after * this method will add widget after html markup for widget in frontend * @since 1.0.0 */ public function widget_after() { return $this->widget_column_end().'
'; } /** * admin_form_start * this method will init form markup for admin panel * @since 1.0.0 */ public function admin_form_start() { return '
'; } /** * admin_form_end * this method will end tag form markup for admin panel * @since 1.0.0 */ public function admin_form_end() { return '
'; } /** * admin_form_submit_button * this method will add a submit button for widget in admin panel * @since 1.0.0 */ public function admin_form_submit_button($text = null){ $button_text = $text ?? __('Save Changes'); return ''; } /** * admin_form_submit_button * this method will add a submit button for widget in admin panel * @since 1.0.0 */ public function admin_language_tab(){ $all_languages = Language::all(); $output = ''; return $output; } /** * admin_language_tab_start * this method will add language tab content start wrapper * @since 1.0.0 * */ public function admin_language_tab_start(){ return '
'; } /** * admin_language_tab_end * this method will add language tab content end wrapper * @since 1.0.0 * */ public function admin_language_tab_end(){ return '
'; } /** * admin_language_tab_content_start * this method will add language tab panel start * @since 1.0.0 * */ public function admin_language_tab_content_start($args){ return '
'; } /** * admin_language_tab_content_end * this method will add language tab panel end * @since 1.0.0 * */ public function admin_language_tab_content_end(){ return '
'; } public function admin_form_before(){ $markup = ''; if ($this->args['before']){ $markup .= '
  • '; } $markup .= '

    '.str_replace(['-','_'],[' ',' '],$this->widget_title()).'

    '; return $markup; } public function admin_form_after(){ $markup = '
    '; if ($this->args['after']){ $markup .= '
  • '; } return $markup; } public function repairSerializeString($value) { $data = preg_replace_callback( '/(?<=^|\{|;)s:(\d+):\"(.*?)\";(?=[asbdiO]\:\d|N;|\}|$)/s', function($m){ return 's:' . strlen($m[2]) . ':"' . $m[2] . '";'; }, $value ); return $data; } }